1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-06 00:55:50 +00:00

Use std::string_view whenever reasonable in CharacterController

C++ Core Guidelines SL.str.2
This commit is contained in:
Alexei Kotov 2022-06-11 03:12:43 +03:00
parent 97d4206a3d
commit 93068d71ea
3 changed files with 11 additions and 9 deletions

View File

@ -928,9 +928,9 @@ CharacterController::~CharacterController()
}
}
void CharacterController::handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map)
void CharacterController::handleTextKey(std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map)
{
const std::string &evt = key->second;
std::string_view evt = key->second;
if(evt.compare(0, 7, "sound: ") == 0)
{
@ -942,7 +942,7 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil:
auto& charClass = mPtr.getClass();
if(evt.compare(0, 10, "soundgen: ") == 0)
{
std::string soundgen = evt.substr(10);
std::string soundgen = std::string(evt.substr(10));
// The event can optionally contain volume and pitch modifiers
float volume=1.f, pitch=1.f;
@ -1022,16 +1022,18 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil:
{
std::multimap<float, std::string>::const_iterator hitKey = key;
std::string hitKeyName = std::string(groupname) + ": hit";
std::string stopKeyName = std::string(groupname) + ": stop";
// Not all animations have a hit key defined. If there is none, the hit happens with the start key.
bool hasHitKey = false;
while (hitKey != map.end())
{
if (hitKey->second == groupname + ": hit")
if (hitKey->second == hitKeyName)
{
hasHitKey = true;
break;
}
if (hitKey->second == groupname + ": stop")
if (hitKey->second == stopKeyName)
break;
++hitKey;
}
@ -2658,7 +2660,7 @@ std::string CharacterController::getMovementBasedAttackType() const
return "chop";
}
bool CharacterController::isRandomAttackAnimation(const std::string& group)
bool CharacterController::isRandomAttackAnimation(std::string_view group)
{
return (group == "attack1" || group == "swimattack1" ||
group == "attack2" || group == "swimattack2" ||

View File

@ -209,7 +209,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener
void updateIdleStormState(bool inwater) const;
std::string chooseRandomAttackAnimation() const;
static bool isRandomAttackAnimation(const std::string& group);
static bool isRandomAttackAnimation(std::string_view group);
bool isPersistentAnimPlaying() const;
@ -246,7 +246,7 @@ public:
const MWWorld::Ptr& getPtr() const { return mPtr; }
void handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) override;
void handleTextKey(std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key, const SceneUtil::TextKeyMap& map) override;
// Be careful when to call this, see comment in Actors
void updateContinuousVfx() const;

View File

@ -149,7 +149,7 @@ public:
class TextKeyListener
{
public:
virtual void handleTextKey(const std::string &groupname, SceneUtil::TextKeyMap::ConstIterator key,
virtual void handleTextKey(std::string_view groupname, SceneUtil::TextKeyMap::ConstIterator key,
const SceneUtil::TextKeyMap& map) = 0;
virtual ~TextKeyListener() = default;