BsSceneObject.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #include "BsSceneObject.h"
  4. #include "BsComponent.h"
  5. #include "BsCoreSceneManager.h"
  6. #include "BsException.h"
  7. #include "BsDebug.h"
  8. #include "BsSceneObjectRTTI.h"
  9. #include "BsMemorySerializer.h"
  10. #include "BsGameObjectManager.h"
  11. #include "BsPrefabUtility.h"
  12. #include "BsMatrix3.h"
  13. #include "BsCoreApplication.h"
  14. namespace BansheeEngine
  15. {
  16. SceneObject::SceneObject(const String& name, UINT32 flags)
  17. : GameObject(), mPrefabHash(0), mFlags(flags), mPosition(Vector3::ZERO), mRotation(Quaternion::IDENTITY)
  18. , mScale(Vector3::ONE), mWorldPosition(Vector3::ZERO), mWorldRotation(Quaternion::IDENTITY)
  19. , mWorldScale(Vector3::ONE), mCachedLocalTfrm(Matrix4::IDENTITY), mCachedWorldTfrm(Matrix4::IDENTITY)
  20. , mDirtyFlags(0xFFFFFFFF), mDirtyHash(0), mActiveSelf(true), mActiveHierarchy(true)
  21. {
  22. setName(name);
  23. }
  24. SceneObject::~SceneObject()
  25. {
  26. if(!mThisHandle.isDestroyed())
  27. {
  28. LOGWRN("Object is being deleted without being destroyed first? " + mName);
  29. destroyInternal(mThisHandle, true);
  30. }
  31. }
  32. HSceneObject SceneObject::create(const String& name, UINT32 flags)
  33. {
  34. HSceneObject newObject = createInternal(name, flags);
  35. if (newObject->isInstantiated())
  36. gCoreSceneManager().registerNewSO(newObject);
  37. return newObject;
  38. }
  39. HSceneObject SceneObject::createInternal(const String& name, UINT32 flags)
  40. {
  41. SPtr<SceneObject> sceneObjectPtr = SPtr<SceneObject>(new (bs_alloc<SceneObject>()) SceneObject(name, flags),
  42. &bs_delete<SceneObject>, StdAlloc<SceneObject>());
  43. HSceneObject sceneObject = GameObjectManager::instance().registerObject(sceneObjectPtr);
  44. sceneObject->mThisHandle = sceneObject;
  45. return sceneObject;
  46. }
  47. HSceneObject SceneObject::createInternal(const SPtr<SceneObject>& soPtr, UINT64 originalId)
  48. {
  49. HSceneObject sceneObject = GameObjectManager::instance().registerObject(soPtr, originalId);
  50. sceneObject->mThisHandle = sceneObject;
  51. return sceneObject;
  52. }
  53. void SceneObject::destroy(bool immediate)
  54. {
  55. // Parent is our owner, so when his reference to us is removed, delete might be called.
  56. // So make sure this is the last thing we do.
  57. if(mParent != nullptr)
  58. {
  59. if(!mParent.isDestroyed())
  60. mParent->removeChild(mThisHandle);
  61. mParent = nullptr;
  62. }
  63. destroyInternal(mThisHandle, immediate);
  64. }
  65. void SceneObject::destroyInternal(GameObjectHandleBase& handle, bool immediate)
  66. {
  67. if (immediate)
  68. {
  69. for (auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
  70. (*iter)->destroyInternal(*iter, true);
  71. mChildren.clear();
  72. for (auto iter = mComponents.begin(); iter != mComponents.end(); ++iter)
  73. {
  74. HComponent component = *iter;
  75. component->_setIsDestroyed();
  76. if (isInstantiated())
  77. {
  78. if (getActive())
  79. component->onDisabled();
  80. component->onDestroyed();
  81. }
  82. component->destroyInternal(*iter, true);
  83. }
  84. mComponents.clear();
  85. GameObjectManager::instance().unregisterObject(handle);
  86. }
  87. else
  88. GameObjectManager::instance().queueForDestroy(handle);
  89. }
  90. void SceneObject::_setInstanceData(GameObjectInstanceDataPtr& other)
  91. {
  92. GameObject::_setInstanceData(other);
  93. // Instance data changed, so make sure to refresh the handles to reflect that
  94. SPtr<SceneObject> thisPtr = mThisHandle.getInternalPtr();
  95. mThisHandle._setHandleData(thisPtr);
  96. }
  97. String SceneObject::getPrefabLink() const
  98. {
  99. const SceneObject* curObj = this;
  100. while (curObj != nullptr)
  101. {
  102. if (!curObj->mPrefabLinkUUID.empty())
  103. return curObj->mPrefabLinkUUID;
  104. if (curObj->mParent != nullptr)
  105. curObj = curObj->mParent.get();
  106. else
  107. curObj = nullptr;
  108. }
  109. return "";
  110. }
  111. HSceneObject SceneObject::getPrefabParent() const
  112. {
  113. HSceneObject curObj = mThisHandle;
  114. while (curObj != nullptr)
  115. {
  116. if (!curObj->mPrefabLinkUUID.empty())
  117. return curObj;
  118. if (curObj->mParent != nullptr)
  119. curObj = curObj->mParent;
  120. else
  121. curObj = nullptr;
  122. }
  123. return curObj;
  124. }
  125. void SceneObject::breakPrefabLink()
  126. {
  127. SceneObject* rootObj = this;
  128. while (rootObj != nullptr)
  129. {
  130. if (!rootObj->mPrefabLinkUUID.empty())
  131. break;
  132. if (rootObj->mParent != nullptr)
  133. rootObj = rootObj->mParent.get();
  134. else
  135. rootObj = nullptr;
  136. }
  137. if (rootObj != nullptr)
  138. {
  139. rootObj->mPrefabLinkUUID = "";
  140. rootObj->mPrefabDiff = nullptr;
  141. PrefabUtility::clearPrefabIds(rootObj->getHandle(), true, false);
  142. }
  143. }
  144. bool SceneObject::hasFlag(UINT32 flag) const
  145. {
  146. return (mFlags & flag) != 0;
  147. }
  148. void SceneObject::setFlags(UINT32 flags)
  149. {
  150. mFlags |= flags;
  151. for (auto& child : mChildren)
  152. child->setFlags(flags);
  153. }
  154. void SceneObject::unsetFlags(UINT32 flags)
  155. {
  156. mFlags &= ~flags;
  157. for (auto& child : mChildren)
  158. child->unsetFlags(flags);
  159. }
  160. void SceneObject::_instantiate(bool prefabOnly)
  161. {
  162. std::function<void(SceneObject*)> instantiateRecursive = [&](SceneObject* obj)
  163. {
  164. obj->mFlags &= ~SOF_DontInstantiate;
  165. if (obj->mParent == nullptr)
  166. gCoreSceneManager().registerNewSO(obj->mThisHandle);
  167. for (auto& component : obj->mComponents)
  168. component->_instantiate();
  169. for (auto& child : obj->mChildren)
  170. {
  171. if(!prefabOnly || child->getPrefabLink().empty())
  172. instantiateRecursive(child.get());
  173. }
  174. };
  175. std::function<void(SceneObject*)> triggerEventsRecursive = [&](SceneObject* obj)
  176. {
  177. for (auto& component : obj->mComponents)
  178. {
  179. component->onInitialized();
  180. if (obj->getActive())
  181. component->onEnabled();
  182. }
  183. for (auto& child : obj->mChildren)
  184. {
  185. if (!prefabOnly || child->getPrefabLink().empty())
  186. triggerEventsRecursive(child.get());
  187. }
  188. };
  189. instantiateRecursive(this);
  190. triggerEventsRecursive(this);
  191. }
  192. /************************************************************************/
  193. /* Transform */
  194. /************************************************************************/
  195. void SceneObject::setPosition(const Vector3& position)
  196. {
  197. mPosition = position;
  198. notifyTransformChanged(TCF_Transform);
  199. }
  200. void SceneObject::setRotation(const Quaternion& rotation)
  201. {
  202. mRotation = rotation;
  203. notifyTransformChanged(TCF_Transform);
  204. }
  205. void SceneObject::setScale(const Vector3& scale)
  206. {
  207. mScale = scale;
  208. notifyTransformChanged(TCF_Transform);
  209. }
  210. void SceneObject::setWorldPosition(const Vector3& position)
  211. {
  212. if (mParent != nullptr)
  213. {
  214. Vector3 invScale = mParent->getWorldScale();
  215. if (invScale.x != 0) invScale.x = 1.0f / invScale.x;
  216. if (invScale.y != 0) invScale.y = 1.0f / invScale.y;
  217. if (invScale.z != 0) invScale.z = 1.0f / invScale.z;
  218. Quaternion invRotation = mParent->getWorldRotation().inverse();
  219. mPosition = invRotation.rotate(position - mParent->getWorldPosition()) * invScale;
  220. }
  221. else
  222. mPosition = position;
  223. notifyTransformChanged(TCF_Transform);
  224. }
  225. void SceneObject::setWorldRotation(const Quaternion& rotation)
  226. {
  227. if (mParent != nullptr)
  228. {
  229. Quaternion invRotation = mParent->getWorldRotation().inverse();
  230. mRotation = invRotation * rotation;
  231. }
  232. else
  233. mRotation = rotation;
  234. notifyTransformChanged(TCF_Transform);
  235. }
  236. void SceneObject::setWorldScale(const Vector3& scale)
  237. {
  238. if (mParent != nullptr)
  239. {
  240. Matrix3 rotScale;
  241. mParent->getWorldTfrm().extract3x3Matrix(rotScale);
  242. rotScale.inverse();
  243. Matrix3 scaleMat = Matrix3(Quaternion::IDENTITY, scale);
  244. scaleMat = rotScale * scaleMat;
  245. Quaternion rotation;
  246. Vector3 localScale;
  247. scaleMat.decomposition(rotation, localScale);
  248. mScale = localScale;
  249. }
  250. else
  251. mScale = scale;
  252. notifyTransformChanged(TCF_Transform);
  253. }
  254. const Vector3& SceneObject::getWorldPosition() const
  255. {
  256. if (!isCachedWorldTfrmUpToDate())
  257. updateWorldTfrm();
  258. return mWorldPosition;
  259. }
  260. const Quaternion& SceneObject::getWorldRotation() const
  261. {
  262. if (!isCachedWorldTfrmUpToDate())
  263. updateWorldTfrm();
  264. return mWorldRotation;
  265. }
  266. const Vector3& SceneObject::getWorldScale() const
  267. {
  268. if (!isCachedWorldTfrmUpToDate())
  269. updateWorldTfrm();
  270. return mWorldScale;
  271. }
  272. void SceneObject::lookAt(const Vector3& location, const Vector3& up)
  273. {
  274. Vector3 forward = location - getWorldPosition();
  275. Quaternion rotation = getWorldRotation();
  276. rotation.lookRotation(forward, up);
  277. setWorldRotation(rotation);
  278. }
  279. const Matrix4& SceneObject::getWorldTfrm() const
  280. {
  281. if (!isCachedWorldTfrmUpToDate())
  282. updateWorldTfrm();
  283. return mCachedWorldTfrm;
  284. }
  285. Matrix4 SceneObject::getInvWorldTfrm() const
  286. {
  287. if (!isCachedWorldTfrmUpToDate())
  288. updateWorldTfrm();
  289. Matrix4 worldToLocal = Matrix4::inverseTRS(mWorldPosition, mWorldRotation, mWorldScale);
  290. return worldToLocal;
  291. }
  292. const Matrix4& SceneObject::getLocalTfrm() const
  293. {
  294. if (!isCachedLocalTfrmUpToDate())
  295. updateLocalTfrm();
  296. return mCachedLocalTfrm;
  297. }
  298. void SceneObject::move(const Vector3& vec)
  299. {
  300. setPosition(mPosition + vec);
  301. }
  302. void SceneObject::moveRelative(const Vector3& vec)
  303. {
  304. // Transform the axes of the relative vector by camera's local axes
  305. Vector3 trans = mRotation.rotate(vec);
  306. setPosition(mPosition + trans);
  307. }
  308. void SceneObject::rotate(const Vector3& axis, const Radian& angle)
  309. {
  310. Quaternion q;
  311. q.fromAxisAngle(axis, angle);
  312. rotate(q);
  313. }
  314. void SceneObject::rotate(const Quaternion& q)
  315. {
  316. // Note the order of the mult, i.e. q comes after
  317. // Normalize the quat to avoid cumulative problems with precision
  318. Quaternion qnorm = q;
  319. qnorm.normalize();
  320. setRotation(qnorm * mRotation);
  321. }
  322. void SceneObject::roll(const Radian& angle)
  323. {
  324. // Rotate around local Z axis
  325. Vector3 zAxis = mRotation.rotate(Vector3::UNIT_Z);
  326. rotate(zAxis, angle);
  327. }
  328. void SceneObject::yaw(const Radian& angle)
  329. {
  330. Vector3 yAxis = mRotation.rotate(Vector3::UNIT_Y);
  331. rotate(yAxis, angle);
  332. }
  333. void SceneObject::pitch(const Radian& angle)
  334. {
  335. // Rotate around local X axis
  336. Vector3 xAxis = mRotation.rotate(Vector3::UNIT_X);
  337. rotate(xAxis, angle);
  338. }
  339. void SceneObject::setForward(const Vector3& forwardDir)
  340. {
  341. Quaternion currentRotation = getWorldRotation();
  342. currentRotation.lookRotation(forwardDir);
  343. setWorldRotation(currentRotation);
  344. }
  345. void SceneObject::updateTransformsIfDirty()
  346. {
  347. if (!isCachedLocalTfrmUpToDate())
  348. updateLocalTfrm();
  349. if (!isCachedWorldTfrmUpToDate())
  350. updateWorldTfrm();
  351. }
  352. void SceneObject::notifyTransformChanged(TransformChangedFlags flags) const
  353. {
  354. mDirtyFlags |= DirtyFlags::LocalTfrmDirty | DirtyFlags::WorldTfrmDirty;
  355. mDirtyHash++;
  356. for(auto& entry : mComponents)
  357. {
  358. if (entry->supportsNotify(flags))
  359. entry->onTransformChanged(flags);
  360. }
  361. for (auto& entry : mChildren)
  362. entry->notifyTransformChanged(flags);
  363. }
  364. void SceneObject::updateWorldTfrm() const
  365. {
  366. if(mParent != nullptr)
  367. {
  368. // Update orientation
  369. const Quaternion& parentOrientation = mParent->getWorldRotation();
  370. mWorldRotation = parentOrientation * mRotation;
  371. // Update scale
  372. const Vector3& parentScale = mParent->getWorldScale();
  373. // Scale own position by parent scale, just combine
  374. // as equivalent axes, no shearing
  375. mWorldScale = parentScale * mScale;
  376. // Change position vector based on parent's orientation & scale
  377. mWorldPosition = parentOrientation.rotate(parentScale * mPosition);
  378. // Add altered position vector to parents
  379. mWorldPosition += mParent->getWorldPosition();
  380. mCachedWorldTfrm.setTRS(mWorldPosition, mWorldRotation, mWorldScale);
  381. }
  382. else
  383. {
  384. mWorldRotation = mRotation;
  385. mWorldPosition = mPosition;
  386. mWorldScale = mScale;
  387. mCachedWorldTfrm = getLocalTfrm();
  388. }
  389. mDirtyFlags &= ~DirtyFlags::WorldTfrmDirty;
  390. }
  391. void SceneObject::updateLocalTfrm() const
  392. {
  393. mCachedLocalTfrm.setTRS(mPosition, mRotation, mScale);
  394. mDirtyFlags &= ~DirtyFlags::LocalTfrmDirty;
  395. }
  396. /************************************************************************/
  397. /* Hierarchy */
  398. /************************************************************************/
  399. void SceneObject::setParent(const HSceneObject& parent, bool keepWorldTransform)
  400. {
  401. if (parent.isDestroyed())
  402. return;
  403. #if BS_EDITOR_BUILD
  404. String originalPrefab = getPrefabLink();
  405. #endif
  406. _setParent(parent, keepWorldTransform);
  407. #if BS_EDITOR_BUILD
  408. if (gCoreApplication().isEditor())
  409. {
  410. String newPrefab = getPrefabLink();
  411. if (originalPrefab != newPrefab)
  412. PrefabUtility::clearPrefabIds(mThisHandle);
  413. }
  414. #endif
  415. }
  416. void SceneObject::_setParent(const HSceneObject& parent, bool keepWorldTransform)
  417. {
  418. if (mThisHandle == parent)
  419. return;
  420. if (mParent == nullptr || mParent != parent)
  421. {
  422. Vector3 worldPos;
  423. Quaternion worldRot;
  424. Vector3 worldScale;
  425. if (keepWorldTransform)
  426. {
  427. // Make sure the object keeps its world coordinates
  428. worldPos = getWorldPosition();
  429. worldRot = getWorldRotation();
  430. worldScale = getWorldScale();
  431. }
  432. if (mParent != nullptr)
  433. mParent->removeChild(mThisHandle);
  434. if (parent != nullptr)
  435. parent->addChild(mThisHandle);
  436. mParent = parent;
  437. if (keepWorldTransform)
  438. {
  439. setWorldPosition(worldPos);
  440. setWorldRotation(worldRot);
  441. setWorldScale(worldScale);
  442. }
  443. notifyTransformChanged((TransformChangedFlags)(TCF_Parent | TCF_Transform));
  444. }
  445. }
  446. HSceneObject SceneObject::getChild(UINT32 idx) const
  447. {
  448. if(idx >= mChildren.size())
  449. {
  450. BS_EXCEPT(InternalErrorException, "Child index out of range.");
  451. }
  452. return mChildren[idx];
  453. }
  454. int SceneObject::indexOfChild(const HSceneObject& child) const
  455. {
  456. for(int i = 0; i < (int)mChildren.size(); i++)
  457. {
  458. if(mChildren[i] == child)
  459. return i;
  460. }
  461. return -1;
  462. }
  463. void SceneObject::addChild(const HSceneObject& object)
  464. {
  465. mChildren.push_back(object);
  466. object->setFlags(mFlags);
  467. }
  468. void SceneObject::removeChild(const HSceneObject& object)
  469. {
  470. auto result = find(mChildren.begin(), mChildren.end(), object);
  471. if(result != mChildren.end())
  472. mChildren.erase(result);
  473. else
  474. {
  475. BS_EXCEPT(InternalErrorException,
  476. "Trying to remove a child but it's not a child of the transform.");
  477. }
  478. }
  479. HSceneObject SceneObject::findChild(const String& name, bool recursive)
  480. {
  481. for (auto& child : mChildren)
  482. {
  483. if (child->getName() == name)
  484. return child;
  485. }
  486. if (recursive)
  487. {
  488. for (auto& child : mChildren)
  489. {
  490. HSceneObject foundObject = child->findChild(name, true);
  491. if (foundObject != nullptr)
  492. return foundObject;
  493. }
  494. }
  495. return HSceneObject();
  496. }
  497. Vector<HSceneObject> SceneObject::findChildren(const String& name, bool recursive)
  498. {
  499. std::function<void(const HSceneObject&, Vector<HSceneObject>&)> findChildrenInternal =
  500. [&](const HSceneObject& so, Vector<HSceneObject>& output)
  501. {
  502. for (auto& child : so->mChildren)
  503. {
  504. if (child->getName() == name)
  505. output.push_back(child);
  506. }
  507. if (recursive)
  508. {
  509. for (auto& child : so->mChildren)
  510. findChildrenInternal(child, output);
  511. }
  512. };
  513. Vector<HSceneObject> output;
  514. findChildrenInternal(mThisHandle, output);
  515. return output;
  516. }
  517. void SceneObject::setActive(bool active)
  518. {
  519. mActiveSelf = active;
  520. setActiveHierarchy(active);
  521. }
  522. void SceneObject::setActiveHierarchy(bool active, bool triggerEvents)
  523. {
  524. bool activeHierarchy = active && mActiveSelf;
  525. if (mActiveHierarchy != activeHierarchy)
  526. {
  527. mActiveHierarchy = activeHierarchy;
  528. if (triggerEvents)
  529. {
  530. if (activeHierarchy)
  531. {
  532. for (auto& component : mComponents)
  533. component->onEnabled();
  534. }
  535. else
  536. {
  537. for (auto& component : mComponents)
  538. component->onDisabled();
  539. }
  540. }
  541. }
  542. for (auto child : mChildren)
  543. {
  544. child->setActiveHierarchy(mActiveHierarchy, triggerEvents);
  545. }
  546. }
  547. bool SceneObject::getActive(bool self)
  548. {
  549. if (self)
  550. return mActiveSelf;
  551. else
  552. return mActiveHierarchy;
  553. }
  554. HSceneObject SceneObject::clone(bool instantiate)
  555. {
  556. bool isInstantiated = !hasFlag(SOF_DontInstantiate);
  557. if (!instantiate)
  558. setFlags(SOF_DontInstantiate);
  559. else
  560. unsetFlags(SOF_DontInstantiate);
  561. UINT32 bufferSize = 0;
  562. MemorySerializer serializer;
  563. UINT8* buffer = serializer.encode(this, bufferSize, (void*(*)(UINT32))&bs_alloc);
  564. GameObjectManager::instance().setDeserializationMode(GODM_UseNewIds | GODM_RestoreExternal);
  565. SPtr<SceneObject> cloneObj = std::static_pointer_cast<SceneObject>(serializer.decode(buffer, bufferSize));
  566. bs_free(buffer);
  567. if(isInstantiated)
  568. unsetFlags(SOF_DontInstantiate);
  569. else
  570. setFlags(SOF_DontInstantiate);
  571. return cloneObj->mThisHandle;
  572. }
  573. HComponent SceneObject::getComponent(RTTITypeBase* type) const
  574. {
  575. for(auto& entry : mComponents)
  576. {
  577. if(entry->getRTTI()->isDerivedFrom(type))
  578. return entry;
  579. }
  580. return HComponent();
  581. }
  582. void SceneObject::destroyComponent(const HComponent component, bool immediate)
  583. {
  584. if(component == nullptr)
  585. {
  586. LOGDBG("Trying to remove a null component");
  587. return;
  588. }
  589. auto iter = std::find(mComponents.begin(), mComponents.end(), component);
  590. if(iter != mComponents.end())
  591. {
  592. (*iter)->_setIsDestroyed();
  593. if (isInstantiated())
  594. {
  595. if (getActive())
  596. component->onDisabled();
  597. (*iter)->onDestroyed();
  598. }
  599. (*iter)->destroyInternal(*iter, immediate);
  600. mComponents.erase(iter);
  601. }
  602. else
  603. LOGDBG("Trying to remove a component that doesn't exist on this SceneObject.");
  604. }
  605. void SceneObject::destroyComponent(Component* component, bool immediate)
  606. {
  607. auto iterFind = std::find_if(mComponents.begin(), mComponents.end(),
  608. [component](const HComponent& x)
  609. {
  610. if(x.isDestroyed())
  611. return false;
  612. return x._getHandleData()->mPtr->object.get() == component; }
  613. );
  614. if(iterFind != mComponents.end())
  615. {
  616. destroyComponent(*iterFind, immediate);
  617. }
  618. }
  619. void SceneObject::addComponentInternal(const SPtr<Component> component)
  620. {
  621. GameObjectHandle<Component> newComponent = GameObjectManager::instance().getObject(component->getInstanceId());
  622. newComponent->mParent = mThisHandle;
  623. newComponent->mThisHandle = newComponent;
  624. mComponents.push_back(newComponent);
  625. }
  626. RTTITypeBase* SceneObject::getRTTIStatic()
  627. {
  628. return SceneObjectRTTI::instance();
  629. }
  630. RTTITypeBase* SceneObject::getRTTI() const
  631. {
  632. return SceneObject::getRTTIStatic();
  633. }
  634. }