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

Author Topic: event loop in multiple places? :S  (Read 1115 times)

0 Members and 1 Guest are viewing this topic.

j0nte33

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
event loop in multiple places? :S
« on: July 27, 2015, 05:07:13 pm »
okay, so im writing a super basic engine, with a statemanager.
this is basically what happends right now:
void CEngine::Update()
{
        // Code for event loop, ( close application )
                CStateMachine::GetInstance().Update();
                Draw();
}
 
in GameStateGame, lets say i have a character, i need to do keyboard check for movement.
i can't just make a event loop in GameStateGame. tried it.
Any tips?

there are some solutions i've come up with but i would like some pointers...

solution 1:
(click to show/hide)

solution 2:
(click to show/hide)
Thankyou  ;D

kitteh-warrior

  • Guest
Re: event loop in multiple places? :S
« Reply #1 on: July 27, 2015, 05:15:38 pm »
You should only have one event loop that. From there, you can dispatch the events to other class instances the require the event for processing.

CStateMachine::GetInstance().Update();
If this is a singleton (which it looks like), that is typically a bad design.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: event loop in multiple places? :S
« Reply #2 on: July 27, 2015, 08:02:07 pm »
i would like some pointers...
You can tell you're still in coding mode when you read that as "I would like to use some pointers..."
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: event loop in multiple places? :S
« Reply #3 on: July 27, 2015, 08:37:09 pm »
As others have already said; have one event loop.
Once an event is consumed in the loop you can dispatch it to any subsystem that needs to process it if needed. But you should not poll for events in more than one location - once an event is read by one event loop it will not be available to another, so that can easily get confusing.