SceneSystemDB now working properly

This commit is contained in:
antopilo
2025-02-01 12:06:03 -05:00
parent 447fa3cdad
commit 17f96f5af2
6 changed files with 74 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
#include "Modules.h"
#include "AssimpModule/AssimpModule.h"
#include "AudioModule/AudioModule.h"
#include "ExampleModule/ExampleModule.h"
#include "Nuake/Core/Logger.h"
@@ -10,6 +11,8 @@ void Nuake::Modules::StartupModules()
{
Logger::Log("Starting AssimpModule", "modules");
AssimpModule_Startup();
Logger::Log("Starting AudioModule", "modules");
AudioModule_Startup();
Logger::Log("Starting ExampleModule", "modules");
ExampleModule_Startup();
}
@@ -18,6 +21,8 @@ void Nuake::Modules::ShutdownModules()
{
Logger::Log("Shutting down AssimpModule", "modules");
AssimpModule_Shutdown();
Logger::Log("Shutting down AudioModule", "modules");
AudioModule_Shutdown();
Logger::Log("Shutting down ExampleModule", "modules");
ExampleModule_Shutdown();
}

View File

@@ -21,7 +21,6 @@
#include "Nuake/Rendering/Renderer.h"
#include "Nuake/Rendering/Textures/MaterialManager.h"
#include <glad/glad.h>
#include "Engine.h"
#include "Nuake/Core/Maths.h"
@@ -34,6 +33,7 @@
#include "Nuake/Scene/Components/SkinnedModelComponent.h"
#include "Nuake/Scene/Components/BoneComponent.h"
#include "Nuake/Scene/SceneSystems.h"
#include <Tracy.hpp>
@@ -65,13 +65,16 @@ namespace Nuake
scriptingSystem = CreateRef<ScriptingSystem>(this);
// Adding systems - Order is important
SceneSystemDB::Get().InstantiateSystems(this);
m_Systems.push_back(physicsSystem);
m_Systems.push_back(CreateRef<UISystem>(this));
m_Systems.push_back(scriptingSystem);
m_Systems.push_back(CreateRef<AnimationSystem>(this));
m_Systems.push_back(CreateRef<TransformSystem>(this));
m_Systems.push_back(CreateRef<ParticleSystem>(this));
m_Systems.push_back(CreateRef<AudioSystem>(this));
//m_Systems.push_back(CreateRef<AudioSystem>(this));
m_SceneRenderer = CreateRef<SceneRenderer>();
m_SceneRenderer->Init();

View File

@@ -36,10 +36,10 @@ namespace Nuake
// The systems are what updates the components.
// You can create a new system(see 'Systems/'.) and register it
// In the scene constructor.
std::vector<Ref<System>> m_Systems;
static Ref<Environment> m_Environment;
public:
std::vector<Ref<System>> m_Systems;
Ref<EditorCamera> m_EditorCamera;
entt::registry m_Registry;
std::unordered_map<uint32_t, Entity> m_EntitiesIDMap;

View File

@@ -0,0 +1,51 @@
#pragma once
#include "Nuake/Core/Core.h"
#include "Nuake/Scene/Systems/System.h"
#include "Nuake/Scene/Scene.h"
#include <set>
#include <functional>
namespace Nuake
{
class Scene;
class System;
using SystemInitializerFunc = std::function<Ref<System>(Scene*)>;
template<typename T>
concept InheritsFromSystem = std::derived_from<T, System>;
class SceneSystemDB
{
private:
std::vector<SystemInitializerFunc> Systems;
public:
static SceneSystemDB& Get()
{
static SceneSystemDB instance;
return instance;
};
SceneSystemDB() = default;
~SceneSystemDB() = default;
public:
template<InheritsFromSystem T>
void RegisterSceneSystem()
{
Systems.push_back(&System::Instantiate<T>);
}
void InstantiateSystems(Scene* scene)
{
for (auto& system : Systems)
{
scene->m_Systems.push_back(system(scene));
}
}
};
}

View File

@@ -1,6 +1,5 @@
#pragma once
#include "Nuake/Scene/Systems/System.h"
#include "Nuake/Core/Maths.h"
namespace Nuake
{

View File

@@ -4,13 +4,25 @@
#include "Nuake/Core/Core.h"
#include "Nuake/Core/MulticastDelegate.h"
#include <concepts>
namespace Nuake
{
class System;
template<typename T>
concept IsSceneSystem = std::derived_from<T, System>;
class Scene;
class System {
public:
Scene* m_Scene;
template<IsSceneSystem T>
static Ref<System> Instantiate(Scene* scene)
{
return std::static_pointer_cast<System>(CreateRef<T>(scene));
}
virtual bool Init() = 0;