2014-03-12 11:30:44 +01:00
|
|
|
#ifndef OPENMW_MWRENDER_WEAPONANIMATION_H
|
|
|
|
#define OPENMW_MWRENDER_WEAPONANIMATION_H
|
|
|
|
|
2015-05-31 01:07:43 +02:00
|
|
|
#include <components/sceneutil/controller.hpp>
|
|
|
|
|
2014-03-12 11:30:44 +01:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2015-05-31 01:07:43 +02:00
|
|
|
#include "animation.hpp"
|
2014-03-12 11:30:44 +01:00
|
|
|
|
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
|
2015-05-31 18:53:16 +02:00
|
|
|
class RotateController;
|
|
|
|
|
2015-05-31 01:07:43 +02:00
|
|
|
class WeaponAnimationTime : public SceneUtil::ControllerSource
|
2014-03-12 11:30:44 +01:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
Animation* mAnimation;
|
|
|
|
std::string mWeaponGroup;
|
|
|
|
float mStartTime;
|
2019-03-05 13:33:58 +04:00
|
|
|
bool mRelativeTime;
|
2014-03-12 11:30:44 +01:00
|
|
|
public:
|
2019-03-05 13:33:58 +04:00
|
|
|
WeaponAnimationTime(Animation* animation) : mAnimation(animation), mStartTime(0), mRelativeTime(false) {}
|
|
|
|
void setGroup(const std::string& group, bool relativeTime);
|
2014-03-12 11:30:44 +01:00
|
|
|
void updateStartTime();
|
|
|
|
|
2020-10-16 22:18:54 +04:00
|
|
|
float getValue(osg::NodeVisitor* nv) override;
|
2014-03-12 11:30:44 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/// Handles attach & release of projectiles for ranged weapons
|
|
|
|
class WeaponAnimation
|
|
|
|
{
|
|
|
|
public:
|
2015-05-31 01:07:43 +02:00
|
|
|
WeaponAnimation();
|
2015-05-31 18:53:16 +02:00
|
|
|
virtual ~WeaponAnimation();
|
2014-03-12 11:30:44 +01:00
|
|
|
|
2015-01-31 19:46:15 +01:00
|
|
|
/// @note If no weapon (or an invalid weapon) is equipped, this function is a no-op.
|
2021-08-15 19:50:28 +02:00
|
|
|
void attachArrow(const MWWorld::Ptr &actor);
|
2015-01-31 19:46:15 +01:00
|
|
|
|
2020-08-28 15:28:26 +04:00
|
|
|
void detachArrow(MWWorld::Ptr actor);
|
|
|
|
|
2015-01-31 19:46:15 +01:00
|
|
|
/// @note If no weapon (or an invalid weapon) is equipped, this function is a no-op.
|
2015-06-26 05:15:07 +02:00
|
|
|
void releaseArrow(MWWorld::Ptr actor, float attackStrength);
|
2014-03-12 11:30:44 +01:00
|
|
|
|
2015-05-31 18:53:16 +02:00
|
|
|
/// Add WeaponAnimation-related controllers to \a nodes and store the added controllers in \a map.
|
refactors a case insensitive map (#3184)
This PR aims to spark the retirement of a questionable pattern I have found all over our code base. I will illustrate how this pattern encourages code duplication, lacks type safety, requires documentation and can be prone to bugs.
```
std::map<std::string, Object> mMap; // Stored in all lowercase for a case-insensitive lookup
std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.emplace(lowerKey, object);
std::string lowerKey = Misc::StringUtils::lowerCase(key);
mMap.find(lowerKey);
mMap.find(key); // Not found. Oops!
```
An alternative approach produces no such issues.
```
std::unordered_map<std::string, Object, Misc::StringUtils::CiHash, Misc::StringUtils::CiEqual> mMap;
mMap.emplace(key, object);
mMap.find(key);
```
Of course, such an alternative will work for a `map` as well, but an `unordered_map` is generally preferable over a `map` with these changes because we have moved `lowerCase` into the comparison operator.
In this PR I have refactored `Animation::mNodeMap` accordingly. I have reviewed and adapted all direct and indirect usage of `Animation::mNodeMap` to ensure we do not change behaviour with this PR.
2021-10-25 07:18:26 +00:00
|
|
|
void addControllers(const Animation::NodeMap& nodes, std::vector<std::pair<osg::ref_ptr<osg::Node>, osg::ref_ptr<osg::Callback>>>& map, osg::Node* objectRoot);
|
2015-05-31 18:53:16 +02:00
|
|
|
|
|
|
|
void deleteControllers();
|
|
|
|
|
|
|
|
/// Configure controllers, should be called every animation frame.
|
|
|
|
void configureControllers(float characterPitchRadians);
|
|
|
|
|
2014-03-12 11:30:44 +01:00
|
|
|
protected:
|
2015-05-31 01:07:43 +02:00
|
|
|
PartHolderPtr mAmmunition;
|
|
|
|
|
2015-05-31 18:53:16 +02:00
|
|
|
osg::ref_ptr<RotateController> mSpineControllers[2];
|
|
|
|
|
2016-03-01 16:57:11 +01:00
|
|
|
void setControllerRotate(const osg::Quat& rotate);
|
|
|
|
void setControllerEnabled(bool enabled);
|
|
|
|
|
2015-05-31 01:07:43 +02:00
|
|
|
virtual osg::Group* getArrowBone() = 0;
|
|
|
|
virtual osg::Node* getWeaponNode() = 0;
|
|
|
|
virtual Resource::ResourceSystem* getResourceSystem() = 0;
|
|
|
|
|
2014-03-12 11:30:44 +01:00
|
|
|
virtual void showWeapon(bool show) = 0;
|
|
|
|
|
|
|
|
/// A relative factor (0-1) that decides if and how much the skeleton should be pitched
|
|
|
|
/// to indicate the facing orientation of the character, for ranged weapon aiming.
|
|
|
|
float mPitchFactor;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|