From 6037d482104d1609b4d647a417cba54558c47c5c Mon Sep 17 00:00:00 2001 From: antopilo Date: Sat, 5 Apr 2025 16:38:15 -0400 Subject: [PATCH] Added support for modules to specifiy DLLs and Libs to be used by the engine --- Editor/premake5.lua | 29 ++++++++++- Nuake/Source/Engine.cpp | 10 +++- Nuake/Source/Engine.h | 2 +- Nuake/Source/Nuake/Modules/ModuleDB.h | 18 +++++++ Nuake/Source/Nuake/Modules/Modules.lua | 15 ++++++ NuakeNetGenerator/Source/Generator.cs | 66 +++++++++++++++----------- 6 files changed, 108 insertions(+), 32 deletions(-) diff --git a/Editor/premake5.lua b/Editor/premake5.lua index 68db4339..bfc89698 100644 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -1,3 +1,5 @@ +include "Nuake/Source/Nuake/Modules/Modules.lua" + project "Editor" targetname ("Nuake Engine") @@ -75,6 +77,30 @@ project "Editor" "vma" } + libdirs + { + "%{cfg.debugdir}/", + } + + local libCopyCmds = {} + + local modules = {} + if _ACTION then + modules = loadModules("../Nuake/Source/Nuake/Modules") + print(#modules) + for _, m in ipairs(modules) do + print("m") + end + local libTargetDir = "%{cfg.debugdir}/" + local commands = getModuleLibCopy(modules, libTargetDir) + for _, command in ipairs(commands) do + table.insert(libCopyCmds, command) + print(command) + end + + end + + prebuildcommands { '{ECHO} "Copying dxcompiler.dll to Working directory..."', '{COPYFILE} "%{wks.location}Nuake/Thirdparty/dxc/bin/x64/dxcompiler.dll" "%{cfg.debugdir}/"', @@ -82,7 +108,8 @@ project "Editor" '{COPYFILE} "%{wks.location}Nuake/Thirdparty/Coral/Coral.Managed/bin/%{cfg.buildcfg}/Coral.Managed.dll" "%{cfg.debugdir}/"', '{COPYFILE} "%{wks.location}Nuake/Thirdparty/Coral/Coral.Managed/bin/%{cfg.buildcfg}/Coral.Managed.runtimeconfig.json" "%{cfg.debugdir}/"', '{COPYFILE} "%{wks.location}NuakeNet/Build/%{cfg.buildcfg}/Binaries/NuakeNet.dll" "%{cfg.debugdir}/"', - 'xcopy /E /I /Y "%{wks.location}Data" "%{cfg.debugdir}\\Resources"' + 'xcopy /E /I /Y "%{wks.location}Data" "%{cfg.debugdir}\\Resources"', + table.unpack(libCopyCmds) } filter { "system:windows", "action:vs*"} diff --git a/Nuake/Source/Engine.cpp b/Nuake/Source/Engine.cpp index 00bf780e..c2b95529 100644 --- a/Nuake/Source/Engine.cpp +++ b/Nuake/Source/Engine.cpp @@ -207,7 +207,7 @@ namespace Nuake { GetCurrentScene()->OnExit(); Input::ShowMouse(); - gameState = GameState::Stopped; + SetGameState(GameState::Stopped); } } @@ -244,6 +244,12 @@ namespace Nuake Window::Get()->EndDraw(); } + void Engine::SetGameState(GameState state) + { + gameState = state; + ModuleDB::Get().OnGameStateChanged(state); + } + void Engine::Close() { glfwTerminate(); @@ -265,6 +271,8 @@ namespace Nuake if (result) { OnSceneLoaded.Broadcast(scene); + + ModuleDB::Get().OnSceneLoaded(scene); } return result; diff --git a/Nuake/Source/Engine.h b/Nuake/Source/Engine.h index 408cece4..53f2f733 100644 --- a/Nuake/Source/Engine.h +++ b/Nuake/Source/Engine.h @@ -28,7 +28,7 @@ namespace Nuake static void Draw(); // Start new frame static void EndDraw(); // Swap buffer - static void SetGameState(GameState state) { gameState = state; } + static void SetGameState(GameState state); static GameState GetGameState() { return gameState; } static bool IsPlayMode() { return gameState == GameState::Playing; } diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.h b/Nuake/Source/Nuake/Modules/ModuleDB.h index b238998b..a3586a1e 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.h +++ b/Nuake/Source/Nuake/Modules/ModuleDB.h @@ -219,6 +219,24 @@ namespace Nuake return *(T*)std::any_cast(Modules[unmangledName]); } + void OnGameStateChanged(GameState state) + { + for (auto& moduleName : GetModules()) + { + auto& module = GetBaseImpl(moduleName); + module.OnGameStateChanged.Broadcast(state); + } + } + + void OnSceneLoaded(Ref scene) + { + for (auto& moduleName : GetModules()) + { + auto& module = GetBaseImpl(moduleName); + module.OnSceneLoad.Broadcast(scene); + } + } + void FixedUpdate(float ts) { for (auto& moduleName : GetModules()) diff --git a/Nuake/Source/Nuake/Modules/Modules.lua b/Nuake/Source/Nuake/Modules/Modules.lua index 7a70f536..f5f77ed9 100644 --- a/Nuake/Source/Nuake/Modules/Modules.lua +++ b/Nuake/Source/Nuake/Modules/Modules.lua @@ -25,6 +25,21 @@ function loadModules(modulesDir) return modules end +function getModuleLibCopy(modules, outDir) + local libsCopyCommands = {} + for _, module in ipairs(modules) do + if module.libs then + for _, lib in ipairs(module.libs) do + print("Found module libs \"".. lib) + table.insert(libsCopyCommands, '{COPYFILE} "%{wks.location}Nuake/Source/Nuake/Modules/' .. module._name .. '/' .. lib ..'" "' .. outDir .. '/' .. '"') + end + end + + end + + return libsCopyCommands +end + -- Function to generate the final C++ file with startup and shutdown functions function generateModulesFile(modules, outputFilePath, sourceDir) local outputFile = io.open(outputFilePath, "w") diff --git a/NuakeNetGenerator/Source/Generator.cs b/NuakeNetGenerator/Source/Generator.cs index 9b3d49eb..336147f2 100644 --- a/NuakeNetGenerator/Source/Generator.cs +++ b/NuakeNetGenerator/Source/Generator.cs @@ -55,16 +55,20 @@ class Generator foreach (var module in bindings.Modules) { generatedInternals += $" // {module.Name}\n"; - foreach (var function in module.Functions) + + if(module.Functions != null) { - generatedInternals += $" internal static unsafe delegate*<"; - - if (function.NumArgs > 0) + foreach (var function in module.Functions) { - generatedInternals += $"{string.Join(", ", function.Args.Select(a => ConvertTypes(a.Type)))},"; - } + generatedInternals += $" internal static unsafe delegate*<"; - generatedInternals += $"{function.ReturnType}>{module.Name}{function.Name}ICall;\n"; + if (function.NumArgs > 0) + { + generatedInternals += $"{string.Join(", ", function.Args.Select(a => ConvertTypes(a.Type)))},"; + } + + generatedInternals += $"{function.ReturnType}>{module.Name}{function.Name}ICall;\n"; + } } generatedInternals += "\n"; @@ -84,33 +88,37 @@ class Generator moduleApi += " public class " + module.Name + "\n"; moduleApi += " {\n"; - foreach (Function func in module.Functions) + if(module.Functions != null) { - moduleApi += " public static " + func.ReturnType + " " + func.Name + "("; - if (func.NumArgs > 0) + foreach (Function func in module.Functions) { - moduleApi += string.Join(", ", func.Args.Select(a => a.Type + " " + a.Name)); - } - moduleApi += ")\n"; - moduleApi += " {\n"; - moduleApi += " unsafe\n"; - moduleApi += " {\n"; - if (func.ReturnType != "void") - { - moduleApi += $" return "; - } - moduleApi += $" Internals.{module.Name}{func.Name}ICall("; - if (func.NumArgs > 0) - { - moduleApi += string.Join(", ", func.Args.Select(a => a.Name)); - } + moduleApi += " public static " + func.ReturnType + " " + func.Name + "("; + if (func.NumArgs > 0) + { + moduleApi += string.Join(", ", func.Args.Select(a => a.Type + " " + a.Name)); + } + moduleApi += ")\n"; + moduleApi += " {\n"; + moduleApi += " unsafe\n"; + moduleApi += " {\n"; + if (func.ReturnType != "void") + { + moduleApi += $" return "; + } + moduleApi += $" Internals.{module.Name}{func.Name}ICall("; + if (func.NumArgs > 0) + { + moduleApi += string.Join(", ", func.Args.Select(a => a.Name)); + } - moduleApi += ");\n"; + moduleApi += ");\n"; - moduleApi += " }\n"; - moduleApi += " }\n"; + moduleApi += " }\n"; + moduleApi += " }\n"; - } + } + } + moduleApi += " }\n"; moduleApi += "}\n"; return moduleApi;