©2004,2009 Jim E. Brooks http://www.palomino3d.org
[2007/12]
Source code is written in C++. For portability, the code is written to abstract the graphics system and scene graph. Generalized C++ classes and Facade classes are used. For example, the Graph class is a Facade over an osg::Switch node.
The source code is designed to be modular and layered. Layers (in the form of Facade and Mediator C++ classes) keep the top-level of the program from becoming too dependent on drivers, graphics API, scene graph library, etc.
To catch memory corruption or uninitialized data, critical classes have a "type signature" data member which is checked in DEBUG builds.
[2004,2008/04]
Naming convention:
typedef TYPE value_type;
declared by wrapper classes over fundamental types (OSG convention).
// Alternative using a single global: namespace module { namespace global { World gWorld; } // namespace global } // namespace module
// Alternative using a struct of globals: namespace module { struct Globals { Window mWindow; Gui mGui; }; Globals gGlobals; } // namespace module
[2008/06]
See scripts/module.txt.
[2009/10]
Singletons are preferred (despite being slightly slower and cumbersome to write). A limited amount of globals are used for very-frequently-accessed globals or some singletons themselves need to access a global that is plain data.
Singletons have two problems:
When multiple globals are really necessary and one global depends on another, an option is a global C++ struct. C++ defines the order of construction of members in the order they are declared (don't confuse with the order of initialization list). C++ will automatically destroy them in the reverse order at program exit.
#define GET_WINDOW() (module::gGlobals.mWindow) // behaves as a singleton so named accordingly #define GET_GUI() (module::gGlobals.mGui) namespace module { struct Globals { Window mWindow; // no dependencies Gui mGui; // depends on mWindow (ok) }; #if PROGRAM_MODULE_CC Globals globals; #else extern Globals globals; #endif } // namespace module
[2004,2009/05]
std::
prefix.C++ math functions are overloaded to the appropriate type. Eg, sin(f) needlessly promotes to a double, but std::sin(f) is automatically chooses the equivalent of C sinf(f).
namespace global (singular)
class Globals (plural)
SafePtr prevents deleting the pointed-to object.
class Object { Shape* GetShape( void ); SafePtr<Shape> GetShape( void ); };
Object A passes a pointer to its member to object B. But A could be destroyed before B uses the pointer. Or B could delete the passed object, then A tries to use it. SharedPtr can prevent these problems.
Last modified: Wed Feb 3 18:24:24 CST 2010