/** SGX

The   sss    gggg x   x   
     s      g      x x    Engine
      sss   g  gg   x
         s  g   g  x x          Copyright 1995-2009.
     ssss    gggg x   x         Steven Goodwin. All Rights Reserved.
    
This version has been released under the GNU Public License v2.0.

Please see the license files for details.

File: sgx/include/sgx/input/rumble_device.hpp

*/

#ifndef SGX_INPUT_RUMBLE_DEVICE_HPP
#define SGX_INPUT_RUMBLE_DEVICE_HPP	1

#define MAX_RUMBLES		8

class CSGXRumbleState {
public:
	CSGXRumbleState();
	
	void 		update(const tREAL32 telaps);
	tBOOL 		isOn() const;
	tREAL32 	getIntensity(const sgxVector3 &fromPosition) const;
	void 		stop();
	
	const CSGXRumbleProfile *	m_pProfile;
	tREAL32						m_fStrength;

	tBOOL						m_bDurationValid;
	tREAL32						m_fDuration;
	tREAL32						m_fTimecum;

	tBOOL						m_bPositionValid;
	sgxVector3					m_vPosition;
};


class CSGXRumbleDevice {
public:
	CSGXRumbleDevice();

	virtual void 		setRumbleIntensity(const tREAL32 intensity);
	
	virtual void 		mute();
	virtual void 		unmute();
	virtual void 		enable(const tBOOL enable=TRUE);
	virtual tBOOL 		isMute() const;

	virtual void 		suspend(const tBOOL suspend);

	virtual void 		update(const tREAL32 telaps);
	virtual void 		setFromPosition(const sgxVector3 &vPosition);
	virtual void 		getFromPosition(sgxVector3 &vPosition)const ;

	virtual tREAL32		getCurrentIntensity() const;

	// Do rumble for a specifically specified time
	virtual tUINT32 	playRumble(const CSGXRumbleProfile *pProfile, const tREAL32 fStrength = 1.0f, const tREAL32 fDuration = 1.0f);
	virtual tUINT32 	playRumble(const CSGXRumbleProfile *pProfile, const sgxVector3 &vPosition, const tREAL32 fStrength = 1.0f, const tREAL32 fDuration = 1.0f);

	// play the rumble profile until an explicit stop is called
	virtual tUINT32 	startRumble(const CSGXRumbleProfile *pProfile, const tREAL32 fStrength = 1.0f);
	virtual tUINT32 	startRumble(const CSGXRumbleProfile *pProfile, const sgxVector3 &vPosition, const tREAL32 fStrength = 1.0f);

	virtual void 		stopRumble(const tUINT32 handle);
	virtual void 		stopAllRumbles();

protected:
	tBOOL 				m_bMute;
	tBOOL 				m_bSuspend;
	sgxVector3 	   		m_vFromPosition;
	tREAL32		   		m_fCurrentIntensity;
	CSGXRumbleState 	m_RumbleStateList[MAX_RUMBLES];

	virtual tUINT32 	getNewRumbleHandle();
};

#endif // SGX_INPUT_RUMBLE_DEVICE_HPP

