feat: add mesh component editors and scene hierarchy serialization
This commit is contained in:
@@ -30,7 +30,6 @@ GameObject::GameObject(const std::string& name)
|
||||
}
|
||||
|
||||
GameObject::~GameObject() {
|
||||
GetGlobalRegistry().erase(m_id);
|
||||
if (m_transform) {
|
||||
delete m_transform;
|
||||
m_transform = nullptr;
|
||||
@@ -39,8 +38,10 @@ GameObject::~GameObject() {
|
||||
}
|
||||
|
||||
std::unordered_map<GameObject::ID, GameObject*>& GameObject::GetGlobalRegistry() {
|
||||
static std::unordered_map<ID, GameObject*> registry;
|
||||
return registry;
|
||||
// Keep the registry alive until process teardown to avoid static destruction
|
||||
// order issues when GameObject instances are released from other singletons.
|
||||
static auto* registry = new std::unordered_map<ID, GameObject*>();
|
||||
return *registry;
|
||||
}
|
||||
|
||||
void GameObject::NotifyComponentsBecameActive() {
|
||||
|
||||
@@ -108,6 +108,10 @@ Scene::Scene(const std::string& name)
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
auto& registry = GameObject::GetGlobalRegistry();
|
||||
for (const auto& entry : m_gameObjects) {
|
||||
registry.erase(entry.first);
|
||||
}
|
||||
m_gameObjects.clear();
|
||||
}
|
||||
|
||||
@@ -156,6 +160,7 @@ void Scene::DestroyGameObject(GameObject* gameObject) {
|
||||
gameObject->OnDestroy();
|
||||
|
||||
m_gameObjectIDs.erase(gameObject->m_id);
|
||||
GameObject::GetGlobalRegistry().erase(gameObject->m_id);
|
||||
m_gameObjects.erase(gameObject->m_id);
|
||||
}
|
||||
|
||||
@@ -244,6 +249,10 @@ void Scene::LateUpdate(float deltaTime) {
|
||||
}
|
||||
|
||||
void Scene::DeserializeFromString(const std::string& data) {
|
||||
auto& registry = GameObject::GetGlobalRegistry();
|
||||
for (const auto& entry : m_gameObjects) {
|
||||
registry.erase(entry.first);
|
||||
}
|
||||
m_gameObjects.clear();
|
||||
m_rootGameObjects.clear();
|
||||
m_gameObjectIDs.clear();
|
||||
|
||||
Reference in New Issue
Block a user