/**
*
* \file Asura_BillboardPlant_TemplateStore.h
*
* Created by Andrew Weinkove - 05/12/2002
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
**/

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __ASURA_BILLBOARDPLANT_TEMPLATESTORE_H__
#define __ASURA_BILLBOARDPLANT_TEMPLATESTORE_H__

#ifdef ASURA_USE_BILLBOARD_PLANTS
#include "Core/Asura_String.h"

#ifndef ASURA_TOOLS
#include "Debugging/Asura_Assert.h"
#endif

class Asura_BillboardPlant_Template
{
	friend class Tools_Mode_BillboardPlants;
	friend class Asura_BillboardPlant_TemplateStore;
	friend class Asura_Chunk_BillboardPlant_Template;
	friend class Tools_BillboardPlant_Object;
	friend class Asura_BillboardPlant_Batch;
	friend class Tools_Level_Export;
	friend class Tools_SaveAsura;
public:
	~Asura_BillboardPlant_Template();
	float GetStiffness() const {return m_fStiffness;}
	float GetMaxDistortion() const {return m_fMaxDistortion;}
private:
	char *m_szTemplateName; // Only valid in tools.
	char *m_szTextureName;	// Only valid in tools.
	int m_iTextureIndex;
	float m_fTopLeftU;
	float m_fTopLeftV;
	float m_fBottomRightU;
	float m_fBottomRightV;
	float m_fHeight;
	float m_fWidth;
	float m_fMaxDistortion;
	float m_fStiffness;
	unsigned m_uUniqueID;
#define ASURA_BILLBOARDPLANT_DONTTURNTOFACE_POSITION 1
#define ASURA_BILLBOARDPLANT_USERANDOMOFFSET_POSITION 2
	union
	{
		struct
		{
			unsigned	m_bDontTurnToFaceCamera:1,
						m_bUseRandomOffset:1,
						SpareBits:30;
		};
		unsigned m_uFlags;
	};

	void operator =( const Asura_BillboardPlant_Template& xSource )
	{
#ifndef ASURA_TOOLS
		Asura_Assert(false, "This operator should only ever be called from tools");
#endif
		if (xSource.m_szTemplateName)
		{
			m_szTemplateName = new char[strlen(xSource.m_szTemplateName) + 1];
			strcpy(m_szTemplateName, xSource.m_szTemplateName);
		}
		else
			m_szTemplateName = NULL;
		if (xSource.m_szTextureName)
		{
			m_szTextureName = new char[strlen(xSource.m_szTextureName) + 1];
			strcpy(m_szTextureName, xSource.m_szTextureName);
		}
		else
			m_szTextureName = NULL;
		m_iTextureIndex = xSource.m_iTextureIndex;
		m_fTopLeftU = xSource.m_fTopLeftU;
		m_fTopLeftV = xSource.m_fTopLeftV;
		m_fBottomRightU = xSource.m_fBottomRightU;
		m_fBottomRightV = xSource.m_fBottomRightV;
		m_fHeight = xSource.m_fHeight;
		m_fWidth = xSource.m_fWidth;
		m_fMaxDistortion = xSource.m_fMaxDistortion;
		m_fStiffness = xSource.m_fStiffness;
		m_uUniqueID = xSource.m_uUniqueID;
	}

};

class Asura_BillboardPlant_TemplateStore
{
public:
	static void Initialise();
	static void Shutdown();
	static void Reset();
	static void AllocateTemplates(int iNumberOfTemplates);// Called from chunk-load
	static Asura_BillboardPlant_Template* GetTemplate(int iIndex);
	static int GetIndexFromUniqueID(unsigned uID);
	static void SetTextureID(int iIndex);
#ifdef ASURA_TOOLS
	static void LoadTextures();
	static void Save();
	static Asura_BillboardPlant_Template* CreateNewTemplate(const Asura_String &xName);
	static void DeleteTemplate(Asura_BillboardPlant_Template* pxTemplate);
	static int GetNumberOfTemplates();
	static void RegisterUniqueID(unsigned uID);
#endif // ASURA_TOOLS
private:
	static int s_iNumberOfTemplates;
	static Asura_BillboardPlant_Template *s_pxTemplates;
#ifdef ASURA_TOOLS

	static unsigned s_uNextUniqueID;
#endif // ASURA_TOOLS
};

#endif //ASURA_USE_BILLBOARD_PLANTS
#endif //__ASURA_PARTICLE_TEMPLATESTORE_H__
