mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-01 19:45:35 +00:00
Use std::string_view whenever reasonable in CharacterController
C++ Core Guidelines SL.str.2
This commit is contained in:
parent
97d4206a3d
commit
93068d71ea
3 changed files with 11 additions and 9 deletions
|
@ -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)
|
if(evt.compare(0, 7, "sound: ") == 0)
|
||||||
{
|
{
|
||||||
|
@ -942,7 +942,7 @@ void CharacterController::handleTextKey(const std::string &groupname, SceneUtil:
|
||||||
auto& charClass = mPtr.getClass();
|
auto& charClass = mPtr.getClass();
|
||||||
if(evt.compare(0, 10, "soundgen: ") == 0)
|
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
|
// The event can optionally contain volume and pitch modifiers
|
||||||
float volume=1.f, pitch=1.f;
|
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::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.
|
// Not all animations have a hit key defined. If there is none, the hit happens with the start key.
|
||||||
bool hasHitKey = false;
|
bool hasHitKey = false;
|
||||||
while (hitKey != map.end())
|
while (hitKey != map.end())
|
||||||
{
|
{
|
||||||
if (hitKey->second == groupname + ": hit")
|
if (hitKey->second == hitKeyName)
|
||||||
{
|
{
|
||||||
hasHitKey = true;
|
hasHitKey = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (hitKey->second == groupname + ": stop")
|
if (hitKey->second == stopKeyName)
|
||||||
break;
|
break;
|
||||||
++hitKey;
|
++hitKey;
|
||||||
}
|
}
|
||||||
|
@ -2658,7 +2660,7 @@ std::string CharacterController::getMovementBasedAttackType() const
|
||||||
return "chop";
|
return "chop";
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CharacterController::isRandomAttackAnimation(const std::string& group)
|
bool CharacterController::isRandomAttackAnimation(std::string_view group)
|
||||||
{
|
{
|
||||||
return (group == "attack1" || group == "swimattack1" ||
|
return (group == "attack1" || group == "swimattack1" ||
|
||||||
group == "attack2" || group == "swimattack2" ||
|
group == "attack2" || group == "swimattack2" ||
|
||||||
|
|
|
@ -209,7 +209,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
||||||
void updateIdleStormState(bool inwater) const;
|
void updateIdleStormState(bool inwater) const;
|
||||||
|
|
||||||
std::string chooseRandomAttackAnimation() const;
|
std::string chooseRandomAttackAnimation() const;
|
||||||
static bool isRandomAttackAnimation(const std::string& group);
|
static bool isRandomAttackAnimation(std::string_view group);
|
||||||
|
|
||||||
bool isPersistentAnimPlaying() const;
|
bool isPersistentAnimPlaying() const;
|
||||||
|
|
||||||
|
@ -246,7 +246,7 @@ public:
|
||||||
|
|
||||||
const MWWorld::Ptr& getPtr() const { return mPtr; }
|
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
|
// Be careful when to call this, see comment in Actors
|
||||||
void updateContinuousVfx() const;
|
void updateContinuousVfx() const;
|
||||||
|
|
|
@ -149,7 +149,7 @@ public:
|
||||||
class TextKeyListener
|
class TextKeyListener
|
||||||
{
|
{
|
||||||
public:
|
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;
|
const SceneUtil::TextKeyMap& map) = 0;
|
||||||
|
|
||||||
virtual ~TextKeyListener() = default;
|
virtual ~TextKeyListener() = default;
|
||||||
|
|
Loading…
Reference in a new issue