1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-16 20:29:57 +00:00

Merge branch 'for_your_viewing_pleasure' into 'master'

Use string_view in more places

See merge request OpenMW/openmw!2330
This commit is contained in:
psi29a 2022-08-23 17:56:24 +00:00
commit a5a0d26976
28 changed files with 87 additions and 82 deletions

View file

@ -2,6 +2,7 @@
#define GAME_MWBASE_MECHANICSMANAGER_H #define GAME_MWBASE_MECHANICSMANAGER_H
#include <string> #include <string>
#include <string_view>
#include <vector> #include <vector>
#include <set> #include <set>
#include <cstdint> #include <cstdint>
@ -158,7 +159,7 @@ namespace MWBase
virtual void forceStateUpdate(const MWWorld::Ptr &ptr) = 0; virtual void forceStateUpdate(const MWWorld::Ptr &ptr) = 0;
///< Forces an object to refresh its animation state. ///< 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 ///< Run animation for a MW-reference. Calls to this function for references that are currently not
/// in the scene should be ignored. /// in the scene should be ignored.
/// ///

View file

@ -288,7 +288,7 @@ namespace MWClass
return !(ref->mBase->mFlags & ESM::Container::Organic); 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<ESM::Container>(containerId, itemId, amount); MWMechanics::modifyBaseInventory<ESM::Container>(containerId, itemId, amount);
} }

View file

@ -89,7 +89,7 @@ namespace MWClass
bool useAnim() const override; 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;
}; };
} }

View file

@ -898,7 +898,7 @@ namespace MWClass
MWMechanics::setBaseAISetting<ESM::Creature>(id, setting, value); MWMechanics::setBaseAISetting<ESM::Creature>(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<ESM::Creature>(actorId, itemId, amount); MWMechanics::modifyBaseInventory<ESM::Creature>(actorId, itemId, amount);
} }

View file

@ -138,7 +138,7 @@ namespace MWClass
void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; 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; float getWalkSpeed(const MWWorld::Ptr& ptr) const override;

View file

@ -1495,7 +1495,7 @@ namespace MWClass
MWMechanics::setBaseAISetting<ESM::NPC>(id, setting, value); MWMechanics::setBaseAISetting<ESM::NPC>(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<ESM::NPC>(actorId, itemId, amount); MWMechanics::modifyBaseInventory<ESM::NPC>(actorId, itemId, amount);
} }

View file

@ -166,7 +166,7 @@ namespace MWClass
void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const override; 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; float getWalkSpeed(const MWWorld::Ptr& ptr) const override;

View file

@ -270,7 +270,7 @@ namespace MWMechanics
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
animation->addEffect( animation->addEffect(
Misc::ResourceHelpers::correctMeshPath(reflectStatic->mModel, vfs), Misc::ResourceHelpers::correctMeshPath(reflectStatic->mModel, vfs),
ESM::MagicEffect::Reflect, false, std::string()); ESM::MagicEffect::Reflect, false);
} }
caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell(*reflected); caster.getClass().getCreatureStats(caster).getActiveSpells().addSpell(*reflected);
} }

View file

@ -1935,7 +1935,7 @@ namespace MWMechanics
iter->second->getCharacterController().forceStateUpdate(); 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); const auto iter = mIndex.find(ptr.mRef);
if(iter != mIndex.end()) if(iter != mIndex.end())

View file

@ -121,7 +121,7 @@ namespace MWMechanics
void forceStateUpdate(const MWWorld::Ptr &ptr) const; 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; int number, bool persist = false) const;
void skipAnimation(const MWWorld::Ptr& ptr) const; void skipAnimation(const MWWorld::Ptr& ptr) const;
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) const; bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string& groupName) const;

View file

@ -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)) if(!mAnimation || !mAnimation->hasAnimation(groupname))
return false; return false;

View file

@ -260,7 +260,7 @@ public:
void persistAnimationState() const; void persistAnimationState() const;
void unpersistAnimationState(); 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(); void skipAnim();
bool isAnimPlaying(const std::string &groupName) const; bool isAnimPlaying(const std::string &groupName) const;

View file

@ -10,12 +10,12 @@
#include <components/esm3/loadcont.hpp> #include <components/esm3/loadcont.hpp>
#include <algorithm> #include <algorithm>
#include <string> #include <string_view>
namespace MWMechanics namespace MWMechanics
{ {
template <class T> template <class T>
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<T>().find(actorId); T copy = *MWBase::Environment::get().getWorld()->getStore().get<T>().find(actorId);
for (auto& it : copy.mInventory.mList) for (auto& it : copy.mInventory.mList)

View file

@ -761,7 +761,7 @@ namespace MWMechanics
mActors.forceStateUpdate(ptr); 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()) if(ptr.getClass().isActor())
return mActors.playAnimationGroup(ptr, groupName, mode, number, persist); return mActors.playAnimationGroup(ptr, groupName, mode, number, persist);

View file

@ -133,7 +133,7 @@ namespace MWMechanics
/// Attempt to play an animation group /// Attempt to play an animation group
/// @return Success or error /// @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; void skipAnimation(const MWWorld::Ptr& ptr) override;
bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName) override; bool checkAnimationPlaying(const MWWorld::Ptr& ptr, const std::string &groupName) override;
void persistAnimationStates() override; void persistAnimationStates() override;

View file

@ -99,7 +99,7 @@ void Objects::onClose(const MWWorld::Ptr& ptr)
iter->second->onClose(); 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); const auto iter = mIndex.find(ptr.mRef);
if (iter != mIndex.end()) if (iter != mIndex.end())

View file

@ -45,7 +45,7 @@ namespace MWMechanics
bool onOpen(const MWWorld::Ptr& ptr); bool onOpen(const MWWorld::Ptr& ptr);
void onClose(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 skipAnimation(const MWWorld::Ptr& ptr);
void persistAnimationStates(); void persistAnimationStates();

View file

@ -478,7 +478,7 @@ namespace MWMechanics
{ {
animation->addEffect( animation->addEffect(
Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs),
effect->mIndex, false, "", effect->mParticle); effect->mIndex, false, {}, effect->mParticle);
} }
else else
{ {
@ -561,7 +561,7 @@ namespace MWMechanics
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
anim->addEffect( anim->addEffect(
Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs), Misc::ResourceHelpers::correctMeshPath(castStatic->mModel, vfs),
magicEffect.mIndex, loop, "", magicEffect.mParticle); magicEffect.mIndex, loop, {}, magicEffect.mParticle);
} }
} }
} }

View file

@ -277,7 +277,7 @@ namespace
const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS(); const VFS::Manager* const vfs = MWBase::Environment::get().getResourceSystem()->getVFS();
animation->addEffect( animation->addEffect(
Misc::ResourceHelpers::correctMeshPath(absorbStatic->mModel, vfs), Misc::ResourceHelpers::correctMeshPath(absorbStatic->mModel, vfs),
ESM::MagicEffect::SpellAbsorption, false, std::string()); ESM::MagicEffect::SpellAbsorption, false);
} }
const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellId); const ESM::Spell* spell = esmStore.get<ESM::Spell>().search(spellId);
int spellCost = 0; int spellCost = 0;

View file

@ -734,7 +734,7 @@ namespace MWRender
return -1.f; 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) 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) 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; return iterKey->first;
} }
} }
@ -750,20 +750,17 @@ namespace MWRender
return -1.f; 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 SceneUtil::TextKeyMap& map)
{ {
const std::string &evt = key->second; std::string_view evt = key->second;
size_t off = groupname.size()+2; if(evt.starts_with(groupname) && evt.substr(groupname.size()).starts_with(": "))
size_t len = evt.size() - off;
if(evt.compare(0, groupname.size(), groupname) == 0 &&
evt.compare(groupname.size(), 2, ": ") == 0)
{ {
if(evt.compare(off, len, "loop start") == 0) size_t off = groupname.size() + 2;
if(evt.substr(off) == "loop start")
state.mLoopStartTime = key->first; state.mLoopStartTime = key->first;
else if(evt.compare(off, len, "loop stop") == 0) else if(evt.substr(off) == "loop stop")
state.mLoopStopTime = key->first; 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, void Animation::play(std::string_view 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) std::string_view start, std::string_view stop, float startpoint, size_t loops, bool loopfallback)
{ {
if(!mObjectRoot || mAnimSources.empty()) if(!mObjectRoot || mAnimSources.empty())
return; return;
@ -824,7 +821,7 @@ namespace MWRender
state.mPriority = priority; state.mPriority = priority;
state.mBlendMask = blendMask; state.mBlendMask = blendMask;
state.mAutoDisable = autodisable; state.mAutoDisable = autodisable;
mStates[groupname] = state; mStates[std::string{groupname}] = state;
if (state.mPlaying) if (state.mPlaying)
{ {
@ -859,39 +856,48 @@ namespace MWRender
resetActiveGroups(); 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 // 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. // separate walkforward keys, and the last one is supposed to be used.
auto groupend = keys.rbegin(); auto groupend = keys.rbegin();
for(;groupend != keys.rend();++groupend) 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) groupend->second.compare(groupname.size(), 2, ": ") == 0)
break; 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; auto startkey = groupend;
while(startkey != keys.rend() && startkey->second != starttag) while(startkey != keys.rend() && !equals(startkey->second, groupname, ": ", start))
++startkey; ++startkey;
if(startkey == keys.rend() && start == "loop start") if(startkey == keys.rend() && start == "loop start")
{ {
starttag = groupname+": start";
startkey = groupend; startkey = groupend;
while(startkey != keys.rend() && startkey->second != starttag) while(startkey != keys.rend() && !equals(startkey->second, groupname, ": start"))
++startkey; ++startkey;
} }
if(startkey == keys.rend()) if(startkey == keys.rend())
return false; return false;
const std::string stoptag = groupname+": "+stop;
auto stopkey = groupend; auto stopkey = groupend;
std::size_t checkLength = groupname.size() + 2 + stop.size();
while(stopkey != keys.rend() while(stopkey != keys.rend()
// We have to ignore extra garbage at the end. // We have to ignore extra garbage at the end.
// The Scrib's idle3 animation has "Idle3: Stop." instead of "Idle3: Stop". // The Scrib's idle3 animation has "Idle3: Stop." instead of "Idle3: Stop".
// Why, just why? :( // 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; ++stopkey;
if(stopkey == keys.rend()) if(stopkey == keys.rend())
return false; return false;
@ -916,8 +922,6 @@ namespace MWRender
// mLoopStartTime and mLoopStopTime normally get assigned when encountering these keys while playing the animation // 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. // (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; auto key = groupend;
for (; key != startkey && key != keys.rend(); ++key) for (; key != startkey && key != keys.rend(); ++key)
@ -925,9 +929,9 @@ namespace MWRender
if (key->first > state.getTime()) if (key->first > state.getTime())
continue; continue;
if (key->second == loopstarttag) if (equals(key->second, groupname, ": loop start"))
state.mLoopStartTime = key->first; state.mLoopStartTime = key->first;
else if (key->second == loopstoptag) else if (equals(key->second, groupname, ": loop stop"))
state.mLoopStopTime = key->first; state.mLoopStopTime = key->first;
} }
@ -1021,7 +1025,7 @@ namespace MWRender
state->second.mSpeedMult = speedmult; 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)); AnimStateMap::const_iterator state(mStates.find(groupname));
if(state != mStates.end()) if(state != mStates.end())
@ -1029,7 +1033,7 @@ namespace MWRender
return false; 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); AnimStateMap::const_iterator iter = mStates.find(groupname);
if(iter == mStates.end()) if(iter == mStates.end())
@ -1069,7 +1073,7 @@ namespace MWRender
return iter->second.mLoopCount; return iter->second.mLoopCount;
} }
void Animation::disable(const std::string &groupname) void Animation::disable(std::string_view groupname)
{ {
AnimStateMap::iterator iter = mStates.find(groupname); AnimStateMap::iterator iter = mStates.find(groupname);
if(iter != mStates.end()) if(iter != mStates.end())
@ -1272,7 +1276,7 @@ namespace MWRender
return movement; 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)); AnimStateMap::iterator state(mStates.find(groupname));
if(state != mStates.end()) if(state != mStates.end())
@ -1511,7 +1515,7 @@ namespace MWRender
mExtraLightSource->setActorFade(mAlpha); 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()) if (!mObjectRoot.get())
return; return;
@ -1537,7 +1541,7 @@ namespace MWRender
{ {
NodeMap::const_iterator found = getNodeMap().find(bonename); NodeMap::const_iterator found = getNodeMap().find(bonename);
if (found == getNodeMap().end()) 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; parentNode = found->second;
} }
@ -1648,7 +1652,7 @@ namespace MWRender
return true; 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); NodeMap::const_iterator found = getNodeMap().find(name);
if (found == getNodeMap().end()) if (found == getNodeMap().end())
@ -1733,7 +1737,7 @@ namespace MWRender
mRootController = addRotateController("bip01"); mRootController = addRotateController("bip01");
} }
osg::ref_ptr<RotateController> Animation::addRotateController(const std::string &bone) osg::ref_ptr<RotateController> Animation::addRotateController(std::string_view bone)
{ {
auto iter = getNodeMap().find(bone); auto iter = getNodeMap().find(bone);
if (iter == getNodeMap().end()) if (iter == getNodeMap().end())

View file

@ -228,7 +228,7 @@ protected:
return getTime() >= mLoopStopTime && mLoopingEnabled && mLoopCount > 0; return getTime() >= mLoopStopTime && mLoopingEnabled && mLoopCount > 0;
} }
}; };
typedef std::map<std::string,AnimState> AnimStateMap; typedef std::map<std::string, AnimState, std::less<>> AnimStateMap;
AnimStateMap mStates; AnimStateMap mStates;
typedef std::vector<std::shared_ptr<AnimSource> > AnimSourceList; typedef std::vector<std::shared_ptr<AnimSource> > AnimSourceList;
@ -274,7 +274,7 @@ protected:
float mLegsYawRadians; float mLegsYawRadians;
float mBodyPitchRadians; float mBodyPitchRadians;
osg::ref_ptr<RotateController> addRotateController(const std::string& bone); osg::ref_ptr<RotateController> addRotateController(std::string_view bone);
bool mHasMagicEffects; bool mHasMagicEffects;
@ -307,10 +307,10 @@ protected:
* false. * false.
*/ */
bool reset(AnimState &state, const SceneUtil::TextKeyMap &keys, 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); 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); const SceneUtil::TextKeyMap& map);
/** Sets the root model of the object. /** 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 * @param texture override the texture specified in the model's materials - if empty, do not override
* @note Will not add an effect twice. * @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 removeEffect (int effectId);
void removeEffects (); void removeEffects ();
void getLoopingEffects (std::vector<int>& out) const; void getLoopingEffects (std::vector<int>& out) const;
@ -412,8 +412,8 @@ public:
* \param loopFallback Allow looping an animation that has no loop keys, i.e. fall back to use * \param loopFallback Allow looping an animation that has no loop keys, i.e. fall back to use
* the "start" and "stop" keys for looping? * the "start" and "stop" keys for looping?
*/ */
void play(const std::string &groupname, const AnimPriority& priority, int blendMask, bool autodisable, void play(std::string_view groupname, const AnimPriority& priority, int blendMask, bool autodisable,
float speedmult, const std::string &start, const std::string &stop, float speedmult, std::string_view start,std::string_view stop,
float startpoint, size_t loops, bool loopfallback=false); float startpoint, size_t loops, bool loopfallback=false);
/** Adjust the speed multiplier of an already playing animation. /** Adjust the speed multiplier of an already playing animation.
@ -421,7 +421,7 @@ public:
void adjustSpeedMult (const std::string& groupname, float speedmult); void adjustSpeedMult (const std::string& groupname, float speedmult);
/** Returns true if the named animation group is playing. */ /** 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. /// Returns true if no important animations are currently playing on the upper body.
bool upperBodyReady() const; bool upperBodyReady() const;
@ -432,13 +432,13 @@ public:
* \param speedmult Stores the animation speed multiplier * \param speedmult Stores the animation speed multiplier
* \return True if the animation is active, false otherwise. * \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. /// Get the absolute position in the animation track of the first text key with the given group.
float getStartTime(const std::string &groupname) const; float getStartTime(const std::string &groupname) const;
/// Get the absolute position in the animation track of the text key /// 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. /// 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; float getCurrentTime(const std::string& groupname) const;
@ -448,21 +448,21 @@ public:
/** Disables the specified animation group; /** Disables the specified animation group;
* \param groupname Animation group to disable. * \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. */ /** Retrieves the velocity (in units per second) that the animation will move. */
float getVelocity(const std::string &groupname) const; float getVelocity(const std::string &groupname) const;
virtual osg::Vec3f runAnimation(float duration); 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. /// This is typically called as part of runAnimation, but may be called manually if needed.
void updateEffects(); void updateEffects();
/// Return a node with the specified name, or nullptr if not existing. /// Return a node with the specified name, or nullptr if not existing.
/// @note The matching is case-insensitive. /// @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 useShieldAnimations() const { return false; }
virtual bool getWeaponsShown() const { return false; } virtual bool getWeaponsShown() const { return false; }

View file

@ -14,7 +14,7 @@ namespace MWRender
class TextureOverrideVisitor : public osg::NodeVisitor class TextureOverrideVisitor : public osg::NodeVisitor
{ {
public: public:
TextureOverrideVisitor(const std::string& texture, Resource::ResourceSystem* resourcesystem) TextureOverrideVisitor(std::string_view texture, Resource::ResourceSystem* resourcesystem)
: osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN)
, mTexture(texture) , mTexture(texture)
, mResourcesystem(resourcesystem) , mResourcesystem(resourcesystem)
@ -36,13 +36,13 @@ class TextureOverrideVisitor : public osg::NodeVisitor
Resource::ResourceSystem* mResourcesystem; Resource::ResourceSystem* mResourcesystem;
}; };
void overrideFirstRootTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node) void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node)
{ {
TextureOverrideVisitor overrideVisitor(texture, resourceSystem); TextureOverrideVisitor overrideVisitor(texture, resourceSystem);
node->accept(overrideVisitor); node->accept(overrideVisitor);
} }
void overrideTexture(const std::string &texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node) void overrideTexture(std::string_view texture, Resource::ResourceSystem *resourceSystem, osg::ref_ptr<osg::Node> node)
{ {
if (texture.empty()) if (texture.empty())
return; return;

View file

@ -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, // 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. // 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<osg::Node> node); void overrideFirstRootTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
void overrideTexture(const std::string& texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node); void overrideTexture(std::string_view texture, Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Node> node);
// Node callback to entirely skip the traversal. // Node callback to entirely skip the traversal.
class NoTraverseCallback : public osg::NodeCallback class NoTraverseCallback : public osg::NodeCallback

View file

@ -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, std::string{group}, mode, std::numeric_limits<int>::max(), true); MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, group, mode, std::numeric_limits<int>::max(), true);
} }
}; };
@ -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, std::string{group}, mode, loops + 1, true); MWBase::Environment::get().getMechanicsManager()->playAnimationGroup(ptr, group, mode, loops + 1, true);
} }
}; };

View file

@ -118,7 +118,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(), std::string{item}, count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, count);
return; return;
} }
@ -126,7 +126,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(), std::string{item}, count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, 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)
@ -231,14 +231,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(), std::string{item}, -count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -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(), std::string{item}, -count); ptr.getClass().modifyBaseInventory(ptr.getCellRef().getRefId(), item, -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)

View file

@ -64,7 +64,7 @@ namespace
} }
ESM::LevelledListBase::LevelItem item; ESM::LevelledListBase::LevelItem item;
item.mId = std::string{itemId}; item.mId = itemId;
item.mLevel = level; item.mLevel = level;
list->mList.push_back(item); list->mList.push_back(item);
} }

View file

@ -531,7 +531,7 @@ namespace MWWorld
throw std::runtime_error ("class does not have creature stats"); 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"); throw std::runtime_error ("class does not have an inventory store");
} }

View file

@ -368,7 +368,7 @@ namespace MWWorld
virtual void setBaseAISetting(const std::string& id, MWMechanics::AiSetting setting, int value) const; 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;
}; };
} }