#include "openroller/desktop/CabinetBackend.hpp" #include #include namespace { class SoftwareCabinetBackend final : public CabinetBackend { public: void poll() override { const bool* keys = SDL_GetKeyboardState(nullptr); if (!keys) { inputs_.fill(false); return; } const auto down = [&](SDL_Scancode key) { return keys[key]; }; set(CabinetInput::Test, down(SDL_SCANCODE_CAPSLOCK)); set(CabinetInput::Service, down(SDL_SCANCODE_F1)); set(CabinetInput::Coin, down(SDL_SCANCODE_F2)); set(CabinetInput::Select, down(SDL_SCANCODE_F3)); set(CabinetInput::Enter, down(SDL_SCANCODE_RIGHTBRACKET) || down(SDL_SCANCODE_RETURN)); set(CabinetInput::LeftUp, down(SDL_SCANCODE_Q)); set(CabinetInput::LeftDown, down(SDL_SCANCODE_A)); set(CabinetInput::LeftLeft, down(SDL_SCANCODE_LCTRL)); set(CabinetInput::LeftRight, down(SDL_SCANCODE_S)); set(CabinetInput::LeftButton, down(SDL_SCANCODE_LALT)); set(CabinetInput::RightUp, down(SDL_SCANCODE_UP)); set(CabinetInput::RightDown, down(SDL_SCANCODE_DOWN)); set(CabinetInput::RightLeft, down(SDL_SCANCODE_LEFT)); set(CabinetInput::RightRight, down(SDL_SCANCODE_RIGHT)); set(CabinetInput::RightButton, down(SDL_SCANCODE_SPACE)); } bool input(CabinetInput input) const override { return inputs_[static_cast(input)]; } void setLed(std::size_t logicalIndex, CabinetRgb color) override { if (logicalIndex < leds_.size()) leds_[logicalIndex] = color; } void clearLeds() override { leds_.fill({}); } void commitOutputs() override { // The software backend intentionally retains the last committed frame // so the LED test can render exactly what a hardware backend receives. } const std::array& leds() const override { return leds_; } private: void set(CabinetInput input, bool value) { inputs_[static_cast(input)] = value; } std::array(CabinetInput::Count)> inputs_{}; std::array leds_{}; }; } // namespace CabinetBackend& defaultCabinetBackend() { static SoftwareCabinetBackend backend; return backend; }