From c803629b1f06e74ba6f77f6ba12ab1c6312f72ba Mon Sep 17 00:00:00 2001 From: Jaby Date: Thu, 4 Jan 2024 22:28:25 -0600 Subject: [PATCH] Support Second controller port (or not if disabled) and have a fancy background --- .../PoolBox/application/include/shared.hpp | 5 ++- .../ControllerTest/controller_state.cpp | 43 +++++++++++-------- .../ControllerTest/controller_test.cpp | 14 +++--- .../include/controller_state.hpp | 2 +- .../PoolBox/application/src/application.cpp | 7 ++- 5 files changed, 46 insertions(+), 25 deletions(-) diff --git a/examples/PoolBox/application/include/shared.hpp b/examples/PoolBox/application/include/shared.hpp index 49a22010..d902f1e5 100644 --- a/examples/PoolBox/application/include/shared.hpp +++ b/examples/PoolBox/application/include/shared.hpp @@ -1,6 +1,9 @@ #pragma once #include "../src/include/menu.hpp" +#include "../src/include/font_writer.hpp" +#include namespace Shared { - extern Menu::BackMenu back_menu; + extern Menu::BackMenu back_menu; + extern JabyEngine::GPU::POLY_G4 background; } \ No newline at end of file diff --git a/examples/PoolBox/application/src/Overlay/ControllerTest/controller_state.cpp b/examples/PoolBox/application/src/Overlay/ControllerTest/controller_state.cpp index 514b52e7..5eaacd1b 100644 --- a/examples/PoolBox/application/src/Overlay/ControllerTest/controller_state.cpp +++ b/examples/PoolBox/application/src/Overlay/ControllerTest/controller_state.cpp @@ -75,7 +75,7 @@ namespace ControllerTest { } } - void ControllerState :: update(const Periphery::AnalogeController& controller, JabyEngine::FontWriter& font_writer) { + void ControllerState :: update(const Periphery::AnalogeController* controller, JabyEngine::FontWriter& font_writer) { static const DigitalButton ButtonSprtMap[] = { DigitalButton::Triangle, DigitalButton::Circle, DigitalButton::Cross, DigitalButton::Square, DigitalButton::ST, DigitalButton::SEL, DigitalButton::L1, DigitalButton::L2, DigitalButton::R1, DigitalButton::R2, @@ -85,25 +85,34 @@ namespace ControllerTest { DigitalButton::Up, DigitalButton::Right, DigitalButton::Down, DigitalButton::Left }; - auto& cur_button_sprts = this->buttons[GPU::update_id()]; - auto& cur_arrow_poly = this->arrows[GPU::update_id()]; + auto& cur_button_sprts = this->buttons[GPU::update_id()]; + auto& cur_arrow_poly = this->arrows[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])); - } - for(size_t n = 0; n < sizeof(ArrowPolyMap)/sizeof(ArrowPolyMap[0]); n++) { - set_active(cur_arrow_poly[n], controller.button.is_down(ArrowPolyMap[n])); + if(controller) { + for(size_t n = 0; n < sizeof(ButtonSprtMap)/sizeof(ButtonSprtMap[0]); n++) { + set_active(cur_button_sprts[n], controller->button.is_down(ButtonSprtMap[n])); + } + for(size_t n = 0; n < sizeof(ArrowPolyMap)/sizeof(ArrowPolyMap[0]); n++) { + set_active(cur_arrow_poly[n], controller->button.is_down(ArrowPolyMap[n])); + } + + set_active(cur_button_sprts[12], controller->header.state == Periphery::RawController::State::Disconnected); + + // Text stuff down here + const auto offset_point = cur_button_sprts[1]->position; + const auto left_stick = controller->get_left_stick_pos(); + const auto right_stick = controller->get_right_stick_pos(); + + auto cursor = State::create(offset_point.move(16, 0), 0); + font_writer.write(cursor, "Right: %i, %i\nLeft : %i, %i\n", right_stick.x, right_stick.y, left_stick.x, left_stick.y); + font_writer.write(cursor, "[%s]", get_type_name(static_cast(controller->get_type()))); } - set_active(cur_button_sprts[12], controller.header.state == Periphery::RawController::State::Disconnected); - - // Text stuff down here - const auto left_stick = controller.get_left_stick_pos(); - const auto right_stick = controller.get_right_stick_pos(); - - auto cursor = State::create(Make::PositionI16(98, 0), 0); - font_writer.write(cursor, "Right: %i, %i\nLeft : %i, %i\n", right_stick.x, right_stick.y, left_stick.x, left_stick.y); - font_writer.write(cursor, "[%s]", get_type_name(static_cast(controller.get_type()))); + else { + auto cursor = State::create(Make::PositionI16(cur_arrow_poly[3]->vertex0.x, cur_button_sprts[0]->position.y), 0); + font_writer.write(cursor, "!!This Port is not\nenabled in JabyEngine!!", GPU::Color24::Red()); + this->tex_page[GPU::update_id()].terminate(); + } } void ControllerState :: render() { diff --git a/examples/PoolBox/application/src/Overlay/ControllerTest/controller_test.cpp b/examples/PoolBox/application/src/Overlay/ControllerTest/controller_test.cpp index 78afc443..ba609865 100644 --- a/examples/PoolBox/application/src/Overlay/ControllerTest/controller_test.cpp +++ b/examples/PoolBox/application/src/Overlay/ControllerTest/controller_test.cpp @@ -1,5 +1,4 @@ #include "../../../include/shared.hpp" -#include "../../include/font_writer.hpp" #include "include/controller_state.hpp" #include #include @@ -7,11 +6,13 @@ namespace ControllerTest { using namespace JabyEngine; - static auto controller_state = ControllerState::create(); + static auto controller_state0 = ControllerState::create(Make::PositionI16(0, 0)); + static auto controller_state1 = ControllerState::create(Make::PositionI16(0, 76)); static void setup() { Shared::back_menu.reset(); - controller_state.setup(); + controller_state0.setup(); + controller_state1.setup(); } static bool update_or_exit() { @@ -20,12 +21,15 @@ namespace ControllerTest { return true; } - controller_state.update(Periphery::get_primary_controller_as(), FontWriter::new_font_writer); + controller_state0.update(&Periphery::get_primary_controller_as(), FontWriter::new_font_writer); + controller_state1.update(Periphery::PortCount > 1 ? &Periphery::get_controller_as(1, 0) : nullptr, FontWriter::new_font_writer); return false; } static void render() { - controller_state.render(); + GPU::render(Shared::background); + controller_state0.render(); + controller_state1.render(); FontWriter::new_font_writer.render(); Shared::back_menu.render(); } diff --git a/examples/PoolBox/application/src/Overlay/ControllerTest/include/controller_state.hpp b/examples/PoolBox/application/src/Overlay/ControllerTest/include/controller_state.hpp index aa242e66..f64e5365 100644 --- a/examples/PoolBox/application/src/Overlay/ControllerTest/include/controller_state.hpp +++ b/examples/PoolBox/application/src/Overlay/ControllerTest/include/controller_state.hpp @@ -61,7 +61,7 @@ namespace ControllerTest { } void setup(); - void update(const Periphery::AnalogeController& controller, JabyEngine::FontWriter& font_writer); + void update(const Periphery::AnalogeController* controller, JabyEngine::FontWriter& font_writer); void render(); }; } \ No newline at end of file diff --git a/examples/PoolBox/application/src/application.cpp b/examples/PoolBox/application/src/application.cpp index 5c3996ad..11a87536 100644 --- a/examples/PoolBox/application/src/application.cpp +++ b/examples/PoolBox/application/src/application.cpp @@ -46,7 +46,11 @@ static StateChange state_changer; static StateChange old_state_changer; namespace Shared { - Menu::BackMenu back_menu; + Menu::BackMenu back_menu; + JabyEngine::GPU::POLY_G4 background = Make::POLY_G4( + Make::AreaI16(0, 0, GPU::Display::Width, GPU::Display::Height), + {GPU::Color24::Red(0xA0), GPU::Color24::Green(0xA0), GPU::Color24::Blue(0xA0), GPU::Color24::Black()} + ); } static void setup() { @@ -84,6 +88,7 @@ namespace NormalScene { } static void render() { + GPU::render(Shared::background); FontWriter::new_font_writer.render(); FontWriter::bios_font_writer.render(); paco.render();