Archived

This topic is now archived and is closed to further replies.

Lestat3D

Is it well done? (Object Hierarchy)

Recommended Posts

I''m working on an RPG game on VC++ and DX8, and I would to know if I have to write my own Direct3DRM classes, I''ve started with a hierarchy like as follows (it''s just a diagram): class CCamera { //''Look-at'' Vector //''Up'' Vector //Position Vector //Set-Get Camera Methods } class CCharacter { //CMesh Object //Position Vector //''Look-at'' Vector //Position Vector (Relative to Scenario) //Set-Get Mesh Methods //Animation Methods //Talking Methods //Sounds } class CScenario { //CMesh Objects //Position Methods //CCharacters Collection //CCameras Collection //Set-Get Mesh Methods //Animation Methods //Natural Events Methods } class CCollisionManager { //Information About Coordinates and Meshes //CallBack functions that manages collisions between CCharacters } class CGame { //CMenu Object //CPlayers Collection //CCharacters Collection //... } I want to know if I am doing sonething bad in my objects hierarchy. Tnxs a lot.

Share this post


Link to post
Share on other sites
Looks pretty good

Instead of call-backs you can use observers, and/or interface pointers.

Anything that the collision mangager needs to deal with could support a ''ICollisionObject'' interface, for instance.

Magmai Kai Holmlor
- Not For Rent

Share this post


Link to post
Share on other sites
If you''re familar with Java, they call them ''Listeners''.

  
//In some file

interface ISomeObjectObserver
{
HRESULT OnSomeEvent(ISomeObject* pObj, ...);
}

class CSomeObject : public ISomeObject
{
AddObserver(ISomeObjectObserver* pOb)
{
m_pObserver = pOb;
}
HRESULT SomeEvent()
{
return m_pObserver->OnSomeEvent(this, ...);
}
};

//In some other file

class CMyClass : public ISomeObjectObserver
{
HRESULT OnSomeEvent(ISomeObject* pObj, ...)
{
cout<<"SomeObject ("<<pObj<<") fired SomeEvent"<<endl;
}
};

This decouples the event handling code from the event firing code, which makes it easy to make more classes the can send/receive ISomeObject events via the Observer interface.

Share this post


Link to post
Share on other sites
Thanks a lot for your hints.
Yes, I''m familiarized with java, but I don''t know how to implemet it in VC++, could you help me with it?

Share this post


Link to post
Share on other sites