reworked the general update strategy interface

This commit is contained in:
2021-04-28 19:38:25 +02:00
parent b8a5cd7cf4
commit efad254193
53 changed files with 756 additions and 889 deletions

View File

@ -1,4 +1,6 @@
#include "./screen_director.hpp"
#include "mm/services/service.hpp"
#include "mm/update_strategies/update_strategy.hpp"
#include <entt/core/hashed_string.hpp>
@ -8,7 +10,14 @@
namespace MM::Services {
bool ScreenDirector::enable(MM::Engine& engine) {
bool ScreenDirector::enable(MM::Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) {
// add task
task_array.push_back(
UpdateStrategies::TaskInfo{"ScreenDirector::update"}
.fn([this](Engine& e) { update(e); })
.phase(UpdateStrategies::update_phase_t::POST)
);
// start initial screen
if (!queued_screen_id.empty()) {
auto next_screen_id = queued_screen_id;
@ -25,18 +34,6 @@ bool ScreenDirector::enable(MM::Engine& engine) {
void ScreenDirector::disable(MM::Engine&) {
}
std::vector<UpdateStrategies::UpdateCreationInfo> ScreenDirector::registerUpdates(void) {
using namespace entt::literals;
return {
{
"ScreenDirector::update"_hs,
"ScreenDirector::update",
[this](Engine& engine) { update(engine); },
UpdateStrategies::update_phase_t::POST
}
};
}
void ScreenDirector::update(MM::Engine& engine) {
if (curr_screen_id != queued_screen_id) {
engine.getUpdateStrategy().addDeferred([this](MM::Engine& e) {

View File

@ -12,11 +12,9 @@ class ScreenDirector : public Service {
const char* name(void) override { return "ScreenDirector"; }
// enable switches to queued_screen_index
bool enable(MM::Engine&) override;
bool enable(MM::Engine&, std::vector<UpdateStrategies::TaskInfo>& task_array) override;
void disable(MM::Engine&) override;
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
public:
struct Screen {
// lists of services relevant for this screen, disable and enable are called when its changed to

View File

@ -7,7 +7,7 @@ class TestService1 : public MM::Services::Service {
public:
const char* name(void) override { return "TestService1"; }
bool enable(MM::Engine&) override { return true; }
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>&) override { return true; }
void disable(MM::Engine&) override {}
};
@ -15,7 +15,7 @@ class TestService2 : public MM::Services::Service {
public:
const char* name(void) override { return "TestService2"; }
bool enable(MM::Engine&) override { return true; }
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>&) override { return true; }
void disable(MM::Engine&) override {}
};
@ -23,7 +23,7 @@ class TestServiceInterface : public MM::Services::Service {
public:
const char* name(void) override { return "TestServiceInterface"; }
bool enable(MM::Engine&) override { return true; }
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>&) override { return true; }
void disable(MM::Engine&) override {}
public:
@ -34,7 +34,7 @@ class TestServiceInterfaceImpl1 : public TestServiceInterface {
public:
const char* name(void) override { return "TestServiceInterfaceImpl1"; }
bool enable(MM::Engine&) override { return true; }
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>&) override { return true; }
void disable(MM::Engine&) override {}
public:
@ -47,7 +47,7 @@ class TestServiceInterfaceImpl2 : public TestServiceInterface {
public:
const char* name(void) override { return "TestServiceInterfaceImpl2"; }
bool enable(MM::Engine&) override { return true; }
bool enable(MM::Engine&, std::vector<MM::UpdateStrategies::TaskInfo>&) override { return true; }
void disable(MM::Engine&) override {}
public: