Browse Source

expose a getThrottle for vehicles. save some calcs in AIWheeledVehicleControllerData
deletion cleanups

AzaezelX 8 months ago
parent
commit
78a26b0108

+ 2 - 35
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;
 }

+ 8 - 1
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);
 };
 

+ 8 - 0
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<GameBase*>(mControllerRef->getAIInfo()->mObj.getPointer());

+ 1 - 1
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.

+ 2 - 1
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();
 }
 
 

+ 1 - 0
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;