First pass scriptable subsystems that has the same lifetime of the engine

This commit is contained in:
WiggleWizard
2024-09-18 12:44:46 +01:00
parent 67d7865a20
commit 510b577f49
17 changed files with 219 additions and 6 deletions

View File

@@ -20,6 +20,8 @@
#include <imgui/imgui_impl_opengl3.h>
#include <Tracy.hpp>
#include "src/Subsystems/EngineSubsystemScript.h"
#include "src/Subsystems/TickableEngineSubsystem.h"
namespace Nuake
@@ -39,6 +41,8 @@ namespace Nuake
void Engine::Init()
{
ScriptingEngineNet::Get().AddListener<ScriptingEngineNet::GameAssemblyLoadedDelegate>(&Engine::OnScriptingEngineGameAssemblyLoaded);
AudioManager::Get().Initialize();
PhysicsManager::Get().Init();
NavManager::Get().Initialize();
@@ -53,6 +57,8 @@ namespace Nuake
RegisterCoreTypes::RegisterCoreComponents();
Modules::StartupModules();
InitializeCoreSubsystems();
}
void Engine::Tick()
@@ -92,6 +98,15 @@ namespace Nuake
}
}
// Tick all subsystems
for (auto subsystem : tickableSubsystems)
{
if (subsystem != nullptr)
{
subsystem->Tick();
}
}
// Dont update if no scene is loaded.
if (currentWindow->GetScene())
{
@@ -216,6 +231,46 @@ namespace Nuake
return currentProject;
}
Ref<EngineSubsystemScript> Engine::GetScriptedSubsystem(const std::string& subsystemName)
{
if (scriptedSubsystemMap.contains(subsystemName))
{
return scriptedSubsystemMap[subsystemName];
}
return nullptr;
}
void Engine::InitializeCoreSubsystems()
{
}
void Engine::OnScriptingEngineGameAssemblyLoaded()
{
subsystems.clear();
scriptedSubsystemMap.clear();
auto& gameAssembly = ScriptingEngineNet::Get().GetGameAssembly();
auto scriptTypeEngineSubsystem = gameAssembly.GetType("Nuake.Net.EngineSubsystem");
const auto& types = gameAssembly.GetTypes();
for (const auto& type : types)
{
// Initialize all subsystems
if (type->IsSubclassOf(scriptTypeEngineSubsystem))
{
const std::string typeName = std::string(type->GetFullName());
Logger::Log("Creating Scripted Subsystem " + typeName);
Coral::ManagedObject scriptedSubsystem = type->CreateInstance();
Ref<EngineSubsystemScript> subsystemScript = CreateRef<EngineSubsystemScript>(scriptedSubsystem);
subsystems.push_back(subsystemScript);
scriptedSubsystemMap[typeName] = subsystemScript;
}
}
}
bool Engine::LoadProject(Ref<Project> project)
{
currentProject = project;
@@ -236,4 +291,4 @@ namespace Nuake
{
return currentWindow;
}
}
}