From: <cn...@us...> - 2009-07-16 05:05:15
|
Revision: 429 http://hgengine.svn.sourceforge.net/hgengine/?rev=429&view=rev Author: cnlohr Date: 2009-07-16 05:05:11 +0000 (Thu, 16 Jul 2009) Log Message: ----------- add ability for nodes to find a parent by name Modified Paths: -------------- Mercury2/src/MercuryNode.cpp Mercury2/src/MercuryNode.h Modified: Mercury2/src/MercuryNode.cpp =================================================================== --- Mercury2/src/MercuryNode.cpp 2009-07-15 14:33:24 UTC (rev 428) +++ Mercury2/src/MercuryNode.cpp 2009-07-16 05:05:11 UTC (rev 429) @@ -120,7 +120,15 @@ return NULL; } +MercuryNode* MercuryNode::FindParent( const MString & sNameOfNode, int depth ) +{ + MercuryNode * ret = this; + while( ret && ret->GetName() != sNameOfNode ) + ret = ret->Parent(); + return ret; +} + void MercuryNode::RecursiveUpdate(float dTime) { Update(dTime); Modified: Mercury2/src/MercuryNode.h =================================================================== --- Mercury2/src/MercuryNode.h 2009-07-15 14:33:24 UTC (rev 428) +++ Mercury2/src/MercuryNode.h 2009-07-16 05:05:11 UTC (rev 429) @@ -48,6 +48,10 @@ /** The search order is breadth-first, however this may change without notice! */ MercuryNode* FindChild( const MString & sNameOfNode, int depth = MAXINT ); + ///Find a parent node that has the name matching sNameOfNode. + /** Traversal is from the closest parent on upward */ + MercuryNode* FindParent( const MString & sNameOfNode, int depth = MAXINT ); + virtual void Update(float dTime) {}; virtual void RecursiveUpdate(float dTime); void ThreadedUpdate(float dTime); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |