First pass scriptable subsystems that has the same lifetime of the engine
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user