/***************************************************************************
*                                                                          *
*  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 SequenceTrigger : public AbstractTrigger
    {
    public:
        glm::Array<AbstractTrigger::SP> _sequence;

    private:
        glm::PODArray<unsigned int> _sequenceIterator; // idx of the currently evaluated trigger in the sequence

    public:
        typedef SmartPointer<SequenceTrigger> SP;

        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        SequenceTrigger();
        virtual ~SequenceTrigger();

        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 SequenceTrigger* create() const override;
    };

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