Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - Ganitzsh

Pages: [1]
Window / Events outside loop
« on: March 26, 2014, 03:03:26 pm »

Im working on a game, a snake-like but I'm experiencing issues with events.
My design is the following;
I have a Core containing the game logic. (positions, food, snake body)
A dynamicaly linked SFML module to display the window and play the game
A game loop outside the SFML module

Basically, my SFML module create a window when I create the instance and display the snake on the sf::RenderWindow in the game loop located on the main.
I was wondering if there was an other way to handle input in a window than create a loop on RenderWindow::pollEvent().

Here's a sample of code:

/* Called inside loop */
void    SFMLModule::refreshScreen()
  if (!_window->setActive())
  input(); /* <----- input method (see below) */

/* Handling input */
void SFMLModule::input()
  while (_window->pollEvent(_event))
    if (_event.type == sf::Event::Closed)
    else if (_event.type == sf::Event::KeyPressed)
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
      if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))

/* game loop inside main */
# define TIME_PER_FRAME 70000
while (!core->isDone())
   if (!core->getStop())

My problem is in the
Since it's called in a loop, the input method will also create a loop and I suspect this is the root of the lag I have at runtime. Am I wrong?
Also, my sf::RenderWindow does not display correctly sometimes, there's a transparent zone at the bottom.

Thanks  :)


Pages: [1]