diff --git a/Editor/Source/Editor.cpp b/Editor/Source/Editor.cpp index 8d41549d..a77f3567 100644 --- a/Editor/Source/Editor.cpp +++ b/Editor/Source/Editor.cpp @@ -91,6 +91,11 @@ LaunchSettings ParseLaunchSettings(const std::vector& arguments) launchSettings.monitor = stoi(arguments[i + 1]); } } + else if (arg == "--generate-bindings") + { + // Set editor window monitor + launchSettings.generateBindings = true; + } else if (argumentSize == 2 && Nuake::FileSystem::FileExists(arg)) { if (Nuake::String::EndsWith(arg, ".project")) diff --git a/Editor/Source/Editor/EditorApplication.cpp b/Editor/Source/Editor/EditorApplication.cpp index 05d3c1b2..1d04fb3a 100644 --- a/Editor/Source/Editor/EditorApplication.cpp +++ b/Editor/Source/Editor/EditorApplication.cpp @@ -7,6 +7,7 @@ #include "Nuake/UI/NuakeUI.h" #include "Nuake/UI/UIInputManager.h" +#include "Nuake/Modules/ModuleDB.h" void EditorApplication::OnInit() { @@ -14,7 +15,14 @@ void EditorApplication::OnInit() Engine::Init(); // Register bakers, these can convert files into nuake resources - + if (m_LaunchSettings.generateBindings) + { + ModuleDB::Get().GenerateModuleAPI(); + + Logger::Log("Generated Bindings"); + m_Window->Close(); + return; + } m_Window = Engine::GetCurrentWindow(); m_Window->SetSize({ m_Specification.WindowWidth, m_Specification.WindowHeight }); diff --git a/Editor/Source/Editor/LaunchSettings.h b/Editor/Source/Editor/LaunchSettings.h index f5e03e20..7819a58b 100644 --- a/Editor/Source/Editor/LaunchSettings.h +++ b/Editor/Source/Editor/LaunchSettings.h @@ -5,6 +5,7 @@ struct LaunchSettings { int32_t monitor = 1; + bool generateBindings = false; Nuake::Vector2 resolution = { 1100, 630 }; std::string windowTitle = "Nuake Editor "; std::string projectPath; diff --git a/Editor/premake5.lua b/Editor/premake5.lua index d5fc6f85..68db4339 100644 --- a/Editor/premake5.lua +++ b/Editor/premake5.lua @@ -100,4 +100,3 @@ project "Editor" filter "configurations:Release" runtime "Release" optimize "on" - diff --git a/Nuake/Source/Engine.cpp b/Nuake/Source/Engine.cpp index e40bc3a3..00bf780e 100644 --- a/Nuake/Source/Engine.cpp +++ b/Nuake/Source/Engine.cpp @@ -163,12 +163,12 @@ namespace Nuake const float scaledFixedTimestep = fixedUpdateRate * timeScale; currentWindow->FixedUpdate(scaledFixedTimestep); - Modules::FixedUpdate(scaledFixedTimestep); + ModuleDB::Get().FixedUpdate(scaledFixedTimestep); fixedUpdateDifference -= fixedUpdateRate; } - Modules::Update(scaledTimeStep); + ModuleDB::Get().Update(scaledTimeStep); Input::Update(); } diff --git a/Nuake/Source/Nuake/Application/Application.h b/Nuake/Source/Nuake/Application/Application.h index e22f18cd..fbba6a2b 100644 --- a/Nuake/Source/Nuake/Application/Application.h +++ b/Nuake/Source/Nuake/Application/Application.h @@ -18,6 +18,7 @@ namespace Nuake { bool VSync = true; std::string WorkingDirectory = ""; bool Headless = false; + bool GenerateBindings = false; }; class Application diff --git a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp index d093aa11..f834b254 100644 --- a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp +++ b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp @@ -10,6 +10,11 @@ using namespace Nuake; +void HelloWorld() +{ + Logger::Log("Hello World"); +} + float Volume = 1.0f; void SetVolume(float volume) { @@ -22,6 +27,11 @@ void SetMuted(bool muted) Muted = muted; } +void SetName(const std::string& name) +{ + Logger::Log("SetName: " + name); +} + NUAKEMODULE(AudioModule) void AudioModule_Startup() { @@ -37,6 +47,8 @@ void AudioModule_Startup() // Exposed functions(scripting API) module.BindFunction("SetVolume", "volume"); module.BindFunction("SetMuted", "muted"); + module.BindFunction("HelloWorld"); + module.BindFunction("SetName", "name"); // Register custom component & system module.RegisterComponent(); diff --git a/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp b/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp index b7d7c748..6946479e 100644 --- a/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp +++ b/Nuake/Source/Nuake/Modules/ExampleModule/ExampleModule.cpp @@ -57,7 +57,7 @@ public: }; -void ExampleModuleLog(const std::string& hi) +void ExampleModuleLog(NativeString hi) { Nuake::Logger::Log(hi, "ExampleModule", Nuake::VERBOSE); } @@ -81,7 +81,7 @@ void ExampleModule_Startup() // This is to expose functions to the rest of the engine module.BindFunction("ExampleFunction"); - module.BindFunction("ExampleModuleLog", "hi"); + module.BindFunction("ExampleModuleLog16", "hi2"); // The module can hook to certain events module.OnUpdate.AddStatic([](float ts) diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.cpp b/Nuake/Source/Nuake/Modules/ModuleDB.cpp index 53f588f2..c5060dda 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.cpp +++ b/Nuake/Source/Nuake/Modules/ModuleDB.cpp @@ -35,7 +35,7 @@ json ModuleDB::GenerateModuleAPI() { std::string argType = std::string(func.arg(k).info().name()); - if (argType == "class std::basic_string,class std::allocator >") + if (argType == "class Coral::String" || argType == "class std::basic_string,class std::allocator >") { argType = "string"; } diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.h b/Nuake/Source/Nuake/Modules/ModuleDB.h index 9affef2d..b238998b 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.h +++ b/Nuake/Source/Nuake/Modules/ModuleDB.h @@ -15,6 +15,10 @@ #include +#include + +using NativeString = Coral::String; + class ModuleInstance { public: @@ -104,9 +108,12 @@ public: \ } \ \ + + #define NUAKEMODULE(moduleName) \ using TypeNameMap = std::map; \ \ + \ class moduleName : public ModuleInstance \ { \ public: \ @@ -212,6 +219,24 @@ namespace Nuake return *(T*)std::any_cast(Modules[unmangledName]); } + void FixedUpdate(float ts) + { + for (auto& moduleName : GetModules()) + { + auto& module = GetBaseImpl(moduleName); + module.OnFixedUpdate.Broadcast(ts); + } + } + + void Update(float ts) + { + for (auto& moduleName : GetModules()) + { + auto& module = GetBaseImpl(moduleName); + module.OnUpdate.Broadcast(ts); + } + } + template T& GetModule() { diff --git a/Nuake/Source/Nuake/Modules/Modules.cpp b/Nuake/Source/Nuake/Modules/Modules.cpp index 02b814e8..8e9d7f0b 100644 --- a/Nuake/Source/Nuake/Modules/Modules.cpp +++ b/Nuake/Source/Nuake/Modules/Modules.cpp @@ -6,7 +6,6 @@ #include "ExampleModule/ExampleModule.h" #include "Nuake/Core/Logger.h" -#include "Nuake/Modules/ModuleDB.h" void Nuake::Modules::StartupModules() { @@ -18,26 +17,6 @@ void Nuake::Modules::StartupModules() ExampleModule_Startup(); } -void Nuake::Modules::FixedUpdate(float ts) -{ - auto& moduleDB = ModuleDB::Get(); - for (auto& moduleName : moduleDB.GetModules()) - { - auto& module = moduleDB.GetBaseImpl(moduleName); - module.OnFixedUpdate.Broadcast(ts); - } -} - -void Nuake::Modules::Update(float ts) -{ - auto& moduleDB = ModuleDB::Get(); - for (auto& moduleName : moduleDB.GetModules()) - { - auto& module = moduleDB.GetBaseImpl(moduleName); - module.OnUpdate.Broadcast(ts); - } -} - void Nuake::Modules::ShutdownModules() { Logger::Log("Shutting down AssimpModule", "modules"); diff --git a/Nuake/Source/Nuake/Modules/Modules.h b/Nuake/Source/Nuake/Modules/Modules.h index 825c12e1..20ed9e09 100644 --- a/Nuake/Source/Nuake/Modules/Modules.h +++ b/Nuake/Source/Nuake/Modules/Modules.h @@ -12,8 +12,6 @@ namespace Nuake public: static void StartupModules(); - static void FixedUpdate(float ts); - static void Update(float ts); static void ShutdownModules(); }; } \ No newline at end of file diff --git a/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp b/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp index 9c7b22ba..57faf679 100644 --- a/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp @@ -72,7 +72,6 @@ namespace Nuake // Check if we have an .sln in the project. const std::string absoluteAssemblyPath = FileSystem::Root + m_NetDirectory + "/" + m_EngineAssemblyName; - if (!FileSystem::FileExists(m_EngineAssemblyName, true)) { isInitialized = false; diff --git a/Nuake/Source/Nuake/Window.cpp b/Nuake/Source/Nuake/Window.cpp index 54331f1a..ff6f5690 100644 --- a/Nuake/Source/Nuake/Window.cpp +++ b/Nuake/Source/Nuake/Window.cpp @@ -46,6 +46,11 @@ GLFWwindow* Window::GetHandle() return this->window; } +void Window::Close() +{ + glfwSetWindowShouldClose(this->window, true); +} + bool Window::ShouldClose() { return glfwWindowShouldClose(this->window); diff --git a/Nuake/Source/Nuake/Window.h b/Nuake/Source/Nuake/Window.h index a7e08d8d..d92bf151 100644 --- a/Nuake/Source/Nuake/Window.h +++ b/Nuake/Source/Nuake/Window.h @@ -27,6 +27,7 @@ namespace Nuake public: GLFWwindow* GetHandle(); + void Close(); bool ShouldClose(); int Init(); diff --git a/NuakeNet/Source/Generated/AudioModule.cs b/NuakeNet/Source/Generated/AudioModule.cs index f853bed3..431af293 100644 --- a/NuakeNet/Source/Generated/AudioModule.cs +++ b/NuakeNet/Source/Generated/AudioModule.cs @@ -17,5 +17,19 @@ namespace Nuake.Net Internals.AudioModuleSetMutedICall(muted); } } + public static void HelloWorld() + { + unsafe + { + Internals.AudioModuleHelloWorldICall(); + } + } + public static void SetName(string name) + { + unsafe + { + Internals.AudioModuleSetNameICall(name); + } + } } } diff --git a/NuakeNet/Source/Generated/ExampleModule.cs b/NuakeNet/Source/Generated/ExampleModule.cs index 2b0ced88..34ad4fb2 100644 --- a/NuakeNet/Source/Generated/ExampleModule.cs +++ b/NuakeNet/Source/Generated/ExampleModule.cs @@ -10,11 +10,11 @@ namespace Nuake.Net Internals.ExampleModuleExampleFunctionICall(); } } - public static void ExampleModuleLog(string hi) + public static void ExampleModuleLog16(string hi2) { unsafe { - Internals.ExampleModuleExampleModuleLogICall(hi); + Internals.ExampleModuleExampleModuleLog16ICall(hi2); } } } diff --git a/NuakeNet/Source/Generated/Internals.cs b/NuakeNet/Source/Generated/Internals.cs index 5146440c..36f199a1 100644 --- a/NuakeNet/Source/Generated/Internals.cs +++ b/NuakeNet/Source/Generated/Internals.cs @@ -6,10 +6,12 @@ public class Internals // AudioModule internal static unsafe delegate*AudioModuleSetVolumeICall; internal static unsafe delegate*AudioModuleSetMutedICall; + internal static unsafe delegate*AudioModuleHelloWorldICall; + internal static unsafe delegate*AudioModuleSetNameICall; // ExampleModule internal static unsafe delegate*ExampleModuleExampleFunctionICall; - internal static unsafe delegate*ExampleModuleExampleModuleLogICall; + internal static unsafe delegate*ExampleModuleExampleModuleLog16ICall; } } diff --git a/NuakeNet/premake5.lua b/NuakeNet/premake5.lua index 415731f4..0ac30747 100644 --- a/NuakeNet/premake5.lua +++ b/NuakeNet/premake5.lua @@ -27,3 +27,11 @@ project "NuakeNet" "Coral.Managed" } + prebuildcommands { + 'dotnet dotnet run --project %{wks.location}NuakeNetGenerator/NuakeNetGenerator.csproj' + } + + postbuildcommands { + '{COPYFILE} "%{wks.location}NuakeNet/Build/%{cfg.buildcfg}/Binaries/NuakeNet.dll" "%{wks.location}Editor/Build/%{cfg.buildcfg}/Binaries/NuakeNet.dll"' + } +