diff --git a/Nuake/Source/Nuake/Core/RegisterCoreTypes.cpp b/Nuake/Source/Nuake/Core/RegisterCoreTypes.cpp index bfb8cfab..399922e3 100644 --- a/Nuake/Source/Nuake/Core/RegisterCoreTypes.cpp +++ b/Nuake/Source/Nuake/Core/RegisterCoreTypes.cpp @@ -1,6 +1,5 @@ #include "RegisterCoreTypes.h" -#include "Nuake/Scene/Components/AudioEmitterComponent.h" #include "Nuake/Scene/Components/BoneComponent.h" #include "Nuake/Scene/Components/BoxCollider.h" #include "Nuake/Scene/Components/CameraComponent.h" @@ -44,7 +43,6 @@ namespace Nuake CameraComponent::InternalInitializeClass(); BoxColliderComponent::InternalInitializeClass(); BoneComponent::InternalInitializeClass(); - AudioEmitterComponent::InternalInitializeClass(); SkyComponent::InternalInitializeClass(); EnvironmentComponent::InternalInitializeClass(); } diff --git a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp index ff8405cf..d093aa11 100644 --- a/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp +++ b/Nuake/Source/Nuake/Modules/AudioModule/AudioModule.cpp @@ -6,16 +6,9 @@ #include #include "Nuake/Audio/AudioManager.h" +#include "Nuake/Scene/Components/AudioEmitterComponent.h" -void PlayAudio(int id, Nuake::Matrix4 volume) -{ - -} - -void StopAudio() -{ - -} +using namespace Nuake; float Volume = 1.0f; void SetVolume(float volume) @@ -32,22 +25,24 @@ void SetMuted(bool muted) NUAKEMODULE(AudioModule) void AudioModule_Startup() { - using namespace Nuake; - + // Register module info auto& module = ModuleDB::Get().RegisterModule(); module.Name = "AudioModule"; module.Description = "Core audio module"; + // Exposed settings module.RegisterSetting<&Volume>("Volume"); module.RegisterSetting<&Muted>("Muted"); - module.BindFunction("PlayAudio", "id", "volume"); - module.BindFunction("StopAudio"); + // Exposed functions(scripting API) + module.BindFunction("SetVolume", "volume"); + module.BindFunction("SetMuted", "muted"); - AudioManager::Get().Initialize(); - - SceneSystemDB::Get().RegisterSceneSystem(); + // Register custom component & system + module.RegisterComponent(); + module.RegisterComponentSystem(); + // Register module hook on events module.OnUpdate.AddStatic([](float ts) { auto& audioMgr = AudioManager::Get(); @@ -55,9 +50,10 @@ void AudioModule_Startup() audioMgr.AudioUpdate(); }); + + AudioManager::Get().Initialize(); } void AudioModule_Shutdown() { - } \ No newline at end of file diff --git a/Nuake/Source/Nuake/Modules/ModuleDB.h b/Nuake/Source/Nuake/Modules/ModuleDB.h index c51a0941..0153c3ca 100644 --- a/Nuake/Source/Nuake/Modules/ModuleDB.h +++ b/Nuake/Source/Nuake/Modules/ModuleDB.h @@ -10,6 +10,8 @@ #include "Nuake/Core/Object/Object.h" #include "Nuake/Scene/Scene.h" +#include "Nuake/Scene/SceneSystems.h" + #include class ModuleInstance @@ -104,7 +106,7 @@ public: \ #define NUAKEMODULE(moduleName) \ using TypeNameMap = std::map; \ \ -class moduleName : public ModuleInstance \ +class moduleName : public ModuleInstance \ { \ public: \ std::string Description = "No Description"; \ @@ -116,35 +118,46 @@ public: \ inline static auto ClassFactory = entt::meta(); \ template \ inline moduleName& BindFunction(const std::string& name, Args... argNames) \ - { \ - entt::id_type typeId = entt::hashed_string(name.c_str()); \ - TypeNames[typeId] = name; \ - FuncArgNames[typeId] = { argNames ... }; \ - ModuleFactory.func(typeId); \ - return *this; \ - } \ - template \ - static auto RegisterSetting(const char* settingName) \ - { \ - return ClassFactory \ - .data(entt::hashed_string(settingName)) \ - .prop(Nuake::HashedName::DisplayName, settingName); \ - } \ - \ + { \ + entt::id_type typeId = entt::hashed_string(name.c_str()); \ + TypeNames[typeId] = name; \ + FuncArgNames[typeId] = { argNames ... }; \ + ModuleFactory.func(typeId); \ + return *this; \ + } \ + template \ + static auto RegisterSetting(const char* settingName) \ + { \ + return ClassFactory \ + .data(entt::hashed_string(settingName)) \ + .prop(Nuake::HashedName::DisplayName, settingName); \ + } \ + \ + template \ + void RegisterComponent() \ + { \ + /*Nuake::SceneSystemDB::Get().RegisterComponent();*/ \ + } \ \ - template \ - auto Invoke(const std::string& funcName, Args... args) \ + template \ + void RegisterComponentSystem() \ { \ - auto reflection = Resolve();\ - for (auto [id, func] : reflection.func())\ - {\ - const std::string_view returnType = func.ret().info().name();\ - const std::string_view funcTypeName = GetTypeName(id);\ - if (funcName == funcTypeName)\ - {\ - return func.invoke(instance, args...);\ - }\ - } \ + /*Nuake::SceneSystemDB::Get().RegisterSystem(); */ \ + } \ + \ + template \ + auto Invoke(const std::string& funcName, Args... args) \ + { \ + auto reflection = Resolve(); \ + for (auto [id, func] : reflection.func()) \ + { \ + const std::string_view returnType = func.ret().info().name(); \ + const std::string_view funcTypeName = GetTypeName(id); \ + if (funcName == funcTypeName) \ + { \ + return func.invoke(instance, args...); \ + } \ + } \ } \ \ std::vector GetFuncArgNames(entt::id_type id) \ diff --git a/Nuake/Source/Nuake/Modules/Modules.cpp b/Nuake/Source/Nuake/Modules/Modules.cpp index 4d836f74..02b814e8 100644 --- a/Nuake/Source/Nuake/Modules/Modules.cpp +++ b/Nuake/Source/Nuake/Modules/Modules.cpp @@ -4,82 +4,12 @@ #include "AssimpModule/AssimpModule.h" #include "AudioModule/AudioModule.h" #include "ExampleModule/ExampleModule.h" -#include "ModuleDB.h" -#include "Nuake/UI/WidgetDrawer.h" - -#include "Nuake/Core/Object/Object.h" #include "Nuake/Core/Logger.h" - -void DrawFloatWidget(entt::meta_data& type, entt::meta_any& instance) -{ - using namespace Nuake; - - float stepSize = 1.f; - if (auto prop = type.prop(HashedFieldPropName::FloatStep)) - stepSize = *prop.value().try_cast(); - - float min = 0.f; - if (auto prop = type.prop(HashedFieldPropName::FloatMin)) - min = *prop.value().try_cast(); - - float max = 0.f; - if (auto prop = type.prop(HashedFieldPropName::FloatMax)) - max = *prop.value().try_cast(); - - auto propDisplayName = type.prop(HashedName::DisplayName); - const char* displayName = *propDisplayName.value().try_cast(); - if (displayName != nullptr) - { - ImGui::Text(displayName); - ImGui::TableNextColumn(); - - auto fieldVal = type.get(instance); - float* floatPtr = fieldVal.try_cast(); - if (floatPtr != nullptr) - { - float floatProxy = *floatPtr; - const std::string controlId = std::string("##") + displayName; - if (ImGui::DragFloat(controlId.c_str(), &floatProxy, stepSize, min, max)) - { - type.set(instance, floatProxy); - } - } - else - { - ImGui::Text("ERR"); - } - } -} - -void DrawBoolWidget(entt::meta_type& type, entt::meta_any& instance) -{ - -} - -void Nuake::Modules::FixedUpdate(float ts) -{ - for (auto& moduleName : ModuleDB::Get().GetModules()) - { - ModuleDB::Get().GetBaseImpl(moduleName).OnFixedUpdate.Broadcast(ts); - } -} - -void Nuake::Modules::Update(float ts) -{ - for (auto& moduleName : ModuleDB::Get().GetModules()) - { - ModuleDB::Get().GetBaseImpl(moduleName).OnUpdate.Broadcast(ts); - } -} +#include "Nuake/Modules/ModuleDB.h" void Nuake::Modules::StartupModules() { - auto& drawer = WidgetDrawer::Get(); - drawer.RegisterTypeDrawer(&drawer); - - //drawer.RegisterTypeDrawer(&DrawBoolWidget); - Logger::Log("Starting AssimpModule", "modules"); AssimpModule_Startup(); Logger::Log("Starting AudioModule", "modules"); @@ -88,6 +18,26 @@ 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/Scene/SceneSystems.h b/Nuake/Source/Nuake/Scene/SceneSystems.h index 1401c953..270db833 100644 --- a/Nuake/Source/Nuake/Scene/SceneSystems.h +++ b/Nuake/Source/Nuake/Scene/SceneSystems.h @@ -15,14 +15,19 @@ namespace Nuake using SystemInitializerFunc = std::function(Scene*)>; + using SystemInitializerFunc = std::function(Scene*)>; + template concept InheritsFromSystem = std::derived_from; + template + concept InheritsFromComponent = std::derived_from; + class SceneSystemDB { private: std::vector Systems; - + public: static SceneSystemDB& Get() { @@ -40,6 +45,12 @@ namespace Nuake Systems.push_back(&System::Instantiate); } + template + void RegisterComponent() + { + T::InternalInitializeClass(); + } + void InstantiateSystems(Scene* scene) { for (auto& system : Systems)