Skip to content

Commit 69c373c

Browse files
committed
refactor(perf): centralize move semantics helper in CppMacros.h
1 parent fae8029 commit 69c373c

File tree

7 files changed

+28
-42
lines changed

7 files changed

+28
-42
lines changed

Dependencies/Utility/Utility/CppMacros.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
// This file contains macros to help upgrade the code for newer cpp standards.
2020
#pragma once
2121

22+
#if __cplusplus >= 201103L
23+
#include <utility>
24+
#endif
25+
2226
#if __cplusplus >= 201703L
2327
#define NOEXCEPT_17 noexcept
2428
#define REGISTER
@@ -44,3 +48,15 @@
4448
#define constexpr
4549
#define nullptr 0
4650
#endif
51+
52+
// TheSuperHackers @performance bobtista 25/11/2025 Helper to move-assign from pointer: uses std::move in C++11, swap in C++98
53+
template<typename T>
54+
inline void move_assign_from_pointer(T& dest, T* src)
55+
{
56+
#if __cplusplus >= 201103L
57+
dest = std::move(*src);
58+
#else
59+
// Use swap to emulate move semantics for VC6 compatibility
60+
dest.swap(*src);
61+
#endif
62+
}

Generals/Code/GameEngine/Include/GameLogic/AI.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "GameLogic/Damage.h"
3636
#include "Common/STLTypedefs.h"
3737
#include "ref_ptr.h"
38+
#include "Utility/CppMacros.h"
3839

3940
class AIGroup;
4041
class AttackPriorityInfo;
@@ -539,27 +540,15 @@ class AICommandInterface
539540
inline void aiFollowExitProductionPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
540541
{
541542
AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource);
542-
#if __cplusplus >= 201103L
543-
parms.m_coords = std::move(*path);
544-
#else
545-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
546-
parms.m_coords.swap(*path);
547-
path->clear();
548-
#endif
543+
move_assign_from_pointer(parms.m_coords, path);
549544
parms.m_obj = ignoreObject;
550545
aiDoCommand(&parms);
551546
}
552547

553548
inline void aiFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
554549
{
555550
AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource);
556-
#if __cplusplus >= 201103L
557-
parms.m_coords = std::move(*path);
558-
#else
559-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
560-
parms.m_coords.swap(*path);
561-
path->clear();
562-
#endif
551+
move_assign_from_pointer(parms.m_coords, path);
563552
parms.m_obj = ignoreObject;
564553
aiDoCommand(&parms);
565554
}

Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ extern Bool outOfWeaponRangeObject( State *thisState, void* userData );
108108
extern Bool outOfWeaponRangePosition( State *thisState, void* userData );
109109
extern Bool wantToSquishTarget( State *thisState, void* userData );
110110

111+
#include "Utility/CppMacros.h"
112+
111113
//-----------------------------------------------------------------------------------------------------------
112114
/**
113115
The AI state machine. This is used by AIUpdate to implement all of the

Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -818,13 +818,7 @@ void AIStateMachine::loadPostProcess( void )
818818
*/
819819
void AIStateMachine::setGoalPath( std::vector<Coord3D>* path )
820820
{
821-
#if __cplusplus >= 201103L
822-
m_goalPath = std::move(*path);
823-
#else
824-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
825-
m_goalPath.swap(*path);
826-
path->clear();
827-
#endif
821+
move_assign_from_pointer(m_goalPath, path);
828822
}
829823

830824
#ifdef STATE_MACHINE_DEBUG

GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "GameLogic/Damage.h"
3636
#include "Common/STLTypedefs.h"
3737
#include "ref_ptr.h"
38+
#include "Utility/CppMacros.h"
3839

3940
class AIGroup;
4041
class AttackPriorityInfo;
@@ -553,27 +554,15 @@ class AICommandInterface
553554
inline void aiFollowExitProductionPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
554555
{
555556
AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource);
556-
#if __cplusplus >= 201103L
557-
parms.m_coords = std::move(*path);
558-
#else
559-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
560-
parms.m_coords.swap(*path);
561-
path->clear();
562-
#endif
557+
move_assign_from_pointer(parms.m_coords, path);
563558
parms.m_obj = ignoreObject;
564559
aiDoCommand(&parms);
565560
}
566561

567562
inline void aiFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
568563
{
569564
AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource);
570-
#if __cplusplus >= 201103L
571-
parms.m_coords = std::move(*path);
572-
#else
573-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
574-
parms.m_coords.swap(*path);
575-
path->clear();
576-
#endif
565+
move_assign_from_pointer(parms.m_coords, path);
577566
parms.m_obj = ignoreObject;
578567
aiDoCommand(&parms);
579568
}

GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ extern Bool outOfWeaponRangeObject( State *thisState, void* userData );
111111
extern Bool outOfWeaponRangePosition( State *thisState, void* userData );
112112
extern Bool wantToSquishTarget( State *thisState, void* userData );
113113

114+
#include "Utility/CppMacros.h"
115+
114116
//-----------------------------------------------------------------------------------------------------------
115117
/**
116118
The AI state machine. This is used by AIUpdate to implement all of the

GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -823,13 +823,7 @@ void AIStateMachine::loadPostProcess( void )
823823
*/
824824
void AIStateMachine::setGoalPath( std::vector<Coord3D>* path )
825825
{
826-
#if __cplusplus >= 201103L
827-
m_goalPath = std::move(*path);
828-
#else
829-
// TheSuperHackers @performance bobtista 23/11/2025 Use swap to emulate move semantics for VC6 compatibility
830-
m_goalPath.swap(*path);
831-
path->clear();
832-
#endif
826+
move_assign_from_pointer(m_goalPath, path);
833827
}
834828

835829
#ifdef STATE_MACHINE_DEBUG

0 commit comments

Comments
 (0)