mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-21 02:11:33 +00:00
extract function onIdleStatePerFrameActions().
This commit is contained in:
parent
b3d5b47fea
commit
5ec310dfba
2 changed files with 39 additions and 30 deletions
|
@ -195,18 +195,10 @@ namespace MWMechanics
|
||||||
|
|
||||||
|
|
||||||
WanderState& wanderState = storage.mState;
|
WanderState& wanderState = storage.mState;
|
||||||
// Check if an idle actor is too close to a door - if so start walking
|
|
||||||
mDoorCheckDuration += duration;
|
if (wanderState == Wander_IdleNow)
|
||||||
if(mDoorCheckDuration >= DOOR_CHECK_INTERVAL)
|
|
||||||
{
|
{
|
||||||
mDoorCheckDuration = 0; // restart timer
|
onIdleStatePerFrameActions(actor, duration, storage);
|
||||||
if(mDistance && // actor is not intended to be stationary
|
|
||||||
(wanderState == Wander_IdleNow) && // but is in idle
|
|
||||||
proximityToDoor(actor, MIN_DIST_TO_DOOR_SQUARED*1.6f*1.6f)) // NOTE: checks interior cells only
|
|
||||||
{
|
|
||||||
wanderState = Wander_MoveNow;
|
|
||||||
mTrimCurrentNode = false; // just in case
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Are we there yet?
|
// Are we there yet?
|
||||||
|
@ -229,29 +221,11 @@ namespace MWMechanics
|
||||||
evadeObstacles(actor, storage, duration);
|
evadeObstacles(actor, storage, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool& rotate = storage.mTurnActorGivingGreetingToFacePlayer;
|
|
||||||
if (rotate)
|
|
||||||
{
|
|
||||||
// Reduce the turning animation glitch by using a *HUGE* value of
|
|
||||||
// epsilon... TODO: a proper fix might be in either the physics or the
|
|
||||||
// animation subsystem
|
|
||||||
if (zTurn(actor, storage.mTargetAngleRadians, osg::DegreesToRadians(5.f)))
|
|
||||||
rotate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if idle animation finished
|
|
||||||
short unsigned& idleAnimation = storage.mIdleAnimation;
|
|
||||||
GreetingState& greetingState = storage.mSaidGreeting;
|
|
||||||
if ((wanderState == Wander_IdleNow) &&
|
|
||||||
!checkIdle(actor, idleAnimation) && (greetingState == Greet_Done || greetingState == Greet_None))
|
|
||||||
{
|
|
||||||
wanderState = Wander_ChooseAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWBase::World *world = MWBase::Environment::get().getWorld();
|
MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||||
|
|
||||||
if (wanderState == Wander_ChooseAction)
|
if (wanderState == Wander_ChooseAction)
|
||||||
{
|
{
|
||||||
|
short unsigned& idleAnimation = storage.mIdleAnimation;
|
||||||
idleAnimation = getRandomIdle();
|
idleAnimation = getRandomIdle();
|
||||||
|
|
||||||
if(!idleAnimation && mDistance)
|
if(!idleAnimation && mDistance)
|
||||||
|
@ -355,6 +329,40 @@ namespace MWMechanics
|
||||||
return false; // AiWander package not yet completed
|
return false; // AiWander package not yet completed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AiWander::onIdleStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage)
|
||||||
|
{
|
||||||
|
// Check if an idle actor is too close to a door - if so start walking
|
||||||
|
mDoorCheckDuration += duration;
|
||||||
|
if (mDoorCheckDuration >= DOOR_CHECK_INTERVAL)
|
||||||
|
{
|
||||||
|
mDoorCheckDuration = 0; // restart timer
|
||||||
|
if (mDistance && // actor is not intended to be stationary
|
||||||
|
proximityToDoor(actor, MIN_DIST_TO_DOOR_SQUARED*1.6f*1.6f)) // NOTE: checks interior cells only
|
||||||
|
{
|
||||||
|
storage.mState = Wander_MoveNow;
|
||||||
|
mTrimCurrentNode = false; // just in case
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool& rotate = storage.mTurnActorGivingGreetingToFacePlayer;
|
||||||
|
if (rotate)
|
||||||
|
{
|
||||||
|
// Reduce the turning animation glitch by using a *HUGE* value of
|
||||||
|
// epsilon... TODO: a proper fix might be in either the physics or the
|
||||||
|
// animation subsystem
|
||||||
|
if (zTurn(actor, storage.mTargetAngleRadians, osg::DegreesToRadians(5.f)))
|
||||||
|
rotate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if idle animation finished
|
||||||
|
GreetingState& greetingState = storage.mSaidGreeting;
|
||||||
|
if (!checkIdle(actor, storage.mIdleAnimation) && (greetingState == Greet_Done || greetingState == Greet_None))
|
||||||
|
{
|
||||||
|
storage.mState = Wander_ChooseAction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration)
|
void AiWander::evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration)
|
||||||
{
|
{
|
||||||
if (mObstacleCheck.check(actor, duration))
|
if (mObstacleCheck.check(actor, duration))
|
||||||
|
|
|
@ -83,6 +83,7 @@ namespace MWMechanics
|
||||||
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration);
|
void evadeObstacles(const MWWorld::Ptr& actor, AiWanderStorage& storage, float duration);
|
||||||
void playIdleDialogueRandomly(const MWWorld::Ptr& actor);
|
void playIdleDialogueRandomly(const MWWorld::Ptr& actor);
|
||||||
void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage);
|
void turnActorToFacePlayer(const osg::Vec3f& actorPosition, const osg::Vec3f& playerPosition, AiWanderStorage& storage);
|
||||||
|
void onIdleStatePerFrameActions(const MWWorld::Ptr& actor, float duration, AiWanderStorage& storage);
|
||||||
|
|
||||||
int mDistance; // how far the actor can wander from the spawn point
|
int mDistance; // how far the actor can wander from the spawn point
|
||||||
int mDuration;
|
int mDuration;
|
||||||
|
|
Loading…
Reference in a new issue