Support exiting GPU Test

This commit is contained in:
Jaby 2024-01-03 22:44:13 -06:00
parent a0fed6f756
commit 839b9a45c3
5 changed files with 80 additions and 3 deletions

View File

@ -0,0 +1,6 @@
#pragma once
#include "../src/include/menu.hpp"
namespace Shared {
extern Menu::BackMenu back_menu;
}

View File

@ -1,6 +1,8 @@
#include "../../../include/shared.hpp"
#include "include/gpu_test_assets.hpp" #include "include/gpu_test_assets.hpp"
#include <PSX/GPU/gpu.hpp> #include <PSX/GPU/gpu.hpp>
#include <PSX/GPU/make_gpu_primitives.hpp> #include <PSX/GPU/make_gpu_primitives.hpp>
#include <PSX/Periphery/periphery.hpp>
#include <stdio.h> #include <stdio.h>
namespace GPUTest { namespace GPUTest {
@ -118,8 +120,17 @@ namespace GPUTest {
void main() { void main() {
rect9.concat(rect10); rect9.concat(rect10);
Shared::back_menu.reset();
while(true) { while(true) {
// Update Phase
Periphery::query_controller();
if(Shared::back_menu.update(Make::PositionI16(0, GPU::Display::Height - 32))) {
break;
}
GPU::swap_buffers_vsync(2);
GPU::render(triangle1); GPU::render(triangle1);
GPU::render(triangle2); GPU::render(triangle2);
GPU::render(triangle3); GPU::render(triangle3);
@ -147,8 +158,7 @@ namespace GPUTest {
GPU::render(line4); GPU::render(line4);
GPU::render(rect9); GPU::render(rect9);
Shared::back_menu.render();
GPU::swap_buffers_vsync(2);
} }
} }
} }

View File

@ -45,10 +45,16 @@ static Menu::SimpleMenu menu;
static StateChange state_changer; static StateChange state_changer;
static StateChange old_state_changer; static StateChange old_state_changer;
namespace Shared {
Menu::BackMenu back_menu;
}
static void setup() { static void setup() {
Assets::Main::load(); Assets::Main::load();
FontWriter::setup(); FontWriter::setup();
paco.setup(); paco.setup();
Shared::back_menu.setup(&FontWriter::bios_font_writer);
menu.setup([](uint32_t selection) { menu.setup([](uint32_t selection) {
switch(selection) { switch(selection) {
case 0: case 0:

View File

@ -1,6 +1,7 @@
#pragma once #pragma once
#include "font_writer.hpp" #include "font_writer.hpp"
#include <FontWriter/font_writer.hpp> #include <FontWriter/font_writer.hpp>
#include <PSX/Timer/frame_timer.hpp>
namespace Menu { namespace Menu {
using namespace JabyEngine; using namespace JabyEngine;
@ -29,4 +30,21 @@ namespace Menu {
void update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start); void update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start);
}; };
class BackMenu {
private:
JabyEngine::FontWriter* font_writer;
SimpleTimer<uint32_t> timeout;
bool waiting;
public:
void setup(JabyEngine::FontWriter* font_writer);
void reset() {
this->timeout.reset();
this->waiting = false;
}
bool update(const GPU::PositionI16& position);
void render();
};
} }

View File

@ -2,6 +2,8 @@
#include <PSX/Periphery/periphery.hpp> #include <PSX/Periphery/periphery.hpp>
namespace Menu { namespace Menu {
using DigitalButton = Periphery::GenericController::Button;
void SimpleMenu :: setup(Callback callback, const Entry* entries, size_t size) { void SimpleMenu :: setup(Callback callback, const Entry* entries, size_t size) {
this->selection_callback = callback; this->selection_callback = callback;
this->entries = entries; this->entries = entries;
@ -10,7 +12,6 @@ namespace Menu {
} }
void SimpleMenu :: update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start) { void SimpleMenu :: update(JabyEngine::FontWriter& font_writer, State& cursor, const GPU::PositionI16& start) {
using DigitalButton = Periphery::GenericController::Button;
const auto& controller = Periphery::get_primary_controller_as<JabyEngine::Periphery::GenericController>(); const auto& controller = Periphery::get_primary_controller_as<JabyEngine::Periphery::GenericController>();
if(controller.button.went_down(DigitalButton::Up) && this->cur_selection > 0) { if(controller.button.went_down(DigitalButton::Up) && this->cur_selection > 0) {
@ -38,4 +39,40 @@ namespace Menu {
} }
} }
} }
void BackMenu :: setup(JabyEngine::FontWriter* font_writer) {
this->font_writer = font_writer;
this->timeout.reset();
this->waiting = false;
}
bool BackMenu :: update(const GPU::PositionI16& position) {
const auto& controller = Periphery::get_primary_controller_as<JabyEngine::Periphery::GenericController>();
if(controller.button.is_down(DigitalButton::Circle)) {
this->waiting = true;
if(this->timeout.is_expired_for(2500_ms)) {
return true;
}
}
else {
this->waiting = false;
this->timeout.reset();
}
if(this->waiting) {
auto state = JabyEngine::State::create(position);
this->font_writer->write(state, "Press and hold ()\nto get back", GPU::Color24::Red());
}
else {
this->font_writer->clear();
}
return false;
}
void BackMenu :: render() {
this->font_writer->render();
}
} }