Added support for modules to specifiy DLLs and Libs to be used by the engine

This commit is contained in:
antopilo
2025-04-05 16:38:15 -04:00
parent 5bb4303eff
commit 6037d48210
6 changed files with 108 additions and 32 deletions

View File

@@ -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*"}

View File

@@ -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;

View File

@@ -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; }

View File

@@ -219,6 +219,24 @@ namespace Nuake
return *(T*)std::any_cast<ModuleInstance*>(Modules[unmangledName]);
}
void OnGameStateChanged(GameState state)
{
for (auto& moduleName : GetModules())
{
auto& module = GetBaseImpl(moduleName);
module.OnGameStateChanged.Broadcast(state);
}
}
void OnSceneLoaded(Ref<Scene> scene)
{
for (auto& moduleName : GetModules())
{
auto& module = GetBaseImpl(moduleName);
module.OnSceneLoad.Broadcast(scene);
}
}
void FixedUpdate(float ts)
{
for (auto& moduleName : GetModules())

View File

@@ -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")

View File

@@ -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;