//
// Asura_Chunk_ResourceFile_PC.cpp
//
// Created by KJL - 11/04/2003 15:17:04
//
// Copyright (C) 2003 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"

// This file's header.
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC.h"

#include "Debugging/Asura_Assert.h"
#include "ChunkSystem/Asura_Chunk_ResourceFile.h"
#include "ChunkSystem/Asura_Chunk_Stream.h"
#include "Core/Asura_Handle.h"
#include "FileAccess/Asura_FileAccess.h"

#include "ChunkSystem/Asura_Chunk_ResourceFile_PC.h"
#if defined( ASURA_USE_BOTANICALS)
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Botanical.h"
#endif
#if defined( ASURA_USE_CARPET)
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Carpet.h"
#endif
#if defined(ASURA_PC_USE_SHADER_MODEL_3_SMOOTH_SKIN_RENDERER) && ASURA_PC_USE_SHADER_MODEL_3_SMOOTH_SKIN_RENDERER
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_SmoothSkin.h"
#endif
#if !defined(ASURA_PC_DISABLE_PRESM3_SMOOTH_SKIN_RENDERER) || (!ASURA_PC_DISABLE_PRESM3_SMOOTH_SKIN_RENDERER)
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Character.h"
#endif
#if defined(ASURA_TARGET_SM3)
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Environment_SM3.h"
#endif
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Environment.h"
#if defined ASURA_USE_MATERIAL_RESPONSE_SYSTEM
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_MaterialResponse.h"
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_MRPShaders.h"
#endif
#if defined( ASURA_USE_STATIC_DECAL_SYSTEM)
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_StaticDecals.h"
#endif
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Object.h"
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_ObjectHierarchy.h"
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_ReplaceableSounds.h"
#include "ChunkSystem/Asura_Chunk_ResourceFile_PC_Skin.h"
#include "Sound/Asura_PC_ReplaceableSounds.h"

// C L A S S   I M P L E M E N T A T I O N S /////////////////////////////////

bool Asura_Chunk_ResourceFile::Platform_Process( Asura_Handle __hFile, const char* szOriginalFileName )
{
	Asura_Chunk_File_Stream	xStream (__hFile);
	// (MP - 16.09.2002) Note that I've omitted the semi-colon at the end of
	// this macro; this stops Lint complaining.
	#define PROCESS( type, class_for_type ) \
		case type: \
		return reinterpret_cast<class_for_type*>(this)->Process( __hFile )
	#define PROCESS_STREAM( type, class_for_type ) \
		case type: \
		return reinterpret_cast<class_for_type*>(this)->Process( szOriginalFileName, xStream )

	switch( this->SubType )
	{
		// Process known subtypes.
#if defined(ASURA_TARGET_SM3)
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_ENVIRONMENT_SM3, Asura_Chunk_ResourceFile_PC_Environment_SM3);
#endif
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_ENVIRONMENT, Asura_Chunk_ResourceFile_PC_Environment);
#if defined(ASURA_PC_USE_SHADER_MODEL_3_SMOOTH_SKIN_RENDERER) && ASURA_PC_USE_SHADER_MODEL_3_SMOOTH_SKIN_RENDERER
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_SMOOTHSKIN, Asura_Chunk_ResourceFile_PC_SmoothSkin);
#endif
#if !defined(ASURA_PC_DISABLE_PRESM3_SMOOTH_SKIN_RENDERER) || (!ASURA_PC_DISABLE_PRESM3_SMOOTH_SKIN_RENDERER)
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_CHARACTER, Asura_Chunk_ResourceFile_PC_Character);
#endif
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_OBJECT, Asura_Chunk_ResourceFile_PC_Object);
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_OBJECTHIERARCHY, Asura_Chunk_ResourceFile_PC_ObjectHierarchy);
#if defined(ASURA_TARGET_SM3)
		PROCESS_STREAM( ASURA_RESOURCEFILE_TYPE_PC_SKIN, Asura_Chunk_ResourceFile_PC_Skin);
#endif
#if !defined(ASURA_USE_AUDIO_SYSTEM)
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_REPLACEABLESOUNDSINFO, Asura_Chunk_ResourceFile_PC_ReplaceableSoundsInfo);
#endif
#if defined( ASURA_USE_CARPET)
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_CARPET, Asura_Chunk_ResourceFile_PC_Carpet);
#endif
#if defined( ASURA_USE_BOTANICALS)
		PROCESS( ASURA_RESOURCEFILE_TYPE_PC_BOTANICAL, Asura_Chunk_ResourceFile_PC_Botanical);
#endif
#if defined ASURA_USE_MATERIAL_RESPONSE_SYSTEM
		PROCESS_STREAM( ASURA_RESOURCEFILE_TYPE_PC_MATERIALRESPONSE, Asura_Chunk_ResourceFile_PC_MaterialResponse);
		PROCESS_STREAM( ASURA_RESOURCEFILE_TYPE_PC_MRPSHADERS, Asura_Chunk_ResourceFile_PC_MRPShaders);
#endif
#if defined( ASURA_USE_STATIC_DECAL_SYSTEM)
		PROCESS_STREAM( ASURA_RESOURCEFILE_TYPE_PC_STATICDECALS_SM3, Asura_Chunk_ResourceFile_PC_StaticDecals);
#endif
		case ASURA_RESOURCEFILE_TYPE_PC_D3DEFFECT_DEPRECATED:
		{
			Asura_Assert(0, "D3D effect chunks are no longer supported");
			Asura_FileAccess::SkipData( __hFile, this->FileSize );
			return false;
		}
		case ASURA_RESOURCEFILE_TYPE_PC_REPLACEABLESOUNDDATA:
		{
			#if defined( ASURA_TOOLS) && !defined( ASURA_USE_AUDIO_SYSTEM)
			//take note of the filename
			Asura_PC_ReplaceableSounds::AddReplaceableSoundName(Asura_FileAccess::GetFilePosition(__hFile),szOriginalFileName);
			#endif
			
			// this data isn't used directly, just skip it.
			Asura_FileAccess::SkipData( __hFile, this->FileSize );
			return false;
		}
			
		
		default:
		{
            Asura_Assert( false, "Unrecognised resource file subtype." );
			
			// skip the data to keep things happy
			Asura_FileAccess::SkipData( __hFile, this->FileSize );
			return false;
		}
    }
}


