Compare commits
1
Commits
master
..
7a158a0bf8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a158a0bf8 |
@@ -12,16 +12,32 @@
|
|||||||
class MscEngine : public IMscEngineModuleAPI
|
class MscEngine : public IMscEngineModuleAPI
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
/// Loaded modules list
|
using clock = std::chrono::steady_clock;
|
||||||
|
|
||||||
|
/// @brief Loaded modules list
|
||||||
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
std::vector<std::shared_ptr<MscEngineModule>> _modules;
|
||||||
|
|
||||||
|
/// @brief Common event bus
|
||||||
MscEventBus _bus;
|
MscEventBus _bus;
|
||||||
|
|
||||||
|
/// @brief Is engine running rn
|
||||||
|
bool _isRunning = false;
|
||||||
|
|
||||||
|
/// @brief Last update time
|
||||||
|
clock::time_point _lastUpdate;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Actual version
|
/// Actual version
|
||||||
static uint16_t REV;
|
static uint16_t REV;
|
||||||
|
|
||||||
MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules);
|
MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules);
|
||||||
|
|
||||||
|
/// @brief Start engine
|
||||||
|
void start();
|
||||||
|
|
||||||
|
/// @brief Stop engine
|
||||||
|
void stop();
|
||||||
|
|
||||||
MscEventBus &getBus() override;
|
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;
|
MscEngineModule &getModule(const std::string &name) override;
|
||||||
|
|||||||
@@ -23,8 +23,26 @@ public:
|
|||||||
virtual const std::unordered_map<std::string, MscRevisionRange> &
|
virtual const std::unordered_map<std::string, MscRevisionRange> &
|
||||||
getDependencies() const = 0;
|
getDependencies() const = 0;
|
||||||
|
|
||||||
/// Module initialization phase
|
/// @brief Module initialization
|
||||||
|
/// @param engine engine public API for modules
|
||||||
virtual void onInitialize(IMscEngineModuleAPI &engine) = 0;
|
virtual void onInitialize(IMscEngineModuleAPI &engine) = 0;
|
||||||
|
|
||||||
|
/// @brief Engine start event handler
|
||||||
|
/// @param engine engine public API for modules
|
||||||
|
virtual void onStart(IMscEngineModuleAPI &engine) = 0;
|
||||||
|
|
||||||
|
/// @brief Engine update cycle step
|
||||||
|
/// @param engine engine public API for modules
|
||||||
|
/// @param dt loop delta
|
||||||
|
virtual void onUpdate(IMscEngineModuleAPI &engine, float dt) = 0;
|
||||||
|
|
||||||
|
/// @brief Engine stop event handler
|
||||||
|
/// @param engine engine public API for modules
|
||||||
|
virtual void onStop(IMscEngineModuleAPI &engine) = 0;
|
||||||
|
|
||||||
|
/// @brief Module destroying
|
||||||
|
/// @param engine engine public API for modules
|
||||||
|
virtual void onDestory(IMscEngineModuleAPI &engine) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __MCS_ENGINE_MODULE_HPP__
|
#endif // __MCS_ENGINE_MODULE_HPP__
|
||||||
|
|||||||
@@ -49,11 +49,38 @@ MscEngine::MscEngine(std::vector<std::shared_ptr<MscEngineModule>> modules)
|
|||||||
std::to_string(current_rev));
|
std::to_string(current_rev));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.get()->onInitialize(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
_modules = std::move(modules);
|
_modules = std::move(modules);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MscEngine::start()
|
||||||
|
{
|
||||||
|
if (_isRunning)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isRunning = true;
|
||||||
|
_lastUpdate = clock::now();
|
||||||
|
|
||||||
|
double accumulator = 0.0;
|
||||||
|
constexpr double fixedDt = 1.0 / 30.0;
|
||||||
|
|
||||||
|
while (_isRunning)
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MscEngine::stop()
|
||||||
|
{
|
||||||
|
if (!_isRunning)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isRunning = false;
|
||||||
|
}
|
||||||
|
|
||||||
MscEventBus &MscEngine::getBus()
|
MscEventBus &MscEngine::getBus()
|
||||||
{
|
{
|
||||||
return _bus;
|
return _bus;
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
#include "engine/modules/test1/test1.hpp"
|
|
||||||
#include "engine/core/engine_module_api.hpp"
|
|
||||||
#include "engine/utils/rev_range.hpp"
|
|
||||||
#include <cstdint>
|
|
||||||
#include <string>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
std::string Test1Module::getName() const { return "test1"; }
|
|
||||||
|
|
||||||
uint16_t Test1Module::getRev() const { return 1; }
|
|
||||||
|
|
||||||
const std::unordered_map<std::string, MscRevisionRange> &
|
|
||||||
Test1Module::getDependencies() const
|
|
||||||
{
|
|
||||||
static const std::unordered_map<std::string, MscRevisionRange> deps{};
|
|
||||||
return deps;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Test1Module::onInitialize(IMscEngineModuleAPI &engine)
|
|
||||||
{
|
|
||||||
(void)(engine);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user