Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
57cf4c2
Use move semantics in aiFollowPath and aiFollowExitProductionPath
bobtista Nov 23, 2025
ea081ef
Use move semantics in AIStateMachine::setGoalPath
bobtista Nov 23, 2025
7a8b8a5
Update privateFollowPath to use move semantics
bobtista Nov 23, 2025
86668ca
Use swap instead of move for VC6 compatibility
bobtista Nov 23, 2025
46f05db
Use const_cast in aiDoCommand to pass non-const vector to privateFoll…
bobtista Nov 23, 2025
0b5e2ab
Add conditional compilation for move vs swap and clear source vector
bobtista Nov 25, 2025
5c21432
nit: make comments consistent
bobtista Nov 25, 2025
166de53
refactor(perf): centralize move semantics helper in CppMacros.h
bobtista Nov 25, 2025
42e0465
refactor: remove unnecessary CppMacros.h includes
bobtista Nov 28, 2025
e50980d
refactor(perf): rename move_assign_from_pointer to move_or_swap and c…
bobtista Nov 28, 2025
a4046ce
refactor(perf): remove comment format and fix C++03 move semantics fa…
bobtista Nov 29, 2025
c428f10
refactor(perf): make m_coords mutable to remove const_cast
bobtista Nov 29, 2025
45c064c
remove include
bobtista Nov 29, 2025
8eab14a
refactor(perf): move coords into AICommandParmsStorage via const_cast
bobtista Dec 15, 2025
88b027c
refactor(perf): remove mutable coords from AICommandParms
bobtista Dec 15, 2025
80e022c
refactor(perf): keep AICommandParms const and copy coords where needed
bobtista Dec 15, 2025
8ba6502
Remove inline keyword from aiFollowPath functions
bobtista Dec 22, 2025
1f1a897
Use copy instead of const_cast for m_coords in AICommandParmsStorage:…
bobtista Dec 22, 2025
95b00a1
Clarify comment about copying coordinates in path following cases
bobtista Dec 22, 2025
5965d08
Replicate AI path function changes from GeneralsMD
bobtista Dec 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dependencies/Utility/Utility/CppMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
// This file contains macros to help upgrade the code for newer cpp standards.
#pragma once

#if __cplusplus >= 201103L
#include <utility>
#endif

#if __cplusplus >= 201703L
#define NOEXCEPT_17 noexcept
#define REGISTER
Expand All @@ -44,3 +48,18 @@
#define constexpr
#define nullptr 0
#endif

// Helper to move-assign from reference: uses std::move in C++11, swap in C++98
template<typename T>
inline void move_or_swap(T& dest, T& src)
{
#if __cplusplus >= 201103L
dest = std::move(src);
#else
// C++03 fallback: mimic move semantics
// dest gets src's value, src becomes empty
T empty;
dest.swap(src);
src.swap(empty);
#endif
}
8 changes: 4 additions & 4 deletions Generals/Code/GameEngine/Include/GameLogic/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -536,18 +536,18 @@ class AICommandInterface
aiDoCommand(&parms);
}

void aiFollowExitProductionPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
void aiFollowExitProductionPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
{
AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource);
parms.m_coords = *path;
move_or_swap(parms.m_coords, *path);
parms.m_obj = ignoreObject;
aiDoCommand(&parms);
}

void aiFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
void aiFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
{
AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource);
parms.m_coords = *path;
move_or_swap(parms.m_coords, *path);
parms.m_obj = ignoreObject;
aiDoCommand(&parms);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class AIStateMachine : public StateMachine
virtual StateReturnType setState( StateID newStateID );

/// @todo Rethink state parameter passing. Continuing in this fashion will have a pile of params in the machine (MSB)
void setGoalPath( const std::vector<Coord3D>* path );
void setGoalPath( std::vector<Coord3D>* path );
void addToGoalPath( const Coord3D *pathPoint );
const Coord3D *getGoalPathPosition( Int i ) const; ///< return path position at index "i"
Int getGoalPathSize() const { return m_goalPath.size(); }
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
virtual void privateFollowWaypointPathAsTeam( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowWaypointPathExact( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowWaypointPathAsTeamExact( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPathAppend( const Coord3D *pos, CommandSourceType cmdSource );
virtual void privateAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource ); ///< attack given object
virtual void privateForceAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource ); ///< attack given object
Expand Down Expand Up @@ -338,7 +338,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
virtual Bool isBusy() const;

virtual void onObjectCreated();
virtual void doQuickExit( const std::vector<Coord3D>* path ); ///< get out of this Object
virtual void doQuickExit( std::vector<Coord3D>* path ); ///< get out of this Object

virtual void aiDoCommand(const AICommandParms* parms);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class JetAIUpdate : public AIUpdateInterface
Real friend_getMinHeight() const { return getJetAIUpdateModuleData()->m_minHeight; }
Real friend_getParkingOffset() const { return getJetAIUpdateModuleData()->m_parkingOffset; }
UnsignedInt friend_getTakeoffPause() const { return getJetAIUpdateModuleData()->m_takeoffPause; }
void friend_setGoalPath( const std::vector<Coord3D>* path ) { getStateMachine()->setGoalPath(path); }
void friend_setGoalPath( std::vector<Coord3D>* path ) { getStateMachine()->setGoalPath(path); }
void friend_setTakeoffInProgress(Bool v) { setFlag(TAKEOFF_IN_PROGRESS, v); }
void friend_setLandingInProgress(Bool v) { setFlag(LANDING_IN_PROGRESS, v); }
void friend_setTaxiInProgress(Bool v) { setFlag(TAXI_IN_PROGRESS, v); }
Expand All @@ -122,7 +122,7 @@ class JetAIUpdate : public AIUpdateInterface

virtual AIStateMachine* makeStateMachine();

virtual void privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPathAppend( const Coord3D *pos, CommandSourceType cmdSource );
virtual void privateEnter( Object *obj, CommandSourceType cmdSource ); ///< enter the given object
virtual void privateGetRepaired( Object *repairDepot, CommandSourceType cmdSource );///< get repaired at repair depot
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,9 @@ void AIStateMachine::loadPostProcess( void )
/**
* Define a simple path
*/
void AIStateMachine::setGoalPath( const std::vector<Coord3D>* path )
void AIStateMachine::setGoalPath( std::vector<Coord3D>* path )
{
m_goalPath = *path;
move_or_swap(m_goalPath, *path);
}

#ifdef STATE_MACHINE_DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2619,14 +2619,22 @@ void AIUpdateInterface::aiDoCommand(const AICommandParms* parms)
privateFollowWaypointPathAsTeamExact(parms->m_waypoint, parms->m_cmdSource);
break;
case AICMD_FOLLOW_PATH:
privateFollowPath(&parms->m_coords, parms->m_obj, parms->m_cmdSource, FALSE);
{
// Copy coordinates to a local vector since privateFollowPath requires a non-const pointer.
std::vector<Coord3D> coords = parms->m_coords;
privateFollowPath(&coords, parms->m_obj, parms->m_cmdSource, FALSE);
break;
}
case AICMD_FOLLOW_PATH_APPEND:
privateFollowPathAppend(&parms->m_pos, parms->m_cmdSource);
break;
case AICMD_FOLLOW_EXITPRODUCTION_PATH:
privateFollowPath(&parms->m_coords, parms->m_obj, parms->m_cmdSource, TRUE);
{
// Copy coordinates to a local vector since privateFollowPath requires a non-const pointer.
std::vector<Coord3D> coords = parms->m_coords;
privateFollowPath(&coords, parms->m_obj, parms->m_cmdSource, TRUE);
break;
}
case AICMD_ATTACK_OBJECT:
privateAttackObject(parms->m_obj, parms->m_intValue, parms->m_cmdSource);
break;
Expand Down Expand Up @@ -3240,7 +3248,7 @@ void AIUpdateInterface::privateFollowPathAppend( const Coord3D *pos, CommandSour
/**
* Follow the path defined by the given array of points
*/
void AIUpdateInterface::privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
void AIUpdateInterface::privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
{
if (getObject()->isMobile() == FALSE)
return;
Expand Down Expand Up @@ -3681,7 +3689,7 @@ void AIUpdateInterface::privateExit( Object *objectToExit, CommandSourceType cmd
/**
* Get out of whatever it is inside of
*/
void AIUpdateInterface::doQuickExit( const std::vector<Coord3D>* path )
void AIUpdateInterface::doQuickExit( std::vector<Coord3D>* path )
{

Bool locked = getStateMachine()->isLocked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2172,7 +2172,7 @@ Bool JetAIUpdate::getTreatAsAircraftForLocoDistToGoal() const
/**
* Follow the path defined by the given array of points
*/
void JetAIUpdate::privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
void JetAIUpdate::privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
{
if (exitProduction)
{
Expand Down
8 changes: 4 additions & 4 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,18 +550,18 @@ class AICommandInterface
aiDoCommand(&parms);
}

void aiFollowExitProductionPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
void aiFollowExitProductionPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
{
AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource);
parms.m_coords = *path;
move_or_swap(parms.m_coords, *path);
parms.m_obj = ignoreObject;
aiDoCommand(&parms);
}

void aiFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
void aiFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
{
AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource);
parms.m_coords = *path;
move_or_swap(parms.m_coords, *path);
parms.m_obj = ignoreObject;
aiDoCommand(&parms);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class AIStateMachine : public StateMachine
virtual StateReturnType setState( StateID newStateID );

/// @todo Rethink state parameter passing. Continuing in this fashion will have a pile of params in the machine (MSB)
void setGoalPath( const std::vector<Coord3D>* path );
void setGoalPath( std::vector<Coord3D>* path );
void addToGoalPath( const Coord3D *pathPoint );
const Coord3D *getGoalPathPosition( Int i ) const; ///< return path position at index "i"
Int getGoalPathSize() const { return m_goalPath.size(); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
virtual void privateFollowWaypointPathAsTeam( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowWaypointPathExact( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowWaypointPathAsTeamExact( const Waypoint *way, CommandSourceType cmdSource );///< start following the path from the given point
virtual void privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPathAppend( const Coord3D *pos, CommandSourceType cmdSource );
virtual void privateAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource ); ///< attack given object
virtual void privateForceAttackObject( Object *victim, Int maxShotsToFire, CommandSourceType cmdSource ); ///< attack given object
Expand Down Expand Up @@ -351,7 +351,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface
virtual Bool isBusy() const;

virtual void onObjectCreated();
virtual void doQuickExit( const std::vector<Coord3D>* path ); ///< get out of this Object
virtual void doQuickExit( std::vector<Coord3D>* path ); ///< get out of this Object

virtual void aiDoCommand(const AICommandParms* parms);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class JetAIUpdate : public AIUpdateInterface
Real friend_getMinHeight() const { return getJetAIUpdateModuleData()->m_minHeight; }
Real friend_getParkingOffset() const { return getJetAIUpdateModuleData()->m_parkingOffset; }
UnsignedInt friend_getTakeoffPause() const { return getJetAIUpdateModuleData()->m_takeoffPause; }
void friend_setGoalPath( const std::vector<Coord3D>* path ) { getStateMachine()->setGoalPath(path); }
void friend_setGoalPath( std::vector<Coord3D>* path ) { getStateMachine()->setGoalPath(path); }
void friend_setTakeoffInProgress(Bool v) { setFlag(TAKEOFF_IN_PROGRESS, v); }
void friend_setLandingInProgress(Bool v) { setFlag(LANDING_IN_PROGRESS, v); }
void friend_setTaxiInProgress(Bool v) { setFlag(TAXI_IN_PROGRESS, v); }
Expand All @@ -131,7 +131,7 @@ class JetAIUpdate : public AIUpdateInterface

virtual AIStateMachine* makeStateMachine();

virtual void privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points
virtual void privateFollowPathAppend( const Coord3D *pos, CommandSourceType cmdSource );
virtual void privateEnter( Object *obj, CommandSourceType cmdSource ); ///< enter the given object
virtual void privateGetRepaired( Object *repairDepot, CommandSourceType cmdSource );///< get repaired at repair depot
Expand Down
4 changes: 2 additions & 2 deletions GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,9 +821,9 @@ void AIStateMachine::loadPostProcess( void )
/**
* Define a simple path
*/
void AIStateMachine::setGoalPath( const std::vector<Coord3D>* path )
void AIStateMachine::setGoalPath( std::vector<Coord3D>* path )
{
m_goalPath = *path;
move_or_swap(m_goalPath, *path);
}

#ifdef STATE_MACHINE_DEBUG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2681,14 +2681,22 @@ void AIUpdateInterface::aiDoCommand(const AICommandParms* parms)
privateFollowWaypointPathAsTeamExact(parms->m_waypoint, parms->m_cmdSource);
break;
case AICMD_FOLLOW_PATH:
privateFollowPath(&parms->m_coords, parms->m_obj, parms->m_cmdSource, FALSE);
{
// Copy coordinates to a local vector since privateFollowPath requires a non-const pointer.
std::vector<Coord3D> coords = parms->m_coords;
privateFollowPath(&coords, parms->m_obj, parms->m_cmdSource, FALSE);
break;
}
case AICMD_FOLLOW_PATH_APPEND:
privateFollowPathAppend(&parms->m_pos, parms->m_cmdSource);
break;
case AICMD_FOLLOW_EXITPRODUCTION_PATH:
privateFollowPath(&parms->m_coords, parms->m_obj, parms->m_cmdSource, TRUE);
{
// Copy coordinates to a local vector since privateFollowPath requires a non-const pointer.
std::vector<Coord3D> coords = parms->m_coords;
privateFollowPath(&coords, parms->m_obj, parms->m_cmdSource, TRUE);
break;
}
case AICMD_ATTACK_OBJECT:
privateAttackObject(parms->m_obj, parms->m_intValue, parms->m_cmdSource);
break;
Expand Down Expand Up @@ -3377,7 +3385,7 @@ void AIUpdateInterface::privateFollowPathAppend( const Coord3D *pos, CommandSour
/**
* Follow the path defined by the given array of points
*/
void AIUpdateInterface::privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
void AIUpdateInterface::privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
{
if (getObject()->isMobile() == FALSE)
return;
Expand Down Expand Up @@ -3869,7 +3877,7 @@ void AIUpdateInterface::privateExitInstantly( Object *objectToExit, CommandSourc
/**
* Get out of whatever it is inside of
*/
void AIUpdateInterface::doQuickExit( const std::vector<Coord3D>* path )
void AIUpdateInterface::doQuickExit( std::vector<Coord3D>* path )
{

Bool locked = getStateMachine()->isLocked();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,7 @@ Bool JetAIUpdate::getTreatAsAircraftForLocoDistToGoal() const
/**
* Follow the path defined by the given array of points
*/
void JetAIUpdate::privateFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
void JetAIUpdate::privateFollowPath( std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction )
{
if (exitProduction)
{
Expand Down
Loading