Support Push/Pop in DS

This commit is contained in:
2024-06-01 16:37:00 +02:00
parent 658eed7b46
commit 7dbc829fe8
6 changed files with 98 additions and 41 deletions

View File

@@ -6,11 +6,44 @@
#include <FontWriter/fonts.hpp>
#include <FontWriter/font_writer.hpp>
//#include <PSX/Audio/CDDA.hpp>
#include <PSX/Audio/CDXA.hpp>
#include <PSX/Periphery/periphery.hpp>
#include <stdio.hpp>
using namespace JabyEngine;
struct XAPlayer {
static constexpr auto MaxChannels = 2;
uint8_t channel;
static XAPlayer create() {
return XAPlayer{0};
}
void play() {
this->channel = 0;
Assets::XAAudio::play_fox();
}
void stop() {
CDXA::stop();
}
void change_channel(int8_t step) {
this->channel = (this->channel + step)%MaxChannels;
CDXA::set_channel(this->channel);
}
void push() {
CDXA::push_play();
}
void pop() {
CDXA::pop_play();
}
};
struct StateChange {
void (*asset_load)();
void (*main)();
@@ -46,8 +79,7 @@ static const auto doener_fish = Make::SPRT(
GPU::Color24::Grey()
);
// Do we want this namespace?
// Do we want Paco to be HERE?!
static XAPlayer xa = XAPlayer::create();
static object::Paco paco;
static Menu::SimpleMenu menu;
static StateChange state_changer;
@@ -108,17 +140,29 @@ static void setup() {
// const auto [first_track, last_track] = CDDA::get_tracks();
// CDDA::play(first_track);
Assets::XAAudio::play_fox();
xa.play();
}
namespace NormalScene {
static void update() {
using DigitalButton = Periphery::GenericController::Button;
static const char Title[] = ">> Pool Box <<";
static const char Version[] = "Ver. 0.8.5";
static constexpr auto TitleLength = DefaultFont::Info.estimate_str_render_length(Title);
static constexpr auto VersionLength = DefaultFont::Info.estimate_str_render_length(Version);
Periphery::query_controller();
const auto& controller = Periphery::get_primary_controller_as<JabyEngine::Periphery::GenericController>();
if(controller.button.went_down(DigitalButton::R1)) {
xa.change_channel(1);
}
if(controller.button.went_down(DigitalButton::L1)) {
xa.change_channel(-1);
}
auto cursor = FontWriter::update(Make::PositionI16((GPU::Display::Width-TitleLength)/2, 16));
paco.update();
@@ -165,11 +209,10 @@ namespace LoadingScene {
render();
GPU::swap_buffers_vsync(1);
// TODO: Enable push and pop
//CDDA::push_play();
xa.push();
state_changer.asset_load();
old_state_changer = state_changer;
//CDDA::pop_play();
xa.pop();
}
state_changer.main();