Jump to content
  • Advertisement
Sign in to follow this  
ChristianPena

Message based or Task based?

This topic is 4426 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I just wanted to see what approaches were being taken by the users of this forum in their main game loops. The one that myself and the people I work with are leaning towards is a message based system where the engine contains a message pump which dispatches messages to all listeners. Updates can happen this way as can Initialization, Activatation, Input, Output, etc. When done correctly, this provides for very loosely coupled and reusable code (except, of course, for the bindings that glue the system together). The other option is to create a Task based sort of approach where you have tasks that have the ability to override methods for receiving input, Initializing, Activating, etc. This seems to create more tightly coupled code, but I suppose with some thought, it is possible to just as easily decouple the functionality from the communication method. There are others, I am sure. What approach are you taking? Thanks.

Share this post


Link to post
Share on other sites
Advertisement
Those two are closely related to each other, mind though that Task-based approach will limit you to only a few overridable functions, such as Initialize(), Run() and Destroy(). Whether Message-based approach lets you expand when you need without the necessity of adding extra functions to your Message interface class, Task-based approach fails to provide it in an easy and proper way. An example would be adding an extra message definition to your enum', and the need to add a pure virtual function the the ITask class, which is hardly worth the effort of implementation in ALL of the derived classes.
There are work-arounds to that problem, such that you define not PURE, but just virtual functions in your Task class, or having one generalized function to do all the extra work in.
Also it depends on the sort of the project you're working on. If it may be an SDK, I don't see anything wrong with tightly coupled code, however if it is a toolkit, it may render useless and even wrong.
At the moment, I'm taking the Message-based approach, the Subscriber pattern, however I'm also considering using Task-based approach in a tight game loop for the engine' work, however this might be a little overkill. :)

Share this post


Link to post
Share on other sites
Standard non-message loop for me. Requiring the controlling app call a function or two in the main loop isn't exactly a terrible coupling burden.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!