//
// Asura_Shard_System.h
//
// Created by Andrew Weinkove - 03/12/2002
// 
// Copyright (C) 2002 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __ASURA_SHARD_SYSTEM_H__
#define __ASURA_SHARD_SYSTEM_H__

#include "Core/Asura_Maths.h"
#include "SpecialFX/Asura_Shard_Effect.h"

template<typename T> class Asura_TrackingHandlePool;

class Asura_Shard
{
public:
	// Dynamic data.
	float m_fLifeTimeRemaining;	// Shard will disappear after this time reaches zero.
	Asura_Vector_3 m_axVertices[3];	// Vertex positions.
	Asura_Vector_3 m_axVelocities[3];	// Velocity of the vertices.
	float m_fTimeToStayStill;		// Shard will stay still for this length of time.
	// Static data.
	float m_afU[3];	// Texture coordinates.
	float m_afV[3];	// Texture coordinates.
	float m_afEdgeLengths[3];	// Length of edges.

	inline void CalculateEdgeLengths()	// Only use this function when initialising a shard AFTER setting the vertices.
	{
		for (int i=0;i<3;i++)
		{
			int iOtherVertex = i + 1;
			if (iOtherVertex == 3)
				iOtherVertex = 0;
			m_afEdgeLengths[i] = (m_axVertices[i] - m_axVertices[iOtherVertex]).Magnitude();
		}
	}
};

class Asura_Shard_System
{
	public:

		static void Initialise(void);
		static void Shutdown(void);
		static void Reset(void);

		static void Render(void);
		static void RenderCallback(Asura_Shard_Effect *pxShardEffect);
		static void Update(void);
		static void UpdateCallback(Asura_Shard_Effect *pxShardEffect);

		static Asura_Shard* AllocateShard(void);
		static void DeallocateShard(Asura_Shard* pxShard);

		static Asura_Shard_Effect* CreateShardEffect(void);
		static void DestroyShardEffect(const Asura_Shard_Effect* pxEffect);
		
        static int GetNumActiveShards() { return s_iNumberOfActiveShards; }
	private:

		static void Platform_BeginRender(void);
		static void Platform_EndRender(void);

		static int							s_iNumberOfActiveShards;
		static class Asura_ResizingMempool*	s_pxShardPool;

		static Asura_TrackingHandlePool<Asura_Shard_Effect>*s_pxShardEffectList;
};

#endif//__ASURA_SHARD_SYSTEM_H__
