Message based or Task based?

Started by
1 comment, last by Telastyn 17 years, 9 months ago
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.
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. :)
"Don't try. Do it now."
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.

This topic is closed to new replies.

Advertisement