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

#pragma once

#include "glmAbstractParentBehavior.h"

#include "glmSmartPointer.h"

namespace glm
{
    class GLM_SDK_API NoOrderBehaviorOperator : public AbstractParentBehavior
    {
    private:
        glm::Array<glm::Array<unsigned int>> _childrenToRun;
        glm::PODArray<unsigned int> _childRunning;

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

        NoOrderBehaviorOperator();
        virtual ~NoOrderBehaviorOperator();

        inline virtual bool hasChildLooping(const AbstractBehavior* /*child*/) const override;
        virtual void allocate(BehaviorGraph& graph) override;
        virtual void deallocate() override;
        virtual void resize(BehaviorGraph& graph) override;
        virtual void init(BehaviorGraph& graph) override;
        virtual void init(int64_t index, BehaviorGraph& graph) override;
        virtual void finish(int64_t index, 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;
        inline virtual NoOrderBehaviorOperator* create() const override;

    private:
        void selectChild(int64_t index, BehaviorGraph& graph);
    };

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

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