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

#pragma once

#include "glmSDKAPI.h"
#include "glmTypes.h"
#include "glmTimer.h"
#include "glmProcessingBatch.h"
#include "glmString.h"
#include "glmArray.h"
#include "glmPODArray.h"
#include "glmSingleton.h"

#include "glmQueue.h"
#include "glmArray.h"
#include "glmString.h"

namespace glm
{
    class Simulation;
    class ICallBack;
    class BehaviorContext;
    class IContext;

    /**
	* \brief Root of all simulations, aggregate simulations, and can provide batchs to SimulationProcessor
	*
	* \author Golaem <dev@golaem.com>
	*/
    class GLM_SDK_API SimulationsCollection
    {
    public: //methods
        GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

        SimulationsCollection();

        virtual ~SimulationsCollection();

        void clear(); // delete remaining simulations

        Time getDuration() const;
        int getCurrentFrame() const;

        void addSimulation(Simulation* simulation);    // enqueue init batch
        bool removeSimulation(Simulation* simulation); //// enqueue init batch

        void enqueueUpdate(Time dt); // update all simulations

        void enqueueFinish();

        bool getNextProcessingBatch(ProcessingBatch& batch);

        inline glm::GlmQueue<ProcessingBatch>& getBatchQueue()
        {
            return _batchQueue;
        }

    public:                                 //data
        glm::Array<glm::GlmString> _dirmap; //dirmap contains a list of directories to map to others when loading files (size should always be a factor of 2)

    private:
        glm::PODArray<Simulation*> _simulations;
        glm::GlmQueue<ProcessingBatch> _batchQueue;

        /// simulation duration
        Time _duration;
        int32_t _frame;
    };

    //-------------------------------------------------------------------------
    inline Time SimulationsCollection::getDuration() const
    {
        return _duration;
    }

    //-------------------------------------------------------------------------
    inline int SimulationsCollection::getCurrentFrame() const
    {
        return _frame;
    }

} // namespace glm
