1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-02-02 00:15:48 +00:00

[Client] Send PlayerPosition packets based on a timeout

This commit is contained in:
David Cernat 2017-05-06 00:59:54 +03:00
parent ef12a37d59
commit 62aa6ed7ea

View file

@ -182,12 +182,25 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate)
static MWMechanics::DynamicStat<float> oldMagicka(ptrCreatureStats->getMagicka()); static MWMechanics::DynamicStat<float> oldMagicka(ptrCreatureStats->getMagicka());
static MWMechanics::DynamicStat<float> oldFatigue(ptrCreatureStats->getFatigue()); static MWMechanics::DynamicStat<float> oldFatigue(ptrCreatureStats->getFatigue());
static float timer = 0; static float statTimer = 0;
const float timeoutSec = 0.5; const float timeoutSec = 0.5;
if ((timer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec || forceUpdate) if (forceUpdate || (statTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{ {
if (oldHealth != health || oldMagicka != magicka || oldFatigue != fatigue || forceUpdate) // 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
bool shouldUpdateHealth = oldHealth != health && (health.getCurrent() == 0 || oldHealth.getCurrent() == 0 || abs(oldHealth.getCurrent() - health.getCurrent()) > 3);
bool shouldUpdateMagicka = false;
bool shouldUpdateFatigue = false;
if (!shouldUpdateHealth)
shouldUpdateMagicka = oldMagicka != magicka && (magicka.getCurrent() == 0 || abs(oldMagicka.getCurrent() - magicka.getCurrent()) > 10);
if (!shouldUpdateMagicka)
shouldUpdateFatigue = oldFatigue != fatigue && (fatigue.getCurrent() == 0 || abs(oldFatigue.getCurrent() - fatigue.getCurrent()) > 10);
if (forceUpdate || shouldUpdateHealth || shouldUpdateMagicka || shouldUpdateFatigue)
{ {
oldHealth = health; oldHealth = health;
oldMagicka = magicka; oldMagicka = magicka;
@ -197,7 +210,7 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate)
magicka.writeState(creatureStats.mDynamic[1]); magicka.writeState(creatureStats.mDynamic[1]);
fatigue.writeState(creatureStats.mDynamic[2]); fatigue.writeState(creatureStats.mDynamic[2]);
timer = 0; statTimer = 0;
getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send();
@ -299,22 +312,24 @@ void LocalPlayer::updateBounty(bool forceUpdate)
void LocalPlayer::updatePosition(bool forceUpdate) void LocalPlayer::updatePosition(bool forceUpdate)
{ {
static float positionTimer = 0;
const float timeoutSec = 0.015;
if (forceUpdate || (positionTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
const MWMechanics::Movement &move = player.getClass().getMovementSettings(player);
static bool posWasChanged = false; static bool posWasChanged = false;
static bool isJumping = false; static bool isJumping = false;
static bool sentJumpEnd = true; static bool sentJumpEnd = true;
ESM::Position ptrPos = player.getRefData().getPosition(); const MWMechanics::Movement &move = player.getClass().getMovementSettings(player);
const bool posIsChanging = (move.mPosition[0] != 0 || move.mPosition[1] != 0 || move.mPosition[2] != 0 bool posIsChanging = (move.mPosition[0] != 0 || move.mPosition[1] != 0 || move.mPosition[2] != 0 ||
|| move.mRotation[0] != 0 || move.mRotation[1] != 0 || move.mRotation[2] != 0); move.mRotation[0] != 0 || move.mRotation[1] != 0 || move.mRotation[2] != 0);
if (posIsChanging || posWasChanged || forceUpdate) if (forceUpdate || posIsChanging || posWasChanged)
{ {
posWasChanged = posIsChanging; posWasChanged = posIsChanging;
@ -323,7 +338,7 @@ void LocalPlayer::updatePosition(bool forceUpdate)
isJumping = true; isJumping = true;
} }
position = ptrPos; position = player.getRefData().getPosition();
direction.pos[0] = move.mPosition[0]; direction.pos[0] = move.mPosition[0];
direction.pos[1] = move.mPosition[1]; direction.pos[1] = move.mPosition[1];
@ -341,10 +356,11 @@ void LocalPlayer::updatePosition(bool forceUpdate)
else if (!sentJumpEnd) else if (!sentJumpEnd)
{ {
sentJumpEnd = true; sentJumpEnd = true;
position = ptrPos; position = player.getRefData().getPosition();
getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->setPlayer(this); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->setPlayer(this);
getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send();
} }
}
} }
void LocalPlayer::updateCell(bool forceUpdate) void LocalPlayer::updateCell(bool forceUpdate)