1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-06-20 14:41:36 +00:00

[Client] Limiting updates to ~64 per second

This commit is contained in:
Koncord 2017-06-02 21:20:35 +08:00
parent c2600bac8e
commit ad873e16b8
2 changed files with 73 additions and 81 deletions

View file

@ -71,6 +71,12 @@ MWWorld::Ptr LocalPlayer::getPlayerPtr()
void LocalPlayer::update() void LocalPlayer::update()
{ {
static float updateTimer = 0;
const float timeoutSec = 0.015;
if ((updateTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{
updateTimer = 0;
updateCell(); updateCell();
updatePosition(); updatePosition();
updateAnimFlags(); updateAnimFlags();
@ -83,6 +89,7 @@ void LocalPlayer::update()
updateLevel(); updateLevel();
updateBounty(); updateBounty();
} }
}
void LocalPlayer::charGen(int stageFirst, int stageEnd) void LocalPlayer::charGen(int stageFirst, int stageEnd)
{ {
@ -182,12 +189,7 @@ 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 statTimer = 0;
const float timeoutSec = 0.5;
if (forceUpdate || (statTimer += MWBase::Environment::get().getFrameDuration()) >= timeoutSec)
{
statTimer = 0;
// Update stats when they become 0 or they have changed enough // Update stats when they become 0 or they have changed enough
bool shouldUpdateHealth = oldHealth != health && (health.getCurrent() == 0 || abs(oldHealth.getCurrent() - health.getCurrent()) > 3); bool shouldUpdateHealth = oldHealth != health && (health.getCurrent() == 0 || abs(oldHealth.getCurrent() - health.getCurrent()) > 3);
bool shouldUpdateMagicka = false; bool shouldUpdateMagicka = false;
@ -213,7 +215,6 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate)
getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_STATS_DYNAMIC)->Send();
} }
} }
}
void LocalPlayer::updateAttributes(bool forceUpdate) void LocalPlayer::updateAttributes(bool forceUpdate)
{ {
@ -309,12 +310,6 @@ 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)
{
positionTimer = 0;
MWBase::World *world = MWBase::Environment::get().getWorld(); MWBase::World *world = MWBase::Environment::get().getWorld();
MWWorld::Ptr player = world->getPlayerPtr(); MWWorld::Ptr player = world->getPlayerPtr();
@ -356,7 +351,6 @@ void LocalPlayer::updatePosition(bool forceUpdate)
getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send(); getNetworking()->getPlayerPacket(ID_PLAYER_POSITION)->Send();
} }
} }
}
void LocalPlayer::updateCell(bool forceUpdate) void LocalPlayer::updateCell(bool forceUpdate)
{ {

View file

@ -15,7 +15,5 @@ PacketPlayerStatsDynamic::PacketPlayerStatsDynamic(RakNet::RakPeerInterface *pee
void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send) void PacketPlayerStatsDynamic::Packet(RakNet::BitStream *bs, bool send)
{ {
PlayerPacket::Packet(bs, send); PlayerPacket::Packet(bs, send);
RW(player->creatureStats.mDynamic[0], send); // health RW(player->creatureStats.mDynamic, send);
RW(player->creatureStats.mDynamic[1], send); // magic
RW(player->creatureStats.mDynamic[2], send); // fatigue
} }