uid issue

This commit is contained in:
KittenPopo
2021-07-24 21:11:47 -07:00
commit c2130ba4e9
13850 changed files with 6241419 additions and 0 deletions

View File

@ -0,0 +1,3 @@
LIBRARY inputsystem_360.dll
EXPORTS
CreateInterface @1

View File

@ -0,0 +1,58 @@
// ----------------------------------------- //
// File generated by VPC //
// ----------------------------------------- //
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_dll_check.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_dll_check.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\debug_dll_check.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputstacksystem.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputstacksystem.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputstacksystem.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputsystem.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputsystem.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\inputsystem.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\joystick.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\joystick.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\joystick.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\key_translation.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\key_translation.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\key_translation.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\tier0\memoverride.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\tier0\memoverride.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\public\tier0\memoverride.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\platforminputdevice.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\platforminputdevice.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\common\platforminputdevice.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\steamcontroller.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\steamcontroller.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\steamcontroller.cpp
Containing unity file:
PCH file:
Source file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\xcontroller.cpp
Debug output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\xcontroller.cpp
Release output file: D:\Users\berta\Downloads\csgosourcecode\cstrike15_src\inputsystem\xcontroller.cpp
Containing unity file:
PCH file:

View File

@ -0,0 +1,287 @@
//===== Copyright <20> 1996-2010, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "inputsystem/iinputstacksystem.h"
#include "tier2/tier2.h"
#include "tier1/utlstack.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// An input context
//-----------------------------------------------------------------------------
struct InputContext_t
{
InputCursorHandle_t m_hCursorIcon;
bool m_bEnabled;
bool m_bCursorVisible;
bool m_bMouseCaptureEnabled;
};
//-----------------------------------------------------------------------------
// Stack system implementation
//-----------------------------------------------------------------------------
class CInputStackSystem : public CTier2AppSystem< IInputStackSystem >
{
typedef CTier2AppSystem< IInputStackSystem > BaseClass;
// Methods of IAppSystem
public:
virtual const AppSystemInfo_t* GetDependencies();
virtual void Shutdown();
// Methods of IInputStackSystem
public:
virtual InputContextHandle_t PushInputContext();
virtual void PopInputContext( );
virtual void EnableInputContext( InputContextHandle_t hContext, bool bEnable );
virtual void SetCursorVisible( InputContextHandle_t hContext, bool bVisible );
virtual void SetCursorIcon( InputContextHandle_t hContext, InputCursorHandle_t hCursor );
virtual void SetMouseCapture( InputContextHandle_t hContext, bool bEnable );
virtual void SetCursorPosition( InputContextHandle_t hContext, int x, int y );
virtual bool IsTopmostEnabledContext( InputContextHandle_t hContext ) const;
private:
// Updates the cursor based on the current state of the input stack
void UpdateCursorState();
CUtlStack< InputContext_t * > m_ContextStack;
};
//-----------------------------------------------------------------------------
// Singleton instance
//-----------------------------------------------------------------------------
static CInputStackSystem s_InputStackSystem;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CInputStackSystem, IInputStackSystem,
INPUTSTACKSYSTEM_INTERFACE_VERSION, s_InputStackSystem );
//-----------------------------------------------------------------------------
// Get dependencies
//-----------------------------------------------------------------------------
static AppSystemInfo_t s_Dependencies[] =
{
{ "inputsystem" DLL_EXT_STRING, INPUTSYSTEM_INTERFACE_VERSION },
{ NULL, NULL }
};
const AppSystemInfo_t* CInputStackSystem::GetDependencies()
{
return s_Dependencies;
}
//-----------------------------------------------------------------------------
// Shutdown
//-----------------------------------------------------------------------------
void CInputStackSystem::Shutdown()
{
// Delete any leaked contexts
while( m_ContextStack.Count() )
{
InputContext_t *pContext = NULL;
m_ContextStack.Pop( pContext );
delete pContext;
}
BaseClass::Shutdown();
}
//-----------------------------------------------------------------------------
// Allocates an input context, pushing it on top of the input stack,
// thereby giving it top priority
//-----------------------------------------------------------------------------
InputContextHandle_t CInputStackSystem::PushInputContext()
{
InputContext_t *pContext = new InputContext_t;
pContext->m_bEnabled = true;
pContext->m_bCursorVisible = true;
pContext->m_bMouseCaptureEnabled = false;
pContext->m_hCursorIcon = g_pInputSystem->GetStandardCursor( INPUT_CURSOR_ARROW );
m_ContextStack.Push( pContext );
UpdateCursorState();
return (InputContextHandle_t)pContext;
}
//-----------------------------------------------------------------------------
// Pops the top input context off the input stack, and destroys it.
//-----------------------------------------------------------------------------
void CInputStackSystem::PopInputContext( )
{
if ( m_ContextStack.Count() == 0 )
return;
InputContext_t *pContext = NULL;
m_ContextStack.Pop( pContext );
delete pContext;
UpdateCursorState();
}
//-----------------------------------------------------------------------------
// Enables/disables an input context, allowing something lower on the
// stack to have control of input. Disabling an input context which
// owns mouse capture
//-----------------------------------------------------------------------------
void CInputStackSystem::EnableInputContext( InputContextHandle_t hContext, bool bEnable )
{
InputContext_t *pContext = ( InputContext_t* )hContext;
if ( !pContext )
return;
if ( pContext->m_bEnabled == bEnable )
return;
// Disabling an input context will deactivate mouse capture, if it's active
if ( !bEnable )
{
SetMouseCapture( hContext, false );
}
pContext->m_bEnabled = bEnable;
// Updates the cursor state since the stack changed
UpdateCursorState();
}
//-----------------------------------------------------------------------------
// Allows a context to make the cursor visible;
// the topmost enabled context wins
//-----------------------------------------------------------------------------
void CInputStackSystem::SetCursorVisible( InputContextHandle_t hContext, bool bVisible )
{
InputContext_t *pContext = ( InputContext_t* )hContext;
if ( !pContext )
return;
if ( pContext->m_bCursorVisible == bVisible )
return;
pContext->m_bCursorVisible = bVisible;
// Updates the cursor state since the stack changed
UpdateCursorState();
}
//-----------------------------------------------------------------------------
// Allows a context to set the cursor icon;
// the topmost enabled context wins
//-----------------------------------------------------------------------------
void CInputStackSystem::SetCursorIcon( InputContextHandle_t hContext, InputCursorHandle_t hCursor )
{
InputContext_t *pContext = ( InputContext_t* )hContext;
if ( !pContext )
return;
if ( pContext->m_hCursorIcon == hCursor )
return;
pContext->m_hCursorIcon = hCursor;
// Updates the cursor state since the stack changed
UpdateCursorState();
}
//-----------------------------------------------------------------------------
// Allows a context to enable mouse capture. Disabling an input context
// deactivates mouse capture. Capture will occur if it happens on the
// topmost enabled context
//-----------------------------------------------------------------------------
void CInputStackSystem::SetMouseCapture( InputContextHandle_t hContext, bool bEnable )
{
InputContext_t *pContext = ( InputContext_t* )hContext;
if ( !pContext )
return;
if ( pContext->m_bMouseCaptureEnabled == bEnable )
return;
pContext->m_bMouseCaptureEnabled = bEnable;
// Updates the cursor state since the stack changed
UpdateCursorState();
}
//-----------------------------------------------------------------------------
// Allows a context to set the mouse position. It only has any effect if the
// specified context is the topmost enabled context
//-----------------------------------------------------------------------------
void CInputStackSystem::SetCursorPosition( InputContextHandle_t hContext, int x, int y )
{
if ( IsTopmostEnabledContext( hContext ) )
{
g_pInputSystem->SetCursorPosition( x, y );
}
}
//-----------------------------------------------------------------------------
// This this context the topmost enabled context?
//-----------------------------------------------------------------------------
bool CInputStackSystem::IsTopmostEnabledContext( InputContextHandle_t hContext ) const
{
InputContext_t *pContext = ( InputContext_t* )hContext;
if ( !pContext )
return false;
int nCount = m_ContextStack.Count();
for ( int i = nCount; --i >= 0; )
{
InputContext_t *pStackContext = m_ContextStack[i];
if ( !pStackContext->m_bEnabled )
continue;
return ( pStackContext == pContext );
}
return false;
}
//-----------------------------------------------------------------------------
// Updates the cursor based on the current state of the input stack
//-----------------------------------------------------------------------------
void CInputStackSystem::UpdateCursorState()
{
int nCount = m_ContextStack.Count();
for ( int i = nCount; --i >= 0; )
{
InputContext_t *pContext = m_ContextStack[i];
if ( !pContext->m_bEnabled )
continue;
if ( !pContext->m_bCursorVisible )
{
g_pInputSystem->SetCursorIcon( INPUT_CURSOR_HANDLE_INVALID );
}
else
{
g_pInputSystem->SetCursorIcon( pContext->m_hCursorIcon );
}
if ( pContext->m_bMouseCaptureEnabled )
{
g_pInputSystem->EnableMouseCapture( g_pInputSystem->GetAttachedWindow() );
}
else
{
g_pInputSystem->DisableMouseCapture( );
}
break;
}
}

2500
inputsystem/inputsystem.cpp Normal file

File diff suppressed because it is too large Load Diff

629
inputsystem/inputsystem.h Normal file
View File

@ -0,0 +1,629 @@
//===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
// $NoKeywords: $
//
//===========================================================================//
#ifndef INPUTSYSTEM_H
#define INPUTSYSTEM_H
#ifdef _WIN32
#pragma once
#endif
#define DONT_DEFINE_DWORD
#include "platform.h"
#include "basetypes.h"
#ifdef PLATFORM_WINDOWS_PC
#define OEMRESOURCE //for OCR_* cursor junk
#define _WIN32_WINNT 0x502
#include <windows.h>
#include <zmouse.h>
#include "xbox/xboxstubs.h"
#include "../../dx9sdk/include/XInput.h"
#endif
#if defined( _WIN32 ) && defined( USE_SDL )
#include "appframework/ilaunchermgr.h"
#endif
#if defined(PLATFORM_POSIX) && !defined(_PS3)
#ifdef PLATFORM_OSX
#define DWORD DWORD
#define CARBON_WORKAROUND
#include <CoreFoundation/CoreFoundation.h>
#include <Carbon/Carbon.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOCFPlugIn.h>
#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
#include <IOKit/hid/IOHIDLib.h>
#include <IOKit/hid/IOHIDKeys.h>
#include <ForceFeedback/ForceFeedback.h>
#include <ForceFeedback/ForceFeedbackConstants.h>
#undef DWORD
#else
typedef char xKey_t;
#endif // OSX
#include "posix_stubs.h"
#endif // POSIX
#include "appframework/ilaunchermgr.h"
#include "inputsystem/iinputsystem.h"
#include "tier2/tier2.h"
#ifdef _PS3
#include "ps3/ps3_platform.h"
#include "ps3/ps3_win32stubs.h"
#include "ps3/ps3_core.h"
#include "ps3/ps3stubs.h"
#include <cell/pad.h>
#endif
#include "tier1/UtlStringMap.h"
#include "inputsystem/ButtonCode.h"
#include "inputsystem/AnalogCode.h"
#include "bitvec.h"
#include "tier1/utlvector.h"
#include "tier1/utlflags.h"
#include "input_device.h"
#include "steam/steam_api.h"
#if defined( _X360 )
#include "xbox/xbox_win32stubs.h"
#include "xbox/xbox_console.h"
#endif
enum
{
INPUT_TYPE_GENERIC_JOYSTICK = 0,
INPUT_TYPE_STEAMCONTROLLER,
};
//-----------------------------------------------------------------------------
// Implementation of the input system
//-----------------------------------------------------------------------------
class CInputSystem : public CTier2AppSystem< IInputSystem >
{
typedef CTier2AppSystem< IInputSystem > BaseClass;
public:
// Constructor, destructor
CInputSystem();
virtual ~CInputSystem();
// Inherited from IAppSystem
virtual InitReturnVal_t Init();
virtual bool Connect( CreateInterfaceFn factory );
virtual void Shutdown();
// Inherited from IInputSystem
virtual void AttachToWindow( void* hWnd );
virtual void DetachFromWindow( );
virtual void EnableInput( bool bEnable );
virtual void EnableMessagePump( bool bEnable );
virtual int GetPollTick() const;
virtual void PollInputState( bool bIsInGame = false );
virtual bool IsButtonDown( ButtonCode_t code ) const;
virtual int GetButtonPressedTick( ButtonCode_t code ) const;
virtual int GetButtonReleasedTick( ButtonCode_t code ) const;
virtual int GetAnalogValue( AnalogCode_t code ) const;
virtual int GetAnalogDelta( AnalogCode_t code ) const;
virtual int GetEventCount() const;
virtual bool MotionControllerActive() const;
virtual Quaternion GetMotionControllerOrientation() const;
virtual float GetMotionControllerPosX() const;
virtual float GetMotionControllerPosY() const;
virtual int GetMotionControllerDeviceStatus() const;
virtual uint64 GetMotionControllerDeviceStatusFlags() const;
virtual void SetMotionControllerDeviceStatus( int nStatus );
virtual void SetMotionControllerCalibrationInvalid( void );
virtual void StepMotionControllerCalibration( void );
virtual void ResetMotionControllerScreenCalibration( void );
virtual const InputEvent_t* GetEventData( ) const;
virtual void PostUserEvent( const InputEvent_t &event );
virtual int GetJoystickCount() const;
virtual void EnableJoystickInput( int nJoystick, bool bEnable );
virtual void EnableJoystickDiagonalPOV( int nJoystick, bool bEnable );
virtual void SampleDevices( void );
virtual void SetRumble( float fLeftMotor, float fRightMotor, int userId );
virtual void StopRumble( int userId = INVALID_USER_ID );
virtual void ResetInputState( void );
virtual const char *ButtonCodeToString( ButtonCode_t code ) const;
virtual const char *AnalogCodeToString( AnalogCode_t code ) const;
virtual ButtonCode_t StringToButtonCode( const char *pString ) const;
virtual AnalogCode_t StringToAnalogCode( const char *pString ) const;
virtual ButtonCode_t VirtualKeyToButtonCode( int nVirtualKey ) const;
virtual int ButtonCodeToVirtualKey( ButtonCode_t code ) const;
virtual ButtonCode_t ScanCodeToButtonCode( int lParam ) const;
virtual void SleepUntilInput( int nMaxSleepTimeMS );
virtual int GetPollCount() const;
virtual void SetCursorPosition( int x, int y );
void GetRawMouseAccumulators( int& accumX, int& accumY );
virtual void GetCursorPosition( int *pX, int *pY );
virtual void SetMouseCursorVisible( bool bVisible );
virtual void AddUIEventListener();
virtual void RemoveUIEventListener();
virtual PlatWindow_t GetAttachedWindow() const;
virtual InputCursorHandle_t GetStandardCursor( InputStandardCursor_t id );
virtual InputCursorHandle_t LoadCursorFromFile( const char *pFileName, const char *pPathID = NULL );
virtual void SetCursorIcon( InputCursorHandle_t hCursor );
virtual void EnableMouseCapture( PlatWindow_t hWnd );
virtual void DisableMouseCapture();
#ifdef PLATFORM_WINDOWS
LRESULT WindowProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
#elif defined(PLATFORM_OSX)
// helper function for callbacks
struct JoystickInfo_t;
void HIDAddElement(CFTypeRef refElement, JoystickInfo_t &info );
#endif
#ifdef _PS3
virtual void SetPS3CellPadDataHook( BCellPadDataHook_t hookFunc );
virtual void SetPS3CellPadNoDataHook( BCellPadNoDataHook_t hookFunc );
virtual void SetPS3StartButtonIdentificationMode();
virtual bool GetPS3CursorPos( int &x, int &y );
virtual void DisableHardwareCursor( void );
virtual void EnableHardwareCursor( void );
void ExitHardwareCursor( void );
#endif
#if defined( USE_SDL )
virtual void DisableHardwareCursor( void );
virtual void EnableHardwareCursor( void );
#endif
virtual void ResetCursorIcon();
// handles the connected input devices
virtual InputDevice_t GetConnectedInputDevices( void ); // returns the bitfield of all connected devices
virtual bool IsInputDeviceConnected( InputDevice_t device );
virtual void SetInputDeviceConnected( InputDevice_t device, bool connected = true );
virtual InputDevice_t IsOnlySingleDeviceConnected( void );
// handles the selected "current" primary input device
virtual bool IsDeviceReadingInput( InputDevice_t device ) const; // returns whether the passed in device is the current device. Returns true if no current device is defined
virtual InputDevice_t GetCurrentInputDevice( void ); // returns the enum referring to the one currently selected device
virtual void SetCurrentInputDevice( InputDevice_t device );
virtual void ResetCurrentInputDevice( void ); // sets the input device to the platform default
virtual void SampleInputToFindCurrentDevice( bool ); // looks for the next 'significant' button press to determine and set the current input device
virtual bool IsSamplingForCurrentDevice( void );
void InitPlatfromInputDeviceInfo( void );
private:
enum
{
STICK1_AXIS_X,
STICK1_AXIS_Y,
STICK2_AXIS_X,
STICK2_AXIS_Y,
MAX_STICKAXIS
};
enum
{
INPUT_STATE_QUEUED = 0,
INPUT_STATE_CURRENT,
INPUT_STATE_COUNT,
};
public:
#if defined(PLATFORM_OSX)
struct OSXInputValue_t
{
bool m_bSet;
int m_MinVal;
int m_MaxVal;
int m_MinReport;
int m_MaxReport;
int m_Cookie;
uint32 m_Usage;
CFTypeRef m_RefElement;
};
#define MAX_JOYSTICK_BUTTONS 32
#endif
struct JoystickInfo_t
{
#if defined(PLATFORM_WINDOWS) || defined(_GAMECONSOLE)
JOYINFOEX m_JoyInfoEx;
#elif defined(PLATFORM_OSX)
FFDeviceObjectReference m_FFInterface;
IOHIDDeviceInterface **m_Interface;
long usage; // from IOUSBHID Parser.h
long usagePage; // from IOUSBHID Parser.h
CInputSystem *m_pParent;
bool m_bRemoved;
bool m_bXBoxRumbleEnabled;
OSXInputValue_t m_xaxis;
OSXInputValue_t m_yaxis;
OSXInputValue_t m_zaxis;
OSXInputValue_t m_raxis;
OSXInputValue_t m_uaxis;
OSXInputValue_t m_vaxis;
OSXInputValue_t m_POV;
OSXInputValue_t m_Buttons[MAX_JOYSTICK_BUTTONS];
#elif defined(LINUX)
void *m_pDevice; // Really an SDL_GameController*, NULL if not present.
void *m_pHaptic; // Really an SDL_Haptic*
float m_fCurrentRumble;
bool m_bRumbleEnabled;
#else
#error
#endif
int m_nButtonCount;
int m_nAxisFlags;
int m_nDeviceId;
bool m_bHasPOVControl;
bool m_bDiagonalPOVControlEnabled;
unsigned int m_nFlags;
unsigned int m_nLastPolledButtons;
unsigned int m_nLastPolledAxisButtons;
unsigned int m_nLastPolledPOVState;
unsigned long m_pLastPolledAxes[MAX_JOYSTICK_AXES];
};
private:
struct xdevice_t
{
int userId;
byte type;
byte subtype;
word flags;
bool active;
XINPUT_STATE states[2];
int newState;
// track Xbox stick keys from previous frame
xKey_t lastStickKeys[MAX_STICKAXIS];
int stickThreshold[MAX_STICKAXIS];
float stickScale[MAX_STICKAXIS];
int quitTimeout;
int dpadLock;
// rumble
XINPUT_VIBRATION vibration;
bool pendingRumbleUpdate;
};
struct appKey_t
{
int repeats;
int sample;
};
struct InputState_t
{
// Analog states
CBitVec<BUTTON_CODE_LAST> m_ButtonState;
int m_ButtonPressedTick[ BUTTON_CODE_LAST ];
int m_ButtonReleasedTick[ BUTTON_CODE_LAST ];
int m_pAnalogDelta[ ANALOG_CODE_LAST ];
int m_pAnalogValue[ ANALOG_CODE_LAST ];
CUtlVector< InputEvent_t > m_Events;
bool m_bDirty;
};
// Steam Controller
struct steampad_t
{
steampad_t()
{
m_nHardwareIndex = 0;
m_nJoystickIndex = INVALID_USER_ID;
m_nLastPacketIndex = 0;
active = false;
memset( lastAnalogKeys, 0, sizeof( lastAnalogKeys ) );
}
bool active;
sKey_t lastAnalogKeys[MAX_STEAMPADAXIS];
appKey_t m_appSKeys[ SK_MAX_KEYS ];
// Hardware index and joystick index don't necessarily match
// Joystick index will depend on the order of multiple initialized devices
// Which could include other controller types
// Hardware index should line up 1:1 with the order they're polled
// and could change based on removing devices, unlike Joystick Index
uint32 m_nHardwareIndex;
int m_nJoystickIndex;
uint32 m_nLastPacketIndex;
};
steampad_t m_SteamControllerDevice[MAX_STEAM_CONTROLLERS];
uint32 m_unNumSteamControllerConnected;
bool m_bControllerModeActive;
int m_nControllerType[MAX_JOYSTICKS+MAX_STEAM_CONTROLLERS];
//Steam controllers start after this index.
int m_nJoystickBaseline;
public:
// Initializes all Xbox controllers
void InitializeXDevices( void );
// Opens an Xbox controller
void OpenXDevice( xdevice_t* pXDevice, int userId );
// Closes an Xbox controller
void CloseXDevice( xdevice_t* pXDevice );
// Samples the Xbox controllers
void PollXDevices( void );
// Samples console mouse
void PollXMouse();
// Samples console keyboard
void PollXKeyboard();
// Helper function used by ReadXDevice to handle stick direction events
void HandleXDeviceAxis( xdevice_t *pXDevice, int nAxisValue, xKey_t negativeKey, xKey_t positiveKey, int axisID );
// Samples an Xbox controller and queues input events
void ReadXDevice( xdevice_t* pXDevice );
// Submits force feedback data to an Xbox controller
void WriteToXDevice( xdevice_t* pXDevice );
// Sets rumble values for an Xbox controller
void SetXDeviceRumble( float fLeftMotor, float fRightMotor, int userId );
#if !defined( _CERT ) && !defined(LINUX)
CON_COMMAND_MEMBER_F( CInputSystem, "press_x360_button", PressX360Button, "Press the specified Xbox 360 controller button (lt, rt, st[art], ba[ck], lb, rb, a, b, x, y, l[eft], r[right], u[p], d[own])", 0 );
void PollPressX360Button( void );
uint32 m_press_x360_buttons[ 2 ];
#endif
#if defined( _PS3 )
void PS3_PollKeyboard( void );
void PS3_PollMouse( void );
void PS3_XInputPollEverything( BCellPadDataHook_t hookFunc, BCellPadNoDataHook_t hookNoDataFunc );
DWORD PS3_XInputGetState( DWORD dwUserIndex, PXINPUT_STATE pState );
void HandlePS3SharpshooterButtons( void );
void HandlePS3Move( PXINPUT_STATE& pState );
virtual void PS3SetupHardwareCursor( void* image );
#endif
void QueueMoveControllerRumble( float fRightMotor );
// Posts an Xbox key event, ignoring key repeats
void PostXKeyEvent( int nUserId, xKey_t xKey, int nSample );
// Dispatches all joystick button events through the game's window procs
void ProcessEvent( UINT uMsg, WPARAM wParam, LPARAM lParam );
// Initializes SteamControllers - Returns true if steam is running and finds controllers, otherwise false
bool InitializeSteamControllers( void );
// Samples all Steam Controllers - returns true if active this frame
bool PollSteamControllers( void );
// Initializes joysticks
void InitializeJoysticks( void );
// Samples the joystick
void PollJoystick( void );
// Update the joystick button state
void UpdateJoystickButtonState( int nJoystick );
// Update the joystick POV control
void UpdateJoystickPOVControl( int nJoystick );
// Record button state and post the event
void JoystickButtonEvent( ButtonCode_t button, int sample );
bool IsSteamControllerActive() const;
void SetSteamControllerMode( const char *pSteamControllerMode, const void *obj );
private:
// Purpose: Get raw joystick sample along axis
#if defined(LINUX)
void AxisAnalogButtonEvent( ButtonCode_t buttonCode, bool state, int nLastSampleTick );
#elif defined(OSX)
unsigned int AxisValue( JoystickAxis_t axis, JoystickInfo_t &info );
#else
unsigned int AxisValue( JoystickAxis_t axis, JOYINFOEX& ji );
#endif
// Chains the window message to the previous wndproc
LRESULT ChainWindowMessage( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
// Post an event to the queue
void PostEvent( int nType, int nTick, int nData = 0, int nData2 = 0, int nData3 = 0 );
// Deals with app deactivation (sends a bunch of button released messages)
void ActivateInputSystem( bool bActivated );
// Determines all mouse button presses
int ButtonMaskFromMouseWParam( WPARAM wParam, ButtonCode_t code = BUTTON_CODE_INVALID, bool bDown = false ) const;
// Updates the state of all mouse buttons
void UpdateMouseButtonState( int nButtonMask, ButtonCode_t dblClickCode = BUTTON_CODE_INVALID );
// Copies the input state record over
void CopyInputState( InputState_t *pDest, const InputState_t &src, bool bCopyEvents );
// Post an button press/release event to the queue
void PostButtonPressedEvent( InputEventType_t nType, int nTick, ButtonCode_t scanCode, ButtonCode_t virtualCode );
void PostButtonReleasedEvent( InputEventType_t nType, int nTick, ButtonCode_t scanCode, ButtonCode_t virtualCode );
// Release all buttons
void ReleaseAllButtons( int nFirstButton = 0, int nLastButton = BUTTON_CODE_LAST - 1 );
// Zero analog state
void ZeroAnalogState( int nFirstState, int nLastState );
// Converts xbox keys to button codes
ButtonCode_t XKeyToButtonCode( int nUserId, int nXKey ) const;
// Converts SteamController keys to button codes
ButtonCode_t SKeyToButtonCode( int nUserId, int nXKey ) const;
// Computes the sample tick
int ComputeSampleTick();
// Clears the input state, doesn't generate key-up messages
void ClearInputState( bool bPurgeState );
// Called for mouse move events. Sets the current x and y and posts events for the mouse moving.
void UpdateMousePositionState( InputState_t &state, short x, short y );
// Should we generate UI events?
bool ShouldGenerateUIEvents() const;
// Generates LocateMouseClick messages
void LocateMouseClick( LPARAM lParam );
// Initializes, shuts down cursors
void InitCursors();
void ShutdownCursors();
#ifdef WIN32
void PollInputState_Windows();
#endif
// Poll input state for different OSes.
#if defined( PLATFORM_OSX )
void PollInputState_OSX();
void HIDGetElementInfo( CFTypeRef refElement, OSXInputValue_t &input );
bool HIDBuildDevice( io_object_t ioHIDDeviceObject, JoystickInfo_t &info );
bool HIDCreateOpenDeviceInterface( io_object_t hidDevice, JoystickInfo_t &info );
void HIDGetDeviceInfo( io_object_t hidDevice, CFMutableDictionaryRef hidProperties, JoystickInfo_t &info );
void HIDGetElements( CFTypeRef refElementCurrent, JoystickInfo_t &info );
void HIDGetCollectionElements( CFMutableDictionaryRef deviceProperties, JoystickInfo_t &info );
void HIDDisposeDevice( JoystickInfo_t &info );
int HIDGetElementValue( JoystickInfo_t &info, OSXInputValue_t &value );
int HIDScaledCalibratedValue( JoystickInfo_t &info, OSXInputValue_t &value );
void HIDSortJoystickButtons( JoystickInfo_t &info );
#elif defined(LINUX)
public:
void PollInputState_Linux();
void JoystickHotplugAdded( int joystickIndex );
void JoystickHotplugRemoved( int joystickId );
void JoystickButtonPress( int joystickId, int button ); // button is a SDL_CONTROLLER_BUTTON;
void JoystickButtonRelease( int joystickId, int button ); // same as above.
void JoystickAxisMotion( int joystickId, int axis, int value );
#endif
private:
#if defined( USE_SDL ) || defined( OSX )
ILauncherMgr *m_pLauncherMgr;
#endif
WNDPROC m_ChainedWndProc;
HWND m_hAttachedHWnd;
HWND m_hLastIMEHWnd;
bool m_bEnabled;
bool m_bPumpEnabled;
bool m_bIsPolling;
bool m_bIMEComposing;
bool m_bIsInGame;
// Current button state
InputState_t m_InputState[INPUT_STATE_COUNT];
DWORD m_StartupTimeTick;
int m_nLastPollTick;
int m_nLastSampleTick;
int m_nPollCount;
// Mouse wheel hack
UINT m_uiMouseWheel;
// Joystick info
CUtlFlags<unsigned short> m_JoysticksEnabled;
int m_nJoystickCount;
bool m_bXController;
bool m_bSteamController;
float m_flLastSteamControllerInput;
float m_flLastControllerPollTime;
public:
JoystickInfo_t m_pJoystickInfo[ MAX_JOYSTICKS ];
private:
// Xbox controller info
appKey_t m_appXKeys[ XUSER_MAX_COUNT ][ XK_MAX_KEYS ];
xdevice_t m_XDevices[ XUSER_MAX_COUNT ];
// Used to determine whether to generate UI events
int m_nUIEventClientCount;
// raw mouse input
bool m_bRawInputSupported;
int m_mouseRawAccumX, m_mouseRawAccumY;
// Current mouse capture window
PlatWindow_t m_hCurrentCaptureWnd;
// For the 'SleepUntilInput' feature
HANDLE m_hEvent;
// Cursors, foiled again!
InputCursorHandle_t m_pDefaultCursors[ INPUT_CURSOR_COUNT ];
CUtlStringMap< InputCursorHandle_t > m_UserCursors;
CSysModule *m_pXInputDLL;
CSysModule *m_pRawInputDLL;
// NVNT falcon module
CSysModule *m_pNovintDLL;
private:
bool m_bCursorVisible;
bool m_bMotionControllerActive;
Quaternion m_qMotionControllerOrientation;
float m_fMotionControllerPosX;
float m_fMotionControllerPosY;
Vector m_vecMotionControllerPos;
int m_nMotionControllerStatus;
uint64 m_nMotionControllerStatusFlags;
public:
InputCursorHandle_t m_hCursor;
#ifdef _PS3
BCellPadDataHook_t m_pPS3CellPadDataHook;
BCellPadNoDataHook_t m_pPS3CellNoPadDataHook;
bool m_PS3KeyboardConnected;
bool m_PS3MouseConnected;
#endif
// describes all connected devices. A bitmask of InputDevice entries
InputDevice_t m_currentlyConnectedInputDevices;
// describes the current default input device
InputDevice_t m_currentInputDevice;
// number of different input devices on this platform
bool m_setCurrentInputDeviceOnNextButtonPress;
};
// Should we generate UI events?
inline bool CInputSystem::ShouldGenerateUIEvents() const
{
return m_nUIEventClientCount > 0;
}
#endif // INPUTSYSTEM_H

View File

@ -0,0 +1,72 @@
//-----------------------------------------------------------------------------
// INPUTSYSTEM.VPC
//
// Project Script
//-----------------------------------------------------------------------------
$macro SRCDIR ".."
$Macro OUTBINDIR "$SRCDIR\..\game\bin"
$include "$SRCDIR\vpc_scripts\source_dll_base.vpc"
$Configuration
{
$Compiler
{
$PreprocessorDefinitions "$BASE;NO_STRING_T;VERSION_SAFE_STEAM_API_INTERFACES;PROTECTED_THINGS_ENABLE"
$PreprocessorDefinitions "$BASE;INCLUDE_SCALEFORM" [$WIN32]
}
$Linker [!$PS3]
{
$AdditionalDependencies "$BASE Winmm.lib" [$WINDOWS]
$AdditionalDependencies "$BASE imm32.lib" [$WINDOWS]
$SystemLibraries "iconv" [$OSXALL]
$SystemFrameworks "Carbon;ForceFeedback;IOKit"
$SystemLibraries "SDL2" [$LINUXALL]
}
$Linker [$PS3]
{
$AdditionalDependencies "$BASE $SCE_PPU_LIBROOT\libio_stub.a $SCE_PPU_LIBROOT\libcamera_stub.a $SCE_PPU_LIBROOT\libgem_stub.a $SCE_PPU_LIBROOT\libspurs_stub.a $SCE_PPU_LIBROOT\libgcm_cmd.a $SCE_PPU_LIBROOT\libgcm_sys_stub.a"
}
}
$Project "inputsystem"
{
$Folder "Source Files"
{
$File "inputstacksystem.cpp"
$File "inputsystem.cpp"
$File "inputsystem.h"
$File "joystick.cpp" [!$POSIX]
$File "joystick_osx.cpp" [$OSXALL]
$File "joystick_linux.cpp" [$LINUXALL]
$File "steamcontroller.cpp"
$File "key_translation.cpp"
$File "key_translation.h"
$File "movecontroller_ps3.cpp" [$PS3]
$File "movecontroller_ps3.h" [$PS3]
$File "xcontroller.cpp" [!$POSIX]
$File "$SRCDIR\common\platforminputdevice.cpp"
}
$Folder "Public Headers"
{
$File "$SRCDIR\public\inputsystem\AnalogCode.h"
$File "$SRCDIR\public\inputsystem\ButtonCode.h"
$File "$SRCDIR\public\inputsystem\iinputsystem.h"
$File "$SRCDIR\public\inputsystem\iinputstacksystem.h"
$File "$SRCDIR\public\inputsystem\InputEnums.h"
$File "$SRCDIR\dx9sdk\include\XInput.h"
$File "$SRCDIR\common\platforminputdevice.h"
}
$Folder "Link Libraries"
{
$Lib "tier2"
$Lib "mathlib"
$ImplibExternal steam_api [ ( $WIN32 || $POSIX || $PS3 ) && !$NO_STEAM ]
$ImplibExternal steam_api64 [ $WIN64 && !$NO_STEAM ]
}
}

View File

@ -0,0 +1,13 @@
"vpc_cache"
{
"CacheVersion" "1"
"win32"
{
"CRCFile" "inputsystem.vcxproj.vpc_crc"
"OutputFiles"
{
"0" "inputsystem.vcxproj"
"1" "inputsystem.vcxproj.filters"
}
}
}

369
inputsystem/joystick.cpp Normal file
View File

@ -0,0 +1,369 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: PC Joystick implementation for inputsystem.dll
//
//===========================================================================//
#include "inputsystem.h"
#include "tier1/convar.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Joystick helpers
//-----------------------------------------------------------------------------
#define JOY_POVFWDRIGHT ( ( JOY_POVFORWARD + JOY_POVRIGHT ) >> 1 ) // 4500
#define JOY_POVRIGHTBACK ( ( JOY_POVRIGHT + JOY_POVBACKWARD ) >> 1 ) // 13500
#define JOY_POVFBACKLEFT ( ( JOY_POVBACKWARD + JOY_POVLEFT ) >> 1 ) // 22500
#define JOY_POVLEFTFWD ( ( JOY_POVLEFT + JOY_POVFORWARD ) >> 1 ) // 31500
ConVar joy_wwhack1( "joy_wingmanwarrior_centerhack", "0", FCVAR_ARCHIVE, "Wingman warrior centering hack." );
ConVar joy_axisbutton_threshold( "joy_axisbutton_threshold", "0.3", FCVAR_ARCHIVE, "Analog axis range before a button press is registered." );
//-----------------------------------------------------------------------------
// Initialize all joysticks
//-----------------------------------------------------------------------------
void CInputSystem::InitializeJoysticks( void )
{
// assume no joystick
m_nJoystickCount = 0;
// abort startup if user requests no joystick
if ( CommandLine()->FindParm("-nojoy" ) )
return;
// verify joystick driver is present
int nMaxJoysticks = joyGetNumDevs();
if ( nMaxJoysticks > MAX_JOYSTICKS )
{
nMaxJoysticks = MAX_JOYSTICKS;
}
else if ( nMaxJoysticks <= 0 )
{
DevMsg( 1, "joystick not found -- driver not present\n");
return;
}
// cycle through the joysticks looking for valid ones
MMRESULT mmr;
for ( int i=0; i < nMaxJoysticks; i++ )
{
JOYINFOEX ji;
Q_memset( &ji, 0, sizeof( ji ) );
ji.dwSize = sizeof(ji);
ji.dwFlags = JOY_RETURNCENTERED;
mmr = joyGetPosEx( i, &ji );
if ( mmr != JOYERR_NOERROR )
continue;
// get the capabilities of the selected joystick
// abort startup if command fails
JOYCAPS jc;
Q_memset( &jc, 0, sizeof( jc ) );
mmr = joyGetDevCaps( i, &jc, sizeof( jc ) );
if ( mmr != JOYERR_NOERROR )
continue;
JoystickInfo_t &info = m_pJoystickInfo[m_nJoystickCount];
info.m_nDeviceId = i;
info.m_JoyInfoEx = ji;
info.m_nButtonCount = (int)jc.wNumButtons;
info.m_bHasPOVControl = ( jc.wCaps & JOYCAPS_HASPOV ) ? true : false;
info.m_bDiagonalPOVControlEnabled = false;
info.m_nFlags = JOY_RETURNCENTERED | JOY_RETURNBUTTONS | JOY_RETURNX | JOY_RETURNY;
info.m_nAxisFlags = 0;
if ( jc.wNumAxes >= 2 )
{
info.m_nAxisFlags |= 0x3;
}
if ( info.m_bHasPOVControl )
{
info.m_nFlags |= JOY_RETURNPOV;
}
if ( jc.wCaps & JOYCAPS_HASZ )
{
info.m_nFlags |= JOY_RETURNZ;
info.m_nAxisFlags |= 0x4;
}
if ( jc.wCaps & JOYCAPS_HASR )
{
info.m_nFlags |= JOY_RETURNR;
info.m_nAxisFlags |= 0x8;
}
if ( jc.wCaps & JOYCAPS_HASU )
{
info.m_nFlags |= JOY_RETURNU;
info.m_nAxisFlags |= 0x10;
}
if ( jc.wCaps & JOYCAPS_HASV )
{
info.m_nFlags |= JOY_RETURNV;
info.m_nAxisFlags |= 0x20;
}
info.m_nLastPolledButtons = 0;
info.m_nLastPolledAxisButtons = 0;
info.m_nLastPolledPOVState = 0;
memset( info.m_pLastPolledAxes, 0, sizeof(info.m_pLastPolledAxes) );
++m_nJoystickCount;
EnableJoystickInput( i, true );
}
}
//-----------------------------------------------------------------------------
// Process the event
//-----------------------------------------------------------------------------
void CInputSystem::JoystickButtonEvent( ButtonCode_t button, int sample )
{
// package the key
if ( sample )
{
PostButtonPressedEvent( IE_ButtonPressed, m_nLastSampleTick, button, button );
}
else
{
PostButtonReleasedEvent( IE_ButtonReleased, m_nLastSampleTick, button, button );
}
}
//-----------------------------------------------------------------------------
// Update the joystick button state
//-----------------------------------------------------------------------------
void CInputSystem::UpdateJoystickButtonState( int nJoystick )
{
JoystickInfo_t &info = m_pJoystickInfo[nJoystick];
JOYINFOEX& ji = info.m_JoyInfoEx;
// Standard joystick buttons
unsigned int buttons = ji.dwButtons ^ info.m_nLastPolledButtons;
if ( buttons )
{
for ( int j = 0 ; j < info.m_nButtonCount ; ++j )
{
int mask = buttons & ( 1 << j );
if ( !mask )
continue;
ButtonCode_t code = (ButtonCode_t)JOYSTICK_BUTTON( nJoystick, j );
if ( mask & ji.dwButtons )
{
// down event
JoystickButtonEvent( code, MAX_BUTTONSAMPLE );
}
else
{
// up event
JoystickButtonEvent( code, 0 );
}
}
info.m_nLastPolledButtons = (unsigned int)ji.dwButtons;
}
// Analog axis buttons
const float minValue = joy_axisbutton_threshold.GetFloat() * MAX_BUTTONSAMPLE;
for ( int j = 0 ; j < MAX_JOYSTICK_AXES; ++j )
{
if ( ( info.m_nAxisFlags & (1 << j) ) == 0 )
continue;
// Positive side of the axis
int mask = ( 1 << (j << 1) );
ButtonCode_t code = JOYSTICK_AXIS_BUTTON( nJoystick, (j << 1) );
float value = GetAnalogValue( JOYSTICK_AXIS( nJoystick, j ) );
if ( value > minValue && !(info.m_nLastPolledAxisButtons & mask) )
{
info.m_nLastPolledAxisButtons |= mask;
JoystickButtonEvent( code, MAX_BUTTONSAMPLE );
}
if ( value <= minValue && (info.m_nLastPolledAxisButtons & mask) )
{
info.m_nLastPolledAxisButtons &= ~mask;
JoystickButtonEvent( code, 0 );
}
// Negative side of the axis
mask <<= 1;
code = (ButtonCode_t)( code + 1 );
if ( value < -minValue && !(info.m_nLastPolledAxisButtons & mask) )
{
info.m_nLastPolledAxisButtons |= mask;
JoystickButtonEvent( code, MAX_BUTTONSAMPLE );
}
if ( value >= -minValue && (info.m_nLastPolledAxisButtons & mask) )
{
info.m_nLastPolledAxisButtons &= ~mask;
JoystickButtonEvent( code, 0 );
}
}
}
//-----------------------------------------------------------------------------
// Purpose: Get raw joystick sample along axis
//-----------------------------------------------------------------------------
unsigned int CInputSystem::AxisValue( JoystickAxis_t axis, JOYINFOEX& ji )
{
switch (axis)
{
case JOY_AXIS_X:
return (unsigned int)ji.dwXpos;
case JOY_AXIS_Y:
return (unsigned int)ji.dwYpos;
case JOY_AXIS_Z:
return (unsigned int)ji.dwZpos;
case JOY_AXIS_R:
return (unsigned int)ji.dwRpos;
case JOY_AXIS_U:
return (unsigned int)ji.dwUpos;
case JOY_AXIS_V:
return (unsigned int)ji.dwVpos;
}
// FIX: need to do some kind of error
return (unsigned int)ji.dwXpos;
}
//-----------------------------------------------------------------------------
// Update the joystick POV control
//-----------------------------------------------------------------------------
void CInputSystem::UpdateJoystickPOVControl( int nJoystick )
{
JoystickInfo_t &info = m_pJoystickInfo[nJoystick];
JOYINFOEX& ji = info.m_JoyInfoEx;
if ( !info.m_bHasPOVControl )
return;
// convert POV information into 4 bits of state information
// this avoids any potential problems related to moving from one
// direction to another without going through the center position
unsigned int povstate = 0;
if ( ji.dwPOV != JOY_POVCENTERED )
{
if (ji.dwPOV == JOY_POVFORWARD) // 0
{
povstate |= 0x01;
}
if (ji.dwPOV == JOY_POVRIGHT) // 9000
{
povstate |= 0x02;
}
if (ji.dwPOV == JOY_POVBACKWARD) // 18000
{
povstate |= 0x04;
}
if (ji.dwPOV == JOY_POVLEFT) // 27000
{
povstate |= 0x08;
}
// Deal with diagonals if user wants them
if ( info.m_bDiagonalPOVControlEnabled )
{
if (ji.dwPOV == JOY_POVFWDRIGHT) // 4500
{
povstate |= ( 0x01 | 0x02 );
}
if (ji.dwPOV == JOY_POVRIGHTBACK) // 13500
{
povstate |= ( 0x02 | 0x04 );
}
if (ji.dwPOV == JOY_POVFBACKLEFT) // 22500
{
povstate |= ( 0x04 | 0x08 );
}
if (ji.dwPOV == JOY_POVLEFTFWD) // 31500
{
povstate |= ( 0x08 | 0x01 );
}
}
}
// determine which bits have changed and key an auxillary event for each change
unsigned int buttons = povstate ^ info.m_nLastPolledPOVState;
if ( buttons )
{
for ( int i = 0; i < JOYSTICK_POV_BUTTON_COUNT; ++i )
{
unsigned int mask = buttons & ( 1 << i );
if ( !mask )
continue;
ButtonCode_t code = (ButtonCode_t)JOYSTICK_POV_BUTTON( nJoystick, i );
if ( mask & povstate )
{
// Keydown on POV buttons
JoystickButtonEvent( code, MAX_BUTTONSAMPLE );
}
else
{
// KeyUp on POV buttons
JoystickButtonEvent( code, 0 );
}
}
// Latch old values
info.m_nLastPolledPOVState = povstate;
}
}
//-----------------------------------------------------------------------------
// Purpose: Sample the joystick
//-----------------------------------------------------------------------------
void CInputSystem::PollJoystick( void )
{
if ( !m_JoysticksEnabled.IsAnyFlagSet() )
return;
InputState_t &state = m_InputState[ m_bIsPolling ];
for ( int i = 0; i < m_nJoystickCount; ++i )
{
if ( !m_JoysticksEnabled.IsFlagSet( 1 << i ) )
continue;
JoystickInfo_t &info = m_pJoystickInfo[i];
JOYINFOEX& ji = info.m_JoyInfoEx;
Q_memset( &ji, 0, sizeof( ji ) );
ji.dwSize = sizeof( ji );
ji.dwFlags = (DWORD)info.m_nFlags;
if ( joyGetPosEx( info.m_nDeviceId, &ji ) != JOYERR_NOERROR )
continue;
// This hack fixes a bug in the Logitech WingMan Warrior DirectInput Driver
// rather than having 32768 be the zero point, they have the zero point at 32668
// go figure -- anyway, now we get the full resolution out of the device
if ( joy_wwhack1.GetBool() )
{
ji.dwUpos += 100;
}
// Poll joystick axes
for ( int j = 0; j < MAX_JOYSTICK_AXES; ++j )
{
if ( ( info.m_nAxisFlags & ( 1 << j ) ) == 0 )
continue;
AnalogCode_t code = JOYSTICK_AXIS( i, j );
int nValue = AxisValue( (JoystickAxis_t)j, ji ) - MAX_BUTTONSAMPLE;
state.m_pAnalogDelta[ code ] = nValue - state.m_pAnalogValue[ code ];
state.m_pAnalogValue[ code ] = nValue;
if ( state.m_pAnalogDelta[ code ] != 0 )
{
PostEvent( IE_AnalogValueChanged, m_nLastSampleTick, code, state.m_pAnalogValue[ code ], state.m_pAnalogDelta[ code ] );
}
}
UpdateJoystickButtonState( i );
UpdateJoystickPOVControl( i );
}
}

View File

@ -0,0 +1,566 @@
//===== Copyright (c) 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose: Linux Joystick implementation for inputsystem.dll
//
//===========================================================================//
/* For force feedback testing. */
#include "inputsystem.h"
#include "tier1/convar.h"
#include "tier0/icommandline.h"
#include "SDL.h"
#include "SDL_gamecontroller.h"
#include "SDL_haptic.h"
// NOTE: This has to be the last file included!
#include "tier0/memdbgon.h"
static ButtonCode_t ControllerButtonToButtonCode( SDL_GameControllerButton button );
static AnalogCode_t ControllerAxisToAnalogCode( SDL_GameControllerAxis axis );
static int JoystickSDLWatcher( void *userInfo, SDL_Event *event );
ConVar joy_axisbutton_threshold( "joy_axisbutton_threshold", "0.3", FCVAR_ARCHIVE, "Analog axis range before a button press is registered." );
ConVar joy_axis_deadzone( "joy_axis_deadzone", "0.2", FCVAR_ARCHIVE, "Dead zone near the zero point to not report movement." );
static void joy_active_changed_f( IConVar *var, const char *pOldValue, float flOldValue );
ConVar joy_active( "joy_active", "-1", FCVAR_NONE, "Which of the connected joysticks / gamepads to use (-1 means first found)", &joy_active_changed_f);
static void joy_gamecontroller_config_changed_f( IConVar *var, const char *pOldValue, float flOldValue );
ConVar joy_gamecontroller_config( "joy_gamecontroller_config", "", FCVAR_ARCHIVE, "Game controller mapping (passed to SDL with SDL_HINT_GAMECONTROLLERCONFIG), can also be configured in Steam Big Picture mode.", &joy_gamecontroller_config_changed_f );
void SearchForDevice()
{
int newJoystickId = joy_active.GetInt();
CInputSystem *pInputSystem = (CInputSystem *)g_pInputSystem;
CInputSystem::JoystickInfo_t& currentJoystick = pInputSystem->m_pJoystickInfo[ 0 ];
if ( !pInputSystem )
{
return;
}
// -1 means "first available."
if ( newJoystickId < 0 )
{
pInputSystem->JoystickHotplugAdded(0);
return;
}
for ( int device_index = 0; device_index < SDL_NumJoysticks(); ++device_index )
{
SDL_Joystick *joystick = SDL_JoystickOpen(device_index);
if ( joystick == NULL )
{
continue;
}
int joystickId = SDL_JoystickInstanceID(joystick);
SDL_JoystickClose(joystick);
if ( joystickId == newJoystickId )
{
pInputSystem->JoystickHotplugAdded(device_index);
break;
}
}
}
//---------------------------------------------------------------------------------------
// Switch our active joystick to another device
//---------------------------------------------------------------------------------------
void joy_active_changed_f( IConVar *var, const char *pOldValue, float flOldValue )
{
SearchForDevice();
}
//---------------------------------------------------------------------------------------
// Reinitialize the game controller layer when the joy_gamecontroller_config is updated.
//---------------------------------------------------------------------------------------
void joy_gamecontroller_config_changed_f( IConVar *var, const char *pOldValue, float flOldValue )
{
CInputSystem *pInputSystem = (CInputSystem *)g_pInputSystem;
if ( pInputSystem && SDL_WasInit(SDL_INIT_GAMECONTROLLER) )
{
// We need to reinitialize the whole thing (i.e. undo CInputSystem::InitializeJoysticks and then call it again)
// due to SDL_GameController only reading the SDL_HINT_GAMECONTROLLERCONFIG on init.
SDL_DelEventWatch(JoystickSDLWatcher, pInputSystem);
if ( pInputSystem->m_pJoystickInfo[ 0 ].m_pDevice != NULL )
{
pInputSystem->JoystickHotplugRemoved(pInputSystem->m_pJoystickInfo[ 0 ].m_nDeviceId);
}
SDL_QuitSubSystem(SDL_INIT_GAMECONTROLLER);
pInputSystem->InitializeJoysticks();
}
}
//-----------------------------------------------------------------------------
// Handle the events coming from the GameController SDL subsystem.
//-----------------------------------------------------------------------------
int JoystickSDLWatcher( void *userInfo, SDL_Event *event )
{
// This is executed on the same thread as SDL_PollEvent, as PollEvent updates the joystick subsystem,
// which then calls SDL_PushEvent for the various events below. PushEvent invokes this callback.
// SDL_PollEvent is called in PumpWindowsMessageLoop which is coming from PollInputState_Linux, so there's
// no worry about calling PostEvent (which doesn't seem to be thread safe) from other threads.
Assert(ThreadInMainThread());
CInputSystem *pInputSystem = (CInputSystem *)userInfo;
Assert(pInputSystem != NULL);
Assert(event != NULL);
if ( event == NULL || pInputSystem == NULL )
{
Warning("No input system\n");
return 1;
}
switch ( event->type )
{
case SDL_CONTROLLERAXISMOTION:
{
pInputSystem->JoystickAxisMotion(event->caxis.which, event->caxis.axis, event->caxis.value);
break;
}
case SDL_CONTROLLERBUTTONDOWN:
pInputSystem->JoystickButtonPress(event->cbutton.which, event->cbutton.button);
break;
case SDL_CONTROLLERBUTTONUP:
pInputSystem->JoystickButtonRelease(event->cbutton.which, event->cbutton.button);
break;
case SDL_CONTROLLERDEVICEADDED:
pInputSystem->JoystickHotplugAdded(event->cdevice.which);
break;
case SDL_CONTROLLERDEVICEREMOVED:
pInputSystem->JoystickHotplugRemoved(event->cdevice.which);
SearchForDevice();
break;
}
return 1;
}
//-----------------------------------------------------------------------------
// Initialize all joysticks
//-----------------------------------------------------------------------------
void CInputSystem::InitializeJoysticks( void )
{
// assume no joystick
m_nJoystickCount = 0;
// abort startup if user requests no joystick
if ( CommandLine()->FindParm("-nojoy") ) return;
if ( !SDL_WasInit(SDL_INIT_GAMECONTROLLER) )
{
const char *controllerConfig = joy_gamecontroller_config.GetString();
if ( strlen(controllerConfig) > 0 )
{
DevMsg("Passing joy_gamecontroller_config to SDL ('%s').\n", controllerConfig);
// We need to pass this hint to SDL *before* we init the gamecontroller subsystem, otherwise it gets ignored.
SDL_SetHint(SDL_HINT_GAMECONTROLLERCONFIG, controllerConfig);
}
if ( SDL_InitSubSystem(SDL_INIT_GAMECONTROLLER) == -1 )
{
Warning("Gamecontroller not found -- SDL_Init(SDL_INIT_GAMECONTROLLER) failed: %s.\n", SDL_GetError());
return;
}
SDL_AddEventWatch(JoystickSDLWatcher, this);
}
if ( !SDL_WasInit(SDL_INIT_HAPTIC) )
{
if ( SDL_InitSubSystem(SDL_INIT_HAPTIC) == -1 )
{
Warning("Joystick init failed -- SDL_Init(SDL_INIT_HAPTIC) failed: %s.\n", SDL_GetError());
return;
}
}
memset(m_pJoystickInfo, 0, sizeof(m_pJoystickInfo));
for ( int i = 0; i < MAX_JOYSTICKS; ++i )
{
m_pJoystickInfo[ i ].m_nDeviceId = -1;
}
const int totalSticks = SDL_NumJoysticks();
for ( int i = 0; i < totalSticks; i++ )
{
if ( SDL_IsGameController(i) )
{
JoystickHotplugAdded(i);
}
else
{
SDL_JoystickGUID joyGUID = SDL_JoystickGetDeviceGUID(i);
char szGUID[sizeof(joyGUID.data)*2 + 1];
SDL_JoystickGetGUIDString(joyGUID, szGUID, sizeof(szGUID));
Msg("Found joystick '%s' (%s), but no recognized controller configuration for it.\n", SDL_JoystickNameForIndex(i), szGUID);
}
}
if ( totalSticks < 1 )
{
Msg("Did not detect any valid joysticks.\n");
}
}
// Update the joy_xcontroller_found convar to force CInput::JoyStickMove to re-exec 360controller-linux.cfg
static void SetJoyXControllerFound( bool found )
{
static ConVarRef xcontrollerVar( "joy_xcontroller_found" );
static ConVarRef joystickVar( "joystick" );
if ( xcontrollerVar.IsValid() )
{
xcontrollerVar.SetValue(found);
}
if ( found && joystickVar.IsValid() )
{
joystickVar.SetValue(true);
}
}
void CInputSystem::JoystickHotplugAdded( int joystickIndex )
{
// SDL_IsGameController doesn't bounds check its inputs.
if ( joystickIndex < 0 || joystickIndex >= SDL_NumJoysticks() )
{
return;
}
if ( !SDL_IsGameController(joystickIndex) )
{
Warning("Joystick is not recognized by the game controller system. You can configure the controller in Steam Big Picture mode.\n");
return;
}
SDL_Joystick *joystick = SDL_JoystickOpen(joystickIndex);
if ( joystick == NULL )
{
Warning("Could not open joystick %i: %s", joystickIndex, SDL_GetError());
return;
}
int joystickId = SDL_JoystickInstanceID(joystick);
SDL_JoystickClose(joystick);
int activeJoystick = joy_active.GetInt();
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( activeJoystick < 0 )
{
// Only opportunistically open devices if we don't have one open already.
if ( info.m_nDeviceId != -1 )
{
Msg("Detected supported joystick #%i '%s'. Currently active joystick is #%i.\n", joystickId, SDL_JoystickNameForIndex(joystickIndex), info.m_nDeviceId);
return;
}
}
else if ( activeJoystick != joystickId )
{
Msg("Detected supported joystick #%i '%s'. Currently active joystick is #%i.\n", joystickId, SDL_JoystickNameForIndex(joystickIndex), activeJoystick);
return;
}
if ( info.m_nDeviceId != -1 )
{
// Don't try to open the device we already have open.
if ( info.m_nDeviceId == joystickId )
{
return;
}
DevMsg("Joystick #%i already initialized, removing it first.\n", info.m_nDeviceId);
JoystickHotplugRemoved(info.m_nDeviceId);
}
Msg("Initializing joystick #%i and making it active.\n", joystickId);
SDL_GameController *controller = SDL_GameControllerOpen(joystickIndex);
if ( controller == NULL )
{
Warning("Failed to open joystick %i: %s\n", joystickId, SDL_GetError());
return;
}
// XXX: This will fail if this is a *real* hotplug event (and not coming from the initial InitializeJoysticks call).
// That's because the SDL haptic subsystem currently doesn't do hotplugging. Everything but haptics will work fine.
SDL_Haptic *haptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(controller));
if ( haptic == NULL || SDL_HapticRumbleInit(haptic) != 0 )
{
Warning("Unable to initialize rumble for joystick #%i: %s\n", joystickId, SDL_GetError());
haptic = NULL;
}
info.m_pDevice = controller;
info.m_pHaptic = haptic;
info.m_nDeviceId = SDL_JoystickInstanceID(SDL_GameControllerGetJoystick(controller));
info.m_nButtonCount = SDL_CONTROLLER_BUTTON_MAX;
info.m_bRumbleEnabled = false;
SetJoyXControllerFound(true);
EnableJoystickInput(0, true);
m_nJoystickCount = 1;
m_bXController = true;
// We reset joy_active to -1 because joystick ids are never reused - until you restart.
// Setting it to -1 means that you get expected hotplugging behavior if you disconnect the current joystick.
joy_active.SetValue(-1);
}
void CInputSystem::JoystickHotplugRemoved( int joystickId )
{
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( info.m_nDeviceId != joystickId )
{
DevMsg("Ignoring hotplug remove for #%i, active joystick is #%i.\n", joystickId, info.m_nDeviceId);
return;
}
if ( info.m_pDevice == NULL )
{
info.m_nDeviceId = -1;
DevMsg("Got hotplug remove event for removed joystick %i, ignoring.\n");
return;
}
m_nJoystickCount = 0;
m_bXController = false;
EnableJoystickInput(0, false);
SetJoyXControllerFound(false);
SDL_HapticClose((SDL_Haptic *)info.m_pHaptic);
SDL_GameControllerClose((SDL_GameController *)info.m_pDevice);
info.m_pHaptic = NULL;
info.m_pDevice = NULL;
info.m_nButtonCount = 0;
info.m_nDeviceId = -1;
info.m_bRumbleEnabled = false;
Msg("Joystick %i removed.\n", joystickId);
}
void CInputSystem::JoystickButtonPress( int joystickId, int button )
{
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( info.m_nDeviceId != joystickId )
{
Warning("Not active device input system (%i x %i)\n", info.m_nDeviceId, joystickId);
return;
}
ButtonCode_t buttonCode = ControllerButtonToButtonCode((SDL_GameControllerButton)button);
PostButtonPressedEvent(IE_ButtonPressed, m_nLastSampleTick, buttonCode, buttonCode);
}
void CInputSystem::JoystickButtonRelease( int joystickId, int button )
{
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( info.m_nDeviceId != joystickId )
{
return;
}
ButtonCode_t buttonCode = ControllerButtonToButtonCode((SDL_GameControllerButton)button);
PostButtonReleasedEvent(IE_ButtonReleased, m_nLastSampleTick, buttonCode, buttonCode);
}
void CInputSystem::AxisAnalogButtonEvent( ButtonCode_t buttonCode, bool bState, int nLastSampleTick )
{
int keyIndex = buttonCode - JOYSTICK_FIRST_AXIS_BUTTON;
Assert(keyIndex >= 0 && keyIndex < ARRAYSIZE(m_appXKeys[0]));
bool bExistingState = m_appXKeys[0][keyIndex].repeats > 0;
if ( bState != bExistingState )
{
if ( bState )
{
PostButtonPressedEvent( IE_ButtonPressed, nLastSampleTick, buttonCode, buttonCode );
}
else
{
PostButtonReleasedEvent( IE_ButtonReleased, nLastSampleTick, buttonCode, buttonCode );
}
m_appXKeys[0][keyIndex].repeats = bState ? 1 : 0;
}
}
void CInputSystem::JoystickAxisMotion( int joystickId, int axis, int value )
{
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( info.m_nDeviceId != joystickId )
{
return;
}
AnalogCode_t code = ControllerAxisToAnalogCode((SDL_GameControllerAxis)axis);
if ( code == ANALOG_CODE_INVALID )
{
Warning("Invalid code for axis %i\n", axis);
return;
}
int minValue = joy_axis_deadzone.GetFloat() * 32767;
if ( abs(value) < minValue )
{
value = 0;
}
// Trigger right and left both map to the Z axis, but they only have positive values.
// To differentiate, right trigger is negative values, left is positive.
switch ( axis )
{
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
AxisAnalogButtonEvent( KEY_XBUTTON_RTRIGGER, value != 0, m_nLastSampleTick );
break;
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
AxisAnalogButtonEvent( KEY_XBUTTON_LTRIGGER, value != 0, m_nLastSampleTick );
break;
case SDL_CONTROLLER_AXIS_LEFTX:
AxisAnalogButtonEvent( KEY_XSTICK1_LEFT, value < 0, m_nLastSampleTick );
AxisAnalogButtonEvent( KEY_XSTICK1_RIGHT, value > 0, m_nLastSampleTick );
break;
case SDL_CONTROLLER_AXIS_LEFTY:
AxisAnalogButtonEvent( KEY_XSTICK1_UP, value < 0, m_nLastSampleTick );
AxisAnalogButtonEvent( KEY_XSTICK1_DOWN, value > 0, m_nLastSampleTick );
break;
}
InputState_t& state = m_InputState[ m_bIsPolling ];
state.m_pAnalogDelta[ code ] = value - state.m_pAnalogValue[ code ];
state.m_pAnalogValue[ code ] = value;
if ( state.m_pAnalogDelta[ code ] != 0 )
{
PostEvent(IE_AnalogValueChanged, m_nLastSampleTick, code, state.m_pAnalogValue[ code ] , state.m_pAnalogDelta[ code ] );
}
}
//-----------------------------------------------------------------------------
// Process the event
//-----------------------------------------------------------------------------
void CInputSystem::JoystickButtonEvent( ButtonCode_t button, int sample )
{
// Not used - we post button events from JoystickButtonPress/Release.
}
//-----------------------------------------------------------------------------
// Update the joystick button state
//-----------------------------------------------------------------------------
void CInputSystem::UpdateJoystickButtonState( int nJoystick )
{
// We don't sample - we get events posted by SDL_GameController in JoystickSDLWatcher
}
//-----------------------------------------------------------------------------
// Update the joystick POV control
//-----------------------------------------------------------------------------
void CInputSystem::UpdateJoystickPOVControl( int nJoystick )
{
// SDL GameController does not support joystick POV. Should we poll?
}
//-----------------------------------------------------------------------------
// Purpose: Sample the joystick
//-----------------------------------------------------------------------------
void CInputSystem::PollJoystick( void )
{
// We don't sample - we get events posted by SDL_GameController in JoystickSDLWatcher
}
void CInputSystem::SetXDeviceRumble( float fLeftMotor, float fRightMotor, int userId )
{
JoystickInfo_t& info = m_pJoystickInfo[ 0 ];
if ( info.m_nDeviceId < 0 || info.m_pHaptic == NULL )
{
return;
}
float strength = (fLeftMotor + fRightMotor) / 2.f;
if ( info.m_bRumbleEnabled && abs(info.m_fCurrentRumble - strength) < 0.01f )
{
return;
}
else
{
info.m_bRumbleEnabled = true;
}
info.m_fCurrentRumble = strength;
if ( SDL_HapticRumblePlay((SDL_Haptic *)info.m_pHaptic, strength, SDL_HAPTIC_INFINITY) != 0 )
{
Warning("Couldn't play rumble (strength %.1f): %s\n", strength, SDL_GetError());
}
}
ButtonCode_t ControllerButtonToButtonCode( SDL_GameControllerButton button )
{
switch ( button )
{
case SDL_CONTROLLER_BUTTON_A: // KEY_XBUTTON_A
case SDL_CONTROLLER_BUTTON_B: // KEY_XBUTTON_B
case SDL_CONTROLLER_BUTTON_X: // KEY_XBUTTON_X
case SDL_CONTROLLER_BUTTON_Y: // KEY_XBUTTON_Y
return JOYSTICK_BUTTON(0, button);
case SDL_CONTROLLER_BUTTON_BACK:
return KEY_XBUTTON_BACK;
case SDL_CONTROLLER_BUTTON_START:
return KEY_XBUTTON_START;
case SDL_CONTROLLER_BUTTON_GUIDE:
return KEY_XBUTTON_BACK; // XXX: How are we supposed to handle this? Steam overlay etc.
case SDL_CONTROLLER_BUTTON_LEFTSTICK:
return KEY_XBUTTON_STICK1;
case SDL_CONTROLLER_BUTTON_RIGHTSTICK:
return KEY_XBUTTON_STICK2;
case SDL_CONTROLLER_BUTTON_LEFTSHOULDER:
return KEY_XBUTTON_LEFT_SHOULDER;
case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER:
return KEY_XBUTTON_RIGHT_SHOULDER;
case SDL_CONTROLLER_BUTTON_DPAD_UP:
return KEY_XBUTTON_UP;
case SDL_CONTROLLER_BUTTON_DPAD_DOWN:
return KEY_XBUTTON_DOWN;
case SDL_CONTROLLER_BUTTON_DPAD_LEFT:
return KEY_XBUTTON_LEFT;
case SDL_CONTROLLER_BUTTON_DPAD_RIGHT:
return KEY_XBUTTON_RIGHT;
}
return BUTTON_CODE_NONE;
}
AnalogCode_t ControllerAxisToAnalogCode( SDL_GameControllerAxis axis )
{
switch ( axis )
{
case SDL_CONTROLLER_AXIS_LEFTX:
return JOYSTICK_AXIS(0, JOY_AXIS_X);
case SDL_CONTROLLER_AXIS_LEFTY:
return JOYSTICK_AXIS(0, JOY_AXIS_Y);
case SDL_CONTROLLER_AXIS_RIGHTX:
return JOYSTICK_AXIS(0, JOY_AXIS_U);
case SDL_CONTROLLER_AXIS_RIGHTY:
return JOYSTICK_AXIS(0, JOY_AXIS_R);
case SDL_CONTROLLER_AXIS_TRIGGERRIGHT:
case SDL_CONTROLLER_AXIS_TRIGGERLEFT:
return JOYSTICK_AXIS(0, JOY_AXIS_Z);
}
return ANALOG_CODE_INVALID;
}

1025
inputsystem/joystick_osx.cpp Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,39 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#ifndef KEY_TRANSLATION_H
#define KEY_TRANSLATION_H
#ifdef _WIN32
#pragma once
#endif
#include "inputsystem/ButtonCode.h"
#include "inputsystem/AnalogCode.h"
// Call this to initialize the system
void ButtonCode_InitKeyTranslationTable();
// Convert from Windows scan codes to Button codes.
ButtonCode_t ButtonCode_ScanCodeToButtonCode( int lParam );
// Update scan codes for foreign keyboards
void ButtonCode_UpdateScanCodeLayout( );
// Convert from Windows virtual key codes to Button codes.
ButtonCode_t ButtonCode_VirtualKeyToButtonCode( int keyCode );
int ButtonCode_ButtonCodeToVirtualKey( ButtonCode_t code );
ButtonCode_t ButtonCode_XKeyToButtonCode( int nPort, int keyCode );
ButtonCode_t ButtonCode_SKeyToButtonCode( int nPort, int keyCode );
// Convert back + forth between ButtonCode/AnalogCode + strings
const char *ButtonCode_ButtonCodeToString( ButtonCode_t code, bool bXController );
const char *AnalogCode_AnalogCodeToString( AnalogCode_t code );
ButtonCode_t ButtonCode_StringToButtonCode( const char *pString, bool bXController );
AnalogCode_t AnalogCode_StringToAnalogCode( const char *pString );
#endif // KEY_TRANSLATION_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,66 @@
//================ Copyright (c) Valve Corporation. All Rights Reserved. ===========================
//
//
//
//==================================================================================================
#ifndef INCLUDED_MOVECONTROLLER_PS3_H
#define INCLUDED_MOVECONTROLLER_PS3_H
#include <vjobs_interface.h>
#include <cell/gem.h> // PS3 move controller lib
#include <mathlib/vector.h>
// Max number of supported move controllers
// Increasing this value increases the memory required by the GEM lib
#define MAX_PS3_MOVE_CONTROLLERS 1
class QAngle;
struct MoveControllerState
{
CellGemInfo m_CellGemInfo;
CellGemState m_aCellGemState[MAX_PS3_MOVE_CONTROLLERS];
int32 m_aStatus[MAX_PS3_MOVE_CONTROLLERS];
uint64 m_aStatusFlags[MAX_PS3_MOVE_CONTROLLERS];
Vector m_pos[MAX_PS3_MOVE_CONTROLLERS];
Quaternion m_quat[MAX_PS3_MOVE_CONTROLLERS];
float m_posX[MAX_PS3_MOVE_CONTROLLERS];
float m_posY[MAX_PS3_MOVE_CONTROLLERS];
int32 m_camStatus;
};
//--------------------------------------------------------------------------------------------------
// CMoveController
// Manages PS3 Move Controller
// Use of VJobInstance ensures init gets called after Vjobs SPURS init
//--------------------------------------------------------------------------------------------------
class CMoveController: public VJobInstance
{
public:
void Init();
void Shutdown();
void ReadState(MoveControllerState* pState);
void OnVjobsInit(); // gets called after m_pRoot was created and assigned
void OnVjobsShutdown(); // gets called before m_pRoot is about to be destructed and NULL'ed
// Disable/Enable for use debugging
// Stops/starts update thread
void Disable();
void Enable();
void InvalidateCalibration( void );
void StepMotionControllerCalibration( void );
void ResetMotionControllerScreenCalibration( void );
void Rumble( unsigned char rumbleVal );
bool m_bEnabled;
// Memory required by GEM lib
void* m_pGemMem;
int32 m_iSizeGemMem;
};
extern CMoveController* g_pMoveController;
#endif // INCLUDED_MOVECONTROLLER_PS3_H

138
inputsystem/novint.cpp Normal file
View File

@ -0,0 +1,138 @@
//===== Copyright <20> 1996-2005, Valve Corporation, All rights reserved. ======//
//
// Purpose:
//
//===========================================================================//
#include "inputsystem.h"
#include "key_translation.h"
#include "inputsystem/buttoncode.h"
#include "inputsystem/analogcode.h"
#include "tier1/convar.h"
typedef void*(*NovintGetIHaptics_t)(void);
typedef bool (*NovintAttemptHWND_t)(void *hWnd);
typedef void (*NovintDisableHWND_t)(void);
typedef void (*NovintPollDevices_t)(void);
typedef bool (*NovintButtonState_t)(int nDevice,
int &down,
int &pressed,
int &released);
typedef int (*NovintDeviceCount_t)();
typedef int (*NovintButtonCount_t)(int nDevice);
typedef bool (__cdecl *NovintMouseModeCallback_t) (void);
typedef void (*NovintInputActive_t)(bool bGameInput);
typedef __int64 (*NovintGetDeviceID_t)(int nDevice);
NovintGetIHaptics_t NovintGetIHaptics = NULL;
NovintAttemptHWND_t NovintAttemptHWND = NULL;
NovintDisableHWND_t NovintDisableHWND = NULL;
NovintPollDevices_t NovintPollDevices = NULL;
NovintButtonState_t NovintButtonState = NULL;
NovintDeviceCount_t NovintDeviceCount = NULL;
NovintButtonCount_t NovintButtonCount = NULL;
NovintInputActive_t NovintInputActive = NULL;
NovintGetDeviceID_t NovintGetDeviceID = NULL;
static CInputSystem *pNovintInputSystem = 0;
static bool bNovintPure = false;
bool __cdecl NovintDevicesInputMode(void)
{
if(pNovintInputSystem)
{
return !bNovintPure;
}
return false;
}
void *CInputSystem::GetHapticsInterfaceAddress(void)const
{
if( NovintGetIHaptics )
return NovintGetIHaptics();
return NULL;
}
void CInputSystem::AttachWindowToNovintDevices( void * hWnd )
{
if( NovintAttemptHWND )
NovintAttemptHWND( hWnd );
}
void CInputSystem::DetachWindowFromNovintDevices(void)
{
if( NovintDisableHWND )
NovintDisableHWND();
}
void CInputSystem::InitializeNovintDevices()
{
pNovintInputSystem = this;
// assume no novint devices
m_bNovintDevices = false;
m_nNovintDeviceCount = 0;
if(!m_pNovintDLL)
return;
NovintGetIHaptics = (NovintGetIHaptics_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintGetIHaptics" );
NovintAttemptHWND = (NovintAttemptHWND_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintAttemptHWND" );
NovintDisableHWND = (NovintDisableHWND_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintDisableHWND" );
NovintPollDevices = (NovintPollDevices_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintPollDevices" );
NovintButtonState = (NovintButtonState_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintButtonState" );
NovintDeviceCount = (NovintDeviceCount_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintDeviceCount" );
NovintButtonCount = (NovintButtonCount_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintButtonCount" );
NovintGetDeviceID = (NovintGetDeviceID_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintGetDeviceID" );
NovintInputActive = (NovintInputActive_t)GetProcAddress( (HMODULE)m_pNovintDLL, "NovintInputActive" );
m_nNovintDeviceCount = NovintDeviceCount();
if( m_nNovintDeviceCount > 0 )
m_bNovintDevices = true;
}
void CInputSystem::PollNovintDevices()
{
if( NovintPollDevices )
NovintPollDevices();
for ( int i = 0; i < m_nNovintDeviceCount; i++ )
{
UpdateNovintDeviceButtonState(i);
}
}
void CInputSystem::UpdateNovintDeviceButtonState(int nDevice)
{
int nDown;
int nPressed;
int nReleased;
if(NovintButtonState(nDevice, nDown, nPressed, nReleased))
{
for ( int i = 0; i < 4; i++ )
{
ButtonCode_t code = (ButtonCode_t)( NOVINT_FIRST + ( nDevice * 4 ) + i );
if( nPressed & (1 << i) )
{
PostButtonPressedEvent(IE_ButtonPressed, m_nLastSampleTick, code, KEY_NONE);
}
if( nReleased & (1 << i) )
{
PostButtonReleasedEvent(IE_ButtonReleased, m_nLastSampleTick, code, KEY_NONE);
}
}
}
}
void CInputSystem::SetNovintPure( bool bPure )
{
bNovintPure = bPure;
if(NovintInputActive)
NovintInputActive(bNovintPure);
}

118
inputsystem/posix_stubs.h Normal file
View File

@ -0,0 +1,118 @@
//================ Copyright (c) 1996-2009 Valve Corporation. All Rights Reserved. =================
//
//
//
//==================================================================================================
#ifndef POSIX_WIN32STUBS_H
#define POSIX_WIN32STUBS_H
#ifdef _WIN32
#pragma once
#endif
#include "tier0/basetypes.h"
#include "tier0/platform.h"
typedef int32 LRESULT;
typedef void* HWND;
typedef uint32 UINT;
typedef uintp WPARAM;
typedef uintp LPARAM;
typedef uint8 BYTE;
typedef int16 SHORT;
typedef void* WNDPROC;
typedef void* HANDLE;
//typedef char xKey_t;
#define XUSER_MAX_COUNT 2
#if defined( _OSX )
// [will] Added Xbox button constants for MacOSX
typedef enum
{
XK_NULL,
XK_BUTTON_UP,
XK_BUTTON_DOWN,
XK_BUTTON_LEFT,
XK_BUTTON_RIGHT,
XK_BUTTON_START,
XK_BUTTON_BACK,
XK_BUTTON_STICK1,
XK_BUTTON_STICK2,
XK_BUTTON_A,
XK_BUTTON_B,
XK_BUTTON_X,
XK_BUTTON_Y,
XK_BUTTON_LEFT_SHOULDER,
XK_BUTTON_RIGHT_SHOULDER,
XK_BUTTON_LTRIGGER,
XK_BUTTON_RTRIGGER,
XK_STICK1_UP,
XK_STICK1_DOWN,
XK_STICK1_LEFT,
XK_STICK1_RIGHT,
XK_STICK2_UP,
XK_STICK2_DOWN,
XK_STICK2_LEFT,
XK_STICK2_RIGHT,
XK_BUTTON_INACTIVE_START, // Special key that is passed through on disabled controllers
XK_BUTTON_FIREMODE_SELECTOR_1,
XK_BUTTON_FIREMODE_SELECTOR_2,
XK_BUTTON_FIREMODE_SELECTOR_3,
XK_BUTTON_RELOAD,
XK_BUTTON_TRIGGER,
XK_BUTTON_PUMP_ACTION,
XK_XBUTTON_ROLL_RIGHT,
XK_XBUTTON_ROLL_LEFT,
XK_MAX_KEYS,
} xKey_t;
#else
#define XK_MAX_KEYS 20
#endif // _OSX
typedef struct joyinfoex_tag
{
DWORD dwSize;
DWORD dwFlags;
DWORD dwXpos;
DWORD dwYpos;
DWORD dwZpos;
DWORD dwRpos;
DWORD dwUpos;
DWORD dwVpos;
DWORD dwButtons;
DWORD dwButtonNumber;
DWORD dwPOV;
DWORD dwReserved1;
DWORD dwReserved2;
} JOYINFOEX, *LPJOYINFOEX;
typedef struct _XINPUT_GAMEPAD
{
WORD wButtons;
BYTE bLeftTrigger;
BYTE bRightTrigger;
SHORT sThumbLX;
SHORT sThumbLY;
SHORT sThumbRX;
SHORT sThumbRY;
} XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;
typedef struct _XINPUT_STATE
{
DWORD dwPacketNumber;
XINPUT_GAMEPAD Gamepad;
} XINPUT_STATE, *PXINPUT_STATE;
typedef struct _XINPUT_VIBRATION
{
WORD wLeftMotorSpeed;
WORD wRightMotorSpeed;
} XINPUT_VIBRATION, *PXINPUT_VIBRATION;
#endif // POSIX_WIN32STUBS_H

View File

@ -0,0 +1,275 @@
//=========== Copyright Valve Corporation, All rights reserved. ===============//
//
// Purpose: Native Steam Controller Interface
//=============================================================================//
#include "inputsystem.h"
#include "key_translation.h"
#include "filesystem.h"
#include "steam/isteamcontroller.h"
#include "math.h"
#include "steam/steam_api.h"
// memdbgon must be the last include file in a .cpp file!!!
#include <tier0/memdbgon.h>
static CSteamAPIContext s_SteamAPIContext;
CSteamAPIContext *steamapicontext = &s_SteamAPIContext;
ConVar sc_joystick_map( "sc_joystick_map", "1", FCVAR_ARCHIVE, "How to map the analog joystick deadzone and extents 0 = Scaled Cross, 1 = Concentric Mapping to Square." );
bool CInputSystem::InitializeSteamControllers()
{
static bool s_bSteamControllerInitAttempted = false; // we only initialize SteamAPI once, prevent multiple calls
static bool s_bSteamControllerInitSucceeded = false; // cached result from first SteamController()->Init() call
if ( !s_bSteamControllerInitAttempted )
{
s_bSteamControllerInitAttempted = true;
SteamAPI_InitSafe();
s_SteamAPIContext.Init();
if( s_SteamAPIContext.SteamController() )
{
m_flLastSteamControllerInput = -FLT_MAX;
s_bSteamControllerInitSucceeded = steamapicontext->SteamController()->Init();
if ( s_bSteamControllerInitSucceeded )
{
DevMsg( "Successfully Initialized Steam Controller Configuration." );
}
else
{
DevMsg( "Failed to Initialize Steam Controller Configuration." );
}
m_nJoystickBaseline = m_nJoystickCount;
s_SteamAPIContext.SteamController()->ActivateActionSet( STEAM_CONTROLLER_HANDLE_ALL_CONTROLLERS, s_SteamAPIContext.SteamController()->GetActionSetHandle( "MenuControls" ) );
}
}
return s_bSteamControllerInitSucceeded;
}
struct SDigitalMenuAction
{
const char *strName;
ButtonCode_t buttonCode;
ControllerDigitalActionHandle_t handle;
bool bState;
bool bActive;
};
static SDigitalMenuAction g_DigitalMenuActions[] = {
{ "menu_left", KEY_XSTICK1_LEFT, 0, false, false },
{ "menu_right", KEY_XSTICK1_RIGHT, 0, false, false },
{ "menu_up", KEY_XSTICK1_UP, 0, false, false },
{ "menu_down", KEY_XSTICK1_DOWN, 0, false, false },
{ "menu_cancel", KEY_XBUTTON_B, 0, false, false },
{ "menu_select", KEY_XBUTTON_A, 0, false, false },
{ "menu_x", KEY_XBUTTON_X, 0, false, false },
{ "menu_y", KEY_XBUTTON_Y, 0, false, false },
{ "pause_menu", KEY_ESCAPE, 0, false, false }, // Command is actually in the FPS Controls game action set.
{ "vote_yes", KEY_F1, 0, false, false }, // Command is actually in the FPS Controls game action set.
{ "vote_no", KEY_F2, 0, false, false }, // Command is actually in the FPS Controls game action set.
};
static void InitDigitalMenuActions()
{
for ( int i = 0; i != ARRAYSIZE( g_DigitalMenuActions ); ++i )
{
g_DigitalMenuActions[i].handle = steamapicontext->SteamController()->GetDigitalActionHandle( g_DigitalMenuActions[i].strName );
}
}
static const char *g_pSteamControllerMode = "MenuControls";
bool CInputSystem::PollSteamControllers( void )
{
unsigned int unNumConnected = 0;
if ( InitializeSteamControllers() )
{
ISteamController& ctrl = *s_SteamAPIContext.SteamController();
ctrl.RunFrame();
ControllerHandle_t handles[MAX_STEAM_CONTROLLERS];
int nControllers = ctrl.GetConnectedControllers( handles );
SetInputDeviceConnected( INPUT_DEVICE_STEAM_CONTROLLER, nControllers > 0 );
if ( nControllers > 0 )
{
static bool s_bInitialized = false;
if ( s_bInitialized == false )
{
ctrl.ActivateActionSet( STEAM_CONTROLLER_HANDLE_ALL_CONTROLLERS, ctrl.GetActionSetHandle( g_pSteamControllerMode ) );
InitDigitalMenuActions();
s_bInitialized = true;
}
for ( int i = 0; i != ARRAYSIZE( g_DigitalMenuActions ); ++i )
{
SDigitalMenuAction& action = g_DigitalMenuActions[ i ];
bool bNewState = false;
bool bNewActive = false;
for ( uint64 j = 0; j < nControllers; ++j )
{
ControllerDigitalActionData_t data = steamapicontext->SteamController()->GetDigitalActionData( handles[ j ], action.handle );
if ( data.bActive )
{
bNewActive = true;
}
if ( data.bState && data.bActive )
{
bNewState = true;
}
}
bNewActive = bNewActive && ( action.bActive || !bNewState );
if ( action.bActive && bNewState != action.bState )
{
if ( bNewState )
{
SetCurrentInputDevice( INPUT_DEVICE_STEAM_CONTROLLER );
PostButtonPressedEvent( IE_ButtonPressed, m_nLastSampleTick, action.buttonCode, action.buttonCode );
}
else
{
PostButtonReleasedEvent( IE_ButtonReleased, m_nLastSampleTick, action.buttonCode, action.buttonCode );
}
}
action.bState = bNewState;
action.bActive = bNewActive;
}
}
}
m_unNumSteamControllerConnected = unNumConnected;
return unNumConnected > 0;
}
bool CInputSystem::IsSteamControllerActive() const
{
if ( steamapicontext && steamapicontext->SteamController() )
{
uint64 nControllerHandles[STEAM_CONTROLLER_MAX_COUNT];
return steamapicontext->SteamController()->GetConnectedControllers( nControllerHandles ) > 0;
}
return false;
}
static const int g_nControllerModeMaxStackSize = 16;
static const void *g_pControllerModeObjectStack[g_nControllerModeMaxStackSize];
static const char *g_pControllerModeStack[g_nControllerModeMaxStackSize];
static int g_nControllerModeStackSize = 0;
static const char *g_pBaseControllerMode = "MenuControls";
static const char *GetCurrentSteamControllerMode()
{
if ( g_nControllerModeStackSize == 0 )
{
return g_pBaseControllerMode;
}
return g_pControllerModeStack[ g_nControllerModeStackSize-1 ];
}
void CInputSystem::SetSteamControllerMode( const char *pSteamControllerMode, const void *obj )
{
if ( !s_SteamAPIContext.SteamController() )
{
return;
}
if ( obj == NULL )
{
g_pBaseControllerMode = pSteamControllerMode;
}
else
{
int nIndex = 0;
while ( nIndex < g_nControllerModeStackSize && g_pControllerModeObjectStack[ nIndex ] != obj )
{
++nIndex;
}
Assert( nIndex < g_nControllerModeMaxStackSize );
if ( nIndex == g_nControllerModeMaxStackSize )
{
return;
}
if ( pSteamControllerMode != NULL )
{
g_pControllerModeObjectStack[ nIndex ] = obj;
g_pControllerModeStack[ nIndex ] = pSteamControllerMode;
if ( nIndex == g_nControllerModeStackSize )
{
++g_nControllerModeStackSize;
}
}
else if ( nIndex < g_nControllerModeStackSize )
{
for ( int i = nIndex+1; i < g_nControllerModeStackSize; ++i )
{
g_pControllerModeObjectStack[ i - 1 ] = g_pControllerModeObjectStack[ i ];
g_pControllerModeStack[ i - 1 ] = g_pControllerModeStack[ i ];
}
--g_nControllerModeStackSize;
}
}
const char *pNewMode = GetCurrentSteamControllerMode();
if ( V_strcmp( pNewMode, g_pSteamControllerMode ) == 0 )
{
return;
}
g_pSteamControllerMode = pNewMode;
s_SteamAPIContext.SteamController()->ActivateActionSet( STEAM_CONTROLLER_HANDLE_ALL_CONTROLLERS, s_SteamAPIContext.SteamController()->GetActionSetHandle( pNewMode ) );
}
CON_COMMAND( steam_controller_status, "Spew report of steam controller status" )
{
if ( !s_SteamAPIContext.SteamController() )
{
Msg( "Steam controller API is unavailable" );
return;
}
ControllerDigitalActionHandle_t handleAction = s_SteamAPIContext.SteamController()->GetActionSetHandle( GetCurrentSteamControllerMode() );
Msg( "Steam controller mode: %s (%d)\n", GetCurrentSteamControllerMode(), (int)handleAction );
ControllerHandle_t handles[MAX_STEAM_CONTROLLERS];
int nControllers = s_SteamAPIContext.SteamController()->GetConnectedControllers( handles );
Msg( "Controllers connected: %d\n", nControllers );
for ( int i = 0; i < nControllers; ++i )
{
Msg( " Controller %d, action set = %d\n", i, (int)s_SteamAPIContext.SteamController()->GetCurrentActionSet( handles[ i ] ) );
for ( int j = 0; j < STEAM_CONTROLLER_MAX_DIGITAL_ACTIONS; ++j )
{
ControllerDigitalActionData_t data = s_SteamAPIContext.SteamController()->GetDigitalActionData( handles[ i ], (int)j );
if ( data.bState && data.bActive )
{
Msg( " active action: %d\n", j );
}
}
}
}

2
inputsystem/vsi.nul Normal file
View File

@ -0,0 +1,2 @@
SN Visual Studio Integration
IMPORTANT: Do not remove the custom build step for this file

2236
inputsystem/xcontroller.cpp Normal file

File diff suppressed because it is too large Load Diff