feat: implement module lifecycle
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
#ifndef __MCS_ENGINE_HPP__
|
||||
#define __MCS_ENGINE_HPP__
|
||||
|
||||
#include <cstdint>
|
||||
#include <engine/core/engine_db_provider.hpp>
|
||||
#include <engine/core/engine_module.hpp>
|
||||
#include <engine/core/engine_module_api.hpp>
|
||||
#include <engine/core/engine_db_provider.hpp>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
class MscEngine : public IMscEngineModuleAPI
|
||||
{
|
||||
private:
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
/// @brief Loaded modules list
|
||||
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
||||
|
||||
@@ -39,10 +37,12 @@ public:
|
||||
void stop();
|
||||
|
||||
MscEventBus &getBus() override;
|
||||
std::unordered_map<std::string, std::uint16_t> getLoadedModules() const override;
|
||||
std::unordered_map<std::string, std::uint16_t>
|
||||
getLoadedModules() const override;
|
||||
MscEngineModule &getModule(const std::string &name) override;
|
||||
std::unique_ptr<MscEngineDBProvider> createDBProvider() override;
|
||||
std::unique_ptr<MscEngineDBProvider> createDBProvider(const std::string &filepath) override;
|
||||
std::unique_ptr<MscEngineDBProvider>
|
||||
createDBProvider(const std::string &filepath) override;
|
||||
};
|
||||
|
||||
#endif // __MCS_ENGINE_HPP__
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifndef __MCS_ENGINE_MODULE_HPP__
|
||||
#define __MCS_ENGINE_MODULE_HPP__
|
||||
|
||||
#include "engine/utils/rev_range.hpp"
|
||||
#include "engine/core/engine_module_api.hpp"
|
||||
#include "engine/utils/rev_range.hpp"
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
@@ -34,7 +34,8 @@ public:
|
||||
/// @brief Engine update cycle step
|
||||
/// @param engine engine public API for modules
|
||||
/// @param dt loop delta
|
||||
virtual void onUpdate(IMscEngineModuleAPI &engine, float dt) = 0;
|
||||
virtual void onUpdate(IMscEngineModuleAPI &engine,
|
||||
IMscEngineModuleAPI::clock::duration dt) = 0;
|
||||
|
||||
/// @brief Engine stop event handler
|
||||
/// @param engine engine public API for modules
|
||||
|
||||
@@ -1,25 +1,28 @@
|
||||
#ifndef __MSC_ENGINE_MODULE_API_HPP__
|
||||
#define __MSC_ENGINE_MODULE_API_HPP__
|
||||
|
||||
#include <cstdint>
|
||||
#include <engine/core/engine_bus.hpp>
|
||||
#include <engine/core/engine_db_provider.hpp>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
|
||||
class MscEngineModule;
|
||||
|
||||
class IMscEngineModuleAPI
|
||||
{
|
||||
public:
|
||||
using clock = std::chrono::steady_clock;
|
||||
|
||||
virtual ~IMscEngineModuleAPI() = default;
|
||||
|
||||
/// @brief Get access to engine event bus
|
||||
virtual MscEventBus &getBus() = 0;
|
||||
|
||||
/// @brief Get access to loaded module list
|
||||
virtual std::unordered_map<std::string, std::uint16_t> getLoadedModules() const = 0;
|
||||
virtual std::unordered_map<std::string, std::uint16_t>
|
||||
getLoadedModules() const = 0;
|
||||
|
||||
/// @brief Access module by its name
|
||||
virtual MscEngineModule &getModule(const std::string &name) = 0;
|
||||
@@ -28,7 +31,8 @@ public:
|
||||
virtual std::unique_ptr<MscEngineDBProvider> createDBProvider() = 0;
|
||||
|
||||
/// @brief Create database provider with file database
|
||||
virtual std::unique_ptr<MscEngineDBProvider> createDBProvider(const std::string &filepath) = 0;
|
||||
virtual std::unique_ptr<MscEngineDBProvider>
|
||||
createDBProvider(const std::string &filepath) = 0;
|
||||
};
|
||||
|
||||
#endif // __MSC_ENGINE_MODULE_API_HPP__
|
||||
|
||||
Reference in New Issue
Block a user