Merge branch 'develop' of https://github.com/antopilo/Nuake into develop

This commit is contained in:
antopilo
2024-09-18 17:10:18 -04:00
16 changed files with 336 additions and 9 deletions

View File

@@ -1,10 +1,15 @@
#include "EngineNetAPI.h"
#include <Coral/String.hpp>
#include <src/Core/Maths.h>
#include <Engine.h>
#include "src/Core/Maths.h"
#include "src/Rendering/SceneRenderer.h"
#include "Engine.h"
#include "src/Physics/PhysicsManager.h"
#include <Coral/String.hpp>
#include <Coral/ManagedObject.hpp>
#include <Coral/Array.hpp>
#include <src/Physics/PhysicsManager.h>
#include "Coral/Type.hpp"
#include "..\..\Subsystems\EngineSubsystemScriptable.h"
namespace Nuake {
@@ -112,10 +117,22 @@ namespace Nuake {
Engine::QueueSceneSwitch(std::string(path));
}
Coral::ManagedObject GetEngineSubsystemByName(Coral::String subsystemName)
{
const Ref<EngineSubsystemScriptable> scriptedSubsystem = Engine::GetScriptedSubsystem(subsystemName);
if (scriptedSubsystem == nullptr)
{
return {};
}
return scriptedSubsystem->GetManagedObjectInstance();
}
void EngineNetAPI::RegisterMethods()
{
RegisterMethod("Engine.LoadSceneIcall", &LoadScene);
RegisterMethod("Engine.LoggerLogIcall", (void*)(&Log));
RegisterMethod("Engine.GetSubsystemByNameIcall", &GetEngineSubsystemByName);
// Debug renderer
RegisterMethod("Debug.DrawLineIcall", &DrawLine);

View File

@@ -0,0 +1,37 @@
#include "EngineSubsystemNetAPI.h"
#include "Engine.h"
#include "src/Subsystems/EngineSubsystemScriptable.h"
namespace Nuake
{
void SetCanTick(int subsystemId, bool tick)
{
auto subsystem = Engine::GetScriptedSubsystem(subsystemId);
if (subsystem == nullptr)
{
Logger::Log("Subsystem isn't a valid scripted subsystem", "EngineSubsystemNetAPI", WARNING);
return;
}
subsystem->SetCanTick(tick);
}
bool GetCanTick(int subsystemId)
{
auto subsystem = Engine::GetScriptedSubsystem(subsystemId);
if (subsystem == nullptr)
{
Logger::Log("Subsystem isn't a valid scripted subsystem", "EngineSubsystemNetAPI", WARNING);
return false;
}
return subsystem->CanEverTick();
}
void EngineSubsystemNetAPI::RegisterMethods()
{
RegisterMethod("EngineSubsystem.SetCanTickIcall", &SetCanTick);
RegisterMethod("EngineSubsystem.GetCanTickIcall", &GetCanTick);
}
}

View File

@@ -0,0 +1,14 @@
#pragma once
#include "NetAPIModule.h"
namespace Nuake
{
class EngineSubsystemNetAPI : public Nuake::NetAPIModule
{
public:
virtual const std::string GetModuleName() const override { return "EngineSubsystem"; }
virtual void RegisterMethods() override;
};
}

View File

@@ -8,6 +8,7 @@
#include "src/Scene/Components/NetScriptComponent.h"
#include "NetModules/EngineNetAPI.h"
#include "NetModules/EngineSubsystemNetAPI.h"
#include "NetModules/InputNetAPI.h"
#include "NetModules/SceneNetAPI.h"
#include "NetModules/UINetAPI.h"
@@ -53,6 +54,7 @@ namespace Nuake
modules =
{
CreateRef<EngineNetAPI>(),
CreateRef<EngineSubsystemNetAPI>(),
CreateRef<InputNetAPI>(),
CreateRef<SceneNetAPI>(),
CreateRef<UINetAPI>()
@@ -329,6 +331,15 @@ namespace Nuake
return widgetUUIDToManagedObjects[std::make_pair(canvasUUID, uuid)];
}
template<class T>
void ScriptingEngineNet::AddListener(const T& delegate) {}
template <>
void ScriptingEngineNet::AddListener<ScriptingEngineNet::GameAssemblyLoadedDelegate>(const GameAssemblyLoadedDelegate& delegate)
{
listenersGameAssemblyLoaded.push_back(delegate);
}
std::vector<CompilationError> ScriptingEngineNet::BuildProjectAssembly(Ref<Project> project)
{
const std::string sanitizedProjectName = String::Sanitize(project->Name);
@@ -529,6 +540,11 @@ namespace Nuake
}
}
}
for (auto& delegate : listenersGameAssemblyLoaded)
{
delegate();
}
}
}

View File

@@ -74,6 +74,9 @@ namespace Nuake
class ScriptingEngineNet
{
public:
using GameAssemblyLoadedDelegate = std::function<void()>;
public:
static ScriptingEngineNet& Get();
@@ -84,6 +87,7 @@ namespace Nuake
Coral::HostInstance* GetHostInstance() { return hostInstance; }
Coral::AssemblyLoadContext& GetLoadContext() { return loadContext; }
Coral::ManagedAssembly GetNuakeAssembly() const { return nuakeAssembly; }
Coral::ManagedAssembly& GetGameAssembly() { return gameAssembly; }
Coral::ManagedAssembly ReloadEngineAPI(Coral::AssemblyLoadContext & context);
@@ -111,6 +115,9 @@ namespace Nuake
std::unordered_map<std::string, NetGameScriptObject> GetPointEntities() const { return pointEntityTypes; }
std::unordered_map<std::string, UIWidgetObject> GetUIWidgets() const { return uiWidgets; }
template<class T> void AddListener(const T& delegate);
template<> void AddListener(const GameAssemblyLoadedDelegate& delegate);
private:
const std::string m_Scope = "Nuake.Net";
const std::string m_EngineAssemblyName = "NuakeNet.dll";
@@ -141,6 +148,8 @@ namespace Nuake
std::unordered_map<uint32_t, Coral::ManagedObject> entityToManagedObjects;
std::map<std::pair<UUID, UUID>, Coral::ManagedObject> widgetUUIDToManagedObjects;
std::vector<GameAssemblyLoadedDelegate> listenersGameAssemblyLoaded;
ScriptingEngineNet();
~ScriptingEngineNet();
@@ -149,4 +158,4 @@ namespace Nuake
std::string GenerateGUID();
std::vector<CompilationError> ExtractErrors(const std::string& input);
};
}
}