Working Pausing and Resuming

This commit is contained in:
David Markowitz 2023-08-07 00:44:57 -07:00
parent 6a5ff30a32
commit aa734ef7ae
2 changed files with 34 additions and 2 deletions

View File

@ -25,6 +25,7 @@ namespace {
MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : Component(parent) { MovementAIComponent::MovementAIComponent(Entity* parent, MovementAIInfo info) : Component(parent) {
m_Info = info; m_Info = info;
m_IsPaused = true;
m_AtFinalWaypoint = true; m_AtFinalWaypoint = true;
m_BaseCombatAI = nullptr; m_BaseCombatAI = nullptr;
@ -70,8 +71,8 @@ void MovementAIComponent::Update(const float deltaTime) {
return; return;
} }
// Are we done? // Are we done or paused?
if (AtFinalWaypoint()) return; if (AtFinalWaypoint() || IsPaused()) return;
if (m_HaltDistance > 0) { if (m_HaltDistance > 0) {
// Prevent us from hugging the target // Prevent us from hugging the target
@ -207,6 +208,25 @@ bool MovementAIComponent::Warp(const NiPoint3& point) {
return true; return true;
} }
void MovementAIComponent::Pause() {
if (AtFinalWaypoint() || IsPaused()) return;
SetPosition(ApproximateLocation());
SetVelocity(NiPoint3::ZERO);
// Clear this as we may be somewhere else when we resume movement.
m_InterpolatedWaypoints.clear();
m_IsPaused = true;
m_PathIndex = 0;
m_TimeToTravel = 0;
m_TimeTravelled = 0;
}
void MovementAIComponent::Resume() {
if (AtFinalWaypoint() || !IsPaused()) return;
m_IsPaused = false;
SetDestination(GetCurrentPathWaypoint());
}
void MovementAIComponent::Stop() { void MovementAIComponent::Stop() {
if (AtFinalWaypoint()) return; if (AtFinalWaypoint()) return;
@ -363,6 +383,7 @@ void MovementAIComponent::SetDestination(const NiPoint3& destination) {
m_TimeToTravel = 0; m_TimeToTravel = 0;
m_AtFinalWaypoint = false; m_AtFinalWaypoint = false;
m_IsPaused = false;
} }
NiPoint3 MovementAIComponent::GetDestination() const { NiPoint3 MovementAIComponent::GetDestination() const {

View File

@ -173,6 +173,12 @@ public:
*/ */
bool AtFinalWaypoint() const { return m_AtFinalWaypoint; } bool AtFinalWaypoint() const { return m_AtFinalWaypoint; }
bool IsPaused() const { return m_IsPaused; }
void Pause();
void Resume();
/** /**
* Renders the entity stationary * Renders the entity stationary
*/ */
@ -322,6 +328,11 @@ private:
* Whether or not the path is being read in reverse * Whether or not the path is being read in reverse
*/ */
bool m_IsInReverse; bool m_IsInReverse;
/**
* Whether or not the current movement via pathing is paused.
*/
bool m_IsPaused;
}; };
#endif // MOVEMENTAICOMPONENT_H #endif // MOVEMENTAICOMPONENT_H