Files
openroller/apps/desktop/src/CabinetBackend.cpp
T
tsuki 831d96e562 Initial public source release
Split reusable rendering and format support into vectorail-core and vectorail-gc.
2026-08-02 17:05:27 +02:00

72 lines
2.3 KiB
C++

#include "openroller/desktop/CabinetBackend.hpp"
#include <SDL3/SDL.h>
#include <algorithm>
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<std::size_t>(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<CabinetRgb, 118>& leds() const override {
return leds_;
}
private:
void set(CabinetInput input, bool value) {
inputs_[static_cast<std::size_t>(input)] = value;
}
std::array<bool, static_cast<std::size_t>(CabinetInput::Count)> inputs_{};
std::array<CabinetRgb, 118> leds_{};
};
} // namespace
CabinetBackend& defaultCabinetBackend() {
static SoftwareCabinetBackend backend;
return backend;
}