good object oriented design
good object oriented design
how can i design my classes so scene manager can be accessed by other classes.
i have now the class in which all the models are loaded and rendered,but things got to complicated,i have many models and textures and i thought that the best should be to write clasess that will handle similiar things.like player class,that should handle all player model loading,weapons class that should handle all weapons loading,etc...but how can i access scnene manager from these classess?i tried many things,but i think that i should rewrite all from the scratch so what is the best way to do this.
please reply thanx.
i have now the class in which all the models are loaded and rendered,but things got to complicated,i have many models and textures and i thought that the best should be to write clasess that will handle similiar things.like player class,that should handle all player model loading,weapons class that should handle all weapons loading,etc...but how can i access scnene manager from these classess?i tried many things,but i think that i should rewrite all from the scratch so what is the best way to do this.
please reply thanx.
ich bin ein berliner
pass it to object as constructor argument:
Code: Select all
class Example
{
irr::scene::IAnimatedMesh *mesh;
irr::scene::IAnimatedMeshSceneNode *node;
public:
Example(irr::IrrlichtDevice *device, const irr::c8 *filename)
{
mesh=device->getSceneManager()->getMesh(filename);
node=evice->getSceneManager()->addAnimatedMeshSceneNode(mesh);
}
~Example() {}
};
check this out
http://home.earthlink.net/~huston2/dp/patterns.html
and many more on google "C++ design pattern"
http://home.earthlink.net/~huston2/dp/patterns.html
and many more on google "C++ design pattern"
-
- Posts: 63
- Joined: Thu Aug 05, 2004 9:40 am
- Location: Germany
http://irrlicht.sourceforge.net/phpBB2/ ... php?t=3423
Hi,
I use this base class:
Has someone tried another approach?Code: Select all
class Constants { public: Constants(irr::IrrlichtDevice* Device) : device(Device) { drvr = device->getVideoDriver(); smgr = device->getSceneManager(); }; irr::IrrlichtDevice* device; irr::video::IVideoDriver* drvr; irr::scene::ISceneManager* smgr; };
-
- Posts: 602
- Joined: Sat Aug 23, 2003 2:03 am
- Location: Pottstown, PA
- Contact:
-
- Posts: 237
- Joined: Thu May 27, 2004 3:18 pm
- Location: Canada
As to why globals are bad...
Well, for one, they are global. This runs into a whole potential slew of redefinition errors, etc...
No gaurantee of state. Its hard to gaurantee when a global is initialized, so either you have potentially uninit'ed variables, or you have to put a ton of "just in case" tests to see if its properly set, or you have potentially volitile code.
As above, with a global variable, it could also be deleted or corupted at any point in your code, which for one makes debugging hell.
Hard to tell, or properly control when, or if, memory is released.
Global makes for name collision issues, as the global variable namespace will be available at every scope. Using a unique identifier such as g_myVar is a fairly effective work around.
In almost every case, a singleton is a better method to use then a global. Really all a singleton is, is a global object wrapper around an instance variable. The largest benefits are 1) you are gauranteed that the object varaible has been initialized 2) memory isnt allocated until first use 3) slightly more namespace friendly.
The biggest downside, is the minor overhead to the call... which can be minimalized to a large extent in most cases. If however, the varaible is going to be called a number of times in a fairly tight loop, you are better of creating a local reference and using it.
Cheers.
Well, for one, they are global. This runs into a whole potential slew of redefinition errors, etc...
No gaurantee of state. Its hard to gaurantee when a global is initialized, so either you have potentially uninit'ed variables, or you have to put a ton of "just in case" tests to see if its properly set, or you have potentially volitile code.
As above, with a global variable, it could also be deleted or corupted at any point in your code, which for one makes debugging hell.
Hard to tell, or properly control when, or if, memory is released.
Global makes for name collision issues, as the global variable namespace will be available at every scope. Using a unique identifier such as g_myVar is a fairly effective work around.
In almost every case, a singleton is a better method to use then a global. Really all a singleton is, is a global object wrapper around an instance variable. The largest benefits are 1) you are gauranteed that the object varaible has been initialized 2) memory isnt allocated until first use 3) slightly more namespace friendly.
The biggest downside, is the minor overhead to the call... which can be minimalized to a large extent in most cases. If however, the varaible is going to be called a number of times in a fairly tight loop, you are better of creating a local reference and using it.
Cheers.