mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-20 15:40:32 +00:00
Use string_view in the CharacterController
This commit is contained in:
parent
45a94bdf32
commit
55134d1e31
@ -31,7 +31,7 @@ namespace
|
||||
{
|
||||
|
||||
//chooses an attack depending on probability to avoid uniformity
|
||||
std::string chooseBestAttack(const ESM::Weapon* weapon);
|
||||
std::string_view chooseBestAttack(const ESM::Weapon* weapon);
|
||||
|
||||
osg::Vec3f AimDirToMovingTarget(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, const osg::Vec3f& vLastTargetPos,
|
||||
float duration, int weapType, float strength);
|
||||
@ -682,10 +682,8 @@ namespace MWMechanics
|
||||
namespace
|
||||
{
|
||||
|
||||
std::string chooseBestAttack(const ESM::Weapon* weapon)
|
||||
std::string_view chooseBestAttack(const ESM::Weapon* weapon)
|
||||
{
|
||||
std::string attackType;
|
||||
|
||||
if (weapon != nullptr)
|
||||
{
|
||||
//the more damage attackType deals the more probability it has
|
||||
@ -696,16 +694,13 @@ std::string chooseBestAttack(const ESM::Weapon* weapon)
|
||||
auto& prng = MWBase::Environment::get().getWorld()->getPrng();
|
||||
float roll = Misc::Rng::rollClosedProbability(prng) * (slash + chop + thrust);
|
||||
if(roll <= slash)
|
||||
attackType = "slash";
|
||||
return "slash";
|
||||
else if(roll <= (slash + thrust))
|
||||
attackType = "thrust";
|
||||
return "thrust";
|
||||
else
|
||||
attackType = "chop";
|
||||
return "chop";
|
||||
}
|
||||
else
|
||||
attackType = MWMechanics::CharacterController::getRandomAttackType();
|
||||
|
||||
return attackType;
|
||||
return MWMechanics::CharacterController::getRandomAttackType();
|
||||
}
|
||||
|
||||
osg::Vec3f AimDirToMovingTarget(const MWWorld::Ptr& actor, const MWWorld::Ptr& target, const osg::Vec3f& vLastTargetPos,
|
||||
|
@ -428,8 +428,9 @@ void CharacterController::refreshJumpAnims(JumpingState jump, bool force)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
std::string jumpAnimName = "jump" + weapShortGroup;
|
||||
std::string_view weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
std::string jumpAnimName = "jump";
|
||||
jumpAnimName += weapShortGroup;
|
||||
MWRender::Animation::BlendMask jumpmask = MWRender::Animation::BlendMask_All;
|
||||
if (!weapShortGroup.empty() && !mAnimation->hasAnimation(jumpAnimName))
|
||||
jumpAnimName = fallbackShortWeaponGroup("jump", &jumpmask);
|
||||
@ -490,13 +491,13 @@ void CharacterController::onClose() const
|
||||
}
|
||||
}
|
||||
|
||||
std::string CharacterController::getWeaponAnimation(int weaponType) const
|
||||
std::string_view CharacterController::getWeaponAnimation(int weaponType) const
|
||||
{
|
||||
std::string weaponGroup = getWeaponType(weaponType)->mLongGroup;
|
||||
std::string_view weaponGroup = getWeaponType(weaponType)->mLongGroup;
|
||||
if (isRealWeapon(weaponType) && !mAnimation->hasAnimation(weaponGroup))
|
||||
{
|
||||
static const std::string oneHandFallback = getWeaponType(ESM::Weapon::LongBladeOneHand)->mLongGroup;
|
||||
static const std::string twoHandFallback = getWeaponType(ESM::Weapon::LongBladeTwoHand)->mLongGroup;
|
||||
static const std::string_view oneHandFallback = getWeaponType(ESM::Weapon::LongBladeOneHand)->mLongGroup;
|
||||
static const std::string_view twoHandFallback = getWeaponType(ESM::Weapon::LongBladeTwoHand)->mLongGroup;
|
||||
|
||||
const ESM::WeaponType* weapInfo = getWeaponType(weaponType);
|
||||
|
||||
@ -512,7 +513,7 @@ std::string CharacterController::getWeaponAnimation(int weaponType) const
|
||||
return weaponGroup;
|
||||
}
|
||||
|
||||
std::string CharacterController::getWeaponShortGroup(int weaponType) const
|
||||
std::string_view CharacterController::getWeaponShortGroup(int weaponType) const
|
||||
{
|
||||
if (weaponType == ESM::Weapon::HandToHand && !mPtr.getClass().isBipedal(mPtr))
|
||||
return {};
|
||||
@ -529,8 +530,8 @@ std::string CharacterController::fallbackShortWeaponGroup(const std::string& bas
|
||||
return baseGroupName;
|
||||
}
|
||||
|
||||
static const std::string oneHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeOneHand);
|
||||
static const std::string twoHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeTwoHand);
|
||||
static const std::string_view oneHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeOneHand);
|
||||
static const std::string_view twoHandFallback = getWeaponShortGroup(ESM::Weapon::LongBladeTwoHand);
|
||||
|
||||
std::string groupName = baseGroupName;
|
||||
const ESM::WeaponType* weapInfo = getWeaponType(mWeaponType);
|
||||
@ -583,20 +584,26 @@ void CharacterController::refreshMovementAnims(CharacterState movement, bool for
|
||||
|
||||
MWRender::Animation::BlendMask movemask = MWRender::Animation::BlendMask_All;
|
||||
|
||||
std::string weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
std::string_view weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
|
||||
// Non-biped creatures don't use spellcasting-specific movement animations.
|
||||
if(!isRealWeapon(mWeaponType) && !mPtr.getClass().isBipedal(mPtr))
|
||||
weapShortGroup.clear();
|
||||
weapShortGroup = {};
|
||||
|
||||
if (swimpos == std::string::npos && !weapShortGroup.empty())
|
||||
{
|
||||
std::string weapMovementAnimName;
|
||||
// Spellcasting stance turning is a special case
|
||||
if (mWeaponType == ESM::Weapon::Spell && isTurning())
|
||||
weapMovementAnimName = weapShortGroup + movementAnimName;
|
||||
{
|
||||
weapMovementAnimName = weapShortGroup;
|
||||
weapMovementAnimName += movementAnimName;
|
||||
}
|
||||
else
|
||||
weapMovementAnimName = movementAnimName + weapShortGroup;
|
||||
{
|
||||
weapMovementAnimName = movementAnimName;
|
||||
weapMovementAnimName += weapShortGroup;
|
||||
}
|
||||
|
||||
if (!mAnimation->hasAnimation(weapMovementAnimName))
|
||||
weapMovementAnimName = fallbackShortWeaponGroup(movementAnimName, &movemask);
|
||||
@ -705,10 +712,11 @@ void CharacterController::refreshIdleAnims(CharacterState idle, bool force)
|
||||
|
||||
if (fallback || mIdleState == CharState_Idle || mIdleState == CharState_SpecialIdle)
|
||||
{
|
||||
std::string weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
std::string_view weapShortGroup = getWeaponShortGroup(mWeaponType);
|
||||
if (!weapShortGroup.empty())
|
||||
{
|
||||
std::string weapIdleGroup = idleGroup + weapShortGroup;
|
||||
std::string weapIdleGroup = idleGroup;
|
||||
weapIdleGroup += weapShortGroup;
|
||||
if (!mAnimation->hasAnimation(weapIdleGroup))
|
||||
weapIdleGroup = fallbackShortWeaponGroup(idleGroup);
|
||||
idleGroup = weapIdleGroup;
|
||||
@ -2631,7 +2639,7 @@ void CharacterController::setVisibility(float visibility) const
|
||||
mAnimation->setAlpha(visibility);
|
||||
}
|
||||
|
||||
std::string CharacterController::getMovementBasedAttackType() const
|
||||
std::string_view CharacterController::getMovementBasedAttackType() const
|
||||
{
|
||||
float *move = mPtr.getClass().getMovementSettings(mPtr).mPosition;
|
||||
if (std::abs(move[1]) > std::abs(move[0]) + 0.2f) // forward-backward
|
||||
@ -2730,12 +2738,12 @@ void CharacterController::castSpell(const std::string& spellId, bool manualSpell
|
||||
action.prepare(mPtr);
|
||||
}
|
||||
|
||||
void CharacterController::setAIAttackType(const std::string& attackType)
|
||||
void CharacterController::setAIAttackType(std::string_view attackType)
|
||||
{
|
||||
mAttackType = attackType;
|
||||
}
|
||||
|
||||
std::string CharacterController::getRandomAttackType()
|
||||
std::string_view CharacterController::getRandomAttackType()
|
||||
{
|
||||
MWBase::World* world = MWBase::Environment::get().getWorld();
|
||||
float random = Misc::Rng::rollProbability(world->getPrng());
|
||||
|
@ -183,7 +183,7 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
||||
bool mIsMovingBackward{false};
|
||||
osg::Vec2f mSmoothedSpeed;
|
||||
|
||||
std::string getMovementBasedAttackType() const;
|
||||
std::string_view getMovementBasedAttackType() const;
|
||||
|
||||
void clearStateAnimation(std::string &anim) const;
|
||||
void resetCurrentJumpState();
|
||||
@ -227,8 +227,8 @@ class CharacterController : public MWRender::Animation::TextKeyListener
|
||||
|
||||
std::string fallbackShortWeaponGroup(const std::string& baseGroupName, MWRender::Animation::BlendMask* blendMask = nullptr) const;
|
||||
|
||||
std::string getWeaponAnimation(int weaponType) const;
|
||||
std::string getWeaponShortGroup(int weaponType) const;
|
||||
std::string_view getWeaponAnimation(int weaponType) const;
|
||||
std::string_view getWeaponShortGroup(int weaponType) const;
|
||||
|
||||
bool getAttackingOrSpell() const;
|
||||
void setAttackingOrSpell(bool attackingOrSpell) const;
|
||||
@ -289,8 +289,8 @@ public:
|
||||
|
||||
void setVisibility(float visibility) const;
|
||||
void castSpell(const std::string& spellId, bool manualSpell=false);
|
||||
void setAIAttackType(const std::string& attackType);
|
||||
static std::string getRandomAttackType();
|
||||
void setAIAttackType(std::string_view attackType);
|
||||
static std::string_view getRandomAttackType();
|
||||
|
||||
bool readyToPrepareAttack() const;
|
||||
bool readyToStartAttack() const;
|
||||
|
@ -692,7 +692,7 @@ namespace MWRender
|
||||
mAnimVelocities.clear();
|
||||
}
|
||||
|
||||
bool Animation::hasAnimation(const std::string &anim) const
|
||||
bool Animation::hasAnimation(std::string_view anim) const
|
||||
{
|
||||
AnimSourceList::const_iterator iter(mAnimSources.begin());
|
||||
for(;iter != mAnimSources.end();++iter)
|
||||
|
@ -385,7 +385,7 @@ public:
|
||||
|
||||
virtual void updatePtr(const MWWorld::Ptr &ptr);
|
||||
|
||||
bool hasAnimation(const std::string &anim) const;
|
||||
bool hasAnimation(std::string_view anim) const;
|
||||
|
||||
// Specifies the axis' to accumulate on. Non-accumulated axis will just
|
||||
// move visually, but not affect the actual movement. Each x/y/z value
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace SceneUtil
|
||||
{
|
||||
@ -57,12 +58,12 @@ namespace SceneUtil
|
||||
return mTextKeyByTime.empty();
|
||||
}
|
||||
|
||||
auto findGroupStart(const std::string &groupName) const
|
||||
auto findGroupStart(std::string_view groupName) const
|
||||
{
|
||||
return std::find_if(mTextKeyByTime.begin(), mTextKeyByTime.end(), IsGroupStart{groupName});
|
||||
}
|
||||
|
||||
bool hasGroupStart(const std::string &groupName) const
|
||||
bool hasGroupStart(std::string_view groupName) const
|
||||
{
|
||||
return mGroups.count(groupName) > 0;
|
||||
}
|
||||
@ -70,7 +71,7 @@ namespace SceneUtil
|
||||
private:
|
||||
struct IsGroupStart
|
||||
{
|
||||
const std::string &mGroupName;
|
||||
std::string_view mGroupName;
|
||||
|
||||
bool operator ()(const std::multimap<float, std::string>::value_type& value) const
|
||||
{
|
||||
@ -79,7 +80,7 @@ namespace SceneUtil
|
||||
}
|
||||
};
|
||||
|
||||
std::set<std::string> mGroups;
|
||||
std::set<std::string, std::less<>> mGroups;
|
||||
std::multimap<float, std::string> mTextKeyByTime;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user