Skip to content

Commit d7957f8

Browse files
committed
perf(gui): Eliminate expensive and unnecessary processing when populating the replay and map lists after they are full
1 parent 834f369 commit d7957f8

File tree

5 files changed

+35
-16
lines changed

5 files changed

+35
-16
lines changed

GeneralsMD/Code/GameEngine/Include/GameClient/GadgetListBox.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ extern void GadgetListboxCreateScrollbar( GameWindow *listbox );
6969
extern void GadgetListBoxAddMultiSelect( GameWindow *listbox );
7070
extern void GadgetListBoxRemoveMultiSelect( GameWindow *listbox );
7171
extern void GadgetListBoxSetListLength( GameWindow *listbox, Int newLength );
72-
extern Int GadgetListBoxGetListLength( GameWindow *listbox );
72+
extern Int GadgetListBoxGetListLength( GameWindow *listbox ); ///< Returns the maximum possible number of list entries. Length is synonymous to rows
73+
extern Int GadgetListBoxGetMaxSelectedLength( GameWindow *listbox ); ///< Returns the maximum possible number of list entries that can be selected
7374
extern Int GadgetListBoxGetNumEntries( GameWindow *listbox );
7475
extern Int GadgetListBoxGetNumColumns( GameWindow *listbox );
7576
extern Int GadgetListBoxGetColumnWidth( GameWindow *listbox, Int column );

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/ReplayMenu.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ void PopulateReplayFileListbox(GameWindow *listbox)
240240
return;
241241

242242
GadgetListBoxReset(listbox);
243+
const Int listboxLength = GadgetListBoxGetListLength(listbox);
243244

244245
// TheSuperHackers @tweak xezon 08/06/2025 Now shows missing maps in red color.
245246
enum {
@@ -273,7 +274,6 @@ void PopulateReplayFileListbox(GameWindow *listbox)
273274

274275
TheMapCache->updateCache();
275276

276-
277277
for (it = replayFilenames.begin(); it != replayFilenames.end(); ++it)
278278
{
279279
// just want the filename
@@ -355,10 +355,15 @@ void PopulateReplayFileListbox(GameWindow *listbox)
355355
mapColor = colors[COLOR_MISSING_MAP_CRC_MISMATCH];
356356
}
357357

358-
Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0);
358+
const Int insertionIndex = GadgetListBoxAddEntryText(listbox, replayNameToShow, color, -1, 0);
359+
DEBUG_ASSERTCRASH(insertionIndex >= 0, ("Expects valid index"));
359360
GadgetListBoxAddEntryText(listbox, displayTimeBuffer, color, insertionIndex, 1);
360361
GadgetListBoxAddEntryText(listbox, header.versionString, color, insertionIndex, 2);
361362
GadgetListBoxAddEntryText(listbox, mapStr, mapColor, insertionIndex, 3);
363+
364+
// TheSuperHackers @performance Now stops processing when the list is full.
365+
if (insertionIndex == listboxLength - 1)
366+
break;
362367
}
363368
}
364369
GadgetListBoxSetSelected(listbox, 0);

GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetListBox.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2576,21 +2576,24 @@ void GadgetListBoxSetListLength( GameWindow *listbox, Int newLength )
25762576

25772577
}
25782578

2579-
// GadgetListBoxGetListLength =================================================
2580-
/** Get the list length data contained in the listboxData
2581-
* parameter. */
25822579
//=============================================================================
25832580
Int GadgetListBoxGetListLength( GameWindow *listbox )
25842581
{
25852582
ListboxData *listboxData = (ListboxData *)listbox->winGetUserData();
2586-
if (listboxData->multiSelect)
2587-
{
2583+
if (listboxData)
25882584
return listboxData->listLength;
2589-
}
2590-
else
2591-
{
2592-
return 1;
2593-
}
2585+
2586+
return 0;
2587+
}
2588+
2589+
//=============================================================================
2590+
Int GadgetListBoxGetMaxSelectedLength( GameWindow *listbox )
2591+
{
2592+
ListboxData *listboxData = (ListboxData *)listbox->winGetUserData();
2593+
if (listboxData)
2594+
return listboxData->multiSelect ? listboxData->listLength : 1;
2595+
2596+
return 0;
25942597
}
25952598

25962599
// GadgetListBoxGetNumEntries =================================================

GeneralsMD/Code/GameEngine/Source/GameClient/MapUtil.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
790790
// reset the listbox content
791791
//GadgetListBoxReset( listbox );
792792

793-
Int numColumns = GadgetListBoxGetNumColumns( listbox );
793+
const Int listboxLength = GadgetListBoxGetListLength( listbox );
794+
const Int numColumns = GadgetListBoxGetNumColumns( listbox );
794795
const Image *easyImage = NULL;
795796
const Image *mediumImage = NULL;
796797
const Image *brutalImage = NULL;
@@ -923,7 +924,15 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
923924
index = GadgetListBoxAddEntryImage( listbox, NULL, index, 0, w, h, TRUE);
924925
}
925926
}
927+
926928
index = GadgetListBoxAddEntryText( listbox, mapDisplayName, color, index, numColumns-1 );
929+
DEBUG_ASSERTCRASH(index >= 0, ("Expects valid index"));
930+
931+
// TheSuperHackers @performance Now stops processing when the list is full.
932+
if (index == listboxLength - 1)
933+
{
934+
goto Done;
935+
}
927936

928937
if (it->first == mapToSelect)
929938
{
@@ -947,6 +956,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
947956
++curNumPlayersInMap;
948957
}
949958

959+
Done:
950960
delete battleHonors;
951961
battleHonors = NULL;
952962

@@ -960,7 +970,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
960970
if (selectionIndex >= bottomIndex)
961971
{
962972
Int newTop = max( 0, selectionIndex - max( 1, rowsOnScreen / 2 ) );
963-
//The trouble is that rowsonscreen/2 can be zero if bottom is 1 and top is zero
973+
//The trouble is that rowsOnScreen/2 can be zero if bottom is 1 and top is zero
964974
GadgetListBoxSetTopVisibleEntry( listbox, newTop );
965975
}
966976
}

GeneralsMD/Code/GameEngine/Source/GameNetwork/GameSpy/Chat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ Bool GameSpyInfo::sendChat( UnicodeString message, Bool isAction, GameWindow *pl
140140
}
141141

142142
// Get the selections (is this a private message?)
143-
Int maxSel = GadgetListBoxGetListLength(playerListbox);
143+
Int maxSel = GadgetListBoxGetMaxSelectedLength(playerListbox);
144144
Int *selections;
145145
GadgetListBoxGetSelected(playerListbox, (Int *)&selections);
146146

0 commit comments

Comments
 (0)