From 262b29ed40e65024736221085d9ceb557b19f6a9 Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 23 Aug 2022 16:59:03 +0200 Subject: [PATCH 1/2] Use string_view in modifyBaseInventory --- apps/openmw/mwclass/container.cpp | 2 +- apps/openmw/mwclass/container.hpp | 2 +- apps/openmw/mwclass/creature.cpp | 2 +- apps/openmw/mwclass/creature.hpp | 2 +- apps/openmw/mwclass/npc.cpp | 2 +- apps/openmw/mwclass/npc.hpp | 2 +- apps/openmw/mwmechanics/inventory.hpp | 4 ++-- apps/openmw/mwscript/containerextensions.cpp | 8 ++++---- apps/openmw/mwscript/miscextensions.cpp | 2 +- apps/openmw/mwworld/class.cpp | 2 +- apps/openmw/mwworld/class.hpp | 2 +- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/openmw/mwclass/container.cpp b/apps/openmw/mwclass/container.cpp index 1d352035aa..fe38c1da09 100644 --- a/apps/openmw/mwclass/container.cpp +++ b/apps/openmw/mwclass/container.cpp @@ -288,7 +288,7 @@ namespace MWClass return !(ref->mBase->mFlags & ESM::Container::Organic); } - void Container::modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount) const + void Container::modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const { MWMechanics::modifyBaseInventory(containerId, itemId, amount); } diff --git a/apps/openmw/mwclass/container.hpp b/apps/openmw/mwclass/container.hpp index 029e86c9e2..b9573700d6 100644 --- a/apps/openmw/mwclass/container.hpp +++ b/apps/openmw/mwclass/container.hpp @@ -89,7 +89,7 @@ namespace MWClass bool useAnim() const override; - void modifyBaseInventory(const std::string& containerId, const std::string& itemId, int amount) const override; + void modifyBaseInventory(std::string_view containerId, std::string_view itemId, int amount) const override; }; } diff --git a/apps/openmw/mwclass/creature.cpp b/apps/openmw/mwclass/creature.cpp index 36076f100b..da105686f7 100644 --- a/apps/openmw/mwclass/creature.cpp +++ b/apps/openmw/mwclass/creature.cpp @@ -898,7 +898,7 @@ namespace MWClass MWMechanics::setBaseAISetting(id, setting, value); } - void Creature::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const + void Creature::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const { MWMechanics::modifyBaseInventory(actorId, itemId, amount); } diff --git a/apps/openmw/mwclass/creature.hpp b/apps/openmw/mwclass/creature.hpp index d578e262b6..73b716d1ed 100644 --- a/apps/openmw/mwclass/creature.hpp +++ b/apps/openmw/mwclass/creature.hpp @@ -138,7 +138,7 @@ namespace MWClass void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; - void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override; + void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override; float getWalkSpeed(const MWWorld::Ptr& ptr) const override; diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 823babe83a..f188c672a2 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -1495,7 +1495,7 @@ namespace MWClass MWMechanics::setBaseAISetting(id, setting, value); } - void Npc::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const + void Npc::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const { MWMechanics::modifyBaseInventory(actorId, itemId, amount); } diff --git a/apps/openmw/mwclass/npc.hpp b/apps/openmw/mwclass/npc.hpp index 5b05b0cdc2..cb1b146faf 100644 --- a/apps/openmw/mwclass/npc.hpp +++ b/apps/openmw/mwclass/npc.hpp @@ -166,7 +166,7 @@ namespace MWClass void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; - void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const override; + void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const override; float getWalkSpeed(const MWWorld::Ptr& ptr) const override; diff --git a/apps/openmw/mwmechanics/inventory.hpp b/apps/openmw/mwmechanics/inventory.hpp index 6ce04a675b..517eb24820 100644 --- a/apps/openmw/mwmechanics/inventory.hpp +++ b/apps/openmw/mwmechanics/inventory.hpp @@ -10,12 +10,12 @@ #include #include -#include +#include namespace MWMechanics { template - void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) + void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) { T copy = *MWBase::Environment::get().getWorld()->getStore().get().find(actorId); for (auto& it : copy.mInventory.mList) diff --git a/apps/openmw/mwscript/containerextensions.cpp b/apps/openmw/mwscript/containerextensions.cpp index c042727edb..68d714d58b 100644 --- a/apps/openmw/mwscript/containerextensions.cpp +++ b/apps/openmw/mwscript/containerextensions.cpp @@ -118,7 +118,7 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count); return; } @@ -126,7 +126,7 @@ namespace MWScript if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) @@ -231,14 +231,14 @@ namespace MWScript // Explicit calls to non-unique actors affect the base record if(!R::implicit && ptr.getClass().isActor() && MWBase::Environment::get().getWorld()->getStore().getRefCount(ptr.getCellRef().getRefId()) > 1) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count); return; } // Calls to unresolved containers affect the base record instead else if(ptr.getClass().getType() == ESM::Container::sRecordId && (!ptr.getRefData().getCustomData() || !ptr.getClass().getContainerStore(ptr).isResolved())) { - ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), std::string{item}, -count); + ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -count); const ESM::Container* baseRecord = MWBase::Environment::get().getWorld()->getStore().get().find(ptr.getCellRef().getRefId()); const auto& ptrs = MWBase::Environment::get().getWorld()->getAll(ptr.getCellRef().getRefId()); for(const auto& container : ptrs) diff --git a/apps/openmw/mwscript/miscextensions.cpp b/apps/openmw/mwscript/miscextensions.cpp index 5ba808c217..cb289d83b0 100644 --- a/apps/openmw/mwscript/miscextensions.cpp +++ b/apps/openmw/mwscript/miscextensions.cpp @@ -64,7 +64,7 @@ namespace } ESM::LevelledListBase::LevelItem item; - item.mId = std::string{itemId}; + item.mId = itemId; item.mLevel = level; list->mList.push_back(item); } diff --git a/apps/openmw/mwworld/class.cpp b/apps/openmw/mwworld/class.cpp index 928383698f..7639b5d8b6 100644 --- a/apps/openmw/mwworld/class.cpp +++ b/apps/openmw/mwworld/class.cpp @@ -531,7 +531,7 @@ namespace MWWorld throw std::runtime_error ("class does not have creature stats"); } - void Class::modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const + void Class::modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const { throw std::runtime_error ("class does not have an inventory store"); } diff --git a/apps/openmw/mwworld/class.hpp b/apps/openmw/mwworld/class.hpp index e6e656299d..4cc16ee7f2 100644 --- a/apps/openmw/mwworld/class.hpp +++ b/apps/openmw/mwworld/class.hpp @@ -368,7 +368,7 @@ namespace MWWorld virtual void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const; - virtual void modifyBaseInventory(const std::string& actorId, const std::string& itemId, int amount) const; + virtual void modifyBaseInventory(std::string_view actorId, std::string_view itemId, int amount) const; }; } From 42e59878c5316eee9c3798a06c3edfd834f9c57a Mon Sep 17 00:00:00 2001 From: Evil Eye Date: Tue, 23 Aug 2022 18:25:25 +0200 Subject: [PATCH 2/2] Use string_view in more animation code --- apps/openmw/mwbase/mechanicsmanager.hpp | 3 +- apps/openmw/mwmechanics/activespells.cpp | 2 +- apps/openmw/mwmechanics/actors.cpp | 2 +- apps/openmw/mwmechanics/actors.hpp | 2 +- apps/openmw/mwmechanics/character.cpp | 2 +- apps/openmw/mwmechanics/character.hpp | 2 +- .../mwmechanics/mechanicsmanagerimp.cpp | 2 +- .../mwmechanics/mechanicsmanagerimp.hpp | 2 +- apps/openmw/mwmechanics/objects.cpp | 2 +- apps/openmw/mwmechanics/objects.hpp | 2 +- apps/openmw/mwmechanics/spellcasting.cpp | 4 +- apps/openmw/mwmechanics/spelleffects.cpp | 2 +- apps/openmw/mwrender/animation.cpp | 72 ++++++++++--------- apps/openmw/mwrender/animation.hpp | 26 +++---- apps/openmw/mwrender/util.cpp | 6 +- apps/openmw/mwrender/util.hpp | 4 +- apps/openmw/mwscript/animationextensions.cpp | 4 +- 17 files changed, 72 insertions(+), 67 deletions(-) diff --git a/apps/openmw/mwbase/mechanicsmanager.hpp b/apps/openmw/mwbase/mechanicsmanager.hpp index e542883012..55f024e5b0 100644 --- a/apps/openmw/mwbase/mechanicsmanager.hpp +++ b/apps/openmw/mwbase/mechanicsmanager.hpp @@ -2,6 +2,7 @@ #define GAME_MWBASE_MECHANICSMANAGER_H #include +#include #include #include #include @@ -158,7 +159,7 @@ namespace MWBase virtual void forceStateUpdate(const MWWorld::Ptr &ptr) = 0; ///< Forces an object to refresh its animation state. - virtual bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number=1, bool persist=false) = 0; + virtual bool playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number=1, bool persist=false) = 0; ///< Run animation for a MW-reference. Calls to this function for references that are currently not /// in the scene should be ignored. /// diff --git a/apps/openmw/mwmechanics/activespells.cpp b/apps/openmw/mwmechanics/activespells.cpp index 18f8d4eb16..df4deada05 100644 --- a/apps/openmw/mwmechanics/activespells.cpp +++ b/apps/openmw/mwmechanics/activespells.cpp @@ -270,7 +270,7 @@ namespace MWMechanics const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); animation->addEffect( Misc::ResourceHelpers::correctMeshPath(reflectStatic->mModel, vfs), - ESM::MagicEffect::Reflect, false, std::string()); + ESM::MagicEffect::Reflect, false); } caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell(*reflected); } diff --git a/apps/openmw/mwmechanics/actors.cpp b/apps/openmw/mwmechanics/actors.cpp index 40aa628f01..3c298569cf 100644 --- a/apps/openmw/mwmechanics/actors.cpp +++ b/apps/openmw/mwmechanics/actors.cpp @@ -1935,7 +1935,7 @@ namespace MWMechanics iter->second->getCharacterController().forceStateUpdate(); } - bool Actors::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist) const + bool Actors::playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist) const { const auto iter = mIndex.find(ptr.mRef); if(iter != mIndex.end()) diff --git a/apps/openmw/mwmechanics/actors.hpp b/apps/openmw/mwmechanics/actors.hpp index 071e2e5d84..c2102615f3 100644 --- a/apps/openmw/mwmechanics/actors.hpp +++ b/apps/openmw/mwmechanics/actors.hpp @@ -121,7 +121,7 @@ namespace MWMechanics void forceStateUpdate(const MWWorld::Ptr &ptr) const; - bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, + bool playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist = false) const; void skipAnimation(const MWWorld::Ptr& ptr) const; bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) const; diff --git a/apps/openmw/mwmechanics/character.cpp b/apps/openmw/mwmechanics/character.cpp index 090b4e902b..597a0c143c 100644 --- a/apps/openmw/mwmechanics/character.cpp +++ b/apps/openmw/mwmechanics/character.cpp @@ -2347,7 +2347,7 @@ void CharacterController::unpersistAnimationState() } } -bool CharacterController::playGroup(const std::string &groupname, int mode, int count, bool persist) +bool CharacterController::playGroup(std::string_view groupname, int mode, int count, bool persist) { if(!mAnimation || !mAnimation->hasAnimation(groupname)) return false; diff --git a/apps/openmw/mwmechanics/character.hpp b/apps/openmw/mwmechanics/character.hpp index 48eefdb4b3..441815e834 100644 --- a/apps/openmw/mwmechanics/character.hpp +++ b/apps/openmw/mwmechanics/character.hpp @@ -260,7 +260,7 @@ public: void persistAnimationState() const; void unpersistAnimationState(); - bool playGroup(const std::string &groupname, int mode, int count, bool persist=false); + bool playGroup(std::string_view groupname, int mode, int count, bool persist=false); void skipAnim(); bool isAnimPlaying(const std::string &groupName) const; diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp index acb03b1504..732e0fccff 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.cpp @@ -761,7 +761,7 @@ namespace MWMechanics mActors.forceStateUpdate(ptr); } - bool MechanicsManager::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist) + bool MechanicsManager::playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist) { if(ptr.getClass().isActor()) return mActors.playAnimationGroup(ptr, groupName, mode, number, persist); diff --git a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp index 43e6794429..3dae0d9a1e 100644 --- a/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp +++ b/apps/openmw/mwmechanics/mechanicsmanagerimp.hpp @@ -133,7 +133,7 @@ namespace MWMechanics /// Attempt to play an animation group /// @return Success or error - bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false) override; + bool playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist=false) override; void skipAnimation(const MWWorld::Ptr& ptr) override; bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName) override; void persistAnimationStates() override; diff --git a/apps/openmw/mwmechanics/objects.cpp b/apps/openmw/mwmechanics/objects.cpp index 5a474abf1c..2814240db7 100644 --- a/apps/openmw/mwmechanics/objects.cpp +++ b/apps/openmw/mwmechanics/objects.cpp @@ -99,7 +99,7 @@ void Objects::onClose(const MWWorld::Ptr& ptr) iter->second->onClose(); } -bool Objects::playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist) +bool Objects::playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist) { const auto iter = mIndex.find(ptr.mRef); if (iter != mIndex.end()) diff --git a/apps/openmw/mwmechanics/objects.hpp b/apps/openmw/mwmechanics/objects.hpp index a6b2d7c675..7463093480 100644 --- a/apps/openmw/mwmechanics/objects.hpp +++ b/apps/openmw/mwmechanics/objects.hpp @@ -45,7 +45,7 @@ namespace MWMechanics bool onOpen(const MWWorld::Ptr& ptr); void onClose(const MWWorld::Ptr& ptr); - bool playAnimationGroup(const MWWorld::Ptr& ptr, const std::string& groupName, int mode, int number, bool persist=false); + bool playAnimationGroup(const MWWorld::Ptr& ptr, std::string_view groupName, int mode, int number, bool persist=false); void skipAnimation(const MWWorld::Ptr& ptr); void persistAnimationStates(); diff --git a/apps/openmw/mwmechanics/spellcasting.cpp b/apps/openmw/mwmechanics/spellcasting.cpp index f31e1baa86..58bd76ca49 100644 --- a/apps/openmw/mwmechanics/spellcasting.cpp +++ b/apps/openmw/mwmechanics/spellcasting.cpp @@ -478,7 +478,7 @@ namespace MWMechanics { animation->addEffect( Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), - effect->mIndex, false, "", effect->mParticle); + effect->mIndex, false, {}, effect->mParticle); } else { @@ -561,7 +561,7 @@ namespace MWMechanics const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); anim->addEffect( Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), - magicEffect.mIndex, loop, "", magicEffect.mParticle); + magicEffect.mIndex, loop, {}, magicEffect.mParticle); } } } diff --git a/apps/openmw/mwmechanics/spelleffects.cpp b/apps/openmw/mwmechanics/spelleffects.cpp index f491b785f6..509695c4e7 100644 --- a/apps/openmw/mwmechanics/spelleffects.cpp +++ b/apps/openmw/mwmechanics/spelleffects.cpp @@ -277,7 +277,7 @@ namespace const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); animation->addEffect( Misc::ResourceHelpers::correctMeshPath(absorbStatic->mModel, vfs), - ESM::MagicEffect::SpellAbsorption, false, std::string()); + ESM::MagicEffect::SpellAbsorption, false); } const ESM::Spell* spell = esmStore.get().search(spellId); int spellCost = 0; diff --git a/apps/openmw/mwrender/animation.cpp b/apps/openmw/mwrender/animation.cpp index 462d5ed138..2a80b6c20b 100644 --- a/apps/openmw/mwrender/animation.cpp +++ b/apps/openmw/mwrender/animation.cpp @@ -734,7 +734,7 @@ namespace MWRender return -1.f; } - float Animation::getTextKeyTime(const std::string &textKey) const + float Animation::getTextKeyTime(std::string_view textKey) const { for(AnimSourceList::const_reverse_iterator iter(mAnimSources.rbegin()); iter != mAnimSources.rend(); ++iter) { @@ -742,7 +742,7 @@ namespace MWRender for(auto iterKey = keys.begin(); iterKey != keys.end(); ++iterKey) { - if(iterKey->second.compare(0, textKey.size(), textKey) == 0) + if(iterKey->second.starts_with(textKey) == 0) return iterKey->first; } } @@ -750,20 +750,17 @@ namespace MWRender return -1.f; } - void Animation::handleTextKey(AnimState &state, const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, + void Animation::handleTextKey(AnimState &state, std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) { - const std::string &evt = key->second; + std::string_view evt = key->second; - size_t off = groupname.size()+2; - size_t len = evt.size() - off; - - if(evt.compare(0, groupname.size(), groupname) == 0 && - evt.compare(groupname.size(), 2, ": ") == 0) + if(evt.starts_with(groupname) && evt.substr(groupname.size()).starts_with(": ")) { - if(evt.compare(off, len, "loop start") == 0) + size_t off = groupname.size() + 2; + if(evt.substr(off) == "loop start") state.mLoopStartTime = key->first; - else if(evt.compare(off, len, "loop stop") == 0) + else if(evt.substr(off) == "loop stop") state.mLoopStopTime = key->first; } @@ -780,8 +777,8 @@ namespace MWRender } } - void Animation::play(const std::string &groupname, const AnimPriority& priority, int blendMask, bool autodisable, float speedmult, - const std::string &start, const std::string &stop, float startpoint, size_t loops, bool loopfallback) + void Animation::play(std::string_view groupname, const AnimPriority& priority, int blendMask, bool autodisable, float speedmult, + std::string_view start, std::string_view stop, float startpoint, size_t loops, bool loopfallback) { if(!mObjectRoot || mAnimSources.empty()) return; @@ -824,7 +821,7 @@ namespace MWRender state.mPriority = priority; state.mBlendMask = blendMask; state.mAutoDisable = autodisable; - mStates[groupname] = state; + mStates[std::string{groupname}] = state; if (state.mPlaying) { @@ -859,39 +856,48 @@ namespace MWRender resetActiveGroups(); } - bool Animation::reset(AnimState &state, const SceneUtil::TextKeyMap &keys, const std::string &groupname, const std::string &start, const std::string &stop, float startpoint, bool loopfallback) + bool Animation::reset(AnimState& state, const SceneUtil::TextKeyMap& keys, std::string_view groupname, std::string_view start, std::string_view stop, float startpoint, bool loopfallback) { // Look for text keys in reverse. This normally wouldn't matter, but for some reason undeadwolf_2.nif has two // separate walkforward keys, and the last one is supposed to be used. auto groupend = keys.rbegin(); for(;groupend != keys.rend();++groupend) { - if(groupend->second.compare(0, groupname.size(), groupname) == 0 && + if(groupend->second.starts_with(groupname) && groupend->second.compare(groupname.size(), 2, ": ") == 0) break; } - std::string starttag = groupname+": "+start; + auto equals = [] (std::string_view value, std::string_view s1, std::string_view s2, std::string_view s3 = {}) + { + if (value.starts_with(s1)) + { + value = value.substr(s1.size()); + if(value.starts_with(s2)) + return value.substr(s2.size()) == s3; + } + return false; + }; + auto startkey = groupend; - while(startkey != keys.rend() && startkey->second != starttag) + while(startkey != keys.rend() && !equals(startkey->second, groupname, ": ", start)) ++startkey; if(startkey == keys.rend() && start == "loop start") { - starttag = groupname+": start"; startkey = groupend; - while(startkey != keys.rend() && startkey->second != starttag) + while(startkey != keys.rend() && !equals(startkey->second, groupname, ": start")) ++startkey; } if(startkey == keys.rend()) return false; - const std::string stoptag = groupname+": "+stop; auto stopkey = groupend; + std::size_t checkLength = groupname.size() + 2 + stop.size(); while(stopkey != keys.rend() // We have to ignore extra garbage at the end. // The Scrib's idle3 animation has "Idle3: Stop." instead of "Idle3: Stop". // Why, just why? :( - && (stopkey->second.size() < stoptag.size() || stopkey->second.compare(0,stoptag.size(), stoptag) != 0)) + && !equals(std::string_view{stopkey->second}.substr(0, checkLength), groupname, ": ", stop)) ++stopkey; if(stopkey == keys.rend()) return false; @@ -916,8 +922,6 @@ namespace MWRender // mLoopStartTime and mLoopStopTime normally get assigned when encountering these keys while playing the animation // (see handleTextKey). But if startpoint is already past these keys, or start time is == stop time, we need to assign them now. - const std::string loopstarttag = groupname+": loop start"; - const std::string loopstoptag = groupname+": loop stop"; auto key = groupend; for (; key != startkey && key != keys.rend(); ++key) @@ -925,9 +929,9 @@ namespace MWRender if (key->first > state.getTime()) continue; - if (key->second == loopstarttag) + if (equals(key->second, groupname, ": loop start")) state.mLoopStartTime = key->first; - else if (key->second == loopstoptag) + else if (equals(key->second, groupname, ": loop stop")) state.mLoopStopTime = key->first; } @@ -1021,7 +1025,7 @@ namespace MWRender state->second.mSpeedMult = speedmult; } - bool Animation::isPlaying(const std::string &groupname) const + bool Animation::isPlaying(std::string_view groupname) const { AnimStateMap::const_iterator state(mStates.find(groupname)); if(state != mStates.end()) @@ -1029,7 +1033,7 @@ namespace MWRender return false; } - bool Animation::getInfo(const std::string &groupname, float *complete, float *speedmult) const + bool Animation::getInfo(std::string_view groupname, float *complete, float *speedmult) const { AnimStateMap::const_iterator iter = mStates.find(groupname); if(iter == mStates.end()) @@ -1069,7 +1073,7 @@ namespace MWRender return iter->second.mLoopCount; } - void Animation::disable(const std::string &groupname) + void Animation::disable(std::string_view groupname) { AnimStateMap::iterator iter = mStates.find(groupname); if(iter != mStates.end()) @@ -1272,7 +1276,7 @@ namespace MWRender return movement; } - void Animation::setLoopingEnabled(const std::string &groupname, bool enabled) + void Animation::setLoopingEnabled(std::string_view groupname, bool enabled) { AnimStateMap::iterator state(mStates.find(groupname)); if(state != mStates.end()) @@ -1511,7 +1515,7 @@ namespace MWRender mExtraLightSource->setActorFade(mAlpha); } - void Animation::addEffect (const std::string& model, int effectId, bool loop, const std::string& bonename, const std::string& texture) + void Animation::addEffect(const std::string& model, int effectId, bool loop, std::string_view bonename, std::string_view texture) { if (!mObjectRoot.get()) return; @@ -1537,7 +1541,7 @@ namespace MWRender { NodeMap::const_iterator found = getNodeMap().find(bonename); if (found == getNodeMap().end()) - throw std::runtime_error("Can't find bone " + bonename); + throw std::runtime_error("Can't find bone " + std::string{bonename}); parentNode = found->second; } @@ -1648,7 +1652,7 @@ namespace MWRender return true; } - const osg::Node* Animation::getNode(const std::string &name) const + const osg::Node* Animation::getNode(std::string_view name) const { NodeMap::const_iterator found = getNodeMap().find(name); if (found == getNodeMap().end()) @@ -1733,7 +1737,7 @@ namespace MWRender mRootController = addRotateController("bip01"); } - osg::ref_ptr Animation::addRotateController(const std::string &bone) + osg::ref_ptr Animation::addRotateController(std::string_view bone) { auto iter = getNodeMap().find(bone); if (iter == getNodeMap().end()) diff --git a/apps/openmw/mwrender/animation.hpp b/apps/openmw/mwrender/animation.hpp index 4c6aac4c85..a958429f39 100644 --- a/apps/openmw/mwrender/animation.hpp +++ b/apps/openmw/mwrender/animation.hpp @@ -228,7 +228,7 @@ protected: return getTime() >= mLoopStopTime && mLoopingEnabled && mLoopCount > 0; } }; - typedef std::map AnimStateMap; + typedef std::map> AnimStateMap; AnimStateMap mStates; typedef std::vector > AnimSourceList; @@ -274,7 +274,7 @@ protected: float mLegsYawRadians; float mBodyPitchRadians; - osg::ref_ptr addRotateController(const std::string& bone); + osg::ref_ptr addRotateController(std::string_view bone); bool mHasMagicEffects; @@ -307,10 +307,10 @@ protected: * false. */ bool reset(AnimState &state, const SceneUtil::TextKeyMap &keys, - const std::string &groupname, const std::string &start, const std::string &stop, + std::string_view groupname, std::string_view start, std::string_view stop, float startpoint, bool loopfallback); - void handleTextKey(AnimState &state, const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, + void handleTextKey(AnimState &state, std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map); /** Sets the root model of the object. @@ -374,7 +374,7 @@ public: * @param texture override the texture specified in the model's materials - if empty, do not override * @note Will not add an effect twice. */ - void addEffect (const std::string& model, int effectId, bool loop = false, const std::string& bonename = "", const std::string& texture = ""); + void addEffect(const std::string& model, int effectId, bool loop = false, std::string_view bonename = {}, std::string_view texture = {}); void removeEffect (int effectId); void removeEffects (); void getLoopingEffects (std::vector& out) const; @@ -412,8 +412,8 @@ public: * \param loopFallback Allow looping an animation that has no loop keys, i.e. fall back to use * the "start" and "stop" keys for looping? */ - void play(const std::string &groupname, const AnimPriority& priority, int blendMask, bool autodisable, - float speedmult, const std::string &start, const std::string &stop, + void play(std::string_view groupname, const AnimPriority& priority, int blendMask, bool autodisable, + float speedmult, std::string_view start,std::string_view stop, float startpoint, size_t loops, bool loopfallback=false); /** Adjust the speed multiplier of an already playing animation. @@ -421,7 +421,7 @@ public: void adjustSpeedMult (const std::string& groupname, float speedmult); /** Returns true if the named animation group is playing. */ - bool isPlaying(const std::string &groupname) const; + bool isPlaying(std::string_view groupname) const; /// Returns true if no important animations are currently playing on the upper body. bool upperBodyReady() const; @@ -432,13 +432,13 @@ public: * \param speedmult Stores the animation speed multiplier * \return True if the animation is active, false otherwise. */ - bool getInfo(const std::string &groupname, float *complete=nullptr, float *speedmult=nullptr) const; + bool getInfo(std::string_view groupname, float *complete=nullptr, float *speedmult=nullptr) const; /// Get the absolute position in the animation track of the first text key with the given group. float getStartTime(const std::string &groupname) const; /// Get the absolute position in the animation track of the text key - float getTextKeyTime(const std::string &textKey) const; + float getTextKeyTime(std::string_view textKey) const; /// Get the current absolute position in the animation track for the animation that is currently playing from the given group. float getCurrentTime(const std::string& groupname) const; @@ -448,21 +448,21 @@ public: /** Disables the specified animation group; * \param groupname Animation group to disable. */ - void disable(const std::string &groupname); + void disable(std::string_view groupname); /** Retrieves the velocity (in units per second) that the animation will move. */ float getVelocity(const std::string &groupname) const; virtual osg::Vec3f runAnimation(float duration); - void setLoopingEnabled(const std::string &groupname, bool enabled); + void setLoopingEnabled(std::string_view groupname, bool enabled); /// This is typically called as part of runAnimation, but may be called manually if needed. void updateEffects(); /// Return a node with the specified name, or nullptr if not existing. /// @note The matching is case-insensitive. - const osg::Node* getNode(const std::string& name) const; + const osg::Node* getNode(std::string_view name) const; virtual bool useShieldAnimations() const { return false; } virtual bool getWeaponsShown() const { return false; } diff --git a/apps/openmw/mwrender/util.cpp b/apps/openmw/mwrender/util.cpp index e3fc48040f..1c7497c395 100644 --- a/apps/openmw/mwrender/util.cpp +++ b/apps/openmw/mwrender/util.cpp @@ -14,7 +14,7 @@ namespace MWRender class TextureOverrideVisitor : public osg::NodeVisitor { public: - TextureOverrideVisitor(const std::string& texture, Resource::ResourceSystem* resourcesystem) + TextureOverrideVisitor(std::string_view texture, Resource::ResourceSystem* resourcesystem) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) , mTexture(texture) , mResourcesystem(resourcesystem) @@ -36,13 +36,13 @@ class TextureOverrideVisitor : public osg::NodeVisitor Resource::ResourceSystem* mResourcesystem; }; -void overrideFirstRootTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr node) +void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr node) { TextureOverrideVisitor overrideVisitor(texture, resourceSystem); node->accept(overrideVisitor); } -void overrideTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr node) +void overrideTexture(std::string_view texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr node) { if (texture.empty()) return; diff --git a/apps/openmw/mwrender/util.hpp b/apps/openmw/mwrender/util.hpp index a89baa22b1..559df45c15 100644 --- a/apps/openmw/mwrender/util.hpp +++ b/apps/openmw/mwrender/util.hpp @@ -19,9 +19,9 @@ namespace MWRender { // Overrides the texture of nodes in the mesh that had the same NiTexturingProperty as the first NiTexturingProperty of the .NIF file's root node, // if it had a NiTexturingProperty. Used for applying "particle textures" to magic effects. - void overrideFirstRootTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr node); + void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr node); - void overrideTexture(const std::string& texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr node); + void overrideTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr node); // Node callback to entirely skip the traversal. class NoTraverseCallback : public osg::NodeCallback diff --git a/apps/openmw/mwscript/animationextensions.cpp b/apps/openmw/mwscript/animationextensions.cpp index 12fe5256be..de715f93ac 100644 --- a/apps/openmw/mwscript/animationextensions.cpp +++ b/apps/openmw/mwscript/animationextensions.cpp @@ -58,7 +58,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, std::numeric_limits::max(), true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, group, mode, std::numeric_limits::max(), true); } }; @@ -94,7 +94,7 @@ namespace MWScript throw std::runtime_error ("animation mode out of range"); } - MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, std::string{group}, mode, loops + 1, true); + MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, group, mode, loops + 1, true); } };