Use array list for scene nodes

This commit is contained in:
Benau 2022-04-26 10:55:24 +08:00
parent 98763a10eb
commit fddc19225c
10 changed files with 75 additions and 116 deletions

View File

@ -24,8 +24,6 @@ namespace scene
{ {
class ISceneManager; class ISceneManager;
//! Typedef for list of scene nodes
typedef core::list<ISceneNode*> ISceneNodeList;
//! Typedef for list of scene node animators //! Typedef for list of scene node animators
typedef core::list<ISceneNodeAnimator*> ISceneNodeAnimatorList; typedef core::list<ISceneNodeAnimator*> ISceneNodeAnimatorList;
@ -92,9 +90,8 @@ namespace scene
{ {
if (IsVisible) if (IsVisible)
{ {
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it) Children[i]->OnRegisterSceneNode();
(*it)->OnRegisterSceneNode();
} }
} }
@ -127,9 +124,8 @@ namespace scene
// perform the post render process on all children // perform the post render process on all children
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it) Children[i]->OnAnimate(timeMs);
(*it)->OnAnimate(timeMs);
} }
} }
@ -142,9 +138,8 @@ namespace scene
// perform the post render process on all children // perform the post render process on all children
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it) Children[i]->recursiveUpdateAbsolutePosition();
(*it)->recursiveUpdateAbsolutePosition();
} }
} }
@ -314,16 +309,16 @@ namespace scene
e.g. because it couldn't be found in the children list. */ e.g. because it couldn't be found in the children list. */
virtual bool removeChild(ISceneNode* child) virtual bool removeChild(ISceneNode* child)
{ {
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it)
if ((*it) == child)
{ {
(*it)->Parent = 0; if (Children[i] == child)
(*it)->drop(); {
Children.erase(it); child->Parent = 0;
child->drop();
Children.erase(i);
return true; return true;
} }
}
_IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX; _IRR_IMPLEMENT_MANAGED_MARSHALLING_BUGFIX;
return false; return false;
} }
@ -335,13 +330,11 @@ namespace scene
*/ */
virtual void removeAll() virtual void removeAll()
{ {
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it)
{ {
(*it)->Parent = 0; Children[i]->Parent = 0;
(*it)->drop(); Children[i]->drop();
} }
Children.clear(); Children.clear();
} }
@ -598,14 +591,14 @@ namespace scene
//! Returns a const reference to the list of all children. //! Returns a const reference to the list of all children.
/** \return The list of all children of this node. */ /** \return The list of all children of this node. */
const core::list<ISceneNode*>& getChildren() const const core::array<ISceneNode*>& getChildren() const
{ {
return Children; return Children;
} }
//! Returns a list of all children (non-const version). //! Returns a list of all children (non-const version).
/** \return The list of all children of this node. */ /** \return The list of all children of this node. */
core::list<ISceneNode*>& getChildren() core::array<ISceneNode*>& getChildren()
{ {
return Children; return Children;
} }
@ -794,10 +787,8 @@ namespace scene
// clone children // clone children
ISceneNodeList::Iterator it = toCopyFrom->Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != toCopyFrom->Children.end(); ++it) Children[i]->clone(this, newManager);
(*it)->clone(this, newManager);
// clone animators // clone animators
ISceneNodeAnimatorList::Iterator ait = toCopyFrom->Animators.begin(); ISceneNodeAnimatorList::Iterator ait = toCopyFrom->Animators.begin();
@ -818,9 +809,9 @@ namespace scene
{ {
SceneManager = newManager; SceneManager = newManager;
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it) Children[i]->setSceneManager(newManager);
(*it)->setSceneManager(newManager);
} }
//! Name of the scene node. //! Name of the scene node.
@ -842,7 +833,7 @@ namespace scene
ISceneNode* Parent; ISceneNode* Parent;
//! List of all children of this node //! List of all children of this node
core::list<ISceneNode*> Children; core::array<ISceneNode*> Children;
//! List of all animator nodes //! List of all animator nodes
core::list<ISceneNodeAnimator*> Animators; core::list<ISceneNodeAnimator*> Animators;

View File

@ -77,9 +77,8 @@ void CBoneSceneNode::OnAnimate(u32 timeMs)
//updateAbsolutePosition(); //updateAbsolutePosition();
// perform the post render process on all children // perform the post render process on all children
ISceneNodeList::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
for (; it != Children.end(); ++it) Children[i]->OnAnimate(timeMs);
(*it)->OnAnimate(timeMs);
} }
} }
@ -88,10 +87,9 @@ void CBoneSceneNode::helper_updateAbsolutePositionOfAllChildren(ISceneNode *Node
{ {
Node->updateAbsolutePosition(); Node->updateAbsolutePosition();
ISceneNodeList::ConstIterator it = Node->getChildren().begin(); for (unsigned i = 0; i < Node->getChildren().size(); ++i)
for (; it != Node->getChildren().end(); ++it)
{ {
helper_updateAbsolutePositionOfAllChildren( (*it) ); helper_updateAbsolutePositionOfAllChildren( Node->getChildren()[i] );
} }
} }

View File

@ -74,13 +74,11 @@ void CSceneCollisionManager::getPickedNodeBB(ISceneNode* root,
core::line3df& ray, s32 bits, bool noDebugObjects, core::line3df& ray, s32 bits, bool noDebugObjects,
f32& outbestdistance, ISceneNode*& outbestnode) f32& outbestdistance, ISceneNode*& outbestnode)
{ {
const ISceneNodeList& children = root->getChildren();
const core::vector3df rayVector = ray.getVector().normalize(); const core::vector3df rayVector = ray.getVector().normalize();
ISceneNodeList::ConstIterator it = children.begin(); for (unsigned i = 0; i != root->getChildren().size(); ++i)
for (; it != children.end(); ++it)
{ {
ISceneNode* current = *it; ISceneNode* current = root->getChildren()[i];
if (current->isVisible()) if (current->isVisible())
{ {
@ -275,12 +273,9 @@ void CSceneCollisionManager::getPickedNodeFromBBAndSelector(
core::vector3df & outBestCollisionPoint, core::vector3df & outBestCollisionPoint,
core::triangle3df & outBestTriangle) core::triangle3df & outBestTriangle)
{ {
const ISceneNodeList& children = root->getChildren(); for (unsigned i = 0; i != root->getChildren().size(); ++i)
ISceneNodeList::ConstIterator it = children.begin();
for (; it != children.end(); ++it)
{ {
ISceneNode* current = *it; ISceneNode* current = root->getChildren()[i];
ITriangleSelector * selector = current->getTriangleSelector(); ITriangleSelector * selector = current->getTriangleSelector();
if (selector && current->isVisible() && if (selector && current->isVisible() &&

View File

@ -1668,11 +1668,9 @@ ISceneNode* CSceneManager::getSceneNodeFromName(const char* name, ISceneNode* st
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); for (unsigned i = 0; i < start->getChildren().size(); ++i)
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromName(name, *it); node = getSceneNodeFromName(name, start->getChildren()[i]);
if (node) if (node)
return node; return node;
} }
@ -1692,11 +1690,9 @@ ISceneNode* CSceneManager::getSceneNodeFromId(s32 id, ISceneNode* start)
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); for (unsigned i = 0; i < start->getChildren().size(); ++i)
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromId(id, *it); node = getSceneNodeFromId(id, start->getChildren()[i]);
if (node) if (node)
return node; return node;
} }
@ -1716,11 +1712,9 @@ ISceneNode* CSceneManager::getSceneNodeFromType(scene::ESCENE_NODE_TYPE type, IS
ISceneNode* node = 0; ISceneNode* node = 0;
const ISceneNodeList& list = start->getChildren(); for (unsigned i = 0; i < start->getChildren().size(); ++i)
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{ {
node = getSceneNodeFromType(type, *it); node = getSceneNodeFromType(type, start->getChildren()[i]);
if (node) if (node)
return node; return node;
} }
@ -1738,12 +1732,9 @@ void CSceneManager::getSceneNodesFromType(ESCENE_NODE_TYPE type, core::array<sce
if (start->getType() == type || ESNT_ANY == type) if (start->getType() == type || ESNT_ANY == type)
outNodes.push_back(start); outNodes.push_back(start);
const ISceneNodeList& list = start->getChildren(); for (unsigned i = 0; i < start->getChildren().size(); ++i)
ISceneNodeList::ConstIterator it = list.begin();
for (; it!=list.end(); ++it)
{ {
getSceneNodesFromType(type, outNodes, *it); getSceneNodesFromType(type, outNodes, start->getChildren()[i]);
} }
} }
@ -2101,9 +2092,8 @@ void CSceneManager::writeSceneNode(io::IXMLWriter* writer, ISceneNode* node, ISc
} }
else else
{ {
ISceneNodeList::ConstIterator it = node->getChildren().begin(); for (unsigned i = 0; i < node->getChildren().size(); ++i)
for (; it != node->getChildren().end(); ++it) writeSceneNode(writer, node->getChildren()[i], userDataSerializer, currentPath);
writeSceneNode(writer, (*it), userDataSerializer, currentPath);
} }
attr->drop(); attr->drop();

View File

@ -136,49 +136,48 @@ void DrawCalls::renderBoundingBoxes()
} // renderBoundingBoxes } // renderBoundingBoxes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
void DrawCalls::parseSceneManager(core::list<scene::ISceneNode*> &List, void DrawCalls::parseSceneManager(core::array<scene::ISceneNode*> &List,
const scene::ICameraSceneNode *cam) const scene::ICameraSceneNode *cam)
{ {
core::list<scene::ISceneNode*>::Iterator I = List.begin(), E = List.end(); for (unsigned i = 0; i < List.size(); ++i)
for (; I != E; ++I)
{ {
if (LODNode *node = dynamic_cast<LODNode *>(*I)) if (LODNode *node = dynamic_cast<LODNode *>(List[i]))
{ {
node->updateVisibility(); node->updateVisibility();
} }
(*I)->updateAbsolutePosition(); List[i]->updateAbsolutePosition();
if (!(*I)->isVisible()) if (!List[i]->isVisible())
continue; continue;
if (STKParticle *node = dynamic_cast<STKParticle*>(*I)) if (STKParticle *node = dynamic_cast<STKParticle*>(List[i]))
{ {
if (!isCulledPrecise(cam, *I, irr_driver->getBoundingBoxesViz())) if (!isCulledPrecise(cam, List[i], irr_driver->getBoundingBoxesViz()))
CPUParticleManager::getInstance()->addParticleNode(node); CPUParticleManager::getInstance()->addParticleNode(node);
continue; continue;
} }
if (scene::IBillboardSceneNode *node = if (scene::IBillboardSceneNode *node =
dynamic_cast<scene::IBillboardSceneNode*>(*I)) dynamic_cast<scene::IBillboardSceneNode*>(List[i]))
{ {
if (!isCulledPrecise(cam, *I)) if (!isCulledPrecise(cam, List[i]))
CPUParticleManager::getInstance()->addBillboardNode(node); CPUParticleManager::getInstance()->addBillboardNode(node);
continue; continue;
} }
if (STKTextBillboard *tb = if (STKTextBillboard *tb =
dynamic_cast<STKTextBillboard*>(*I)) dynamic_cast<STKTextBillboard*>(List[i]))
{ {
if (!isCulledPrecise(cam, *I, irr_driver->getBoundingBoxesViz())) if (!isCulledPrecise(cam, List[i], irr_driver->getBoundingBoxesViz()))
TextBillboardDrawer::addTextBillboard(tb); TextBillboardDrawer::addTextBillboard(tb);
continue; continue;
} }
SP::SPMeshNode* node = dynamic_cast<SP::SPMeshNode*>(*I); SP::SPMeshNode* node = dynamic_cast<SP::SPMeshNode*>(List[i]);
if (node) if (node)
{ {
SP::addObject(node); SP::addObject(node);
} }
parseSceneManager((*I)->getChildren(), cam); parseSceneManager(List[i]->getChildren(), cam);
} }
} }

View File

@ -33,7 +33,7 @@ private:
GLsync m_sync; GLsync m_sync;
std::vector<float> m_bounding_boxes; std::vector<float> m_bounding_boxes;
void parseSceneManager(core::list<scene::ISceneNode*> &List, void parseSceneManager(core::array<scene::ISceneNode*> &List,
const scene::ICameraSceneNode *cam); const scene::ICameraSceneNode *cam);
bool isCulledPrecise(const scene::ICameraSceneNode *cam, bool isCulledPrecise(const scene::ICameraSceneNode *cam,

View File

@ -129,15 +129,14 @@ void LODNode::OnAnimate(u32 timeMs)
Box = m_nodes[m_detail.size()-1]->getBoundingBox(); Box = m_nodes[m_detail.size()-1]->getBoundingBox();
// If this node has children other than the LOD nodes, animate it // If this node has children other than the LOD nodes, animate it
core::list<ISceneNode*>::Iterator it; for (unsigned i = 0; i < Children.size(); ++i)
for (it = Children.begin(); it != Children.end(); it++)
{ {
if (m_nodes_set.find(*it) == m_nodes_set.end()) if (m_nodes_set.find(Children[i]) == m_nodes_set.end())
{ {
assert(*it != NULL); assert(Children[i] != NULL);
if ((*it)->isVisible()) if (Children[i]->isVisible())
{ {
(*it)->OnAnimate(timeMs); Children[i]->OnAnimate(timeMs);
} }
} }
} }
@ -178,11 +177,8 @@ void LODNode::OnRegisterSceneNode()
#ifndef SERVER_ONLY #ifndef SERVER_ONLY
if (!CVS->isGLSL()) if (!CVS->isGLSL())
{ {
for (core::list<ISceneNode*>::Iterator it = Children.begin(); for (unsigned i = 0; i < Children.size(); ++i)
it != Children.end(); it++) Children[i]->updateAbsolutePosition();
{
(*it)->updateAbsolutePosition();
}
} }
#endif #endif
scene::ISceneNode::OnRegisterSceneNode(); scene::ISceneNode::OnRegisterSceneNode();

View File

@ -453,14 +453,13 @@ void STKTextBillboard::reload()
} // reload } // reload
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
static void updateTextBillboard(core::list<scene::ISceneNode*>& List) static void updateTextBillboard(core::array<scene::ISceneNode*>& List)
{ {
core::list<scene::ISceneNode*>::Iterator I = List.begin(), E = List.end(); for (unsigned i = 0; i < List.size(); i++)
for (; I != E; ++I)
{ {
if (STKTextBillboard* tb = dynamic_cast<STKTextBillboard*>(*I)) if (STKTextBillboard* tb = dynamic_cast<STKTextBillboard*>(List[i]))
tb->reload(); tb->reload();
updateTextBillboard((*I)->getChildren()); updateTextBillboard(List[i]->getChildren());
} }
} // updateTextBillboard } // updateTextBillboard

View File

@ -124,11 +124,9 @@ void ThreeStrikesBattle::reset(bool restart)
scene::ISceneNode* kart_node = m_karts[n]->getNode(); scene::ISceneNode* kart_node = m_karts[n]->getNode();
core::list<scene::ISceneNode*>& children = kart_node->getChildren(); for (unsigned i = 0; i < kart_node->getChildren().size(); i++)
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{ {
scene::ISceneNode* curr = *it; scene::ISceneNode* curr = kart_node->getChildren()[i];
if (core::stringc(curr->getName()) == "tire1") if (core::stringc(curr->getName()) == "tire1")
{ {
@ -302,11 +300,9 @@ bool ThreeStrikesBattle::kartHit(int kart_id, int hitter)
} }
scene::ISceneNode* kart_node = m_karts[kart_id]->getNode(); scene::ISceneNode* kart_node = m_karts[kart_id]->getNode();
core::list<scene::ISceneNode*>& children = kart_node->getChildren(); for (unsigned i = 0; i < kart_node->getChildren().size(); i++)
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{ {
scene::ISceneNode* curr = *it; scene::ISceneNode* curr = kart_node->getChildren()[i];
if (core::stringc(curr->getName()) == "tire1") if (core::stringc(curr->getName()) == "tire1")
{ {
@ -590,11 +586,9 @@ void ThreeStrikesBattle::addKartLife(unsigned int id)
updateKartRanks(); updateKartRanks();
scene::ISceneNode* kart_node = m_karts[id]->getNode(); scene::ISceneNode* kart_node = m_karts[id]->getNode();
core::list<scene::ISceneNode*>& children = kart_node->getChildren(); for (unsigned i = 0; i < kart_node->getChildren().size(); i++)
for (core::list<scene::ISceneNode*>::Iterator it = children.begin();
it != children.end(); it++)
{ {
scene::ISceneNode* curr = *it; scene::ISceneNode* curr = kart_node->getChildren()[i];
if (core::stringc(curr->getName()) == "tire1") if (core::stringc(curr->getName()) == "tire1")
{ {
curr->setVisible(m_kart_info[id].m_lives >= 3); curr->setVisible(m_kart_info[id].m_lives >= 3);

View File

@ -1747,11 +1747,8 @@ static void recursiveUpdatePosition(scene::ISceneNode *node)
{ {
node->updateAbsolutePosition(); node->updateAbsolutePosition();
scene::ISceneNodeList::ConstIterator it = node->getChildren().begin(); for (unsigned i = 0; i < node->getChildren().size(); i++)
for (; it != node->getChildren().end(); ++it) recursiveUpdatePosition(node->getChildren()[i]);
{
recursiveUpdatePosition(*it);
}
} // recursiveUpdatePosition } // recursiveUpdatePosition
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------