mirror of
https://github.com/wiiu-env/launchiine.git
synced 2024-11-22 01:39:18 +01:00
Add mutex to position vector
This commit is contained in:
parent
fff867846d
commit
3e37d5aa46
@ -161,12 +161,14 @@ GuiIconGrid::~GuiIconGrid() {
|
|||||||
|
|
||||||
int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) {
|
int32_t GuiIconGrid::offsetForTitleId(uint64_t titleId) {
|
||||||
int32_t offset = -1;
|
int32_t offset = -1;
|
||||||
|
positionMutex.lock();
|
||||||
for(uint32_t i = 0; i < position.size(); i++) {
|
for(uint32_t i = 0; i < position.size(); i++) {
|
||||||
if(position.at(i) == titleId) {
|
if(position.at(i) == titleId) {
|
||||||
offset = i;
|
offset = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
positionMutex.unlock();
|
||||||
return offset;
|
return offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,6 +205,7 @@ uint64_t GuiIconGrid::getSelectedGame(void) {
|
|||||||
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
||||||
gameList->lock();
|
gameList->lock();
|
||||||
containerMutex.lock();
|
containerMutex.lock();
|
||||||
|
positionMutex.lock();
|
||||||
// At first delete the ones that were deleted;
|
// At first delete the ones that were deleted;
|
||||||
auto it = gameInfoContainers.begin();
|
auto it = gameInfoContainers.begin();
|
||||||
while (it != gameInfoContainers.end()) {
|
while (it != gameInfoContainers.end()) {
|
||||||
@ -239,8 +242,8 @@ void GuiIconGrid::OnGameTitleListUpdated(GameList * gameList) {
|
|||||||
OnGameTitleAdded(info);
|
OnGameTitleAdded(info);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
positionMutex.unlock();
|
||||||
containerMutex.unlock();
|
containerMutex.unlock();
|
||||||
|
|
||||||
gameList->unlock();
|
gameList->unlock();
|
||||||
setSelectedGame(0);
|
setSelectedGame(0);
|
||||||
gameSelectionChanged(this, selectedGame);
|
gameSelectionChanged(this, selectedGame);
|
||||||
@ -472,7 +475,9 @@ void GuiIconGrid::OnGameTitleAdded(gameInfo * info) {
|
|||||||
containerMutex.unlock();
|
containerMutex.unlock();
|
||||||
this->append(button);
|
this->append(button);
|
||||||
|
|
||||||
position.push_back(info->titleId);
|
positionMutex.lock();
|
||||||
|
position.push_back(info->titleId);
|
||||||
|
positionMutex.unlock();
|
||||||
|
|
||||||
bUpdatePositions = true;
|
bUpdatePositions = true;
|
||||||
}
|
}
|
||||||
@ -501,7 +506,7 @@ void GuiIconGrid::process() {
|
|||||||
if(currentlyHeld != NULL) {
|
if(currentlyHeld != NULL) {
|
||||||
if(!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) {
|
if(!currentlyHeld->isStateSet(GuiElement::STATE_HELD)) {
|
||||||
DEBUG_FUNCTION_LINE("Not held anymore\n");
|
DEBUG_FUNCTION_LINE("Not held anymore\n");
|
||||||
|
positionMutex.lock();
|
||||||
if(dragTarget) {
|
if(dragTarget) {
|
||||||
DEBUG_FUNCTION_LINE("Let's swap\n");
|
DEBUG_FUNCTION_LINE("Let's swap\n");
|
||||||
|
|
||||||
@ -517,7 +522,6 @@ void GuiIconGrid::process() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint32_t i = 0; i< positionButtons.size(); i++) {
|
for(uint32_t i = 0; i< positionButtons.size(); i++) {
|
||||||
if(positionButtons[i] == dragTarget) {
|
if(positionButtons[i] == dragTarget) {
|
||||||
if(i < position.size() && i != currentlyHeldPosition) {
|
if(i < position.size() && i != currentlyHeldPosition) {
|
||||||
@ -530,16 +534,17 @@ void GuiIconGrid::process() {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
|
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
|
||||||
position[currentlyHeldPosition] = targetTitleId;
|
position[currentlyHeldPosition] = targetTitleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
dragTarget = NULL;
|
dragTarget = NULL;
|
||||||
} else {
|
} else {
|
||||||
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
|
if(currentlyHeldPosition >= 0 && currentlyHeldPosition <= (int32_t) position.size()) {
|
||||||
position[currentlyHeldPosition] = currentlyHeldTitleId;
|
position[currentlyHeldPosition] = currentlyHeldTitleId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
positionMutex.unlock();
|
||||||
currentlyHeld = NULL;
|
currentlyHeld = NULL;
|
||||||
currentlyHeldTitleId = 0;
|
currentlyHeldTitleId = 0;
|
||||||
|
|
||||||
@ -581,6 +586,7 @@ void GuiIconGrid::update(GuiController * c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GuiIconGrid::updateButtonPositions() {
|
void GuiIconGrid::updateButtonPositions() {
|
||||||
|
positionMutex.lock();
|
||||||
arrowRightButton.setState(GuiElement::STATE_DISABLED);
|
arrowRightButton.setState(GuiElement::STATE_DISABLED);
|
||||||
arrowRightButton.setVisible(false);
|
arrowRightButton.setVisible(false);
|
||||||
arrowLeftButton.setState(GuiElement::STATE_DISABLED);
|
arrowLeftButton.setState(GuiElement::STATE_DISABLED);
|
||||||
@ -631,7 +637,7 @@ void GuiIconGrid::updateButtonPositions() {
|
|||||||
|
|
||||||
uint32_t elementSize = position.size();
|
uint32_t elementSize = position.size();
|
||||||
uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) +1;
|
uint32_t pages = (elementSize / (MAX_COLS * MAX_ROWS)) +1;
|
||||||
if(elementSize % (MAX_COLS * MAX_ROWS) == 0){
|
if(elementSize % (MAX_COLS * MAX_ROWS) == 0) {
|
||||||
pages--;
|
pages--;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,11 +730,12 @@ void GuiIconGrid::updateButtonPositions() {
|
|||||||
if(currentlyHeld != NULL) {
|
if(currentlyHeld != NULL) {
|
||||||
append(currentlyHeld);
|
append(currentlyHeld);
|
||||||
}
|
}
|
||||||
if(positionButtons.size() > position.size()) {
|
if(positionButtons.size() > position.size() && targetLeftPosition == currentLeftPosition) {
|
||||||
for(uint32_t i = 0; i < positionButtons.size() - position.size(); i++) {
|
for(uint32_t i = 0; i < positionButtons.size() - position.size(); i++) {
|
||||||
position.push_back(0);
|
position.push_back(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
positionMutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GuiIconGrid::draw(CVideo *pVideo) {
|
void GuiIconGrid::draw(CVideo *pVideo) {
|
||||||
@ -738,6 +745,8 @@ void GuiIconGrid::draw(CVideo *pVideo) {
|
|||||||
pVideo->setStencilRender(false);
|
pVideo->setStencilRender(false);
|
||||||
|
|
||||||
containerMutex.lock();
|
containerMutex.lock();
|
||||||
|
positionMutex.lock();
|
||||||
GuiFrame::draw(pVideo);
|
GuiFrame::draw(pVideo);
|
||||||
|
positionMutex.unlock();
|
||||||
containerMutex.unlock();
|
containerMutex.unlock();
|
||||||
}
|
}
|
||||||
|
@ -145,6 +145,7 @@ private:
|
|||||||
GuiButton * button;
|
GuiButton * button;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
std::recursive_mutex positionMutex;
|
||||||
std::recursive_mutex containerMutex;
|
std::recursive_mutex containerMutex;
|
||||||
std::map<uint64_t, GameInfoContainer *> gameInfoContainers;
|
std::map<uint64_t, GameInfoContainer *> gameInfoContainers;
|
||||||
std::vector<uint64_t> position;
|
std::vector<uint64_t> position;
|
||||||
|
Loading…
Reference in New Issue
Block a user