Skip to content

Commit 2412e93

Browse files
committed
threaded song data?
1 parent 636ea0c commit 2412e93

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

src/SongManager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,12 @@ void SongManager::setVibecodedVentilla(const bool value) {
306306

307307
bool SongManager::getVibecodedVentilla() const {
308308
return m_vibecodedVentilla;
309+
}
310+
311+
void SongManager::setFinishedCalculatingSongLengths(const bool value) {
312+
m_finishedCalculatingSongLengths = value;
313+
}
314+
315+
bool SongManager::getFinishedCalculatingSongLengths() const {
316+
return m_finishedCalculatingSongLengths;
309317
}

src/SongManager.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ class SongManager {
9292
geode::Mod* getColonMenuLoopStartTime() const;
9393
void setVibecodedVentilla(const bool);
9494
bool getVibecodedVentilla() const;
95+
void setFinishedCalculatingSongLengths(const bool);
96+
bool getFinishedCalculatingSongLengths() const;
9597

9698
private:
9799
SongManager();
@@ -121,4 +123,5 @@ class SongManager {
121123
int m_towerRepeatCount = 0;
122124
geode::Mod* m_colonMenuLoopStartTime {};
123125
SongToSongData m_songToSongDataMap;
126+
bool m_finishedCalculatingSongLengths;
124127
};

src/Utils.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ void Utils::popualteSongToSongDataMap() {
470470

471471
const std::vector<std::string>& blacklist = songManager.getBlacklist();
472472
const std::vector<std::string>& favorites = songManager.getFavorites();
473+
std::vector<std::filesystem::path> tempKeys = {};
473474

474475
for (const std::string_view song : songManager.getSongs()) {
475476
SongType songType = SongType::Regular;
@@ -488,7 +489,16 @@ void Utils::popualteSongToSongDataMap() {
488489
};
489490

490491
songToSongData.emplace(theirPath, songData);
492+
tempKeys.push_back(theirPath);
491493
}
494+
495+
songManager.setFinishedCalculatingSongLengths(false);
496+
std::thread([&songToSongData, &songManager]() {
497+
for (auto& [path, songData] : songToSongData) {
498+
songData.songLength = SongListLayer::getLength(geode::utils::string::pathToString(path), false);
499+
}
500+
songManager.setFinishedCalculatingSongLengths(true);
501+
}).detach();
492502
}
493503

494504
std::vector<std::string> Utils::parseBlacklistFile(const std::filesystem::path& blacklistFilePath) {

src/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ bool originalOverrideWasEmpty = false;
1717
songManager.setConstantShuffleMode();
1818
songManager.setLastMenuLoopPosition(0);
1919
songManager.setShouldRestoreMenuLoopPoint(true);
20+
songManager.setFinishedCalculatingSongLengths(false);
2021
songManager.setAdvancedLogs(Mod::get()->getSettingValue<bool>("advancedLogs"));
2122
songManager.setVibecodedVentilla(VIBECODED_RADIO && (VIBECODED_RADIO->isEnabled() || VIBECODED_RADIO->shouldLoad()));
2223
if (!std::filesystem::exists(configDir / "playlistOne.txt")) Utils::writeToFile("# This file was generated automatically as it hadn't existed previously.", configDir / "playlistOne.txt");

src/ui/SongControlMenu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void SongControlMenu::onPreviousButton(CCObject*) {
204204
}
205205

206206
void SongControlMenu::onPlaylistButton(CCObject*) {
207+
if (!SongManager::get().getFinishedCalculatingSongLengths()) return FLAlertLayer::create("Hold on a sec!", "Menu Loop Randomizer is still calculating a few things. Hang tight, and try again later.", "I Understand")->show();
207208
SongControlMenu::onClose(nullptr);
208209
SongListLayer::create()->show();
209210
}

0 commit comments

Comments
 (0)