#ifndef _RUCONTROLLER_HIERARCHY_H_
#define _RUCONTROLLER_HIERARCHY_H_

#include "../../Scene/Base/RuEntityBase.h"
#include "../../Scene/Base/RuEntityContainer.h"

#pragma unmanaged

// ************************************************************************************************************************************************************

/*!
	@author John Tang
	@version 2004/12/10
*/
class CRuController_Hierarchy : public IRuEntity_Controller
{
	ruRTTI_DECLARE
	ruHEAP_DECLARE
	ruCLASSGUID_DECLARE

protected:
	CRuEntity*								m_targetEntity;									//!< Target entity that owns the target interpolator
	CRuAnimationInterpolator*				m_targetInterpolator;							//!< Interpolator that the controller operates on

	BOOL									m_applied;										//!< Has the animation been applied to the target interpolator?
	CRuAnimation*							m_animation;									//!< Instanced animation data

	// Controller settings
	BOOL									m_embedAnimation;								//!< Embed animation during serialization?
	char*									m_animationName;								//!< Animation name
	REAL									m_blendInTime;									//!< Blend-in time
	REAL									m_blendOutTime;									//!< Blend-out time

public:
											CRuController_Hierarchy();
	virtual									~CRuController_Hierarchy();

	// Base class implementation
	virtual IRuObject*						Clone(IRuObject *clonedObject = NULL);
	virtual BOOL							SerializeFrom(IRuStream *stream);
	virtual BOOL							SerializeTo(IRuStream *stream);

	virtual BOOL							Update(REAL elapsedTime);

	virtual REAL							GetDuration();									//!< Override GetDuration to provide on-demand animation loading

	virtual IRuObject*						GetTarget();
	virtual BOOL							SetTarget(IRuObject *target);

	const char*								GetAnimationName();
	REAL									GetBlendInTime();
	REAL									GetBlendOutTime();

	void									SetAnimation(const char *animationName);
	void									SetAnimation(CRuAnimation *animation);
	void									SetBlendInTime(REAL blendInTime);
	void									SetBlendOutTime(REAL blendOutTime);

	// IRuEntityEventListener implementation
	virtual BOOL							HandleEvent(CRuEntity *entity, INT32 eventID, INT32 eventParameter0, INT32 eventParameter1, const char *eventString, REAL eventDuration, void *userData);

protected:
	BOOL									InstanceAnimation();
};

// ************************************************************************************************************************************************************

ruOBJECTMODULE_DEFINE(CRuObjectModule_Controller_Hierarchy, CRuController_Hierarchy)

// ************************************************************************************************************************************************************

#pragma managed

#endif
