Use string_view in Fallback::Map

crashfix_debugdraw
Evil Eye 2 years ago
parent 2222b47e3d
commit fb9bc5f535

@ -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;

@ -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};

@ -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)

@ -1807,9 +1807,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;

@ -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);

@ -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;

@ -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

@ -169,8 +169,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.

@ -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