diff --git a/Nuake/Source/Engine.cpp b/Nuake/Source/Engine.cpp index 6945ee89..e40bc3a3 100644 --- a/Nuake/Source/Engine.cpp +++ b/Nuake/Source/Engine.cpp @@ -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); diff --git a/Nuake/Source/Nuake/Core/Object/Object.h b/Nuake/Source/Nuake/Core/Object/Object.h index 5037a2b3..ed56455b 100644 --- a/Nuake/Source/Nuake/Core/Object/Object.h +++ b/Nuake/Source/Nuake/Core/Object/Object.h @@ -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, diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.h b/Nuake/Source/Nuake/Modules/ModuleDB.h index 32bde48a..9affef2d 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.h +++ b/Nuake/Source/Nuake/Modules/ModuleDB.h @@ -122,7 +122,8 @@ public: \ entt::id_type typeId = entt::hashed_string(name.c_str()); \ ClassFactory.func(typeId) \ .prop(Nuake::HashedName::DisplayName, name) \ - .prop(Nuake::HashedName::ArgsName, std::vector({argNames...})); \ + .prop(Nuake::HashedName::ArgsName, std::vector({argNames...}))\ + .prop(Nuake::HashedUserValue::FuncPtr, (void*)T); \ } \ \ template \ diff --git a/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.cpp b/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.cpp new file mode 100644 index 00000000..b4d78e73 --- /dev/null +++ b/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.cpp @@ -0,0 +1,43 @@ +#include "ModulesAPI.h" + +#include "Nuake/Modules/ModuleDB.h" + +#include +#include + +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()->c_str(); + // const std::string& fullName = modulePrefix + funcNameStd; + // + // auto funcPtrMeta = func.prop(HashedUserValue::FuncPtr); + // auto funcPtr = funcPtrMeta.value().try_cast(); + // RegisterMethod(fullName, &SetVolume); + // } + //} + } + +} + diff --git a/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.h b/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.h new file mode 100644 index 00000000..88a78bf0 --- /dev/null +++ b/Nuake/Source/Nuake/Scripting/NetModules/ModulesAPI.h @@ -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; + + }; +} \ No newline at end of file diff --git a/Nuake/Source/Nuake/Scripting/NetModules/NetAPIModule.h b/Nuake/Source/Nuake/Scripting/NetModules/NetAPIModule.h index 50ac35ca..09d9fb09 100644 --- a/Nuake/Source/Nuake/Scripting/NetModules/NetAPIModule.h +++ b/Nuake/Source/Nuake/Scripting/NetModules/NetAPIModule.h @@ -8,6 +8,8 @@ namespace Nuake { class NetAPIModule { public: + bool isModule = false; + using MethodMap = std::unordered_map; virtual const std::string GetModuleName() const = 0; diff --git a/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp b/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp index a6127271..1ef4e63f 100644 --- a/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp +++ b/Nuake/Source/Nuake/Scripting/ScriptingEngineNet.cpp @@ -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 @@ -61,7 +61,8 @@ namespace Nuake CreateRef(), CreateRef(), CreateRef(), - CreateRef() + CreateRef(), + CreateRef(), }; 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); + } } } diff --git a/NuakeNet/Source/Generated/AudioModule.cs b/NuakeNet/Source/Generated/AudioModule.cs index 1b7e24f4..fbe8f8f4 100644 --- a/NuakeNet/Source/Generated/AudioModule.cs +++ b/NuakeNet/Source/Generated/AudioModule.cs @@ -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); } } } diff --git a/NuakeNet/Source/Generated/ExampleModule.cs b/NuakeNet/Source/Generated/ExampleModule.cs index 2dc0a1ed..425cd06b 100644 --- a/NuakeNet/Source/Generated/ExampleModule.cs +++ b/NuakeNet/Source/Generated/ExampleModule.cs @@ -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); - } - } - } + } diff --git a/NuakeNet/Source/Generated/Internals.cs b/NuakeNet/Source/Generated/Internals.cs index f55f2aaf..0198233e 100644 --- a/NuakeNet/Source/Generated/Internals.cs +++ b/NuakeNet/Source/Generated/Internals.cs @@ -1,12 +1,11 @@ using Coral.Managed.Interop; -public class Internals +namespace Nuake.Net { - // AudioModule - public static unsafe delegate* AudioModuleSetVolumeICall; - public static unsafe delegate* AudioModuleSetMutedICall; - - // ExampleModule - public static unsafe delegate* ExampleModuleExampleFunctionICall; - public static unsafe delegate* ExampleModuleExampleModuleLogICall; - + public class Internals + { + // AudioModule + public static unsafe delegate* SetVolumeICall; + } } + +