//////////////////////////////////////////////////////////////////////////////
//
// Asura_PlatformTimers.cpp
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
// Description:
//
//     PS2 implementation of Asura_Timers platform-specific functionality
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura.h"

// independent includes
#include "Core/Asura_Timers.h"

// ps2 includes
#include "Core/Asura_PS2_Timers.h"
#include "Rendering/Asura_PS2_GS.h"


// G L O B A L S /////////////////////////////////////////////////////////////
static u_int g_uLastCycleCount;

void Asura_Timers::Platform_Initialise()
{}


void Asura_Timers::Platform_Reset()
{}


void Asura_Timers::Platform_Shutdown()
{}


void Asura_Timers::Platform_Update()
{
}

u_int Asura_Timers::Platform_GetTicksThisFrame()
{
	u_int uNewCycleCount = Asura_PS2_Timers::GetCycleCount();
    u_int uDuration      = Asura_PS2_Timers::GetElapsedCycles( g_uLastCycleCount, uNewCycleCount );
	g_uLastCycleCount = uNewCycleCount;
	return uDuration;
}

u_int Asura_Timers::Platform_GetTicksInFrame()
{
	return Asura_PS2_Timers::GetElapsedCycles( g_uLastCycleCount, Asura_PS2_Timers::GetCycleCount() );
}

float Asura_Timers::Platform_GetTickFrequency()
{
	return ASURA_PS2_EE_CYCLES_PER_SEC;
}


float Asura_Timers::Platform_GetDefaultFrameRate()
{
	return Asura_PS2_GS::GetRefreshRate();
}


Asura_TickCount Asura_Timers::Platform_GetCurTicks()
{
	return Asura_PS2_Timers::GetCycleCount();
}
u_int Asura_Timers::Platform_GetElapsedTicks(Asura_TickCount xStartTicks)
{
	u_int xCurrentTickCount = Asura_PS2_Timers::GetCycleCount();
	return xCurrentTickCount - xStartTicks;
}
float Asura_Timers::Platform_TicksToSeconds(Asura_TickCount uTicks)
{
	return static_cast<float>(uTicks) / ASURA_PS2_EE_CYCLES_PER_SEC;
}

Asura_TickCount Asura_Timers::Platform_SecondsToTicks(float fSeconds)
{
	return Asura_Maths::FloatToInt_Near(ASURA_PS2_EE_CYCLES_PER_SEC * fSeconds);
}
