Skip to content

Refactor selection screen data storage to remove fixed arrays - #7739

Merged
Goober5000 merged 2 commits into
scp-fs2open:masterfrom
Goober5000:refactor/loadout_ui
Aug 31, 2026
Merged

Refactor selection screen data storage to remove fixed arrays#7739
Goober5000 merged 2 commits into
scp-fs2open:masterfrom
Goober5000:refactor/loadout_ui

Conversation

@Goober5000

@Goober5000 Goober5000 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Convert the mission ship/weapon select screens' per-class UI state from dense MAX_SHIP_CLASSES / MAX_WEAPON_TYPES arrays to sparse containers keyed by loadout-pool membership, matching the Ss_pool / Wl_pool maps they shadow:

ss_icon_info Ss_icons_teams[][MAX_SHIP_CLASSES] -> SCP_map<int, ss_icon_info>[]
wl_icon_info Wl_icons_teams[][MAX_WEAPON_TYPES] -> SCP_map<int, wl_icon_info>[]
wl_ship_class_info Wl_ships[MAX_SHIP_CLASSES] -> SCP_map<int, wl_ship_class_info>
int Plist[] / Slist[] + manual size counters -> SCP_vector

The ship-select active list is replaced outright by a vector of ship classes rebuilt on each interface sync, plus the existing scroll offset. active_list_remove() was dead code and is deleted.

Behavior fixes required by the conversion:

  • wl_set_disabled_weapons now computes usability flags for the pool
    weapons plus every weapon currently in a slot's banks, instead of all
    weapon classes. (Bank weapons are not guaranteed pool members.)

  • The two mouse-region handlers that read Plist[Plist_start+index] for
    raw indices 0..3 now bounds-check against the list size (as does
    ss_get_ship_class_from_list).

  • wl_unload_icons and the ss unloaders early-return on a null team
    pointer instead of asserting and dereferencing.

The ship side loads icons for every pool class including exhausted 0-count entries while the weapon side loads only positive counts, preserving the existing asymmetry.

Also:

Fix bitmap and model handle leakage in the ship/weapon select screens, and make release symmetric with load:

  • Initialize each team only once in ship_select_common_init
  • Unload every team's map in ss_unload_team_icons, not just the active one.
  • Add a per-team unload helper and use it in the load-all functions

Also drop the stray per-icon Cur_Anim unload, and call wl_free_ship_class_data before loading in wl_init_ship_class_data.

In draft as it depends on #7737.

@Goober5000 Goober5000 added this to the Release 26.2 milestone Aug 24, 2026
@Goober5000 Goober5000 added ui A feature or issue specific to the menus portion of the user interface refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability labels Aug 24, 2026
@Goober5000
Goober5000 force-pushed the refactor/loadout_ui branch 2 times, most recently from abe98a4 to cef3db3 Compare August 25, 2026 00:55
@Goober5000 Goober5000 added the Requested by Active Mod A feature request that has been requested by a mod that is actively in development. label Aug 25, 2026
@Goober5000
Goober5000 marked this pull request as ready for review August 28, 2026 21:00
@Goober5000
Goober5000 force-pushed the refactor/loadout_ui branch from cef3db3 to 6afc8b8 Compare August 28, 2026 21:17

@JohnAFernandez JohnAFernandez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing really sticks out to me. My attempt at this was much more invasive, but this PR is pretty much as simple as it could be.

@Goober5000

Copy link
Copy Markdown
Contributor Author

It definitely helped to do the data structure redesign first. Thanks!

Goober5000 and others added 2 commits August 30, 2026 19:08
Convert the mission ship/weapon select screens' per-class UI state from dense MAX_SHIP_CLASSES / MAX_WEAPON_TYPES arrays to sparse containers keyed by loadout-pool membership, matching the Ss_pool / Wl_pool maps they shadow:

  ss_icon_info Ss_icons_teams[][MAX_SHIP_CLASSES] -> SCP_map<int, ss_icon_info>[]
  wl_icon_info Wl_icons_teams[][MAX_WEAPON_TYPES] -> SCP_map<int, wl_icon_info>[]
  wl_ship_class_info Wl_ships[MAX_SHIP_CLASSES]   -> SCP_map<int, wl_ship_class_info>
  int Plist[] / Slist[] + manual size counters    -> SCP_vector<int>

The ship-select active list is replaced outright by a vector of ship classes rebuilt on each interface sync, plus the existing scroll offset.  active_list_remove() was dead code and is deleted.

Behavior fixes required by the conversion:

 * wl_set_disabled_weapons now computes usability flags for the pool
   weapons plus every weapon currently in a slot's banks, instead of all
   weapon classes.  (Bank weapons are not guaranteed pool members.)

 * The two mouse-region handlers that read Plist[Plist_start+index] for
   raw indices 0..3 now bounds-check against the list size (as does
   ss_get_ship_class_from_list).

 * wl_unload_icons and the ss unloaders early-return on a null team
   pointer instead of asserting and dereferencing.

The ship side loads icons for every pool class including exhausted 0-count entries while the weapon side loads only positive counts, preserving the existing asymmetry.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Fix bitmap and model handle leakage in the ship/weapon select screens, and make release symmetric with load:

 * Initialize each team only once in `ship_select_common_init`
 * Unload every team's map in `ss_unload_team_icons`, not just the active one.
 * Add a per-team unload helper and use it in the load-all functions

Also drop the stray per-icon Cur_Anim unload, and call `wl_free_ship_class_data` before loading in `wl_init_ship_class_data`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Goober5000
Goober5000 force-pushed the refactor/loadout_ui branch from 6afc8b8 to 3f5cf1c Compare August 30, 2026 23:13
@Goober5000
Goober5000 merged commit 3db9049 into scp-fs2open:master Aug 31, 2026
18 checks passed
@Goober5000
Goober5000 deleted the refactor/loadout_ui branch August 31, 2026 00:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor A cleanup/restructure of a feature for speed, simplicity, and/or maintainability Requested by Active Mod A feature request that has been requested by a mod that is actively in development. ui A feature or issue specific to the menus portion of the user interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants