Sign in to follow this  
notbad

Does your world class look something like this?

Recommended Posts

Hi all, I have started coding my world class. I have little experience in what should be in, I have decided to have something like this class CWorld { public: CWorld::CWorld() {} virtual CWorld::~CWorld() private: //Render Engine and parititioning Ogre::SceneManager* m_pSceneMgr; //Physics Engine auto_ptr<OgreNewt::World> m_pPhycisWorld; //Entity Management auto_ptr<CEntityMgr> m_pEntityMgr; }; It is not completed, just wanted to show a blueprint of it. I think my world class should contain the logic representation of entities (physics world), entities in the world, and the scene manager (that is partitioning the world, etc...). Does I have any other options? Do you see any pitfalls using this this way?. Thanks in advance, notbad. [Edited by - notbad on November 25, 2007 7:25:36 AM]

Share this post


Link to post
Share on other sites
Ok. Here's a basic checklist of things to do when designing a class before writing a single line of code:
1) Write down a list of reasons for the class to exist. For example, for a linked list class: this class exists to store objects in a linked list.

2a) If there is more than one thing on that list then your object is probably too big. Split each reason to exist into a different class and go back to step 1.
2b) If there is nothing in that list then your object has no reason to exist. Scrap it and move on to something else.

3) Create a list of class invariants: things about your class that should always be true. For example. If you have a time class that contains hours and minutes and seconds, then your list might be:
* hours is always between 1 and 12
* minutes is always between 0 and 60
* seconds is always between 0 and 60

4a) If there are no invariants, then you don't really have a class. Either scrap it and move on, or create a struct with all public variables and move on.
4b) Group the invariants together. Put invariants in the same group if they can't be maintained without messing with others in the same group. So in the time class, hours, minutes and seconds are all related because if you overflow seconds, minutes needs to get modified, and then hours might need to get modified.
4c) If there is more than one group, then your class is probably too big. Split up the class and go back to step 1.

Share this post


Link to post
Share on other sites
[quote]Original post by notbad
virtual CWorld::~CWorld()

[/quote]

I advise not to declare your destructor virtual unless you intend to inherit the class and in which case having a scenegraph, entity and physics manager created every time you implement an object derived from CWorld would probably cause a considerable unneeded overhead.

It is considered good programming practise to only declare a destructor virtual if you have one or more virtual functions in the class itself.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this