OpenVicProject / OpenVic

Main Repo for the OpenVic Project
https://openvic.com
GNU General Public License v3.0
360 stars 27 forks source link

Population Menu - Distribution Lists Optimisation #260

Open Hop311 opened 4 weeks ago

Hop311 commented 4 weeks ago

Problem

Currently the lists next to each of the 6 large pie charts in the Population Menu generate a row for each item, regardless of how many are visible at once, which can cause lag spikes when the lists have many items.

Solution

In PopulationMenu.gdscript, only generate at most as many rows as are visible at once, using GUIListBox's set_fixed(item_count, item_height) and get_fixed_visible_items() functions to find the number of rows to generate, and connecting its scroll_index_changed signal to a function that updates the rows' contents based on the current scroll level.

This will also require changes in MenuSingleton.hpp and PopulationMenu.cpp, replacing get_population_menu_distribution_info with a function that returns just the visible row data for a single distribution (similar to get_population_menu_pop_rows) and adding a function to get the total number of rows for a single distribution (similar to get_population_menu_pop_row_count).

It may be useful to create an enum with values for the 6 distributions to use for arguments that choose which distribution's rows or total row count you want to get. You can make enums accesible to GDScript by registering the type with VARIANT_ENUM_CAST at the bottom of MenuSingleton.hpp and registering the individual values with BIND_ENUM_CONSTANT in MenuSingleton.cpp's _bind_methods function.

SearchPanel.gdscript (and it's corresponding C++ code in MenuSingleton.hpp and MenuSingleton.cpp) provides a similar example for limiting the number of search result rows generated.