Subsystems and their management.

posted in Adam Omega
Published January 23, 2011
Advertisement
I am developing a component based system using the concept of subsystems for my current game. The system is the game (which controls level loading, timiing, etc) and the subsystems as things such as physics, audio, scripting, rendering, etc. Now each subsystem has its own data that it uses to perform its tasks. These subsystems however don't modify their data, but instead the use modifiers to change it. For example a render subsystem instance may contain a texture pointer, the RECT from the texture to use, and the destination RECT. Now we add a modifier for animation for example. This modifier can change the texture pointer or either source or destination RECTs.

Each subsystem is meant to be encapsulated and abstracted to the point that it can be used in any system (Direct X or OpenGL, PhysX or Havok, etc) with little modification. To achieve this we need to store instances of each subsystem inside a manager for that particular subsystem.
std::map< SubSystem*, std::map< std::string, std::string > > subsystems;
This does the trick. We use the map to store a pointer to the instance, and map that pointer to a properties name/value map. This allows use to store and retrieve information about the particular instance, such as an id, name, size, etc.

To register a particular instance we can use this simple function:

void SysMgr::RegisterSubSystem( SubSystem* s )
{
s->Register(this);
this->subsystems["name"] = s->GetName();<br />}<br /></code><br />SubSystem::GetName() returns a std::string with the instance or subsystem name. We also pass along a pointer to the manager so the instance can set or remove propeties or callbacks. To accomplish that task we use:<br /><code><br />void SysMgr::SetProperty( SubSystem* s, std::string name, std::string value )<br />{<br /> this->subsystems[name] = value;<br />}<br />void SysMgr::RemoveProperty( SubSystem* s, std::string name )<br />{<br /> this->subsystems.erase(name);<br />}<br /></code><br />Simple and effective.<br /><br />I have attached the manager and subsystem code below. These are virtual classes and will need to be subclasses to your own needs. I will try and post an example subsystem later today or tomorrow to give a feel for how to use the system. Modifiers are not included as that aspect isn't passed the idea stage quite yet.<div> </div>
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement