Merge branch 'string_viewing' into 'master'

Use string_view in yet more places

See merge request OpenMW/openmw!2348
crashfix_debugdraw
psi29a 2 years ago
commit 4ff7f8ddfb

@ -164,7 +164,7 @@ bool Launcher::AdvancedPage::loadSettings()
// Audio
{
std::string selectedAudioDevice = Settings::Manager::getString("device", "Sound");
const std::string& selectedAudioDevice = Settings::Manager::getString("device", "Sound");
if (selectedAudioDevice.empty() == false)
{
int audioDeviceIndex = audioDeviceSelectorComboBox->findData(QString::fromStdString(selectedAudioDevice));
@ -178,7 +178,7 @@ bool Launcher::AdvancedPage::loadSettings()
{
enableHRTFComboBox->setCurrentIndex(hrtfEnabledIndex + 1);
}
std::string selectedHRTFProfile = Settings::Manager::getString("hrtf", "Sound");
const std::string& selectedHRTFProfile = Settings::Manager::getString("hrtf", "Sound");
if (selectedHRTFProfile.empty() == false)
{
int hrtfProfileIndex = hrtfProfileSelectorComboBox->findData(QString::fromStdString(selectedHRTFProfile));
@ -323,7 +323,7 @@ void Launcher::AdvancedPage::saveSettings()
// Audio
{
int audioDeviceIndex = audioDeviceSelectorComboBox->currentIndex();
std::string prevAudioDevice = Settings::Manager::getString("device", "Sound");
const std::string& prevAudioDevice = Settings::Manager::getString("device", "Sound");
if (audioDeviceIndex != 0)
{
const std::string& newAudioDevice = audioDeviceSelectorComboBox->currentText().toUtf8().constData();
@ -340,7 +340,7 @@ void Launcher::AdvancedPage::saveSettings()
Settings::Manager::setInt("hrtf enable", "Sound", hrtfEnabledIndex);
}
int selectedHRTFProfileIndex = hrtfProfileSelectorComboBox->currentIndex();
std::string prevHRTFProfile = Settings::Manager::getString("hrtf", "Sound");
const std::string& prevHRTFProfile = Settings::Manager::getString("hrtf", "Sound");
if (selectedHRTFProfileIndex != 0)
{
const std::string& newHRTFProfile = hrtfProfileSelectorComboBox->currentText().toUtf8().constData();

@ -49,7 +49,7 @@ namespace CSMPrefs
{
if (mButton)
{
std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
const std::string& shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
int modifier;
State::get().getShortcutManager().convertFromString(shortcut, modifier);

@ -55,7 +55,7 @@ namespace CSMPrefs
{
if (mButton)
{
std::string shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
const std::string& shortcut = Settings::Manager::getString(getKey(), getParent()->getKey());
QKeySequence sequence;
State::get().getShortcutManager().convertFromString(shortcut, sequence);

@ -629,7 +629,7 @@ std::vector<std::pair<int,std::string>>CSMWorld::Columns::getEnums (ColumnId col
{
for (int i=0; i<8; i++)
{
const std::string& bloodName = Fallback::Map::getString("Blood_Texture_Name_" + std::to_string(i));
std::string_view bloodName = Fallback::Map::getString("Blood_Texture_Name_" + std::to_string(i));
if (!bloodName.empty())
enums.emplace_back(i, bloodName);
}

@ -162,8 +162,9 @@ namespace CSVRender
mWaterGeometry->setStateSet(SceneUtil::createSimpleWaterStateSet(Alpha, RenderBin));
// Add water texture
std::string textureName = Fallback::Map::getString("Water_SurfaceTexture");
textureName = "textures/water/" + textureName + "00.dds";
std::string textureName = "textures/water/";
textureName += Fallback::Map::getString("Water_SurfaceTexture");
textureName += "00.dds";
Resource::ImageManager* imageManager = mData.getResourceSystem()->getImageManager();

@ -850,7 +850,7 @@ void OMW::Engine::prepareEngine()
if (!mSkipMenu)
{
const std::string& logo = Fallback::Map::getString("Movies_Company_Logo");
std::string_view logo = Fallback::Map::getString("Movies_Company_Logo");
if (!logo.empty())
mWindowManager->playVideo(logo, true);
}
@ -1069,7 +1069,7 @@ void OMW::Engine::go()
// start in main menu
mWindowManager->pushGuiMode (MWGui::GM_MainMenu);
mSoundManager->playTitleMusic();
const std::string& logo = Fallback::Map::getString("Movies_Morrowind_Logo");
std::string_view logo = Fallback::Map::getString("Movies_Morrowind_Logo");
if (!logo.empty())
mWindowManager->playVideo(logo, /*allowSkipping*/true, /*overrideSounds*/false);
}

@ -108,7 +108,7 @@ namespace MWBase
/// @note This method will block until the video finishes playing
/// (and will continually update the window while doing so)
virtual void playVideo(const std::string& name, bool allowSkipping, bool overrideSounds = true) = 0;
virtual void playVideo(std::string_view name, bool allowSkipping, bool overrideSounds = true) = 0;
virtual void setNewGame(bool newgame) = 0;

@ -163,7 +163,7 @@ namespace MWClass
text += "\n#{sType} ";
int skill = MWMechanics::getWeaponType(ref->mBase->mData.mType)->mSkill;
const std::string type = ESM::Skill::sSkillNameIds[skill];
const std::string& type = ESM::Skill::sSkillNameIds[skill];
std::string_view oneOrTwoHanded;
if (weaponType->mWeaponClass == ESM::WeaponType::Melee)
{

@ -45,10 +45,10 @@ namespace
{
number++;
std::string question = Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_Question");
std::string answer0 = Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerOne");
std::string answer1 = Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerTwo");
std::string answer2 = Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerThree");
std::string question{Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_Question")};
std::string answer0{Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerOne")};
std::string answer1{Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerTwo")};
std::string answer2{Fallback::Map::getString("Question_" + MyGUI::utility::toString(number) + "_AnswerThree")};
std::string sound = "vo\\misc\\chargen qa" + MyGUI::utility::toString(number) + ".wav";
Response r0 = {answer0, ESM::Class::Combat};

@ -768,8 +768,8 @@ namespace MWGui
if (!Settings::Manager::getBool("color topic enable", "GUI"))
return;
std::string specialColour = Settings::Manager::getString("color topic specific", "GUI");
std::string oldColour = Settings::Manager::getString("color topic exhausted", "GUI");
const std::string& specialColour = Settings::Manager::getString("color topic specific", "GUI");
const std::string& oldColour = Settings::Manager::getString("color topic exhausted", "GUI");
for (const std::string& keyword : mKeywords)
{

@ -393,7 +393,7 @@ namespace MWGui
const ESM::Spell* spell =
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
std::string spellName = spell->mName;
const std::string& spellName = spell->mName;
if (spellName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;
@ -463,7 +463,7 @@ namespace MWGui
void HUD::unsetSelectedSpell()
{
std::string spellName = "#{sNone}";
std::string_view spellName = "#{sNone}";
if (spellName != mSpellName && mSpellVisible)
{
mWeaponSpellTimer = 5.0f;

@ -791,7 +791,7 @@ namespace MWGui
int incr = next ? 1 : -1;
bool found = false;
std::string lastId;
std::string_view lastId;
if (selected != -1)
lastId = model.getItem(selected).mBase.getCellRef().getRefId();
ItemModel::ModelIndex cycled = selected;

@ -18,6 +18,7 @@
#include "../mwmechanics/actorutil.hpp"
#include "class.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -138,13 +139,13 @@ namespace MWGui
int level = creatureStats.getLevel ()+1;
mLevelText->setCaptionWithReplacing("#{sLevelUpMenu1} " + MyGUI::utility::toString(level));
std::string levelupdescription;
std::string_view levelupdescription;
levelupdescription = Fallback::Map::getString("Level_Up_Level"+MyGUI::utility::toString(level));
if (levelupdescription == "")
if (levelupdescription.empty())
levelupdescription = Fallback::Map::getString("Level_Up_Default");
mLevelDescription->setCaption (levelupdescription);
mLevelDescription->setCaption(toUString(levelupdescription));
unsigned int availableAttributes = 0;
for (int i = 0; i < 8; ++i)

@ -93,7 +93,7 @@ namespace MWGui
{
MWBase::WindowManager *winMgr = MWBase::Environment::get().getWindowManager();
std::string name = *sender->getUserData<std::string>();
const std::string& name = *sender->getUserData<std::string>();
winMgr->playSound("Menu Click");
if (name == "return")
{

@ -287,16 +287,16 @@ namespace MWGui
while (mConfigArea->getChildCount() > 0)
MyGUI::Gui::getInstance().destroyWidget(mConfigArea->getChildAt(0));
mShaderInfo->setCaption("");
mShaderInfo->setCaption({});
std::ostringstream ss;
const std::string NA = "#{Interface:NotAvailableShort}";
const std::string endl = "\n";
const std::string_view NA = "#{Interface:NotAvailableShort}";
const char endl = '\n';
std::string author = technique->getAuthor().empty() ? NA : std::string(technique->getAuthor());
std::string version = technique->getVersion().empty() ? NA : std::string(technique->getVersion());
std::string description = technique->getDescription().empty() ? NA : std::string(technique->getDescription());
std::string_view author = technique->getAuthor().empty() ? NA : technique->getAuthor();
std::string_view version = technique->getVersion().empty() ? NA : technique->getVersion();
std::string_view description = technique->getDescription().empty() ? NA : technique->getDescription();
auto serializeBool = [](bool value) {
return value ? "#{sYes}" : "#{sNo}";

@ -68,7 +68,7 @@ void Recharge::updateView()
{
MWWorld::Ptr gem = *mGemIcon->getUserData<MWWorld::Ptr>();
std::string soul = gem.getCellRef().getSoul();
const std::string& soul = gem.getCellRef().getSoul();
const ESM::Creature *creature = MWBase::Environment::get().getWorld()->getStore().get<ESM::Creature>().find(soul);
mChargeLabel->setCaptionWithReplacing("#{sCharges} " + MyGUI::utility::toString(creature->mData.mSoul));

@ -30,6 +30,7 @@
#include "../mwstate/character.hpp"
#include "confirmationdialog.hpp"
#include "ustring.hpp"
namespace MWGui
{
@ -176,7 +177,7 @@ namespace MWGui
// For a custom class, we will not find it in the store (unless we loaded the savegame first).
// Fall back to name stored in savegame header in that case.
std::string className;
std::string_view className;
if (it->getSignature().mPlayerClassId.empty())
className = it->getSignature().mPlayerClassName;
else
@ -190,7 +191,7 @@ namespace MWGui
className = "?"; // From an older savegame format that did not support custom classes properly.
}
title << " (#{sLevel} " << it->getSignature().mPlayerLevel << " " << MyGUI::TextIterator::toTagsString(className) << ")";
title << " (#{sLevel} " << it->getSignature().mPlayerLevel << " " << MyGUI::TextIterator::toTagsString(toUString(className)) << ")";
mCharacterSelection->addItem (MyGUI::LanguageManager::getInstance().replaceTags(title.str()));

@ -238,7 +238,7 @@ namespace MWGui
, mCurrentPage(-1)
{
bool terrain = Settings::Manager::getBool("distant terrain", "Terrain");
const std::string widgetName = terrain ? "RenderingDistanceSlider" : "LargeRenderingDistanceSlider";
const std::string_view widgetName = terrain ? "RenderingDistanceSlider" : "LargeRenderingDistanceSlider";
MyGUI::Widget* unusedSlider;
getWidget(unusedSlider, widgetName);
unusedSlider->setVisible(false);
@ -338,7 +338,7 @@ namespace MWGui
}
highlightCurrentResolution();
std::string tmip = Settings::Manager::getString("texture mipmap", "General");
const std::string& tmip = Settings::Manager::getString("texture mipmap", "General");
mTextureFilteringButton->setCaptionWithReplacing(textureMipmappingToStr(tmip));
int waterTextureSize = Settings::Manager::getInt("rtt size", "Water");

@ -34,10 +34,7 @@ namespace MWGui
bool SpellBuyingWindow::sortSpells (const ESM::Spell* left, const ESM::Spell* right)
{
std::string leftName = Misc::StringUtils::lowerCase(left->mName);
std::string rightName = Misc::StringUtils::lowerCase(right->mName);
return leftName.compare(rightName) < 0;
return Misc::StringUtils::ciLess(left->mName, right->mName);
}
void SpellBuyingWindow::addSpell(const ESM::Spell& spell)

@ -555,7 +555,7 @@ namespace MWGui
for (const short effectId : knownEffects)
{
std::string name = MWBase::Environment::get().getWorld ()->getStore ().get<ESM::GameSetting>().find(
const std::string& name = MWBase::Environment::get().getWorld ()->getStore ().get<ESM::GameSetting>().find(
ESM::MagicEffect::effectIdToString(effectId))->mValue.getString();
MyGUI::Widget* w = mAvailableEffectsList->getItemWidget(name);

@ -149,7 +149,7 @@ namespace MWGui
image->setImageTexture(Misc::ResourceHelpers::correctIconPath(effect->mIcon,
MWBase::Environment::get().getResourceSystem()->getVFS()));
std::string name = ESM::MagicEffect::effectIdToString (effectId);
const std::string& name = ESM::MagicEffect::effectIdToString(effectId);
ToolTipInfo tooltipInfo;
tooltipInfo.caption = "#{" + name + "}";

@ -147,7 +147,7 @@ namespace MWGui
MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find(spellId);
MWWorld::Ptr player = MWMechanics::getPlayer();
std::string raceId = player.get<ESM::NPC>()->mBase->mRace;
const std::string& raceId = player.get<ESM::NPC>()->mBase->mRace;
const ESM::Race* race = MWBase::Environment::get().getWorld()->getStore().get<ESM::Race>().find(raceId);
// can't delete racial spells, birthsign spells or powers
bool isInherent = race->mPowers.exists(spell->mId) || spell->mData.mType == ESM::Spell::ST_Power;

@ -400,9 +400,9 @@ namespace MWGui
else
mDynamicToolTipBox->changeWidgetSkin(MWBase::Environment::get().getWindowManager()->isGuiMode() ? "HUD_Box_NoTransp" : "HUD_Box");
std::string caption = info.caption;
std::string image = info.icon;
int imageSize = (image != "") ? info.imageSize : 0;
const std::string& caption = info.caption;
const std::string& image = info.icon;
int imageSize = (!image.empty()) ? info.imageSize : 0;
std::string text = info.text;
// remove the first newline (easier this way)
@ -411,7 +411,7 @@ namespace MWGui
const ESM::Enchantment* enchant = nullptr;
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
if (info.enchant != "")
if (!info.enchant.empty())
{
enchant = store.get<ESM::Enchantment>().search(info.enchant);
if (enchant)
@ -432,8 +432,8 @@ namespace MWGui
const MyGUI::IntPoint padding(8, 8);
const int imageCaptionHPadding = (caption != "" ? 8 : 0);
const int imageCaptionVPadding = (caption != "" ? 4 : 0);
const int imageCaptionHPadding = !caption.empty() ? 8 : 0;
const int imageCaptionVPadding = !caption.empty() ? 4 : 0;
const int maximumWidth = MyGUI::RenderManager::getInstance().getViewSize().width - imageCaptionHPadding * 2;
@ -446,7 +446,7 @@ namespace MWGui
captionWidget->setCaptionWithReplacing(caption);
MyGUI::IntSize captionSize = captionWidget->getTextSize();
int captionHeight = std::max(caption != "" ? captionSize.height : 0, imageSize);
int captionHeight = std::max(!caption.empty() ? captionSize.height : 0, imageSize);
Gui::EditBox* textWidget = mDynamicToolTipBox->createWidget<Gui::EditBox>("SandText", MyGUI::IntCoord(0, captionHeight+imageCaptionVPadding, 300, 300-captionHeight-imageCaptionVPadding), MyGUI::Align::Stretch, "ToolTipText");
textWidget->setEditStatic(true);
@ -458,8 +458,8 @@ namespace MWGui
MyGUI::IntSize textSize = textWidget->getTextSize();
captionSize += MyGUI::IntSize(imageSize, 0); // adjust for image
MyGUI::IntSize totalSize = MyGUI::IntSize( std::min(std::max(textSize.width,captionSize.width + ((image != "") ? imageCaptionHPadding : 0)),maximumWidth),
((text != "") ? textSize.height + imageCaptionVPadding : 0) + captionHeight );
MyGUI::IntSize totalSize = MyGUI::IntSize( std::min(std::max(textSize.width,captionSize.width + ((!image.empty()) ? imageCaptionHPadding : 0)),maximumWidth),
(!text.empty() ? textSize.height + imageCaptionVPadding : 0) + captionHeight );
for (const std::string& note : info.notes)
{
@ -578,7 +578,7 @@ namespace MWGui
textWidget->setPosition (textWidget->getPosition() + MyGUI::IntPoint(0, padding.top)); // only apply vertical padding, the horizontal works automatically due to Align::HCenter
if (image != "")
if (!image.empty())
{
MyGUI::ImageBox* imageWidget = mDynamicToolTipBox->createWidget<MyGUI::ImageBox>("ImageBox",
MyGUI::IntCoord((totalSize.width - captionSize.width - imageCaptionHPadding)/2, 0, imageSize, imageSize),
@ -611,7 +611,7 @@ namespace MWGui
std::string ToolTips::getWeightString(const float weight, const std::string& prefix)
{
if (weight == 0)
return "";
return {};
else
return "\n" + prefix + ": " + toString(weight);
}
@ -619,7 +619,7 @@ namespace MWGui
std::string ToolTips::getPercentString(const float value, const std::string& prefix)
{
if (value == 0)
return "";
return {};
else
return "\n" + prefix + ": " + toString(value*100) +"%";
}
@ -627,15 +627,15 @@ namespace MWGui
std::string ToolTips::getValueString(const int value, const std::string& prefix)
{
if (value == 0)
return "";
return {};
else
return "\n" + prefix + ": " + toString(value);
}
std::string ToolTips::getMiscString(const std::string& text, const std::string& prefix)
{
if (text == "")
return "";
if (text.empty())
return {};
else
return "\n" + prefix + ": " + text;
}
@ -643,7 +643,7 @@ namespace MWGui
std::string ToolTips::getCountString(const int value)
{
if (value == 1)
return "";
return {};
else
return " (" + MyGUI::utility::toString(value) + ")";
}
@ -652,11 +652,11 @@ namespace MWGui
{
const std::string& soul = cellref.getSoul();
if (soul.empty())
return std::string();
return {};
const MWWorld::ESMStore &store = MWBase::Environment::get().getWorld()->getStore();
const ESM::Creature *creature = store.get<ESM::Creature>().search(soul);
if (!creature)
return std::string();
return {};
if (creature->mName.empty())
return " (" + creature->mId + ")";
return " (" + creature->mName + ")";
@ -677,7 +677,7 @@ namespace MWGui
if (cellref.getFactionRank() >= 0)
{
int rank = cellref.getFactionRank();
const std::string rankName = fact->mRanks[rank];
const std::string& rankName = fact->mRanks[rank];
if (rankName.empty())
ret += getValueString(cellref.getFactionRank(), "Rank");
else
@ -802,9 +802,9 @@ namespace MWGui
if (attributeId == -1)
return;
std::string icon = ESM::Attribute::sAttributeIcons[attributeId];
std::string name = ESM::Attribute::sGmstAttributeIds[attributeId];
std::string desc = ESM::Attribute::sGmstAttributeDescIds[attributeId];
const std::string& icon = ESM::Attribute::sAttributeIcons[attributeId];
const std::string& name = ESM::Attribute::sGmstAttributeIds[attributeId];
const std::string& desc = ESM::Attribute::sGmstAttributeDescIds[attributeId];
widget->setUserString("ToolTipType", "Layout");
widget->setUserString("ToolTipLayout", "AttributeToolTip");
@ -850,12 +850,9 @@ namespace MWGui
widget->setUserString("ToolTipType", "Layout");
widget->setUserString("ToolTipLayout", "BirthSignToolTip");
widget->setUserString("ImageTexture_BirthSignImage", Misc::ResourceHelpers::correctTexturePath(sign->mTexture, vfs));
std::string text;
std::string text = sign->mName + "\n#{fontcolourhtml=normal}" + sign->mDescription;
text += sign->mName;
text += "\n#{fontcolourhtml=normal}" + sign->mDescription;
std::vector<std::string> abilities, powers, spells;
std::vector<const ESM::Spell*> abilities, powers, spells;
for (const std::string& spellId : sign->mPowers.mList)
{
@ -867,35 +864,27 @@ namespace MWGui
continue; // We only want spell, ability and powers.
if (type == ESM::Spell::ST_Ability)
abilities.push_back(spellId);
abilities.push_back(spell);
else if (type == ESM::Spell::ST_Power)
powers.push_back(spellId);
powers.push_back(spell);
else if (type == ESM::Spell::ST_Spell)
spells.push_back(spellId);
}
struct {
const std::vector<std::string> &spells;
std::string label;
spells.push_back(spell);
}
categories[3] = {
{abilities, "sBirthsignmenu1"},
{powers, "sPowers"},
{spells, "sBirthsignmenu2"}
};
for (int category = 0; category < 3; ++category)
using Category = std::pair<const std::vector<const ESM::Spell*>&, std::string_view>;
for (const auto&[category, label] : std::initializer_list<Category>{{abilities, "sBirthsignmenu1"}, {powers, "sPowers"}, {spells, "sBirthsignmenu2"}})
{
bool addHeader = true;
for (const std::string& spellId : categories[category].spells)
for (const ESM::Spell* spell : category)
{
if (addHeader)
{
text += std::string("\n\n#{fontcolourhtml=header}") + std::string("#{") + categories[category].label + "}";
text += "\n\n#{fontcolourhtml=header}#{";
text += label;
text += '}';
addHeader = false;
}
const ESM::Spell *spell = store.get<ESM::Spell>().find(spellId);
text += "\n#{fontcolourhtml=normal}" + spell->mName;
}
}

@ -1806,9 +1806,9 @@ namespace MWGui
&& (!isGuiMode() || (mGuiModes.size() == 1 && (getMode() == GM_MainMenu || getMode() == GM_Rest)));
}
void WindowManager::playVideo(const std::string &name, bool allowSkipping, bool overrideSounds)
void WindowManager::playVideo(std::string_view name, bool allowSkipping, bool overrideSounds)
{
mVideoWidget->playVideo("video\\" + name);
mVideoWidget->playVideo("video\\" + std::string{name});
mVideoWidget->eventKeyButtonPressed.clear();
mVideoBackground->eventKeyButtonPressed.clear();

@ -149,7 +149,7 @@ namespace MWGui
/// @note This method will block until the video finishes playing
/// (and will continually update the window while doing so)
void playVideo(const std::string& name, bool allowSkipping, bool overrideSounds = true) override;
void playVideo(std::string_view name, bool allowSkipping, bool overrideSounds = true) override;
/// Warning: do not use MyGUI::InputManager::setKeyFocusWidget directly. Instead use this.
void setKeyFocusWidget (MyGUI::Widget* widget) override;

@ -300,7 +300,7 @@ void MWMechanics::AiPackage::openDoors(const MWWorld::Ptr& actor)
return;
}
const std::string keyId = door.getCellRef().getKey();
const std::string& keyId = door.getCellRef().getKey();
if (keyId.empty())
return;

@ -60,8 +60,7 @@ namespace MWMechanics
actor.getClass().getCreatureStats(actor).getSpells().add(spell);
MWBase::Environment::get().getWorld()->applyLoopingParticles(actor);
std::string msg = "sMagicContractDisease";
msg = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find(msg)->mValue.getString();
std::string msg = MWBase::Environment::get().getWorld()->getStore().get<ESM::GameSetting>().find("sMagicContractDisease")->mValue.getString();
msg = Misc::StringUtils::format(msg, spell->mName);
MWBase::Environment::get().getWindowManager()->messageBox(msg);
}

@ -27,7 +27,7 @@ EffectManager::~EffectManager()
clear();
}
void EffectManager::addEffect(const std::string &model, const std::string& textureOverride, const osg::Vec3f &worldPosition, float scale, bool isMagicVFX)
void EffectManager::addEffect(const std::string& model, std::string_view textureOverride, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX)
{
osg::ref_ptr<osg::Node> node = mResourceSystem->getSceneManager()->getInstance(model);

@ -33,7 +33,7 @@ namespace MWRender
~EffectManager();
/// Add an effect. When it's finished playing, it will be removed automatically.
void addEffect (const std::string& model, const std::string& textureOverride, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX = true);
void addEffect(const std::string& model, std::string_view textureOverride, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX = true);
void update(float dt);

@ -514,7 +514,7 @@ void NpcAnimation::updateNpcBase()
if(!is1stPerson)
{
const std::string base = Settings::Manager::getString("xbaseanim", "Models");
const std::string& base = Settings::Manager::getString("xbaseanim", "Models");
if (smodel != base && !isWerewolf)
addAnimSource(base, smodel);
@ -528,7 +528,7 @@ void NpcAnimation::updateNpcBase()
}
else
{
const std::string base = Settings::Manager::getString("xbaseanim1st", "Models");
const std::string& base = Settings::Manager::getString("xbaseanim1st", "Models");
if (smodel != base && !isWerewolf)
addAnimSource(base, smodel);

@ -493,9 +493,9 @@ namespace MWRender
mEffectManager = std::make_unique<EffectManager>(sceneRoot, mResourceSystem);
const std::string normalMapPattern = Settings::Manager::getString("normal map pattern", "Shaders");
const std::string heightMapPattern = Settings::Manager::getString("normal height map pattern", "Shaders");
const std::string specularMapPattern = Settings::Manager::getString("terrain specular map pattern", "Shaders");
const std::string& normalMapPattern = Settings::Manager::getString("normal map pattern", "Shaders");
const std::string& heightMapPattern = Settings::Manager::getString("normal height map pattern", "Shaders");
const std::string& specularMapPattern = Settings::Manager::getString("terrain specular map pattern", "Shaders");
const bool useTerrainNormalMaps = Settings::Manager::getBool("auto use terrain normal maps", "Shaders");
const bool useTerrainSpecularMaps = Settings::Manager::getBool("auto use terrain specular maps", "Shaders");
@ -1174,7 +1174,7 @@ namespace MWRender
mActorsPaths->updatePtr(old, updated);
}
void RenderingManager::spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale, bool isMagicVFX)
void RenderingManager::spawnEffect(const std::string& model, std::string_view texture, const osg::Vec3f& worldPosition, float scale, bool isMagicVFX)
{
mEffectManager->addEffect(model, texture, worldPosition, scale, isMagicVFX);
}

@ -184,7 +184,7 @@ namespace MWRender
SkyManager* getSkyManager();
void spawnEffect(const std::string &model, const std::string &texture, const osg::Vec3f &worldPosition, float scale = 1.f, bool isMagicVFX = true);
void spawnEffect(const std::string& model, std::string_view texture, const osg::Vec3f& worldPosition, float scale = 1.f, bool isMagicVFX = true);
/// Clear all savegame-specific data
void clear();

@ -34,7 +34,7 @@ namespace
if (rippleFrameCount <= 0)
return;
const std::string& tex = Fallback::Map::getString("Water_RippleTexture");
std::string_view tex = Fallback::Map::getString("Water_RippleTexture");
std::vector<osg::ref_ptr<osg::Texture2D> > textures;
for (int i=0; i<rippleFrameCount; ++i)

@ -587,7 +587,7 @@ void Water::createSimpleWaterStateSet(osg::Node* node, float alpha)
// Add animated textures
std::vector<osg::ref_ptr<osg::Texture2D> > textures;
const int frameCount = std::clamp(Fallback::Map::getInt("Water_SurfaceFrameCount"), 0, 320);
const std::string& texture = Fallback::Map::getString("Water_SurfaceTexture");
std::string_view texture = Fallback::Map::getString("Water_SurfaceTexture");
for (int i=0; i<frameCount; ++i)
{
std::ostringstream texname;
@ -734,7 +734,7 @@ Water::~Water()
void Water::listAssetsToPreload(std::vector<std::string> &textures)
{
const int frameCount = std::clamp(Fallback::Map::getInt("Water_SurfaceFrameCount"), 0, 320);
const std::string& texture = Fallback::Map::getString("Water_SurfaceTexture");
std::string_view texture = Fallback::Map::getString("Water_SurfaceTexture");
for (int i=0; i<frameCount; ++i)
{
std::ostringstream texname;

@ -210,7 +210,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override
{
std::string name{runtime.getStringLiteral(runtime[0].mInteger)};
std::string_view name = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop();
bool allowSkipping = runtime[0].mInteger != 0;

@ -96,12 +96,12 @@ namespace MWSound
return;
}
std::string hrtfname = Settings::Manager::getString("hrtf", "Sound");
const std::string& hrtfname = Settings::Manager::getString("hrtf", "Sound");
int hrtfstate = Settings::Manager::getInt("hrtf enable", "Sound");
HrtfMode hrtfmode = hrtfstate < 0 ? HrtfMode::Auto :
hrtfstate > 0 ? HrtfMode::Enable : HrtfMode::Disable;
std::string devname = Settings::Manager::getString("device", "Sound");
const std::string& devname = Settings::Manager::getString("device", "Sound");
if(!mOutput->init(devname, hrtfname, hrtfmode))
{
Log(Debug::Error) << "Failed to initialize audio output, sound disabled";

@ -30,7 +30,7 @@ namespace MWWorld
}
const auto& target = getTarget();
const std::string targetSoul = target.getCellRef().getSoul();
const std::string& targetSoul = target.getCellRef().getSoul();
if (targetSoul.empty())
{

@ -137,7 +137,7 @@ void MWWorld::ContainerStore::storeStates (const CellRefList<T>& collection,
}
}
const std::string MWWorld::ContainerStore::sGoldId = "gold_001";
const std::string_view MWWorld::ContainerStore::sGoldId = "gold_001";
MWWorld::ContainerStore::ContainerStore()
: mListener(nullptr)

@ -90,7 +90,7 @@ namespace MWWorld
static constexpr int Type_All = 0xffff;
static const std::string sGoldId;
static const std::string_view sGoldId;
protected:
ContainerStoreListener* mListener;

@ -271,7 +271,7 @@ namespace MWWorld
if (!bypass)
{
const std::string& video = Fallback::Map::getString("Movies_New_Game");
std::string_view video = Fallback::Map::getString("Movies_New_Game");
if (!video.empty())
MWBase::Environment::get().getWindowManager()->playVideo(video, true);
}
@ -3713,12 +3713,12 @@ namespace MWWorld
if (ptr == getPlayerPtr() && Settings::Manager::getBool("hit fader", "GUI"))
return;
std::string texture = Fallback::Map::getString("Blood_Texture_" + std::to_string(ptr.getClass().getBloodTexture(ptr)));
std::string_view texture = Fallback::Map::getString("Blood_Texture_" + std::to_string(ptr.getClass().getBloodTexture(ptr)));
if (texture.empty())
texture = Fallback::Map::getString("Blood_Texture_0");
std::string model = Misc::ResourceHelpers::correctMeshPath(
Fallback::Map::getString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3))), // [0, 2]
std::string{Fallback::Map::getString("Blood_Model_" + std::to_string(Misc::Rng::rollDice(3)))}, // [0, 2]
mResourceSystem->getVFS());
mRendering->spawnEffect(model, texture, worldPosition, 1.0f, false);

@ -6,29 +6,31 @@
namespace Fallback
{
std::map<std::string,std::string> Map::mFallbackMap;
std::map<std::string, std::string, std::less<>> Map::mFallbackMap;
void Map::init(const std::map<std::string,std::string>& fallback)
{
mFallbackMap = fallback;
for(const auto& entry : fallback)
mFallbackMap.insert(entry);
}
std::string Map::getString(const std::string& fall)
std::string_view Map::getString(std::string_view fall)
{
std::map<std::string,std::string>::const_iterator it;
if ((it = mFallbackMap.find(fall)) == mFallbackMap.end())
auto it = mFallbackMap.find(fall);
if (it == mFallbackMap.end())
{
return std::string();
return {};
}
return it->second;
}
float Map::getFloat(const std::string& fall)
float Map::getFloat(std::string_view fall)
{
const std::string& fallback = getString(fall);
std::string_view fallback = getString(fall);
if (!fallback.empty())
{
std::stringstream stream(fallback);
std::stringstream stream;
stream << fallback;
float number = 0.f;
stream >> number;
return number;
@ -37,12 +39,13 @@ namespace Fallback
return 0;
}
int Map::getInt(const std::string& fall)
int Map::getInt(std::string_view fall)
{
const std::string& fallback = getString(fall);
std::string_view fallback = getString(fall);
if (!fallback.empty())
{
std::stringstream stream(fallback);
std::stringstream stream;
stream << fallback;
int number = 0;
stream >> number;
return number;
@ -51,15 +54,15 @@ namespace Fallback
return 0;
}
bool Map::getBool(const std::string& fall)
bool Map::getBool(std::string_view fall)
{
const std::string& fallback = getString(fall);
std::string_view fallback = getString(fall);
return !fallback.empty() && fallback != "0";
}
osg::Vec4f Map::getColour(const std::string& fall)
osg::Vec4f Map::getColour(std::string_view fall)
{
const std::string& sum = getString(fall);
std::string_view sum = getString(fall);
if (!sum.empty())
{
try

@ -3,6 +3,7 @@
#include <map>
#include <string>
#include <string_view>
#include <osg/Vec4f>
@ -11,15 +12,15 @@ namespace Fallback
/// @brief contains settings imported from the Morrowind INI file.
class Map
{
static std::map<std::string,std::string> mFallbackMap;
static std::map<std::string, std::string, std::less<>> mFallbackMap;
public:
static void init(const std::map<std::string,std::string>& fallback);
static std::string getString(const std::string& fall);
static float getFloat(const std::string& fall);
static int getInt(const std::string& fall);
static bool getBool(const std::string& fall);
static osg::Vec4f getColour(const std::string& fall);
static std::string_view getString(std::string_view fall);
static float getFloat(std::string_view fall);
static int getInt(std::string_view fall);
static bool getBool(std::string_view fall);
static osg::Vec4f getColour(std::string_view fall);
};
}
#endif

@ -212,8 +212,8 @@ namespace Gui
void FontLoader::loadFonts()
{
std::string defaultFont = Fallback::Map::getString("Fonts_Font_0");
std::string scrollFont = Fallback::Map::getString("Fonts_Font_2");
std::string defaultFont{Fallback::Map::getString("Fonts_Font_0")};
std::string scrollFont{Fallback::Map::getString("Fonts_Font_2")};
loadFont(defaultFont, "DefaultFont");
loadFont(scrollFont, "ScrollFont");
loadFont("DejaVuLGCSansMono", "MonoFont"); // We need to use a TrueType monospace font to display debug texts properly.

@ -4,7 +4,7 @@
namespace SceneUtil
{
std::string getActorSkeleton(bool firstPerson, bool isFemale, bool isBeast, bool isWerewolf)
const std::string& getActorSkeleton(bool firstPerson, bool isFemale, bool isBeast, bool isWerewolf)
{
if (!firstPerson)
{

@ -5,7 +5,7 @@
namespace SceneUtil
{
std::string getActorSkeleton(bool firstPerson, bool female, bool beast, bool werewolf);
const std::string& getActorSkeleton(bool firstPerson, bool female, bool beast, bool werewolf);
}
#endif

@ -814,7 +814,7 @@ namespace SceneUtil
return;
}
std::string lightingMethodString = Settings::Manager::getString("lighting method", "Shaders");
const std::string& lightingMethodString = Settings::Manager::getString("lighting method", "Shaders");
auto lightingMethod = LightManager::getLightingMethodFromString(lightingMethodString);
static bool hasLoggedWarnings = false;

@ -43,10 +43,10 @@ namespace SceneUtil
mShadowSettings->setMinimumShadowMapNearFarRatio(Settings::Manager::getFloat("minimum lispsm near far ratio", "Shadows"));
std::string computeSceneBounds = Settings::Manager::getString("compute scene bounds", "Shadows");
if (Misc::StringUtils::lowerCase(computeSceneBounds) == "primitives")
const std::string& computeSceneBounds = Settings::Manager::getString("compute scene bounds", "Shadows");
if (Misc::StringUtils::ciEqual(computeSceneBounds, "primitives"))
mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_PRIMITIVES);
else if (Misc::StringUtils::lowerCase(computeSceneBounds) == "bounds")
else if (Misc::StringUtils::ciEqual(computeSceneBounds, "bounds"))
mShadowSettings->setComputeNearFarModeOverride(osg::CullSettings::COMPUTE_NEAR_FAR_USING_BOUNDING_VOLUMES);
int mapres = Settings::Manager::getInt("shadow map resolution", "Shadows");

@ -71,7 +71,7 @@ void Manager::saveUser(const std::string &file)
parser.saveSettingsFile(file, mUserSettings);
}
std::string Manager::getString(std::string_view setting, std::string_view category)
const std::string& Manager::getString(std::string_view setting, std::string_view category)
{
const auto key = std::make_pair(category, setting);
CategorySettingValueMap::iterator it = mUserSettings.find(key);

@ -63,7 +63,7 @@ namespace Settings
static std::int64_t getInt64(std::string_view setting, std::string_view category);
static float getFloat(std::string_view setting, std::string_view category);
static double getDouble(std::string_view setting, std::string_view category);
static std::string getString(std::string_view setting, std::string_view category);
static const std::string& getString(std::string_view setting, std::string_view category);
static std::vector<std::string> getStringArray(std::string_view setting, std::string_view category);
static bool getBool(std::string_view setting, std::string_view category);
static osg::Vec2f getVector2(std::string_view setting, std::string_view category);

@ -18,7 +18,7 @@ bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out)
if (tag.compare(0, fontcolourLength, fontcolour) == 0)
{
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourLength);
std::string str = Fallback::Map::getString(fallbackName);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);
@ -36,7 +36,7 @@ bool replaceTag(const MyGUI::UString& tag, MyGUI::UString& out)
else if (tag.compare(0, fontcolourhtmlLength, fontcolourhtml) == 0)
{
std::string fallbackName = "FontColor_color_" + tag.substr(fontcolourhtmlLength);
std::string str = Fallback::Map::getString(fallbackName);
std::string_view str = Fallback::Map::getString(fallbackName);
if (str.empty())
throw std::runtime_error("Unknown fallback name: " + fallbackName);

Loading…
Cancel
Save