Skip to content

Commit c245d1a

Browse files
committed
Replaced hacky C++03 lambdas with C++11 lambdas
1 parent 17f2040 commit c245d1a

File tree

13 files changed

+61
-84
lines changed

13 files changed

+61
-84
lines changed

Client/core/CMainMenu.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1121,7 +1121,7 @@ void CMainMenu::WantsToDisconnectCallBack( void* pData, uint uiButton )
11211121

11221122
if ( uiButton == 1 )
11231123
{
1124-
uchar menuType = (uchar)pData;
1124+
int menuType = (int)pData;
11251125
switch( menuType )
11261126
{
11271127
case MENU_ITEM_HOST_GAME: OnHostGameButtonClick (); break;

Client/core/CTimingCheckpoints.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,11 @@ class CTimingCheckpoints
243243
resultList.push_back ( &iter->second );
244244
}
245245

246-
sort_inline ( resultList.begin (), resultList.end (), ( const SSectionInfo* a, const SSectionInfo* b ) { return a->totalTime > b->totalTime; } );
246+
std::sort(resultList.begin(), resultList.end(),
247+
[](const SSectionInfo* a, const SSectionInfo* b)
248+
{
249+
return a->totalTime > b->totalTime;
250+
});
247251

248252

249253
// Output to string

Client/core/CVersionUpdater.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3190,12 +3190,7 @@ int CVersionUpdater::DoSendDownloadRequestToNextServer ( void )
31903190
g_pGraphics->GetRenderItemManager ()->GetDxStatus ( dxStatus );
31913191
CGameSettings* gameSettings = CCore::GetSingleton ( ).GetGame ( )->GetSettings();
31923192
SString strVideoCard = SStringX ( g_pDeviceState->AdapterState.Name ).Left ( 30 );
3193-
{
3194-
LOCAL_FUNCTION_START
3195-
static bool IsNotAlnum ( int c ) { return !isalnum(c); }
3196-
LOCAL_FUNCTION_END
3197-
std::replace_if( strVideoCard.begin(), strVideoCard.end(), LOCAL_FUNCTION::IsNotAlnum, '_' );
3198-
}
3193+
std::replace_if(strVideoCard.begin(), strVideoCard.end(), [](int c) { return !isalnum(c); }, '_');
31993194
SString strSystemStats ( "1_%d_%d_%d_%d_%d"
32003195
"_%d%d%d%d"
32013196
"_%s"

Client/core/CrashHandler.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,18 +192,16 @@ BOOL __stdcall SetCrashHandlerFilter ( PFNCHFILTFN pFn )
192192

193193
// Stop the OS from turning off our handler
194194
// Ref: http://www.codeproject.com/Articles/154686/SetUnhandledExceptionFilter-and-the-C-C-Runtime-Li
195+
LONG(WINAPI *RedirectedSetUnhandledExceptionFilter)(EXCEPTION_POINTERS *) = [](EXCEPTION_POINTERS * /*ExceptionInfo*/) -> LONG
196+
{
197+
// When the CRT calls SetUnhandledExceptionFilter with NULL parameter
198+
// our handler will not get removed.
199+
return 0;
200+
};
195201

196-
LOCAL_FUNCTION_START
197-
static LONG WINAPI RedirectedSetUnhandledExceptionFilter(EXCEPTION_POINTERS * /*ExceptionInfo*/)
198-
{
199-
// When the CRT calls SetUnhandledExceptionFilter with NULL parameter
200-
// our handler will not get removed.
201-
return 0;
202-
}
203-
LOCAL_FUNCTION_END
202+
DetourFunction(DetourFindFunction("Kernel32.dll", "SetUnhandledExceptionFilter"),
203+
reinterpret_cast <PBYTE> (RedirectedSetUnhandledExceptionFilter));
204204

205-
reinterpret_cast < LPTOP_LEVEL_EXCEPTION_FILTER > ( DetourFunction ( DetourFindFunction( "Kernel32.dll", "SetUnhandledExceptionFilter" ),
206-
reinterpret_cast < PBYTE > ( LOCAL_FUNCTION::RedirectedSetUnhandledExceptionFilter ) ) );
207205
}
208206
}
209207
return ( TRUE ) ;

Client/core/Graphics/CMaterialLine3DBatcher.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ void CMaterialLine3DBatcher::Flush ( void )
156156

157157
// Sort index list by distance
158158
ms_pLines = &m_LineList [ 0 ];
159-
sort_inline ( indexList.begin (), indexList.end (), ( const uint a, const uint b ) { return ms_pLines [ a ].fDistSq > ms_pLines [ b ].fDistSq; } );
159+
std::sort ( indexList.begin (), indexList.end (),
160+
[](const uint a, const uint b)
161+
{
162+
return ms_pLines[a].fDistSq > ms_pLines[b].fDistSq;
163+
});
160164

161165
pIndices = &indexList [ 0 ];
162166

Client/game_sa/CRenderWareSA.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,15 +294,13 @@ RpClump * CRenderWareSA::ReadDFF ( const SString& strFilename, const CBuffer& fi
294294
//
295295
void CRenderWareSA::GetClumpAtomicList ( RpClump* pClump, std::vector < RpAtomic* >& outAtomicList )
296296
{
297-
LOCAL_FUNCTION_START
298-
static RpAtomic* GetClumpAtomicListCB ( RpAtomic* pAtomic, std::vector < RpAtomic* >* pData )
299-
{
300-
pData->push_back ( pAtomic );
301-
return pAtomic;
302-
}
303-
LOCAL_FUNCTION_END
297+
auto GetClumpAtomicListCB = [](RpAtomic* pAtomic, std::vector < RpAtomic* >* pData)
298+
{
299+
pData->push_back(pAtomic);
300+
return pAtomic;
301+
};
304302

305-
RpClumpForAllAtomics ( pClump, LOCAL_FUNCTION::GetClumpAtomicListCB, &outAtomicList );
303+
RpClumpForAllAtomics ( pClump, (void*)&GetClumpAtomicListCB, &outAtomicList );
306304
}
307305

308306

@@ -846,4 +844,4 @@ CD3DDUMMY* GetDeletedMapKey ( CD3DDUMMY** )
846844
RwFrame * CRenderWareSA::GetFrameFromName ( RpClump * pRoot, SString strName )
847845
{
848846
return RwFrameFindFrame ( RpGetFrame ( pRoot ), strName );
849-
}
847+
}

Server/core/CCrashHandlerAPI.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,15 @@ BOOL __stdcall SetCrashHandlerFilter ( PFNCHFILTFN pFn )
204204

205205
// Stop the OS from turning off our handler
206206
// Ref: http://www.codeproject.com/Articles/154686/SetUnhandledExceptionFilter-and-the-C-C-Runtime-Li
207-
208-
LOCAL_FUNCTION_START
209-
static LONG WINAPI RedirectedSetUnhandledExceptionFilter(EXCEPTION_POINTERS * /*ExceptionInfo*/)
210-
{
211-
// When the CRT calls SetUnhandledExceptionFilter with NULL parameter
212-
// our handler will not get removed.
213-
return 0;
214-
}
215-
LOCAL_FUNCTION_END
216-
217-
reinterpret_cast < LPTOP_LEVEL_EXCEPTION_FILTER > ( DetourFunction ( DetourFindFunction( "Kernel32.dll", "SetUnhandledExceptionFilter" ),
218-
reinterpret_cast < PBYTE > ( LOCAL_FUNCTION::RedirectedSetUnhandledExceptionFilter ) ) );
207+
LONG(WINAPI *RedirectedSetUnhandledExceptionFilter)(EXCEPTION_POINTERS *) = [](EXCEPTION_POINTERS * /*ExceptionInfo*/) -> LONG
208+
{
209+
// When the CRT calls SetUnhandledExceptionFilter with NULL parameter
210+
// our handler will not get removed.
211+
return 0;
212+
};
213+
214+
DetourFunction ( DetourFindFunction( "Kernel32.dll", "SetUnhandledExceptionFilter" ),
215+
reinterpret_cast < PBYTE > ( RedirectedSetUnhandledExceptionFilter ) );
219216
}
220217
}
221218
return ( TRUE ) ;

Server/mods/deathmatch/logic/CPerfStat.EventPacketUsage.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ void CPerfStatEventPacketUsageImpl::MaybeRecordStats ( void )
204204
iter->second.strName = iter->first;
205205
m_EventUsageSortedList.push_back( iter->second );
206206
}
207-
sort_inline ( m_EventUsageSortedList.begin (), m_EventUsageSortedList.end (), ( const SEventUsage& a, const SEventUsage& b ) { return a.iTotal > b.iTotal; } );
207+
208+
std::sort ( m_EventUsageSortedList.begin (), m_EventUsageSortedList.end (),
209+
[](const SEventUsage& a, const SEventUsage& b)
210+
{
211+
return a.iTotal > b.iTotal;
212+
});
208213

209214
m_EventUsageLiveMap.clear();
210215
}

Server/mods/deathmatch/logic/CResource.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,11 @@ bool CResource::Start ( list<CResource *> * dependents, bool bStartedManually, b
10361036
// Add us to the running resources list
10371037
m_StartedResources.push_back ( this );
10381038

1039-
// Sort by priority, for start grouping on the client
1040-
sort_list_inline ( m_StartedResources, ( CResource* a, CResource* b ) { return a->m_iDownloadPriorityGroup > b->m_iDownloadPriorityGroup; } );
1039+
// Sort by priority, for start grouping on the client
1040+
m_StartedResources.sort([](CResource* a, CResource* b)
1041+
{
1042+
return a->m_iDownloadPriorityGroup > b->m_iDownloadPriorityGroup;
1043+
});
10411044
}
10421045
return m_bActive;
10431046
}

Shared/sdk/SharedUtil.Defines.h

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -141,29 +141,6 @@
141141
#define ZERO_POD_STRUCT(ptr) \
142142
memset ( ptr, 0, sizeof(*(ptr)) )
143143

144-
// Crazy thing
145-
#define LOCAL_FUNCTION_START struct local {
146-
#define LOCAL_FUNCTION_END };
147-
#define LOCAL_FUNCTION local
148-
/*
149-
// Inline callback definition for std::sort
150-
#define sort_inline(a,b,c) \
151-
{ \
152-
LOCAL_FUNCTION_START \
153-
static bool SortPredicate c \
154-
LOCAL_FUNCTION_END \
155-
std::sort ( a, b, LOCAL_FUNCTION::SortPredicate ); \
156-
}
157-
158-
// Inline callback definition for std::list::sort
159-
#define sort_list_inline(a,c) \
160-
{ \
161-
LOCAL_FUNCTION_START \
162-
static bool SortPredicate c \
163-
LOCAL_FUNCTION_END \
164-
a.sort ( LOCAL_FUNCTION::SortPredicate ); \
165-
}
166-
*/
167144
// printf/wprintf helpers
168145
//
169146
// http://www.firstobject.com/wchar_t-string-on-linux-osx-windows.htm

0 commit comments

Comments
 (0)