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

#pragma once

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

namespace glm
{
    class GLM_SDK_API AccuOpTrigger : public AbstractTrigger
    {
    public:
        typedef SmartPointer<AccuOpTrigger> SP;

    private:
        AbstractTrigger::SP _previousTrigger;

        unsigned int _accuCount;
        bool _resetOnFalse;
        glm::Array<unsigned int> _accuCurrCount; //!< Per entity data
    public:
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        AccuOpTrigger(AbstractTrigger::SP trigger = NULL, unsigned int accuCount = 0, bool resetOnFalse = false);

        virtual ~AccuOpTrigger();

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

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

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

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