Skip to content

Commit 2eb73a8

Browse files
committed
perf(gui): Eliminate expensive and unnecessary processing when populating the replay and map lists after they are full (#1758)
1 parent 733e3db commit 2eb73a8

File tree

10 files changed

+68
-30
lines changed

10 files changed

+68
-30
lines changed

Generals/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 );

Generals/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);

Generals/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 =================================================

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
754754
// reset the listbox content
755755
//GadgetListBoxReset( listbox );
756756

757-
Int numColumns = GadgetListBoxGetNumColumns( listbox );
757+
const Int listboxLength = GadgetListBoxGetListLength( listbox );
758+
const Int numColumns = GadgetListBoxGetNumColumns( listbox );
758759
const Image *easyImage = NULL;
759760
const Image *mediumImage = NULL;
760761
const Image *brutalImage = NULL;
@@ -889,7 +890,9 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
889890
index = GadgetListBoxAddEntryImage( listbox, NULL, index, 0, w, h, TRUE);
890891
}
891892
}
893+
892894
index = GadgetListBoxAddEntryText( listbox, mapDisplayName, color, index, numColumns-1 );
895+
DEBUG_ASSERTCRASH(index >= 0, ("Expects valid index"));
893896

894897
if (it->first == mapToSelect)
895898
{
@@ -904,6 +907,12 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
904907
{
905908
GadgetListBoxSetItemData( listbox, (void *)imageItemData, index, 1 );
906909
}
910+
911+
// TheSuperHackers @performance Now stops processing when the list is full.
912+
if (index == listboxLength - 1)
913+
{
914+
goto Done;
915+
}
907916
}
908917
++tempit;
909918
}
@@ -913,6 +922,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
913922
++curNumPlayersInMap;
914923
}
915924

925+
Done:
916926
delete battleHonors;
917927
battleHonors = NULL;
918928

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

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

150150
// Get the selections (is this a private message?)
151-
Int maxSel = GadgetListBoxGetListLength(playerListbox);
151+
Int maxSel = GadgetListBoxGetMaxSelectedLength(playerListbox);
152152
Int *selections;
153153
GadgetListBoxGetSelected(playerListbox, (Int *)&selections);
154154

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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
754754
// reset the listbox content
755755
//GadgetListBoxReset( listbox );
756756

757-
Int numColumns = GadgetListBoxGetNumColumns( listbox );
757+
const Int listboxLength = GadgetListBoxGetListLength( listbox );
758+
const Int numColumns = GadgetListBoxGetNumColumns( listbox );
758759
const Image *easyImage = NULL;
759760
const Image *mediumImage = NULL;
760761
const Image *brutalImage = NULL;
@@ -889,7 +890,9 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
889890
index = GadgetListBoxAddEntryImage( listbox, NULL, index, 0, w, h, TRUE);
890891
}
891892
}
893+
892894
index = GadgetListBoxAddEntryText( listbox, mapDisplayName, color, index, numColumns-1 );
895+
DEBUG_ASSERTCRASH(index >= 0, ("Expects valid index"));
893896

894897
if (it->first == mapToSelect)
895898
{
@@ -904,6 +907,12 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
904907
{
905908
GadgetListBoxSetItemData( listbox, (void *)imageItemData, index, 1 );
906909
}
910+
911+
// TheSuperHackers @performance Now stops processing when the list is full.
912+
if (index == listboxLength - 1)
913+
{
914+
goto Done;
915+
}
907916
}
908917
++tempit;
909918
}
@@ -913,6 +922,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
913922
++curNumPlayersInMap;
914923
}
915924

925+
Done:
916926
delete battleHonors;
917927
battleHonors = NULL;
918928

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

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

150150
// Get the selections (is this a private message?)
151-
Int maxSel = GadgetListBoxGetListLength(playerListbox);
151+
Int maxSel = GadgetListBoxGetMaxSelectedLength(playerListbox);
152152
Int *selections;
153153
GadgetListBoxGetSelected(playerListbox, (Int *)&selections);
154154

0 commit comments

Comments
 (0)