//
// Asura_Chunk_RagdollDescription.cpp
//
// Created by Paul Humphries - 19/6/2007
// 
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
#include "Core/Asura.h"

#ifndef ASURA_PHYSICS_DISABLE_RAGDOLL

#include "ChunkSystem/Asura_Chunk_RagdollDescription.h"

#include "ChunkSystem/Asura_Chunk_Stream.h"
#include "ChunkSystem/Asura_SaveBlock.h"
#include "Physics/Asura_Physics_Ragdoll.h"
#include "Physics/Asura_Physics_Ragdoll_Description.h"

#ifdef ASURA_TOOLS

void Asura_Chunk_RagdollDescription::Create(Asura_Chunk_Stream& xStream, Asura_Physics_Ragdoll_Description& xRagdollDescription)
{
	u_int uChunkFlags = 0;

	xStream.WriteChunk_Start( ASURA_CHUNK_RAGDOLLDESCRIPTION, Asura_Physics_Ragdoll_Description::CURRENT_CHUNK_VERSION, uChunkFlags );
	xStream << xRagdollDescription.GetName();
	xRagdollDescription.WriteToChunkStream(xStream);
	xStream.WriteChunk_End();
}
#endif

bool Asura_Chunk_RagdollDescription::Process(Asura_Chunk_Stream& xStream) const
{
	if (Version > Asura_Physics_Ragdoll_Description::CURRENT_CHUNK_VERSION )
	{
		Asura_Assertf(false, ("Unknown chunk version %d for Asura_Chunk_RagdollDescription", Version));
		return false;
	}

	Asura_String xName;
	xStream >> xName;

	Asura_Physics_Ragdoll_Description* const pxRagdollDescription = Asura_Physics_Ragdoll_System::CreateNewRagdollDescription(xName);
	pxRagdollDescription->ReadFromChunkStream( xStream, Version );

	return true;
}

bool Asura_Chunk_RagdollDescription::Process(int iHandle) const
{
	Asura_Chunk_File_Stream	xStream(iHandle);
	return Process(xStream);
}

#endif // #ifndef ASURA_PHYSICS_DISABLE_RAGDOLL
