mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-20 19:56:37 +02:00
UpdateStrategy Refactor: 6. draft, now looks good, not fully tested
This commit is contained in:
@ -1,52 +0,0 @@
|
||||
#include "./default_service.hpp"
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
// TODO: error handling
|
||||
bool DefaultService::enable(Engine& engine) {
|
||||
{
|
||||
_func_handles[0] = engine.addUpdate([this](Engine& e) { this->preSceneUpdate(e); });
|
||||
auto tmp_lock = _func_handles[0].lock();
|
||||
tmp_lock->priority = 1;
|
||||
tmp_lock->name = "DefaultService::preSceneUpdate";
|
||||
}
|
||||
|
||||
{
|
||||
_func_handles[1] = engine.addUpdate([this](Engine& e) { this->postSceneUpdate(e); });
|
||||
auto tmp_lock = _func_handles[1].lock();
|
||||
tmp_lock->priority = -1;
|
||||
tmp_lock->name = "DefaultService::postSceneUpdate";
|
||||
}
|
||||
|
||||
{
|
||||
_func_handles[2] = engine.addFixedUpdate([this](Engine& e) { this->preSceneFixedUpdate(e); });
|
||||
auto tmp_lock = _func_handles[2].lock();
|
||||
tmp_lock->priority = 1;
|
||||
tmp_lock->name = "DefaultService::preSceneFixedUpdate";
|
||||
}
|
||||
|
||||
{
|
||||
_func_handles[3] = engine.addFixedUpdate([this](Engine& e) { this->postSceneFixedUpdate(e); });
|
||||
auto tmp_lock = _func_handles[3].lock();
|
||||
tmp_lock->priority = -1;
|
||||
tmp_lock->name = "DefaultService::postSceneFixedUpdate";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DefaultService::disable(Engine& engine) {
|
||||
engine.removeUpdate(_func_handles[0]);
|
||||
engine.removeUpdate(_func_handles[1]);
|
||||
|
||||
engine.removeFixedUpdate(_func_handles[2]);
|
||||
engine.removeFixedUpdate(_func_handles[3]);
|
||||
|
||||
_func_handles[0].reset();
|
||||
_func_handles[1].reset();
|
||||
_func_handles[2].reset();
|
||||
_func_handles[3].reset();
|
||||
}
|
||||
|
||||
} // MM::Services
|
||||
|
@ -1,26 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "./service.hpp"
|
||||
#include <mm/engine.hpp>
|
||||
|
||||
namespace MM::Services {
|
||||
|
||||
class DefaultService : public Service {
|
||||
private:
|
||||
Engine::FunctionDataHandle _func_handles[4];
|
||||
|
||||
public:
|
||||
virtual const char* name(void) override { return "DefaultService"; }
|
||||
|
||||
virtual bool enable(Engine& engine) override;
|
||||
virtual void disable(Engine& engine) override;
|
||||
|
||||
virtual void preSceneUpdate(Engine&) {}
|
||||
virtual void postSceneUpdate(Engine&) {}
|
||||
virtual void preSceneFixedUpdate(Engine&) {}
|
||||
virtual void postSceneFixedUpdate(Engine&) {}
|
||||
};
|
||||
|
||||
} //MM::Services
|
||||
|
||||
|
@ -1,8 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace MM {
|
||||
|
||||
class Engine;
|
||||
namespace UpdateStrategies {
|
||||
struct UpdateCreationInfo;
|
||||
}
|
||||
|
||||
namespace Services {
|
||||
|
||||
@ -10,12 +15,13 @@ namespace MM {
|
||||
public:
|
||||
virtual ~Service(void) {}
|
||||
|
||||
virtual const char* name(void) { return "UnNamedService"; }
|
||||
//virtual const char* name(void) = 0; // use this to find unnamed services
|
||||
virtual const char* name(void) = 0;
|
||||
|
||||
// required
|
||||
virtual bool enable(Engine& engine) = 0;
|
||||
virtual void disable(Engine& engine) = 0;
|
||||
|
||||
// optional, only if service actually needs to be part of the update loop
|
||||
virtual std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) { return {}; }
|
||||
};
|
||||
|
||||
} // Services
|
||||
|
Reference in New Issue
Block a user