From: <cn...@us...> - 2009-11-13 07:40:22
|
Revision: 614 http://hgengine.svn.sourceforge.net/hgengine/?rev=614&view=rev Author: cnlohr Date: 2009-11-13 07:40:16 +0000 (Fri, 13 Nov 2009) Log Message: ----------- virtualize addition/removal of children, and add macro for helping out load from XML. Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-11-13 07:38:19 UTC (rev 613) +++ Mercury2/src/MercuryNode.cpp 2009-11-13 07:40:16 UTC (rev 614) @@ -275,11 +275,11 @@ { SetName( node.Attribute("name") ); - if ( !node.Attribute("hidden").empty() ) - m_hidden = StrToBool( node.Attribute("hidden") ); + LOAD_FROM_XML( "hidden", m_hidden, StrToBool ); + LOAD_FROM_XML( "alphaPath", m_useAlphaPath, StrToBool ); + LOAD_FROM_XML( "enableSave", m_bEnableSave, StrToBool ); + LOAD_FROM_XML( "enableSaveChildren", m_bEnableSaveChildren, StrToBool ); - if ( !node.Attribute("alphaPath").empty() ) - m_useAlphaPath = StrToBool( node.Attribute("alphaPath") ); //Not much to do here except run through all the children nodes for (XMLNode child = node.Child(); child.IsValid(); child = child.NextNode()) Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-11-13 07:38:19 UTC (rev 613) +++ Mercury2/src/MercuryNode.h 2009-11-13 07:40:16 UTC (rev 614) @@ -17,14 +17,7 @@ Each node exists as a single entity in the scene graph. **/ -/* -#define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \ -{ const MercuryNode* tn = n; \ -while(tn) { if (typeid(x) == typeid(*tn)) return true; tn = *n; } \ -return false;} -*/ - #define STANDARD_PASS 7 ///Which passes, by default, should be run on all nodes. #define DEFAULT_PASSES ( (1<<STANDARD_PASS) ) @@ -41,8 +34,8 @@ MercuryNode(); virtual ~MercuryNode(); - void AddChild(MercuryNode* n); - void RemoveChild(MercuryNode* n); + virtual void AddChild(MercuryNode* n); + virtual void RemoveChild(MercuryNode* n); inline MercuryNode* Parent() const { return m_parent; } inline MercuryNode* NextSibling() const { return m_nextSibling; } @@ -128,6 +121,8 @@ const MercuryMatrix & GetModelViewMatrix() const { return m_pModelViewMatrix[g_iViewportID]; } inline unsigned short GetPasses() const { return m_iPasses; } + + virtual void SetHidden( bool bHide ) { m_hidden = bHide; } protected: std::list< MercuryNode* > m_children; //These nodes are unique, not instanced MercuryNode* m_parent; @@ -182,6 +177,8 @@ static InstanceCounter<NodeFactory> NFcounter("NodeFactory"); + +///Register a new instance of the node with the main Mercury Node Registration System. #define REGISTER_NODE_TYPE(class)\ MercuryNode* FactoryFunct##class() { return new class(); } \ Callback0R<MercuryNode*> factoryclbk##class( FactoryFunct##class ); \ @@ -195,6 +192,17 @@ } } +///Load a variable from XML (safely) - this loads a variable of type name into variable using the transform function. +#define LOAD_FROM_XML( name, variable, function ) \ + if ( !node.Attribute( name ).empty() ) \ + variable = function ( node.Attribute(name) ); + +///Call callee if attribute name exists in XML - attribute can be transformed using function +#define LOAD_FROM_XML_CALL( name, callee, function ) \ + if ( !node.Attribute( name ).empty() ) \ + callee( function ( node.Attribute(name) ) ); + + #endif /**************************************************************************** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |