[Client] Send ActorPosition packets based on a timeout

This commit is contained in:
David Cernat 2017-05-06 00:33:48 +03:00
parent db3859565b
commit ef12a37d59
2 changed files with 16 additions and 7 deletions

View file

@ -28,6 +28,7 @@ LocalActor::LocalActor()
wasForceMoveJumping = false; wasForceMoveJumping = false;
wasFlying = false; wasFlying = false;
positionTimer = 0;
statTimer = 0; statTimer = 0;
attack.type = Attack::MELEE; attack.type = Attack::MELEE;
@ -62,19 +63,26 @@ void LocalActor::updateCell()
} }
void LocalActor::updatePosition(bool forceUpdate) void LocalActor::updatePosition(bool forceUpdate)
{
const float timeoutSec = 0.03;
if (forceUpdate || (positionTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{ {
bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || direction.pos[2] != 0 || bool posIsChanging = (direction.pos[0] != 0 || direction.pos[1] != 0 || direction.pos[2] != 0 ||
direction.rot[0] != 0 || direction.rot[1] != 0 || direction.rot[2] != 0); direction.rot[0] != 0 || direction.rot[1] != 0 || direction.rot[2] != 0);
if (posIsChanging || posWasChanged || forceUpdate) if (forceUpdate || posIsChanging || posWasChanged)
{ {
posWasChanged = posIsChanging; posWasChanged = posIsChanging;
position = ptr.getRefData().getPosition(); position = ptr.getRefData().getPosition();
positionTimer = 0;
mwmp::Main::get().getNetworking()->getActorList()->addPositionActor(*this); mwmp::Main::get().getNetworking()->getActorList()->addPositionActor(*this);
} }
} }
}
void LocalActor::updateAnimFlags(bool forceUpdate) void LocalActor::updateAnimFlags(bool forceUpdate)
{ {
@ -183,7 +191,6 @@ void LocalActor::updateStatsDynamic(bool forceUpdate)
statTimer = 0; statTimer = 0;
mwmp::Main::get().getNetworking()->getActorList()->addStatsDynamicActor(*this); mwmp::Main::get().getNetworking()->getActorList()->addStatsDynamicActor(*this);
LOG_MESSAGE_SIMPLE(Log::LOG_INFO, "Updating stats for %s-%i-%i: %f, %f, %f", refId.c_str(), refNumIndex, mpNum, health.getCurrent(), magicka.getCurrent(), fatigue.getCurrent());
} }
} }
} }

View file

@ -45,6 +45,8 @@ namespace mwmp
MWMechanics::DynamicStat<float> oldHealth; MWMechanics::DynamicStat<float> oldHealth;
MWMechanics::DynamicStat<float> oldMagicka; MWMechanics::DynamicStat<float> oldMagicka;
MWMechanics::DynamicStat<float> oldFatigue; MWMechanics::DynamicStat<float> oldFatigue;
float positionTimer;
float statTimer; float statTimer;
}; };
} }