Skip to content

Commit 33aadb3

Browse files
committed
fix song cache
this change makes it so that you have to go to the settings screen to scan songs, over the game confusingly scanning songs before the game even allows you to do anything the first time. matches other game behaviours
1 parent ff573a6 commit 33aadb3

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

Encore/src/menus/cacheLoadingScreen.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "cacheLoadingScreen.h"
66

77
#include <filesystem>
8+
#include <mutex>
89
#include <thread>
910

1011
#include "gameMenu.h"
@@ -39,8 +40,8 @@ void cacheLoadingScreen::Load() {
3940

4041
// todo(3drosalia): make another class for drawing these things without having to uh.
4142
// implement it in every menu class
42-
bool finished = false;
43-
bool started = false;
43+
std::atomic_bool finished = false;
44+
std::atomic_bool started = false;
4445

4546
void LoadCache() {
4647
TheSongList.LoadCache(TheGameSettings.SongPaths);
@@ -111,11 +112,12 @@ void cacheLoadingScreen::Draw() {
111112
);
112113
if (!started) {
113114
started = true;
114-
std::thread CacheLoader(LoadCache);
115+
std::jthread CacheLoader(LoadCache);
115116
CacheLoader.detach();
116117
}
117-
if (finished)
118+
if (finished) {
118119
TheMenuManager.SwitchScreen(MAIN_MENU);
120+
}
119121
}
120122

121123
cacheLoadingScreen::~cacheLoadingScreen() {}

Encore/src/menus/gameMenu.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ void MainMenu::MainMenuScreen() {
393393
"Invalid song cache!"
394394
);
395395
// TheSongList.ScanSongs(TheGameSettings.SongPaths);
396-
songsLoaded = false;
397396
DrawRectanglePro(
398397
{ ((float)GetScreenWidth() / 2) - 125,
399398
((float)GetScreenHeight() / 2) - 120,

Encore/src/song/songlist.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ void SongList::ScanFolder(const std::filesystem::path &folder) {
185185
std::filesystem::path infoPath = folder / "info.json";
186186
if (std::filesystem::exists(infoPath)) {
187187
Song song;
188-
song.songInfoPath = (folder / "info.json");
188+
song.songInfoPath = folder / "info.json";
189189
song.songDir = folder.string();
190190
for (auto &file : std::filesystem::directory_iterator(folder)) {
191191
if (file.path().stem() == "cover") {
@@ -197,7 +197,7 @@ void SongList::ScanFolder(const std::filesystem::path &folder) {
197197
songs.push_back(std::move(song));
198198
} else if (std::filesystem::exists(folder / "song.ini")) {
199199
Song song;
200-
song.songInfoPath = (folder / "song.ini").string();
200+
song.songInfoPath = folder / "song.ini";
201201
song.songDir = folder.string();
202202
song.LoadSongIni(folder);
203203
song.ini = true;
@@ -371,23 +371,23 @@ void SongList::LoadCache(const std::vector<std::filesystem::path> &songsFolder)
371371

372372
jsonHashNew = picosha2::hash256_hex_string(jsonString);
373373
}
374-
375-
if (song.jsonHash != jsonHashNew) {
376-
continue;
377-
}
374+
// todo: FIX THIS
375+
//if (song.jsonHash != jsonHashNew) {
376+
// continue;
377+
//}
378378
loadedSongs.insert(song.songDir);
379-
songs.push_back(std::move(song));
379+
this->songs.emplace_back(song);
380380

381381
}
382382

383383
SongCacheIn.close();
384384
size_t loadedSongCount = songs.size();
385385

386386

387-
if (cachedSongCount != loadedSongCount || songs.size() != loadedSongCount) {
388-
Encore::EncoreLog(LOG_INFO, "CACHE: Updating song cache");
389-
WriteCache();
390-
}
387+
//if (cachedSongCount != loadedSongCount || songs.size() != loadedSongCount) {
388+
// Encore::EncoreLog(LOG_INFO, "CACHE: Updating song cache");
389+
// WriteCache();
390+
//}
391391

392392
// ScanSongs(songsFolder);
393393
sortList(SortType::Title);

0 commit comments

Comments
 (0)