//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS2_Input.h
//
// Created by Neil Massey.
//
// Copyright (c) 2002 Rebellion. All rights reserved.
//
// Implementation of an input manager class
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ___ASURA_PS2_INPUT_H___
#define ___ASURA_PS2_INPUT_H___ 1

// I N C L U D E S ///////////////////////////////////////////////////////////

// Project platform-specific.
#include "ProjectSettings/Asura_PS2_ProjectControllerDefines.h"

// F O R W A R D   D E C L A R A T I O N S
class Asura_PS2_ControlPortDevice;
class Asura_PS2_USBMouse;
class Asura_PS2_USBKeyboard;
class Asura_PS2_USBGuncon2;

const int ASURA_PS2_MAX_MULTITAPS   = 1;
const int ASURA_PS2_MAX_CONTROLLERS = 2 + (3 * ASURA_PS2_MAX_MULTITAPS);
const int ASURA_PS2_MAX_GUNCON2S    = 2;

#if ASURA_PS2_SUPPORT_KEYBOARD
const int ASURA_PS2_MAX_KEYBOARDS   = 1;
#else
const int ASURA_PS2_MAX_KEYBOARDS   = 0;
#endif //ASURA_PS2_SUPPORT_KEYBOARD

#if ASURA_PS2_SUPPORT_MOUSE
const int ASURA_PS2_MAX_MICE        = 1;
#else
const int ASURA_PS2_MAX_MICE        = 0;
#endif //ASURA_PS2_SUPPORT_MOUSE


enum
{
    ASURA_PS2_CONTROL_PORT_1    = 0,
    ASURA_PS2_CONTROL_PORT_1_A  = 0,
    ASURA_PS2_CONTROL_PORT_1_B  = 1,
    ASURA_PS2_CONTROL_PORT_1_C  = 2,
    ASURA_PS2_CONTROL_PORT_1_D  = 3,

    ASURA_PS2_CONTROL_PORT_2    = 4,
    ASURA_PS2_CONTROL_PORT_2_A  = 4,
    ASURA_PS2_CONTROL_PORT_2_B  = 5,
    ASURA_PS2_CONTROL_PORT_2_C  = 6,
    ASURA_PS2_CONTROL_PORT_2_D  = 7,
};

class Asura_PS2_Input
{
public:
	// Called from Asura_PlatformInput::Update()
	static void Update(void);
	static void PreInitialise(void);
	static void Initialise(u_char *pucAsuraCurrentInput, float *pfAsuraAxis);
	static void Shutdown(void);
	static void SetPressureSensitivity(bool bEnable);	// default is false
	static Asura_PS2_ControlPortDevice* GetControlPortDevice(int iControlPortNumber);

    // (NRM - 20.05.2003) InOrder means that it will return the number of consecutive controllers
    static int  GetNumberOfActiveControllers(bool bInOrder = false);
    static bool IsControllerActive(int iControllerNum);
	static int GetPlayerNumber(int iControllerNum);

    static bool IsKeyToggled(int iKey);

#if ASURA_PS2_SUPPORT_MOUSE
	static Asura_PS2_USBMouse*			GetUSBMouse(void) {return s_pxUSBMouse;}
    static bool MouseAvailable(void);
#endif

#if ASURA_PS2_SUPPORT_KEYBOARD
    static Asura_PS2_USBKeyboard*       GetUSBKeyboard(void) {return s_pxUSBKeyboard;}
    static bool KeyboardAvailable(void);
#endif

#if ASURA_PS2_SUPPORT_GUNCON2
    static void UpdateGuncon2(int iDeviceNumber);
    static void TranslateGuncon2(int iDeviceNumber);
    static Asura_PS2_USBGuncon2*        GetUSBGuncon2(int iDeviceNumber);
    static bool Guncon2Available(int iDeviceNumber);
#endif

#if ASURA_PS2_SUPPORT_MULTITAP
	static void CheckForMultitap(int iPort);
    static bool MultitapAvailable(int iPort);
#else
	static bool MultitapAvailable(int iPort) {return false;}
#endif

private:
	static void UpdateControlPortDevices(void);
	static void UpdateUSBDevices(void);

	// Arrays of pointers to instances of the controller classes
	static Asura_PS2_ControlPortDevice* s_apxControlPortDevices[ASURA_PS2_MAX_CONTROLLERS];

#if ASURA_PS2_SUPPORT_MOUSE
    static Asura_PS2_USBMouse*         s_pxUSBMouse;
#endif

#if ASURA_PS2_SUPPORT_KEYBOARD
    static Asura_PS2_USBKeyboard*      s_pxUSBKeyboard;
#endif

#if ASURA_PS2_SUPPORT_GUNCON2
    static Asura_PS2_USBGuncon2*       s_pxGuncon2[ASURA_PS2_MAX_GUNCON2S];
#endif

#if ASURA_PS2_SUPPORT_MULTITAP
	static bool s_abMultitap[ASURA_PS2_MAX_MULTITAPS];
#endif

	// Pointer to the Asura_Axis buffer
	static float   *s_pfAsuraAxis;
	static u_char  *s_pucAsuraCurrentInput;

	// flag for pressure sensitivity
	static bool		s_bPressureEnabled;
};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ___ASURA_PS2_INPUT_H___
