//////////////////////////////////////////////////////////////////////////////
//
// Asura_LoadAndSave.h
//
// Load and save functionality for Asura engine (project independent & platform independent).
//
// Copyright (C) 2007 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __ASURA_LOADANDSAVE_H__
#define __ASURA_LOADANDSAVE_H__ 1

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class Asura_Chunk_Header;
class Asura_Chunk_Stream;
class Asura_SaveBlock_Base;
class Asura_CompressedSaveBlock;

// C L A S S E S /////////////////////////////////////////////////////////////

class Asura_LoadAndSave 
{
public:
	static bool SaveToBuffer( Asura_SaveBlock_Base& xSaveBlock );
	static bool LoadFromBuffer( const Asura_SaveBlock_Base& xSaveBlock, bool bResetBeforeLoad=true );
    static bool IsLoadingFromBuffer() { return s_bLoadingFromBuffer; }
    static bool LoadFromDisk(const char* szFileName);

#if defined(_DEBUG) && defined(ASURA_SAVEBLOCK_USE_ZLIB)
	static void RunCompressedSaveBlockTests(Asura_CompressedSaveBlock& xSaveBlock);
#endif

	// Returns true if the header is valid.
	static bool ProcessAsuraFileHeader(Asura_Chunk_Stream& xStream);
	// Returns true if not the final chunk
	static bool ProcessChunk(Asura_Chunk_Stream& xStream);

#ifdef ASURA_USE_STREAMING
	// Special versions for streaming games, only saving the mission data
	static bool SaveMissionToBuffer( Asura_SaveBlock_Base& xSaveBlock );
	static bool LoadMissionFromBuffer( const Asura_SaveBlock_Base& xSaveBlock, bool bResetBeforeLoad=true );
#endif

	// AJG - 04/12/07 - Publicised this method - could be used for resetting the appropriate systems on a client machine that then
	//					just waits for the server to tell it about the loaded entities, rather than loading something itself.
    static void ResetBeforeLoad( void );

private:
	static bool Project_AddHeader( Asura_SaveBlock_Base& xSaveBlock );
	
	static bool Project_SaveToBuffer( Asura_SaveBlock_Base& xSaveBlock );
	static bool Project_LoadFromBuffer( Asura_Chunk_Header* pxChunkHeader, Asura_Chunk_Stream& xStream );

    static void Project_ResetBeforeLoad( void );

#ifdef ASURA_USE_STREAMING
	static bool Project_SaveMissionToBuffer( Asura_SaveBlock_Base& xSaveBlock );
	static bool Project_LoadMissionFromBuffer( const Asura_Chunk_Header* pxChunk, Asura_Chunk_Stream& xStream );

	static void ResetMissionBeforeLoad( void );
    static void Project_ResetMissionBeforeLoad( void );
#endif

    static bool s_bLoadingFromBuffer;
};

//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

#endif
