Quote:Original post by Ubik
Quote:Original post by virus-
Have subsystems register with other subsystem for messages, that way we can send messages to those subsystems that care about them but this requires knowledge of those subsystems so adding a new system might require changes to others.
An alternative to this is that you have a messaging module, and the other modules register themselves only with it, telling what kind of messages they want to send and receive. This way a module need knowledge of only one other module, and I think that in a messaging based system a dependency to messaging system is acceptable.
Though now that I think about it, messaging could be arranged so that the messaging system is the one that asks the modules what kind of messages they want to send and receive, this way only the messaging system needs to know anything about other modules. And if the modules have generic enough messaging interface, even the messaging module could be pretty ignorant about whose messages it is delivering.
My vote is against messaging systems. It tends to introduce implicit and hidden dependencies. If A is delivering a message to B, then either A needs to know how B would like to have it's message, or B has to know what kind of messages are passed around by A (ie: the direction of the dependency is a design choice). So (conceptually) there is a dependency. And if there is, it better be explicit.
Having the messaging system in the middle can introduce strange behavior when some subsystem is not hooked in the system. Some expected or required messages may not be received, or synchronization between sender and receiver of a message may pose a problem. If I had to chose between having to pass a few extra references around and add some include files, or hunting down obscure problems caused by messages not being passed around, I'd chose the first.
Perhaps you can eliminate the inter-subsystem communication entirely. Your subsystems are only working on the data, and your "data" is responsible for notifying others that it has changed.
In terms of animations and rendering, your animation subsystem works on an animation, and once the animation is ready to be rendered the animation component itself tells all the interested subsystems, rendering, it has changed.
Quote:You can probably draw rest of the system out and it'd fall perfectly to number 5. on Adam's list, excessive use of observer pattern
I don't quite understand why this would stand in the way of a component system, other than just being a design challenge and PERHAPS a performance issue. (Note: I never implemented a component based system, only read about it, so I may be wrong).
The idea is that a subsystem is notified of changes of the data in a component. An observer pattern would be able to fulfill that purpose just as well as a messaging system. The design challenge is how to get the subsystem subscribed and unsubscribed to the component as it is loaded or unloaded.
The performance issue might be with excessive subscribe and unsubscribe actions. But then again, you're not going to do thousands of subscriptions every frame, are you?
From the top of my head: I'd probably use the approach of having a component factory to tackle the design challenge. Have the subsystems tell the component factory in which type of components they are interested, and the factory can notify the subsystems if a new component is created or loaded.
In short, when reading the original post it seems to me that the messaging system is the cause of the problem. I believe that the messaging system can be eliminated to create an easier to understand system that can solve your problems in a much easier way, and still be considered a component based system.
Again, I have no experience creating a component based system, so I may have missed something.