Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
}
10 changes: 5 additions & 5 deletions Generals/Code/GameEngine/Include/GameLogic/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ struct AICommandParms
Object* m_obj;
Object* m_otherObj;
const Team* m_team;
std::vector<Coord3D> m_coords;
mutable std::vector<Coord3D> m_coords;
const Waypoint* m_waypoint;
const PolygonTrigger* m_polygon;
Int m_intValue; /// misc usage
Expand Down Expand Up @@ -536,18 +536,18 @@ class AICommandInterface
aiDoCommand(&parms);
}

inline void aiFollowExitProductionPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
inline 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);
}

inline void aiFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
inline 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
4 changes: 3 additions & 1 deletion Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ extern Bool outOfWeaponRangeObject( State *thisState, void* userData );
extern Bool outOfWeaponRangePosition( State *thisState, void* userData );
extern Bool wantToSquishTarget( State *thisState, void* userData );

#include "Utility/CppMacros.h"

//-----------------------------------------------------------------------------------------------------------
/**
The AI state machine. This is used by AIUpdate to implement all of the
Expand Down Expand Up @@ -138,7 +140,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 @@ -3240,7 +3240,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 +3681,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 @@ -2175,7 +2175,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
10 changes: 5 additions & 5 deletions GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ struct AICommandParms
Object* m_obj;
Object* m_otherObj;
const Team* m_team;
std::vector<Coord3D> m_coords;
mutable std::vector<Coord3D> m_coords;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking about this more, let us do a lightweight refactor and only touch where we can easily avoid a copy without const_casts or mutables.

Then also close #1924

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, so close 1924, and close this, and make another PR? Which changes do we want?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the mutable and then keep the copies where it would fail to compile.

const Waypoint* m_waypoint;
const PolygonTrigger* m_polygon;
Int m_intValue; /// misc usage
Expand Down Expand Up @@ -550,18 +550,18 @@ class AICommandInterface
aiDoCommand(&parms);
}

inline void aiFollowExitProductionPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
inline 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);
}

inline void aiFollowPath( const std::vector<Coord3D>* path, Object *ignoreObject, CommandSourceType cmdSource )
inline 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 @@ -111,6 +111,8 @@ extern Bool outOfWeaponRangeObject( State *thisState, void* userData );
extern Bool outOfWeaponRangePosition( State *thisState, void* userData );
extern Bool wantToSquishTarget( State *thisState, void* userData );

#include "Utility/CppMacros.h"

//-----------------------------------------------------------------------------------------------------------
/**
The AI state machine. This is used by AIUpdate to implement all of the
Expand Down Expand Up @@ -141,7 +143,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 @@ -3381,7 +3381,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 @@ -3873,7 +3873,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 @@ -2402,7 +2402,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