//
// Asura_Platform_Chunk_ResourceFile.cpp
//
// Created by KOR - 09 October 2006
//
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#include "Core/Asura.h"

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

// Asura headers
#include "FileAccess/Asura_FileAccess.h"

// Platform headers
#include "ChunkSystem/Asura_Chunk_ResourceFile_Wii_StreamedSounds.h"
#include "ChunkSystem/Asura_Platform_Chunk_ResourceFile.h"
#include "Rendering/Asura_GX_Environment.h"
#include "Rendering/Asura_GX_Hierarchy.h"
#include "Rendering/Asura_GX_Shape.h"
#include "Rendering/Asura_GX_SmoothSkin.h"
#include "Rendering/Asura_GX_TextureManagement.h"

bool Asura_Chunk_ResourceFile::Platform_Process( Asura_Handle hFile, const char* szOriginalFileName )
{
	bool bSuccess;
    #define PROCESS( type, class_for_type ) \
        case type: \
            bSuccess = reinterpret_cast<class_for_type*>(this)->Process( hFile ); \
            break

    switch( this->SubType )
    {
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_STRIPPEDENV, Asura_Chunk_ResourceFile_Wii_StrippedEnv);
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_SHAPE, Asura_Chunk_ResourceFile_Wii_Shape);
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_HIERARCHY, Asura_Chunk_ResourceFile_Wii_Hierarchy);
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_SMOOTHSKIN, Asura_Chunk_ResourceFile_Wii_SmoothSkin);
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_ALPHAMAPS, Asura_Chunk_ResourceFile_Wii_AlphaMaps);
		PROCESS(ASURA_RESOURCEFILE_TYPE_WII_STREAMINGSOUNDS, Asura_Chunk_ResourceFile_Wii_StreamedSounds);
        default:
			bSuccess = false;
            Asura_Assert( false, "Unrecognised resource file subtype." );
		    Asura_FileAccess::SkipData( hFile, this->FileSize );
    }
	return bSuccess;
}

bool Asura_Chunk_ResourceFile_Wii_StrippedEnv::Process(Asura_Handle fileHandle)
{
	return Asura_GX_Environment::Initialise(fileHandle);
}

bool Asura_Chunk_ResourceFile_Wii_Shape::Process(Asura_Handle fileHandle)
{
	return Asura_GX_ShapeRenderer::AddShape(fileHandle);
}

bool Asura_Chunk_ResourceFile_Wii_Hierarchy::Process(Asura_Handle fileHandle)
{
	Asura_Assert(0 <= Version && Version <= ASURA_WII_HIERARCHY_CHUNK_VERSION, "Unrecognised hierarchy version");
	return Asura_GX_HierarchyRenderer::AddHierarchy(fileHandle, Version);
}

bool Asura_Chunk_ResourceFile_Wii_SmoothSkin::Process(Asura_Handle fileHandle)
{
	Asura_Assert(0 <= Version && Version <= ASURA_WII_SMOOTHSKIN_CHUNK_VERSION, "Unrecognised smooth skin version");
	return Asura_GX_SmoothSkinRenderer::AddSmoothSkin(fileHandle, Version, Flags);
}

bool Asura_Chunk_ResourceFile_Wii_AlphaMaps::Process(Asura_Handle fileHandle)
{
	return Asura_GX_Texture_Management::InitialiseAlphaMapping(fileHandle);
}
