From 689050e1d0fcc3bd661e37fe67a5b28c67dc7219 Mon Sep 17 00:00:00 2001 From: Koncord Date: Tue, 27 Jun 2017 21:01:04 +0800 Subject: [PATCH] [Client] Long expression to lambda --- apps/openmw/mwmp/LocalPlayer.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/openmw/mwmp/LocalPlayer.cpp b/apps/openmw/mwmp/LocalPlayer.cpp index 6486e5148..6b7966702 100644 --- a/apps/openmw/mwmp/LocalPlayer.cpp +++ b/apps/openmw/mwmp/LocalPlayer.cpp @@ -195,11 +195,13 @@ void LocalPlayer::updateStatsDynamic(bool forceUpdate) // 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 shouldUpdateMagicka = oldMagicka != magicka && (magicka.getCurrent() == 0 || abs(oldMagicka.getCurrent() - magicka.getCurrent()) > 10); - bool shouldUpdateFatigue = oldFatigue != fatigue && (fatigue.getCurrent() == 0 || abs(oldFatigue.getCurrent() - fatigue.getCurrent()) > 10); + auto needUpdate = [](MWMechanics::DynamicStat &oldVal, MWMechanics::DynamicStat &newVal, int limit) { + return oldVal != newVal && (newVal.getCurrent() == 0 || oldVal.getCurrent() == 0 + || abs(oldVal.getCurrent() - newVal.getCurrent()) > limit); + }; - if (forceUpdate || shouldUpdateHealth || shouldUpdateMagicka || shouldUpdateFatigue) + if (forceUpdate || needUpdate(oldHealth, health, 5) || needUpdate(oldMagicka, magicka, 10) || + needUpdate(oldFatigue, fatigue, 10)) { oldHealth = health; oldMagicka = magicka;