From 78a26b010876502bf1b9cd5743dc627340122f36 Mon Sep 17 00:00:00 2001 From: AzaezelX Date: Fri, 18 Apr 2025 11:00:13 -0500 Subject: [PATCH] expose a getThrottle for vehicles. save some calcs in AIWheeledVehicleControllerData deletion cleanups --- Engine/source/T3D/AI/AIController.cpp | 37 ++------------------------- Engine/source/T3D/AI/AIController.h | 9 ++++++- Engine/source/T3D/AI/AINavigation.cpp | 8 ++++++ Engine/source/T3D/AI/AINavigation.h | 2 +- Engine/source/T3D/player.cpp | 3 ++- Engine/source/T3D/vehicles/vehicle.h | 1 + 6 files changed, 22 insertions(+), 38 deletions(-) diff --git a/Engine/source/T3D/AI/AIController.cpp b/Engine/source/T3D/AI/AIController.cpp index 8ce21583b..974f5e10a 100644 --- a/Engine/source/T3D/AI/AIController.cpp +++ b/Engine/source/T3D/AI/AIController.cpp @@ -695,42 +695,10 @@ F32 AIWheeledVehicleControllerData::getSteeringAngle(AIController* obj, Point3F steerState = Left; } - - F32 xDiff = obj->getNav()->mMoveDestination.x - location.x; - F32 yDiff = obj->getNav()->mMoveDestination.y - location.y; - Point3F rotation = wvo->getTransform().toEuler(); - Point2F mov; - // Build move direction in world space - if (mIsZero(xDiff)) - mov.y = (location.y > obj->getNav()->mMoveDestination.y) ? -1.0f : 1.0f; - else - { - if (mIsZero(yDiff)) - mov.x = (location.x > obj->getNav()->mMoveDestination.x) ? -1.0f : 1.0f; - else - if (mFabs(xDiff) > mFabs(yDiff)) - { - F32 value = mFabs(yDiff / xDiff); - mov.y = (location.y > obj->getNav()->mMoveDestination.y) ? -value : value; - mov.x = (location.x > obj->getNav()->mMoveDestination.x) ? -1.0f : 1.0f; - } - else - { - F32 value = mFabs(xDiff / yDiff); - mov.x = (location.x > obj->getNav()->mMoveDestination.x) ? -value : value; - mov.y = (location.y > obj->getNav()->mMoveDestination.y) ? -1.0f : 1.0f; - } - } - // Rotate the move into object space (this really only needs - // a 2D matrix) - Point3F throttle; - MatrixF moveMatrix; - moveMatrix.set(EulerF(0.0f, 0.0f, -(rotation.z + steering.x))); - moveMatrix.mulV(Point3F(mov.x, mov.y, 0.0f), &throttle); - F32 turnAdjust = myAngle - steering.x; - if (throttle.y < 0.0f) + F32 throttle = wvo->getThrottle(); + if (throttle < 0.0f) { F32 reverseReduction = 0.25f; if (steerState == Left) @@ -757,7 +725,6 @@ F32 AIWheeledVehicleControllerData::getSteeringAngle(AIController* obj, Point3F break; }; - // Con::printf("AI Steering : %f", steer); return steer; } diff --git a/Engine/source/T3D/AI/AIController.h b/Engine/source/T3D/AI/AIController.h index ccaaf5a35..43c9be04c 100644 --- a/Engine/source/T3D/AI/AIController.h +++ b/Engine/source/T3D/AI/AIController.h @@ -125,7 +125,14 @@ public: mCover = NULL; mMovement.mMoveState = ModeStop; }; - + ~AIController() + { + SAFE_DELETE(mAIInfo); + SAFE_DELETE(mNav); + clearGoal(); + clearAim(); + clearCover(); + } DECLARE_CONOBJECT(AIController); }; diff --git a/Engine/source/T3D/AI/AINavigation.cpp b/Engine/source/T3D/AI/AINavigation.cpp index 57d2be27a..abe6d512a 100644 --- a/Engine/source/T3D/AI/AINavigation.cpp +++ b/Engine/source/T3D/AI/AINavigation.cpp @@ -29,6 +29,14 @@ AINavigation::AINavigation(AIController* controller) mNavSize = Regular; } +AINavigation::~AINavigation() +{ +#ifdef TORQUE_NAVIGATION_ENABLED + clearPath(); + clearFollow(); +#endif +} + NavMesh* AINavigation::findNavMesh() const { GameBase* gbo = dynamic_cast(mControllerRef->getAIInfo()->mObj.getPointer()); diff --git a/Engine/source/T3D/AI/AINavigation.h b/Engine/source/T3D/AI/AINavigation.h index ad9ae6a70..978ae01c6 100644 --- a/Engine/source/T3D/AI/AINavigation.h +++ b/Engine/source/T3D/AI/AINavigation.h @@ -35,7 +35,7 @@ struct AINavigation AINavigation() = delete; AINavigation(AIController* controller); - + ~AINavigation(); /// Stores information about a path. struct PathData { /// Pointer to path object. diff --git a/Engine/source/T3D/player.cpp b/Engine/source/T3D/player.cpp index 00f929742..e48f204e6 100644 --- a/Engine/source/T3D/player.cpp +++ b/Engine/source/T3D/player.cpp @@ -1643,7 +1643,7 @@ Player::Player() mLastAbsoluteYaw = 0.0f; mLastAbsolutePitch = 0.0f; mLastAbsoluteRoll = 0.0f; - + mAIController = NULL; afx_init(); } @@ -1654,6 +1654,7 @@ Player::~Player() delete mShapeFPInstance[i]; mShapeFPInstance[i] = 0; } + if (mAIController) mAIController->deleteObject(); } diff --git a/Engine/source/T3D/vehicles/vehicle.h b/Engine/source/T3D/vehicles/vehicle.h index 52dbb8e68..8c43a6e41 100644 --- a/Engine/source/T3D/vehicles/vehicle.h +++ b/Engine/source/T3D/vehicles/vehicle.h @@ -147,6 +147,7 @@ public: void onRemove() override; Point2F getSteering() { return mSteering; }; + F32 getThrottle() { return mThrottle;}; /// Interpolates between move ticks @see processTick /// @param dt Change in time between the last call and this call to the function void advanceTime(F32 dt) override;