Skip to content

Commit

Permalink
Fix location performance under some circumstances
Browse files Browse the repository at this point in the history
Improved performance when state can't be cached and multiple things
change on a single frame.

Only enabled when AllowDeferredLogicUpdate is set, which will probably
become the default in a future version.
  • Loading branch information
black-sliver committed Feb 16, 2025
1 parent da48035 commit a8d2b81
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
40 changes: 34 additions & 6 deletions src/ui/trackerview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,9 @@ void TrackerView::render(Renderer renderer, int offX, int offY)
relayout();
setSize(oldSize);
}
if (_mapsDirty) {
updateLocationsNow();
}
// store global coordinates for overlay calculations
_absX = offX+_pos.left;
_absY = offY+_pos.top;
Expand Down Expand Up @@ -377,6 +380,7 @@ void TrackerView::updateLayout(const std::string& layout)
_mapTooltipOwner = nullptr;
_items.clear();
_maps.clear();
_mapsDirty = false;
_tabs.clear();
_layoutRefs.clear();
clearChildren();
Expand All @@ -390,25 +394,49 @@ void TrackerView::updateLayout(const std::string& layout)

void TrackerView::updateLocations()
{
updateLocation("", true);
if (_tracker->allowDeferredLogicUpdate()) {
_mapsDirty = true; // will be updated on next frame render
} else {
updateLocationsNow();
}
updateMapTooltip(); // TODO: move this into updateLocation and detect if the location is hovered
}

void TrackerView::updateLocation(const std::string& location, bool all)
void TrackerView::updateLocationsNow()
{
for (auto& mappair: _maps) {
for (auto& w: mappair.second) {
std::string lastLocation;
size_t n = 0; // nth map location of the same location on the same map
for (const auto& pair : _tracker->getMapLocations(mappair.first)) {
if (!all && pair.first != location)
continue;
if (all && lastLocation != pair.first) {
if (lastLocation != pair.first) {
lastLocation = pair.first;
n = 0;
}
int state = CalculateLocationState(_tracker, pair.first, pair.second);
if (_maps.size()<1) {
if (_maps.empty()) {
// ui file loaded while updating states
return;
}
w->setLocationState(pair.first, state, n);
n++;
}
}
}
_mapsDirty = false;
}

void TrackerView::updateLocation(const std::string& location)
{
for (auto& mappair: _maps) {
for (auto& w: mappair.second) {
std::string lastLocation;
size_t n = 0; // nth map location of the same location on the same map
for (const auto& pair : _tracker->getMapLocations(mappair.first)) {
if (pair.first != location)
continue;
int state = CalculateLocationState(_tracker, pair.first, pair.second);
if (_maps.empty()) {
printf("TrackerView: UI changed during updateLocations()\n");
fprintf(stderr, "cybuuuuuu!!\n");
return;
Expand Down
4 changes: 3 additions & 1 deletion src/ui/trackerview.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TrackerView : public SimpleContainer {
int _absY=0;
std::map<std::string, std::list<Item*>> _items;
std::map<std::string, std::list<MapWidget*>> _maps;
bool _mapsDirty = false;
std::list<Tabs*> _tabs;
std::list<std::string> _activeTabs;
std::list< std::pair<std::string,std::string> > _missedHints;
Expand All @@ -75,7 +76,8 @@ class TrackerView : public SimpleContainer {
void updateDisplay(const std::string& check);
void updateState(const std::string& check);
void updateLocations();
void updateLocation(const std::string& location, bool all=false);
void updateLocationsNow();
void updateLocation(const std::string& location);
void updateMapTooltip();
void updateItem(Item* w, const BaseItem& item);

Expand Down

0 comments on commit a8d2b81

Please # to comment.