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

#pragma once

#include "glmAbstractParentBehavior.h"
#include "glmSmartPointer.h"

#include "glmSmartPointer.h"

namespace glm
{
    class GLM_SDK_API ParallelBehaviorOperator : public AbstractParentBehavior
    {
    public:
        int _indexOfChildTriggeringStop;
        static const int ALL_FINISHED = -1;
        static const int ANYONE_FINISHED = -2;

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

        ParallelBehaviorOperator(int indexOfChildTriggeringStop = ALL_FINISHED);
        virtual ~ParallelBehaviorOperator();

        inline virtual bool hasChildLooping(const AbstractBehavior* /*child*/) const override;
        virtual void init(BehaviorGraph& graph) override;
        virtual void update(int64_t index, BehaviorGraph& graph, Time dt) override;
        virtual void requestStart(int64_t index, BehaviorGraph& graph) override;
        virtual void requestStop(int64_t index, BehaviorGraph& graph, unsigned int next = _nextInvalidId) override;

        // type checking - value derived from this type
        virtual bool isThisType(const AbstractBehavior* value) const override;

    protected:
        // cloning
        friend class CloneFactory;
        virtual void cloneImpl(AbstractBehavior* clone, CloneFactory* factory) const override;
        inline virtual ParallelBehaviorOperator* create() const override;
    };

    //-------------------------------------------------------------------------
    inline bool ParallelBehaviorOperator::hasChildLooping(const AbstractBehavior* /*child*/) const
    {
        return false;
    }

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

} // namespace glm
