Skip to content

Commit a1cf8c8

Browse files
committed
refactor(radar): Simplify function Radar::deleteListResources (#1893)
1 parent 7f2c94c commit a1cf8c8

File tree

2 files changed

+18
-34
lines changed

2 files changed

+18
-34
lines changed

GeneralsMD/Code/GameEngine/Include/Common/Radar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class Radar : public Snapshot,
239239
void internalCreateEvent( const Coord3D *world, RadarEventType type, Real secondsToLive,
240240
const RGBAColorInt *color1, const RGBAColorInt *color2 );
241241

242+
void deleteList( RadarObject **list );
242243
void deleteListResources( void ); ///< delete list radar resources used
243244
Bool deleteFromList( Object *obj, RadarObject **list ); ///< try to remove object from specific list
244245

GeneralsMD/Code/GameEngine/Source/Common/System/Radar.cpp

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -62,56 +62,39 @@ Radar *TheRadar = NULL; ///< the radar global singleton
6262
#define RADAR_QUEUE_TERRAIN_REFRESH_DELAY (LOGICFRAMES_PER_SECOND * 3.0f)
6363

6464
//-------------------------------------------------------------------------------------------------
65-
/** Delete list resources used by the radar and return them to the memory pools */
6665
//-------------------------------------------------------------------------------------------------
67-
void Radar::deleteListResources( void )
66+
void Radar::deleteList( RadarObject **list )
6867
{
69-
RadarObject *nextObject;
70-
71-
// delete entries from the local object list
72-
while( m_localObjectList )
68+
while( *list )
7369
{
74-
7570
// get next object
76-
nextObject = m_localObjectList->friend_getNext();
71+
RadarObject *nextObject = (*list)->friend_getNext();
7772

7873
// remove radar data from object
79-
m_localObjectList->friend_getObject()->friend_setRadarData( NULL );
74+
(*list)->friend_getObject()->friend_setRadarData( NULL );
8075

8176
// delete the head of the list
82-
deleteInstance(m_localObjectList);
77+
deleteInstance(*list);
8378

8479
// set head of the list to the next object
85-
m_localObjectList = nextObject;
86-
80+
*list = nextObject;
8781
}
82+
}
8883

89-
// delete entries from the regular object list
90-
while( m_objectList )
91-
{
92-
93-
// get next object
94-
nextObject = m_objectList->friend_getNext();
95-
96-
// remove radar data from object
97-
m_objectList->friend_getObject()->friend_setRadarData( NULL );
98-
99-
// delete the head of the list
100-
deleteInstance(m_objectList);
101-
102-
// set head of the list to the next object
103-
m_objectList = nextObject;
104-
105-
}
84+
//-------------------------------------------------------------------------------------------------
85+
/** Delete list resources used by the radar and return them to the memory pools */
86+
//-------------------------------------------------------------------------------------------------
87+
void Radar::deleteListResources( void )
88+
{
89+
deleteList(&m_objectList);
90+
deleteList(&m_localObjectList);
10691

107-
Object *obj;
108-
for( obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
92+
#ifdef DEBUG_CRASHING
93+
for( Object *obj = TheGameLogic->getFirstObject(); obj; obj = obj->getNextObject() )
10994
{
110-
11195
DEBUG_ASSERTCRASH( obj->friend_getRadarData() == NULL, ("oops") );
112-
11396
}
114-
97+
#endif
11598
}
11699

117100
// PUBLIC METHODS /////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)