Archived

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

Is it well done? (Object Hierarchy)

This topic is 5886 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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