//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_Rumble.cpp
//
// Created by AAM - 19/01/2004 11:00:12
//
// Copyright (c) 2004 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

/******************************************************************************/
/* Included Files                                                             */
/******************************************************************************/

#include "Core/Asura.h"

#include "Input/Asura_Platform_Rumble.h"

#if (defined ASURA_SUPPORT_CONTROLLER_RUMBLE) && (ASURA_SUPPORT_CONTROLLER_RUMBLE != 0)

#ifdef ASURA_PC_SUPPORT_XINPUT
#include "Input/Asura_Platform_Rumble_XInput.h"
#endif

#include "Input/Asura_Platform_Rumble_DirectInput.h"

#include "Input/Asura_PlatformInput.h"
#include "Input/Asura_Rumble_System.h"

/******************************************************************************/
/* Static Class Data                                                          */
/******************************************************************************/

Asura_Platform_Rumble* Asura_Rumble_System::ASURA_STANDARD_RUMBLE_EXPLOSION;
Asura_Platform_Rumble* Asura_Rumble_System::ASURA_STANDARD_RUMBLE_SINGLESHOT;
Asura_Platform_Rumble* Asura_Rumble_System::ASURA_STANDARD_RUMBLE_HEARTBEAT;
Asura_Platform_Rumble* Asura_Rumble_System::ASURA_STANDARD_RUMBLE_HIT;

/******************************************************************************/
/* Global Variables                                                           */
/******************************************************************************/

/******************************************************************************/
/* Class Functions                                                            */
/******************************************************************************/

void Asura_Rumble_System::Platform_Initialise()
{
	// set up the standard Asura rumbles

	// Shot
	Asura_Handle iSingleShotSlowMotor = Asura_Rumble::CreateAsuraRumble(RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 1.0f, 0.0f, 2.5f, 1);
	Asura_Handle iSingleShotRumble = s_pxDynamicPlatformRumbleList->Allocate();
	ASURA_STANDARD_RUMBLE_SINGLESHOT = s_pxDynamicPlatformRumbleList->GetPointer(iSingleShotRumble);
	ASURA_STANDARD_RUMBLE_SINGLESHOT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR1] = NULL;
	ASURA_STANDARD_RUMBLE_SINGLESHOT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR2] = Asura_Rumble::GetRumblePointer(iSingleShotSlowMotor);

	ASURA_STANDARD_RUMBLE_HIT = ASURA_STANDARD_RUMBLE_SINGLESHOT;
	ASURA_STANDARD_RUMBLE_EXPLOSION = ASURA_STANDARD_RUMBLE_SINGLESHOT;
	ASURA_STANDARD_RUMBLE_HEARTBEAT = ASURA_STANDARD_RUMBLE_SINGLESHOT;

	// Hit	
	Asura_Handle iHitSlowMotor = Asura_Rumble::CreateAsuraRumble(RUMBLE_BASE_LINEAR, RUMBLE_ADJUST_REVERSE, 0.75f, 0.0f, 1.0f, 1);
	Asura_Handle iHitRumble = s_pxDynamicPlatformRumbleList->Allocate();
	ASURA_STANDARD_RUMBLE_HIT = s_pxDynamicPlatformRumbleList->GetPointer(iHitRumble);
	ASURA_STANDARD_RUMBLE_HIT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR1] = NULL;
	ASURA_STANDARD_RUMBLE_HIT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR2] = Asura_Rumble::GetRumblePointer(iHitSlowMotor);

	// Explosion
	Asura_Handle iExplosionFastMotor = Asura_Rumble::CreateAsuraRumble(RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 1.0f, 0.0f, 2.5f, 1);
	Asura_Rumble::AddRumbleStep(iExplosionFastMotor, RUMBLE_BASE_LINEAR, RUMBLE_ADJUST_REVERSE, 1.0f, 0.0f, 1.0f, 1);
	Asura_Handle iExplosionSlowMotor = Asura_Rumble::CreateAsuraRumble(RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 1.0f, 0.0f, 2.5f, 1);
	Asura_Rumble::AddRumbleStep(iExplosionSlowMotor, RUMBLE_BASE_LINEAR, RUMBLE_ADJUST_REVERSE, 1.0f, 0.0f, 0.5f, 1);
	Asura_Handle iExplosionRumble = s_pxDynamicPlatformRumbleList->Allocate();
	ASURA_STANDARD_RUMBLE_EXPLOSION = s_pxDynamicPlatformRumbleList->GetPointer(iExplosionRumble);
	ASURA_STANDARD_RUMBLE_EXPLOSION->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR1] = Asura_Rumble::GetRumblePointer(iExplosionFastMotor);
	ASURA_STANDARD_RUMBLE_EXPLOSION->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR2] = Asura_Rumble::GetRumblePointer(iExplosionSlowMotor);

	// Heartbeat
	Asura_Handle iHeartbeatSlowMotor = Asura_Rumble::CreateAsuraRumble(RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 0.0f, 0.0f, 5.0f, 1);
	Asura_Rumble::AddRumbleStep(iHeartbeatSlowMotor, RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 0.3f, 0.0f, 2.0f, 1);
	Asura_Rumble::AddRumbleStep(iHeartbeatSlowMotor, RUMBLE_BASE_CONSTANT, RUMBLE_ADJUST_NONE, 0.0f, 0.0f, 1.0f, 1);
	Asura_Handle iHeartbeatRumble = s_pxDynamicPlatformRumbleList->Allocate();
	ASURA_STANDARD_RUMBLE_HEARTBEAT = s_pxDynamicPlatformRumbleList->GetPointer(iHeartbeatRumble);
	ASURA_STANDARD_RUMBLE_HEARTBEAT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR1] = NULL;
	ASURA_STANDARD_RUMBLE_HEARTBEAT->m_apxMotorRumbles[ASURA_PC_RUMBLE_MOTOR2] = Asura_Rumble::GetRumblePointer(iHeartbeatSlowMotor);

	// Need to init both interfaces here
	#ifdef ASURA_PC_SUPPORT_XINPUT
	Asura_Rumble_XInput::Platform_Initialise();
	#endif
	Asura_Rumble_DirectInput::Platform_Initialise();
}

void Asura_Rumble_System::Platform_Shutdown()
{
	#ifdef ASURA_PC_SUPPORT_XINPUT
	Asura_Rumble_XInput::Platform_Shutdown();
	#endif
	Asura_Rumble_DirectInput::Platform_Shutdown();
}

void Asura_Rumble_System::Platform_Reset()
{
	Platform_Shutdown();
	Platform_Initialise();
}

void Asura_Rumble_System::Platform_PlayCurrentRumbles()
{
	// Update both interfaces - each is internally checked to make sure they're the right type of device
	#ifdef ASURA_PC_SUPPORT_XINPUT
	Asura_Rumble_XInput::Platform_PlayCurrentRumbles();
	#endif
	Asura_Rumble_DirectInput::Platform_PlayCurrentRumbles();
}

////////////////////////////////////////////////////////////////////////////////
//
// Asura_Rumble_System::Platform_StopAllRumbles()
//
// PC implementation. Stops all rumbling
//
// Parameters:		None
// Return value:	None
//
////////////////////////////////////////////////////////////////////////////////

void Asura_Rumble_System::Platform_StopAllRumbles()
{
	#ifdef ASURA_PC_SUPPORT_XINPUT
	Asura_Rumble_XInput::Platform_StopAllRumbles();
	#endif
	Asura_Rumble_DirectInput::Platform_StopAllRumbles();
}

#endif // (defined ASURA_SUPPORT_CONTROLLER_RUMBLE) && (ASURA_SUPPORT_CONTROLLER_RUMBLE != 0)
