|
From: <cn...@us...> - 2009-07-04 06:23:29
|
Revision: 398
http://hgengine.svn.sourceforge.net/hgengine/?rev=398&view=rev
Author: cnlohr
Date: 2009-07-04 06:23:28 +0000 (Sat, 04 Jul 2009)
Log Message:
-----------
add FindNode() (to find children by name
Modified Paths:
--------------
Mercury2/src/MercuryMath.h
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryMath.h
===================================================================
--- Mercury2/src/MercuryMath.h 2009-07-03 04:53:25 UTC (rev 397)
+++ Mercury2/src/MercuryMath.h 2009-07-04 06:23:28 UTC (rev 398)
@@ -15,6 +15,8 @@
#define INFINITY (std::numeric_limits<float>::infinity())
#endif
+#define MAXINT (0x7FFFFFFF)
+
void ZeroFloatRow(FloatRow& r);
#define DEGRAD 0.01745329251994329576f //degree to radian
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-07-03 04:53:25 UTC (rev 397)
+++ Mercury2/src/MercuryNode.cpp 2009-07-04 06:23:28 UTC (rev 398)
@@ -97,6 +97,30 @@
return child->PrevSibling();
}
+MercuryNode* MercuryNode::FindChild( const MString & sNameOfNode, int depth )
+{
+ if( depth >= 0 )
+ {
+ for( std::list< MercuryNode* >::iterator i = m_children.begin(); i != m_children.end(); i++ )
+ {
+ if( (*i)->GetName().compare( sNameOfNode ) == 0 )
+ return (*i);
+ }
+
+ for( std::list< MercuryNode* >::iterator i = m_children.begin(); i != m_children.end(); i++ )
+ {
+ MercuryNode * ret;
+ if( ( ret = (*i)->FindChild( sNameOfNode, depth - 1 ) ) )
+ {
+ if( (*i)->GetName().compare( sNameOfNode ) == 0 )
+ return ret;
+ }
+ }
+ }
+ return NULL;
+}
+
+
void MercuryNode::RecursiveUpdate(float dTime)
{
Update(dTime);
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-07-03 04:53:25 UTC (rev 397)
+++ Mercury2/src/MercuryNode.h 2009-07-04 06:23:28 UTC (rev 398)
@@ -42,7 +42,11 @@
MercuryNode* NextChild(const MercuryNode* n) const; ///Finds the next child in regards to n
MercuryNode* PrevChild(const MercuryNode* n) const; ///Finds the previous child in regards to n
const std::list< MercuryNode* >& Children() const { return m_children; }
-
+
+ ///Find a child node that has the name matching sNameOfNode.
+ /** The search order is breadth-first, however this may change without notice! */
+ MercuryNode* FindChild( 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.
|