mirror of
https://github.com/MadeOfJelly/MushMachine.git
synced 2025-06-19 11:16:37 +02:00
reworked the general update strategy interface
This commit is contained in:
@ -77,7 +77,7 @@ InputService::InputService(void) {
|
||||
InputService::~InputService(void) {
|
||||
}
|
||||
|
||||
bool InputService::enable(Engine& engine) {
|
||||
bool InputService::enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) {
|
||||
auto* sdl_ss = engine.tryService<SDLService>();
|
||||
if (!sdl_ss) {
|
||||
LOG_ERROR("InputService requires SDLService in engine!");
|
||||
@ -90,6 +90,24 @@ bool InputService::enable(Engine& engine) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// add task
|
||||
task_array.push_back(
|
||||
UpdateStrategies::TaskInfo{"InputService::update"}
|
||||
.fn([this](MM::Engine&) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (!_player_active[i])
|
||||
continue;
|
||||
|
||||
auto& p = _player[i];
|
||||
if (p.is_controller) {
|
||||
} else {
|
||||
updateKPlayerDirs(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -105,28 +123,6 @@ void InputService::disable(Engine& engine) {
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> InputService::registerUpdates(void) {
|
||||
using namespace entt::literals;
|
||||
return {
|
||||
{
|
||||
"InputService::update"_hs,
|
||||
"InputService::update",
|
||||
[this](MM::Engine&) {
|
||||
for (size_t i = 0; i < 4; i++) {
|
||||
if (!_player_active[i])
|
||||
continue;
|
||||
|
||||
auto& p = _player[i];
|
||||
if (p.is_controller) {
|
||||
} else {
|
||||
updateKPlayerDirs(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bool InputService::handleSDL_Event(const SDL_Event& e, MM::Engine& engine) {
|
||||
ZoneScopedN("MM::InputService::handleSDL_Event");
|
||||
switch (e.type) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#include "mm/services/service.hpp"
|
||||
#include <glm/vec2.hpp>
|
||||
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
@ -108,14 +107,11 @@ namespace MM::Services {
|
||||
SDLService::EventHandlerHandle _event_handle = nullptr;
|
||||
|
||||
public:
|
||||
bool enable(Engine& engine) override;
|
||||
bool enable(Engine& engine, std::vector<UpdateStrategies::TaskInfo>& task_array) override;
|
||||
void disable(Engine& engine) override;
|
||||
|
||||
const char* name(void) override { return "InputService"; }
|
||||
|
||||
// you will likely want to make the scene depend on this
|
||||
std::vector<UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override;
|
||||
|
||||
public:
|
||||
// returns true if event was relevant
|
||||
bool handleSDL_Event(const SDL_Event& e, MM::Engine& engine);
|
||||
|
@ -1,4 +1,6 @@
|
||||
#include "mm/services/service.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <mm/services/input_service.hpp>
|
||||
#include <mm/services/sdl_service.hpp>
|
||||
#include <mm/services/filesystem.hpp>
|
||||
@ -11,7 +13,6 @@
|
||||
|
||||
#include <imgui/imgui.h>
|
||||
|
||||
|
||||
class InputVisualizer : public MM::Services::Service {
|
||||
private:
|
||||
MM::Input::PlayerID _player_id;
|
||||
@ -20,7 +21,7 @@ class InputVisualizer : public MM::Services::Service {
|
||||
public:
|
||||
const char* name(void) override { return "InputVisualizer"; }
|
||||
|
||||
bool enable(MM::Engine& engine) override {
|
||||
bool enable(MM::Engine& engine, std::vector<MM::UpdateStrategies::TaskInfo>& task_array) override {
|
||||
_player_id = UINT16_MAX;
|
||||
|
||||
auto* sdl_ss = engine.tryService<MM::Services::SDLService>();
|
||||
@ -40,27 +41,18 @@ class InputVisualizer : public MM::Services::Service {
|
||||
}
|
||||
}
|
||||
|
||||
task_array.push_back(
|
||||
MM::UpdateStrategies::TaskInfo{"InputVisualizer::render"}
|
||||
.fn([this](MM::Engine& e){ renderImGui(e); })
|
||||
.succeed("InputService::update")
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void disable(MM::Engine&) override {
|
||||
}
|
||||
|
||||
std::vector<MM::UpdateStrategies::UpdateCreationInfo> registerUpdates(void) override {
|
||||
using namespace entt::literals;
|
||||
return {
|
||||
{
|
||||
"InputVisualizer::render"_hs,
|
||||
"InputVisualizer::render",
|
||||
[this](MM::Engine& e){ this->renderImGui(e); },
|
||||
MM::UpdateStrategies::update_phase_t::MAIN,
|
||||
true,
|
||||
{ "InputService::update"_hs }
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
void renderImGui(MM::Engine& engine) {
|
||||
ImGui::Begin("InputVisualizer", NULL, ImGuiWindowFlags_AlwaysAutoResize);
|
||||
|
Reference in New Issue
Block a user