53 lines
2.0 KiB
C++
53 lines
2.0 KiB
C++
#include "include/controller_state.hpp"
|
|
#include <PSX/GPU/gpu.hpp>
|
|
|
|
namespace ControllerTest {
|
|
using DigitalButton = Periphery::GenericController::Button;
|
|
using namespace JabyEngine;
|
|
|
|
// This should go to JabyEngine eventually
|
|
template<typename T>
|
|
static GPU::Link* link_array(GPU::Link* last_prim, T* elements, size_t length) {
|
|
for(size_t n = 0; n < length; n++) {
|
|
last_prim->concat(elements[n]);
|
|
last_prim = &elements[n];
|
|
}
|
|
|
|
last_prim->terminate();
|
|
return last_prim;
|
|
}
|
|
|
|
template<typename T, size_t N>
|
|
static GPU::Link* link_array(GPU::Link* last_prim, T(&elements)[N]) {
|
|
return link_array(last_prim, elements, N);
|
|
}
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------------
|
|
|
|
static void set_active(GPU::SPRT_16::Linked& sprt, bool is_active) {
|
|
sprt->tex_offset.y = is_active ? 16 : 0;
|
|
}
|
|
|
|
void ControllerState :: setup() {
|
|
for(size_t n = 0; n < 2; n++) {
|
|
link_array(link_array(&this->tex_page[n], this->buttons[n]), this->arrows[n]);
|
|
}
|
|
}
|
|
|
|
void ControllerState :: update(const Periphery::GenericController& controller) {
|
|
static const DigitalButton ButtonSprtMap[] = {
|
|
DigitalButton::Triangle, DigitalButton::Circle, DigitalButton::Cross, DigitalButton::Square,
|
|
DigitalButton::ST, DigitalButton::SEL, DigitalButton::L1, DigitalButton::L2, DigitalButton::R1, DigitalButton::R2
|
|
};
|
|
|
|
auto& cur_button_sprts = this->buttons[GPU::update_id()];
|
|
for(size_t n = 0; n < sizeof(ButtonSprtMap)/sizeof(ButtonSprtMap[0]); n++) {
|
|
set_active(cur_button_sprts[n], controller.button.is_down(ButtonSprtMap[n]));
|
|
}
|
|
set_active(cur_button_sprts[12], controller.header.state == Periphery::RawController::State::Disconnected);
|
|
}
|
|
|
|
void ControllerState :: render() {
|
|
GPU::render(this->tex_page[GPU::render_id()]);
|
|
}
|
|
} |