Remove filtering options from the GameList

This commit is contained in:
Maschell 2020-02-24 18:44:02 +01:00
parent e07c0aa47c
commit 7815e5b3fc
3 changed files with 34 additions and 152 deletions

View File

@ -9,10 +9,17 @@
#include "GameList.h" #include "GameList.h"
#include "common/common.h" #include "common/common.h"
#include "fs/DirList.h"
#include "fs/FSUtils.h" #include "fs/FSUtils.h"
#include "utils/logger.h" #include "utils/logger.h"
#include "utils/StringTools.h"
GameList::GameList() {
}
GameList::~GameList() {
stopAsyncLoading = true;
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
clear();
};
void GameList::clear() { void GameList::clear() {
lock(); lock();
@ -25,24 +32,24 @@ void GameList::clear() {
delete x; delete x;
} }
} }
gameFilter.clear();
fullGameList.clear(); fullGameList.clear();
filteredList.clear();
//! Clear memory of the vector completely //! Clear memory of the vector completely
std::vector<gameInfo *>().swap(filteredList);
std::vector<gameInfo*>().swap(fullGameList); std::vector<gameInfo*>().swap(fullGameList);
unlock(); unlock();
titleListChanged(this); titleListChanged(this);
} }
gameInfo * GameList::getGameInfo(uint64_t titleId) const { gameInfo * GameList::getGameInfo(uint64_t titleId){
for (uint32_t i = 0; i < filteredList.size(); ++i) { gameInfo * result = NULL;
if(titleId == filteredList[i]->titleId) lock();
return filteredList[i]; for (uint32_t i = 0; i < fullGameList.size(); ++i) {
if(titleId == fullGameList[i]->titleId){
result = fullGameList[i];
break;
}
} }
unlock();
return NULL; return result;
} }
extern "C" int ACPGetTitleMetaXml(uint64_t titleid, ACPMetaXml*); extern "C" int ACPGetTitleMetaXml(uint64_t titleid, ACPMetaXml*);
@ -82,7 +89,7 @@ int32_t GameList::readGameList() {
} }
for (auto title_candidate : titles) { for (auto title_candidate : titles) {
if((title_candidate.titleId & 0xFFFFFFFF00000000L) == 0x0005000000000000L) { if(true || (title_candidate.titleId & 0xFFFFFFFF00000000L) == 0x0005000000000000L) {
gameInfo* newGameInfo = new gameInfo; gameInfo* newGameInfo = new gameInfo;
newGameInfo->titleId = title_candidate.titleId; newGameInfo->titleId = title_candidate.titleId;
newGameInfo->gamePath = title_candidate.path; newGameInfo->gamePath = title_candidate.path;
@ -183,78 +190,17 @@ void GameList::updateTitleInfo() {
} }
} }
void GameList::internalFilterList(std::vector<gameInfo*> &fullList) { int32_t GameList::load() {
for (uint32_t i = 0; i < fullList.size(); ++i) {
gameInfo *header = fullList[i];
if (StringTools::findStringIC(header->name,gameFilter)) {
filteredList.push_back(header);
}
}
}
int32_t GameList::filterList(const char * filter) {
lock();
if(filter) {
gameFilter = filter;
}
if(fullGameList.size() == 0) {
readGameList();
}
filteredList.clear();
// Filter current game list if selected
internalFilterList(fullGameList);
sortList();
titleListChanged(this);
AsyncExecutor::execute([&] { updateTitleInfo();});
int32_t res = filteredList.size();
unlock();
return res;
}
void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
for (uint32_t i = 0; i < fullList.size(); ++i) {
gameInfo *header = fullList[i];
filteredList.push_back(header);
}
}
int32_t GameList::loadUnfiltered() {
lock(); lock();
if(fullGameList.size() == 0) { if(fullGameList.size() == 0) {
readGameList(); readGameList();
} }
gameFilter.clear();
filteredList.clear();
// Filter current game list if selected
internalLoadUnfiltered(fullGameList);
sortList();
AsyncExecutor::execute([&] { updateTitleInfo();}); AsyncExecutor::execute([&] { updateTitleInfo();});
titleListChanged(this); titleListChanged(this);
int res = filteredList.size(); int res = fullGameList.size();
unlock(); unlock();
return res; return res;
} }
void GameList::sortList() {
lock();
std::sort(filteredList.begin(), filteredList.end(), nameSortCallback);
unlock();
}
bool GameList::nameSortCallback(const gameInfo *a, const gameInfo *b) {
return (strcasecmp(((gameInfo *) a)->name.c_str(), ((gameInfo *) b)->name.c_str()) < 0);
}

View File

@ -18,16 +18,12 @@ typedef struct _gameInfo {
class GameList { class GameList {
public: public:
GameList() : selectedGame(0) { }; GameList();
~GameList() { ~GameList();
stopAsyncLoading = true;
DCFlushRange(&stopAsyncLoading, sizeof(stopAsyncLoading));
clear();
};
int32_t size() { int32_t size() {
lock(); lock();
int32_t res = filteredList.size(); int32_t res = fullGameList.size();
unlock(); unlock();
return res; return res;
} }
@ -37,8 +33,6 @@ public:
unlock(); unlock();
return res; return res;
} }
int32_t filterList(const char * gameFilter = NULL);
int32_t loadUnfiltered();
gameInfo * at(int32_t i) { gameInfo * at(int32_t i) {
return operator[](i); return operator[](i);
@ -46,68 +40,24 @@ public:
gameInfo * operator[](int32_t i) { gameInfo * operator[](int32_t i) {
lock(); lock();
gameInfo * res = NULL; gameInfo * res = NULL;
if (i < 0 || i >= (int32_t) filteredList.size()) if (i < 0 || i >= (int32_t) fullGameList.size()) {
res = NULL; res = NULL;
res = filteredList[i]; } else {
res = fullGameList[i];
}
unlock(); unlock();
return res; return res;
} }
gameInfo * getGameInfo(uint64_t titleId) const; gameInfo * getGameInfo(uint64_t titleId);
const char * getCurrentFilter() const {
return gameFilter.c_str();
}
void sortList();
void clear(); void clear();
bool operator!() {
lock();
bool res = (fullGameList.size() == 0);
unlock();
return res;
}
//! Gamelist scrolling operators
int32_t operator+=(int32_t i) {
lock();
int32_t res = (selectedGame = (selectedGame+i) % filteredList.size());
unlock();
return res;
}
int32_t operator-=(int32_t i) {
lock();
int32_t res = (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
unlock();
return res;
}
int32_t operator++() {
lock();
int32_t res = (selectedGame = (selectedGame+1) % filteredList.size());
unlock();
return res;
}
int32_t operator--() {
lock();
int32_t res = (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
unlock();
return res;
}
int32_t operator++(int32_t i) {
return operator++();
}
int32_t operator--(int32_t i) {
return operator--();
}
gameInfo * GetCurrentSelected() {
return operator[](selectedGame);
}
std::vector<gameInfo *> & getfilteredList(void) {
return filteredList;
}
std::vector<gameInfo *> & getFullGameList(void) { std::vector<gameInfo *> & getFullGameList(void) {
return fullGameList; return fullGameList;
} }
int32_t load();
sigslot::signal1<GameList *> titleListChanged; sigslot::signal1<GameList *> titleListChanged;
sigslot::signal1<gameInfo *> titleUpdated; sigslot::signal1<gameInfo *> titleUpdated;
sigslot::signal1<gameInfo *> titleAdded; sigslot::signal1<gameInfo *> titleAdded;
@ -115,25 +65,13 @@ public:
void lock() { void lock() {
_lock.lock(); _lock.lock();
} }
void unlock(){ void unlock() {
_lock.unlock(); _lock.unlock();
} }
protected: protected:
int32_t readGameList(); int32_t readGameList();
void internalFilterList(std::vector<gameInfo*> & fullList);
void internalLoadUnfiltered(std::vector<gameInfo*> & fullList);
void updateTitleInfo(); void updateTitleInfo();
static bool nameSortCallback(const gameInfo *a, const gameInfo *b);
static GameList *gameListInstance;
std::string gameFilter;
int32_t selectedGame;
std::vector<gameInfo *> filteredList;
std::vector<gameInfo *> fullGameList; std::vector<gameInfo *> fullGameList;
std::recursive_mutex _lock; std::recursive_mutex _lock;

View File

@ -45,7 +45,7 @@ MainWindow::MainWindow(int32_t w, int32_t h)
gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged); gameList.titleListChanged.connect(this, &MainWindow::OnGameTitleListChanged);
gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated); gameList.titleUpdated.connect(this, &MainWindow::OnGameTitleUpdated);
gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded); gameList.titleAdded.connect(this, &MainWindow::OnGameTitleAdded);
AsyncExecutor::execute([&] {gameList.loadUnfiltered();}); AsyncExecutor::execute([&] {gameList.load();});
} }
@ -119,8 +119,6 @@ void MainWindow::process() {
currentTvFrame->clearState(GuiElement::STATE_DISABLED); currentTvFrame->clearState(GuiElement::STATE_DISABLED);
currentDrcFrame->clearState(GuiElement::STATE_DISABLED); currentDrcFrame->clearState(GuiElement::STATE_DISABLED);
mainSwitchButtonFrame->clearState(GuiElement::STATE_DISABLED); mainSwitchButtonFrame->clearState(GuiElement::STATE_DISABLED);
gameList.filterList(result.c_str());
} else { } else {
} }
} }