libraries/animation: cppcheck fixes

* Fix for potential bug in AnimLoop due to _maxFrameIndexHint being uninitialized.
* made more single argument constructors explicit.
This commit is contained in:
Anthony Thibault 2016-03-13 17:17:34 -07:00
parent 11fcf00b2a
commit 9f30556084
9 changed files with 14 additions and 21 deletions

View file

@ -21,7 +21,7 @@
class AnimExpression { class AnimExpression {
public: public:
friend class AnimTests; friend class AnimTests;
AnimExpression(const QString& str); explicit AnimExpression(const QString& str);
protected: protected:
struct Token { struct Token {
enum Type { enum Type {
@ -49,8 +49,8 @@ protected:
Comma, Comma,
Error Error
}; };
Token(Type type) : type {type} {} explicit Token(Type type) : type {type} {}
Token(const QStringRef& strRef) : type {Type::Identifier}, strVal {strRef.toString()} {} explicit Token(const QStringRef& strRef) : type {Type::Identifier}, strVal {strRef.toString()} {}
explicit Token(int val) : type {Type::Int}, intVal {val} {} explicit Token(int val) : type {Type::Int}, intVal {val} {}
explicit Token(bool val) : type {Type::Bool}, intVal {val} {} explicit Token(bool val) : type {Type::Bool}, intVal {val} {}
explicit Token(float val) : type {Type::Float}, floatVal {val} {} explicit Token(float val) : type {Type::Float}, floatVal {val} {}
@ -82,7 +82,7 @@ protected:
Modulus, Modulus,
UnaryMinus UnaryMinus
}; };
OpCode(Type type) : type {type} {} explicit OpCode(Type type) : type {type} {}
explicit OpCode(const QStringRef& strRef) : type {Type::Identifier}, strVal {strRef.toString()} {} explicit OpCode(const QStringRef& strRef) : type {Type::Identifier}, strVal {strRef.toString()} {}
explicit OpCode(const QString& str) : type {Type::Identifier}, strVal {str} {} explicit OpCode(const QString& str) : type {Type::Identifier}, strVal {str} {}
explicit OpCode(int val) : type {Type::Int}, intVal {val} {} explicit OpCode(int val) : type {Type::Int}, intVal {val} {}

View file

@ -25,7 +25,7 @@ class RotationConstraint;
class AnimInverseKinematics : public AnimNode { class AnimInverseKinematics : public AnimNode {
public: public:
AnimInverseKinematics(const QString& id); explicit AnimInverseKinematics(const QString& id);
virtual ~AnimInverseKinematics() override; virtual ~AnimInverseKinematics() override;
void loadDefaultPoses(const AnimPoseVec& poses); void loadDefaultPoses(const AnimPoseVec& poses);

View file

@ -25,7 +25,7 @@ class AnimNodeLoader : public QObject {
Q_OBJECT Q_OBJECT
public: public:
AnimNodeLoader(const QUrl& url); explicit AnimNodeLoader(const QUrl& url);
signals: signals:
void success(AnimNode::Pointer node); void success(AnimNode::Pointer node);

View file

@ -110,7 +110,7 @@ protected:
public: public:
AnimStateMachine(const QString& id); explicit AnimStateMachine(const QString& id);
virtual ~AnimStateMachine() override; virtual ~AnimStateMachine() override;
virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt, Triggers& triggersOut) override; virtual const AnimPoseVec& evaluate(const AnimVariantMap& animVars, float dt, Triggers& triggersOut) override;

View file

@ -38,7 +38,7 @@ protected:
virtual QSharedPointer<Resource> createResource(const QUrl& url, virtual QSharedPointer<Resource> createResource(const QUrl& url,
const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra); const QSharedPointer<Resource>& fallback, bool delayLoad, const void* extra);
private: private:
AnimationCache(QObject* parent = NULL); explicit AnimationCache(QObject* parent = NULL);
virtual ~AnimationCache() { } virtual ~AnimationCache() { }
}; };
@ -51,7 +51,7 @@ class Animation : public Resource {
public: public:
Animation(const QUrl& url); explicit Animation(const QUrl& url);
const FBXGeometry& getGeometry() const { return *_geometry; } const FBXGeometry& getGeometry() const { return *_geometry; }

View file

@ -40,6 +40,7 @@ AnimationLoop::AnimationLoop(const AnimationDetails& animationDetails) :
_lastFrame(animationDetails.lastFrame), _lastFrame(animationDetails.lastFrame),
_running(animationDetails.running), _running(animationDetails.running),
_currentFrame(animationDetails.currentFrame), _currentFrame(animationDetails.currentFrame),
_maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME),
_resetOnRunning(true), _resetOnRunning(true),
_lastSimulated(usecTimestampNow()) _lastSimulated(usecTimestampNow())
{ {
@ -55,6 +56,7 @@ AnimationLoop::AnimationLoop(float fps, bool loop, bool hold, bool startAutomati
_lastFrame(lastFrame), _lastFrame(lastFrame),
_running(running), _running(running),
_currentFrame(currentFrame), _currentFrame(currentFrame),
_maxFrameIndexHint(MAXIMUM_POSSIBLE_FRAME),
_resetOnRunning(true), _resetOnRunning(true),
_lastSimulated(usecTimestampNow()) _lastSimulated(usecTimestampNow())
{ {

View file

@ -19,7 +19,7 @@ public:
static const float MAXIMUM_POSSIBLE_FRAME; static const float MAXIMUM_POSSIBLE_FRAME;
AnimationLoop(); AnimationLoop();
AnimationLoop(const AnimationDetails& animationDetails); explicit AnimationLoop(const AnimationDetails& animationDetails);
AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame, AnimationLoop(float fps, bool loop, bool hold, bool startAutomatically, float firstFrame,
float lastFrame, bool running, float currentFrame); float lastFrame, bool running, float currentFrame);

View file

@ -37,17 +37,7 @@ static bool isEqual(const glm::quat& p, const glm::quat& q) {
return 1.0f - fabsf(glm::dot(p, q)) <= EPSILON; return 1.0f - fabsf(glm::dot(p, q)) <= EPSILON;
} }
#ifdef NDEBUG #define ASSERT(cond) assert(cond)
#define ASSERT(cond)
#else
#define ASSERT(cond) \
do { \
if (!(cond)) { \
int* ptr = nullptr; \
*ptr = 10; \
} \
} while (0)
#endif
// 2 meter tall dude // 2 meter tall dude
const glm::vec3 DEFAULT_RIGHT_EYE_POS(-0.3f, 0.9f, 0.0f); const glm::vec3 DEFAULT_RIGHT_EYE_POS(-0.3f, 0.9f, 0.0f);

View file

@ -83,6 +83,7 @@ public:
Hover Hover
}; };
Rig() {}
virtual ~Rig() {} virtual ~Rig() {}
void destroyAnimGraph(); void destroyAnimGraph();