Support a few buttons

This commit is contained in:
Jaby
2024-01-04 18:39:42 -06:00
parent fabe37a824
commit 60286f41b8
3 changed files with 21 additions and 3 deletions

View File

@@ -2,8 +2,10 @@
#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++) {
@@ -20,14 +22,29 @@ namespace ControllerTest {
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() {
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() {