diff --git a/include/scene.h b/include/scene.h index 6218012..1a2f843 100644 --- a/include/scene.h +++ b/include/scene.h @@ -108,6 +108,14 @@ class Scene { ecs_systems_.emplace_back(hash, std::make_unique(this)); } + /* Pushes old systems starting at 'index' along by 1 */ + template + void RegisterSystemAtIndex(size_t index) + { + size_t hash = typeid(T).hash_code(); + ecs_systems_.emplace(ecs_systems_.begin() + index, hash, std::make_unique(this)); + } + template T* GetSystem() { diff --git a/src/scene.cpp b/src/scene.cpp index f6a1d9b..93f5db2 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -26,11 +26,11 @@ Scene::Scene(Application* app) : app_(app) { RegisterComponent(); // Order here matters: + RegisterSystem(); // potentially modifies transforms RegisterSystem(); - RegisterSystem(); - RegisterSystem(); - RegisterSystem(); - RegisterSystem(); + RegisterSystem(); // depends on transformed world matrix + RegisterSystem(); // depends on transformed world matrix + RegisterSystem(); // does nothing as of now } Scene::~Scene() {} diff --git a/test/src/game.cpp b/test/src/game.cpp index 56f70ac..4fb9e27 100644 --- a/test/src/game.cpp +++ b/test/src/game.cpp @@ -68,7 +68,7 @@ void PlayGame(GameSettings settings) //engine::Entity temple = engine::util::LoadGLTF(*start_scene, "C:/games/temple.glb", true); start_scene->RegisterComponent(); - start_scene->RegisterSystem(); + start_scene->RegisterSystemAtIndex(0); start_scene->AddComponent(camera)->noclip = true; start_scene->GetPosition(camera).z += 10.0f; } @@ -93,7 +93,7 @@ void PlayGame(GameSettings settings) camera_transform->is_static = false; main_scene->RegisterComponent(); - main_scene->RegisterSystem(); + main_scene->RegisterSystemAtIndex(0); main_scene->AddComponent(camera); /* floor */