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

#pragma once

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

namespace glm
{
    // Trigger enabled when a requested delay is exceeded
    class GLM_SDK_API DelayTrigger : public AbstractTrigger
    {
    private:
        glm::PODArray<glm::Time> _startTime;
        glm::PODArray<glm::Time> _triggerDelays;
        glm::Time _defaultTriggerDelay;

    public:
        typedef SmartPointer<DelayTrigger> SP;

        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        DelayTrigger();
        virtual ~DelayTrigger();

        inline void setTriggerDelay(int64_t index, glm::Time delay);
        inline void setDefaultTriggerDelay(glm::Time delay);

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

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

        // cloning
        friend class CloneFactory;
        virtual void cloneImpl(AbstractTrigger* clone, CloneFactory* factory) const override;
        inline virtual DelayTrigger* create() const override;
    };

    //-------------------------------------------------------------------------
    inline void DelayTrigger::setTriggerDelay(int64_t index, glm::Time delay)
    {
        _triggerDelays[index] = delay;
    }

    //-------------------------------------------------------------------------
    inline void DelayTrigger::setDefaultTriggerDelay(glm::Time delay)
    {
        _defaultTriggerDelay = delay;
    }

    //-------------------------------------------------------------------------
    inline DelayTrigger* DelayTrigger::create() const
    {
        DelayTrigger* myNewDelayTrigger = GLM_NEW(DelayTrigger, myNewDelayTrigger, getClassMemoryStatId());
        return myNewDelayTrigger;
    }

} // namespace glm
