feat: add mesh component editors and scene hierarchy serialization

This commit is contained in:
2026-03-31 21:25:59 +08:00
parent b92f9bfa70
commit be15bc2fc4
7 changed files with 341 additions and 7 deletions

View File

@@ -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() {

View File

@@ -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();