Skip to content

Commit

Permalink
add song browser lag fix (robtop bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Dec 18, 2023
1 parent 511539a commit 1d3035b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 7 deletions.
6 changes: 0 additions & 6 deletions src/hooks/MoreSearchLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class $modify(BIMoreSearchLayer, MoreSearchLayer) {
}

void onSaved(CCObject* sender){
log::info("{}", m_fields->m_settings);

auto browser = GJSongBrowser::create(m_fields->m_settings);
CCScene::get()->addChild(browser);
browser->setZOrder(CCScene::get()->getHighestChildZ() + 1);
Expand All @@ -36,12 +34,8 @@ class $modify(BIMoreSearchLayer, MoreSearchLayer) {
void onSongIDCheck(float dt){
if(m_fields->m_settings->m_level->m_songID != m_fields->m_songID){
m_fields->m_songID = m_fields->m_settings->m_level->m_songID;

log::info("Song ID changed: {}", m_fields->m_songID);
GameLevelManager::sharedState()->setIntForKey(m_fields->m_songID, "song_filter");
m_enterSongID->setString(std::to_string(m_fields->m_songID));

log::info("CCTextInputNode* m_enterSongID; {}", m_enterSongID);
}
}

Expand Down
35 changes: 35 additions & 0 deletions src/hooks/bugfixes/SongBrowserLag.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <Geode/Bindings.hpp>
#include <Geode/modify/MusicDownloadManager.hpp>
#include <Geode/modify/LevelInfoLayer.hpp>

#include "../../managers/BetterInfoCache.h"

using namespace geode::prelude;

class $modify(BIMusicDownloadManager, MusicDownloadManager) {
bool isSongDownloaded(int songID) {
auto BICache = BetterInfoCache::sharedState();
if(BICache->m_downloadedSongs.contains(songID)) {
return BICache->m_downloadedSongs[songID];
}

BICache->m_downloadedSongs[songID] = MusicDownloadManager::isSongDownloaded(songID);
return BICache->m_downloadedSongs[songID];
}
};

class $modify(BISBLLevelInfoLayer, LevelInfoLayer) {
void onPlay(CCObject* sender) {
auto BICache = BetterInfoCache::sharedState();
if(BICache->m_downloadedSongs.contains(this->m_level->m_songID)) BICache->m_downloadedSongs.erase(this->m_level->m_songID);

LevelInfoLayer::onPlay(sender);
}

bool init(GJGameLevel* level) {
auto BICache = BetterInfoCache::sharedState();
if(BICache->m_downloadedSongs.contains(level->m_songID)) BICache->m_downloadedSongs.erase(level->m_songID);

return LevelInfoLayer::init(level);
}
};
26 changes: 25 additions & 1 deletion src/managers/BetterInfoCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ bool BetterInfoCache::init(){
if(!BaseJsonManager::init("cache.json")) return false;
Loader::get()->queueInMainThread([this]() {
checkDailies();
populateDownloadedSongsFast();
});
return true;
}
Expand Down Expand Up @@ -253,4 +254,27 @@ void BetterInfoCache::loadListFinished(cocos2d::CCArray* levels, const char*) {
}

void BetterInfoCache::loadListFailed(const char*) {}
void BetterInfoCache::setupPageInfo(std::string, const char*) {}
void BetterInfoCache::setupPageInfo(std::string, const char*) {}

void BetterInfoCache::populateDownloadedSongsFast() {
auto MDM = MusicDownloadManager::sharedState();
std::vector<int> knownSongs;
auto dict = CCDictionaryExt<std::string, CCString>(MDM->m_songsDict);
try {
for(auto [id, song] : dict) {
knownSongs.push_back(std::stoi(id));
}
} catch(std::exception) {
log::error("Exception in populateDownloadedSongsFast loop");
return;
}

auto songPath = GameManager::sharedState()->getGameVariable("0033") ? CCFileUtils::sharedFileUtils()->getWritablePath2() : CCFileUtils::sharedFileUtils()->getWritablePath();
std::thread([this, knownSongs, songPath]() {
for(auto song : knownSongs) {
if(ghc::filesystem::exists(fmt::format("{}/{}.mp3", songPath, song))) {
m_downloadedSongs[song] = true;
}
}
}).detach();
}
3 changes: 3 additions & 0 deletions src/managers/BetterInfoCache.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class BetterInfoCache : public BaseJsonManager, public OnlineListDelegate {

public:
UploadDateDelegate* m_uploadDateDelegate = nullptr;
std::unordered_map<int, bool> m_downloadedSongs;

bool init();

Expand Down Expand Up @@ -45,4 +46,6 @@ class BetterInfoCache : public BaseJsonManager, public OnlineListDelegate {
void loadListFinished(cocos2d::CCArray*, const char*);
void loadListFailed(const char*);
void setupPageInfo(std::string, const char*);

void populateDownloadedSongsFast();
};

0 comments on commit 1d3035b

Please sign in to comment.