Node.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #include "Precompiled.h"
  24. #include "Component.h"
  25. #include "Context.h"
  26. #include "Log.h"
  27. #include "Scene.h"
  28. #include "VectorBuffer.h"
  29. #include "XMLElement.h"
  30. #include "DebugNew.h"
  31. // Normalize rotation quaternion after this many incremental updates to prevent distortion
  32. static const int NORMALIZE_ROTATION_EVERY = 32;
  33. OBJECTTYPESTATIC(Node);
  34. Node::Node(Context* context) :
  35. Serializable(context),
  36. id_(0),
  37. parent_(0),
  38. scene_(0),
  39. owner_(0),
  40. position_(Vector3::ZERO),
  41. rotation_(Quaternion::IDENTITY),
  42. scale_(Vector3::UNITY),
  43. worldTransform_(Matrix4x3::IDENTITY),
  44. rotateCount_(0),
  45. dirty_(false)
  46. {
  47. }
  48. Node::~Node()
  49. {
  50. RemoveAllChildren();
  51. RemoveAllComponents();
  52. // Remove from the scene
  53. if (scene_)
  54. scene_->NodeRemoved(this);
  55. }
  56. void Node::RegisterObject(Context* context)
  57. {
  58. context->RegisterFactory<Node>();
  59. ATTRIBUTE(Node, VAR_STRING, "Name", name_, String());
  60. ATTRIBUTE(Node, VAR_VECTOR3, "Position", position_, Vector3::ZERO);
  61. ATTRIBUTE(Node, VAR_QUATERNION, "Rotation", rotation_, Quaternion::IDENTITY);
  62. ATTRIBUTE(Node, VAR_VECTOR3, "Scale", scale_, Vector3::UNITY);
  63. ATTRIBUTE_MODE(Node, VAR_VARIANTMAP, "Variables", vars_, VariantMap(), AM_SERIALIZATION);
  64. }
  65. void Node::OnEvent(Object* sender, bool broadcast, StringHash eventType, VariantMap& eventData)
  66. {
  67. // Make a weak pointer to self to check for destruction during event handling
  68. WeakPtr<Node> self(this);
  69. // If this is a targeted event, forward it to all components
  70. if (!broadcast)
  71. {
  72. for (unsigned i = components_.Size() - 1; i < components_.Size(); --i)
  73. {
  74. components_[i]->OnEvent(sender, broadcast, eventType, eventData);
  75. if (self.IsExpired())
  76. return;
  77. }
  78. }
  79. else
  80. Object::OnEvent(sender, broadcast, eventType, eventData);
  81. }
  82. void Node::OnSetAttribute(const AttributeInfo& attr, const Variant& value)
  83. {
  84. switch (attr.offset_)
  85. {
  86. case offsetof(Node, name_):
  87. SetName(value.GetString());
  88. break;
  89. case offsetof(Node, position_):
  90. case offsetof(Node, rotation_):
  91. case offsetof(Node, scale_):
  92. Serializable::OnSetAttribute(attr, value);
  93. // If transform changes, dirty the node as applicable
  94. if (!dirty_)
  95. MarkDirty();
  96. break;
  97. default:
  98. Serializable::OnSetAttribute(attr, value);
  99. break;
  100. }
  101. }
  102. bool Node::Load(Deserializer& source)
  103. {
  104. return Load(source, true);
  105. }
  106. bool Node::Save(Serializer& dest)
  107. {
  108. if (!Serializable::Save(dest))
  109. return false;
  110. dest.WriteVLE(components_.Size());
  111. for (unsigned i = 0; i < components_.Size(); ++i)
  112. {
  113. Component* component = components_[i];
  114. // Create a separate buffer to be able to skip unknown components during deserialization
  115. VectorBuffer compBuffer;
  116. compBuffer.WriteShortStringHash(component->GetType());
  117. compBuffer.WriteUInt(component->GetID());
  118. if (!component->Save(compBuffer))
  119. return false;
  120. dest.WriteVLE(compBuffer.GetSize());
  121. dest.Write(compBuffer.GetData(), compBuffer.GetSize());
  122. }
  123. dest.WriteVLE(children_.Size());
  124. for (unsigned i = 0; i < children_.Size(); ++i)
  125. {
  126. Node* node = children_[i];
  127. dest.WriteUInt(node->GetID());
  128. if (!node->Save(dest))
  129. return false;
  130. }
  131. return true;
  132. }
  133. bool Node::LoadXML(const XMLElement& source)
  134. {
  135. return LoadXML(source, true);
  136. }
  137. bool Node::SaveXML(XMLElement& dest)
  138. {
  139. if (!Serializable::SaveXML(dest))
  140. return false;
  141. for (unsigned i = 0; i < components_.Size(); ++i)
  142. {
  143. Component* component = components_[i];
  144. XMLElement compElem = dest.CreateChildElement("component");
  145. compElem.SetString("type", component->GetTypeName());
  146. compElem.SetInt("id", component->GetID());
  147. if (!component->SaveXML(compElem))
  148. return false;
  149. }
  150. for (unsigned i = 0; i < children_.Size(); ++i)
  151. {
  152. Node* node = children_[i];
  153. XMLElement childElem = dest.CreateChildElement("node");
  154. childElem.SetInt("id", node->GetID());
  155. if (!node->SaveXML(childElem))
  156. return false;
  157. }
  158. return true;
  159. }
  160. void Node::PostLoad()
  161. {
  162. for (unsigned i = 0; i < components_.Size(); ++i)
  163. components_[i]->PostLoad();
  164. for (unsigned i = 0; i < children_.Size(); ++i)
  165. children_[i]->PostLoad();
  166. }
  167. void Node::SetName(const String& name)
  168. {
  169. name_ = name;
  170. nameHash_ = StringHash(name);
  171. }
  172. void Node::SetPosition(const Vector3& position)
  173. {
  174. position_ = position;
  175. if (!dirty_)
  176. MarkDirty();
  177. }
  178. void Node::SetRotation(const Quaternion& rotation)
  179. {
  180. rotation_ = rotation;
  181. rotateCount_ = 0;
  182. if (!dirty_)
  183. MarkDirty();
  184. }
  185. void Node::SetDirection(const Vector3& direction)
  186. {
  187. SetRotation(Quaternion(Vector3::FORWARD, direction));
  188. }
  189. void Node::SetScale(float scale)
  190. {
  191. scale_ = Vector3(scale, scale, scale);
  192. if (!dirty_)
  193. MarkDirty();
  194. }
  195. void Node::SetScale(const Vector3& scale)
  196. {
  197. scale_ = scale;
  198. if (!dirty_)
  199. MarkDirty();
  200. }
  201. void Node::SetTransform(const Vector3& position, const Quaternion& rotation)
  202. {
  203. position_ = position;
  204. rotation_ = rotation;
  205. rotateCount_ = 0;
  206. if (!dirty_)
  207. MarkDirty();
  208. }
  209. void Node::SetTransform(const Vector3& position, const Quaternion& rotation, float scale)
  210. {
  211. position_ = position;
  212. rotation_ = rotation;
  213. scale_ = Vector3(scale, scale, scale);
  214. rotateCount_ = 0;
  215. if (!dirty_)
  216. MarkDirty();
  217. }
  218. void Node::SetTransform(const Vector3& position, const Quaternion& rotation, const Vector3& scale)
  219. {
  220. position_ = position;
  221. rotation_ = rotation;
  222. scale_ = scale;
  223. rotateCount_ = 0;
  224. if (!dirty_)
  225. MarkDirty();
  226. }
  227. void Node::Translate(const Vector3& delta)
  228. {
  229. position_ += delta;
  230. if (!dirty_)
  231. MarkDirty();
  232. }
  233. void Node::TranslateRelative(const Vector3& delta)
  234. {
  235. position_ += rotation_ * delta;
  236. if (!dirty_)
  237. MarkDirty();
  238. }
  239. void Node::Rotate(const Quaternion& delta, bool fixedAxis)
  240. {
  241. if (!fixedAxis)
  242. rotation_ = rotation_ * delta;
  243. else
  244. rotation_ = delta * rotation_;
  245. ++rotateCount_;
  246. if (rotateCount_ >= NORMALIZE_ROTATION_EVERY)
  247. {
  248. rotation_.Normalize();
  249. rotateCount_ = 0;
  250. }
  251. if (!dirty_)
  252. MarkDirty();
  253. }
  254. void Node::Yaw(float angle, bool fixedAxis)
  255. {
  256. Rotate(Quaternion(angle, Vector3::UP), fixedAxis);
  257. }
  258. void Node::Pitch(float angle, bool fixedAxis)
  259. {
  260. Rotate(Quaternion(angle, Vector3::RIGHT), fixedAxis);
  261. }
  262. void Node::Roll(float angle, bool fixedAxis)
  263. {
  264. Rotate(Quaternion(angle, Vector3::FORWARD), fixedAxis);
  265. }
  266. void Node::Scale(float scale)
  267. {
  268. scale_ *= scale;
  269. if (!dirty_)
  270. MarkDirty();
  271. }
  272. void Node::Scale(const Vector3& scale)
  273. {
  274. scale_ *= scale;
  275. if (!dirty_)
  276. MarkDirty();
  277. }
  278. void Node::MarkDirty()
  279. {
  280. dirty_ = true;
  281. // Notify listener components first, then mark child nodes
  282. for (Vector<WeakPtr<Component> >::Iterator i = listeners_.Begin(); i != listeners_.End();)
  283. {
  284. if (*i)
  285. {
  286. (*i)->OnMarkedDirty(this);
  287. ++i;
  288. }
  289. // If listener has expired, erase from list
  290. else
  291. i = listeners_.Erase(i);
  292. }
  293. for (Vector<SharedPtr<Node> >::Iterator i = children_.Begin(); i != children_.End(); ++i)
  294. (*i)->MarkDirty();
  295. }
  296. Node* Node::CreateChild(const String& name, bool local)
  297. {
  298. Node* newNode = CreateChild(0, local);
  299. newNode->SetName(name);
  300. return newNode;
  301. }
  302. void Node::AddChild(Node* node)
  303. {
  304. // Check for illegal parent assignments, including attempt to reparent the scene
  305. if ((!node) || (node == this) || (node->parent_ == this) || (parent_ == node) || (scene_ == node))
  306. return;
  307. // Add first, then remove from old parent, to ensure the node does not get deleted
  308. children_.Push(SharedPtr<Node>(node));
  309. if (node->parent_)
  310. node->parent_->RemoveChild(node);
  311. // Add to the scene if not added yet
  312. if ((scene_) && (!node->GetScene()))
  313. scene_->NodeAdded(node);
  314. node->parent_ = this;
  315. node->MarkDirty();
  316. }
  317. void Node::RemoveChild(Node* node)
  318. {
  319. if (!node)
  320. return;
  321. for (Vector<SharedPtr<Node> >::Iterator i = children_.Begin(); i != children_.End(); ++i)
  322. {
  323. if (i->GetPtr() == node)
  324. {
  325. RemoveChild(i);
  326. return;
  327. }
  328. }
  329. }
  330. void Node::RemoveAllChildren()
  331. {
  332. while (children_.Size())
  333. RemoveChild(children_.End() - 1);
  334. }
  335. Component* Node::CreateComponent(ShortStringHash type, bool local)
  336. {
  337. return CreateComponent(type, 0, local);
  338. }
  339. Component* Node::GetOrCreateComponent(ShortStringHash type, bool local)
  340. {
  341. Component* oldComponent = GetComponent(type);
  342. if (oldComponent)
  343. return oldComponent;
  344. else
  345. return CreateComponent(type, 0, local);
  346. }
  347. void Node::RemoveComponent(Component* component)
  348. {
  349. for (Vector<SharedPtr<Component> >::Iterator i = components_.Begin(); i != components_.End(); ++i)
  350. {
  351. if (*i == component)
  352. {
  353. WeakPtr<Component> componentWeak(*i);
  354. RemoveListener(*i);
  355. if (scene_)
  356. scene_->ComponentRemoved(*i);
  357. components_.Erase(i);
  358. // If the component is still referenced elsewhere, reset its node pointer now
  359. if (componentWeak)
  360. componentWeak->SetNode(0);
  361. return;
  362. }
  363. }
  364. }
  365. void Node::RemoveAllComponents()
  366. {
  367. while (components_.Size())
  368. {
  369. Vector<SharedPtr<Component> >::Iterator i = components_.End() - 1;
  370. WeakPtr<Component> componentWeak(*i);
  371. RemoveListener(*i);
  372. if (scene_)
  373. scene_->ComponentRemoved(*i);
  374. components_.Erase(i);
  375. // If the component is still referenced elsewhere, reset its node pointer now
  376. if (componentWeak)
  377. componentWeak->SetNode(0);
  378. }
  379. }
  380. void Node::AddListener(Component* component)
  381. {
  382. if (!component)
  383. return;
  384. // Check for not adding twice
  385. for (Vector<WeakPtr<Component> >::Iterator i = listeners_.Begin(); i != listeners_.End(); ++i)
  386. {
  387. if ((*i) == component)
  388. return;
  389. }
  390. listeners_.Push(WeakPtr<Component>(component));
  391. // If the node is currently dirty, notify immediately
  392. if (dirty_)
  393. component->OnMarkedDirty(this);
  394. }
  395. void Node::RemoveListener(Component* component)
  396. {
  397. for (Vector<WeakPtr<Component> >::Iterator i = listeners_.Begin(); i != listeners_.End(); ++i)
  398. {
  399. if ((*i) == component)
  400. {
  401. listeners_.Erase(i);
  402. return;
  403. }
  404. }
  405. }
  406. void Node::Remove()
  407. {
  408. if (parent_)
  409. parent_->RemoveChild(this);
  410. }
  411. void Node::SetParent(Node* parent)
  412. {
  413. if (parent)
  414. parent->AddChild(this);
  415. }
  416. unsigned Node::GetNumChildren(bool recursive) const
  417. {
  418. if (!recursive)
  419. return children_.Size();
  420. else
  421. {
  422. unsigned allChildren = children_.Size();
  423. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  424. allChildren += (*i)->GetNumChildren(true);
  425. return allChildren;
  426. }
  427. }
  428. void Node::GetChildren(PODVector<Node*>& dest, bool recursive) const
  429. {
  430. dest.Clear();
  431. if (!recursive)
  432. {
  433. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  434. dest.Push(*i);
  435. }
  436. else
  437. GetChildrenRecursive(dest);
  438. }
  439. void Node::GetChildrenWithComponent(PODVector<Node*>& dest, ShortStringHash type, bool recursive) const
  440. {
  441. dest.Clear();
  442. if (!recursive)
  443. {
  444. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  445. {
  446. if ((*i)->HasComponent(type))
  447. dest.Push(*i);
  448. }
  449. }
  450. else
  451. GetChildrenWithComponentRecursive(dest, type);
  452. }
  453. Node* Node::GetChild(unsigned index) const
  454. {
  455. return index < children_.Size() ? children_[index].GetPtr() : 0;
  456. }
  457. Node* Node::GetChild(const String& name, bool recursive) const
  458. {
  459. return GetChild(StringHash(name), recursive);
  460. }
  461. Node* Node::GetChild(StringHash nameHash, bool recursive) const
  462. {
  463. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  464. {
  465. if ((*i)->GetNameHash() == nameHash)
  466. return *i;
  467. if (recursive)
  468. {
  469. Node* node = (*i)->GetChild(nameHash, true);
  470. if (node)
  471. return node;
  472. }
  473. }
  474. return 0;
  475. }
  476. void Node::GetComponents(PODVector<Component*>& dest, ShortStringHash type) const
  477. {
  478. dest.Clear();
  479. for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
  480. {
  481. if ((*i)->GetType() == type)
  482. dest.Push(*i);
  483. }
  484. }
  485. bool Node::HasComponent(ShortStringHash type) const
  486. {
  487. for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
  488. {
  489. if ((*i)->GetType() == type)
  490. return true;
  491. }
  492. return false;
  493. }
  494. Component* Node::GetComponent(unsigned index) const
  495. {
  496. return index < components_.Size() ? components_[index].GetPtr() : 0;
  497. }
  498. Component* Node::GetComponent(ShortStringHash type, unsigned index) const
  499. {
  500. unsigned cmpIndex = 0;
  501. for (Vector<SharedPtr<Component> >::ConstIterator i = components_.Begin(); i != components_.End(); ++i)
  502. {
  503. if ((*i)->GetType() == type)
  504. {
  505. if (cmpIndex == index)
  506. return *i;
  507. ++cmpIndex;
  508. }
  509. }
  510. return 0;
  511. }
  512. void Node::SetID(unsigned id)
  513. {
  514. id_ = id;
  515. }
  516. void Node::SetScene(Scene* scene)
  517. {
  518. scene_ = scene;
  519. }
  520. void Node::SetOwner(Connection* owner)
  521. {
  522. owner_ = owner;
  523. }
  524. bool Node::Load(Deserializer& source, bool readChildren)
  525. {
  526. // Remove all children and components first in case this is not a fresh load
  527. RemoveAllChildren();
  528. RemoveAllComponents();
  529. // ID has been read at the parent level
  530. if (!Serializable::Load(source))
  531. return false;
  532. unsigned numComponents = source.ReadVLE();
  533. for (unsigned i = 0; i < numComponents; ++i)
  534. {
  535. VectorBuffer compBuffer(source, source.ReadVLE());
  536. ShortStringHash newType = compBuffer.ReadShortStringHash();
  537. Component* newComponent = CreateComponent(newType, compBuffer.ReadUInt(), false);
  538. if (newComponent)
  539. {
  540. if (!newComponent->Load(compBuffer))
  541. return false;
  542. }
  543. }
  544. if (!readChildren)
  545. return true;
  546. unsigned numChildren = source.ReadVLE();
  547. for (unsigned i = 0; i < numChildren; ++i)
  548. {
  549. Node* newNode = CreateChild(source.ReadUInt(), false);
  550. if (!newNode->Load(source))
  551. return false;
  552. }
  553. return true;
  554. }
  555. bool Node::LoadXML(const XMLElement& source, bool readChildren)
  556. {
  557. // Remove all children and components first in case this is not a fresh load
  558. RemoveAllChildren();
  559. RemoveAllComponents();
  560. if (!Serializable::LoadXML(source))
  561. return false;
  562. XMLElement compElem = source.GetChildElement("component");
  563. while (compElem)
  564. {
  565. String typeName = compElem.GetString("type");
  566. Component* newComponent = CreateComponent(ShortStringHash(compElem.GetString("type")), compElem.GetInt("id"), false);
  567. if (newComponent)
  568. {
  569. if (!newComponent->LoadXML(compElem))
  570. return false;
  571. }
  572. compElem = compElem.GetNextElement("component");
  573. }
  574. if (!readChildren)
  575. return true;
  576. XMLElement childElem = source.GetChildElement("node");
  577. while (childElem)
  578. {
  579. Node* newNode = CreateChild(childElem.GetInt("id"), false);
  580. if (!newNode->LoadXML(childElem))
  581. return false;
  582. childElem = childElem.GetNextElement("node");
  583. }
  584. return true;
  585. }
  586. Component* Node::CreateComponent(ShortStringHash type, unsigned id, bool local)
  587. {
  588. // Make sure the object in question is a component
  589. SharedPtr<Component> newComponent = DynamicCast<Component>(context_->CreateObject(type));
  590. if (!newComponent)
  591. {
  592. LOGERROR("Could not create unknown component type " + type);
  593. return 0;
  594. }
  595. components_.Push(newComponent);
  596. // If zero ID specified, let the scene assign
  597. if (scene_)
  598. {
  599. newComponent->SetID(id ? id : scene_->GetFreeComponentID(local));
  600. scene_->ComponentAdded(newComponent);
  601. }
  602. else
  603. newComponent->SetID(id);
  604. newComponent->SetNode(this);
  605. newComponent->OnMarkedDirty(this);
  606. return newComponent;
  607. }
  608. Node* Node::CreateChild(unsigned id, bool local)
  609. {
  610. SharedPtr<Node> newNode(new Node(context_));
  611. // If zero ID specified, let the scene assign
  612. if (scene_)
  613. newNode->SetID(id ? id : scene_->GetFreeunsigned(local));
  614. else
  615. newNode->SetID(id);
  616. AddChild(newNode);
  617. return newNode;
  618. }
  619. void Node::UpdateWorldTransform()
  620. {
  621. // For now, assume that the Scene has identity transform so that we skip one matrix multiply. However in the future
  622. // we may want dynamic root nodes for large worlds
  623. if ((parent_) && (parent_ != scene_))
  624. {
  625. if (parent_->dirty_)
  626. parent_->UpdateWorldTransform();
  627. worldTransform_ = parent_->worldTransform_ * Matrix4x3(position_, rotation_, scale_);
  628. }
  629. else
  630. worldTransform_ = Matrix4x3(position_, rotation_, scale_);
  631. dirty_ = false;
  632. }
  633. void Node::RemoveChild(Vector<SharedPtr<Node> >::Iterator i)
  634. {
  635. (*i)->parent_ = 0;
  636. (*i)->MarkDirty();
  637. children_.Erase(i);
  638. }
  639. void Node::GetChildrenRecursive(PODVector<Node*>& dest) const
  640. {
  641. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  642. {
  643. Node* node = *i;
  644. dest.Push(node);
  645. if (!node->children_.Empty())
  646. node->GetChildrenRecursive(dest);
  647. }
  648. }
  649. void Node::GetChildrenWithComponentRecursive(PODVector<Node*>& dest, ShortStringHash type) const
  650. {
  651. for (Vector<SharedPtr<Node> >::ConstIterator i = children_.Begin(); i != children_.End(); ++i)
  652. {
  653. Node* node = *i;
  654. if (node->HasComponent(type))
  655. dest.Push(node);
  656. if (!node->children_.Empty())
  657. node->GetChildrenRecursive(dest);
  658. }
  659. }