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

#pragma once

#include <glmGenericSpecificConverter.h>
#include <glmSmartPointer.h>

#include <glmMutex.h>

namespace glm
{
	struct GLM_SDK_API AnimationCacheData
	{		
	public:		

		GenericSpecificConverter* _genericSpecificConverter = NULL;
		GolaemCharacter* _character = NULL;
		int _loadCharacterStatus = LoadCharacterFileErrorCode::END;
	};

	class GLM_SDK_API GenericSpecificConverterPool
	{
	public:

		GLM_CLASS_STAT_ID( glm::MemoryStatIds::GolaemShared)

		GenericSpecificConverterPool();

		~GenericSpecificConverterPool();

		//************************************************************
		//! @name Generic Specific Converter cache per mapping name
		//************************************************************
		//@{

		// character file name will be used as key for storage
		AnimationCacheData& loadCacheData(const GlmString& characterFile, GenericSpecificConverter::SpecificPostureBlindData::Value specificAnimationBlindDataMod, float rollExtractionBaseOffset);
	
		// only get existing converter, or return NULL
		GenericSpecificConverter* getGenericSpecificConverter(const char* characterFile);
		GolaemCharacter* getCharacter(const char* characterFile);

		void createDummyCharacter(); // create a one bone character called "dummy" (utility for external entities of crowd)
		GenericSpecificConverter* getDummyGenericSpecificConverter();
		//GolaemCharacter* getDummyCharacter(); unused

		void clear();
		//@}

	protected:

		//************************************************************
		//! @name Generic Animation Cache data
		//************************************************************
		//@{
		glm::GlmMap<glm::GlmString, AnimationCacheData> _animationCacheData;
		//@}

		glm::SpinLock _converterPoolCacheLock;
	};
}
