
#pragma once
#ifndef AI_DEBUGRENDERER_HPP
#define AI_DEBUGRENDERER_HPP


#include <Stuff\Auto_Ptr.hpp>
#include <ElementRenderer\LineCloudElement.hpp>
#pragma warning (push)
#include <stlport\vector>
#include <stlport\string>
#pragma warning (pop)




namespace MW4AI
{
	class DebugRenderer
	{
	  public:
		DebugRenderer();
		~DebugRenderer();

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Instance
		//
		static DebugRenderer* GetInstance();

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Drawing
		//
	    void Execute();

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// AI Statistics
		//
		enum STATS_RENDERING
		{
			STATS_NONE,
			STATS_ALL,
			STATS_CURRENT_VEHICLE
		};

		STATS_RENDERING GetAIStatsRendering() const;
		void SetAIStatsRendering(STATS_RENDERING fDrawStats);

		bool GetDamageInfoRendering() const;
		void SetDamageInfoRendering(bool fDrawDamageInfo);

		bool GetMovementLineRendering() const;
		void SetMovementLineRendering(bool fDrawMovementLines);

		bool GetMovementPathRendering() const;
		void SetMovementPathRendering(bool fDrawMovementPaths);

		bool GetDeadReckoningRendering() const;
		void SetDeadReckoningRenderTime(Stuff::Time time = 0);
		Stuff::Time GetDeadReckoningRenderTime() const;

		bool GetShowNumPathRequests() const;
		void SetShowNumPathRequests(bool fShow);

		bool GetDiagnosticsRendering() const;

	  private:
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Helper functions
		//
		bool WorldToScreenCoords(const Stuff::Point3D& world_coords,
								 Stuff::Vector2DOf<Stuff::Scalar>& screen_coords) const;

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Rendering functions
		//

		void DrawLines();
		void DrawMovementPaths();
		void DrawAIStatsAndDamageInfo();
		void DrawNumPathRequests();
		void DrawLineCloud();
		void DrawDiagnostics();

		bool PositionIsInFrontOfCamera(const Stuff::Point3D& pos) const;
		Stuff::Scalar DistanceFromCamera(const Stuff::Point3D& pos) const;

		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Line-drawing functions
		//

		void ResetLinesToDraw();
		void AddPointsToLinesToDraw(const std::vector<Stuff::Point3D>& points,
									const Stuff::RGBAColor& color);

	  private:
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		// Data members
		//
		static DebugRenderer* m_Instance;

		STATS_RENDERING m_AIStatsRendering;
		bool m_DamageInfoRendering;
		bool m_DrawingMovementLines;
		bool m_DrawingMovementPaths;

		enum	{ MAX_LINE_POINTS = 400 };

		Stuff::Point3D	m_PointData[MAX_LINE_POINTS];
		Stuff::RGBAColor m_ColorData[MAX_LINE_POINTS];
		unsigned m_PointCount;
		ElementRenderer::LineCloudElement* m_LineCloud;

		Stuff::Time m_DeadReckoningRenderTime;

		bool m_ShowNumPathRequests;

		unsigned int m_LastDiagnosticSpewFileIndex;
		std::string m_LastDiagnosticSpew;

		int m_WheelDelta;
	};
};



#endif // AI_DEBUGRENDERER_HPP