mirror of
https://github.com/wiiu-env/launchiine.git
synced 2024-11-22 01:39:18 +01:00
Add a mutex for accessing the GameList
This commit is contained in:
parent
25a0aa54e7
commit
340baed8ed
@ -16,6 +16,7 @@
|
|||||||
#include "system/CMutex.h"
|
#include "system/CMutex.h"
|
||||||
|
|
||||||
void GameList::clear() {
|
void GameList::clear() {
|
||||||
|
lock();
|
||||||
for (auto const& x : fullGameList) {
|
for (auto const& x : fullGameList) {
|
||||||
if(x != NULL) {
|
if(x != NULL) {
|
||||||
if(x->imageData != NULL) {
|
if(x->imageData != NULL) {
|
||||||
@ -31,6 +32,8 @@ void GameList::clear() {
|
|||||||
//! Clear memory of the vector completely
|
//! Clear memory of the vector completely
|
||||||
std::vector<gameInfo *>().swap(filteredList);
|
std::vector<gameInfo *>().swap(filteredList);
|
||||||
std::vector<gameInfo*>().swap(fullGameList);
|
std::vector<gameInfo*>().swap(fullGameList);
|
||||||
|
|
||||||
|
unlock();
|
||||||
titleListChanged(this);
|
titleListChanged(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +93,7 @@ int32_t GameList::readGameList() {
|
|||||||
newGameInfo->name = "<unknown>";
|
newGameInfo->name = "<unknown>";
|
||||||
newGameInfo->imageData = NULL;
|
newGameInfo->imageData = NULL;
|
||||||
DCFlushRange(newGameInfo, sizeof(gameInfo));
|
DCFlushRange(newGameInfo, sizeof(gameInfo));
|
||||||
|
|
||||||
fullGameList.push_back(newGameInfo);
|
fullGameList.push_back(newGameInfo);
|
||||||
titleAdded(newGameInfo);
|
titleAdded(newGameInfo);
|
||||||
cnt++;
|
cnt++;
|
||||||
@ -184,6 +188,7 @@ void GameList::internalFilterList(std::vector<gameInfo*> &fullList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t GameList::filterList(const char * filter) {
|
int32_t GameList::filterList(const char * filter) {
|
||||||
|
lock();
|
||||||
if(filter) {
|
if(filter) {
|
||||||
gameFilter = filter;
|
gameFilter = filter;
|
||||||
}
|
}
|
||||||
@ -202,8 +207,9 @@ int32_t GameList::filterList(const char * filter) {
|
|||||||
titleListChanged(this);
|
titleListChanged(this);
|
||||||
|
|
||||||
AsyncExecutor::execute([&] { updateTitleInfo();});
|
AsyncExecutor::execute([&] { updateTitleInfo();});
|
||||||
|
int32_t res = filteredList.size();
|
||||||
return filteredList.size();
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
|
void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
|
||||||
@ -215,6 +221,7 @@ void GameList::internalLoadUnfiltered(std::vector<gameInfo*> & fullList) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int32_t GameList::loadUnfiltered() {
|
int32_t GameList::loadUnfiltered() {
|
||||||
|
lock();
|
||||||
if(fullGameList.size() == 0) {
|
if(fullGameList.size() == 0) {
|
||||||
readGameList();
|
readGameList();
|
||||||
}
|
}
|
||||||
@ -231,11 +238,15 @@ int32_t GameList::loadUnfiltered() {
|
|||||||
|
|
||||||
titleListChanged(this);
|
titleListChanged(this);
|
||||||
|
|
||||||
return filteredList.size();
|
int res = filteredList.size();
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameList::sortList() {
|
void GameList::sortList() {
|
||||||
|
lock();
|
||||||
std::sort(filteredList.begin(), filteredList.end(), nameSortCallback);
|
std::sort(filteredList.begin(), filteredList.end(), nameSortCallback);
|
||||||
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameList::nameSortCallback(const gameInfo *a, const gameInfo *b) {
|
bool GameList::nameSortCallback(const gameInfo *a, const gameInfo *b) {
|
||||||
|
@ -17,24 +17,36 @@ typedef struct _gameInfo {
|
|||||||
class GameList {
|
class GameList {
|
||||||
public:
|
public:
|
||||||
GameList() : selectedGame(0) { };
|
GameList() : selectedGame(0) { };
|
||||||
~GameList() { clear(); };
|
~GameList() {
|
||||||
|
clear();
|
||||||
|
};
|
||||||
|
|
||||||
int32_t size() const {
|
int32_t size() {
|
||||||
return filteredList.size();
|
lock();
|
||||||
|
int32_t res = filteredList.size();
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t gameCount() const {
|
int32_t gameCount() {
|
||||||
return fullGameList.size();
|
lock();
|
||||||
|
int32_t res = fullGameList.size();
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t filterList(const char * gameFilter = NULL);
|
int32_t filterList(const char * gameFilter = NULL);
|
||||||
int32_t loadUnfiltered();
|
int32_t loadUnfiltered();
|
||||||
|
|
||||||
gameInfo * at(int32_t i) const {
|
gameInfo * at(int32_t i) {
|
||||||
return operator[](i);
|
return operator[](i);
|
||||||
}
|
}
|
||||||
gameInfo * operator[](int32_t i) const {
|
gameInfo * operator[](int32_t i) {
|
||||||
|
lock();
|
||||||
|
gameInfo * res = NULL;
|
||||||
if (i < 0 || i >= (int32_t) filteredList.size())
|
if (i < 0 || i >= (int32_t) filteredList.size())
|
||||||
return NULL;
|
res = NULL;
|
||||||
return filteredList[i];
|
res = filteredList[i];
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
gameInfo * getGameInfo(uint64_t titleId) const;
|
gameInfo * getGameInfo(uint64_t titleId) const;
|
||||||
|
|
||||||
@ -43,22 +55,37 @@ public:
|
|||||||
}
|
}
|
||||||
void sortList();
|
void sortList();
|
||||||
void clear();
|
void clear();
|
||||||
bool operator!() const {
|
bool operator!() {
|
||||||
return (fullGameList.size() == 0);
|
lock();
|
||||||
|
bool res = (fullGameList.size() == 0);
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Gamelist scrolling operators
|
//! Gamelist scrolling operators
|
||||||
int32_t operator+=(int32_t i) {
|
int32_t operator+=(int32_t i) {
|
||||||
return (selectedGame = (selectedGame+i) % filteredList.size());
|
lock();
|
||||||
|
int32_t res = (selectedGame = (selectedGame+i) % filteredList.size());
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t operator-=(int32_t i) {
|
int32_t operator-=(int32_t i) {
|
||||||
return (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
|
lock();
|
||||||
|
int32_t res = (selectedGame = (selectedGame-i+filteredList.size()) % filteredList.size());
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t operator++() {
|
int32_t operator++() {
|
||||||
return (selectedGame = (selectedGame+1) % filteredList.size());
|
lock();
|
||||||
|
int32_t res = (selectedGame = (selectedGame+1) % filteredList.size());
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t operator--() {
|
int32_t operator--() {
|
||||||
return (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
|
lock();
|
||||||
|
int32_t res = (selectedGame = (selectedGame-1+filteredList.size()) % filteredList.size());
|
||||||
|
unlock();
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
int32_t operator++(int32_t i) {
|
int32_t operator++(int32_t i) {
|
||||||
return operator++();
|
return operator++();
|
||||||
@ -66,7 +93,7 @@ public:
|
|||||||
int32_t operator--(int32_t i) {
|
int32_t operator--(int32_t i) {
|
||||||
return operator--();
|
return operator--();
|
||||||
}
|
}
|
||||||
gameInfo * GetCurrentSelected() const {
|
gameInfo * GetCurrentSelected() {
|
||||||
return operator[](selectedGame);
|
return operator[](selectedGame);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,6 +107,13 @@ public:
|
|||||||
sigslot::signal1<GameList *> titleListChanged;
|
sigslot::signal1<GameList *> titleListChanged;
|
||||||
sigslot::signal1<gameInfo *> titleUpdated;
|
sigslot::signal1<gameInfo *> titleUpdated;
|
||||||
sigslot::signal1<gameInfo *> titleAdded;
|
sigslot::signal1<gameInfo *> titleAdded;
|
||||||
|
|
||||||
|
void lock() {
|
||||||
|
_lock.lock();
|
||||||
|
}
|
||||||
|
void unlock(){
|
||||||
|
_lock.unlock();
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
int32_t readGameList();
|
int32_t readGameList();
|
||||||
@ -97,6 +131,8 @@ protected:
|
|||||||
int32_t selectedGame;
|
int32_t selectedGame;
|
||||||
std::vector<gameInfo *> filteredList;
|
std::vector<gameInfo *> filteredList;
|
||||||
std::vector<gameInfo *> fullGameList;
|
std::vector<gameInfo *> fullGameList;
|
||||||
|
|
||||||
|
CMutex _lock;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,6 +74,7 @@ uint64_t GuiIconGrid::getSelectedGame(void) {
|
|||||||
|
|
||||||
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
||||||
containerMutex.lock();
|
containerMutex.lock();
|
||||||
|
gameList->lock();
|
||||||
for(int32_t i = 0; i < gameList->size(); i++) {
|
for(int32_t i = 0; i < gameList->size(); i++) {
|
||||||
gameInfo * info = gameList->at(i);
|
gameInfo * info = gameList->at(i);
|
||||||
GameInfoContainer * container = NULL;
|
GameInfoContainer * container = NULL;
|
||||||
@ -89,6 +90,7 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
|||||||
OnGameTitleAdded(info);
|
OnGameTitleAdded(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
gameList->unlock();
|
||||||
containerMutex.unlock();
|
containerMutex.unlock();
|
||||||
bUpdatePositions = true;
|
bUpdatePositions = true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user