
///////////////////////////////////////////////////////////////////////////////
//
// File   : Tools_FacialAnimation_FaceType.h
// Author : Andy Tate
// Date   : 13-Jun-2008
//
// Copyright (C) 2008 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif   // ifdef ASURA_USE_PRAGMA_ONCE

#ifndef __TOOLS_FACIALANIMATION_FACETYPE_H__
#define __TOOLS_FACIALANIMATION_FACETYPE_H__

#if defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)

////////////////////////////////////////////////////////////////////////////////
// Include files...
////////////////////////////////////////////////////////////////////////////////

#include "Core/Asura_HashTree.h"
#include "Core/Asura_List.h"

#include "FacialAnimation/Tools_FacialAnimation_FaceType_MuscleGroup.h"


////////////////////////////////////////////////////////////////////////////////
// Forward class declarations...
////////////////////////////////////////////////////////////////////////////////

class Asura_Chunk_Stream;
class Tools_FacialAnimation_FacePose;


////////////////////////////////////////////////////////////////////////////////
// Class declaration...
////////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Class        : Tools_FacialAnimation_FaceType
// Author       : Andy Tate
// Date         : 13-Jun-2008
//
// Description  : Class used to store the face-type data for Tools.
////////////////////////////////////////////////////////////////////////////////

class Tools_FacialAnimation_FaceType
{
public:
	// Public typedefs...
	typedef Asura_List<Asura_String> PhonemeNameContainer;
	typedef Asura_List_It<Asura_String> PhonemeNameIterator;
	typedef Asura_List_ConstIt<Asura_String> PhonemeNameConstIterator;

	typedef Asura_List<Tools_FacialAnimation_FaceType_MuscleGroup> MuscleGroupContainer;
	typedef Asura_List_It<Tools_FacialAnimation_FaceType_MuscleGroup> MuscleGroupIterator;
	typedef Asura_List_ConstIt<Tools_FacialAnimation_FaceType_MuscleGroup> MuscleGroupConstIterator;

	typedef Asura_TemplateHashTree<Asura_String> PhonemeToFacePoseMappingContainer;
	typedef Asura_TemplateHashTree_Iterator<Asura_String> PhonemeToFacePoseMappingIterator;
	typedef Asura_TemplateHashTree_ConstIterator<Asura_String> PhonemeToFacePoseMappingConstIterator;

	// Public functions...
	Tools_FacialAnimation_FaceType(void);
	Tools_FacialAnimation_FaceType(const Asura_Hash_ID uHash, Asura_Chunk_Stream& xStream);
	~Tools_FacialAnimation_FaceType();

	// Chunk-stream functions...
	void	ReadFromChunkStream(Asura_Chunk_Stream& xStream);
	void	WriteToChunkStream(Asura_Chunk_Stream& xStream) const;

	// Muscle-group name functions...
	Tools_FacialAnimation_FaceType_MuscleGroup*	CreateMuscleGroup(const char* szName, const Asura_FacialAnimation_MuscleGroup::ControlType eControlType);
	bool										DestroyMuscleGroup(const char* szName);

	void	SwapMuscleGroups(const Tools_FacialAnimation_FaceType_MuscleGroup* pxMuscleGroup1, const Tools_FacialAnimation_FaceType_MuscleGroup* pxMuscleGroup2);

	Tools_FacialAnimation_FaceType_MuscleGroup*			FindMuscleGroup(const char* szName);
	const Tools_FacialAnimation_FaceType_MuscleGroup*	FindMuscleGroup(const char* szName) const;

	int	FindMuscleGroupIndex(const Asura_Hash_ID uHash) const;
	int	FindMuscleGroupIndex(const char* szName) const			{ return(FindMuscleGroupIndex(Asura_GetHashID(szName))); }
	int	FindMuscleGroupIndex(const Asura_String& xString) const	{ return(FindMuscleGroupIndex(xString.GetHash())); }

	// Phoneme name functions...
	Asura_String*	CreatePhonemeName(const char* szName);
	bool			DestroyPhonemeName(const char* szName);

	void	SwapPhonemeNames(const Asura_String* pxName1, const Asura_String* pxName2);

	Asura_String*		FindPhonemeName(const char* szName);
	const Asura_String*	FindPhonemeName(const char* szName) const;

	// Phoneme to face-pose mapping functions...
	Asura_String*	CreatePhonemeToFacePoseMapping(const char* szPhonemeName, const Tools_FacialAnimation_FacePose& xPose);
	bool			DestroyPhonemeToFacePoseMapping(const char* szPhonemeName);

	const Asura_String*	FindFacePoseNameForPhonemeName(const char* szPhonemeName) const				{ return(m_xMappingContainer.GetDataByName(szPhonemeName)); }
	const Asura_String*	FindFacePoseNameForPhonemeName(const Asura_Hash_ID uPhonemeNameHash) const	{ return(m_xMappingContainer.GetDataByHash(uPhonemeNameHash)); }

	// Accessor functions...
	void				SetName(const char* szName)			{ m_xName = szName; }
	void				SetName(const Asura_String& xName)	{ m_xName = xName; }
	const Asura_String&	GetName(void) const					{ return(m_xName); }

	u_int	GetNumMuscleGroups(void) const	{ return(m_xMuscleGroupContainer.GetNumEntries()); }

	MuscleGroupContainer&		GetMuscleGroupContainer(void)		{ return(m_xMuscleGroupContainer); }
	const MuscleGroupContainer&	GetMuscleGroupContainer(void) const	{ return(m_xMuscleGroupContainer); }

	u_int	GetNumPhonemeNames(void) const	{ return(m_xPhonemeNameContainer.GetNumEntries()); }

	PhonemeNameContainer&		GetPhonemeNameContainer(void)		{ return(m_xPhonemeNameContainer); }
	const PhonemeNameContainer&	GetPhonemeNameContainer(void) const	{ return(m_xPhonemeNameContainer); }


protected:
	// Protected variables...

	// Protected functions...


private:
	// Private variables...
	Asura_String						m_xName;					// The name of this face-type.
	PhonemeNameContainer				m_xPhonemeNameContainer;	// List of all of the possible phonemes for this face-type.
	MuscleGroupContainer				m_xMuscleGroupContainer;	// List of all of the possible muscle-groups for this face-type.
	PhonemeToFacePoseMappingContainer	m_xMappingContainer;		// Tree of mappings between phonemes and face-poses.

	static const u_int					s_uChunkVersion;			// Current version used for reading/writing data.

	// Private functions...
	Tools_FacialAnimation_FaceType(const Tools_FacialAnimation_FaceType& xOther);

	Tools_FacialAnimation_FaceType&	operator=(const Tools_FacialAnimation_FaceType& xOther);

};   // End of class 'Tools_FacialAnimation_FaceType'.

#endif	//defined(ASURA_USE_FACIAL_ANIMATION_SYSTEM)

#endif   // ifndef __TOOLS_FACIALANIMATION_FACETYPE_H__


/// End of file. ///
