Skip to content

Commit 4f5121d

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

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
@@ -793,7 +793,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
793793
// reset the listbox content
794794
//GadgetListBoxReset( listbox );
795795

796-
Int numColumns = GadgetListBoxGetNumColumns( listbox );
796+
const Int listboxLength = GadgetListBoxGetListLength( listbox );
797+
const Int numColumns = GadgetListBoxGetNumColumns( listbox );
797798
const Image *easyImage = NULL;
798799
const Image *mediumImage = NULL;
799800
const Image *brutalImage = NULL;
@@ -928,7 +929,9 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
928929
index = GadgetListBoxAddEntryImage( listbox, NULL, index, 0, w, h, TRUE);
929930
}
930931
}
932+
931933
index = GadgetListBoxAddEntryText( listbox, mapDisplayName, color, index, numColumns-1 );
934+
DEBUG_ASSERTCRASH(index >= 0, ("Expects valid index"));
932935

933936
if (it->first == mapToSelect)
934937
{
@@ -943,6 +946,12 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
943946
{
944947
GadgetListBoxSetItemData( listbox, (void *)imageItemData, index, 1 );
945948
}
949+
950+
// TheSuperHackers @performance Now stops processing when the list is full.
951+
if (index == listboxLength - 1)
952+
{
953+
goto Done;
954+
}
946955
}
947956
++tempit;
948957
}
@@ -952,6 +961,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
952961
++curNumPlayersInMap;
953962
}
954963

964+
Done:
955965
delete battleHonors;
956966
battleHonors = NULL;
957967

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
@@ -793,7 +793,8 @@ Int populateMapListboxNoReset( GameWindow *listbox, Bool useSystemMaps, Bool isM
793793
// reset the listbox content
794794
//GadgetListBoxReset( listbox );
795795

796-
Int numColumns = GadgetListBoxGetNumColumns( listbox );
796+
const Int listboxLength = GadgetListBoxGetListLength( listbox );
797+
const Int numColumns = GadgetListBoxGetNumColumns( listbox );
797798
const Image *easyImage = NULL;
798799
const Image *mediumImage = NULL;
799800
const Image *brutalImage = NULL;
@@ -928,7 +929,9 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
928929
index = GadgetListBoxAddEntryImage( listbox, NULL, index, 0, w, h, TRUE);
929930
}
930931
}
932+
931933
index = GadgetListBoxAddEntryText( listbox, mapDisplayName, color, index, numColumns-1 );
934+
DEBUG_ASSERTCRASH(index >= 0, ("Expects valid index"));
932935

933936
if (it->first == mapToSelect)
934937
{
@@ -943,6 +946,12 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
943946
{
944947
GadgetListBoxSetItemData( listbox, (void *)imageItemData, index, 1 );
945948
}
949+
950+
// TheSuperHackers @performance Now stops processing when the list is full.
951+
if (index == listboxLength - 1)
952+
{
953+
goto Done;
954+
}
946955
}
947956
++tempit;
948957
}
@@ -952,6 +961,7 @@ typedef MapDisplayToFileNameList::iterator MapDisplayToFileNameListIter;
952961
++curNumPlayersInMap;
953962
}
954963

964+
Done:
955965
delete battleHonors;
956966
battleHonors = NULL;
957967

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)