Broken runtime
This commit is contained in:
81
src/main.cpp
81
src/main.cpp
@@ -4,13 +4,16 @@
|
||||
#include <psyqo/font.hh>
|
||||
#include <psyqo/gpu.hh>
|
||||
#include <psyqo/scene.hh>
|
||||
#include <psyqo/task.hh>
|
||||
#include <psyqo/trigonometry.hh>
|
||||
|
||||
#include "renderer.hh"
|
||||
#include "scenemanager.hh"
|
||||
#include "sceneloader.hh"
|
||||
#include "pcdrv_handler.hh"
|
||||
#include "loadingscreen.hh"
|
||||
#include "fileloader.hh"
|
||||
|
||||
#if defined(LOADER_CDROM)
|
||||
#include "fileloader_cdrom.hh"
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -30,11 +33,10 @@ class MainScene final : public psyqo::Scene {
|
||||
|
||||
psxsplash::SceneManager m_sceneManager;
|
||||
|
||||
// Loading screen (persists between scenes; owned here, passed to SceneManager)
|
||||
psxsplash::LoadingScreen m_loadingScreen;
|
||||
|
||||
// PCdrv-loaded scene data (owned)
|
||||
uint8_t* m_sceneData = nullptr;
|
||||
// Task queue for async FileLoader init (CD-ROM reset + ISO parse).
|
||||
// After init completes, loadScene() handles everything synchronously.
|
||||
psyqo::TaskQueue m_initQueue;
|
||||
bool m_ready = false;
|
||||
};
|
||||
|
||||
PSXSplash app;
|
||||
@@ -52,6 +54,16 @@ void PSXSplash::prepare() {
|
||||
|
||||
// Initialize the Renderer singleton
|
||||
psxsplash::Renderer::Init(gpu());
|
||||
|
||||
// Let the active file-loader backend do any early setup.
|
||||
// CDRom: CDRomDevice::prepare() must happen here.
|
||||
psxsplash::FileLoader::Get().prepare();
|
||||
|
||||
#if defined(LOADER_CDROM)
|
||||
// The CD-ROM backend needs a GPU pointer for LoadFileSync's spin loop.
|
||||
static_cast<psxsplash::FileLoaderCDRom&>(
|
||||
psxsplash::FileLoader::Get()).setGPU(&gpu());
|
||||
#endif
|
||||
}
|
||||
|
||||
void PSXSplash::createScene() {
|
||||
@@ -61,42 +73,31 @@ void PSXSplash::createScene() {
|
||||
}
|
||||
|
||||
void MainScene::start(StartReason reason) {
|
||||
// On real hardware: register break handler for PCDRV over SIO1 + redirect printf
|
||||
// On emulator: no-op (pcsx-redux handles PCDRV natively)
|
||||
psxsplash::pcdrv_sio1_init();
|
||||
// Initialise the FileLoader backend, then load scene 0 through
|
||||
// the same SceneManager::loadScene() path used for all transitions.
|
||||
//
|
||||
// For PCdrv the init task resolves synchronously so both steps
|
||||
// execute in one go. For CD-ROM the init is async (drive reset +
|
||||
// ISO9660 parse) and yields to the main loop until complete.
|
||||
|
||||
// Initialize PCdrv (break instructions - handled by emulator or our break handler)
|
||||
psxsplash::SceneLoader::Init();
|
||||
|
||||
// Blank display immediately so the user never sees a frozen frame
|
||||
gpu().clear(psyqo::Color{.r = 0, .g = 0, .b = 0});
|
||||
gpu().pumpCallbacks();
|
||||
|
||||
// Try to load a loading screen for scene 0
|
||||
if (m_loadingScreen.load(gpu(), app.m_font, 0)) {
|
||||
m_loadingScreen.renderInitialAndFree(gpu());
|
||||
}
|
||||
|
||||
// Load the first scene via PCdrv.
|
||||
// Files are relative to the pcdrvbase directory (PSXBuild/).
|
||||
int fileSize = 0;
|
||||
m_sceneData = psxsplash::SceneLoader::LoadFile("scene_0.splashpack", fileSize);
|
||||
|
||||
if (!m_sceneData) {
|
||||
// Fallback: try legacy name for backwards compatibility
|
||||
m_sceneData = psxsplash::SceneLoader::LoadFile("output.bin", fileSize);
|
||||
}
|
||||
|
||||
if (m_loadingScreen.isActive()) {
|
||||
m_loadingScreen.updateProgress(gpu(), 30);
|
||||
}
|
||||
|
||||
if (m_sceneData) {
|
||||
m_sceneManager.InitializeScene(m_sceneData, &m_loadingScreen);
|
||||
}
|
||||
m_initQueue
|
||||
.startWith(psxsplash::FileLoader::Get().scheduleInit())
|
||||
.then([this](psyqo::TaskQueue::Task* task) {
|
||||
m_sceneManager.loadScene(gpu(), 0, /*isFirstScene=*/true);
|
||||
m_ready = true;
|
||||
task->resolve();
|
||||
})
|
||||
.butCatch([](psyqo::TaskQueue*) {
|
||||
// FileLoader init failed — nothing we can do on PS1.
|
||||
})
|
||||
.run();
|
||||
}
|
||||
|
||||
void MainScene::frame() {
|
||||
// Don't run the game loop while FileLoader init is still executing
|
||||
// (only relevant for the async CD-ROM backend).
|
||||
if (!m_ready) return;
|
||||
|
||||
uint32_t beginFrame = gpu().now();
|
||||
auto currentFrameCounter = gpu().getFrameCount();
|
||||
auto deltaTime = currentFrameCounter - mainScene.m_lastFrameCounter;
|
||||
|
||||
Reference in New Issue
Block a user