1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-01 09:32:40 +00:00

Changed more hardcoded RefId to be static to avoid multiple runtime creations

adresses multiple review comments
This commit is contained in:
fteppe 2022-10-13 23:14:00 +02:00 committed by florent.teppe
parent b57dd6d083
commit 7da38113be
25 changed files with 65 additions and 52 deletions

View File

@ -273,7 +273,7 @@ namespace MWBase
* @param id Identifier for the GMST setting, e.g. "aName" * @param id Identifier for the GMST setting, e.g. "aName"
* @param default Default value if the GMST setting cannot be used. * @param default Default value if the GMST setting cannot be used.
*/ */
virtual std::string_view getGameSettingString(const std::string_view& id, std::string_view default_) = 0; virtual std::string_view getGameSettingString(std::string_view id, std::string_view default_) = 0;
virtual void processChangedSettings(const std::set<std::pair<std::string, std::string>>& changed) = 0; virtual void processChangedSettings(const std::set<std::pair<std::string, std::string>>& changed) = 0;

View File

@ -121,25 +121,25 @@ namespace MWClass
const ESM::RefId& Clothing::getUpSoundId(const MWWorld::ConstPtr& ptr) const const ESM::RefId& Clothing::getUpSoundId(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>(); const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
static ESM::RefId sound; static const ESM::RefId ringUp = ESM::RefId::stringRefId("Item Ring Up");
static const ESM::RefId clothsUp = ESM::RefId::stringRefId("Item Clothes Up");
if (ref->mBase->mData.mType == 8) if (ref->mBase->mData.mType == 8)
{ {
sound = ESM::RefId::stringRefId("Item Ring Up"); return ringUp;
} }
sound = ESM::RefId::stringRefId("Item Clothes Up"); return clothsUp;
return sound;
} }
const ESM::RefId& Clothing::getDownSoundId(const MWWorld::ConstPtr& ptr) const const ESM::RefId& Clothing::getDownSoundId(const MWWorld::ConstPtr& ptr) const
{ {
const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>(); const MWWorld::LiveCellRef<ESM::Clothing>* ref = ptr.get<ESM::Clothing>();
static ESM::RefId sound; static const ESM::RefId ringDown = ESM::RefId::stringRefId("Item Ring Down");
static const ESM::RefId clothsDown = ESM::RefId::stringRefId("Item Clothes Down");
if (ref->mBase->mData.mType == 8) if (ref->mBase->mData.mType == 8)
{ {
sound = ESM::RefId::stringRefId("Item Ring Down"); return ringDown;
} }
sound = ESM::RefId::stringRefId("Item Clothes Down"); return clothsDown;
return sound;
} }
const std::string& Clothing::getInventoryIcon(const MWWorld::ConstPtr& ptr) const const std::string& Clothing::getInventoryIcon(const MWWorld::ConstPtr& ptr) const

View File

@ -9,6 +9,7 @@
#include <components/esm3/loadsoun.hpp> #include <components/esm3/loadsoun.hpp>
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <components/settings/settings.hpp> #include <components/settings/settings.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwmechanics/actorutil.hpp" #include "../mwmechanics/actorutil.hpp"
#include "../mwmechanics/aisetting.hpp" #include "../mwmechanics/aisetting.hpp"
@ -448,7 +449,7 @@ namespace MWClass
MWBase::Environment::get().getWorld()->spawnBloodEffect(ptr, hitPosition); MWBase::Environment::get().getWorld()->spawnBloodEffect(ptr, hitPosition);
} }
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); MWBase::Environment::get().getSoundManager()->playSound3D(ptr, ESM::sHealthDamageSoundId, 1.0f, 1.0f);
MWMechanics::DynamicStat<float> health(stats.getHealth()); MWMechanics::DynamicStat<float> health(stats.getHealth());
health.setCurrent(health.getCurrent() - damage); health.setCurrent(health.getCurrent() - damage);

View File

@ -113,8 +113,8 @@ namespace MWClass
const ESM::RefId& openSound = ref->mBase->mOpenSound; const ESM::RefId& openSound = ref->mBase->mOpenSound;
const ESM::RefId& closeSound = ref->mBase->mCloseSound; const ESM::RefId& closeSound = ref->mBase->mCloseSound;
const ESM::RefId lockedSound = ESM::RefId::stringRefId("LockedDoor"); static const ESM::RefId lockedSound = ESM::RefId::stringRefId("LockedDoor");
const ESM::RefId trapActivationSound = ESM::RefId::stringRefId("Disarm Trap Fail"); static const ESM::RefId trapActivationSound = ESM::RefId::stringRefId("Disarm Trap Fail");
// FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors // FIXME: If NPC activate teleporting door, it can lead to crash due to iterator invalidation in the Actors
// update. Make such activation a no-op for now, like how it is in the vanilla game. // update. Make such activation a no-op for now, like how it is in the vanilla game.

View File

@ -113,20 +113,21 @@ namespace MWClass
const ESM::RefId& Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const const ESM::RefId& Miscellaneous::getUpSoundId(const MWWorld::ConstPtr& ptr) const
{ {
static ESM::RefId sound; static const ESM::RefId soundGold = ESM::RefId::stringRefId("Item Gold Up");
static const ESM::RefId soundMisc = ESM::RefId::stringRefId("Item Misc Up");
if (isGold(ptr)) if (isGold(ptr))
sound = ESM::RefId::stringRefId("Item Gold Up"); return soundGold;
sound = ESM::RefId::stringRefId("Item Misc Up");
return sound; return soundMisc;
} }
const ESM::RefId& Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const const ESM::RefId& Miscellaneous::getDownSoundId(const MWWorld::ConstPtr& ptr) const
{ {
static ESM::RefId sound; static const ESM::RefId soundGold = ESM::RefId::stringRefId("Item Gold Down");
static const ESM::RefId soundMisc = ESM::RefId::stringRefId("Item Misc Down");
if (isGold(ptr)) if (isGold(ptr))
sound = ESM::RefId::stringRefId("Item Gold Down"); return soundGold;
sound = ESM::RefId::stringRefId("Item Misc Down"); return soundMisc;
return sound;
} }
const std::string& Miscellaneous::getInventoryIcon(const MWWorld::ConstPtr& ptr) const const std::string& Miscellaneous::getInventoryIcon(const MWWorld::ConstPtr& ptr) const
@ -184,19 +185,19 @@ namespace MWClass
{ {
int goldAmount = getValue(ptr) * count; int goldAmount = getValue(ptr) * count;
std::string_view base = "Gold_001"; const ESM::RefId* base = &ESM::sGoldId001;
if (goldAmount >= 100) if (goldAmount >= 100)
base = "Gold_100"; base = &ESM::sGoldId100;
else if (goldAmount >= 25) else if (goldAmount >= 25)
base = "Gold_025"; base = &ESM::sGoldId025;
else if (goldAmount >= 10) else if (goldAmount >= 10)
base = "Gold_010"; base = &ESM::sGoldId010;
else if (goldAmount >= 5) else if (goldAmount >= 5)
base = "Gold_005"; base = &ESM::sGoldId005;
// Really, I have no idea why moving ref out of conditional // Really, I have no idea why moving ref out of conditional
// scope causes list::push_back throwing std::bad_alloc // scope causes list::push_back throwing std::bad_alloc
MWWorld::ManualRef newRef(store, ESM::RefId::stringRefId(base)); MWWorld::ManualRef newRef(store, *base);
const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = newRef.getPtr().get<ESM::Miscellaneous>(); const MWWorld::LiveCellRef<ESM::Miscellaneous>* ref = newRef.getPtr().get<ESM::Miscellaneous>();
newPtr = MWWorld::Ptr(cell.insert(ref), &cell); newPtr = MWWorld::Ptr(cell.insert(ref), &cell);

View File

@ -9,6 +9,7 @@
#include <components/misc/rng.hpp> #include <components/misc/rng.hpp>
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm3/loadbody.hpp> #include <components/esm3/loadbody.hpp>
#include <components/esm3/loadclas.hpp> #include <components/esm3/loadclas.hpp>
#include <components/esm3/loadmgef.hpp> #include <components/esm3/loadmgef.hpp>
@ -892,7 +893,7 @@ namespace MWClass
if (damage > 0.0f) if (damage > 0.0f)
{ {
sndMgr->playSound3D(ptr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); sndMgr->playSound3D(ptr, ESM::sHealthDamageSoundId, 1.0f, 1.0f);
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
MWBase::Environment::get().getWindowManager()->activateHitOverlay(); MWBase::Environment::get().getWindowManager()->activateHitOverlay();
if (!attacker.isEmpty()) if (!attacker.isEmpty())

View File

@ -84,7 +84,7 @@ bool MWDialogue::Filter::testActor(const ESM::DialInfo& info) const
// actor id // actor id
if (!info.mActor.empty()) if (!info.mActor.empty())
{ {
if (!(info.mActor == mActor.getCellRef().getRefId())) if (info.mActor != mActor.getCellRef().getRefId())
return false; return false;
} }
else if (isCreature) else if (isCreature)

View File

@ -38,7 +38,7 @@ namespace MWDialogue
mEntries.push_back(entry); mEntries.push_back(entry);
} }
ESM::RefId Topic::getTopic() const const ESM::RefId& Topic::getTopic() const
{ {
return mTopic; return mTopic;
} }

View File

@ -42,7 +42,7 @@ namespace MWDialogue
///< Add entry without checking for redundant entries or modifying the state of the ///< Add entry without checking for redundant entries or modifying the state of the
/// topic otherwise /// topic otherwise
ESM::RefId getTopic() const; const ESM::RefId& getTopic() const;
virtual std::string_view getName() const; virtual std::string_view getName() const;

View File

@ -551,7 +551,7 @@ namespace MWGui
unsigned combat = mGenerateClassSpecializations[0]; unsigned combat = mGenerateClassSpecializations[0];
unsigned magic = mGenerateClassSpecializations[1]; unsigned magic = mGenerateClassSpecializations[1];
unsigned stealth = mGenerateClassSpecializations[2]; unsigned stealth = mGenerateClassSpecializations[2];
std::string className; std::string_view className;
if (combat > 7) if (combat > 7)
{ {
className = "Warrior"; className = "Warrior";

View File

@ -376,7 +376,7 @@ namespace MWGui
setFactions(PCstats.getFactionRanks()); setFactions(PCstats.getFactionRanks());
setExpelled(PCstats.getExpelled()); setExpelled(PCstats.getExpelled());
auto signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign(); const auto& signId = MWBase::Environment::get().getWorld()->getPlayer().getBirthSign();
setBirthSign(signId); setBirthSign(signId);
setReputation(PCstats.getReputation()); setReputation(PCstats.getReputation());

View File

@ -90,7 +90,7 @@ namespace MWGui
else else
toAdd->setUserString("interior", "n"); toAdd->setUserString("interior", "n");
std::string nameString = name.getRefIdString(); const std::string& nameString = name.getRefIdString();
toAdd->setUserString("price", std::to_string(price)); toAdd->setUserString("price", std::to_string(price));
toAdd->setCaptionWithReplacing("#{sCell=" + nameString + "} - " + MyGUI::utility::toString(price) + "#{sgp}"); toAdd->setCaptionWithReplacing("#{sCell=" + nameString + "} - " + MyGUI::utility::toString(price) + "#{sgp}");
toAdd->setSize(mDestinationsView->getWidth(), lineHeight); toAdd->setSize(mDestinationsView->getWidth(), lineHeight);

View File

@ -21,6 +21,7 @@
#include <sstream> #include <sstream>
#include <components/esm/refidhardcoded.hpp>
#include <components/esm/records.hpp> #include <components/esm/records.hpp>
#include <components/misc/mathutil.hpp> #include <components/misc/mathutil.hpp>
#include <components/misc/resourcehelpers.hpp> #include <components/misc/resourcehelpers.hpp>
@ -2137,7 +2138,7 @@ namespace MWMechanics
float realHealthLost = healthLost * (1.0f - 0.25f * fatigueTerm); float realHealthLost = healthLost * (1.0f - 0.25f * fatigueTerm);
health.setCurrent(health.getCurrent() - realHealthLost); health.setCurrent(health.getCurrent() - realHealthLost);
cls.getCreatureStats(mPtr).setHealth(health); cls.getCreatureStats(mPtr).setHealth(health);
sndMgr->playSound3D(mPtr, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); sndMgr->playSound3D(mPtr, ESM::sHealthDamageSoundId, 1.0f, 1.0f);
if (isPlayer) if (isPlayer)
MWBase::Environment::get().getWindowManager()->activateHitOverlay(); MWBase::Environment::get().getWindowManager()->activateHitOverlay();
} }

View File

@ -9,6 +9,7 @@
#include <components/esm3/loadench.hpp> #include <components/esm3/loadench.hpp>
#include <components/esm3/loadmgef.hpp> #include <components/esm3/loadmgef.hpp>
#include <components/esm3/loadsoun.hpp> #include <components/esm3/loadsoun.hpp>
#include <components/esm/refidhardcoded.hpp>
#include "../mwbase/environment.hpp" #include "../mwbase/environment.hpp"
#include "../mwbase/mechanicsmanager.hpp" #include "../mwbase/mechanicsmanager.hpp"
@ -382,7 +383,7 @@ namespace MWMechanics
health.setCurrent(health.getCurrent() - x); health.setCurrent(health.getCurrent() - x);
attackerStats.setHealth(health); attackerStats.setHealth(health);
MWBase::Environment::get().getSoundManager()->playSound3D(attacker, ESM::RefId::stringRefId("Health Damage"), 1.0f, 1.0f); MWBase::Environment::get().getSoundManager()->playSound3D(attacker, ESM::sHealthDamageSoundId, 1.0f, 1.0f);
} }
} }

View File

@ -914,7 +914,8 @@ namespace MWMechanics
return false; return false;
// A special case for evidence chest - we should not allow to take items even if it is technically permitted // A special case for evidence chest - we should not allow to take items even if it is technically permitted
return !(cellref.getRefId() == ESM::RefId::stringRefId("stolen_goods")); static const ESM::RefId stolenGoods = ESM::RefId::stringRefId("stolen_goods");
return !(cellref.getRefId() == stolenGoods);
} }
bool MechanicsManager::sleepInBed(const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed) bool MechanicsManager::sleepInBed(const MWWorld::Ptr& ptr, const MWWorld::Ptr& bed)

View File

@ -97,7 +97,7 @@ namespace MWMechanics
MWBase::Environment::get().getWindowManager()->messageBox(message); MWBase::Environment::get().getWindowManager()->messageBox(message);
ESM::RefId soulGemAzura = ESM::RefId::stringRefId("Misc_SoulGem_Azura"); static const ESM::RefId soulGemAzura = ESM::RefId::stringRefId("Misc_SoulGem_Azura");
// special case: readd Azura's Star // special case: readd Azura's Star
if (gem.get<ESM::Miscellaneous>()->mBase->mId == soulGemAzura) if (gem.get<ESM::Miscellaneous>()->mBase->mId == soulGemAzura)
player.getClass().getContainerStore(player).add(soulGemAzura, 1, player); player.getClass().getContainerStore(player).add(soulGemAzura, 1, player);

View File

@ -191,9 +191,9 @@ namespace MWScript
ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger)); ESM::RefId item = ESM::RefId::stringRefId(runtime.getStringLiteral(runtime[0].mInteger));
runtime.pop(); runtime.pop();
if (item == ESM::RefId::stringRefId("gold_005") ||item == ESM::RefId::stringRefId("gold_010") if (item == ESM::sGoldId005 || item == ESM::sGoldId010
|| item == ESM::RefId::stringRefId("gold_025") ||item == ESM::RefId::stringRefId("gold_100")) || item == ESM::sGoldId025 || item == ESM::sGoldId100)
item = ESM::RefId::stringRefId("gold_001"); item = ESM::sGoldId001;
MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr); MWWorld::ContainerStore& store = ptr.getClass().getContainerStore(ptr);
@ -222,9 +222,9 @@ namespace MWScript
if (count == 0) if (count == 0)
return; return;
if (item == ESM::RefId::stringRefId("gold_005") || item == ESM::RefId::stringRefId("gold_010") if (item == ESM::sGoldId005 || item == ESM::sGoldId010
|| item == ESM::RefId::stringRefId("gold_025") || item == ESM::RefId::stringRefId("gold_100")) || item == ESM::sGoldId025 || item == ESM::sGoldId100)
item = ESM::RefId::stringRefId("gold_001"); item = ESM::sGoldId001;
// Explicit calls to non-unique actors affect the base record // Explicit calls to non-unique actors affect the base record
if (!R::implicit && ptr.getClass().isActor() if (!R::implicit && ptr.getClass().isActor()

View File

@ -293,7 +293,8 @@ namespace MWWorld
// NOTE: Don't show WerewolfRobe objects in the inventory, or allow them to be taken. // NOTE: Don't show WerewolfRobe objects in the inventory, or allow them to be taken.
// Vanilla likely uses a hack like this since there's no other way to prevent it from // Vanilla likely uses a hack like this since there's no other way to prevent it from
// being shown or taken. // being shown or taken.
return (ptr.getCellRef().getRefId() != ESM::RefId::stringRefId("werewolfrobe")); static const ESM::RefId werewolfrobe = ESM::RefId::stringRefId("werewolfrobe");
return (ptr.getCellRef().getRefId() != werewolfrobe);
} }
bool Class::hasToolTip(const ConstPtr& ptr) const bool Class::hasToolTip(const ConstPtr& ptr) const

View File

@ -6,6 +6,7 @@
#include <components/debug/debuglog.hpp> #include <components/debug/debuglog.hpp>
#include <components/esm3/inventorystate.hpp> #include <components/esm3/inventorystate.hpp>
#include <components/esm3/loadench.hpp> #include <components/esm3/loadench.hpp>
#include <components/esm/refidhardcoded.hpp>
#include <components/misc/strings/algorithm.hpp> #include <components/misc/strings/algorithm.hpp>
#include <components/misc/strings/lower.hpp> #include <components/misc/strings/lower.hpp>
#include <components/sceneutil/positionattitudetransform.hpp> #include <components/sceneutil/positionattitudetransform.hpp>
@ -137,7 +138,7 @@ void MWWorld::ContainerStore::storeStates(
} }
} }
const ESM::RefId MWWorld::ContainerStore::sGoldId = ESM::RefId::stringRefId("gold_001"); const ESM::RefId MWWorld::ContainerStore::sGoldId = ESM::sGoldId001;
MWWorld::ContainerStore::ContainerStore() MWWorld::ContainerStore::ContainerStore()
: mListener(nullptr) : mListener(nullptr)

View File

@ -435,7 +435,7 @@ namespace MWWorld
else else
mStatic.insert(it, std::move(land)); mStatic.insert(it, std::move(land));
return RecordId(ESM::RefId::stringRefId(""), isDeleted); return RecordId(ESM::RefId::sEmpty, isDeleted);
} }
void Store<ESM::Land>::setUp() void Store<ESM::Land>::setUp()
{ {

View File

@ -2635,7 +2635,7 @@ namespace MWWorld
if (actor == getPlayerPtr()) if (actor == getPlayerPtr())
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
auto healthDamage = ESM::RefId::stringRefId("Health Damage"); auto healthDamage = ESM::sHealthDamageSoundId;
if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor,healthDamage)) if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor,healthDamage))
MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f); MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f);
} }
@ -2669,7 +2669,7 @@ namespace MWWorld
if (actor == getPlayerPtr()) if (actor == getPlayerPtr())
MWBase::Environment::get().getWindowManager()->activateHitOverlay(false); MWBase::Environment::get().getWindowManager()->activateHitOverlay(false);
auto healthDamage = ESM::RefId::stringRefId("Health Damage"); auto healthDamage = ESM::sHealthDamageSoundId;
if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor, healthDamage )) if (!MWBase::Environment::get().getSoundManager()->getSoundPlaying(actor, healthDamage ))
MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f); MWBase::Environment::get().getSoundManager()->playSound3D(actor, healthDamage, 1.0f, 1.0f);
} }

View File

@ -26,7 +26,7 @@ namespace ESM
return newRefId; return newRefId;
} }
const RefId RefId::sEmpty = RefId::stringRefId(""); const RefId RefId::sEmpty = {};
} }

View File

@ -10,6 +10,7 @@ namespace ESM
const RefId sGoldId010 = ESM::RefId::stringRefId("gold_010"); const RefId sGoldId010 = ESM::RefId::stringRefId("gold_010");
const RefId sGoldId025 = ESM::RefId::stringRefId("gold_025"); const RefId sGoldId025 = ESM::RefId::stringRefId("gold_025");
const RefId sGoldId100 = ESM::RefId::stringRefId("gold_100"); const RefId sGoldId100 = ESM::RefId::stringRefId("gold_100");
const RefId sHealthDamageSoundId = ESM::RefId::stringRefId("Health Damage");
} }

View File

@ -4,7 +4,7 @@
namespace ESM namespace ESM
{ {
extern const RefId sPlayerId, sMenuClickSoundId, sBookPageSoundId; extern const RefId sPlayerId, sMenuClickSoundId, sBookPageSoundId, sHealthDamageSoundId;
extern const RefId sGoldId001, sGoldId005, sGoldId010, sGoldId025, sGoldId100; extern const RefId sGoldId001, sGoldId005, sGoldId010, sGoldId025, sGoldId100;
} }

View File

@ -160,8 +160,12 @@ std::string Misc::ResourceHelpers::correctSoundPath(std::string_view resPath, co
bool Misc::ResourceHelpers::isHiddenMarker(const ESM::RefId& id) bool Misc::ResourceHelpers::isHiddenMarker(const ESM::RefId& id)
{ {
return id == ESM::RefId::stringRefId("prisonmarker") ||id == ESM::RefId::stringRefId("divinemarker") static const ESM::RefId prisonMarker = ESM::RefId::stringRefId("prisonmarker");
|| id == ESM::RefId::stringRefId("templemarker") || id == ESM::RefId::stringRefId("northmarker"); static const ESM::RefId divineMarker = ESM::RefId::stringRefId("divinemarker");
static const ESM::RefId templeMarker = ESM::RefId::stringRefId("templemarker");
static const ESM::RefId northMarker = ESM::RefId::stringRefId("northmarker");
return id == prisonMarker || id == divineMarker || id == templeMarker || id == northMarker;
} }
namespace namespace