expose a getThrottle for vehicles. save some calcs in AIWheeledVehicleControllerData

deletion cleanups
This commit is contained in:
AzaezelX 2025-04-18 11:00:13 -05:00
parent 2d5e8c1560
commit 78a26b0108
6 changed files with 22 additions and 38 deletions

View file

@ -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;
}

View file

@ -125,7 +125,14 @@ public:
mCover = NULL;
mMovement.mMoveState = ModeStop;
};
~AIController()
{
SAFE_DELETE(mAIInfo);
SAFE_DELETE(mNav);
clearGoal();
clearAim();
clearCover();
}
DECLARE_CONOBJECT(AIController);
};

View file

@ -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());

View file

@ -35,7 +35,7 @@ struct AINavigation
AINavigation() = delete;
AINavigation(AIController* controller);
~AINavigation();
/// Stores information about a path.
struct PathData {
/// Pointer to path object.

View file

@ -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();
}

View file

@ -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;