Vectorize MsgItems - #7687
Conversation
|
There is an existing behavior where if you input a "comms menu move up" command in the same frame as opening the comms menu, you end up with a |
|
I vote fixing the bug would be good, though you may also want to look at #7688. Possibly they could all be combined into one PR here? |
|
I'd recommend, instead, fixing the bug in #7688 and keeping this PR focused on the vectorization. Then this PR can be rebased on 7688, after merge, and inherit or accommodate the fix. |
|
Ah yeah good point! Though I think merging this one first might work better, and then I can fully test all the cleanup and fixes in 7688 once this is merged :) |
|
@Goober5000 is this one good to merge now or is more review needed? Note, once this is merged I'll address various other fixes in 7688 |
No, there are several things that need to be addressed, but I haven't had time to respond. Will try to follow up ASAP. |
|
Thanks, sounds good! |
Goober5000
left a comment
There was a problem hiding this comment.
It will be necessary to handle config mode, because MsgItems is only valid during a mission. So, in hudsquadmsg.cpp:
- Remove the
active = -1assignment, and enclosing if(), inHudGaugeSquadMessage::render - Then, 22 lines later, add this before the if() and change the if() to use
item_visible:
bool item_visible = config
? !(Hide_main_rearm_items_in_comms_gauge && (i == TYPE_REPAIR_REARM_ITEM || i == TYPE_REPAIR_REARM_ABORT_ITEM))
: (MsgItems[First_menu_item + i].active >= 0);
Goober5000
left a comment
There was a problem hiding this comment.
Additional comments. With these changes, every ternary MsgItems ? sz2i(MsgItems.size()) : -1 can become just sz2i(MsgItems.size()).
Goober5000
left a comment
There was a problem hiding this comment.
This looks good now! One optional thing before merging.
| extern mmode_item MsgItems[MAX_MENU_ITEMS]; | ||
| extern int Num_menu_items; // number of items for a message menu | ||
| extern SCP_vector<mmode_item> MsgItems; | ||
| extern bool Rebuild_MsgItems; |
There was a problem hiding this comment.
This no longer needs to be in the header file. The declaration in the .cpp file can be made static.
Convert MsgItems from an array to a vector, and remove the associated limit value and counter.
MsgItems is dynamically rewritten at runtime, and previously used a counter value of -1 to indicate that the array was in a state suitable for rewriting in some circumstances. To replicate this behavior, MsgItems is now actually an
std::optional<SCP_vector<mmode_item>>, and its nullopt state corresponds to -1.