[Client] Use update timer in mwmp::Cell instead of LocalActor

This commit is contained in:
David Cernat 2017-06-10 03:29:51 +03:00
parent 18bf79e08b
commit 312fc84a6f
4 changed files with 39 additions and 47 deletions

View File

@ -23,11 +23,21 @@ mwmp::Cell::Cell(MWWorld::CellStore* cellStore)
std::map<std::string, LocalActor *> localActors; std::map<std::string, LocalActor *> localActors;
std::map<std::string, DedicatedActor *> dedicatedActors; std::map<std::string, DedicatedActor *> dedicatedActors;
updateTimer = 0;
} }
void Cell::updateLocal(bool forceUpdate) void Cell::updateLocal(bool forceUpdate)
{ {
if (localActors.empty()) return; if (localActors.empty())
return;
const float timeoutSec = 0.025;
if (!forceUpdate && (updateTimer += MWBase::Environment::get().getFrameDuration()) < timeoutSec)
return;
else
updateTimer = 0;
CellController *cellController = Main::get().getCellController(); CellController *cellController = Main::get().getCellController();
ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList(); ActorList *actorList = mwmp::Main::get().getNetworking()->getActorList();

View File

@ -52,6 +52,8 @@ namespace mwmp
std::map<std::string, LocalActor *> localActors; std::map<std::string, LocalActor *> localActors;
std::map<std::string, DedicatedActor *> dedicatedActors; std::map<std::string, DedicatedActor *> dedicatedActors;
float updateTimer;
}; };
} }

View File

@ -31,9 +31,6 @@ LocalActor::LocalActor()
wasForceMoveJumping = false; wasForceMoveJumping = false;
wasFlying = false; wasFlying = false;
positionTimer = 0;
statTimer = 0;
attack.type = Attack::MELEE; attack.type = Attack::MELEE;
attack.shouldSend = false; attack.shouldSend = false;
@ -74,10 +71,6 @@ 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);
@ -88,12 +81,9 @@ void LocalActor::updatePosition(bool forceUpdate)
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)
{ {
@ -167,10 +157,6 @@ void LocalActor::updateStatsDynamic(bool forceUpdate)
MWMechanics::DynamicStat<float> magicka(ptrCreatureStats->getMagicka()); MWMechanics::DynamicStat<float> magicka(ptrCreatureStats->getMagicka());
MWMechanics::DynamicStat<float> fatigue(ptrCreatureStats->getFatigue()); MWMechanics::DynamicStat<float> fatigue(ptrCreatureStats->getFatigue());
const float timeoutSec = 0.5;
if (forceUpdate || (statTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{
// Update stats when they become 0 or they have changed enough // Update stats when they become 0 or they have changed enough
// //
// Also check for an oldHealth of 0 changing to something else for resurrected NPCs // Also check for an oldHealth of 0 changing to something else for resurrected NPCs
@ -196,12 +182,9 @@ void LocalActor::updateStatsDynamic(bool forceUpdate)
creatureStats.mDead = ptrCreatureStats->isDead(); creatureStats.mDead = ptrCreatureStats->isDead();
statTimer = 0;
mwmp::Main::get().getNetworking()->getActorList()->addStatsDynamicActor(*this); mwmp::Main::get().getNetworking()->getActorList()->addStatsDynamicActor(*this);
} }
} }
}
void LocalActor::updateEquipment(bool forceUpdate) void LocalActor::updateEquipment(bool forceUpdate)
{ {

View File

@ -47,9 +47,6 @@ 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;
}; };
} }