Added basic events for modules to register to

OnUpdate, OnFixedUpdate, OnSceneLoad, OnGameStateChanged
This commit is contained in:
Antoine Pilote
2025-04-02 16:27:06 -04:00
parent 729ae9050d
commit ef70a04da9
2 changed files with 23 additions and 6 deletions

View File

@@ -71,17 +71,30 @@ void ExampleModule_Startup()
TestClass::InternalInitializeClass();
// Register the module & info
auto& module = ModuleDB::Get().RegisterModule<ExampleModule>();
module.instance = module.Resolve().construct();
module.Description = "This is an example module";
// This is to expose parameters in the modules settings
module.RegisterSetting<&mySetting>("mySetting");
// This is to expose functions to the rest of the engine
module.BindFunction<ExampleFunction>("ExampleFunction");
module.BindFunction<ExampleModuleLog>("ExampleModuleLog", "hi");
//module.Invoke("ExampleModuleLog", "Hello World");
// The module can hook to certain events
module.OnUpdate.AddStatic([](float ts)
{
});
module.OnFixedUpdate.AddStatic([](float ts)
{
});
entt::id_type typeId = entt::hashed_string(TestClass::ClassName().c_str());
entt::meta_type metaType = entt::resolve(typeId);
@@ -157,8 +170,6 @@ void ExampleModule_Startup()
//Logger::Log("Serialized original component: " + jsonDataOG.dump(4), "ExampleModule", VERBOSE);
}
void ExampleModule_Shutdown()
{

View File

@@ -4,11 +4,14 @@
#include <map>
#include <vector>
#include "Nuake/Core/Logger.h"
#include "Nuake/Core/GameState.h"
#include "Nuake/Core/MulticastDelegate.h"
#include "Nuake/Core/Object/Object.h"
#include "Nuake/Scene/Scene.h"
#include <entt/entt.hpp>
#include "Nuake/Core/Logger.h"
class ModuleInstance
{
public:
@@ -21,7 +24,10 @@ public:
return entt::resolve(entt::hashed_string(Name.c_str()));
}
MulticastDelegate<Ref<Nuake::Scene>> OnSceneLoad;
MulticastDelegate<float> OnUpdate;
MulticastDelegate<float> OnFixedUpdate;
MulticastDelegate<Nuake::GameState> OnGameStateChanged;
};
class Class