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

#pragma once

#include "glmMemory.h"

#include <glmIContext.h>

namespace glm
{
	// predeclarations
	class AbstractUserCallbackBehavior;

	//*************************************************************************************
	/*! \class UserCallbackContext
		\brief User callback context
		\details Defines a context for behavior called at the END_USER step
	*/ //**********************************************************************************
	class GLM_SDK_API UserCallbackContext : public IContext
	{
	public:

		GLM_CLASS_STAT_ID( glm::MemoryStatIds::Simulation);

		//************************************************************
		/*! @name Constructor & Destructor
		*/ //*********************************************************
		//@{
		UserCallbackContext(ContextType::Value contextType = ContextType::USER_BEGIN); // gives order of this callback context : USER_BEGIN for PRE context, USER_END for POST context, USER_PREPHYSIC for pre physic 
		virtual ~UserCallbackContext();

		void addCallbackBehavior(SimuEntityHandle entityHandle, AbstractUserCallbackBehavior* behavior);
		void removeCallbackBehavior(SimuEntityHandle entityHandle, AbstractUserCallbackBehavior* behavior);
		//@}

		virtual bool registeredOnCreateEntityType() override { return true; }
		virtual void onCreateEntityType(int64_t maxCount) override
		{
			_components.addType(maxCount);
		}

		virtual bool registeredOnCreateEntityComponent() override { return true; }
		virtual void onCreateEntityComponent(int entityTypeIndex, int64_t entityIndex) override
		{
			_components.addComponent(entityTypeIndex, entityIndex);
		}

		virtual bool registeredOnDestroyEntityComponent() override { return true; }
		virtual void onDestroyEntityComponent(int entityTypeIndex, int64_t entityIndex) override
		{
			_components.removeComponent(entityTypeIndex, entityIndex);
		}

	private:

		virtual void doInit() override;
		virtual void doUpdateSubset(Time, int updateOrder) override;
		virtual void doFinish() override;
		virtual void setContextType() override;

		GLM_DISALLOW_COPY_AND_ASSIGN(UserCallbackContext);

		glm::ComponentsArray< glm::PODArray<AbstractUserCallbackBehavior*> >	_components;
		//glm::ComponentsArray< glm::PODArray<AbstractUserCallbackBehavior*> >	_groupComponents;
		int	_userCallbackContextType;
	};
}
