Event system for updates vs callbacks
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?
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).
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 use events for menus when its items are clicked, highlighted, etc. They make more sense for interface elements such as these.
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).
What kind of objects are you talking about sending onUpdate messages to? That probably affects the appropriate design somewhat.
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?
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().
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement