//
// Asura_DebugText.h
//
// Created by Kevin Lea - 12/06/2001 11:06:11
// Modified by Andrew Weinkove - 11/11/02
// 
// Copyright (C) 2001 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __ASURA_DEBUGTEXT_H__
#define __ASURA_DEBUGTEXT_H__

#ifdef ASURA_USE_DEBUG_TEXT

#ifndef ASURA_DEBUG_TEXT_MAX_BLOCKS
#define ASURA_DEBUG_TEXT_MAX_BLOCKS		128
#endif
#ifndef ASURA_DEBUG_TEXT_MAX_CHARS
#define ASURA_DEBUG_TEXT_MAX_CHARS		2048
#endif

#define ASURA_DEBUGTEXT_FORMAT_LEFTJUSTIFIED 0
#define ASURA_DEBUGTEXT_FORMAT_RIGHTJUSTIFIED 1
#define ASURA_DEBUGTEXT_FORMAT_CENTREJUSTIFIED 2
// ARC - 01 September 2006 12:34:29 - Block ID to allow reuse of blocks.
// The reason for this is to allow debug prints in code that isn't called every
// frame, BUT also can change at any time, e.g. information about physics objects
// as seen in the network message processing.
// Simply having a frame count for displaying the message in this case isn't
// sufficient because there isn't a guaranteed number of frames between debug prints
// leading to either:
//		(1) text flashing because the frame persistence count is too low
//		(2) adding multiple blocks containing the same information if the frame
//          persistence count is too high, leading to potential rejection of messages
//          with more current information
// By explicitly specifying a block ID, calling code can 'overwrite' the information
// in the debug text buffer, allowing high frame persistence counts to prevent problem
// (1), and only single instances of messages that will be updated as necessary,
// preventing problem (2)
//
// Specify a non-zero ID in the format flags to use (zero is treated as meaning 'no ID')
#define ASURA_DEBUGTEXT_FORMAT_BLOCKID 0x00ff0000
#define ASURA_DEBUGTEXT_BLOCKIDBITSHIFT 16
#define ASURA_DEBUGTEXT_FORMAT_NOFRAMEDISPLAY 0xff000000
#define ASURA_DEBUGTEXT_NOFRAMEDISPLAYBITSHIFT 24

#define ASURA_CHAR_TICK 6

#define ASURA_DEBUGTEXT_OUTPUT_FONT_WIDTH  (10.0f)
#define ASURA_DEBUGTEXT_OUTPUT_FONT_HEIGHT (14.0f)

#include <stdarg.h> // for using variable arguments (va_list, etc.)

#include "Core/Asura_PlatformBasics.h"

struct Asura_DebugTextBlock
{
	unsigned int uX;
	unsigned int uY;
	unsigned int uColour;
	int iFormatFlags;
	Asura_Char *szText;
};

typedef void(Asura_DebugText_PlatformPrint)(const Asura_DebugTextBlock* pxTextBlock);

class Asura_DebugText
{
	public:
		static void Initialise(void);
		static void Shutdown(void);
		static void Reset(void);
		static void IncrementDefaultTextX(const u_int uIncrement = 1)	{ s_uDefaultTextX += uIncrement; }
		static void IncrementDefaultTextY(const u_int uIncrement = 1)	{ s_uDefaultTextY += uIncrement; }
		static void AddDefaultTextBlock(const unsigned int uColour, const int iFormatFlags, const Asura_Char* szString, ...);
		static void AddTextBlock(const unsigned int uX, const unsigned int uY, const unsigned int uColour, const int iFormatFlags, const Asura_Char* szString, ...);
		static void RenderAll(void);

		static void SetPlatformOverride(Asura_DebugText_PlatformPrint* pfnOverride) { s_pfnPlatformOverride = pfnOverride; }
	private:
		static u_int	s_uDefaultTextX;
		static u_int	s_uDefaultTextY;

		static int s_iFontTextureIndex;
		static unsigned s_uNumTextBlocksUsed;
		static Asura_DebugTextBlock s_axDebugTextBlocks[ASURA_DEBUG_TEXT_MAX_BLOCKS];
		static unsigned s_uNumCharsUsed;
		static Asura_Char s_acTextBuffer[ASURA_DEBUG_TEXT_MAX_CHARS];
		static Asura_DebugText_PlatformPrint* s_pfnPlatformOverride;

		static void AddTextBlock(const unsigned int uX, const unsigned int uY, const unsigned int uColour, const int iFormatFlags, const Asura_Char* szString, va_list& xVAList);
};
#endif //ASURA_USE_DEBUG_TEXT

// MACROS.
#ifdef ASURA_USE_DEBUG_TEXT
	#define Asura_DebugTextPrint( __params ) \
	{ \
		Asura_DebugText::AddTextBlock __params ; \
	}
	#define Asura_DebugDefaultTextPrint( __params ) \
	{ \
		Asura_DebugText::AddDefaultTextBlock __params ; \
	}
#else
	#define Asura_DebugTextPrint( __params ) {}
	#define Asura_DebugDefaultTextPrint( __params ) {}
#endif	//ASURA_USE_DEBUG_TEXT



#endif//__ASURA_DEBUGTEXT_H__
