//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// AVP_Platform_Profile_LoadAndSave.cpp
// Callum Hope - 19,1,09
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//
// File functionality to deal with saving data to file on the PS3 platform
// No actual profile functionality, just profile reading saving, loading, and writing of data used in profiles. 
// *** This file is the Main thread interface to the thread running the class Asura_PS3_SaveLoad ***
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

#if defined(AVP_SUPPORT_PROFILE_LOADANDSAVE)

// personal header
#include "LoadAndSave/AVP_Profile_LoadAndSave.h"

// asura headers
//#include "Utility/Asura_PS3_SaveLoad.h"

// avp headers
//#include "LoadAndSave/AVP_Platform_SaveState.h"

// G L O B A L   V A R I A B L E S ///////////////////////////////////////////

//static bool		g_bSaveRequestedProfile		= false;

/*// CAH TEMP here until we decide what the names will be and how we want to store multi-languages of them
static Asura_Char*			g_szProjDirName_PS3		= "AliensVsPredator";
static Asura_UnicodeChar*	g_szProjName_PS3		= L"AliensVsPredator";
static Asura_UnicodeChar*	g_szProfileSaveName_PS3	= L"ProfileData";
static Asura_UnicodeChar*	g_szProfileSaveDesc_PS3	= L"Data And Settings Unique to This Profile";
static Asura_UnicodeChar*	g_szNewSaveTitle_PS3	= L"Blank Save Slot";

// CAH TEMP until checkpoint data and save/load system is sorted out. 
static char*	g_szTEMP_CheckpointData	= 0;
*/
// F U N C T I O N   D E F I N I T I O N S ///////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_Initialise
// Scope		: static private
// Author       : 
// Date         : 
//
// Desc			: 
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_Initialise()
{
/*	// fisrt make sure that s_xProfileSaveData has values in it. 
	Platform_CopyDataToProfileFromLoadAndSave();

	// find the size of the profile data and set the global holder for it to be used whenever a save or load occurs. 
	m_iSaveFile_MaxSize = sizeof( s_xProfileSaveData );

	// set the PS3 save system goig on its own thread. 
	Asura_PS3_SaveLoad::Initialise();

	// Set the save directory on the PS3 for saves. 
	// CAH: TODO PS3 TRC ISSUE, this will have to be the game product code once we knnow it, until then its just the game name. 
	Asura_PS3_SaveLoad::SetProjectDirName( g_szProjDirName_PS3 );

	// this is generaly the name of the title. 
	Asura_PS3_SaveLoad::SetSaveDataTitle( g_szProjName_PS3 );

	// set the text inserted to blank save slots. 
	Asura_PS3_SaveLoad::SetNewDataTitle( g_szNewSaveTitle_PS3 );

	// set the callback for the profile check after loading, not used in AVP but needs to be set up. 
	Asura_PS3_SaveLoad::SetProfileCheckCallback( AVP_PS3_SaveState::CheckProfile );

	Platform_BeginProfileFlow();
*/
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_Update
// Scope		: Static Private. 
// Author       : Callum Hope
// Date         : 19/1/09
//
// Desc			: Per-frame update, because we are interacting with a asyncronous thread essentially this is ues to handle all of the requests
//				  For actions that could not be done until the other thread is idle again. 
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_Update()
{
/*	AVP_PS3_SaveState::Update();

	if( m_eLoadingState == AVP_PROFILELOAD_STATE_JUSTLOADED )
	{
		Platform_CopyDataToProfileFromLoadAndSave();
		//MKC - Applying the settigns we have just loaded so everyting is set to the right values
		s_pxProfile->ApplySettings();
	}

	if( g_bSaveRequestedProfile )
	{
		Platform_SaveProfileData();
	}
	else if( m_eLoadingState == AVP_PROFILELOAD_STATE_LOADREQUESTED )
	{
		Platform_LoadProfileData();
	}
*/
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_Shutdown
// Scope		: static private
// Author       : 
// Date         : 
//
// Desc			: Just a standard shut down for the various elements that were initialised. 
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_Shutdown()
{
	//Asura_PS3_SaveLoad::Shutdown();
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_BeginProfileFlow
// Scope		: Static Private 
// Author       : 
// Date         : 
//
// Desc			: 
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_BeginProfileFlow()
{
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_SaveProfileData
// Scope		: Static Private
// Author       : 
// Date         : 
//
// Desc			: Routein to actually (and finally) tell Asura_PS3_SaveLoad to save the profile data to disk. 
// Return		: bool, indicates a successful or failed save. 
////////////////////////////////////////////////////////////////////////////////

bool AVP_Profile_LoadAndSave::Platform_SaveProfileData()
{ 
/*	Platform_CopyDataToLoadAndSaveFromProfile();

	Asura_PS3_SaveLoad::SetSaveDataSubTitle( g_szProfileSaveName_PS3 );
	Asura_PS3_SaveLoad::SetSaveDataDetail( g_szProfileSaveDesc_PS3 );

	if( ! Asura_PS3_SaveLoad::IsBusy() )
	{
		g_bSaveRequestedProfile = false;
		return AVP_PS3_SaveState::Save( true, &s_xProfileSaveData, NULL);
	}
	else
	{
		g_bSaveRequestedProfile = true;
		return false;
	}
*/
	return false;
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_LoadProfileData
// Scope		: Static Private
// Author       : 
// Date         : 
//
// Desc			: Routein to actually (and finally) tell the Asura_PS3_SaveLoad to load the profile data on disk. 
// Return		: Return an error feedback state for the AVP_Prifile system to use. 
////////////////////////////////////////////////////////////////////////////////

AVP_Profile::E_PROFILE_FILE_STATES AVP_Profile_LoadAndSave::Platform_LoadProfileData( )
{
/*	if( ! Asura_PS3_SaveLoad::IsBusy() )
	{
		AVP_PS3_SaveState::Load( &s_xProfileSaveData, NULL );

		// NOTE no need to set the state to "Just Loaded" this is done in the AVP_PS3_SaveState Machine. 
		// set the loading state back to idle as we did not load and are not loading. 
		m_eLoadingState = AVP_PROFILELOAD_STATE_IDLE;
	}
	else
	{
		m_eLoadingState = AVP_PROFILELOAD_STATE_LOADREQUESTED;
	}
*/
	return AVP_Profile::PROFILE_DEVICE_ERROR;
}

// comment to do on implementation
void AVP_Profile_LoadAndSave::Platform_SetLoadSaveSlot( int iSlot )
{
	s_iSlot = iSlot;
}

// comment to do on implementation
void AVP_Profile_LoadAndSave::Platform_SaveCheckpoint( )
{
	// set the name fo the save about to be written
	// TODO, write a routein to dynamically make a relavalt checkpoint save name. 
	//Asura_PS3_SaveLoad::SetSaveDataSubTitle( g_szProfileSaveName_PS3 );
}

// comment to do on implementation
void AVP_Profile_LoadAndSave::Platform_LoadCheckpoint( )
{
}

// comment to do on implementation
AVP_Profile_State AVP_Profile_LoadAndSave::Platform_GetState( )
{
	return AVP_PROFILE_STATE_ERROR;
}

// comment to do on implementation
AVP_Profile_Error AVP_Profile_LoadAndSave::Platform_GetLastError( )
{
	return AVP_PROFILE_ERROR_NONE;
}

// comment to do on implementation
const Asura_UnicodeChar* AVP_Profile_LoadAndSave::Platform_GetSlotDisplayText ( const int iSlot )
{
	return L"Not Done Yet";
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_CopyDataToLoadAndSaveFromProfile
// Scope		: Static Private
// Author       : Callum Hope
// Date         : 16/1/09
//
// Desc			: Function to stop repetition in other code. 
//				  Copies all of the data in AVP_Profile that needs to be saved into the data structure that is saved. 
//				  This can be done like this because of the Friend relationship AVP_Prifile has with AVP_Profile_LoadAndSave
//				  all functions that talk to friend class AVP_Profile are private in AVP_Prifile_SaveAndLoad
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_CopyDataToLoadAndSaveFromProfile()
{
	// this copying if fine due to AVP_Profile_LoadAndSave's friend relationship with AVP_Profile. 
	s_xProfileSaveData.m_xControls = s_pxProfile->m_xControls;
	s_xProfileSaveData.m_xGraphics = s_pxProfile->m_xGraphics;
	s_xProfileSaveData.m_xSounds = s_pxProfile->m_xSounds;
}

////////////////////////////////////////////////////////////////////////////////
// Function     : AVP_Profile_LoadAndSave::Platform_CopyDataToProfileFromLoadAndSave
// Scope		: Static Private
// Author       : Callum Hope
// Date         : 16/1/09
//
// Desc			: Function to stop repetition in other code. 
//				  Copies all of the data that has been loaded from file back to the AVP_Profile class where it can be used by the rest of the code. 
//				  This can be done like this because of the Friend relationship AVP_Prifile has with AVP_Profile_LoadAndSave
//				  all functions that talk to friend class AVP_Profile are private in AVP_Prifile_SaveAndLoad
////////////////////////////////////////////////////////////////////////////////

void AVP_Profile_LoadAndSave::Platform_CopyDataToProfileFromLoadAndSave()
{
	// this copying if fine due to AVP_Profile_LoadAndSave's friend relationship with AVP_Profile. 
	s_pxProfile->m_xControls = s_xProfileSaveData.m_xControls;
	s_pxProfile->m_xGraphics = s_xProfileSaveData.m_xGraphics;
	s_pxProfile->m_xSounds = s_xProfileSaveData.m_xSounds;
}

#endif	//defined(AVP_SUPPORT_PROFILE_LOADANDSAVE)


/// End of file. ///
