diff --git a/apps/openmw/mwbase/dialoguemanager.hpp b/apps/openmw/mwbase/dialoguemanager.hpp index 4fbd958381..94543ed955 100644 --- a/apps/openmw/mwbase/dialoguemanager.hpp +++ b/apps/openmw/mwbase/dialoguemanager.hpp @@ -2,6 +2,7 @@ #define GAME_MWBASE_DIALOGUEMANAGER_H #include +#include #include #include @@ -55,9 +56,9 @@ namespace MWBase virtual bool inJournal (const std::string& topicId, const std::string& infoId) = 0; - virtual void addTopic (const std::string& topic) = 0; + virtual void addTopic(std::string_view topic) = 0; - virtual void addChoice (const std::string& text,int choice) = 0; + virtual void addChoice(std::string_view text,int choice) = 0; virtual const std::vector >& getChoices() = 0; virtual bool isGoodbye() = 0; @@ -105,12 +106,12 @@ namespace MWBase virtual void readRecord (ESM::ESMReader& reader, uint32_t type) = 0; /// Changes faction1's opinion of faction2 by \a diff. - virtual void modFactionReaction (const std::string& faction1, const std::string& faction2, int diff) = 0; + virtual void modFactionReaction (std::string_view faction1, std::string_view faction2, int diff) = 0; - virtual void setFactionReaction (const std::string& faction1, const std::string& faction2, int absolute) = 0; + virtual void setFactionReaction (std::string_view faction1, std::string_view faction2, int absolute) = 0; /// @return faction1's opinion of faction2 - virtual int getFactionReaction (const std::string& faction1, const std::string& faction2) const = 0; + virtual int getFactionReaction (std::string_view faction1, std::string_view faction2) const = 0; /// Removes the last added topic response for the given actor from the journal virtual void clearInfoActor (const MWWorld::Ptr& actor) const = 0; diff --git a/apps/openmw/mwbase/soundmanager.hpp b/apps/openmw/mwbase/soundmanager.hpp index 9d3e99d06b..641be742ff 100644 --- a/apps/openmw/mwbase/soundmanager.hpp +++ b/apps/openmw/mwbase/soundmanager.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include "../mwworld/ptr.hpp" @@ -128,19 +129,19 @@ namespace MWBase /// returned by \ref playTrack). Only intended to be called by the track /// decoder's read method. - virtual Sound *playSound(const std::string& soundId, float volume, float pitch, + virtual Sound *playSound(std::string_view soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) = 0; ///< Play a sound, independently of 3D-position ///< @param offset Number of seconds into the sound to start playback. - virtual Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, + virtual Sound *playSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) = 0; ///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified. ///< @param offset Number of seconds into the sound to start playback. - virtual Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId, + virtual Sound *playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) = 0; ///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition. @@ -148,7 +149,7 @@ namespace MWBase virtual void stopSound(Sound *sound) = 0; ///< Stop the given sound from playing - virtual void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) = 0; + virtual void stopSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId) = 0; ///< Stop the given object from playing the given sound, virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0; @@ -157,13 +158,13 @@ namespace MWBase virtual void stopSound(const MWWorld::CellStore *cell) = 0; ///< Stop all sounds for the given cell. - virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) = 0; + virtual void fadeOutSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId, float duration) = 0; ///< Fade out given sound (that is already playing) of given object ///< @param reference Reference to object, whose sound is faded out ///< @param soundId ID of the sound to fade out. ///< @param duration Time until volume reaches 0. - virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const = 0; + virtual bool getSoundPlaying(const MWWorld::ConstPtr &reference, std::string_view soundId) const = 0; ///< Is the given sound currently playing on the given object? /// If you want to check if sound played with playSound is playing, use empty Ptr diff --git a/apps/openmw/mwbase/world.hpp b/apps/openmw/mwbase/world.hpp index 15177b4301..3d904631cd 100644 --- a/apps/openmw/mwbase/world.hpp +++ b/apps/openmw/mwbase/world.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -174,19 +175,19 @@ namespace MWBase virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector& out) = 0; ///< get a list of teleport door markers for a given cell, to be displayed on the local map - virtual void setGlobalInt (const std::string& name, int value) = 0; + virtual void setGlobalInt(std::string_view name, int value) = 0; ///< Set value independently from real type. - virtual void setGlobalFloat (const std::string& name, float value) = 0; + virtual void setGlobalFloat(std::string_view name, float value) = 0; ///< Set value independently from real type. - virtual int getGlobalInt (const std::string& name) const = 0; + virtual int getGlobalInt(std::string_view name) const = 0; ///< Get value independently from real type. - virtual float getGlobalFloat (const std::string& name) const = 0; + virtual float getGlobalFloat(std::string_view name) const = 0; ///< Get value independently from real type. - virtual char getGlobalVariableType (const std::string& name) const = 0; + virtual char getGlobalVariableType(std::string_view name) const = 0; ///< Return ' ', if there is no global variable with this name. virtual std::string getCellName (const MWWorld::CellStore *cell = nullptr) const = 0; @@ -199,11 +200,11 @@ namespace MWBase virtual void removeRefScript (MWWorld::RefData *ref) = 0; //< Remove the script attached to ref from mLocalScripts - virtual MWWorld::Ptr getPtr (const std::string& name, bool activeOnly) = 0; + virtual MWWorld::Ptr getPtr (std::string_view name, bool activeOnly) = 0; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. - virtual MWWorld::Ptr searchPtr (const std::string& name, bool activeOnly, bool searchInContainers = true) = 0; + virtual MWWorld::Ptr searchPtr (std::string_view name, bool activeOnly, bool searchInContainers = true) = 0; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp index 9d8516ae79..e0b88bba12 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.cpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.cpp @@ -71,7 +71,7 @@ namespace MWDialogue mPermanentDispositionChange = 0; } - void DialogueManager::addTopic (const std::string& topic) + void DialogueManager::addTopic(std::string_view topic) { mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) ); } @@ -516,7 +516,7 @@ namespace MWDialogue updateActorKnownTopics(); } - void DialogueManager::addChoice (const std::string& text, int choice) + void DialogueManager::addChoice(std::string_view text, int choice) { mIsInChoice = true; mChoices.emplace_back(text, choice); @@ -704,7 +704,7 @@ namespace MWDialogue } } - void DialogueManager::modFactionReaction(const std::string &faction1, const std::string &faction2, int diff) + void DialogueManager::modFactionReaction(std::string_view faction1, std::string_view faction2, int diff) { std::string fact1 = Misc::StringUtils::lowerCase(faction1); std::string fact2 = Misc::StringUtils::lowerCase(faction2); @@ -719,7 +719,7 @@ namespace MWDialogue map[fact2] = newValue; } - void DialogueManager::setFactionReaction(const std::string &faction1, const std::string &faction2, int absolute) + void DialogueManager::setFactionReaction(std::string_view faction1, std::string_view faction2, int absolute) { std::string fact1 = Misc::StringUtils::lowerCase(faction1); std::string fact2 = Misc::StringUtils::lowerCase(faction2); @@ -732,7 +732,7 @@ namespace MWDialogue map[fact2] = absolute; } - int DialogueManager::getFactionReaction(const std::string &faction1, const std::string &faction2) const + int DialogueManager::getFactionReaction(std::string_view faction1, std::string_view faction2) const { std::string fact1 = Misc::StringUtils::lowerCase(faction1); std::string fact2 = Misc::StringUtils::lowerCase(faction2); diff --git a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp index 7a3e44349e..5d0c5279d2 100644 --- a/apps/openmw/mwdialogue/dialoguemanagerimp.hpp +++ b/apps/openmw/mwdialogue/dialoguemanagerimp.hpp @@ -87,9 +87,9 @@ namespace MWDialogue bool inJournal (const std::string& topicId, const std::string& infoId) override; - void addTopic (const std::string& topic) override; + void addTopic(std::string_view topic) override; - void addChoice (const std::string& text,int choice) override; + void addChoice(std::string_view text,int choice) override; const std::vector >& getChoices() override; bool isGoodbye() override; @@ -117,12 +117,12 @@ namespace MWDialogue void readRecord (ESM::ESMReader& reader, uint32_t type) override; /// Changes faction1's opinion of faction2 by \a diff. - void modFactionReaction (const std::string& faction1, const std::string& faction2, int diff) override; + void modFactionReaction (std::string_view faction1, std::string_view faction2, int diff) override; - void setFactionReaction (const std::string& faction1, const std::string& faction2, int absolute) override; + void setFactionReaction (std::string_view faction1, std::string_view faction2, int absolute) override; /// @return faction1's opinion of faction2 - int getFactionReaction (const std::string& faction1, const std::string& faction2) const override; + int getFactionReaction (std::string_view faction1, std::string_view faction2) const override; /// Removes the last added topic response for the given actor from the journal void clearInfoActor (const MWWorld::Ptr& actor) const override; diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index d0cdb4b8bb..8dcf6ca90c 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -333,7 +333,7 @@ namespace MWMechanics return mSpells.end(); } - bool ActiveSpells::isSpellActive(const std::string& id) const + bool ActiveSpells::isSpellActive(std::string_view id) const { return std::find_if(mSpells.begin(), mSpells.end(), [&] (const auto& spell) { @@ -434,7 +434,7 @@ namespace MWMechanics return removedCurrentSpell; } - void ActiveSpells::removeEffects(const MWWorld::Ptr& ptr, const std::string &id) + void ActiveSpells::removeEffects(const MWWorld::Ptr& ptr, std::string_view id) { purge([=] (const ActiveSpellParams& params) { diff --git a/apps/openmw/mwmechanics/activespells.hpp b/apps/openmw/mwmechanics/activespells.hpp index 5fb732ea8a..55b089dc52 100644 --- a/apps/openmw/mwmechanics/activespells.hpp +++ b/apps/openmw/mwmechanics/activespells.hpp @@ -127,7 +127,7 @@ namespace MWMechanics void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor); /// Removes the active effects from this spell/potion/.. with \a id - void removeEffects (const MWWorld::Ptr& ptr, const std::string& id); + void removeEffects (const MWWorld::Ptr& ptr, std::string_view id); /// Remove all active effects with this effect id void purgeEffect (const MWWorld::Ptr& ptr, short effectId); @@ -141,7 +141,7 @@ namespace MWMechanics /// Remove all spells void clear(const MWWorld::Ptr& ptr); - bool isSpellActive (const std::string& id) const; + bool isSpellActive (std::string_view id) const; ///< case insensitive void skipWorsenings(double hours); diff --git a/apps/openmw/mwscript/aiextensions.cpp b/apps/openmw/mwscript/aiextensions.cpp index f862508ee4..519af584f0 100644 --- a/apps/openmw/mwscript/aiextensions.cpp +++ b/apps/openmw/mwscript/aiextensions.cpp @@ -45,7 +45,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); // The value of the reset argument doesn't actually matter @@ -102,7 +102,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -140,10 +140,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -168,7 +168,7 @@ namespace MWScript if (cellID.empty()) return; - if (!MWBase::Environment::get().getWorld()->getStore().get().search(cellID)) + if (!MWBase::Environment::get().getWorld()->getStore().get().search(std::string{cellID})) return; MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast(duration), x, y, z, repeat); @@ -320,7 +320,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -358,10 +358,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float duration = runtime[0].mFloat; @@ -421,7 +421,7 @@ namespace MWScript { MWWorld::Ptr observer = R()(runtime, false); // required=false - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); @@ -444,7 +444,7 @@ namespace MWScript MWWorld::Ptr source = R()(runtime); - std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); @@ -465,7 +465,7 @@ namespace MWScript void execute (Interpreter::Runtime &runtime) override { MWWorld::Ptr actor = R()(runtime); - std::string testedTargetId = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view testedTargetId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); bool targetsAreEqual = false; @@ -497,7 +497,7 @@ namespace MWScript void execute (Interpreter::Runtime &runtime) override { MWWorld::Ptr actor = R()(runtime); - std::string targetID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view targetID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false); diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index 9320c86a88..12fe5256be 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -44,7 +44,7 @@ namespace MWScript if (!ptr.getRefData().isEnabled()) return; - std::string group = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view group = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer mode = 0; @@ -58,7 +58,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, std::numeric_limits::max(), true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, std::numeric_limits::max(), true); } }; @@ -74,7 +74,7 @@ namespace MWScript if (!ptr.getRefData().isEnabled()) return; - std::string group = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view group = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer loops = runtime[0].mInteger; @@ -94,7 +94,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, loops + 1, true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, loops + 1, true); } }; diff --git a/apps/openmw/mwscript/cellextensions.cpp b/apps/openmw/mwscript/cellextensions.cpp index f00fcfd447..0419d37962 100644 --- a/apps/openmw/mwscript/cellextensions.cpp +++ b/apps/openmw/mwscript/cellextensions.cpp @@ -87,7 +87,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string cell = runtime.getStringLiteral (runtime[0].mInteger); + std::string cell{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); ESM::Position pos; @@ -160,7 +160,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(); if (!MWMechanics::getPlayer().isInCell()) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index 8db1c04551..11e9095e2c 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -87,7 +87,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; @@ -116,7 +116,7 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); return; } @@ -124,7 +124,7 @@ namespace MWScript if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) @@ -183,7 +183,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if(::Misc::StringUtils::ciEqual(item, "gold_005") @@ -207,7 +207,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; @@ -229,14 +229,14 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); return; } // Calls to unresolved containers affect the base record instead else if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) @@ -297,7 +297,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); @@ -408,7 +408,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); @@ -434,7 +434,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - const std::string &name = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int count = 0; diff --git a/apps/openmw/mwscript/dialogueextensions.cpp b/apps/openmw/mwscript/dialogueextensions.cpp index a147bce6ea..f06ee022e2 100644 --- a/apps/openmw/mwscript/dialogueextensions.cpp +++ b/apps/openmw/mwscript/dialogueextensions.cpp @@ -34,7 +34,7 @@ namespace MWScript if (ptr.isEmpty()) ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); - std::string quest = runtime.getStringLiteral (runtime[0].mInteger); + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; @@ -59,7 +59,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string quest = runtime.getStringLiteral (runtime[0].mInteger); + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer index = runtime[0].mInteger; @@ -75,7 +75,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string quest = runtime.getStringLiteral (runtime[0].mInteger); + std::string quest{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); int index = MWBase::Environment::get().getJournal()->getJournalIndex (quest); @@ -91,7 +91,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string topic = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view topic = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getDialogueManager()->addTopic(topic); @@ -107,7 +107,7 @@ namespace MWScript MWBase::DialogueManager* dialogue = MWBase::Environment::get().getDialogueManager(); while(arg0>0) { - std::string question = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view question = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); arg0 = arg0 -1; Interpreter::Type_Integer choice = 1; @@ -220,10 +220,10 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string faction1 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int modReaction = runtime[0].mInteger; @@ -239,10 +239,10 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string faction1 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); runtime.push(MWBase::Environment::get().getDialogueManager() @@ -256,10 +256,10 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string faction1 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction1 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int newValue = runtime[0].mInteger; diff --git a/apps/openmw/mwscript/globalscripts.cpp b/apps/openmw/mwscript/globalscripts.cpp index 4a38d09bd0..16a32a0a12 100644 --- a/apps/openmw/mwscript/globalscripts.cpp +++ b/apps/openmw/mwscript/globalscripts.cpp @@ -135,20 +135,21 @@ namespace MWScript : mStore (store) {} - void GlobalScripts::addScript (const std::string& name, const MWWorld::Ptr& target) + void GlobalScripts::addScript(std::string_view name, const MWWorld::Ptr& target) { - const auto iter = mScripts.find (::Misc::StringUtils::lowerCase (name)); + std::string lowerName = ::Misc::StringUtils::lowerCase(name); + const auto iter = mScripts.find(lowerName); if (iter==mScripts.end()) { - if (const ESM::Script *script = mStore.get().search(name)) + if (const ESM::Script *script = mStore.get().search(lowerName)) { auto desc = std::make_shared(); MWWorld::Ptr ptr = target; desc->mTarget = ptr; desc->mRunning = true; desc->mLocals.configure (*script); - mScripts.insert (std::make_pair(name, desc)); + mScripts.insert (std::make_pair(lowerName, desc)); } else { @@ -163,7 +164,7 @@ namespace MWScript } } - void GlobalScripts::removeScript (const std::string& name) + void GlobalScripts::removeScript (std::string_view name) { const auto iter = mScripts.find (::Misc::StringUtils::lowerCase (name)); @@ -171,7 +172,7 @@ namespace MWScript iter->second->mRunning = false; } - bool GlobalScripts::isRunning (const std::string& name) const + bool GlobalScripts::isRunning (std::string_view name) const { const auto iter = mScripts.find (::Misc::StringUtils::lowerCase (name)); @@ -306,14 +307,14 @@ namespace MWScript return false; } - Locals& GlobalScripts::getLocals (const std::string& name) + Locals& GlobalScripts::getLocals(std::string_view name) { std::string name2 = ::Misc::StringUtils::lowerCase (name); auto iter = mScripts.find (name2); if (iter==mScripts.end()) { - const ESM::Script *script = mStore.get().find (name); + const ESM::Script *script = mStore.get().find(name2); auto desc = std::make_shared(); desc->mLocals.configure (*script); @@ -324,7 +325,7 @@ namespace MWScript return iter->second->mLocals; } - const Locals* GlobalScripts::getLocalsIfPresent (const std::string& name) const + const Locals* GlobalScripts::getLocalsIfPresent(std::string_view name) const { std::string name2 = ::Misc::StringUtils::lowerCase (name); auto iter = mScripts.find (name2); diff --git a/apps/openmw/mwscript/globalscripts.hpp b/apps/openmw/mwscript/globalscripts.hpp index 8725959e66..556f815238 100644 --- a/apps/openmw/mwscript/globalscripts.hpp +++ b/apps/openmw/mwscript/globalscripts.hpp @@ -56,11 +56,11 @@ namespace MWScript GlobalScripts (const MWWorld::ESMStore& store); - void addScript (const std::string& name, const MWWorld::Ptr& target = MWWorld::Ptr()); + void addScript(std::string_view name, const MWWorld::Ptr& target = MWWorld::Ptr()); - void removeScript (const std::string& name); + void removeScript (std::string_view name); - bool isRunning (const std::string& name) const; + bool isRunning (std::string_view name) const; void run(); ///< run all active global scripts @@ -79,11 +79,11 @@ namespace MWScript /// /// \return Known type? - Locals& getLocals (const std::string& name); + Locals& getLocals(std::string_view name); ///< If the script \a name has not been added as a global script yet, it is added /// automatically, but is not set to running state. - const Locals* getLocalsIfPresent (const std::string& name) const; + const Locals* getLocalsIfPresent(std::string_view name) const; void updatePtrs(const MWWorld::Ptr& base, const MWWorld::Ptr& updated); ///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell. diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp index e44c94e686..f240747f6e 100644 --- a/apps/openmw/mwscript/guiextensions.cpp +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -114,8 +114,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string cell = (runtime.getStringLiteral (runtime[0].mInteger)); - ::Misc::StringUtils::lowerCaseInPlace(cell); + std::string cell = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); // "Will match complete or partial cells, so ShowMap, "Vivec" will show cells Vivec and Vivec, Fred's House as well." diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 72922aa5f3..733bc9260f 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -89,7 +89,7 @@ namespace MWScript MissingImplicitRefError::MissingImplicitRefError() : std::runtime_error("no implicit reference") {} int InterpreterContext::findLocalVariableIndex (const std::string& scriptId, - const std::string& name, char type) const + std::string_view name, char type) const { int index = MWBase::Environment::get().getScriptManager()->getLocals (scriptId). searchIndex (type, name); @@ -200,33 +200,33 @@ namespace MWScript { } - int InterpreterContext::getGlobalShort (const std::string& name) const + int InterpreterContext::getGlobalShort(std::string_view name) const { return MWBase::Environment::get().getWorld()->getGlobalInt (name); } - int InterpreterContext::getGlobalLong (const std::string& name) const + int InterpreterContext::getGlobalLong(std::string_view name) const { // a global long is internally a float. return MWBase::Environment::get().getWorld()->getGlobalInt (name); } - float InterpreterContext::getGlobalFloat (const std::string& name) const + float InterpreterContext::getGlobalFloat(std::string_view name) const { return MWBase::Environment::get().getWorld()->getGlobalFloat (name); } - void InterpreterContext::setGlobalShort (const std::string& name, int value) + void InterpreterContext::setGlobalShort(std::string_view name, int value) { MWBase::Environment::get().getWorld()->setGlobalInt (name, value); } - void InterpreterContext::setGlobalLong (const std::string& name, int value) + void InterpreterContext::setGlobalLong(std::string_view name, int value) { MWBase::Environment::get().getWorld()->setGlobalInt (name, value); } - void InterpreterContext::setGlobalFloat (const std::string& name, float value) + void InterpreterContext::setGlobalFloat(std::string_view name, float value) { MWBase::Environment::get().getWorld()->setGlobalFloat (name, value); } @@ -245,13 +245,13 @@ namespace MWScript return ids; } - char InterpreterContext::getGlobalType (const std::string& name) const + char InterpreterContext::getGlobalType(std::string_view name) const { MWBase::World *world = MWBase::Environment::get().getWorld(); return world->getGlobalVariableType(name); } - std::string InterpreterContext::getActionBinding(const std::string& targetAction) const + std::string InterpreterContext::getActionBinding(std::string_view targetAction) const { MWBase::InputManager* input = MWBase::Environment::get().getInputManager(); std::vector actions = input->getActionKeySorting (); @@ -427,7 +427,7 @@ namespace MWScript } } - int InterpreterContext::getMemberShort (const std::string& id, const std::string& name, + int InterpreterContext::getMemberShort(std::string_view id, std::string_view name, bool global) const { std::string scriptId (id); @@ -437,7 +437,7 @@ namespace MWScript return locals.mShorts[findLocalVariableIndex (scriptId, name, 's')]; } - int InterpreterContext::getMemberLong (const std::string& id, const std::string& name, + int InterpreterContext::getMemberLong(std::string_view id, std::string_view name, bool global) const { std::string scriptId (id); @@ -447,7 +447,7 @@ namespace MWScript return locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')]; } - float InterpreterContext::getMemberFloat (const std::string& id, const std::string& name, + float InterpreterContext::getMemberFloat(std::string_view id, std::string_view name, bool global) const { std::string scriptId (id); @@ -457,7 +457,7 @@ namespace MWScript return locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')]; } - void InterpreterContext::setMemberShort (const std::string& id, const std::string& name, + void InterpreterContext::setMemberShort(std::string_view id, std::string_view name, int value, bool global) { std::string scriptId (id); @@ -467,7 +467,7 @@ namespace MWScript locals.mShorts[findLocalVariableIndex (scriptId, name, 's')] = value; } - void InterpreterContext::setMemberLong (const std::string& id, const std::string& name, int value, bool global) + void InterpreterContext::setMemberLong(std::string_view id, std::string_view name, int value, bool global) { std::string scriptId (id); @@ -476,7 +476,7 @@ namespace MWScript locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')] = value; } - void InterpreterContext::setMemberFloat (const std::string& id, const std::string& name, float value, bool global) + void InterpreterContext::setMemberFloat(std::string_view id, std::string_view name, float value, bool global) { std::string scriptId (id); diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index ee40883eac..b675e850d2 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -38,7 +38,7 @@ namespace MWScript ///< \a id is changed to the respective script ID, if \a id wasn't a script ID before /// Throws an exception if local variable can't be found. - int findLocalVariableIndex (const std::string& scriptId, const std::string& name, + int findLocalVariableIndex (const std::string& scriptId, std::string_view name, char type) const; public: @@ -69,23 +69,23 @@ namespace MWScript void report (const std::string& message) override; ///< By default, do nothing. - int getGlobalShort (const std::string& name) const override; + int getGlobalShort(std::string_view name) const override; - int getGlobalLong (const std::string& name) const override; + int getGlobalLong(std::string_view name) const override; - float getGlobalFloat (const std::string& name) const override; + float getGlobalFloat(std::string_view name) const override; - void setGlobalShort (const std::string& name, int value) override; + void setGlobalShort(std::string_view name, int value) override; - void setGlobalLong (const std::string& name, int value) override; + void setGlobalLong(std::string_view name, int value) override; - void setGlobalFloat (const std::string& name, float value) override; + void setGlobalFloat(std::string_view name, float value) override; std::vector getGlobals () const override; - char getGlobalType (const std::string& name) const override; + char getGlobalType(std::string_view name) const override; - std::string getActionBinding(const std::string& action) const override; + std::string getActionBinding(std::string_view action) const override; std::string getActorName() const override; @@ -114,17 +114,17 @@ namespace MWScript void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor); ///< Execute the activation action for this ptr. If ptr is mActivated, mark activation as handled. - int getMemberShort (const std::string& id, const std::string& name, bool global) const override; + int getMemberShort(std::string_view id, std::string_view name, bool global) const override; - int getMemberLong (const std::string& id, const std::string& name, bool global) const override; + int getMemberLong(std::string_view id, std::string_view name, bool global) const override; - float getMemberFloat (const std::string& id, const std::string& name, bool global) const override; + float getMemberFloat(std::string_view id, std::string_view name, bool global) const override; - void setMemberShort (const std::string& id, const std::string& name, int value, bool global) override; + void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override; - void setMemberLong (const std::string& id, const std::string& name, int value, bool global) override; + void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override; - void setMemberFloat (const std::string& id, const std::string& name, float value, bool global) override; + void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override; MWWorld::Ptr getReference(bool required=true) const; ///< Reference, that the script is running from (can be empty) diff --git a/apps/openmw/mwscript/locals.cpp b/apps/openmw/mwscript/locals.cpp index 4c395f83d4..9b9fbc66ad 100644 --- a/apps/openmw/mwscript/locals.cpp +++ b/apps/openmw/mwscript/locals.cpp @@ -62,7 +62,7 @@ namespace MWScript return (mShorts.empty() && mLongs.empty() && mFloats.empty()); } - bool Locals::hasVar(const std::string &script, const std::string &var) + bool Locals::hasVar(const std::string &script, std::string_view var) { ensure (script); @@ -72,7 +72,7 @@ namespace MWScript return (index != -1); } - int Locals::getIntVar(const std::string &script, const std::string &var) + int Locals::getIntVar(const std::string &script, std::string_view var) { ensure (script); @@ -98,7 +98,7 @@ namespace MWScript return 0; } - float Locals::getFloatVar(const std::string &script, const std::string &var) + float Locals::getFloatVar(const std::string &script, std::string_view var) { ensure (script); @@ -124,7 +124,7 @@ namespace MWScript return 0; } - bool Locals::setVarByInt(const std::string& script, const std::string& var, int val) + bool Locals::setVarByInt(const std::string& script, std::string_view var, int val) { ensure (script); diff --git a/apps/openmw/mwscript/locals.hpp b/apps/openmw/mwscript/locals.hpp index d63411a942..6f3d4d5f07 100644 --- a/apps/openmw/mwscript/locals.hpp +++ b/apps/openmw/mwscript/locals.hpp @@ -1,6 +1,8 @@ #ifndef GAME_SCRIPT_LOCALS_H #define GAME_SCRIPT_LOCALS_H +#include +#include #include #include @@ -37,25 +39,25 @@ namespace MWScript /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - bool setVarByInt(const std::string& script, const std::string& var, int val); + bool setVarByInt(const std::string& script, std::string_view var, int val); /// \note Locals will be automatically configured first, if necessary // // \note If it can not be determined if the variable exists, the error will be // ignored and false will be returned. - bool hasVar(const std::string& script, const std::string& var); + bool hasVar(const std::string& script, std::string_view var); /// if var does not exist, returns 0 /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - int getIntVar (const std::string& script, const std::string& var); + int getIntVar (const std::string& script, std::string_view var); /// if var does not exist, returns 0 /// @note var needs to be in lowercase /// /// \note Locals will be automatically configured first, if necessary - float getFloatVar (const std::string& script, const std::string& var); + float getFloatVar (const std::string& script, std::string_view var); /// \note If locals have not been configured yet, no data is written. /// diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 678e195808..d620882dde 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -51,7 +51,7 @@ namespace { - void addToLevList(ESM::LevelledListBase* list, const std::string& itemId, int level) + void addToLevList(ESM::LevelledListBase* list, std::string_view itemId, int level) { for (auto& levelItem : list->mList) { @@ -60,12 +60,12 @@ namespace } ESM::LevelledListBase::LevelItem item; - item.mId = itemId; + item.mId = std::string{itemId}; item.mLevel = level; list->mList.push_back(item); } - void removeFromLevList(ESM::LevelledListBase* list, const std::string& itemId, int level) + void removeFromLevList(ESM::LevelledListBase* list, std::string_view itemId, int level) { // level of -1 removes all items with that itemId for (std::vector::iterator it = list->mList.begin(); it != list->mList.end();) @@ -124,7 +124,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { MWWorld::Ptr target = R()(runtime, false); - std::string name = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name, target); } @@ -136,7 +136,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(); runtime.push(MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning (name)); } @@ -148,7 +148,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(); MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript (name); } @@ -206,7 +206,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string name = runtime.getStringLiteral (runtime[0].mInteger); + std::string name{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); bool allowSkipping = runtime[0].mInteger != 0; @@ -548,7 +548,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string effect = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view effect = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (!ptr.getClass().isActor()) @@ -558,9 +558,9 @@ namespace MWScript } char *end; - long key = strtol(effect.c_str(), &end, 10); + long key = strtol(effect.data(), &end, 10); if(key < 0 || key > 32767 || *end != '\0') - key = ESM::MagicEffect::effectStringToId(effect); + key = ESM::MagicEffect::effectStringToId({effect}); const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); @@ -587,10 +587,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string creature = runtime.getStringLiteral (runtime[0].mInteger); + std::string creature{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - std::string gem = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view gem = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (!ptr.getClass().hasInventoryStore(ptr)) @@ -619,7 +619,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string soul = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); // throw away additional arguments @@ -651,7 +651,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string item = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view item = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer amount = runtime[0].mInteger; @@ -738,7 +738,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string soul = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (!ptr.getClass().hasInventoryStore(ptr)) @@ -806,7 +806,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime); - std::string id = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (!ptr.getClass().isActor()) @@ -973,7 +973,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); @@ -993,7 +993,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); @@ -1036,7 +1036,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { MWWorld::Ptr ptr = R()(runtime, false); - std::string var = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view var = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); std::stringstream output; @@ -1213,10 +1213,10 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string spellId = runtime.getStringLiteral (runtime[0].mInteger); + std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral (runtime[0].mInteger)); + std::string targetId = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger)); runtime.pop(); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); @@ -1228,7 +1228,7 @@ namespace MWScript if (ptr == MWMechanics::getPlayer()) { - MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId); + MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spell->mId); return; } @@ -1236,7 +1236,7 @@ namespace MWScript { if (!MWBase::Environment::get().getMechanicsManager()->isCastingSpell(ptr)) { - MWMechanics::AiCast castPackage(targetId, spellId, true); + MWMechanics::AiCast castPackage(targetId, spell->mId, true); ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr); } return; @@ -1262,7 +1262,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string spellId = runtime.getStringLiteral (runtime[0].mInteger); + std::string spellId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().search(spellId); @@ -1274,7 +1274,7 @@ namespace MWScript if (ptr == MWMechanics::getPlayer()) { - MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId); + MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spell->mId); return; } @@ -1282,7 +1282,7 @@ namespace MWScript { if (!MWBase::Environment::get().getMechanicsManager()->isCastingSpell(ptr)) { - MWMechanics::AiCast castPackage(ptr.getCellRef().getRefId(), spellId, true); + MWMechanics::AiCast castPackage(ptr.getCellRef().getRefId(), spell->mId, true); ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr); } return; @@ -1407,7 +1407,7 @@ namespace MWScript while (arg0 > 0) { - std::string notes = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view notes = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (!notes.empty()) msg << "Notes: " << notes << std::endl; @@ -1425,9 +1425,9 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const std::string& creatureId = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1443,9 +1443,9 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const std::string& creatureId = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1461,9 +1461,9 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const std::string& itemId = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); @@ -1479,9 +1479,9 @@ namespace MWScript public: void execute(Interpreter::Runtime &runtime) override { - const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); + std::string levId{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - const std::string& itemId = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); int level = runtime[0].mInteger; runtime.pop(); diff --git a/apps/openmw/mwscript/ref.cpp b/apps/openmw/mwscript/ref.cpp index 6347c2c2e5..145cd2cd25 100644 --- a/apps/openmw/mwscript/ref.cpp +++ b/apps/openmw/mwscript/ref.cpp @@ -10,7 +10,7 @@ MWWorld::Ptr MWScript::ExplicitRef::operator() (Interpreter::Runtime& runtime, bool required, bool activeOnly) const { - std::string id = runtime.getStringLiteral(runtime[0].mInteger); + std::string_view id = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (required) diff --git a/apps/openmw/mwscript/ref.hpp b/apps/openmw/mwscript/ref.hpp index c52b419c1d..8c7657280f 100644 --- a/apps/openmw/mwscript/ref.hpp +++ b/apps/openmw/mwscript/ref.hpp @@ -1,8 +1,6 @@ #ifndef GAME_MWSCRIPT_REF_H #define GAME_MWSCRIPT_REF_H -#include - #include "../mwworld/ptr.hpp" namespace Interpreter diff --git a/apps/openmw/mwscript/skyextensions.cpp b/apps/openmw/mwscript/skyextensions.cpp index 1d00b8c052..f81645b280 100644 --- a/apps/openmw/mwscript/skyextensions.cpp +++ b/apps/openmw/mwscript/skyextensions.cpp @@ -87,7 +87,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string region = runtime.getStringLiteral (runtime[0].mInteger); + std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer id = runtime[0].mInteger; @@ -107,7 +107,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime, unsigned int arg0) override { - std::string region = runtime.getStringLiteral (runtime[0].mInteger); + std::string region{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); std::vector chances; diff --git a/apps/openmw/mwscript/soundextensions.cpp b/apps/openmw/mwscript/soundextensions.cpp index b8d1470ea8..1e0ad12946 100644 --- a/apps/openmw/mwscript/soundextensions.cpp +++ b/apps/openmw/mwscript/soundextensions.cpp @@ -33,10 +33,10 @@ namespace MWScript MWScript::InterpreterContext& context = static_cast (runtime.getContext()); - std::string file = runtime.getStringLiteral (runtime[0].mInteger); + std::string file{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); - std::string text = runtime.getStringLiteral (runtime[0].mInteger); + std::string text{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); MWBase::Environment::get().getSoundManager()->say (ptr, file); @@ -65,7 +65,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string sound{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); MWBase::Environment::get().getSoundManager()->streamMusic (sound); @@ -78,7 +78,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getSoundManager()->playSound(sound, 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv); @@ -91,7 +91,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float volume = runtime[0].mFloat; @@ -113,7 +113,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0, @@ -132,7 +132,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float volume = runtime[0].mFloat; @@ -158,7 +158,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string sound = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); MWBase::Environment::get().getSoundManager()->stopSound3D (ptr, sound); diff --git a/apps/openmw/mwscript/statsextensions.cpp b/apps/openmw/mwscript/statsextensions.cpp index 9a9a315bdb..4be2b9b8f4 100644 --- a/apps/openmw/mwscript/statsextensions.cpp +++ b/apps/openmw/mwscript/statsextensions.cpp @@ -447,13 +447,13 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string id = runtime.getStringLiteral (runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get().find (id); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); - creatureStats.getSpells().add(id); + creatureStats.getSpells().add(spell); ESM::Spell::SpellType type = static_cast(spell->mData.mType); if (type != ESM::Spell::ST_Spell && type != ESM::Spell::ST_Power) { @@ -474,7 +474,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string id = runtime.getStringLiteral (runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); @@ -499,7 +499,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string spellid = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view spellid = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); ptr.getClass().getCreatureStats (ptr).getActiveSpells().removeEffects(ptr, spellid); @@ -532,7 +532,7 @@ namespace MWScript MWWorld::Ptr ptr = R()(runtime); - std::string id = runtime.getStringLiteral (runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Integer value = 0; @@ -748,7 +748,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string id = runtime.getStringLiteral (runtime[0].mInteger); + std::string id{runtime.getStringLiteral(runtime[0].mInteger)}; runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths (id); } }; @@ -890,14 +890,12 @@ namespace MWScript { MWWorld::ConstPtr ptr = R()(runtime); - std::string race = runtime.getStringLiteral(runtime[0].mInteger); - ::Misc::StringUtils::lowerCaseInPlace(race); + std::string_view race = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string npcRace = ptr.get()->mBase->mRace; - ::Misc::StringUtils::lowerCaseInPlace(npcRace); + const std::string& npcRace = ptr.get()->mBase->mRace; - runtime.push (npcRace == race); + runtime.push(::Misc::StringUtils::ciEqual(race, npcRace)); } }; diff --git a/apps/openmw/mwscript/transformationextensions.cpp b/apps/openmw/mwscript/transformationextensions.cpp index d87888c282..dbcb1087f9 100644 --- a/apps/openmw/mwscript/transformationextensions.cpp +++ b/apps/openmw/mwscript/transformationextensions.cpp @@ -43,7 +43,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { MWWorld::Ptr from = R()(runtime, !R::implicit); - std::string name = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view name = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); if (from.isEmpty()) @@ -74,7 +74,7 @@ namespace MWScript const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false); if (to.isEmpty()) { - std::string error = "Failed to find an instance of object '" + name + "'"; + std::string error = "Failed to find an instance of object '" + std::string(name) + "'"; runtime.getContext().report(error); Log(Debug::Error) << error; runtime.push(0.f); @@ -155,7 +155,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float angle = osg::DegreesToRadians(runtime[0].mFloat); runtime.pop(); @@ -190,7 +190,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); float ret = 0.f; @@ -222,7 +222,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); float ret = 0.f; @@ -254,7 +254,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); float ret = 0.f; @@ -286,7 +286,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float pos = runtime[0].mFloat; runtime.pop(); @@ -340,7 +340,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); float ret = 0.f; @@ -380,7 +380,7 @@ namespace MWScript runtime.pop(); Interpreter::Type_Float zRot = runtime[0].mFloat; runtime.pop(); - std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); + std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); if (ptr.getContainerStore()) @@ -495,9 +495,9 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string itemID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); - std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); + std::string cellID{runtime.getStringLiteral(runtime[0].mInteger)}; runtime.pop(); Interpreter::Type_Float x = runtime[0].mFloat; @@ -549,7 +549,7 @@ namespace MWScript void execute (Interpreter::Runtime& runtime) override { - std::string itemID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float x = runtime[0].mFloat; @@ -601,7 +601,7 @@ namespace MWScript ? MWMechanics::getPlayer() : R()(runtime); - std::string itemID = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Integer count = runtime[0].mInteger; @@ -641,7 +641,7 @@ namespace MWScript { const MWWorld::Ptr& ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); runtime.pop(); @@ -667,7 +667,7 @@ namespace MWScript { MWWorld::Ptr ptr = R()(runtime); - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); runtime.pop(); @@ -726,7 +726,7 @@ namespace MWScript if (!ptr.isInCell()) return; - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); runtime.pop(); @@ -773,7 +773,7 @@ namespace MWScript if (!ptr.isInCell()) return; - std::string axis = runtime.getStringLiteral (runtime[0].mInteger); + std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger); runtime.pop(); Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); runtime.pop(); diff --git a/apps/openmw/mwsound/soundmanagerimp.cpp b/apps/openmw/mwsound/soundmanagerimp.cpp index 222c95437f..27f4589bb9 100644 --- a/apps/openmw/mwsound/soundmanagerimp.cpp +++ b/apps/openmw/mwsound/soundmanagerimp.cpp @@ -489,7 +489,7 @@ namespace MWSound } - Sound* SoundManager::playSound(const std::string& soundId, float volume, float pitch, Type type, PlayMode mode, float offset) + Sound* SoundManager::playSound(std::string_view soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { if(!mOutput->isInitialized()) return nullptr; @@ -518,7 +518,7 @@ namespace MWSound return result; } - Sound *SoundManager::playSound3D(const MWWorld::ConstPtr &ptr, const std::string& soundId, + Sound *SoundManager::playSound3D(const MWWorld::ConstPtr &ptr, std::string_view soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { @@ -579,7 +579,7 @@ namespace MWSound return result; } - Sound *SoundManager::playSound3D(const osg::Vec3f& initialPos, const std::string& soundId, + Sound *SoundManager::playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, Type type, PlayMode mode, float offset) { @@ -633,7 +633,7 @@ namespace MWSound } } - void SoundManager::stopSound3D(const MWWorld::ConstPtr &ptr, const std::string& soundId) + void SoundManager::stopSound3D(const MWWorld::ConstPtr &ptr, std::string_view soundId) { if(!mOutput->isInitialized()) return; @@ -685,7 +685,7 @@ namespace MWSound } void SoundManager::fadeOutSound3D(const MWWorld::ConstPtr &ptr, - const std::string& soundId, float duration) + std::string_view soundId, float duration) { SoundMap::iterator snditer = mActiveSounds.find(ptr.mRef); if(snditer != mActiveSounds.end()) @@ -701,7 +701,7 @@ namespace MWSound } } - bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr &ptr, const std::string& soundId) const + bool SoundManager::getSoundPlaying(const MWWorld::ConstPtr &ptr, std::string_view soundId) const { SoundMap::const_iterator snditer = mActiveSounds.find(ptr.mRef); if(snditer != mActiveSounds.end()) diff --git a/apps/openmw/mwsound/soundmanagerimp.hpp b/apps/openmw/mwsound/soundmanagerimp.hpp index 4c4df8c0b6..ab74d4acd3 100644 --- a/apps/openmw/mwsound/soundmanagerimp.hpp +++ b/apps/openmw/mwsound/soundmanagerimp.hpp @@ -211,17 +211,17 @@ namespace MWSound /// returned by \ref playTrack). Only intended to be called by the track /// decoder's read method. - Sound *playSound(const std::string& soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) override; + Sound *playSound(std::string_view soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) override; ///< Play a sound, independently of 3D-position ///< @param offset Number of seconds into the sound to start playback. - Sound *playSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, + Sound *playSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId, float volume, float pitch, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal, float offset=0) override; ///< Play a 3D sound attached to an MWWorld::Ptr. Will be updated automatically with the Ptr's position, unless Play_NoTrack is specified. ///< @param offset Number of seconds into the sound to start playback. - Sound *playSound3D(const osg::Vec3f& initialPos, const std::string& soundId, + Sound *playSound3D(const osg::Vec3f& initialPos, std::string_view soundId, float volume, float pitch, Type type, PlayMode mode, float offset=0) override; ///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition. ///< @param offset Number of seconds into the sound to start playback. @@ -230,7 +230,7 @@ namespace MWSound ///< Stop the given sound from playing /// @note no-op if \a sound is null - void stopSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId) override; + void stopSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId) override; ///< Stop the given object from playing the given sound, void stopSound3D(const MWWorld::ConstPtr &reference) override; @@ -239,13 +239,13 @@ namespace MWSound void stopSound(const MWWorld::CellStore *cell) override; ///< Stop all sounds for the given cell. - void fadeOutSound3D(const MWWorld::ConstPtr &reference, const std::string& soundId, float duration) override; + void fadeOutSound3D(const MWWorld::ConstPtr &reference, std::string_view soundId, float duration) override; ///< Fade out given sound (that is already playing) of given object ///< @param reference Reference to object, whose sound is faded out ///< @param soundId ID of the sound to fade out. ///< @param duration Time until volume reaches 0. - bool getSoundPlaying(const MWWorld::ConstPtr &reference, const std::string& soundId) const override; + bool getSoundPlaying(const MWWorld::ConstPtr &reference, std::string_view soundId) const override; ///< Is the given sound currently playing on the given object? void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) override; diff --git a/apps/openmw/mwworld/containerstore.cpp b/apps/openmw/mwworld/containerstore.cpp index a096231f2d..14a19c482c 100644 --- a/apps/openmw/mwworld/containerstore.cpp +++ b/apps/openmw/mwworld/containerstore.cpp @@ -179,7 +179,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end() return ContainerStoreIterator (this); } -int MWWorld::ContainerStore::count(const std::string &id) const +int MWWorld::ContainerStore::count(std::string_view id) const { int total=0; for (const auto&& iter : *this) @@ -278,7 +278,7 @@ bool MWWorld::ContainerStore::stacks(const ConstPtr& ptr1, const ConstPtr& ptr2) && cls2.getItemHealth(ptr2) == cls2.getItemMaxHealth(ptr2))); } -MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(const std::string &id, int count, const Ptr &actorPtr) +MWWorld::ContainerStoreIterator MWWorld::ContainerStore::add(std::string_view id, int count, const Ptr &actorPtr) { MWWorld::ManualRef ref(MWBase::Environment::get().getWorld()->getStore(), id, count); return add(ref.getPtr(), count, actorPtr); @@ -457,7 +457,7 @@ void MWWorld::ContainerStore::updateRechargingItems() } } -int MWWorld::ContainerStore::remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) +int MWWorld::ContainerStore::remove(std::string_view itemId, int count, const Ptr& actor, bool equipReplacement, bool resolveFirst) { if(resolveFirst) resolve(); diff --git a/apps/openmw/mwworld/containerstore.hpp b/apps/openmw/mwworld/containerstore.hpp index 92c28bbcb5..74e46ea5f4 100644 --- a/apps/openmw/mwworld/containerstore.hpp +++ b/apps/openmw/mwworld/containerstore.hpp @@ -175,10 +175,10 @@ namespace MWWorld /// /// @return if stacking happened, return iterator to the item that was stacked against, otherwise iterator to the newly inserted item. - ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr); + ContainerStoreIterator add(std::string_view id, int count, const Ptr& actorPtr); ///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) - int remove(const std::string& itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); + int remove(std::string_view itemId, int count, const Ptr& actor, bool equipReplacement = 0, bool resolve = true); ///< Remove \a count item(s) designated by \a itemId from this container. /// /// @return the number of items actually removed @@ -201,7 +201,7 @@ namespace MWWorld /// If a compatible stack is found, the item's count is added to that stack, then the original is deleted. /// @return If the item was stacked, return the stack, otherwise return the old (untouched) item. - int count (const std::string& id) const; + int count(std::string_view id) const; ///< @return How many items with refID \a id are in this container? ContainerStoreListener* getContListener() const; diff --git a/apps/openmw/mwworld/datetimemanager.cpp b/apps/openmw/mwworld/datetimemanager.cpp index 0894c974d3..67d1ce1fbc 100644 --- a/apps/openmw/mwworld/datetimemanager.cpp +++ b/apps/openmw/mwworld/datetimemanager.cpp @@ -159,7 +159,7 @@ namespace MWWorld return setting->mValue.getString(); } - bool DateTimeManager::updateGlobalFloat(const std::string& name, float value) + bool DateTimeManager::updateGlobalFloat(std::string_view name, float value) { if (name=="gamehour") { @@ -192,7 +192,7 @@ namespace MWWorld return false; } - bool DateTimeManager::updateGlobalInt(const std::string& name, int value) + bool DateTimeManager::updateGlobalInt(std::string_view name, int value) { if (name=="gamehour") { diff --git a/apps/openmw/mwworld/datetimemanager.hpp b/apps/openmw/mwworld/datetimemanager.hpp index b460be746a..e48eec5184 100644 --- a/apps/openmw/mwworld/datetimemanager.hpp +++ b/apps/openmw/mwworld/datetimemanager.hpp @@ -35,8 +35,8 @@ namespace MWWorld void advanceTime(double hours, Globals& globalVariables); void setup(Globals& globalVariables); - bool updateGlobalInt(const std::string& name, int value); - bool updateGlobalFloat(const std::string& name, float value); + bool updateGlobalInt(std::string_view name, int value); + bool updateGlobalFloat(std::string_view name, float value); }; } diff --git a/apps/openmw/mwworld/globals.cpp b/apps/openmw/mwworld/globals.cpp index cb1d26cb71..5b236996b3 100644 --- a/apps/openmw/mwworld/globals.cpp +++ b/apps/openmw/mwworld/globals.cpp @@ -10,22 +10,22 @@ namespace MWWorld { - Globals::Collection::const_iterator Globals::find (const std::string& name) const + Globals::Collection::const_iterator Globals::find (std::string_view name) const { Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); if (iter==mVariables.end()) - throw std::runtime_error ("unknown global variable: " + name); + throw std::runtime_error ("unknown global variable: " + std::string{name}); return iter; } - Globals::Collection::iterator Globals::find (const std::string& name) + Globals::Collection::iterator Globals::find (std::string_view name) { Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); if (iter==mVariables.end()) - throw std::runtime_error ("unknown global variable: " + name); + throw std::runtime_error ("unknown global variable: " + std::string{name}); return iter; } @@ -42,17 +42,17 @@ namespace MWWorld } } - const ESM::Variant& Globals::operator[] (const std::string& name) const + const ESM::Variant& Globals::operator[] (std::string_view name) const { return find (Misc::StringUtils::lowerCase (name))->second.mValue; } - ESM::Variant& Globals::operator[] (const std::string& name) + ESM::Variant& Globals::operator[] (std::string_view name) { return find (Misc::StringUtils::lowerCase (name))->second.mValue; } - char Globals::getType (const std::string& name) const + char Globals::getType (std::string_view name) const { Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name)); diff --git a/apps/openmw/mwworld/globals.hpp b/apps/openmw/mwworld/globals.hpp index 85cb7c39ce..ff9caadd73 100644 --- a/apps/openmw/mwworld/globals.hpp +++ b/apps/openmw/mwworld/globals.hpp @@ -32,17 +32,17 @@ namespace MWWorld Collection mVariables; // type, value - Collection::const_iterator find (const std::string& name) const; + Collection::const_iterator find (std::string_view name) const; - Collection::iterator find (const std::string& name); + Collection::iterator find (std::string_view name); public: - const ESM::Variant& operator[] (const std::string& name) const; + const ESM::Variant& operator[] (std::string_view name) const; - ESM::Variant& operator[] (const std::string& name); + ESM::Variant& operator[] (std::string_view name); - char getType (const std::string& name) const; + char getType (std::string_view name) const; ///< If there is no global variable with this name, ' ' is returned. void fill (const MWWorld::ESMStore& store); diff --git a/apps/openmw/mwworld/manualref.cpp b/apps/openmw/mwworld/manualref.cpp index 7f7fd60335..6afb3e4142 100644 --- a/apps/openmw/mwworld/manualref.cpp +++ b/apps/openmw/mwworld/manualref.cpp @@ -30,7 +30,7 @@ namespace } } -MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, const std::string& name, const int count) +MWWorld::ManualRef::ManualRef(const MWWorld::ESMStore& store, std::string_view name, const int count) { std::string lowerName = Misc::StringUtils::lowerCase(name); switch (store.find(lowerName)) diff --git a/apps/openmw/mwworld/manualref.hpp b/apps/openmw/mwworld/manualref.hpp index 2fc5994710..84aa0751f2 100644 --- a/apps/openmw/mwworld/manualref.hpp +++ b/apps/openmw/mwworld/manualref.hpp @@ -17,7 +17,7 @@ namespace MWWorld ManualRef& operator= (const ManualRef&); public: - ManualRef(const MWWorld::ESMStore& store, const std::string& name, const int count = 1); + ManualRef(const MWWorld::ESMStore& store, std::string_view name, const int count = 1); const Ptr& getPtr() const { diff --git a/apps/openmw/mwworld/worldimp.cpp b/apps/openmw/mwworld/worldimp.cpp index 8c1eb40c41..6b9930a989 100644 --- a/apps/openmw/mwworld/worldimp.cpp +++ b/apps/openmw/mwworld/worldimp.cpp @@ -656,7 +656,7 @@ namespace MWWorld return mWorldScene->hasCellChanged(); } - void World::setGlobalInt (const std::string& name, int value) + void World::setGlobalInt(std::string_view name, int value) { bool dateUpdated = mCurrentDate->updateGlobalInt(name, value); if (dateUpdated) @@ -665,7 +665,7 @@ namespace MWWorld mGlobalVariables[name].setInteger (value); } - void World::setGlobalFloat (const std::string& name, float value) + void World::setGlobalFloat(std::string_view name, float value) { bool dateUpdated = mCurrentDate->updateGlobalFloat(name, value); if (dateUpdated) @@ -674,17 +674,17 @@ namespace MWWorld mGlobalVariables[name].setFloat(value); } - int World::getGlobalInt (const std::string& name) const + int World::getGlobalInt(std::string_view name) const { return mGlobalVariables[name].getInteger(); } - float World::getGlobalFloat (const std::string& name) const + float World::getGlobalFloat(std::string_view name) const { return mGlobalVariables[name].getFloat(); } - char World::getGlobalVariableType (const std::string& name) const + char World::getGlobalVariableType (std::string_view name) const { return mGlobalVariables.getType (name); } @@ -719,7 +719,7 @@ namespace MWWorld mLocalScripts.remove (ref); } - Ptr World::searchPtr (const std::string& name, bool activeOnly, bool searchInContainers) + Ptr World::searchPtr (std::string_view name, bool activeOnly, bool searchInContainers) { Ptr ret; // the player is always in an active cell. @@ -762,12 +762,12 @@ namespace MWWorld return ptr; } - Ptr World::getPtr (const std::string& name, bool activeOnly) + Ptr World::getPtr (std::string_view name, bool activeOnly) { Ptr ret = searchPtr(name, activeOnly); if (!ret.isEmpty()) return ret; - std::string error = "failed to find an instance of object '" + name + "'"; + std::string error = "failed to find an instance of object '" + std::string(name) + "'"; if (activeOnly) error += " in active cells"; throw std::runtime_error(error); diff --git a/apps/openmw/mwworld/worldimp.hpp b/apps/openmw/mwworld/worldimp.hpp index 088c4097aa..c6e316c25a 100644 --- a/apps/openmw/mwworld/worldimp.hpp +++ b/apps/openmw/mwworld/worldimp.hpp @@ -258,19 +258,19 @@ namespace MWWorld void getDoorMarkers (MWWorld::CellStore* cell, std::vector& out) override; ///< get a list of teleport door markers for a given cell, to be displayed on the local map - void setGlobalInt (const std::string& name, int value) override; + void setGlobalInt(std::string_view name, int value) override; ///< Set value independently from real type. - void setGlobalFloat (const std::string& name, float value) override; + void setGlobalFloat(std::string_view name, float value) override; ///< Set value independently from real type. - int getGlobalInt (const std::string& name) const override; + int getGlobalInt(std::string_view name) const override; ///< Get value independently from real type. - float getGlobalFloat (const std::string& name) const override; + float getGlobalFloat(std::string_view name) const override; ///< Get value independently from real type. - char getGlobalVariableType (const std::string& name) const override; + char getGlobalVariableType(std::string_view name) const override; ///< Return ' ', if there is no global variable with this name. std::string getCellName (const MWWorld::CellStore *cell = nullptr) const override; @@ -283,11 +283,11 @@ namespace MWWorld void removeRefScript (MWWorld::RefData *ref) override; //< Remove the script attached to ref from mLocalScripts - Ptr getPtr (const std::string& name, bool activeOnly) override; + Ptr getPtr (std::string_view name, bool activeOnly) override; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do non search inactive cells. - Ptr searchPtr (const std::string& name, bool activeOnly, bool searchInContainers = false) override; + Ptr searchPtr (std::string_view name, bool activeOnly, bool searchInContainers = false) override; ///< Return a pointer to a liveCellRef with the given name. /// \param activeOnly do not search inactive cells. diff --git a/apps/openmw_test_suite/mwscript/test_utils.hpp b/apps/openmw_test_suite/mwscript/test_utils.hpp index f29cb7bb89..15f2fae661 100644 --- a/apps/openmw_test_suite/mwscript/test_utils.hpp +++ b/apps/openmw_test_suite/mwscript/test_utils.hpp @@ -102,12 +102,12 @@ namespace class GlobalVariables { - std::map mShorts; - std::map mLongs; - std::map mFloats; + std::map> mShorts; + std::map> mLongs; + std::map> mFloats; template - T getGlobal(const std::string& name, const std::map& map) const + T getGlobal(std::string_view name, const std::map>& map) const { auto it = map.find(name); if(it != map.end()) @@ -122,23 +122,23 @@ namespace mFloats.clear(); } - int getShort(const std::string& name) const { return getGlobal(name, mShorts); }; + int getShort(std::string_view name) const { return getGlobal(name, mShorts); }; - int getLong(const std::string& name) const { return getGlobal(name, mLongs); }; + int getLong(std::string_view name) const { return getGlobal(name, mLongs); }; - float getFloat(const std::string& name) const { return getGlobal(name, mFloats); }; + float getFloat(std::string_view name) const { return getGlobal(name, mFloats); }; - void setShort(const std::string& name, int value) { mShorts[name] = value; }; + void setShort(std::string_view name, int value) { mShorts[std::string(name)] = value; }; - void setLong(const std::string& name, int value) { mLongs[name] = value; }; + void setLong(std::string_view name, int value) { mLongs[std::string(name)] = value; }; - void setFloat(const std::string& name, float value) { mFloats[name] = value; }; + void setFloat(std::string_view name, float value) { mFloats[std::string(name)] = value; }; }; class TestInterpreterContext : public Interpreter::Context { LocalVariables mLocals; - std::map mMembers; + std::map> mMembers; public: std::string getTarget() const override { return {}; }; @@ -158,23 +158,23 @@ namespace void report(const std::string& message) override {}; - int getGlobalShort(const std::string& name) const override { return {}; }; + int getGlobalShort(std::string_view name) const override { return {}; }; - int getGlobalLong(const std::string& name) const override { return {}; }; + int getGlobalLong(std::string_view name) const override { return {}; }; - float getGlobalFloat(const std::string& name) const override { return {}; }; + float getGlobalFloat(std::string_view name) const override { return {}; }; - void setGlobalShort(const std::string& name, int value) override {}; + void setGlobalShort(std::string_view name, int value) override {}; - void setGlobalLong(const std::string& name, int value) override {}; + void setGlobalLong(std::string_view name, int value) override {}; - void setGlobalFloat(const std::string& name, float value) override {}; + void setGlobalFloat(std::string_view name, float value) override {}; std::vector getGlobals() const override { return {}; }; - char getGlobalType(const std::string& name) const override { return ' '; }; + char getGlobalType(std::string_view name) const override { return ' '; }; - std::string getActionBinding(const std::string& action) const override { return {}; }; + std::string getActionBinding(std::string_view action) const override { return {}; }; std::string getActorName() const override { return {}; }; @@ -200,7 +200,7 @@ namespace std::string getCurrentCellName() const override { return {}; }; - int getMemberShort(const std::string& id, const std::string& name, bool global) const override + int getMemberShort(std::string_view id, std::string_view name, bool global) const override { auto it = mMembers.find(id); if(it != mMembers.end()) @@ -208,7 +208,7 @@ namespace return {}; }; - int getMemberLong(const std::string& id, const std::string& name, bool global) const override + int getMemberLong(std::string_view id, std::string_view name, bool global) const override { auto it = mMembers.find(id); if(it != mMembers.end()) @@ -216,7 +216,7 @@ namespace return {}; }; - float getMemberFloat(const std::string& id, const std::string& name, bool global) const override + float getMemberFloat(std::string_view id, std::string_view name, bool global) const override { auto it = mMembers.find(id); if(it != mMembers.end()) @@ -224,11 +224,11 @@ namespace return {}; }; - void setMemberShort(const std::string& id, const std::string& name, int value, bool global) override { mMembers[id].setShort(name, value); }; + void setMemberShort(std::string_view id, std::string_view name, int value, bool global) override { mMembers[std::string(id)].setShort(name, value); }; - void setMemberLong(const std::string& id, const std::string& name, int value, bool global) override { mMembers[id].setLong(name, value); }; + void setMemberLong(std::string_view id, std::string_view name, int value, bool global) override { mMembers[std::string(id)].setLong(name, value); }; - void setMemberFloat(const std::string& id, const std::string& name, float value, bool global) override { mMembers[id].setFloat(name, value); }; + void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) override { mMembers[std::string(id)].setFloat(name, value); }; }; struct CompiledScript diff --git a/components/compiler/lineparser.hpp b/components/compiler/lineparser.hpp index 2a0e5d6630..2fd113478f 100644 --- a/components/compiler/lineparser.hpp +++ b/components/compiler/lineparser.hpp @@ -86,7 +86,7 @@ namespace Compiler void visitedCharacter(char c) override {} public: - void process(const std::string& message) override + void process(std::string_view message) override { mArguments.clear(); ::Misc::MessageFormatParser::process(message); diff --git a/components/compiler/locals.cpp b/components/compiler/locals.cpp index f31acb1a8b..8492b8649e 100644 --- a/components/compiler/locals.cpp +++ b/components/compiler/locals.cpp @@ -21,7 +21,7 @@ namespace Compiler throw std::logic_error ("Unknown variable type"); } - int Locals::searchIndex (char type, const std::string& name) const + int Locals::searchIndex (char type, std::string_view name) const { const std::vector& collection = get (type); @@ -33,7 +33,7 @@ namespace Compiler return static_cast(iter-collection.begin()); } - bool Locals::search (char type, const std::string& name) const + bool Locals::search (char type, std::string_view name) const { return searchIndex (type, name)!=-1; } @@ -50,7 +50,7 @@ namespace Compiler throw std::logic_error ("Unknown variable type"); } - char Locals::getType (const std::string& name) const + char Locals::getType (std::string_view name) const { if (search ('s', name)) return 's'; @@ -64,7 +64,7 @@ namespace Compiler return ' '; } - int Locals::getIndex (const std::string& name) const + int Locals::getIndex (std::string_view name) const { int index = searchIndex ('s', name); @@ -94,7 +94,7 @@ namespace Compiler std::ostream_iterator (localFile, " ")); } - void Locals::declare (char type, const std::string& name) + void Locals::declare (char type, std::string_view name) { get (type).push_back (Misc::StringUtils::lowerCase (name)); } diff --git a/components/compiler/locals.hpp b/components/compiler/locals.hpp index 1b2ae60426..c7636ed2a0 100644 --- a/components/compiler/locals.hpp +++ b/components/compiler/locals.hpp @@ -3,6 +3,7 @@ #include #include +#include #include namespace Compiler @@ -19,24 +20,24 @@ namespace Compiler public: - char getType (const std::string& name) const; + char getType (std::string_view name) const; ///< 's': short, 'l': long, 'f': float, ' ': does not exist. - int getIndex (const std::string& name) const; + int getIndex (std::string_view name) const; ///< return index for local variable \a name (-1: does not exist). - bool search (char type, const std::string& name) const; + bool search (char type, std::string_view name) const; /// Return index for local variable \a name of type \a type (-1: variable does not /// exit). - int searchIndex (char type, const std::string& name) const; + int searchIndex (char type, std::string_view name) const; const std::vector& get (char type) const; void write (std::ostream& localFile) const; ///< write declarations to file. - void declare (char type, const std::string& name); + void declare (char type, std::string_view name); ///< declares a variable. void clear(); diff --git a/components/esm3/loadmgef.cpp b/components/esm3/loadmgef.cpp index 9707f2f255..5fb88a3606 100644 --- a/components/esm3/loadmgef.cpp +++ b/components/esm3/loadmgef.cpp @@ -533,10 +533,10 @@ const std::string &MagicEffect::effectIdToString(short effectID) } class FindSecond { - const std::string &mName; + std::string_view mName; public: - FindSecond(const std::string &name) : mName(name) { } + FindSecond(std::string_view name) : mName(name) { } bool operator()(const std::pair &item) const { @@ -546,13 +546,13 @@ public: } }; -short MagicEffect::effectStringToId(const std::string &effect) +short MagicEffect::effectStringToId(std::string_view effect) { std::map::const_iterator name; name = std::find_if(sNames.begin(), sNames.end(), FindSecond(effect)); if(name == sNames.end()) - throw std::runtime_error(std::string("Unimplemented effect ")+effect); + throw std::runtime_error("Unimplemented effect " + std::string(effect)); return name->first; } diff --git a/components/esm3/loadmgef.hpp b/components/esm3/loadmgef.hpp index 64d89dab39..b9151f5d33 100644 --- a/components/esm3/loadmgef.hpp +++ b/components/esm3/loadmgef.hpp @@ -2,6 +2,7 @@ #define OPENMW_ESM_MGEF_H #include +#include #include namespace ESM @@ -70,7 +71,7 @@ struct MagicEffect static const std::map sNames; static const std::string &effectIdToString(short effectID); - static short effectStringToId(const std::string &effect); + static short effectStringToId(std::string_view effect); /// Returns the effect that provides resistance against \a effect (or -1 if there's none) static short getResistanceEffect(short effect); diff --git a/components/interpreter/context.hpp b/components/interpreter/context.hpp index 18d36ffee9..df97bcf232 100644 --- a/components/interpreter/context.hpp +++ b/components/interpreter/context.hpp @@ -2,6 +2,7 @@ #define INTERPRETER_CONTEXT_H_INCLUDED #include +#include #include namespace Interpreter @@ -37,23 +38,23 @@ namespace Interpreter virtual void report (const std::string& message) = 0; - virtual int getGlobalShort (const std::string& name) const = 0; + virtual int getGlobalShort(std::string_view name) const = 0; - virtual int getGlobalLong (const std::string& name) const = 0; + virtual int getGlobalLong(std::string_view name) const = 0; - virtual float getGlobalFloat (const std::string& name) const = 0; + virtual float getGlobalFloat(std::string_view name) const = 0; - virtual void setGlobalShort (const std::string& name, int value) = 0; + virtual void setGlobalShort(std::string_view name, int value) = 0; - virtual void setGlobalLong (const std::string& name, int value) = 0; + virtual void setGlobalLong(std::string_view name, int value) = 0; - virtual void setGlobalFloat (const std::string& name, float value) = 0; + virtual void setGlobalFloat(std::string_view name, float value) = 0; virtual std::vector getGlobals () const = 0; - virtual char getGlobalType (const std::string& name) const = 0; + virtual char getGlobalType(std::string_view name) const = 0; - virtual std::string getActionBinding(const std::string& action) const = 0; + virtual std::string getActionBinding(std::string_view action) const = 0; virtual std::string getActorName() const = 0; @@ -79,17 +80,17 @@ namespace Interpreter virtual std::string getCurrentCellName() const = 0; - virtual int getMemberShort (const std::string& id, const std::string& name, bool global) const = 0; + virtual int getMemberShort(std::string_view id, std::string_view name, bool global) const = 0; - virtual int getMemberLong (const std::string& id, const std::string& name, bool global) const = 0; + virtual int getMemberLong(std::string_view id, std::string_view name, bool global) const = 0; - virtual float getMemberFloat (const std::string& id, const std::string& name, bool global) const = 0; + virtual float getMemberFloat(std::string_view id, std::string_view name, bool global) const = 0; - virtual void setMemberShort (const std::string& id, const std::string& name, int value, bool global) = 0; + virtual void setMemberShort(std::string_view id, std::string_view name, int value, bool global) = 0; - virtual void setMemberLong (const std::string& id, const std::string& name, int value, bool global) = 0; + virtual void setMemberLong(std::string_view id, std::string_view name, int value, bool global) = 0; - virtual void setMemberFloat (const std::string& id, const std::string& name, float value, bool global) + virtual void setMemberFloat(std::string_view id, std::string_view name, float value, bool global) = 0; }; } diff --git a/components/interpreter/interpreter.cpp b/components/interpreter/interpreter.cpp index 69f3111440..7047dec05f 100644 --- a/components/interpreter/interpreter.cpp +++ b/components/interpreter/interpreter.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "opcodes.hpp" diff --git a/components/interpreter/localopcodes.hpp b/components/interpreter/localopcodes.hpp index 72a730ae99..6fe779493f 100644 --- a/components/interpreter/localopcodes.hpp +++ b/components/interpreter/localopcodes.hpp @@ -122,7 +122,7 @@ namespace Interpreter Type_Integer data = runtime[0].mInteger; int index = runtime[1].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); runtime.getContext().setGlobalShort (name, data); @@ -140,7 +140,7 @@ namespace Interpreter Type_Integer data = runtime[0].mInteger; int index = runtime[1].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); runtime.getContext().setGlobalLong (name, data); @@ -158,7 +158,7 @@ namespace Interpreter Type_Float data = runtime[0].mFloat; int index = runtime[1].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); runtime.getContext().setGlobalFloat (name, data); @@ -174,7 +174,7 @@ namespace Interpreter void execute (Runtime& runtime) override { int index = runtime[0].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); Type_Integer value = runtime.getContext().getGlobalShort (name); runtime[0].mInteger = value; } @@ -187,7 +187,7 @@ namespace Interpreter void execute (Runtime& runtime) override { int index = runtime[0].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); Type_Integer value = runtime.getContext().getGlobalLong (name); runtime[0].mInteger = value; } @@ -200,7 +200,7 @@ namespace Interpreter void execute (Runtime& runtime) override { int index = runtime[0].mInteger; - std::string name = runtime.getStringLiteral (index); + std::string_view name = runtime.getStringLiteral (index); Type_Float value = runtime.getContext().getGlobalFloat (name); runtime[0].mFloat = value; } @@ -215,9 +215,9 @@ namespace Interpreter { Type_Integer data = runtime[0].mInteger; Type_Integer index = runtime[1].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[2].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.getContext().setMemberShort (id, variable, data, TGlobal); @@ -236,9 +236,9 @@ namespace Interpreter { Type_Integer data = runtime[0].mInteger; Type_Integer index = runtime[1].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[2].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.getContext().setMemberLong (id, variable, data, TGlobal); @@ -257,9 +257,9 @@ namespace Interpreter { Type_Float data = runtime[0].mFloat; Type_Integer index = runtime[1].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[2].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.getContext().setMemberFloat (id, variable, data, TGlobal); @@ -277,9 +277,9 @@ namespace Interpreter void execute (Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[1].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.pop(); int value = runtime.getContext().getMemberShort (id, variable, TGlobal); @@ -295,9 +295,9 @@ namespace Interpreter void execute (Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[1].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.pop(); int value = runtime.getContext().getMemberLong (id, variable, TGlobal); @@ -313,9 +313,9 @@ namespace Interpreter void execute (Runtime& runtime) override { Type_Integer index = runtime[0].mInteger; - std::string id = runtime.getStringLiteral (index); + std::string_view id = runtime.getStringLiteral (index); index = runtime[1].mInteger; - std::string variable = runtime.getStringLiteral (index); + std::string_view variable = runtime.getStringLiteral (index); runtime.pop(); float value = runtime.getContext().getMemberFloat (id, variable, TGlobal); diff --git a/components/interpreter/miscopcodes.hpp b/components/interpreter/miscopcodes.hpp index 5a9311346a..32b4df2e47 100644 --- a/components/interpreter/miscopcodes.hpp +++ b/components/interpreter/miscopcodes.hpp @@ -97,7 +97,7 @@ namespace Interpreter { } - void process(const std::string& message) override + void process(std::string_view message) override { mFormattedMessage.clear(); MessageFormatParser::process(message); @@ -109,7 +109,7 @@ namespace Interpreter } }; - inline std::string formatMessage (const std::string& message, Runtime& runtime) + inline std::string formatMessage (std::string_view message, Runtime& runtime) { RuntimeMessageFormatter formatter(runtime); formatter.process(message); @@ -128,7 +128,7 @@ namespace Interpreter // message int index = runtime[0].mInteger; runtime.pop(); - std::string message = runtime.getStringLiteral (index); + std::string_view message = runtime.getStringLiteral (index); // buttons std::vector buttons; @@ -137,7 +137,7 @@ namespace Interpreter { index = runtime[0].mInteger; runtime.pop(); - buttons.push_back (runtime.getStringLiteral (index)); + buttons.emplace_back(runtime.getStringLiteral(index)); } std::reverse (buttons.begin(), buttons.end()); @@ -158,7 +158,7 @@ namespace Interpreter // message int index = runtime[0].mInteger; runtime.pop(); - std::string message = runtime.getStringLiteral (index); + std::string_view message = runtime.getStringLiteral (index); // handle additional parameters std::string formattedMessage = formatMessage (message, runtime); diff --git a/components/interpreter/runtime.cpp b/components/interpreter/runtime.cpp index 8170526f35..d5bedfba57 100644 --- a/components/interpreter/runtime.cpp +++ b/components/interpreter/runtime.cpp @@ -33,7 +33,7 @@ namespace Interpreter return *reinterpret_cast (&literalBlock[index]); } - std::string Runtime::getStringLiteral (int index) const + std::string_view Runtime::getStringLiteral(int index) const { if (index < 0 || static_cast (mCode[3]) <= 0) throw std::out_of_range("out of range"); @@ -41,12 +41,12 @@ namespace Interpreter const char *literalBlock = reinterpret_cast (mCode + 4 + mCode[0] + mCode[1] + mCode[2]); - int offset = 0; + size_t offset = 0; for (; index; --index) { - offset += static_cast(std::strlen (literalBlock+offset)) + 1; - if (offset / 4 >= static_cast (mCode[3])) + offset += std::strlen(literalBlock + offset) + 1; + if (offset / 4 >= mCode[3]) throw std::out_of_range("out of range"); } diff --git a/components/interpreter/runtime.hpp b/components/interpreter/runtime.hpp index 2811ab0f0c..7f48ca8d3e 100644 --- a/components/interpreter/runtime.hpp +++ b/components/interpreter/runtime.hpp @@ -2,7 +2,7 @@ #define INTERPRETER_RUNTIME_H_INCLUDED #include -#include +#include #include "types.hpp" @@ -31,7 +31,7 @@ namespace Interpreter float getFloatLiteral (int index) const; - std::string getStringLiteral (int index) const; + std::string_view getStringLiteral(int index) const; void configure (const Type_Code *code, int codeSize, Context& context); ///< \a context and \a code must exist as least until either configure, clear or diff --git a/components/misc/messageformatparser.cpp b/components/misc/messageformatparser.cpp index 6f0e471325..a40dcccd52 100644 --- a/components/misc/messageformatparser.cpp +++ b/components/misc/messageformatparser.cpp @@ -4,7 +4,7 @@ namespace Misc { MessageFormatParser::~MessageFormatParser() {} - void MessageFormatParser::process(const std::string& m) + void MessageFormatParser::process(std::string_view m) { for (unsigned int i = 0; i < m.size(); ++i) { diff --git a/components/misc/messageformatparser.hpp b/components/misc/messageformatparser.hpp index db2a8b0af4..4ceac2be2f 100644 --- a/components/misc/messageformatparser.hpp +++ b/components/misc/messageformatparser.hpp @@ -1,7 +1,7 @@ #ifndef OPENMW_COMPONENTS_MISC_MESSAGEFORMATPARSER_H #define OPENMW_COMPONENTS_MISC_MESSAGEFORMATPARSER_H -#include +#include namespace Misc { @@ -28,7 +28,7 @@ namespace Misc public: virtual ~MessageFormatParser(); - virtual void process(const std::string& message); + virtual void process(std::string_view message); }; }