diff --git a/cdcScene/Scene.cpp b/cdcScene/Scene.cpp index e70bab1..c4fec7b 100644 --- a/cdcScene/Scene.cpp +++ b/cdcScene/Scene.cpp @@ -110,4 +110,11 @@ void Scene::AddEntity(SceneEntity *pEntity) { // line 2541 m_entities.push_back(pEntity); } +void Scene::RemoveEntity(SceneEntity *pEntity) { + uint32_t index = pEntity->entityIndex; + m_entities[index] = m_entities[m_entities.size()-1]; + m_entities[index]->entityIndex = index; + m_entities.resize(m_entities.size()-1); +} + } diff --git a/cdcScene/Scene.h b/cdcScene/Scene.h index 3b9f94b..8e7df36 100644 --- a/cdcScene/Scene.h +++ b/cdcScene/Scene.h @@ -35,6 +35,8 @@ public: // called from SceneEntity ctor void AddEntity(SceneEntity *pEntity); + // called from SceneEntity dtor + void RemoveEntity(SceneEntity *pEntity); // 43 methods void Render() override; diff --git a/cdcScene/SceneEntity.cpp b/cdcScene/SceneEntity.cpp index 9a1fff1..4895177 100644 --- a/cdcScene/SceneEntity.cpp +++ b/cdcScene/SceneEntity.cpp @@ -76,6 +76,16 @@ void SceneEntity::setCellGroup(ISceneCellGroup *newICellGroup) { } } +void SceneEntity::Release() { + // called from SceneLayer::RemoveInstance + delete this; +} + +SceneEntity::~SceneEntity() { + // TODO + scene->RemoveEntity(this); +} + void SceneEntity::QueryVolumeFromDrawable() { // line 370 if (drawable) { drawable->GetBoundingVolume(&cullingVolume); diff --git a/cdcScene/SceneEntity.h b/cdcScene/SceneEntity.h index 72c2936..d76d19b 100644 --- a/cdcScene/SceneEntity.h +++ b/cdcScene/SceneEntity.h @@ -34,6 +34,8 @@ public: void setDrawable(IDrawable *) override; IDrawable *getDrawable() override; void setCellGroup(ISceneCellGroup *) override; + void Release() override; + ~SceneEntity(); }; } diff --git a/cdcScene/cdcScene.h b/cdcScene/cdcScene.h index c566b61..dfc4b80 100644 --- a/cdcScene/cdcScene.h +++ b/cdcScene/cdcScene.h @@ -63,6 +63,8 @@ public: virtual void setDrawable(IDrawable *) = 0; // C virtual IDrawable *getDrawable() = 0; // 10 virtual void setCellGroup(ISceneCellGroup *) = 0; // 38 + virtual void Release() = 0; // 58 + virtual ~ISceneEntity() = default; // 5C }; class ISceneLight : public ISceneEntity { // line 1036 diff --git a/cdcWorld/Inspector.cpp b/cdcWorld/Inspector.cpp index 6610164..abcbb3b 100644 --- a/cdcWorld/Inspector.cpp +++ b/cdcWorld/Inspector.cpp @@ -5,6 +5,7 @@ #include "rendering/CommonMaterial.h" #include "rendering/MaterialData.h" #include "cdcResource/ResolveSection.h" +#include "cdcScene/SceneEntity.h" #include "cdcSound/SoundPlex.h" #include "cdcObjects/ObjectManager.h" #include "cdcWorld/Instance.h" @@ -162,6 +163,11 @@ void buildUI(UIActions& uiact, Instance *instance) { if (instance->instanceDrawable) ImGui::Text(" %s", typeid(*instance->instanceDrawable).name()); + if (ImGui::Button("Recreate scene entity")) { + instance->sceneEntity->Release(); + instance->sceneEntity = nullptr; + } + cdc::Object *object = instance->object; if (false) for (uint32_t i=0; inumAnims; i++) {