mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-29 18:32:36 +00:00
Merge branch 'ugly_rounding' into 'master'
Prevent floating point issues accumulating See merge request OpenMW/openmw!1306
This commit is contained in:
commit
217d17adeb
@ -1,10 +1,20 @@
|
|||||||
#include "magiceffects.hpp"
|
#include "magiceffects.hpp"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <components/esm/effectlist.hpp>
|
#include <components/esm/effectlist.hpp>
|
||||||
#include <components/esm/magiceffects.hpp>
|
#include <components/esm/magiceffects.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
// Round value to prevent precision issues
|
||||||
|
void truncate(float& value)
|
||||||
|
{
|
||||||
|
value = std::roundf(value * 1024.f) / 1024.f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWMechanics
|
namespace MWMechanics
|
||||||
{
|
{
|
||||||
EffectKey::EffectKey() : mId (0), mArg (-1) {}
|
EffectKey::EffectKey() : mId (0), mArg (-1) {}
|
||||||
@ -74,6 +84,7 @@ namespace MWMechanics
|
|||||||
{
|
{
|
||||||
mModifier += param.mModifier;
|
mModifier += param.mModifier;
|
||||||
mBase += param.mBase;
|
mBase += param.mBase;
|
||||||
|
truncate(mModifier);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,6 +92,7 @@ namespace MWMechanics
|
|||||||
{
|
{
|
||||||
mModifier -= param.mModifier;
|
mModifier -= param.mModifier;
|
||||||
mBase -= param.mBase;
|
mBase -= param.mBase;
|
||||||
|
truncate(mModifier);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user