Skip to content

Commit

Permalink
Merge pull request #79 from robsdedude/dynamicListItemLoading
Browse files Browse the repository at this point in the history
Dynamic list item loading
  • Loading branch information
robsdedude authored Apr 20, 2020
2 parents 0a126ca + 65510a9 commit e345826
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 14 deletions.
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ string(REGEX REPLACE "0+0\\." "0." VITA_VERSION_HUMAN ${VITA_VERSION})

set(VERSION_YAML_URL "https://vhbb.download/version.php")
set(UPDATE_URL "https://github.com/devnoname120/vhbb/releases/download/${VITA_VERSION_HUMAN}/VitaHBBrowser.vpk")
# Old test URL's
# Old test URLs
#set(VERSION_YAML_URL "https://github.com/robsdedude/vhbb/raw/updateTestBranch/release/version.yml")
#set(UPDATE_URL "https://github.com/robsdedude/vhbb/raw/updateTestBranch/release/VitaHBBrowser.vpk")

Expand Down Expand Up @@ -217,7 +217,7 @@ if (EXISTS "${psvitaipFilePath}")
file(STRINGS "${psvitaipFilePath}" PSVITAIP)

add_custom_target(send
COMMAND curl -T ${SHORT_NAME}.self ftp://${PSVITAIP}:1337/ux0:/app/${VITA_TITLEID}/eboot.bin
COMMAND curl --ftp-method nocwd -T ${SHORT_NAME}.self ftp://${PSVITAIP}:1337/ux0:/app/${VITA_TITLEID}/eboot.bin
DEPENDS ${SHORT_NAME}.self
)

Expand All @@ -227,7 +227,7 @@ if (EXISTS "${psvitaipFilePath}")
)

add_custom_target(vpksend
COMMAND curl -T ${SHORT_NAME}.vpk ftp://${PSVITAIP}:1337/ux0:/
COMMAND curl --ftp-method nocwd -T ${SHORT_NAME}.vpk ftp://${PSVITAIP}:1337/ux0:/
DEPENDS ${SHORT_NAME}.vpk
)
else ()
Expand Down
105 changes: 100 additions & 5 deletions src/Views/ListView/listView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,99 @@ ListView::ListView(std::vector<Homebrew> homebrews)
{
log_printf(DBG_DEBUG, "posY: %d", posY);
log_printf(DBG_DEBUG, "homebrews size: %d", homebrews.size());
for (Homebrew hb : homebrews)
this->homebrews = homebrews;
listItems = std::vector<std::unique_ptr<ListItem>>(homebrews.size());
LoadListItems();
}

long ListView::_LoadPreviousListItems(long firstDisplayed, long firstToLoad, long maxLoad)
{
long loaded = 0;
for (long i = firstDisplayed; i >= firstToLoad; i--)
{
if (!listItems[i])
{
listItems[i] = std::make_unique<ListItem>(homebrews[i]);
if (++loaded > maxLoad)
{
break;
}
}
}
return loaded;
}

long ListView::_LoadShownListItems(long firstDisplayed, long lastDisplayed, long maxLoad)
{
long loaded = 0;
for (long i = firstDisplayed; i <= lastDisplayed; i++)
{
listItems.emplace_back(hb);
if (!listItems[i])
{
listItems[i] = std::make_unique<ListItem>(homebrews[i]);
if (++loaded > maxLoad)
{
break;
}
}
}
return loaded;
}

long ListView::_LoadNextListItems(long lastDisplayed, long lastToLoad, long maxLoad)
{
long loaded = 0;
for (long i = lastDisplayed; i <= lastToLoad; i++)
{
if (!listItems[i])
{
listItems[i] = std::make_unique<ListItem>(homebrews[i]);
if (++loaded > maxLoad)
{
break;
}
}
}
return loaded;
}

void ListView::LoadListItems()
{
auto first = (long)firstDisplayedItem();
auto last = (long)lastDisplayedItem();
long firstToLoad = std::max<long>(first - PRE_RENDER_EXTRA_LIST_ITEM, 0);
long lastToLoad = std::min<long>(last + PRE_RENDER_EXTRA_LIST_ITEM, listItems.size());
long loaded = 0;
for (long i = 0; i < firstToLoad; i++)
{
listItems[i] = nullptr;
}
for (long i = lastToLoad; i < (long)listItems.size(); i++)
{
listItems[i] = nullptr;
}

loaded += _LoadShownListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE);
if (loaded >= MAX_LOAD_LIST_ITEMS_PER_CYCLE)
return;

if (scrollSpeed >= 0)
{
// preferably pre-load further down the list
loaded += _LoadNextListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE);
if (loaded >= MAX_LOAD_LIST_ITEMS_PER_CYCLE)
return;
loaded += _LoadPreviousListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE);
if (loaded >= MAX_LOAD_LIST_ITEMS_PER_CYCLE)
return;
} else {
// preferably pre-load further up the list
loaded += _LoadPreviousListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE);
if (loaded >= MAX_LOAD_LIST_ITEMS_PER_CYCLE)
return;
loaded += _LoadNextListItems(first, last, MAX_LOAD_LIST_ITEMS_PER_CYCLE);
if (loaded >= MAX_LOAD_LIST_ITEMS_PER_CYCLE)
return;
}
}

Expand Down Expand Up @@ -127,7 +217,7 @@ int ListView::HandleInput(int focus, const Input& input)
log_printf(DBG_DEBUG, "Clicked, adding view...");
try
{
Activity::get_instance()->AddView(std::make_shared<HomebrewView>(listItems.at(selectedItem).homebrew));
Activity::get_instance()->AddView(std::make_shared<HomebrewView>(homebrews.at(selectedItem)));
}
catch (const std::exception& ex)
{
Expand Down Expand Up @@ -205,7 +295,7 @@ int ListView::HandleInput(int focus, const Input& input)
log_printf(DBG_DEBUG, "Pressed, adding view...");
try
{
Activity::get_instance()->AddView(std::make_shared<HomebrewView>(listItems.at(selectedItem).homebrew));
Activity::get_instance()->AddView(std::make_shared<HomebrewView>(homebrews.at(selectedItem)));
}
catch (const std::exception& ex)
{
Expand All @@ -227,6 +317,8 @@ int ListView::HandleInput(int focus, const Input& input)
}
}

LoadListItems();

return 0;
}

Expand All @@ -246,7 +338,10 @@ int ListView::Display()
}
for (int i = firstDisplayedItem(); i <= lastDisplayedItem(); i++)
{
listItems[i].Display(itemPosY(i), i == selectedItem, itemHighlightAlpha);
if(listItems[i])
{
listItems[i]->Display(itemPosY(i), i == selectedItem, itemHighlightAlpha);
}
}
if (itemHighlightDirection)
{
Expand Down
9 changes: 8 additions & 1 deletion src/Views/ListView/listView.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#define LIST_MAX_Y 543 // This ordinate is included too
#define LIST_RANGE_Y (LIST_MAX_Y - LIST_MIN_Y)
#define LIST_HEIGHT (LIST_RANGE_Y + 1)
#define PRE_RENDER_EXTRA_LIST_ITEM 30
#define MAX_LOAD_LIST_ITEMS_PER_CYCLE 1

// Max speed px/ms above which selected item is no more selected
#define LIST_SELECTION_MAX_SPEED 0.000070
Expand All @@ -27,7 +29,9 @@ class ListView: public View {
virtual bool IsReadyToShow() { return true; };

protected:
std::vector<ListItem> listItems;
std::vector<Homebrew> homebrews;
std::vector<std::unique_ptr<ListItem>> listItems;
void LoadListItems();

private:
Font font_43;
Expand All @@ -49,4 +53,7 @@ class ListView: public View {
unsigned int lastFullyDisplayedItem();
int coordinateToItem(double coordY);
int updateScrollSpeed(double &scrollSpeed, unsigned long timeDif);
long _LoadPreviousListItems(long firstDisplayed, long firstToLoad, long maxLoad);
long _LoadShownListItems(long firstDisplayed, long lastDisplayed, long maxLoad);
long _LoadNextListItems(long lastDisplayed, long lastToLoad, long loadMax);
};
9 changes: 4 additions & 5 deletions src/Views/ListView/searchView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ int SearchView::Display()
auto db = Database::get_instance();
std::vector<Homebrew> hbs;
hbs = db->Search(SearchQuery(_ime_search_view_result->userText));
listItems.clear();
for (Homebrew hb : hbs)
{
listItems.emplace_back(hb);
}
homebrews = hbs;

std::fill(listItems.begin(), listItems.end(), nullptr);
LoadListItems();
lastQuery = _ime_search_view_result->userText;
}
else
Expand Down

0 comments on commit e345826

Please sign in to comment.