Now bindings works automatically and is smoooth, aslo strings work now

This commit is contained in:
antopilo
2025-04-04 19:01:01 -04:00
parent a516f09cf5
commit 5bb4303eff
19 changed files with 91 additions and 34 deletions

View File

@@ -91,6 +91,11 @@ LaunchSettings ParseLaunchSettings(const std::vector<std::string>& 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"))

View File

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

View File

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

View File

@@ -100,4 +100,3 @@ project "Editor"
filter "configurations:Release"
runtime "Release"
optimize "on"

View File

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

View File

@@ -18,6 +18,7 @@ namespace Nuake {
bool VSync = true;
std::string WorkingDirectory = "";
bool Headless = false;
bool GenerateBindings = false;
};
class Application

View File

@@ -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>("SetVolume", "volume");
module.BindFunction<SetMuted>("SetMuted", "muted");
module.BindFunction<HelloWorld>("HelloWorld");
module.BindFunction<SetName>("SetName", "name");
// Register custom component & system
module.RegisterComponent<Audio::AudioEmitterComponent>();

View File

@@ -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>("ExampleFunction");
module.BindFunction<ExampleModuleLog>("ExampleModuleLog", "hi");
module.BindFunction<ExampleModuleLog>("ExampleModuleLog16", "hi2");
// The module can hook to certain events
module.OnUpdate.AddStatic([](float ts)

View File

@@ -35,7 +35,7 @@ json ModuleDB::GenerateModuleAPI()
{
std::string argType = std::string(func.arg(k).info().name());
if (argType == "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >")
if (argType == "class Coral::String" || argType == "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >")
{
argType = "string";
}

View File

@@ -15,6 +15,10 @@
#include <entt/entt.hpp>
#include <Coral/String.hpp>
using NativeString = Coral::String;
class ModuleInstance
{
public:
@@ -104,9 +108,12 @@ public: \
} \
\
#define NUAKEMODULE(moduleName) \
using TypeNameMap = std::map<entt::id_type, std::string>; \
\
\
class moduleName : public ModuleInstance \
{ \
public: \
@@ -212,6 +219,24 @@ namespace Nuake
return *(T*)std::any_cast<ModuleInstance*>(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<typename T>
T& GetModule()
{

View File

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

View File

@@ -12,8 +12,6 @@ namespace Nuake
public:
static void StartupModules();
static void FixedUpdate(float ts);
static void Update(float ts);
static void ShutdownModules();
};
}

View File

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

View File

@@ -46,6 +46,11 @@ GLFWwindow* Window::GetHandle()
return this->window;
}
void Window::Close()
{
glfwSetWindowShouldClose(this->window, true);
}
bool Window::ShouldClose()
{
return glfwWindowShouldClose(this->window);

View File

@@ -27,6 +27,7 @@ namespace Nuake
public:
GLFWwindow* GetHandle();
void Close();
bool ShouldClose();
int Init();

View File

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

View File

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

View File

@@ -6,10 +6,12 @@ public class Internals
// AudioModule
internal static unsafe delegate*<float,void>AudioModuleSetVolumeICall;
internal static unsafe delegate*<bool,void>AudioModuleSetMutedICall;
internal static unsafe delegate*<void>AudioModuleHelloWorldICall;
internal static unsafe delegate*<NativeString,void>AudioModuleSetNameICall;
// ExampleModule
internal static unsafe delegate*<void>ExampleModuleExampleFunctionICall;
internal static unsafe delegate*<NativeString,void>ExampleModuleExampleModuleLogICall;
internal static unsafe delegate*<NativeString,void>ExampleModuleExampleModuleLog16ICall;
}
}

View File

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