1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-03-03 19:39:41 +00:00

Make getStringLiteral return a string_view

This commit is contained in:
Evil Eye 2022-05-21 01:21:55 +02:00
parent 58207fc1e3
commit c6ca0e78c9
48 changed files with 356 additions and 348 deletions

View file

@ -55,9 +55,9 @@ namespace MWBase
virtual bool inJournal (const std::string& topicId, const std::string& infoId) = 0; 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<std::pair<std::string, int> >& getChoices() = 0; virtual const std::vector<std::pair<std::string, int> >& getChoices() = 0;
virtual bool isGoodbye() = 0; virtual bool isGoodbye() = 0;
@ -105,12 +105,12 @@ namespace MWBase
virtual void readRecord (ESM::ESMReader& reader, uint32_t type) = 0; virtual void readRecord (ESM::ESMReader& reader, uint32_t type) = 0;
/// Changes faction1's opinion of faction2 by \a diff. /// 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 /// @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 /// Removes the last added topic response for the given actor from the journal
virtual void clearInfoActor (const MWWorld::Ptr& actor) const = 0; virtual void clearInfoActor (const MWWorld::Ptr& actor) const = 0;

View file

@ -128,19 +128,19 @@ namespace MWBase
/// returned by \ref playTrack). Only intended to be called by the track /// returned by \ref playTrack). Only intended to be called by the track
/// decoder's read method. /// 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, Type type=Type::Sfx, PlayMode mode=PlayMode::Normal,
float offset=0) = 0; float offset=0) = 0;
///< Play a sound, independently of 3D-position ///< Play a sound, independently of 3D-position
///< @param offset Number of seconds into the sound to start playback. ///< @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, float volume, float pitch, Type type=Type::Sfx,
PlayMode mode=PlayMode::Normal, float offset=0) = 0; 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. ///< 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. ///< @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, float volume, float pitch, Type type=Type::Sfx,
PlayMode mode=PlayMode::Normal, float offset=0) = 0; 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. ///< Play a 3D sound at \a initialPos. If the sound should be moving, it must be updated using Sound::setPosition.
@ -148,7 +148,7 @@ namespace MWBase
virtual void stopSound(Sound *sound) = 0; virtual void stopSound(Sound *sound) = 0;
///< Stop the given sound from playing ///< 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, ///< Stop the given object from playing the given sound,
virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0; virtual void stopSound3D(const MWWorld::ConstPtr &reference) = 0;
@ -157,13 +157,13 @@ namespace MWBase
virtual void stopSound(const MWWorld::CellStore *cell) = 0; virtual void stopSound(const MWWorld::CellStore *cell) = 0;
///< Stop all sounds for the given cell. ///< 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 ///< Fade out given sound (that is already playing) of given object
///< @param reference Reference to object, whose sound is faded out ///< @param reference Reference to object, whose sound is faded out
///< @param soundId ID of the sound to fade out. ///< @param soundId ID of the sound to fade out.
///< @param duration Time until volume reaches 0. ///< @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? ///< 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 /// If you want to check if sound played with playSound is playing, use empty Ptr

View file

@ -174,19 +174,19 @@ namespace MWBase
virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) = 0; virtual void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) = 0;
///< get a list of teleport door markers for a given cell, to be displayed on the local map ///< 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. ///< 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. ///< 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. ///< 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. ///< 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. ///< Return ' ', if there is no global variable with this name.
virtual std::string getCellName (const MWWorld::CellStore *cell = nullptr) const = 0; virtual std::string getCellName (const MWWorld::CellStore *cell = nullptr) const = 0;
@ -199,11 +199,11 @@ namespace MWBase
virtual void removeRefScript (MWWorld::RefData *ref) = 0; virtual void removeRefScript (MWWorld::RefData *ref) = 0;
//< Remove the script attached to ref from mLocalScripts //< 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. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells. /// \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. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells. /// \param activeOnly do non search inactive cells.

View file

@ -71,7 +71,7 @@ namespace MWDialogue
mPermanentDispositionChange = 0; mPermanentDispositionChange = 0;
} }
void DialogueManager::addTopic (const std::string& topic) void DialogueManager::addTopic(std::string_view topic)
{ {
mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) ); mKnownTopics.insert( Misc::StringUtils::lowerCase(topic) );
} }
@ -516,10 +516,10 @@ namespace MWDialogue
updateActorKnownTopics(); updateActorKnownTopics();
} }
void DialogueManager::addChoice (const std::string& text, int choice) void DialogueManager::addChoice(std::string_view text, int choice)
{ {
mIsInChoice = true; mIsInChoice = true;
mChoices.emplace_back(text, choice); mChoices.emplace_back(std::string{text.begin(), text.end()}, choice);
} }
const std::vector<std::pair<std::string, int> >& DialogueManager::getChoices() const std::vector<std::pair<std::string, int> >& DialogueManager::getChoices()
@ -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 fact1 = Misc::StringUtils::lowerCase(faction1);
std::string fact2 = Misc::StringUtils::lowerCase(faction2); std::string fact2 = Misc::StringUtils::lowerCase(faction2);
@ -719,7 +719,7 @@ namespace MWDialogue
map[fact2] = newValue; 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 fact1 = Misc::StringUtils::lowerCase(faction1);
std::string fact2 = Misc::StringUtils::lowerCase(faction2); std::string fact2 = Misc::StringUtils::lowerCase(faction2);
@ -732,7 +732,7 @@ namespace MWDialogue
map[fact2] = absolute; 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 fact1 = Misc::StringUtils::lowerCase(faction1);
std::string fact2 = Misc::StringUtils::lowerCase(faction2); std::string fact2 = Misc::StringUtils::lowerCase(faction2);

View file

@ -87,9 +87,9 @@ namespace MWDialogue
bool inJournal (const std::string& topicId, const std::string& infoId) override; 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<std::pair<std::string, int> >& getChoices() override; const std::vector<std::pair<std::string, int> >& getChoices() override;
bool isGoodbye() override; bool isGoodbye() override;
@ -117,12 +117,12 @@ namespace MWDialogue
void readRecord (ESM::ESMReader& reader, uint32_t type) override; void readRecord (ESM::ESMReader& reader, uint32_t type) override;
/// Changes faction1's opinion of faction2 by \a diff. /// 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 /// @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 /// Removes the last added topic response for the given actor from the journal
void clearInfoActor (const MWWorld::Ptr& actor) const override; void clearInfoActor (const MWWorld::Ptr& actor) const override;

View file

@ -333,7 +333,7 @@ namespace MWMechanics
return mSpells.end(); 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) return std::find_if(mSpells.begin(), mSpells.end(), [&] (const auto& spell)
{ {
@ -434,7 +434,7 @@ namespace MWMechanics
return removedCurrentSpell; 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) purge([=] (const ActiveSpellParams& params)
{ {

View file

@ -127,7 +127,7 @@ namespace MWMechanics
void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor); void addSpell(const ESM::Spell* spell, const MWWorld::Ptr& actor);
/// Removes the active effects from this spell/potion/.. with \a id /// 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 /// Remove all active effects with this effect id
void purgeEffect (const MWWorld::Ptr& ptr, short effectId); void purgeEffect (const MWWorld::Ptr& ptr, short effectId);
@ -141,7 +141,7 @@ namespace MWMechanics
/// Remove all spells /// Remove all spells
void clear(const MWWorld::Ptr& ptr); void clear(const MWWorld::Ptr& ptr);
bool isSpellActive (const std::string& id) const; bool isSpellActive (std::string_view id) const;
///< case insensitive ///< case insensitive
void skipWorsenings(double hours); void skipWorsenings(double hours);

View file

@ -45,7 +45,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
// The value of the reset argument doesn't actually matter // The value of the reset argument doesn't actually matter
@ -102,7 +102,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat; Interpreter::Type_Float duration = runtime[0].mFloat;
@ -140,10 +140,10 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat; Interpreter::Type_Float duration = runtime[0].mFloat;
@ -168,7 +168,7 @@ namespace MWScript
if (cellID.empty()) if (cellID.empty())
return; return;
if (!MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>().search(cellID)) if (!MWBase::Environment::get().getWorld()->getStore().get<ESM::Cell>().search({cellID.begin(), cellID.end()}))
return; return;
MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat); MWMechanics::AiEscort escortPackage(actorID, cellID, static_cast<int>(duration), x, y, z, repeat);
@ -320,7 +320,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat; Interpreter::Type_Float duration = runtime[0].mFloat;
@ -358,10 +358,10 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view cellID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float duration = runtime[0].mFloat; Interpreter::Type_Float duration = runtime[0].mFloat;
@ -421,7 +421,7 @@ namespace MWScript
{ {
MWWorld::Ptr observer = R()(runtime, false); // required=false 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(); runtime.pop();
MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false); MWWorld::Ptr actor = MWBase::Environment::get().getWorld()->searchPtr(actorID, true, false);
@ -444,7 +444,7 @@ namespace MWScript
MWWorld::Ptr source = R()(runtime); MWWorld::Ptr source = R()(runtime);
std::string actorID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view actorID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
@ -465,7 +465,7 @@ namespace MWScript
void execute (Interpreter::Runtime &runtime) override void execute (Interpreter::Runtime &runtime) override
{ {
MWWorld::Ptr actor = R()(runtime); MWWorld::Ptr actor = R()(runtime);
std::string testedTargetId = runtime.getStringLiteral (runtime[0].mInteger); std::string_view testedTargetId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
bool targetsAreEqual = false; bool targetsAreEqual = false;
@ -497,7 +497,7 @@ namespace MWScript
void execute (Interpreter::Runtime &runtime) override void execute (Interpreter::Runtime &runtime) override
{ {
MWWorld::Ptr actor = R()(runtime); MWWorld::Ptr actor = R()(runtime);
std::string targetID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view targetID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false); MWWorld::Ptr target = MWBase::Environment::get().getWorld()->searchPtr(targetID, true, false);

View file

@ -44,7 +44,7 @@ namespace MWScript
if (!ptr.getRefData().isEnabled()) if (!ptr.getRefData().isEnabled())
return; return;
std::string group = runtime.getStringLiteral (runtime[0].mInteger); std::string_view group = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer mode = 0; Interpreter::Type_Integer mode = 0;
@ -58,7 +58,7 @@ namespace MWScript
throw std::runtime_error ("animation mode out of range"); throw std::runtime_error ("animation mode out of range");
} }
MWBase::Environment::get().getMechanicsManager()->playAnimationGroup (ptr, group, mode, std::numeric_limits<int>::max(), true); MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, {group.begin(), group.end()}, mode, std::numeric_limits<int>::max(), true);
} }
}; };
@ -74,7 +74,7 @@ namespace MWScript
if (!ptr.getRefData().isEnabled()) if (!ptr.getRefData().isEnabled())
return; return;
std::string group = runtime.getStringLiteral (runtime[0].mInteger); std::string_view group = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer loops = runtime[0].mInteger; Interpreter::Type_Integer loops = runtime[0].mInteger;
@ -94,7 +94,7 @@ namespace MWScript
throw std::runtime_error ("animation mode out of range"); 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, {group.begin(), group.end()}, mode, loops + 1, true);
} }
}; };

View file

@ -87,7 +87,8 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string cell = runtime.getStringLiteral (runtime[0].mInteger); std::string_view cellView = runtime.getStringLiteral(runtime[0].mInteger);
std::string cell{cellView.begin(), cellView.end()};
runtime.pop(); runtime.pop();
ESM::Position pos; ESM::Position pos;
@ -160,7 +161,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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.pop();
if (!MWMechanics::getPlayer().isInCell()) if (!MWMechanics::getPlayer().isInCell())

View file

@ -87,7 +87,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer count = runtime[0].mInteger; Interpreter::Type_Integer count = runtime[0].mInteger;
@ -116,7 +116,7 @@ namespace MWScript
// Explicit calls to non-unique actors affect the base record // Explicit calls to non-unique actors affect the base record
if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) 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(), {item.begin(), item.end()}, count);
return; return;
} }
@ -124,7 +124,7 @@ namespace MWScript
if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() ||
!ptr.getClass().getContainerStore(ptr).isResolved())) !ptr.getClass().getContainerStore(ptr).isResolved()))
{ {
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, count);
const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId()); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId());
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
for(const auto& container : ptrs) for(const auto& container : ptrs)
@ -183,7 +183,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if(::Misc::StringUtils::ciEqual(item, "gold_005") if(::Misc::StringUtils::ciEqual(item, "gold_005")
@ -207,7 +207,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer count = runtime[0].mInteger; Interpreter::Type_Integer count = runtime[0].mInteger;
@ -229,14 +229,14 @@ namespace MWScript
// Explicit calls to non-unique actors affect the base record // Explicit calls to non-unique actors affect the base record
if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) 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(), {item.begin(), item.end()}, -count);
return; return;
} }
// Calls to unresolved containers affect the base record instead // Calls to unresolved containers affect the base record instead
else if(ptr.getClass().getType() == ESM::Container::sRecordId && else if(ptr.getClass().getType() == ESM::Container::sRecordId &&
(!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved()))
{ {
ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), {item.begin(), item.end()}, -count);
const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId()); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get<ESM::Container>().find(ptr.getCellRef().getRefId());
const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId());
for(const auto& container : ptrs) for(const auto& container : ptrs)
@ -297,7 +297,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
@ -408,7 +408,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr); const MWWorld::InventoryStore& invStore = ptr.getClass().getInventoryStore (ptr);
@ -434,7 +434,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); 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(); runtime.pop();
int count = 0; int count = 0;

View file

@ -34,7 +34,8 @@ namespace MWScript
if (ptr.isEmpty()) if (ptr.isEmpty())
ptr = MWBase::Environment::get().getWorld()->getPlayerPtr(); ptr = MWBase::Environment::get().getWorld()->getPlayerPtr();
std::string quest = runtime.getStringLiteral (runtime[0].mInteger); std::string_view questView = runtime.getStringLiteral(runtime[0].mInteger);
std::string quest{questView.begin(), questView.end()};
runtime.pop(); runtime.pop();
Interpreter::Type_Integer index = runtime[0].mInteger; Interpreter::Type_Integer index = runtime[0].mInteger;
@ -59,13 +60,13 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string quest = runtime.getStringLiteral (runtime[0].mInteger); std::string_view quest = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer index = runtime[0].mInteger; Interpreter::Type_Integer index = runtime[0].mInteger;
runtime.pop(); runtime.pop();
MWBase::Environment::get().getJournal()->setJournalIndex (quest, index); MWBase::Environment::get().getJournal()->setJournalIndex({quest.begin(), quest.end()}, index);
} }
}; };
@ -75,10 +76,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string quest = runtime.getStringLiteral (runtime[0].mInteger); std::string_view quest = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int index = MWBase::Environment::get().getJournal()->getJournalIndex (quest); int index = MWBase::Environment::get().getJournal()->getJournalIndex({quest.begin(), quest.end()});
runtime.push (index); runtime.push (index);
@ -91,7 +92,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
MWBase::Environment::get().getDialogueManager()->addTopic(topic); MWBase::Environment::get().getDialogueManager()->addTopic(topic);
@ -107,7 +108,7 @@ namespace MWScript
MWBase::DialogueManager* dialogue = MWBase::Environment::get().getDialogueManager(); MWBase::DialogueManager* dialogue = MWBase::Environment::get().getDialogueManager();
while(arg0>0) while(arg0>0)
{ {
std::string question = runtime.getStringLiteral (runtime[0].mInteger); std::string_view question = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
arg0 = arg0 -1; arg0 = arg0 -1;
Interpreter::Type_Integer choice = 1; Interpreter::Type_Integer choice = 1;
@ -220,10 +221,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int modReaction = runtime[0].mInteger; int modReaction = runtime[0].mInteger;
@ -239,10 +240,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
runtime.push(MWBase::Environment::get().getDialogueManager() runtime.push(MWBase::Environment::get().getDialogueManager()
@ -256,10 +257,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
std::string faction2 = runtime.getStringLiteral (runtime[0].mInteger); std::string_view faction2 = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int newValue = runtime[0].mInteger; int newValue = runtime[0].mInteger;

View file

@ -135,20 +135,21 @@ namespace MWScript
: mStore (store) : 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 (iter==mScripts.end())
{ {
if (const ESM::Script *script = mStore.get<ESM::Script>().search(name)) if (const ESM::Script *script = mStore.get<ESM::Script>().search(lowerName))
{ {
auto desc = std::make_shared<GlobalScriptDesc>(); auto desc = std::make_shared<GlobalScriptDesc>();
MWWorld::Ptr ptr = target; MWWorld::Ptr ptr = target;
desc->mTarget = ptr; desc->mTarget = ptr;
desc->mRunning = true; desc->mRunning = true;
desc->mLocals.configure (*script); desc->mLocals.configure (*script);
mScripts.insert (std::make_pair(name, desc)); mScripts.insert (std::make_pair(lowerName, desc));
} }
else 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)); const auto iter = mScripts.find (::Misc::StringUtils::lowerCase (name));
@ -171,7 +172,7 @@ namespace MWScript
iter->second->mRunning = false; 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)); const auto iter = mScripts.find (::Misc::StringUtils::lowerCase (name));
@ -306,14 +307,14 @@ namespace MWScript
return false; return false;
} }
Locals& GlobalScripts::getLocals (const std::string& name) Locals& GlobalScripts::getLocals(std::string_view name)
{ {
std::string name2 = ::Misc::StringUtils::lowerCase (name); std::string name2 = ::Misc::StringUtils::lowerCase (name);
auto iter = mScripts.find (name2); auto iter = mScripts.find (name2);
if (iter==mScripts.end()) if (iter==mScripts.end())
{ {
const ESM::Script *script = mStore.get<ESM::Script>().find (name); const ESM::Script *script = mStore.get<ESM::Script>().find(name2);
auto desc = std::make_shared<GlobalScriptDesc>(); auto desc = std::make_shared<GlobalScriptDesc>();
desc->mLocals.configure (*script); desc->mLocals.configure (*script);
@ -324,7 +325,7 @@ namespace MWScript
return iter->second->mLocals; 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); std::string name2 = ::Misc::StringUtils::lowerCase (name);
auto iter = mScripts.find (name2); auto iter = mScripts.find (name2);

View file

@ -56,11 +56,11 @@ namespace MWScript
GlobalScripts (const MWWorld::ESMStore& store); 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(); void run();
///< run all active global scripts ///< run all active global scripts
@ -79,11 +79,11 @@ namespace MWScript
/// ///
/// \return Known type? /// \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 ///< 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. /// 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); 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. ///< Update the Ptrs stored in mTarget. Should be called after the reference has been moved to a new cell.

View file

@ -114,8 +114,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string cell = (runtime.getStringLiteral (runtime[0].mInteger)); std::string cell = ::Misc::StringUtils::lowerCase(runtime.getStringLiteral(runtime[0].mInteger));
::Misc::StringUtils::lowerCaseInPlace(cell);
runtime.pop(); runtime.pop();
// "Will match complete or partial cells, so ShowMap, "Vivec" will show cells Vivec and Vivec, Fred's House as well." // "Will match complete or partial cells, so ShowMap, "Vivec" will show cells Vivec and Vivec, Fred's House as well."

View file

@ -89,7 +89,7 @@ namespace MWScript
MissingImplicitRefError::MissingImplicitRefError() : std::runtime_error("no implicit reference") {} MissingImplicitRefError::MissingImplicitRefError() : std::runtime_error("no implicit reference") {}
int InterpreterContext::findLocalVariableIndex (const std::string& scriptId, 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). int index = MWBase::Environment::get().getScriptManager()->getLocals (scriptId).
searchIndex (type, name); 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); 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. // a global long is internally a float.
return MWBase::Environment::get().getWorld()->getGlobalInt (name); 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); 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); 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); 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); MWBase::Environment::get().getWorld()->setGlobalFloat (name, value);
} }
@ -245,13 +245,13 @@ namespace MWScript
return ids; 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(); MWBase::World *world = MWBase::Environment::get().getWorld();
return world->getGlobalVariableType(name); 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(); MWBase::InputManager* input = MWBase::Environment::get().getInputManager();
std::vector<int> actions = input->getActionKeySorting (); std::vector<int> 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 bool global) const
{ {
std::string scriptId (id); std::string scriptId (id);
@ -437,7 +437,7 @@ namespace MWScript
return locals.mShorts[findLocalVariableIndex (scriptId, name, 's')]; 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 bool global) const
{ {
std::string scriptId (id); std::string scriptId (id);
@ -447,7 +447,7 @@ namespace MWScript
return locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')]; 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 bool global) const
{ {
std::string scriptId (id); std::string scriptId (id);
@ -457,7 +457,7 @@ namespace MWScript
return locals.mFloats[findLocalVariableIndex (scriptId, name, 'f')]; 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) int value, bool global)
{ {
std::string scriptId (id); std::string scriptId (id);
@ -467,7 +467,7 @@ namespace MWScript
locals.mShorts[findLocalVariableIndex (scriptId, name, 's')] = value; 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); std::string scriptId (id);
@ -476,7 +476,7 @@ namespace MWScript
locals.mLongs[findLocalVariableIndex (scriptId, name, 'l')] = value; 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); std::string scriptId (id);

View file

@ -38,7 +38,7 @@ namespace MWScript
///< \a id is changed to the respective script ID, if \a id wasn't a script ID before ///< \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. /// 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; char type) const;
public: public:
@ -69,23 +69,23 @@ namespace MWScript
void report (const std::string& message) override; void report (const std::string& message) override;
///< By default, do nothing. ///< 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<std::string> getGlobals () const override; std::vector<std::string> 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; std::string getActorName() const override;
@ -114,17 +114,17 @@ namespace MWScript
void executeActivation(const MWWorld::Ptr& ptr, const MWWorld::Ptr& actor); 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. ///< 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; MWWorld::Ptr getReference(bool required=true) const;
///< Reference, that the script is running from (can be empty) ///< Reference, that the script is running from (can be empty)

View file

@ -62,7 +62,7 @@ namespace MWScript
return (mShorts.empty() && mLongs.empty() && mFloats.empty()); 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); ensure (script);
@ -72,7 +72,7 @@ namespace MWScript
return (index != -1); 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); ensure (script);
@ -98,7 +98,7 @@ namespace MWScript
return 0; 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); ensure (script);
@ -124,7 +124,7 @@ namespace MWScript
return 0; 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); ensure (script);

View file

@ -37,25 +37,25 @@ namespace MWScript
/// @note var needs to be in lowercase /// @note var needs to be in lowercase
/// ///
/// \note Locals will be automatically configured first, if necessary /// \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 Locals will be automatically configured first, if necessary
// //
// \note If it can not be determined if the variable exists, the error will be // \note If it can not be determined if the variable exists, the error will be
// ignored and false will be returned. // 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 /// if var does not exist, returns 0
/// @note var needs to be in lowercase /// @note var needs to be in lowercase
/// ///
/// \note Locals will be automatically configured first, if necessary /// \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 /// if var does not exist, returns 0
/// @note var needs to be in lowercase /// @note var needs to be in lowercase
/// ///
/// \note Locals will be automatically configured first, if necessary /// \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. /// \note If locals have not been configured yet, no data is written.
/// ///

View file

@ -51,7 +51,7 @@
namespace 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) for (auto& levelItem : list->mList)
{ {
@ -60,12 +60,12 @@ namespace
} }
ESM::LevelledListBase::LevelItem item; ESM::LevelledListBase::LevelItem item;
item.mId = itemId; item.mId = {itemId.begin(), itemId.end()};
item.mLevel = level; item.mLevel = level;
list->mList.push_back(item); 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 // level of -1 removes all items with that itemId
for (std::vector<ESM::LevelledListBase::LevelItem>::iterator it = list->mList.begin(); it != list->mList.end();) for (std::vector<ESM::LevelledListBase::LevelItem>::iterator it = list->mList.begin(); it != list->mList.end();)
@ -124,7 +124,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
MWWorld::Ptr target = R()(runtime, false); 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(); runtime.pop();
MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name, target); MWBase::Environment::get().getScriptManager()->getGlobalScripts().addScript (name, target);
} }
@ -136,7 +136,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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.pop();
runtime.push(MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning (name)); runtime.push(MWBase::Environment::get().getScriptManager()->getGlobalScripts().isRunning (name));
} }
@ -148,7 +148,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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.pop();
MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript (name); MWBase::Environment::get().getScriptManager()->getGlobalScripts().removeScript (name);
} }
@ -206,13 +206,13 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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.pop();
bool allowSkipping = runtime[0].mInteger != 0; bool allowSkipping = runtime[0].mInteger != 0;
runtime.pop(); runtime.pop();
MWBase::Environment::get().getWindowManager()->playVideo (name, allowSkipping); MWBase::Environment::get().getWindowManager()->playVideo({name.begin(), name.end()}, allowSkipping);
} }
}; };
@ -548,7 +548,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string effect = runtime.getStringLiteral(runtime[0].mInteger); std::string_view effect = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!ptr.getClass().isActor()) if (!ptr.getClass().isActor())
@ -558,9 +558,9 @@ namespace MWScript
} }
char *end; char *end;
long key = strtol(effect.c_str(), &end, 10); long key = strtol(effect.data(), &end, 10);
if(key < 0 || key > 32767 || *end != '\0') if(key < 0 || key > 32767 || *end != '\0')
key = ESM::MagicEffect::effectStringToId(effect); key = ESM::MagicEffect::effectStringToId({effect.begin(), effect.end()});
const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr); const MWMechanics::CreatureStats& stats = ptr.getClass().getCreatureStats(ptr);
@ -587,10 +587,11 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string creature = runtime.getStringLiteral (runtime[0].mInteger); std::string_view creatureView = runtime.getStringLiteral(runtime[0].mInteger);
std::string creature{creatureView.begin(), creatureView.end()};
runtime.pop(); runtime.pop();
std::string gem = runtime.getStringLiteral (runtime[0].mInteger); std::string_view gem = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!ptr.getClass().hasInventoryStore(ptr)) if (!ptr.getClass().hasInventoryStore(ptr))
@ -599,7 +600,7 @@ namespace MWScript
const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore(); const MWWorld::ESMStore& store = MWBase::Environment::get().getWorld()->getStore();
store.get<ESM::Creature>().find(creature); // This line throws an exception if it can't find the creature store.get<ESM::Creature>().find(creature); // This line throws an exception if it can't find the creature
MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add(gem, 1, ptr); MWWorld::Ptr item = *ptr.getClass().getContainerStore(ptr).add({gem.begin(), gem.end()}, 1, ptr);
// Set the soul on just one of the gems, not the whole stack // Set the soul on just one of the gems, not the whole stack
item.getContainerStore()->unstack(item, ptr); item.getContainerStore()->unstack(item, ptr);
@ -619,7 +620,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string soul = runtime.getStringLiteral (runtime[0].mInteger); std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
// throw away additional arguments // throw away additional arguments
@ -651,7 +652,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string item = runtime.getStringLiteral (runtime[0].mInteger); std::string_view item = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer amount = runtime[0].mInteger; Interpreter::Type_Integer amount = runtime[0].mInteger;
@ -738,7 +739,7 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string soul = runtime.getStringLiteral (runtime[0].mInteger); std::string_view soul = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!ptr.getClass().hasInventoryStore(ptr)) if (!ptr.getClass().hasInventoryStore(ptr))
@ -806,7 +807,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id = runtime.getStringLiteral(runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!ptr.getClass().isActor()) if (!ptr.getClass().isActor())
@ -973,7 +974,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
@ -993,7 +994,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string objectID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view objectID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
@ -1036,7 +1037,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
MWWorld::Ptr ptr = R()(runtime, false); 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(); runtime.pop();
std::stringstream output; std::stringstream output;
@ -1213,22 +1214,22 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string spellId = runtime.getStringLiteral (runtime[0].mInteger); std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); 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(); runtime.pop();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search({spellId.begin(), spellId.end()});
if (!spell) if (!spell)
{ {
runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string{spellId.begin(), spellId.end()}+"\"");
return; return;
} }
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId); MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spell->mId);
return; return;
} }
@ -1236,7 +1237,7 @@ namespace MWScript
{ {
if (!MWBase::Environment::get().getMechanicsManager()->isCastingSpell(ptr)) 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); ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr);
} }
return; return;
@ -1262,19 +1263,19 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string spellId = runtime.getStringLiteral (runtime[0].mInteger); std::string_view spellId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search(spellId); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().search({spellId.begin(), spellId.end()});
if (!spell) if (!spell)
{ {
runtime.getContext().report("spellcasting failed: cannot find spell \""+spellId+"\""); runtime.getContext().report("spellcasting failed: cannot find spell \""+std::string{spellId.begin(), spellId.end()}+"\"");
return; return;
} }
if (ptr == MWMechanics::getPlayer()) if (ptr == MWMechanics::getPlayer())
{ {
MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spellId); MWBase::Environment::get().getWorld()->getPlayer().setSelectedSpell(spell->mId);
return; return;
} }
@ -1282,7 +1283,7 @@ namespace MWScript
{ {
if (!MWBase::Environment::get().getMechanicsManager()->isCastingSpell(ptr)) 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); ptr.getClass().getCreatureStats (ptr).getAiSequence().stack(castPackage, ptr);
} }
return; return;
@ -1407,7 +1408,7 @@ namespace MWScript
while (arg0 > 0) while (arg0 > 0)
{ {
std::string notes = runtime.getStringLiteral (runtime[0].mInteger); std::string_view notes = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (!notes.empty()) if (!notes.empty())
msg << "Notes: " << notes << std::endl; msg << "Notes: " << notes << std::endl;
@ -1425,14 +1426,14 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const std::string& creatureId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int level = runtime[0].mInteger; int level = runtime[0].mInteger;
runtime.pop(); runtime.pop();
ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::CreatureLevList>().find(levId); ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::CreatureLevList>().find({levId.begin(), levId.end()});
addToLevList(&listCopy, creatureId, level); addToLevList(&listCopy, creatureId, level);
MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy);
} }
@ -1443,14 +1444,14 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const std::string& creatureId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view creatureId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int level = runtime[0].mInteger; int level = runtime[0].mInteger;
runtime.pop(); runtime.pop();
ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::CreatureLevList>().find(levId); ESM::CreatureLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::CreatureLevList>().find({levId.begin(), levId.end()});
removeFromLevList(&listCopy, creatureId, level); removeFromLevList(&listCopy, creatureId, level);
MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy);
} }
@ -1461,14 +1462,14 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const std::string& itemId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int level = runtime[0].mInteger; int level = runtime[0].mInteger;
runtime.pop(); runtime.pop();
ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().find(levId); ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().find({levId.begin(), levId.end()});
addToLevList(&listCopy, itemId, level); addToLevList(&listCopy, itemId, level);
MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy);
} }
@ -1479,14 +1480,14 @@ namespace MWScript
public: public:
void execute(Interpreter::Runtime &runtime) override void execute(Interpreter::Runtime &runtime) override
{ {
const std::string& levId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view levId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const std::string& itemId = runtime.getStringLiteral(runtime[0].mInteger); std::string_view itemId = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
int level = runtime[0].mInteger; int level = runtime[0].mInteger;
runtime.pop(); runtime.pop();
ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().find(levId); ESM::ItemLevList listCopy = *MWBase::Environment::get().getWorld()->getStore().get<ESM::ItemLevList>().find({levId.begin(), levId.end()});
removeFromLevList(&listCopy, itemId, level); removeFromLevList(&listCopy, itemId, level);
MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy); MWBase::Environment::get().getWorld()->createOverrideRecord(listCopy);
} }

View file

@ -10,7 +10,7 @@
MWWorld::Ptr MWScript::ExplicitRef::operator() (Interpreter::Runtime& runtime, bool required, MWWorld::Ptr MWScript::ExplicitRef::operator() (Interpreter::Runtime& runtime, bool required,
bool activeOnly) const bool activeOnly) const
{ {
std::string id = runtime.getStringLiteral(runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
if (required) if (required)

View file

@ -87,7 +87,8 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string region = runtime.getStringLiteral (runtime[0].mInteger); std::string_view regionView = runtime.getStringLiteral(runtime[0].mInteger);
std::string region{regionView.begin(), regionView.end()};
runtime.pop(); runtime.pop();
Interpreter::Type_Integer id = runtime[0].mInteger; Interpreter::Type_Integer id = runtime[0].mInteger;
@ -107,7 +108,8 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime, unsigned int arg0) override void execute (Interpreter::Runtime& runtime, unsigned int arg0) override
{ {
std::string region = runtime.getStringLiteral (runtime[0].mInteger); std::string_view regionView = runtime.getStringLiteral(runtime[0].mInteger);
std::string region{regionView.begin(), regionView.end()};
runtime.pop(); runtime.pop();
std::vector<char> chances; std::vector<char> chances;

View file

@ -33,16 +33,16 @@ namespace MWScript
MWScript::InterpreterContext& context MWScript::InterpreterContext& context
= static_cast<MWScript::InterpreterContext&> (runtime.getContext()); = static_cast<MWScript::InterpreterContext&> (runtime.getContext());
std::string file = runtime.getStringLiteral (runtime[0].mInteger); std::string_view file = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
std::string text = runtime.getStringLiteral (runtime[0].mInteger); std::string_view text = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWBase::Environment::get().getSoundManager()->say (ptr, file); MWBase::Environment::get().getSoundManager()->say(ptr, {file.begin(), file.end()});
if (MWBase::Environment::get().getWindowManager ()->getSubtitlesEnabled()) if (MWBase::Environment::get().getWindowManager ()->getSubtitlesEnabled())
context.messageBox (text); context.messageBox({text.begin(), text.end()});
} }
}; };
@ -65,10 +65,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
MWBase::Environment::get().getSoundManager()->streamMusic (sound); MWBase::Environment::get().getSoundManager()->streamMusic({sound.begin(), sound.end()});
} }
}; };
@ -78,7 +78,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
MWBase::Environment::get().getSoundManager()->playSound(sound, 1.0, 1.0, MWSound::Type::Sfx, MWSound::PlayMode::NoEnv); 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 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(); runtime.pop();
Interpreter::Type_Float volume = runtime[0].mFloat; Interpreter::Type_Float volume = runtime[0].mFloat;
@ -113,7 +113,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0, MWBase::Environment::get().getSoundManager()->playSound3D(ptr, sound, 1.0, 1.0,
@ -132,7 +132,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float volume = runtime[0].mFloat; Interpreter::Type_Float volume = runtime[0].mFloat;
@ -158,7 +158,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string sound = runtime.getStringLiteral (runtime[0].mInteger); std::string_view sound = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWBase::Environment::get().getSoundManager()->stopSound3D (ptr, sound); MWBase::Environment::get().getSoundManager()->stopSound3D (ptr, sound);

View file

@ -447,13 +447,13 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id = runtime.getStringLiteral (runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find (id); const ESM::Spell* spell = MWBase::Environment::get().getWorld()->getStore().get<ESM::Spell>().find({id.begin(), id.end()});
MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr);
creatureStats.getSpells().add(id); creatureStats.getSpells().add(spell);
ESM::Spell::SpellType type = static_cast<ESM::Spell::SpellType>(spell->mData.mType); ESM::Spell::SpellType type = static_cast<ESM::Spell::SpellType>(spell->mData.mType);
if (type != ESM::Spell::ST_Spell && type != ESM::Spell::ST_Power) if (type != ESM::Spell::ST_Spell && type != ESM::Spell::ST_Power)
{ {
@ -474,11 +474,11 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id = runtime.getStringLiteral (runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr); MWMechanics::CreatureStats& creatureStats = ptr.getClass().getCreatureStats(ptr);
creatureStats.getSpells().remove (id); creatureStats.getSpells().remove({id.begin(), id.end()});
MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager(); MWBase::WindowManager *wm = MWBase::Environment::get().getWindowManager();
@ -499,7 +499,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string spellid = runtime.getStringLiteral (runtime[0].mInteger); std::string_view spellid = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
ptr.getClass().getCreatureStats (ptr).getActiveSpells().removeEffects(ptr, spellid); ptr.getClass().getCreatureStats (ptr).getActiveSpells().removeEffects(ptr, spellid);
@ -532,12 +532,12 @@ namespace MWScript
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string id = runtime.getStringLiteral (runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer value = 0; Interpreter::Type_Integer value = 0;
if (ptr.getClass().isActor() && ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell(id)) if (ptr.getClass().isActor() && ptr.getClass().getCreatureStats(ptr).getSpells().hasSpell({id.begin(), id.end()}))
value = 1; value = 1;
runtime.push (value); runtime.push (value);
@ -748,8 +748,8 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
std::string id = runtime.getStringLiteral (runtime[0].mInteger); std::string_view id = runtime.getStringLiteral(runtime[0].mInteger);
runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths (id); runtime[0].mInteger = MWBase::Environment::get().getMechanicsManager()->countDeaths({id.begin(), id.end()});
} }
}; };
@ -890,14 +890,12 @@ namespace MWScript
{ {
MWWorld::ConstPtr ptr = R()(runtime); MWWorld::ConstPtr ptr = R()(runtime);
std::string race = runtime.getStringLiteral(runtime[0].mInteger); std::string_view race = runtime.getStringLiteral(runtime[0].mInteger);
::Misc::StringUtils::lowerCaseInPlace(race);
runtime.pop(); runtime.pop();
std::string npcRace = ptr.get<ESM::NPC>()->mBase->mRace; const std::string& npcRace = ptr.get<ESM::NPC>()->mBase->mRace;
::Misc::StringUtils::lowerCaseInPlace(npcRace);
runtime.push (npcRace == race); runtime.push(::Misc::StringUtils::ciEqual(race, npcRace));
} }
}; };

View file

@ -43,7 +43,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override void execute (Interpreter::Runtime& runtime) override
{ {
MWWorld::Ptr from = R()(runtime, !R::implicit); 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(); runtime.pop();
if (from.isEmpty()) if (from.isEmpty())
@ -74,7 +74,8 @@ namespace MWScript
const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false); const MWWorld::Ptr to = MWBase::Environment::get().getWorld()->searchPtr(name, false);
if (to.isEmpty()) if (to.isEmpty())
{ {
std::string error = "Failed to find an instance of object '" + name + "'"; std::string error = "Failed to find an instance of object '";
error += name; error += "'";
runtime.getContext().report(error); runtime.getContext().report(error);
Log(Debug::Error) << error; Log(Debug::Error) << error;
runtime.push(0.f); runtime.push(0.f);
@ -155,7 +156,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float angle = osg::DegreesToRadians(runtime[0].mFloat); Interpreter::Type_Float angle = osg::DegreesToRadians(runtime[0].mFloat);
runtime.pop(); runtime.pop();
@ -190,7 +191,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
float ret = 0.f; float ret = 0.f;
@ -222,7 +223,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
float ret = 0.f; float ret = 0.f;
@ -254,7 +255,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
float ret = 0.f; float ret = 0.f;
@ -286,7 +287,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float pos = runtime[0].mFloat; Interpreter::Type_Float pos = runtime[0].mFloat;
runtime.pop(); runtime.pop();
@ -340,7 +341,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
float ret = 0.f; float ret = 0.f;
@ -380,7 +381,8 @@ namespace MWScript
runtime.pop(); runtime.pop();
Interpreter::Type_Float zRot = runtime[0].mFloat; Interpreter::Type_Float zRot = runtime[0].mFloat;
runtime.pop(); runtime.pop();
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view cellIDView = runtime.getStringLiteral(runtime[0].mInteger);
std::string cellID{cellIDView.begin(), cellIDView.end()};
runtime.pop(); runtime.pop();
if (ptr.getContainerStore()) if (ptr.getContainerStore())
@ -495,9 +497,10 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
std::string cellID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view cellIDView = runtime.getStringLiteral(runtime[0].mInteger);
std::string cellID{cellIDView.begin(), cellIDView.end()};
runtime.pop(); runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat; Interpreter::Type_Float x = runtime[0].mFloat;
@ -549,7 +552,7 @@ namespace MWScript
void execute (Interpreter::Runtime& runtime) override 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(); runtime.pop();
Interpreter::Type_Float x = runtime[0].mFloat; Interpreter::Type_Float x = runtime[0].mFloat;
@ -601,7 +604,7 @@ namespace MWScript
? MWMechanics::getPlayer() ? MWMechanics::getPlayer()
: R()(runtime); : R()(runtime);
std::string itemID = runtime.getStringLiteral (runtime[0].mInteger); std::string_view itemID = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Integer count = runtime[0].mInteger; Interpreter::Type_Integer count = runtime[0].mInteger;
@ -641,7 +644,7 @@ namespace MWScript
{ {
const MWWorld::Ptr& ptr = R()(runtime); 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(); runtime.pop();
Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();
@ -667,7 +670,7 @@ namespace MWScript
{ {
MWWorld::Ptr ptr = R()(runtime); MWWorld::Ptr ptr = R()(runtime);
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); Interpreter::Type_Float rotation = osg::DegreesToRadians(runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();
@ -726,7 +729,7 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();
@ -773,7 +776,7 @@ namespace MWScript
if (!ptr.isInCell()) if (!ptr.isInCell())
return; return;
std::string axis = runtime.getStringLiteral (runtime[0].mInteger); std::string_view axis = runtime.getStringLiteral(runtime[0].mInteger);
runtime.pop(); runtime.pop();
Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration()); Interpreter::Type_Float movement = (runtime[0].mFloat*MWBase::Environment::get().getFrameDuration());
runtime.pop(); runtime.pop();

View file

@ -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()) if(!mOutput->isInitialized())
return nullptr; return nullptr;
@ -518,7 +518,7 @@ namespace MWSound
return result; 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 volume, float pitch, Type type, PlayMode mode,
float offset) float offset)
{ {
@ -576,7 +576,7 @@ namespace MWSound
return result; 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 volume, float pitch, Type type, PlayMode mode,
float offset) float offset)
{ {
@ -630,7 +630,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()) if(!mOutput->isInitialized())
return; return;
@ -682,7 +682,7 @@ namespace MWSound
} }
void SoundManager::fadeOutSound3D(const MWWorld::ConstPtr &ptr, 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); SoundMap::iterator snditer = mActiveSounds.find(ptr);
if(snditer != mActiveSounds.end()) if(snditer != mActiveSounds.end())
@ -698,7 +698,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); SoundMap::const_iterator snditer = mActiveSounds.find(ptr);
if(snditer != mActiveSounds.end()) if(snditer != mActiveSounds.end())

View file

@ -198,17 +198,17 @@ namespace MWSound
/// returned by \ref playTrack). Only intended to be called by the track /// returned by \ref playTrack). Only intended to be called by the track
/// decoder's read method. /// 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 ///< Play a sound, independently of 3D-position
///< @param offset Number of seconds into the sound to start playback. ///< @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, float volume, float pitch, Type type=Type::Sfx,
PlayMode mode=PlayMode::Normal, float offset=0) override; 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. ///< 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. ///< @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; 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. ///< 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. ///< @param offset Number of seconds into the sound to start playback.
@ -217,7 +217,7 @@ namespace MWSound
///< Stop the given sound from playing ///< Stop the given sound from playing
/// @note no-op if \a sound is null /// @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, ///< Stop the given object from playing the given sound,
void stopSound3D(const MWWorld::ConstPtr &reference) override; void stopSound3D(const MWWorld::ConstPtr &reference) override;
@ -226,13 +226,13 @@ namespace MWSound
void stopSound(const MWWorld::CellStore *cell) override; void stopSound(const MWWorld::CellStore *cell) override;
///< Stop all sounds for the given cell. ///< 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 ///< Fade out given sound (that is already playing) of given object
///< @param reference Reference to object, whose sound is faded out ///< @param reference Reference to object, whose sound is faded out
///< @param soundId ID of the sound to fade out. ///< @param soundId ID of the sound to fade out.
///< @param duration Time until volume reaches 0. ///< @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? ///< Is the given sound currently playing on the given object?
void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) override; void pauseSounds(MWSound::BlockerType blocker, int types=int(Type::Mask)) override;

View file

@ -179,7 +179,7 @@ MWWorld::ContainerStoreIterator MWWorld::ContainerStore::end()
return ContainerStoreIterator (this); return ContainerStoreIterator (this);
} }
int MWWorld::ContainerStore::count(const std::string &id) const int MWWorld::ContainerStore::count(std::string_view id) const
{ {
int total=0; int total=0;
for (const auto&& iter : *this) for (const auto&& iter : *this)
@ -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) if(resolveFirst)
resolve(); resolve();

View file

@ -178,7 +178,7 @@ namespace MWWorld
ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr); ContainerStoreIterator add(const std::string& id, int count, const Ptr& actorPtr);
///< Utility to construct a ManualRef and call add(ptr, count, actorPtr, true) ///< 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. ///< Remove \a count item(s) designated by \a itemId from this container.
/// ///
/// @return the number of items actually removed /// @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. /// 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. /// @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? ///< @return How many items with refID \a id are in this container?
ContainerStoreListener* getContListener() const; ContainerStoreListener* getContListener() const;

View file

@ -159,7 +159,7 @@ namespace MWWorld
return setting->mValue.getString(); 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") if (name=="gamehour")
{ {
@ -192,7 +192,7 @@ namespace MWWorld
return false; return false;
} }
bool DateTimeManager::updateGlobalInt(const std::string& name, int value) bool DateTimeManager::updateGlobalInt(std::string_view name, int value)
{ {
if (name=="gamehour") if (name=="gamehour")
{ {

View file

@ -35,8 +35,8 @@ namespace MWWorld
void advanceTime(double hours, Globals& globalVariables); void advanceTime(double hours, Globals& globalVariables);
void setup(Globals& globalVariables); void setup(Globals& globalVariables);
bool updateGlobalInt(const std::string& name, int value); bool updateGlobalInt(std::string_view name, int value);
bool updateGlobalFloat(const std::string& name, float value); bool updateGlobalFloat(std::string_view name, float value);
}; };
} }

View file

@ -10,22 +10,22 @@
namespace MWWorld 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)); Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));
if (iter==mVariables.end()) if (iter==mVariables.end())
throw std::runtime_error ("unknown global variable: " + name); throw std::runtime_error ("unknown global variable: " + std::string{name});
return iter; 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)); Collection::iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));
if (iter==mVariables.end()) if (iter==mVariables.end())
throw std::runtime_error ("unknown global variable: " + name); throw std::runtime_error ("unknown global variable: " + std::string{name});
return iter; 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; 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; 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)); Collection::const_iterator iter = mVariables.find (Misc::StringUtils::lowerCase (name));

View file

@ -32,17 +32,17 @@ namespace MWWorld
Collection mVariables; // type, value 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: 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. ///< If there is no global variable with this name, ' ' is returned.
void fill (const MWWorld::ESMStore& store); void fill (const MWWorld::ESMStore& store);

View file

@ -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); std::string lowerName = Misc::StringUtils::lowerCase(name);
switch (store.find(lowerName)) switch (store.find(lowerName))

View file

@ -17,7 +17,7 @@ namespace MWWorld
ManualRef& operator= (const ManualRef&); ManualRef& operator= (const ManualRef&);
public: 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 const Ptr& getPtr() const
{ {

View file

@ -656,7 +656,7 @@ namespace MWWorld
return mWorldScene->hasCellChanged(); 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); bool dateUpdated = mCurrentDate->updateGlobalInt(name, value);
if (dateUpdated) if (dateUpdated)
@ -665,7 +665,7 @@ namespace MWWorld
mGlobalVariables[name].setInteger (value); 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); bool dateUpdated = mCurrentDate->updateGlobalFloat(name, value);
if (dateUpdated) if (dateUpdated)
@ -674,17 +674,17 @@ namespace MWWorld
mGlobalVariables[name].setFloat(value); mGlobalVariables[name].setFloat(value);
} }
int World::getGlobalInt (const std::string& name) const int World::getGlobalInt(std::string_view name) const
{ {
return mGlobalVariables[name].getInteger(); return mGlobalVariables[name].getInteger();
} }
float World::getGlobalFloat (const std::string& name) const float World::getGlobalFloat(std::string_view name) const
{ {
return mGlobalVariables[name].getFloat(); return mGlobalVariables[name].getFloat();
} }
char World::getGlobalVariableType (const std::string& name) const char World::getGlobalVariableType (std::string_view name) const
{ {
return mGlobalVariables.getType (name); return mGlobalVariables.getType (name);
} }
@ -719,7 +719,7 @@ namespace MWWorld
mLocalScripts.remove (ref); 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; Ptr ret;
// the player is always in an active cell. // the player is always in an active cell.
@ -762,12 +762,13 @@ namespace MWWorld
return ptr; 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); Ptr ret = searchPtr(name, activeOnly);
if (!ret.isEmpty()) if (!ret.isEmpty())
return ret; return ret;
std::string error = "failed to find an instance of object '" + name + "'"; std::string error = "failed to find an instance of object '";
error += name; error += "'";
if (activeOnly) if (activeOnly)
error += " in active cells"; error += " in active cells";
throw std::runtime_error(error); throw std::runtime_error(error);

View file

@ -258,19 +258,19 @@ namespace MWWorld
void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) override; void getDoorMarkers (MWWorld::CellStore* cell, std::vector<DoorMarker>& out) override;
///< get a list of teleport door markers for a given cell, to be displayed on the local map ///< 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. ///< 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. ///< 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. ///< 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. ///< 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. ///< Return ' ', if there is no global variable with this name.
std::string getCellName (const MWWorld::CellStore *cell = nullptr) const override; std::string getCellName (const MWWorld::CellStore *cell = nullptr) const override;
@ -283,11 +283,11 @@ namespace MWWorld
void removeRefScript (MWWorld::RefData *ref) override; void removeRefScript (MWWorld::RefData *ref) override;
//< Remove the script attached to ref from mLocalScripts //< 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. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do non search inactive cells. /// \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. ///< Return a pointer to a liveCellRef with the given name.
/// \param activeOnly do not search inactive cells. /// \param activeOnly do not search inactive cells.

View file

@ -102,12 +102,12 @@ namespace
class GlobalVariables class GlobalVariables
{ {
std::map<std::string, int> mShorts; std::map<std::string, int, std::less<>> mShorts;
std::map<std::string, int> mLongs; std::map<std::string, int, std::less<>> mLongs;
std::map<std::string, float> mFloats; std::map<std::string, float, std::less<>> mFloats;
template<class T> template<class T>
T getGlobal(const std::string& name, const std::map<std::string, T>& map) const T getGlobal(std::string_view name, const std::map<std::string, T, std::less<>>& map) const
{ {
auto it = map.find(name); auto it = map.find(name);
if(it != map.end()) if(it != map.end())
@ -122,23 +122,23 @@ namespace
mFloats.clear(); 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[{name.begin(), name.end()}] = value; };
void setLong(const std::string& name, int value) { mLongs[name] = value; }; void setLong(std::string_view name, int value) { mLongs[{name.begin(), name.end()}] = value; };
void setFloat(const std::string& name, float value) { mFloats[name] = value; }; void setFloat(std::string_view name, float value) { mFloats[{name.begin(), name.end()}] = value; };
}; };
class TestInterpreterContext : public Interpreter::Context class TestInterpreterContext : public Interpreter::Context
{ {
LocalVariables mLocals; LocalVariables mLocals;
std::map<std::string, GlobalVariables> mMembers; std::map<std::string, GlobalVariables, std::less<>> mMembers;
public: public:
std::string getTarget() const override { return {}; }; std::string getTarget() const override { return {}; };
@ -158,23 +158,23 @@ namespace
void report(const std::string& message) override {}; 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<std::string> getGlobals() const override { return {}; }; std::vector<std::string> 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 {}; }; std::string getActorName() const override { return {}; };
@ -200,7 +200,7 @@ namespace
std::string getCurrentCellName() const override { return {}; }; 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); auto it = mMembers.find(id);
if(it != mMembers.end()) if(it != mMembers.end())
@ -208,7 +208,7 @@ namespace
return {}; 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); auto it = mMembers.find(id);
if(it != mMembers.end()) if(it != mMembers.end())
@ -216,7 +216,7 @@ namespace
return {}; 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); auto it = mMembers.find(id);
if(it != mMembers.end()) if(it != mMembers.end())
@ -224,11 +224,11 @@ namespace
return {}; 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[{id.begin(), id.end()}].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[{id.begin(), id.end()}].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[{id.begin(), id.end()}].setFloat(name, value); };
}; };
struct CompiledScript struct CompiledScript

View file

@ -86,7 +86,7 @@ namespace Compiler
void visitedCharacter(char c) override {} void visitedCharacter(char c) override {}
public: public:
void process(const std::string& message) override void process(std::string_view message) override
{ {
mArguments.clear(); mArguments.clear();
::Misc::MessageFormatParser::process(message); ::Misc::MessageFormatParser::process(message);

View file

@ -21,7 +21,7 @@ namespace Compiler
throw std::logic_error ("Unknown variable type"); 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<std::string>& collection = get (type); const std::vector<std::string>& collection = get (type);
@ -33,7 +33,7 @@ namespace Compiler
return static_cast<int>(iter-collection.begin()); return static_cast<int>(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; return searchIndex (type, name)!=-1;
} }
@ -50,7 +50,7 @@ namespace Compiler
throw std::logic_error ("Unknown variable type"); 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)) if (search ('s', name))
return 's'; return 's';
@ -64,7 +64,7 @@ namespace Compiler
return ' '; return ' ';
} }
int Locals::getIndex (const std::string& name) const int Locals::getIndex (std::string_view name) const
{ {
int index = searchIndex ('s', name); int index = searchIndex ('s', name);
@ -94,7 +94,7 @@ namespace Compiler
std::ostream_iterator<std::string> (localFile, " ")); std::ostream_iterator<std::string> (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)); get (type).push_back (Misc::StringUtils::lowerCase (name));
} }

View file

@ -19,24 +19,24 @@ namespace Compiler
public: public:
char getType (const std::string& name) const; char getType (std::string_view name) const;
///< 's': short, 'l': long, 'f': float, ' ': does not exist. ///< '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). ///< 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 /// Return index for local variable \a name of type \a type (-1: variable does not
/// exit). /// exit).
int searchIndex (char type, const std::string& name) const; int searchIndex (char type, std::string_view name) const;
const std::vector<std::string>& get (char type) const; const std::vector<std::string>& get (char type) const;
void write (std::ostream& localFile) const; void write (std::ostream& localFile) const;
///< write declarations to file. ///< write declarations to file.
void declare (char type, const std::string& name); void declare (char type, std::string_view name);
///< declares a variable. ///< declares a variable.
void clear(); void clear();

View file

@ -37,23 +37,23 @@ namespace Interpreter
virtual void report (const std::string& message) = 0; 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<std::string> getGlobals () const = 0; virtual std::vector<std::string> 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; virtual std::string getActorName() const = 0;
@ -79,17 +79,17 @@ namespace Interpreter
virtual std::string getCurrentCellName() const = 0; 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; = 0;
}; };
} }

View file

@ -122,7 +122,7 @@ namespace Interpreter
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger; int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index); std::string_view name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalShort (name, data); runtime.getContext().setGlobalShort (name, data);
@ -140,7 +140,7 @@ namespace Interpreter
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
int index = runtime[1].mInteger; int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index); std::string_view name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalLong (name, data); runtime.getContext().setGlobalLong (name, data);
@ -158,7 +158,7 @@ namespace Interpreter
Type_Float data = runtime[0].mFloat; Type_Float data = runtime[0].mFloat;
int index = runtime[1].mInteger; int index = runtime[1].mInteger;
std::string name = runtime.getStringLiteral (index); std::string_view name = runtime.getStringLiteral (index);
runtime.getContext().setGlobalFloat (name, data); runtime.getContext().setGlobalFloat (name, data);
@ -174,7 +174,7 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
int index = runtime[0].mInteger; 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); Type_Integer value = runtime.getContext().getGlobalShort (name);
runtime[0].mInteger = value; runtime[0].mInteger = value;
} }
@ -187,7 +187,7 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
int index = runtime[0].mInteger; 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); Type_Integer value = runtime.getContext().getGlobalLong (name);
runtime[0].mInteger = value; runtime[0].mInteger = value;
} }
@ -200,7 +200,7 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
int index = runtime[0].mInteger; 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); Type_Float value = runtime.getContext().getGlobalFloat (name);
runtime[0].mFloat = value; runtime[0].mFloat = value;
} }
@ -215,9 +215,9 @@ namespace Interpreter
{ {
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
Type_Integer index = runtime[1].mInteger; Type_Integer index = runtime[1].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberShort (id, variable, data, TGlobal); runtime.getContext().setMemberShort (id, variable, data, TGlobal);
@ -236,9 +236,9 @@ namespace Interpreter
{ {
Type_Integer data = runtime[0].mInteger; Type_Integer data = runtime[0].mInteger;
Type_Integer index = runtime[1].mInteger; Type_Integer index = runtime[1].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberLong (id, variable, data, TGlobal); runtime.getContext().setMemberLong (id, variable, data, TGlobal);
@ -257,9 +257,9 @@ namespace Interpreter
{ {
Type_Float data = runtime[0].mFloat; Type_Float data = runtime[0].mFloat;
Type_Integer index = runtime[1].mInteger; Type_Integer index = runtime[1].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[2].mInteger; index = runtime[2].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.getContext().setMemberFloat (id, variable, data, TGlobal); runtime.getContext().setMemberFloat (id, variable, data, TGlobal);
@ -277,9 +277,9 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[1].mInteger; index = runtime[1].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
int value = runtime.getContext().getMemberShort (id, variable, TGlobal); int value = runtime.getContext().getMemberShort (id, variable, TGlobal);
@ -295,9 +295,9 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[1].mInteger; index = runtime[1].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
int value = runtime.getContext().getMemberLong (id, variable, TGlobal); int value = runtime.getContext().getMemberLong (id, variable, TGlobal);
@ -313,9 +313,9 @@ namespace Interpreter
void execute (Runtime& runtime) override void execute (Runtime& runtime) override
{ {
Type_Integer index = runtime[0].mInteger; Type_Integer index = runtime[0].mInteger;
std::string id = runtime.getStringLiteral (index); std::string_view id = runtime.getStringLiteral (index);
index = runtime[1].mInteger; index = runtime[1].mInteger;
std::string variable = runtime.getStringLiteral (index); std::string_view variable = runtime.getStringLiteral (index);
runtime.pop(); runtime.pop();
float value = runtime.getContext().getMemberFloat (id, variable, TGlobal); float value = runtime.getContext().getMemberFloat (id, variable, TGlobal);

View file

@ -97,7 +97,7 @@ namespace Interpreter
{ {
} }
void process(const std::string& message) override void process(std::string_view message) override
{ {
mFormattedMessage.clear(); mFormattedMessage.clear();
MessageFormatParser::process(message); 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); RuntimeMessageFormatter formatter(runtime);
formatter.process(message); formatter.process(message);
@ -128,7 +128,7 @@ namespace Interpreter
// message // message
int index = runtime[0].mInteger; int index = runtime[0].mInteger;
runtime.pop(); runtime.pop();
std::string message = runtime.getStringLiteral (index); std::string_view message = runtime.getStringLiteral (index);
// buttons // buttons
std::vector<std::string> buttons; std::vector<std::string> buttons;
@ -137,7 +137,8 @@ namespace Interpreter
{ {
index = runtime[0].mInteger; index = runtime[0].mInteger;
runtime.pop(); runtime.pop();
buttons.push_back (runtime.getStringLiteral (index)); std::string_view button = runtime.getStringLiteral(index);
buttons.emplace_back(button.begin(), button.end());
} }
std::reverse (buttons.begin(), buttons.end()); std::reverse (buttons.begin(), buttons.end());
@ -158,7 +159,7 @@ namespace Interpreter
// message // message
int index = runtime[0].mInteger; int index = runtime[0].mInteger;
runtime.pop(); runtime.pop();
std::string message = runtime.getStringLiteral (index); std::string_view message = runtime.getStringLiteral (index);
// handle additional parameters // handle additional parameters
std::string formattedMessage = formatMessage (message, runtime); std::string formattedMessage = formatMessage (message, runtime);

View file

@ -33,7 +33,7 @@ namespace Interpreter
return *reinterpret_cast<const float *> (&literalBlock[index]); return *reinterpret_cast<const float *> (&literalBlock[index]);
} }
std::string Runtime::getStringLiteral (int index) const std::string_view Runtime::getStringLiteral(int index) const
{ {
if (index < 0 || static_cast<int> (mCode[3]) <= 0) if (index < 0 || static_cast<int> (mCode[3]) <= 0)
throw std::out_of_range("out of range"); throw std::out_of_range("out of range");
@ -41,12 +41,12 @@ namespace Interpreter
const char *literalBlock = const char *literalBlock =
reinterpret_cast<const char *> (mCode + 4 + mCode[0] + mCode[1] + mCode[2]); reinterpret_cast<const char *> (mCode + 4 + mCode[0] + mCode[1] + mCode[2]);
int offset = 0; size_t offset = 0;
for (; index; --index) for (; index; --index)
{ {
offset += static_cast<int>(std::strlen (literalBlock+offset)) + 1; offset += std::strlen(literalBlock + offset) + 1;
if (offset / 4 >= static_cast<int> (mCode[3])) if (offset / 4 >= mCode[3])
throw std::out_of_range("out of range"); throw std::out_of_range("out of range");
} }

View file

@ -31,7 +31,7 @@ namespace Interpreter
float getFloatLiteral (int index) const; 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); void configure (const Type_Code *code, int codeSize, Context& context);
///< \a context and \a code must exist as least until either configure, clear or ///< \a context and \a code must exist as least until either configure, clear or

View file

@ -4,7 +4,7 @@ namespace Misc
{ {
MessageFormatParser::~MessageFormatParser() {} 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) for (unsigned int i = 0; i < m.size(); ++i)
{ {

View file

@ -28,7 +28,7 @@ namespace Misc
public: public:
virtual ~MessageFormatParser(); virtual ~MessageFormatParser();
virtual void process(const std::string& message); virtual void process(std::string_view message);
}; };
} }