mirror of
https://github.com/antopilo/Nuake.git
synced 2026-01-03 14:09:46 +03:00
Added component registering to modules
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
@@ -6,16 +6,9 @@
|
||||
#include <Nuake/Core/Logger.h>
|
||||
|
||||
#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<AudioModule>();
|
||||
module.Name = "AudioModule";
|
||||
module.Description = "Core audio module";
|
||||
|
||||
// Exposed settings
|
||||
module.RegisterSetting<&Volume>("Volume");
|
||||
module.RegisterSetting<&Muted>("Muted");
|
||||
|
||||
module.BindFunction<PlayAudio>("PlayAudio", "id", "volume");
|
||||
module.BindFunction<StopAudio>("StopAudio");
|
||||
// Exposed functions(scripting API)
|
||||
module.BindFunction<SetVolume>("SetVolume", "volume");
|
||||
module.BindFunction<SetMuted>("SetMuted", "muted");
|
||||
|
||||
AudioManager::Get().Initialize();
|
||||
|
||||
SceneSystemDB::Get().RegisterSceneSystem<Audio::AudioSystem>();
|
||||
// Register custom component & system
|
||||
module.RegisterComponent<Audio::AudioEmitterComponent>();
|
||||
module.RegisterComponentSystem<Audio::AudioSystem>();
|
||||
|
||||
// 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()
|
||||
{
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@
|
||||
#include "Nuake/Core/Object/Object.h"
|
||||
|
||||
#include "Nuake/Scene/Scene.h"
|
||||
#include "Nuake/Scene/SceneSystems.h"
|
||||
|
||||
#include <entt/entt.hpp>
|
||||
|
||||
class ModuleInstance
|
||||
@@ -104,7 +106,7 @@ public: \
|
||||
#define NUAKEMODULE(moduleName) \
|
||||
using TypeNameMap = std::map<entt::id_type, std::string>; \
|
||||
\
|
||||
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<moduleName>(); \
|
||||
template<auto T, typename... Args> \
|
||||
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<T>(typeId); \
|
||||
return *this; \
|
||||
} \
|
||||
template<auto Func> \
|
||||
static auto RegisterSetting(const char* settingName) \
|
||||
{ \
|
||||
return ClassFactory \
|
||||
.data<Func>(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<T>(typeId); \
|
||||
return *this; \
|
||||
} \
|
||||
template<auto Func> \
|
||||
static auto RegisterSetting(const char* settingName) \
|
||||
{ \
|
||||
return ClassFactory \
|
||||
.data<Func>(entt::hashed_string(settingName)) \
|
||||
.prop(Nuake::HashedName::DisplayName, settingName); \
|
||||
} \
|
||||
\
|
||||
template<typename T> \
|
||||
void RegisterComponent() \
|
||||
{ \
|
||||
/*Nuake::SceneSystemDB::Get().RegisterComponent<T>();*/ \
|
||||
} \
|
||||
\
|
||||
template<typename... Args> \
|
||||
auto Invoke(const std::string& funcName, Args... args) \
|
||||
template<typename T> \
|
||||
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<T>(); */ \
|
||||
} \
|
||||
\
|
||||
template<typename... Args> \
|
||||
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<std::string> GetFuncArgNames(entt::id_type id) \
|
||||
|
||||
@@ -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>();
|
||||
|
||||
float min = 0.f;
|
||||
if (auto prop = type.prop(HashedFieldPropName::FloatMin))
|
||||
min = *prop.value().try_cast<float>();
|
||||
|
||||
float max = 0.f;
|
||||
if (auto prop = type.prop(HashedFieldPropName::FloatMax))
|
||||
max = *prop.value().try_cast<float>();
|
||||
|
||||
auto propDisplayName = type.prop(HashedName::DisplayName);
|
||||
const char* displayName = *propDisplayName.value().try_cast<const char*>();
|
||||
if (displayName != nullptr)
|
||||
{
|
||||
ImGui::Text(displayName);
|
||||
ImGui::TableNextColumn();
|
||||
|
||||
auto fieldVal = type.get(instance);
|
||||
float* floatPtr = fieldVal.try_cast<float>();
|
||||
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<float, &WidgetDrawer::DrawFloat>(&drawer);
|
||||
|
||||
//drawer.RegisterTypeDrawer<bool, DrawBoolWidget>(&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");
|
||||
|
||||
@@ -15,14 +15,19 @@ namespace Nuake
|
||||
|
||||
using SystemInitializerFunc = std::function<Ref<System>(Scene*)>;
|
||||
|
||||
using SystemInitializerFunc = std::function<Ref<System>(Scene*)>;
|
||||
|
||||
template<typename T>
|
||||
concept InheritsFromSystem = std::derived_from<T, System>;
|
||||
|
||||
template<typename T>
|
||||
concept InheritsFromComponent = std::derived_from<T, Component>;
|
||||
|
||||
class SceneSystemDB
|
||||
{
|
||||
private:
|
||||
std::vector<SystemInitializerFunc> Systems;
|
||||
|
||||
|
||||
public:
|
||||
static SceneSystemDB& Get()
|
||||
{
|
||||
@@ -40,6 +45,12 @@ namespace Nuake
|
||||
Systems.push_back(&System::Instantiate<T>);
|
||||
}
|
||||
|
||||
template<InheritsFromComponent T>
|
||||
void RegisterComponent()
|
||||
{
|
||||
T::InternalInitializeClass();
|
||||
}
|
||||
|
||||
void InstantiateSystems(Scene* scene)
|
||||
{
|
||||
for (auto& system : Systems)
|
||||
|
||||
Reference in New Issue
Block a user