//==========================================================================//
// File:	 gosFX_PointCloud.hpp											//
// Project:  gosFX					                                        //
// Contents: PointCloud 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 MLRPointCloud;}

namespace gosFX
{
	//############################################################################
	//########################  PointCloud__Specification  #############################
	//############################################################################

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

	public:
		typedef ParticleCloud__Specification BaseClass;

		PointCloud__Specification(Stuff::RegisteredClass::ClassID class_id);
		~PointCloud__Specification();

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

		virtual bool IsDataValid(bool fix_data=false);
	};

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

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

		Stuff::Point3D
			m_worldTranslation;
	};

//############################################################################
//#############################  PointCloud  #################################
//############################################################################

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

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

		static ClassData
			*DefaultData;

		typedef PointCloud__Specification Specification;
		typedef PointCloud__Particle Particle;

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

	protected:
		MidLevelRenderer::MLRPointCloud
			*m_cloudImplementation;
		Stuff::Point3D
			*m_P_localTranslation;
		Stuff::RGBAColor
			*m_P_color;

	//----------------------------------------------------------------------------
	// Constructor/Destructor
	//
	protected:
		PointCloud(
			ClassData *class_data,
			Specification *spec,
			unsigned flags
		);

	public:
		~PointCloud();

		static PointCloud*
			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);
	};
}
