Skip to content
Permalink
Browse files

UI: Quit sorting when done.

This will prevent keeping the gameInfo objects alive unnecessarily.
  • Loading branch information...
unknownbrackets authored and hrydgard committed Jun 5, 2018
1 parent 4fb6068 commit f0be2d5f88470b3806c2f5d9707a3038bb6599c7
Showing with 15 additions and 3 deletions.
  1. +14 −3 UI/SavedataScreen.cpp
  2. +1 −0 UI/SavedataScreen.h
@@ -23,6 +23,7 @@
#include "gfx_es2/draw_buffer.h"
#include "i18n/i18n.h"
#include "math/curves.h"
#include "thread/prioritizedworkqueue.h"
#include "util/text/utf8.h"
#include "ui/ui_context.h"
#include "ui/view.h"
@@ -125,25 +126,30 @@ class SavedataPopupScreen : public PopupScreen {
class SortedLinearLayout : public UI::LinearLayout {
public:
typedef std::function<bool(const View *, const View *)> CompareFunc;
typedef std::function<bool()> DoneFunc;

SortedLinearLayout(UI::Orientation orientation, UI::LayoutParams *layoutParams = nullptr)
: UI::LinearLayout(orientation, layoutParams) {
}

void SetCompare(CompareFunc lessFunc) {
void SetCompare(CompareFunc lessFunc, DoneFunc) {
lessFunc_ = lessFunc;
}

void Update() override;

private:
CompareFunc lessFunc_;
DoneFunc doneFunc_;
};

void SortedLinearLayout::Update() {
if (lessFunc_) {
std::stable_sort(views_.begin(), views_.end(), lessFunc_);
}
if (doneFunc_ && doneFunc_()) {
lessFunc_ = CompareFunc();
}
UI::LinearLayout::Update();
}

@@ -314,9 +320,9 @@ void SavedataBrowser::SetSortOption(SavedataSortOption opt) {
if (gameList_) {
SortedLinearLayout *gl = static_cast<SortedLinearLayout *>(gameList_);
if (sortOption_ == SavedataSortOption::FILENAME) {
gl->SetCompare(&ByFilename);
gl->SetCompare(&ByFilename, &SortDone);
} else if (sortOption_ == SavedataSortOption::SIZE) {
gl->SetCompare(&BySize);
gl->SetCompare(&BySize, &SortDone);
}
}
}
@@ -339,6 +345,11 @@ bool SavedataBrowser::BySize(const UI::View *v1, const UI::View *v2) {
return g1info->gameSize > g2info->gameSize;
}

bool SavedataBrowser::SortDone() {
PrioritizedWorkQueue *wq = g_gameInfoCache->WorkQueue();
return wq->Done();
}

void SavedataBrowser::Refresh() {
using namespace UI;

@@ -42,6 +42,7 @@ class SavedataBrowser : public UI::LinearLayout {
private:
static bool ByFilename(const UI::View *, const UI::View *);
static bool BySize(const UI::View *, const UI::View *);
static bool SortDone();

void Refresh();
UI::EventReturn SavedataButtonClick(UI::EventParams &e);

0 comments on commit f0be2d5

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.