mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-01 05:48:14 +03:00
Added basics for automatic C# -> C++ Bindings
This commit is contained in:
@@ -52,7 +52,6 @@ namespace Nuake
|
||||
{
|
||||
//Window::Get()->OnWindowSetScene().AddStatic(&Engine::OnWindowSetScene);
|
||||
|
||||
ScriptingEngineNet::Get().OnGameAssemblyLoaded().AddStatic(&Engine::OnScriptingEngineGameAssemblyLoaded);
|
||||
|
||||
PhysicsManager::Get().Init();
|
||||
NavManager::Get().Initialize();
|
||||
@@ -72,6 +71,9 @@ namespace Nuake
|
||||
|
||||
Modules::StartupModules();
|
||||
|
||||
ScriptingEngineNet::Get().OnGameAssemblyLoaded().AddStatic(&Engine::OnScriptingEngineGameAssemblyLoaded);
|
||||
|
||||
|
||||
// Writting bindings.json
|
||||
|
||||
Logger::Log("Exporting bindings.json", "modules", VERBOSE);
|
||||
|
||||
@@ -42,6 +42,11 @@ namespace Nuake
|
||||
NK_HASHED_STATIC_STR(ArgsName)
|
||||
};
|
||||
|
||||
struct HashedUserValue
|
||||
{
|
||||
NK_HASHED_STATIC_STR(FuncPtr)
|
||||
};
|
||||
|
||||
enum class ComponentTypeTrait : uint16_t
|
||||
{
|
||||
None = 0,
|
||||
|
||||
@@ -122,7 +122,8 @@ public: \
|
||||
entt::id_type typeId = entt::hashed_string(name.c_str()); \
|
||||
ClassFactory.func<T>(typeId) \
|
||||
.prop(Nuake::HashedName::DisplayName, name) \
|
||||
.prop(Nuake::HashedName::ArgsName, std::vector<const char*>({argNames...})); \
|
||||
.prop(Nuake::HashedName::ArgsName, std::vector<const char*>({argNames...}))\
|
||||
.prop(Nuake::HashedUserValue::FuncPtr, (void*)T); \
|
||||
} \
|
||||
\
|
||||
template<auto Func> \
|
||||
|
||||
43
Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.cpp
Normal file
43
Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.cpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#include "ModulesAPI.h"
|
||||
|
||||
#include "Nuake/Modules/ModuleDB.h"
|
||||
|
||||
#include <Coral/Array.hpp>
|
||||
#include <Coral/String.hpp>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
void SetVolume(float vol)
|
||||
{
|
||||
float myVolume = vol;
|
||||
return;
|
||||
}
|
||||
|
||||
void ModulesAPI::RegisterMethods()
|
||||
{
|
||||
isModule = true;
|
||||
|
||||
RegisterMethod("Internals.SetVolumeICall", &SetVolume);
|
||||
|
||||
//const std::string& internalPrefix = "Internal";
|
||||
//
|
||||
//for (auto& name : ModuleDB::Get().GetModules())
|
||||
//{
|
||||
// const std::string& modulePrefix = internalPrefix + ".";
|
||||
// auto meta = entt::resolve(entt::hashed_string(("class " + name).c_str()));
|
||||
// auto instance = ModuleDB::Get().GetBaseImpl(name).instance;
|
||||
// for (auto [id, func] : meta.func())
|
||||
// {
|
||||
// auto funcName = func.prop(HashedName::DisplayName);
|
||||
// const std::string funcNameStd = funcName.value().try_cast<std::string>()->c_str();
|
||||
// const std::string& fullName = modulePrefix + funcNameStd;
|
||||
//
|
||||
// auto funcPtrMeta = func.prop(HashedUserValue::FuncPtr);
|
||||
// auto funcPtr = funcPtrMeta.value().try_cast<void*>();
|
||||
// RegisterMethod(fullName, &SetVolume);
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
14
Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.h
Normal file
14
Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.h
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
#include "NetAPIModule.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
class ModulesAPI : public NetAPIModule
|
||||
{
|
||||
public:
|
||||
virtual const std::string GetModuleName() const override { return "Modules"; }
|
||||
|
||||
virtual void RegisterMethods() override;
|
||||
|
||||
};
|
||||
}
|
||||
@@ -8,6 +8,8 @@ namespace Nuake {
|
||||
class NetAPIModule
|
||||
{
|
||||
public:
|
||||
bool isModule = false;
|
||||
|
||||
using MethodMap = std::unordered_map<std::string, void*>;
|
||||
|
||||
virtual const std::string GetModuleName() const = 0;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "NetModules/InputNetAPI.h"
|
||||
#include "NetModules/SceneNetAPI.h"
|
||||
#include "NetModules/UINetAPI.h"
|
||||
|
||||
#include "NetModules/ModulesAPI.h"
|
||||
#include "Nuake/Scene/Components/BSPBrushComponent.h"
|
||||
|
||||
#include <filesystem>
|
||||
@@ -61,7 +61,8 @@ namespace Nuake
|
||||
CreateRef<EngineSubsystemNetAPI>(),
|
||||
CreateRef<InputNetAPI>(),
|
||||
CreateRef<SceneNetAPI>(),
|
||||
CreateRef<UINetAPI>()
|
||||
CreateRef<UINetAPI>(),
|
||||
CreateRef<ModulesAPI>(),
|
||||
};
|
||||
|
||||
for (auto& m : modules)
|
||||
@@ -166,8 +167,16 @@ namespace Nuake
|
||||
{
|
||||
for (const auto& [methodName, methodPtr] : netModule->GetMethods())
|
||||
{
|
||||
auto namespaceClassSplit = String::Split(methodName, '.');
|
||||
assembly.AddInternalCall(m_Scope + '.' + namespaceClassSplit[0], namespaceClassSplit[1], methodPtr);
|
||||
if(!netModule->isModule)
|
||||
{
|
||||
auto namespaceClassSplit = String::Split(methodName, '.');
|
||||
assembly.AddInternalCall(m_Scope + '.' + namespaceClassSplit[0], namespaceClassSplit[1], methodPtr);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto namespaceClassSplit = String::Split(methodName, '.');
|
||||
assembly.AddInternalCall(m_Scope + '.' + namespaceClassSplit[0], namespaceClassSplit[1], methodPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,13 @@
|
||||
using System;
|
||||
namespace Nuake
|
||||
namespace Nuake.Net
|
||||
{
|
||||
public static class AudioModule
|
||||
public class AudioModule
|
||||
{
|
||||
public static void SetVolume(float volume)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Internals.AudioModuleSetVolumeICall(volume);
|
||||
}
|
||||
}
|
||||
public static void SetMuted(bool muted)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Internals.AudioModuleSetMutedICall(muted);
|
||||
Internals.SetVolumeICall(volume);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
using System;
|
||||
namespace Nuake
|
||||
namespace Nuake.Net
|
||||
{
|
||||
public static class ExampleModule
|
||||
{
|
||||
public static void ExampleFunction()
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Internals.ExampleModuleExampleFunctionICall();
|
||||
}
|
||||
}
|
||||
public static void ExampleModuleLog(string hi)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
Internals.ExampleModuleExampleModuleLogICall(hi);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Coral.Managed.Interop;
|
||||
public class Internals
|
||||
namespace Nuake.Net
|
||||
{
|
||||
// AudioModule
|
||||
public static unsafe delegate*<float,void> AudioModuleSetVolumeICall;
|
||||
public static unsafe delegate*<bool,void> AudioModuleSetMutedICall;
|
||||
|
||||
// ExampleModule
|
||||
public static unsafe delegate*<void> ExampleModuleExampleFunctionICall;
|
||||
public static unsafe delegate*<NativeString,void> ExampleModuleExampleModuleLogICall;
|
||||
|
||||
public class Internals
|
||||
{
|
||||
// AudioModule
|
||||
public static unsafe delegate*<float, void> SetVolumeICall;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user