From: <axl...@us...> - 2010-04-27 00:16:12
|
Revision: 702 http://hgengine.svn.sourceforge.net/hgengine/?rev=702&view=rev Author: axlecrusher Date: 2010-04-27 00:16:04 +0000 (Tue, 27 Apr 2010) Log Message: ----------- Convert boolean variables into bitwise flags to cut down on memory use. Modified Paths: -------------- Mercury2/src/MercuryMath.h Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryMath.h =================================================================== --- Mercury2/src/MercuryMath.h 2010-04-26 02:41:10 UTC (rev 701) +++ Mercury2/src/MercuryMath.h 2010-04-27 00:16:04 UTC (rev 702) @@ -97,6 +97,10 @@ void TransposeMatrix( FloatRow* m ); void MMCrossProduct( const FloatRow& r1, const FloatRow& r2, FloatRow& result); +//http://graphics.stanford.edu/~seander/bithacks.html +#define SetBit(x,mask,t) ((x & ~mask) | (-t & mask)) /*superscalar CPU version*/ +#define GetBit(x,mask) (x & mask) + //void Float2FloatRow(const float* f, FloatRow& r); //void FloatRow2Float(const FloatRow& fr, float* f); Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2010-04-26 02:41:10 UTC (rev 701) +++ Mercury2/src/MercuryNode.cpp 2010-04-27 00:16:04 UTC (rev 702) @@ -17,9 +17,7 @@ MercuryNode::MercuryNode() :m_parent(NULL), m_prevSibling(NULL), - m_nextSibling(NULL), m_hidden(false), - m_useAlphaPath(false), m_culled(false), - m_bEnableSave(true), m_bEnableSaveChildren(true), + m_nextSibling(NULL), m_flags(SAVECHILDREN & ENABLESAVE), m_iPasses( DEFAULT_PASSES ), m_iForcePasses( 0 ) { m_pGlobalMatrix = &MercuryMatrix::Identity(); @@ -213,7 +211,7 @@ for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) { child->RecursivePreRender(); - m_culled = m_culled && child->IsCulled(); + SetCulled( IsCulled() && child->IsCulled() ); } } @@ -254,7 +252,7 @@ //call render on other render graph entries under me for (MercuryNode* child = FirstChild(); child != NULL; child = NextChild(child)) { - if ( child->m_useAlphaPath ) + if ( child->GetUseAlphaPass() ) CURRENTRENDERGRAPH->AddAlphaNode(child); else child->RecursiveRender(); @@ -284,10 +282,12 @@ { SetName( node.Attribute("name") ); - 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 ); + bool t; + t = IsHidden(); LOAD_FROM_XML( "hidden", t, StrToBool ); SetHidden(t); + t = GetUseAlphaPass(); LOAD_FROM_XML( "alphaPath", t, StrToBool ); SetUseAlphaPass(t); + t = GetEnableSave(); LOAD_FROM_XML( "enableSave", t, StrToBool ); SetEnableSave(t); + t = GetSaveChildren(); LOAD_FROM_XML( "enableSaveChildren", t, StrToBool ); + SetSaveChildren(t); //Not much to do here except run through all the children nodes @@ -324,7 +324,7 @@ void MercuryNode::SaveToXML( MString & sXMLStream, int depth ) { - if( !m_bEnableSave ) return; + if( !GetEnableSave() ) return; sXMLStream += ssprintf( "%*c<node ", depth * 3, 32 ); SaveBaseXMLTag( sXMLStream ); @@ -332,7 +332,7 @@ bool bNoChildren = true; - if( m_bEnableSaveChildren ) + if( GetSaveChildren() ) { if( !m_assets.empty() ) { @@ -350,7 +350,7 @@ //No children yet (but we have them, so terminate (>) ) for( std::list< MercuryNode * >::iterator i = m_children.begin(); i != m_children.end(); i++ ) { - if( (*i)->m_bEnableSave ) + if( (*i)->GetEnableSave() ) { if( bNoChildren ) sXMLStream += ">\n"; @@ -377,7 +377,7 @@ sXMLStream+= ssprintf( "type=\"%s\" ", GetType() ); if( GetName().length() ) sXMLStream += ssprintf( "name=\"%s\" ", GetName().c_str() ); - if( m_useAlphaPath ) + if( GetUseAlphaPass() ) sXMLStream += "alphaPath=\"true\" "; } Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2010-04-26 02:41:10 UTC (rev 701) +++ Mercury2/src/MercuryNode.h 2010-04-27 00:16:04 UTC (rev 702) @@ -28,6 +28,15 @@ ///The Global Pass Number (which Pass is currently doing Render) extern __ThreadLocalStore int g_iPass; +enum MercuryNodeFlagMask +{ + HIDDEN = 1, + CULLED, + SAVECHILDREN, + ENABLESAVE, + ALPHAPATH +}; + class MercuryNode : public MessageHandler { public: @@ -114,10 +123,21 @@ virtual void Render(const MercuryMatrix& matrix); virtual void PostRender(const MercuryMatrix& matrix); - inline bool IsHidden() { return m_hidden; } + virtual void SetHidden( bool bHide ) { m_flags = SetBit(m_flags,HIDDEN,bHide); } //is there anyway to make this not virtual?? + inline bool IsHidden() { return GetBit(m_flags,HIDDEN); } - inline void SetCulled(bool t) { m_culled = t; } - inline bool IsCulled() const { return m_culled; } + inline void SetCulled(bool t) { m_flags = SetBit(m_flags,CULLED,t); } + inline bool IsCulled() const { return GetBit(m_flags,CULLED); } + + inline void SetSaveChildren(bool t) { m_flags = SetBit(m_flags,SAVECHILDREN,t); } + inline bool GetSaveChildren() const { return GetBit(m_flags,SAVECHILDREN); } + + inline void SetEnableSave(bool t) { m_flags = SetBit(m_flags,ENABLESAVE,t); } + inline bool GetEnableSave() const { return GetBit(m_flags,ENABLESAVE); } + + inline void SetUseAlphaPass(bool t) { m_flags = SetBit(m_flags,ALPHAPATH,t); } + inline bool GetUseAlphaPass() const { return GetBit(m_flags,ALPHAPATH); } + virtual MercuryMatrix ManipulateMatrix(const MercuryMatrix& matrix); const MercuryMatrix & GetGlobalMatrix() const { return m_pGlobalMatrix[g_iViewportID]; } @@ -125,7 +145,6 @@ 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; @@ -135,11 +154,7 @@ static bool m_rebuildRenderGraph; MString m_name; - bool m_hidden; - bool m_useAlphaPath; - bool m_culled; - bool m_bEnableSave; - bool m_bEnableSaveChildren; + unsigned char m_flags; bool IsInAssetList(MercuryAsset* asset) const; unsigned short m_iPasses; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |