diff --git a/Dependencies/Utility/Utility/CppMacros.h b/Dependencies/Utility/Utility/CppMacros.h index 8bfb0297f2..aa7b8cf4c6 100644 --- a/Dependencies/Utility/Utility/CppMacros.h +++ b/Dependencies/Utility/Utility/CppMacros.h @@ -19,6 +19,10 @@ // This file contains macros to help upgrade the code for newer cpp standards. #pragma once +#if __cplusplus >= 201103L +#include +#endif + #if __cplusplus >= 201703L #define NOEXCEPT_17 noexcept #define REGISTER @@ -44,3 +48,15 @@ #define constexpr #define nullptr 0 #endif + +// TheSuperHackers @performance bobtista 25/11/2025 Helper to move-assign from pointer: uses std::move in C++11, swap in C++98 +template +inline void move_assign_from_pointer(T& dest, T* src) +{ +#if __cplusplus >= 201103L + dest = std::move(*src); +#else + // Use swap to emulate move semantics for VC6 compatibility + dest.swap(*src); +#endif +} diff --git a/Generals/Code/GameEngine/Include/GameLogic/AI.h b/Generals/Code/GameEngine/Include/GameLogic/AI.h index 502a2723cf..3f4c6b081e 100644 --- a/Generals/Code/GameEngine/Include/GameLogic/AI.h +++ b/Generals/Code/GameEngine/Include/GameLogic/AI.h @@ -35,6 +35,7 @@ #include "GameLogic/Damage.h" #include "Common/STLTypedefs.h" #include "ref_ptr.h" +#include "Utility/CppMacros.h" class AIGroup; class AttackPriorityInfo; @@ -536,18 +537,18 @@ class AICommandInterface aiDoCommand(&parms); } - inline void aiFollowExitProductionPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) + inline void aiFollowExitProductionPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) { AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource); - parms.m_coords = *path; + move_assign_from_pointer(parms.m_coords, path); parms.m_obj = ignoreObject; aiDoCommand(&parms); } - inline void aiFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) + inline void aiFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) { AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource); - parms.m_coords = *path; + move_assign_from_pointer(parms.m_coords, path); parms.m_obj = ignoreObject; aiDoCommand(&parms); } diff --git a/Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h b/Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h index 03f0de0e73..3992972456 100644 --- a/Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h +++ b/Generals/Code/GameEngine/Include/GameLogic/AIStateMachine.h @@ -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 @@ -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* path ); + void setGoalPath( std::vector* 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(); } diff --git a/Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h index 76fdff185c..97432322a9 100644 --- a/Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h +++ b/Generals/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h @@ -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* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points + virtual void privateFollowPath( std::vector* 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 @@ -338,7 +338,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface virtual Bool isBusy() const; virtual void onObjectCreated(); - virtual void doQuickExit( const std::vector* path ); ///< get out of this Object + virtual void doQuickExit( std::vector* path ); ///< get out of this Object virtual void aiDoCommand(const AICommandParms* parms); diff --git a/Generals/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h b/Generals/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h index c1b5facba1..f2e8b792e1 100644 --- a/Generals/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h +++ b/Generals/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h @@ -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* path ) { getStateMachine()->setGoalPath(path); } + void friend_setGoalPath( std::vector* 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); } @@ -122,7 +122,7 @@ class JetAIUpdate : public AIUpdateInterface virtual AIStateMachine* makeStateMachine(); - virtual void privateFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points + virtual void privateFollowPath( std::vector* 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 diff --git a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 79913a7c7d..ad1ca0207f 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -816,9 +816,9 @@ void AIStateMachine::loadPostProcess( void ) /** * Define a simple path */ -void AIStateMachine::setGoalPath( const std::vector* path ) +void AIStateMachine::setGoalPath( std::vector* path ) { - m_goalPath = *path; + move_assign_from_pointer(m_goalPath, path); } #ifdef STATE_MACHINE_DEBUG diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index e515ff54a4..2b6bba6b56 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2619,13 +2619,13 @@ 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); + privateFollowPath(&const_cast(parms)->m_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); + privateFollowPath(&const_cast(parms)->m_coords, parms->m_obj, parms->m_cmdSource, TRUE); break; case AICMD_ATTACK_OBJECT: privateAttackObject(parms->m_obj, parms->m_intValue, parms->m_cmdSource); @@ -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* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) +void AIUpdateInterface::privateFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) { if (getObject()->isMobile() == FALSE) return; @@ -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* path ) +void AIUpdateInterface::doQuickExit( std::vector* path ) { Bool locked = getStateMachine()->isLocked(); diff --git a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index 29034934a4..93b7c257e2 100644 --- a/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -2175,7 +2175,7 @@ Bool JetAIUpdate::getTreatAsAircraftForLocoDistToGoal() const /** * Follow the path defined by the given array of points */ -void JetAIUpdate::privateFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) +void JetAIUpdate::privateFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) { if (exitProduction) { diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h index 710bdf2f0a..41c24482b2 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AI.h @@ -35,6 +35,7 @@ #include "GameLogic/Damage.h" #include "Common/STLTypedefs.h" #include "ref_ptr.h" +#include "Utility/CppMacros.h" class AIGroup; class AttackPriorityInfo; @@ -550,18 +551,18 @@ class AICommandInterface aiDoCommand(&parms); } - inline void aiFollowExitProductionPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) + inline void aiFollowExitProductionPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) { AICommandParms parms(AICMD_FOLLOW_EXITPRODUCTION_PATH, cmdSource); - parms.m_coords = *path; + move_assign_from_pointer(parms.m_coords, path); parms.m_obj = ignoreObject; aiDoCommand(&parms); } - inline void aiFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) + inline void aiFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource ) { AICommandParms parms(AICMD_FOLLOW_PATH, cmdSource); - parms.m_coords = *path; + move_assign_from_pointer(parms.m_coords, path); parms.m_obj = ignoreObject; aiDoCommand(&parms); } diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h index 3171df36bc..67274eae0d 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/AIStateMachine.h @@ -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 @@ -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* path ); + void setGoalPath( std::vector* 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(); } diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h index 3f5a9d4e9e..4b2024645d 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/AIUpdate.h @@ -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* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points + virtual void privateFollowPath( std::vector* 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 @@ -351,7 +351,7 @@ class AIUpdateInterface : public UpdateModule, public AICommandInterface virtual Bool isBusy() const; virtual void onObjectCreated(); - virtual void doQuickExit( const std::vector* path ); ///< get out of this Object + virtual void doQuickExit( std::vector* path ); ///< get out of this Object virtual void aiDoCommand(const AICommandParms* parms); diff --git a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h index 1840d30a4b..a7cd1157aa 100644 --- a/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h +++ b/GeneralsMD/Code/GameEngine/Include/GameLogic/Module/JetAIUpdate.h @@ -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* path ) { getStateMachine()->setGoalPath(path); } + void friend_setGoalPath( std::vector* 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); } @@ -131,7 +131,7 @@ class JetAIUpdate : public AIUpdateInterface virtual AIStateMachine* makeStateMachine(); - virtual void privateFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction );///< follow the path defined by the given array of points + virtual void privateFollowPath( std::vector* 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 diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp index 6988747599..c064b6d5b1 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/AI/AIStates.cpp @@ -821,9 +821,9 @@ void AIStateMachine::loadPostProcess( void ) /** * Define a simple path */ -void AIStateMachine::setGoalPath( const std::vector* path ) +void AIStateMachine::setGoalPath( std::vector* path ) { - m_goalPath = *path; + move_assign_from_pointer(m_goalPath, path); } #ifdef STATE_MACHINE_DEBUG diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp index 2200bfd823..4e2e1df3e5 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp @@ -2681,13 +2681,13 @@ 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); + privateFollowPath(&const_cast(parms)->m_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); + privateFollowPath(&const_cast(parms)->m_coords, parms->m_obj, parms->m_cmdSource, TRUE); break; case AICMD_ATTACK_OBJECT: privateAttackObject(parms->m_obj, parms->m_intValue, parms->m_cmdSource); @@ -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* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) +void AIUpdateInterface::privateFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) { if (getObject()->isMobile() == FALSE) return; @@ -3873,7 +3873,7 @@ void AIUpdateInterface::privateExitInstantly( Object *objectToExit, CommandSourc /** * Get out of whatever it is inside of */ -void AIUpdateInterface::doQuickExit( const std::vector* path ) +void AIUpdateInterface::doQuickExit( std::vector* path ) { Bool locked = getStateMachine()->isLocked(); diff --git a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp index cac797bc77..601173951b 100644 --- a/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp +++ b/GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate/JetAIUpdate.cpp @@ -2402,7 +2402,7 @@ Bool JetAIUpdate::getTreatAsAircraftForLocoDistToGoal() const /** * Follow the path defined by the given array of points */ -void JetAIUpdate::privateFollowPath( const std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) +void JetAIUpdate::privateFollowPath( std::vector* path, Object *ignoreObject, CommandSourceType cmdSource, Bool exitProduction ) { if (exitProduction) {