|
From: <axl...@us...> - 2009-04-01 01:23:03
|
Revision: 191
http://hgengine.svn.sourceforge.net/hgengine/?rev=191&view=rev
Author: axlecrusher
Date: 2009-04-01 01:22:53 +0000 (Wed, 01 Apr 2009)
Log Message:
-----------
keep pointers to siblings and use them for finding children
Modified Paths:
--------------
Mercury2/src/MercuryNode.cpp
Mercury2/src/MercuryNode.h
Modified: Mercury2/src/MercuryNode.cpp
===================================================================
--- Mercury2/src/MercuryNode.cpp 2009-03-28 13:22:39 UTC (rev 190)
+++ Mercury2/src/MercuryNode.cpp 2009-04-01 01:22:53 UTC (rev 191)
@@ -7,7 +7,7 @@
REGISTER_NODE_TYPE(MercuryNode);
MercuryNode::MercuryNode()
- :m_parent(NULL)
+ :m_parent(NULL), m_prevSibling(NULL), m_nextSibling(NULL)
{
}
@@ -24,11 +24,23 @@
void MercuryNode::AddChild(MercuryNode* n)
{
+// list< MercuryNode* >::iterator last = m_children.end();
+
+ n->m_prevSibling = NULL;
+ n->m_nextSibling = NULL;
+ if (m_children.end() != m_children.begin())
+ {
+ MercuryNode* last = m_children.back();
+ last->m_nextSibling = n;
+ n->m_prevSibling = last;
+ }
+
m_children.push_back(n);
n->m_parent = this;
OnAddChild();
n->OnAdded();
+ m_rebuildRenderGraph = true;
}
void MercuryNode::RemoveChild(MercuryNode* n)
@@ -38,48 +50,46 @@
{
if (*i == n)
{
+ MercuryNode* next = n->m_nextSibling;
+ MercuryNode* prev = n->m_prevSibling;
+
n->OnRemoved();
OnRemoveChild();
+
+ if (prev) prev->m_nextSibling = next;
+ if (next) next->m_prevSibling = prev;
+
+ n->m_nextSibling = NULL;
+ n->m_prevSibling = NULL;
n->m_parent = NULL;
+
m_children.erase(i);
+ m_rebuildRenderGraph = true;
+
return;
}
}
}
-MercuryNode* MercuryNode::Parent() const
+MercuryNode* MercuryNode::FirstChild() const
{
- return m_parent;
-}
-
-MercuryNode* MercuryNode::NextSibling() const
-{
- if (m_parent) return m_parent->NextChild(this);
+ if (m_children.begin() != m_children.end())
+ return *(m_children.begin());
return NULL;
}
-MercuryNode* MercuryNode::PrevSibling() const
+MercuryNode* MercuryNode::NextChild(const MercuryNode* child) const
{
- if (m_parent) return m_parent->PrevChild(this);
- return NULL;
+ if (child==NULL) return NULL;
+ return child->NextSibling();
}
-MercuryNode* MercuryNode::NextChild(const MercuryNode* n) const
+MercuryNode* MercuryNode::PrevChild(const MercuryNode* child) const
{
- list< MercuryNode* >::const_iterator i;
- for (i = m_children.begin(); i != m_children.end(); ++i )
- if (*i == n) return *i;
- return NULL;
+ if (child==NULL) return NULL;
+ return child->PrevSibling();
}
-MercuryNode* MercuryNode::PrevChild(const MercuryNode* n) const
-{
- list< MercuryNode* >::const_iterator i;
- for (i = m_children.end(); i != m_children.begin(); --i )
- if (*i == n) return *i;
- return NULL;
-}
-
void MercuryNode::RecursiveUpdate(float dTime)
{
Update(dTime);
@@ -140,6 +150,7 @@
return NULL;
}
+bool MercuryNode::m_rebuildRenderGraph = false;
/***************************************************************************
* Copyright (C) 2008 by Joshua Allen *
* *
Modified: Mercury2/src/MercuryNode.h
===================================================================
--- Mercury2/src/MercuryNode.h 2009-03-28 13:22:39 UTC (rev 190)
+++ Mercury2/src/MercuryNode.h 2009-04-01 01:22:53 UTC (rev 191)
@@ -13,9 +13,9 @@
**/
#define GENRTTI(x) static const x* Cast(const MercuryNode* n) \
-{ return dynamic_cast<const x*>(n); } \
+{ if (n==NULL) return NULL; return dynamic_cast<const x*>(n); } \
static x* Cast(MercuryNode* n) \
-{ return dynamic_cast<x*>(n); }
+{ if (n==NULL) return NULL; return dynamic_cast<x*>(n); }
/*
#define GENRTTI(x) static bool IsMyType(const MercuryNode* n) \
@@ -32,9 +32,10 @@
void AddChild(MercuryNode* n);
void RemoveChild(MercuryNode* n);
- MercuryNode* Parent() const;
- MercuryNode* NextSibling() const;
- MercuryNode* PrevSibling() const;
+ inline MercuryNode* Parent() const { return m_parent; }
+ inline MercuryNode* NextSibling() const { return m_nextSibling; }
+ inline MercuryNode* PrevSibling() const { return m_prevSibling; }
+ MercuryNode* FirstChild() const;
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; }
@@ -63,6 +64,11 @@
protected:
std::list< MercuryNode* > m_children; //These nodes are unique, not instanced
MercuryNode* m_parent;
+ MercuryNode* m_prevSibling;
+ MercuryNode* m_nextSibling;
+
+ static bool m_rebuildRenderGraph;
+
};
class NodeFactory
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|