1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Use lambda instead of bool to make sure GMST initialized once

This is less expensive than having 2 static variables and thread-safe.
This commit is contained in:
elsid 2020-06-14 17:43:30 +02:00
parent a854a6e04a
commit 68ed8487b5
No known key found for this signature in database
GPG Key ID: B845CB9FEE18AB40
2 changed files with 12 additions and 10 deletions

View File

@ -82,12 +82,13 @@ namespace MWClass
const Creature::GMST& Creature::getGmst()
{
static GMST gmst;
static bool inited = false;
if (!inited)
static const GMST gmst = []
{
GMST gmst;
const MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::Store<ESM::GameSetting> &store = world->getStore().get<ESM::GameSetting>();
gmst.fMinWalkSpeedCreature = store.find("fMinWalkSpeedCreature");
gmst.fMaxWalkSpeedCreature = store.find("fMaxWalkSpeedCreature");
gmst.fEncumberedMoveEffect = store.find("fEncumberedMoveEffect");
@ -101,8 +102,9 @@ namespace MWClass
gmst.fKnockDownMult = store.find("fKnockDownMult");
gmst.iKnockDownOddsMult = store.find("iKnockDownOddsMult");
gmst.iKnockDownOddsBase = store.find("iKnockDownOddsBase");
inited = true;
}
return gmst;
} ();
return gmst;
}

View File

@ -266,10 +266,10 @@ namespace MWClass
const Npc::GMST& Npc::getGmst()
{
static GMST gmst;
static bool inited = false;
if(!inited)
static const GMST gmst = []
{
GMST gmst;
const MWBase::World *world = MWBase::Environment::get().getWorld();
const MWWorld::Store<ESM::GameSetting> &store = world->getStore().get<ESM::GameSetting>();
@ -294,8 +294,8 @@ namespace MWClass
gmst.iKnockDownOddsBase = store.find("iKnockDownOddsBase");
gmst.fCombatArmorMinMult = store.find("fCombatArmorMinMult");
inited = true;
}
return gmst;
} ();
return gmst;
}