Broken UI and Loading screens
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "renderer.hh"
|
||||
#include "splashpack.hh"
|
||||
#include "luaapi.hh"
|
||||
#include "loadingscreen.hh"
|
||||
|
||||
#include "lua.h"
|
||||
|
||||
@@ -19,7 +20,9 @@ using namespace psxsplash;
|
||||
// Static member definition
|
||||
psyqo::Font<>* psxsplash::SceneManager::s_font = nullptr;
|
||||
|
||||
void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData, LoadingScreen* loading) {
|
||||
auto& gpu = Renderer::GetInstance().getGPU();
|
||||
|
||||
L.Reset();
|
||||
|
||||
// Initialize audio system
|
||||
@@ -35,6 +38,8 @@ void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
SplashpackSceneSetup sceneSetup;
|
||||
m_loader.LoadSplashpack(splashpackData, sceneSetup);
|
||||
|
||||
if (loading && loading->isActive()) loading->updateProgress(gpu, 40);
|
||||
|
||||
m_luaFiles = std::move(sceneSetup.luaFiles);
|
||||
m_gameObjects = std::move(sceneSetup.objects);
|
||||
m_objectNames = std::move(sceneSetup.objectNames);
|
||||
@@ -76,6 +81,8 @@ void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
m_audio.loadClip((int)i, clip.adpcmData, clip.sizeBytes, clip.sampleRate, clip.loop);
|
||||
}
|
||||
|
||||
if (loading && loading->isActive()) loading->updateProgress(gpu, 55);
|
||||
|
||||
// Copy cutscene data into scene manager storage (sceneSetup is stack-local)
|
||||
m_cutsceneCount = sceneSetup.cutsceneCount;
|
||||
for (int i = 0; i < m_cutsceneCount; i++) {
|
||||
@@ -99,6 +106,8 @@ void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
m_uiSystem.uploadFonts(Renderer::GetInstance().getGPU());
|
||||
Renderer::GetInstance().SetUISystem(&m_uiSystem);
|
||||
|
||||
if (loading && loading->isActive()) loading->updateProgress(gpu, 70);
|
||||
|
||||
// Resolve UI track handles: the splashpack loader stored raw name pointers
|
||||
// in CutsceneTrack.target for UI tracks. Now that UISystem is loaded, resolve
|
||||
// those names to canvas indices / element handles.
|
||||
@@ -196,6 +205,8 @@ void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
L.LoadLuaFile(luaFile->luaCode, luaFile->length, i);
|
||||
}
|
||||
|
||||
if (loading && loading->isActive()) loading->updateProgress(gpu, 85);
|
||||
|
||||
L.RegisterSceneScripts(sceneSetup.sceneLuaFileIndex);
|
||||
|
||||
L.OnSceneCreationStart();
|
||||
@@ -209,6 +220,8 @@ void psxsplash::SceneManager::InitializeScene(uint8_t* splashpackData) {
|
||||
Renderer::GetInstance().SetCamera(m_currentCamera);
|
||||
|
||||
L.OnSceneCreationEnd();
|
||||
|
||||
if (loading && loading->isActive()) loading->updateProgress(gpu, 100);
|
||||
}
|
||||
|
||||
void psxsplash::SceneManager::GameTick(psyqo::GPU &gpu) {
|
||||
@@ -606,10 +619,24 @@ void psxsplash::SceneManager::processPendingSceneLoad() {
|
||||
int targetIndex = m_pendingSceneIndex;
|
||||
m_pendingSceneIndex = -1;
|
||||
|
||||
auto& gpu = Renderer::GetInstance().getGPU();
|
||||
|
||||
// Build filename: scene_N.splashpack
|
||||
char filename[32];
|
||||
snprintf(filename, sizeof(filename), "scene_%d.splashpack", targetIndex);
|
||||
|
||||
// Blank the screen immediately so the user doesn't see a frozen frame
|
||||
gpu.clear(psyqo::Color{.r = 0, .g = 0, .b = 0});
|
||||
gpu.pumpCallbacks();
|
||||
|
||||
// Try to load a loading screen for the target scene
|
||||
LoadingScreen loading;
|
||||
if (s_font) {
|
||||
if (loading.load(gpu, *s_font, targetIndex)) {
|
||||
loading.renderInitialAndFree(gpu);
|
||||
}
|
||||
}
|
||||
|
||||
// 1. Tear down EVERYTHING in the current scene first —
|
||||
// Lua VM, vector backing storage, audio. This returns as much
|
||||
// heap memory as possible before any new allocation.
|
||||
@@ -624,16 +651,22 @@ void psxsplash::SceneManager::processPendingSceneLoad() {
|
||||
m_currentSceneData = nullptr;
|
||||
}
|
||||
|
||||
if (loading.isActive()) loading.updateProgress(gpu, 20);
|
||||
|
||||
// 3. Allocate new scene data (heap is now maximally consolidated)
|
||||
int fileSize = 0;
|
||||
uint8_t* newData = SceneLoader::LoadFile(filename, fileSize);
|
||||
if (!newData) return;
|
||||
if (!newData) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (loading.isActive()) loading.updateProgress(gpu, 30);
|
||||
|
||||
m_currentSceneData = newData;
|
||||
m_currentSceneIndex = targetIndex;
|
||||
|
||||
// 4. Initialize with new data (creates fresh Lua VM inside)
|
||||
InitializeScene(newData);
|
||||
InitializeScene(newData, loading.isActive() ? &loading : nullptr);
|
||||
}
|
||||
|
||||
void psxsplash::SceneManager::clearScene() {
|
||||
|
||||
Reference in New Issue
Block a user