/***************************************************************************
*                                                                          *
*  Copyright (C) Golaem S.A.  All Rights Reserved.                         *
*                                                                          *
***************************************************************************/

#pragma once

#include "glmSDKAPI.h"
#include <glmAbstractTrigger.h>

namespace glm
{
    class PlayAnimationBehavior;
    class LocomotionBehavior;

    class GLM_SDK_API MotionFrameTrigger : public AbstractTrigger
    {
    public:
        typedef SmartPointer<MotionFrameTrigger> SP;

    private:
        glm::GlmString _triggerName;
        PlayAnimationBehavior* _playAnimationBe;
        LocomotionBehavior* _locomotionBe;
        int _locomotionAnimationReferenceIndex;

        double _percent;      //!< Time representation in percent of the motion duration (between [0., +infinite[)
        Time _seconds;        //!< Time representation in seconds
        unsigned int _frames; //!< Time representation in keyframe number

        glm::PODArray<float> _percentTimeToTrigger;

    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        MotionFrameTrigger();
        MotionFrameTrigger(PlayAnimationBehavior* playAnimationBe, const double& percent, const Time& seconds, unsigned int frames);
        MotionFrameTrigger(LocomotionBehavior* locomotionBe, int referenceAnimationIndex, const double& percent, const Time& seconds, unsigned int frames);
        virtual ~MotionFrameTrigger();

        virtual void allocate(BehaviorGraph& behaviorGraph);
        virtual void resize(BehaviorGraph& behaviorGraph);
		virtual bool isShareable() override;

    protected:
        // cloning
        friend class CloneFactory;
        inline virtual MotionFrameTrigger* create() const override;

        virtual bool doCall(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph, bool isAttached) override;
        virtual void doReset(int64_t index, AbstractBehavior* behavior, BehaviorGraph& behaviorGraph) override;
    };

    //-------------------------------------------------------------------------
    inline MotionFrameTrigger* MotionFrameTrigger::create() const
    {
        MotionFrameTrigger* myNewMotionFrameTrigger = GLM_NEW(MotionFrameTrigger, myNewMotionFrameTrigger, getClassMemoryStatId());
        return myNewMotionFrameTrigger;
    }
} // namespace glm
