diff --git a/CMakeLists.txt b/CMakeLists.txt index cc2ad85..fe940dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,7 @@ if (BLAZE_DEBUG) target_compile_definitions(${PROJECT_NAME} PRIVATE BLAZE_DEBUG=1) endif() -CPMAddPackage("gh:dankmeme01/asp2#bf4bc5e") +CPMAddPackage("gh:dankmeme01/asp2#7024af9") CPMAddPackage( NAME Boost VERSION 1.84.0 diff --git a/src/hooks/LoadingLayer.cpp b/src/hooks/LoadingLayer.cpp index a35767f..eff58e9 100644 --- a/src/hooks/LoadingLayer.cpp +++ b/src/hooks/LoadingLayer.cpp @@ -370,10 +370,10 @@ class $modify(MyLoadingLayer, LoadingLayer) { bool init(bool fromReload) { m_fields->startedLoadingGame = std::chrono::high_resolution_clock::now(); - if (!CCLayer::init()) return false; - BLAZE_TIMER_START("(LoadingLayer::init) Initial setup"); + if (!CCLayer::init()) return false; + this->m_fromRefresh = fromReload; CCDirector::get()->m_bDisplayStats = true; CCTexture2D::setDefaultAlphaPixelFormat(cocos2d::kCCTexture2DPixelFormat_Default); @@ -381,11 +381,18 @@ class $modify(MyLoadingLayer, LoadingLayer) { // load the launchsheet and bg in another thread, as fmod setup takes a little bit, and image loading can be parallelized. asp::Thread<> sheetThread; - std::optional launchSheetInitTask; - std::optional bgInitTask; + asp::Channel initTasks; sheetThread.setLoopFunction([&](asp::StopToken<>& stopToken) { - launchSheetInitTask = asyncLoadImage("GJ_LaunchSheet.png", "GJ_LaunchSheet.plist"); - bgInitTask = asyncLoadImage("game_bg_01_001.png", nullptr); +#define ASYNC_IMG(name) if (auto _t = asyncLoadImage(name, nullptr)) { initTasks.push(std::move(_t.value())); } +#define ASYNC_SHEET(name, plist) if (auto _t = asyncLoadImage(name, plist)) { initTasks.push(std::move(_t.value())); } + + ASYNC_SHEET("GJ_LaunchSheet.png", "GJ_LaunchSheet.plist"); + ASYNC_IMG("game_bg_01_001.png"); + ASYNC_IMG("slidergroove.png"); + ASYNC_IMG("sliderBar.png"); + +#undef ASYNC_IMG + stopToken.stop(); }); @@ -397,24 +404,33 @@ class $modify(MyLoadingLayer, LoadingLayer) { FMODAudioEngine::get()->setup(); } + auto* gm = GameManager::get(); + if (gm->m_switchModes) { + gm->m_switchModes = false; + GameLevelManager::get()->getLevelSaveData(); + } + // Continue loading launchsheet BLAZE_TIMER_STEP("Launchsheet loading"); - sheetThread.join(); - if (launchSheetInitTask) { - addTexture(launchSheetInitTask->img, launchSheetInitTask->sheetName); - auto* sfcache = CCSpriteFrameCache::get(); - sfcache->addSpriteFramesWithFile("GJ_LaunchSheet.plist"); - } + auto* sfcache = CCSpriteFrameCache::get(); - if (bgInitTask) { - addTexture(bgInitTask->img, bgInitTask->sheetName); - } + while (true) { + if (initTasks.empty()) { + if (!sheetThread.isStopped()) { + std::this_thread::yield(); + continue; + } else if (initTasks.empty()) { + break; + } + } - auto* gm = GameManager::get(); - if (gm->m_switchModes) { - gm->m_switchModes = false; - GameLevelManager::get()->getLevelSaveData(); + auto iTask = initTasks.popNow(); + + addTexture(iTask.img, iTask.sheetName); + if (iTask.plistToLoad) { + sfcache->addSpriteFramesWithFile("GJ_LaunchSheet.plist"); + } } BLAZE_TIMER_STEP("LoadingLayer UI");