Observer registration in Smoke demo framework

Observer registration in Smoke demo framework


I'm currently taking a look at the smoke framework and having some trouble understanding the way objects from differents systems are linked together.

If you take a look at this object for example:



How are those objects from different scenes linked, so that a position change in the physics system will result in a position change in the graphics system? I can understand the idea of using the observer pattern and one system posting changes so that another system can update its internal copy of the variable thus making sure all system will always get their "fresh" data, but I'm having a hard time following this idea in terms of execution, e.g. how those links are established.

Thanks for any hints or advice!

4 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

I'm sorry the code seems to be hard to read, so here it goes again:

That's a good question. The XML files are parsed at start up and this is when the observer/subject relationships are created. In the example you provided, the XML file is defining an object called "Ball." This object has properties in the Graphics and PhysicsCollision system. When the XML file is parsed, an object will be created in SystemGraphics (ObjectMesh.cpp) and an object will be created in SystemPhysicsCollisionHavok (ObjectPhysics.cpp). If you look at these cpp files you will see two methods called GetPotentialSystemChanges and GetDesiredSystemChanges. GetPotentialSystemChanges lists all the changes this object will make and GetDesiredSystemChanges lists all the changes this object wants to know about. So, when these objects are created, the Change Control Manager calls these functions to determine which data might be propagated. For example, the ObjectPhysics says it will change position and ObjectMesh says it wants to know about position changes. When ObjectPhysics posts a position change, the Change Control Manager knows to tell the ObjectMesh about it.

I hope this helps.
Let me know if you have any further questions.

Thanks for the quick answer! This is exactly what I was looking for.

Leave a Comment

Please sign in to add a comment. Not a member? Join today