14
« on: February 11, 2013, 09:16:38 pm »
@alway:
"particularly since we don't really know what all it will be doing yet." <-- precisely why you want a messaging system. So you can have objects that you write now communicate with objects that someone else writes in two years with the same interface. Siquo's example message is simplistic for the purpose of demonstration, but a real message/message handler system would be more complex and interface with many more components.
As for worrying about a messaging system being too complex to code, I would say don't worry. There are a couple of experienced coders on this forum, and experienced coders know how to make things easy for themselves. That being said, having a good base simulation object and entity/component class including some sort of update, position (if applicable), or other common universal attributes will still be necessary.
There are also many tricks up the sleeve of a computer scientist that will make the performance loss basically unnoticable. And the benefits from the easy multithreading that you basically get for free for making a good messaging system will make these performance losses moot anyways.
@Siquo:
The messaging system is alright for some cases, but I think for GUM we need a different type of messaging system. We don't have centralized objects, so we need some sort of publish/subscribe system (i.e. whenever a new animal is created, it needs to be able to publish a NewAnimal message to everyone who wants to know about such a thing). Also, I don't think the message handler should be tied to a specific thread, since it's not scalable (i.e. the same messagehandler should be able to process 20 messages over 1 thread or 2000 messages over 4 or something like that). In particular, classes like "World" or "Graphics" should definitely not be inheriting from the message handler.
One thing in particular that bothered me, messages should not have an execute function. The message pattern usually involves listeners, and listeners decide how they want to respond to messages. In your particular example, then you wouldn't need to dynamic_cast to check if the message listener is in fact a graphics object. alway is also right in that writing so much boiler-plate code just to send a simple message isn't that great.