cdcScene: implement SceneEntity::Release

This commit is contained in:
Adam Jensen 2024-05-21 23:08:01 +01:00
parent 81ed2768a7
commit 054db15952
6 changed files with 29 additions and 0 deletions

View File

@ -110,4 +110,11 @@ void Scene::AddEntity(SceneEntity *pEntity) { // line 2541
m_entities.push_back(pEntity); 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);
}
} }

View File

@ -35,6 +35,8 @@ public:
// called from SceneEntity ctor // called from SceneEntity ctor
void AddEntity(SceneEntity *pEntity); void AddEntity(SceneEntity *pEntity);
// called from SceneEntity dtor
void RemoveEntity(SceneEntity *pEntity);
// 43 methods // 43 methods
void Render() override; void Render() override;

View File

@ -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 void SceneEntity::QueryVolumeFromDrawable() { // line 370
if (drawable) { if (drawable) {
drawable->GetBoundingVolume(&cullingVolume); drawable->GetBoundingVolume(&cullingVolume);

View File

@ -34,6 +34,8 @@ public:
void setDrawable(IDrawable *) override; void setDrawable(IDrawable *) override;
IDrawable *getDrawable() override; IDrawable *getDrawable() override;
void setCellGroup(ISceneCellGroup *) override; void setCellGroup(ISceneCellGroup *) override;
void Release() override;
~SceneEntity();
}; };
} }

View File

@ -63,6 +63,8 @@ public:
virtual void setDrawable(IDrawable *) = 0; // C virtual void setDrawable(IDrawable *) = 0; // C
virtual IDrawable *getDrawable() = 0; // 10 virtual IDrawable *getDrawable() = 0; // 10
virtual void setCellGroup(ISceneCellGroup *) = 0; // 38 virtual void setCellGroup(ISceneCellGroup *) = 0; // 38
virtual void Release() = 0; // 58
virtual ~ISceneEntity() = default; // 5C
}; };
class ISceneLight : public ISceneEntity { // line 1036 class ISceneLight : public ISceneEntity { // line 1036

View File

@ -5,6 +5,7 @@
#include "rendering/CommonMaterial.h" #include "rendering/CommonMaterial.h"
#include "rendering/MaterialData.h" #include "rendering/MaterialData.h"
#include "cdcResource/ResolveSection.h" #include "cdcResource/ResolveSection.h"
#include "cdcScene/SceneEntity.h"
#include "cdcSound/SoundPlex.h" #include "cdcSound/SoundPlex.h"
#include "cdcObjects/ObjectManager.h" #include "cdcObjects/ObjectManager.h"
#include "cdcWorld/Instance.h" #include "cdcWorld/Instance.h"
@ -162,6 +163,11 @@ void buildUI(UIActions& uiact, Instance *instance) {
if (instance->instanceDrawable) if (instance->instanceDrawable)
ImGui::Text(" %s", typeid(*instance->instanceDrawable).name()); ImGui::Text(" %s", typeid(*instance->instanceDrawable).name());
if (ImGui::Button("Recreate scene entity")) {
instance->sceneEntity->Release();
instance->sceneEntity = nullptr;
}
cdc::Object *object = instance->object; cdc::Object *object = instance->object;
if (false) if (false)
for (uint32_t i=0; i<object->numAnims; i++) { for (uint32_t i=0; i<object->numAnims; i++) {