//==========================================================================//
// File:	 gosFX_SpriteCloud.hpp											//
// Project:  gosFX					                                        //
// Contents: SpriteCloud Component											//
//--------------------------------------------------------------------------//
// Date      Who    Modification                                            //
// 09/28/98  JTR    Created													//
//																			//
//--------------------------------------------------------------------------//
// Copyright (C) 1997-1998, Virtual World Entertainment, Inc.               //
// All Rights reserved worldwide                                            //
// This unpublished sourcecode is PROPRIETARY and CONFIDENTIAL              //
//==========================================================================//
//
#pragma once

#include "gosFX.hpp"
#include "ParticleCloud.hpp"
#include <MLR\MLR.hpp>

namespace MidLevelRenderer {class MLRSpriteCloud;}

namespace gosFX
{
	//############################################################################
	//########################  SpriteCloud__Specification  #############################
	//############################################################################

	class SpriteCloud__Specification:
		public ParticleCloud__Specification
	{
	//----------------------------------------------------------------------
	// Constructors/Destructors
	//
	protected:
		SpriteCloud__Specification(
			Stuff::MemoryStream *stream,
			int gfx_version
		);

	public:
		typedef ParticleCloud__Specification BaseClass;

		SpriteCloud__Specification();
		~SpriteCloud__Specification();

		static SpriteCloud__Specification*
			Make(
				Stuff::MemoryStream *stream,
				int gfx_version
			);


		void 
			BuildDefaults();

		bool 
			IsDataValid(bool fix_data=false);

	//-------------------------------------------------------------------------
	// FCurves
	//
	public:
		SeededCurveOf<ComplexCurve, ComplexCurve,Curve::e_ComplexComplexType>
			m_pScale;
		ConstantCurve
			m_UOffset,
			m_VOffset,
			m_USize,
			m_VSize;
	};

	//############################################################################
	//########################  ParticleCloud__Particle  #############################
	//############################################################################

	class SpriteCloud__Particle:
		public ParticleCloud__Particle
	{
	public:
		typedef ParticleCloud__Particle BaseClass;

		Stuff::Point3D
			m_worldTranslation;
	};

//############################################################################
//#############################  SpriteCloud  #################################
//############################################################################

	class SpriteCloud : public ParticleCloud
	{
	//----------------------------------------------------------------------------
	// Class Registration Support
	//
	public:
		typedef ParticleCloud BaseClass;

		static void InitializeClass();
		static void	TerminateClass();

		static ClassData
			*DefaultData;

		typedef SpriteCloud__Specification Specification;
		typedef SpriteCloud__Particle Particle;

		enum {
			ParticleSize =
				sizeof(Particle) + sizeof(Stuff::Point3D) + sizeof(Stuff::RGBAColor)
				+ sizeof(Stuff::Scalar)
		};

	protected:
		MidLevelRenderer::MLRSpriteCloud
			*m_cloudImplementation;
		Stuff::Point3D
			*m_P_localTranslation;
		Stuff::RGBAColor
			*m_P_color;
		Stuff::Scalar
			*m_P_scale;
		MidLevelRenderer::Vector2DScalar
			m_UVs[4];

	//----------------------------------------------------------------------------
	// Constructor/Destructor
	//
	protected:
		SpriteCloud(
			Specification *spec,
			unsigned flags
		);

	public:
		~SpriteCloud();

		static SpriteCloud*
			Make(
				Specification *spec,
				unsigned flags
			);

		Specification*
			GetSpecification()
				{
					Check_Object(this);
					return
						Cast_Object(Specification*, m_specification);
				}
		Particle*
			GetParticle(unsigned index)
				{
					Check_Object(this); Check_Object(GetSpecification());
					return
						Cast_Pointer(
							Particle*,
							&m_data[index*GetSpecification()->m_particleClassSize]
						);
				}

	//----------------------------------------------------------------------------
	// Testing
	//
	public:
		void
			TestInstance() const;

	//----------------------------------------------------------------------------
	// API
	//
	protected:
		bool
			AnimateParticle(
				unsigned index,
				const Stuff::LinearMatrix4D *world_to_new_local,
				Stuff::Time till
			);
		void
			CreateNewParticle(
				unsigned index,
				Stuff::Point3D *translation
			);
		void
			DestroyParticle(unsigned index);

	public:
		bool
			Execute(ExecuteInfo *info);
		void
			Draw(DrawInfo *info);
	};
}
