///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_Platform_FMV.cpp
// Author : Catalin Arsenescu
// Date   : 24/04/08
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

// This file's header
#include "FMV/AVP_FMV.h"

// Asura Headers
#include "Cutscene/Asura_FMVSubtitles.h"
#include "Core/Asura_String.h"

// Asura PS3 Headers
#include "FMV/Asura_PS3_FMV.h"

// Asura independent headers
#include "Rendering/Asura_Render.h"
#include "Rendering/Asura_Viewport.h"

void Platform_SubtitleCallback(float fTime, void *pArg)
{
	Asura_FMVSubtitles::RenderSubtitleByTime(fTime);
}

void AVP_FMV::Platform_Initialise()
{
}

void AVP_FMV::Platform_Shutdown()
{
}

bool AVP_FMV::Platform_Play(const char* szFilename, int iAudioStream, bool bLoop)
{
	if (true)
	{
		return true;
	}

	u_int uFlags = ASURA_PS3_FMV_ALLOWSKIP;
	if(bLoop)
	{
		uFlags |= ASURA_PS3_FMV_LOOP;
	}
	char szPath[256];
	Asura_PrintfToBfr(szPath,"FMV\\%s.pam",256,0,szFilename);

	// Render a few frames of black since the movie player does not clear the screen
	u_int uPreLogoLoadingScreenRenderCount = 2;
	while( uPreLogoLoadingScreenRenderCount-- )
	{
		Asura_Render::BeginFrame();

		// Clear background.
		Asura_Render::Overlay.Colour           = 0xff000000;
		Asura_Render::Overlay.TextureIndex     = ASURA_TEXTURE_NONE;
		Asura_Render::Overlay.TranslucencyMode = ASURA_TRANSLUCENCY_NORMAL;
		Asura_Render::Overlay.SetRectXY( 0.0f, 0.0f, static_cast< float >( Asura_Viewport::GetWidth() ), static_cast< float >( Asura_Viewport::GetHeight() ) );
		Asura_Render::Overlay.Render();
		Asura_Render::FlushDisplay();

		Asura_Render::EndFrame();
		Asura_PS3_Graphics::CheckExitCallBack();
	}

	return Asura_PS3_FMV::Play(szPath, iAudioStream, uFlags, &Platform_SubtitleCallback);
}


