Jump to content

  • Log In with Google      Sign In   
  • Create Account


Event system for updates vs callbacks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 3DModelerMan   Members   -  Reputation: 974

Like
0Likes
Like

Posted 03 September 2012 - 09:57 AM

What would be better? Would it be better to have onUpdate() callbacks that need to be registered to get? Or would it be better to have an event system that just sends out an update message each frame. I can see a few benefits of both. The onUpdate callback method would have better performance because the event system wouldn't be taking care of the update scheduling. But with the event system sending out update messages, it would end up resulting in less code and an easier to maintain system, and by parralelizing the event system you might be able to get better performance. What are some other tradeoffs?

Edited by 3DModelerMan, 03 September 2012 - 09:57 AM.


Sponsor:

#2 Freya   Members   -  Reputation: 801

Like
1Likes
Like

Posted 03 September 2012 - 02:28 PM

I would go for a combination. If you are making a game then your system will have many other things to do each frame, so messages like "update color of an angry monster" won't need to be sent so often. Although some messages probably need to be sent each frame (like "update position" message).

Edited by Freya, 03 September 2012 - 02:29 PM.

Working on a game "Burnt islands".
Dev blog       
"Burnt islands" on Indie DB

#3 3DModelerMan   Members   -  Reputation: 974

Like
0Likes
Like

Posted 04 September 2012 - 09:20 AM

I'm just trying to decide if the update messages should be sent through the event system, or be called from the main loop.

#4 CC Ricers   Members   -  Reputation: 623

Like
1Likes
Like

Posted 04 September 2012 - 09:51 AM

I use events for menus when its items are clicked, highlighted, etc. They make more sense for interface elements such as these.
My development blog: Electronic Meteor

#5 swiftcoder   Senior Moderators   -  Reputation: 9769

Like
2Likes
Like

Posted 04 September 2012 - 11:08 AM

I'm just trying to decide if the update messages should be sent through the event system, or be called from the main loop.

I don't see any real reason why it couldn't be both. A callback is conceptually the response to an event.

Make your event dispatch system flexible enough to support both regular pulses (i.e. onFrameRenderer), and rare events (i.e. onButtonClicked).

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#6 Hodgman   Moderators   -  Reputation: 28696

Like
1Likes
Like

Posted 04 September 2012 - 11:18 AM

What kind of objects are you talking about sending onUpdate messages to? That probably affects the appropriate design somewhat.

#7 3DModelerMan   Members   -  Reputation: 974

Like
0Likes
Like

Posted 05 September 2012 - 10:10 AM

Game entities and subsystems. I usually just have a system where the game logic has a list of all the entities and subsystems and just loops through and calls onUpdate. But I thought it might be better to have the event system just send out an update event, and then the game logic would only need to worry about updating the event manager. Am I over engineering this and should just have it call the root entity's update method as well?

#8 swiftcoder   Senior Moderators   -  Reputation: 9769

Like
1Likes
Like

Posted 05 September 2012 - 11:45 AM

Game entities and subsystems. I usually just have a system where the game logic has a list of all the entities and subsystems and just loops through and calls onUpdate.

Do all game entities need an onUpdate() method? Do all subsystems?

If the answer to either of those is ever 'no', then you are under-engineering this problem. Something (probably your EventManager) should have a list of objects that are registered for updates, and loop over those calling onUpdate().

Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS