#pragma once
#define MLR_MLRMOVIETEXTURE_HPP

#include <MLR\MLRTexture.hpp>

namespace MidLevelRenderer {

	class MLRTexturePool;

	class MLRMovieTexture:
		public MLRTexture
	{
		friend class MLRTexturePool;

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Initialization
	//
	public:
		static void
			InitializeClass();
		static void
			TerminateClass();

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Constructors/Destructors
	//
	protected:
		MLRMovieTexture(Stuff::MemoryStream *stream, ClassData *class_data = MLRMovieTexture::DefaultData);

	public:
		MLRMovieTexture(
			MLRTexturePool *pool,
			const char* name,
			int nrOfFrames,
			float frameTime,
			int handle,
			int hint=0,
			ClassData *class_data = MLRMovieTexture::DefaultData
		);

		~MLRMovieTexture();

		static MLRMovieTexture*
			Make(Stuff::MemoryStream *stream);

		void
			Save(Stuff::MemoryStream *stream);

		GOSImage*
			GetImage(int *h=NULL) const
				{ Check_Object(this); Verify(currentFrame>=0 && currentFrame<nrOfFrames); if(h) { *h = hint; } return imageArray[currentFrame]; }

		GOSImage*
			GetImage(int nr = 0) const
				{ Check_Object(this); if(nr>=0 && nr<nrOfFrames) return imageArray[nr]; else return NULL; }

		virtual void
			LoadImageGOS(GOSImagePool *imagePool);

		void
			RollAFrame();

		void
			RollAFrame(Stuff::Scalar timeSlice);

		void
			SetFrame(int nr)
				{ Check_Object(this); if(nr>=0 && nr<nrOfFrames) currentFrame = nr; }

		int
			GetFrame()
				{ Check_Object(this); return currentFrame; }

		int
			GetNumFrames()
				{ Check_Object(this); return nrOfFrames; }

		void
			SetFrameTime(Stuff::Scalar time)
				{ Check_Object(this); frameTime = time; }

		Stuff::Scalar
			GetFrameTime()
				{ Check_Object(this); return frameTime; }

	//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// Class Data Support
	//
	public:
		static ClassData
			*DefaultData;

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

	protected:
		Stuff::Scalar frameTime;
		Stuff::Scalar lastTime;
		Stuff::Scalar sumTimeSlice;

		int currentFrame;
		int nrOfFrames;
		GOSImage **imageArray;
	};

}
