mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
GameDB: Add a mutex, and load on demand instead.
This commit is contained in:
parent
c1a7235767
commit
dc4f22d1a4
3 changed files with 25 additions and 10 deletions
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
GameDB g_gameDB;
|
GameDB g_gameDB;
|
||||||
|
|
||||||
|
static const char *const g_gameDBFilename = "redump.csv";
|
||||||
|
|
||||||
static void SplitCSVLine(const std::string_view str, std::vector<std::string_view> &result) {
|
static void SplitCSVLine(const std::string_view str, std::vector<std::string_view> &result) {
|
||||||
result.clear();
|
result.clear();
|
||||||
|
|
||||||
|
@ -57,11 +59,19 @@ static void SplitSV(std::string_view strv, char delim, bool removeWhiteSpace, st
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameDB::LoadFromVFS(VFSInterface &vfs, const char *filename) {
|
void GameDB::LoadIfNeeded() {
|
||||||
|
if (loaded_) {
|
||||||
|
// Already loaded
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loaded_ = true;
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
uint8_t *data = vfs.ReadFile(filename, &size);
|
uint8_t *data = g_VFS.ReadFile(g_gameDBFilename, &size);
|
||||||
if (!data)
|
if (!data)
|
||||||
return false;
|
return;
|
||||||
|
|
||||||
contents_ = std::string((const char *)data, size);
|
contents_ = std::string((const char *)data, size);
|
||||||
delete[] data;
|
delete[] data;
|
||||||
|
|
||||||
|
@ -99,7 +109,6 @@ bool GameDB::LoadFromVFS(VFSInterface &vfs, const char *filename) {
|
||||||
line.size = items[sizeColumn];
|
line.size = items[sizeColumn];
|
||||||
lines_.push_back(line);
|
lines_.push_back(line);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GameDB::GetColumnIndex(std::string_view name) const {
|
size_t GameDB::GetColumnIndex(std::string_view name) const {
|
||||||
|
@ -129,6 +138,10 @@ bool GameDB::GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> guard(loadMutex_);
|
||||||
|
|
||||||
|
LoadIfNeeded();
|
||||||
|
|
||||||
for (auto &line : lines_) {
|
for (auto &line : lines_) {
|
||||||
for (auto &serial : line.serials) {
|
for (auto &serial : line.serials) {
|
||||||
// Ignore version and stuff for now
|
// Ignore version and stuff for now
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
class VFSInterface;
|
class VFSInterface;
|
||||||
|
|
||||||
|
@ -17,10 +18,12 @@ struct GameDBInfo {
|
||||||
|
|
||||||
class GameDB {
|
class GameDB {
|
||||||
public:
|
public:
|
||||||
bool LoadFromVFS(VFSInterface &vfs, const char *filename);
|
// Warning: Linear search. Don't call it every frame if possible.
|
||||||
bool GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos);
|
bool GetGameInfos(std::string_view id, std::vector<GameDBInfo> *infos);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Call under lock.
|
||||||
|
void LoadIfNeeded();
|
||||||
size_t GetColumnIndex(std::string_view name) const;
|
size_t GetColumnIndex(std::string_view name) const;
|
||||||
|
|
||||||
struct Line {
|
struct Line {
|
||||||
|
@ -36,6 +39,9 @@ private:
|
||||||
std::string contents_;
|
std::string contents_;
|
||||||
std::vector<Line> lines_;
|
std::vector<Line> lines_;
|
||||||
std::vector<std::string_view> columns_;
|
std::vector<std::string_view> columns_;
|
||||||
|
bool loaded_ = false;
|
||||||
|
|
||||||
|
std::mutex loadMutex_;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GameDB g_gameDB;
|
extern GameDB g_gameDB;
|
||||||
|
|
|
@ -784,10 +784,6 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch
|
||||||
// Initialize retro achievements runtime.
|
// Initialize retro achievements runtime.
|
||||||
Achievements::Initialize();
|
Achievements::Initialize();
|
||||||
|
|
||||||
#if !defined(__LIBRETRO__)
|
|
||||||
g_gameDB.LoadFromVFS(g_VFS, "redump.csv");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Must be done restarting by now.
|
// Must be done restarting by now.
|
||||||
restarting = false;
|
restarting = false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue