From 98628c554b301caa05de887028ee115119a89362 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sat, 12 Apr 2003 02:21:50 +0000 Subject: [PATCH] (this is all handled in InputHandler_SDL) --- stepmania/src/RageInput.cpp | 113 +++--------------------------------- stepmania/src/RageInput.h | 6 -- 2 files changed, 8 insertions(+), 111 deletions(-) diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index bfec381b02..298fd1f516 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -3,7 +3,7 @@ ----------------------------------------------------------------------------- File: RageInput.h - Desc: Wrapper for DirectInput. Generates InputEvents. + This file just starts up input drivers, which generate InputEvents. Copyright (c) 2001-2002 by the person(s) listed below. All rights reserved. Chris Danford @@ -11,77 +11,30 @@ */ #include "RageInput.h" -#include "SDL_utils.h" #include "RageLog.h" -#include "InputFilter.h" +#include "RageException.h" #include "arch/InputHandler/InputHandler.h" RageInput* INPUTMAN = NULL; // globally accessable input device - - RageInput::RageInput() { LOG->Trace( "RageInput::RageInput()" ); - SDL_InitSubSystem( SDL_INIT_JOYSTICK ); - - - // - // Init keyboard - // - SDL_EnableKeyRepeat( 0, 0 ); - - /* If we use key events, we can do this to get Unicode values - * in the key struct, which (with a little more work) will make - * us work on international keyboards: */ - // SDL_EnableUNICODE( 1 ); - - // - // Init joysticks - // - int iNumJoySticks = min( SDL_NumJoysticks(), NUM_JOYSTICKS ); - LOG->Info( "Found %d joysticks", iNumJoySticks ); - for( int i=0; iInfo(" %d: '%s' Error opening: %s", - i, SDL_JoystickName(i), SDL_GetError()); - continue; - } - - LOG->Info( " %d: '%s' axes: %d, hats: %d, buttons: %d", - i, - SDL_JoystickName(i), - SDL_JoystickNumAxes(pJoystick), - SDL_JoystickNumHats(pJoystick), - SDL_JoystickNumButtons(pJoystick) ); - - /* For some weird reason, we won't get any joystick events at all - * if we don't keep the joystick open. (Why? The joystick event - * API is completely separate from the SDL_Joystick polling API ...) */ - Joysticks.push_back(pJoystick); - } - - SDL_JoystickEventState( SDL_ENABLE ); - /* Init optional devices. */ MakeInputHandlers(Devices); + + /* If no input devices are loaded, the user won't be able to input anything. + * That should never happen. */ + if(Devices.size() == 0) + RageException::Throw("No input devices were loaded. This shouldn't happen; please file a bug."); } RageInput::~RageInput() { /* Delete optional devices. */ - unsigned i; - for(i = 0; i < Devices.size(); ++i) + for(unsigned i = 0; i < Devices.size(); ++i) delete Devices[i]; - - for(i = 0; i < Joysticks.size(); ++i) - SDL_JoystickClose(Joysticks[i]); - - SDL_QuitSubSystem( SDL_INIT_JOYSTICK ); } void RageInput::Update( float fDeltaTime ) @@ -91,53 +44,3 @@ void RageInput::Update( float fDeltaTime ) Devices[i]->Update(fDeltaTime); } -bool RageInput::FeedSDLEvent(const SDL_Event &event) -{ - switch(event.type) - { - case SDL_KEYDOWN: - case SDL_KEYUP: - { - DeviceInput di(DEVICE_KEYBOARD, event.key.keysym.sym); - INPUTFILTER->ButtonPressed(di, event.key.state == SDL_PRESSED); - return true; - } - - case SDL_JOYBUTTONDOWN: - case SDL_JOYBUTTONUP: - { - InputDevice i = InputDevice(DEVICE_JOY1 + event.jbutton.which); - JoystickButton Button = JoystickButton(JOY_1 + event.jbutton.button); - if(Button >= NUM_JOYSTICK_BUTTONS) - { - LOG->Warn("Ignored joystick event (button too high)"); - return true; - } - DeviceInput di(i, Button); - INPUTFILTER->ButtonPressed(di, event.jbutton.state == SDL_PRESSED); - return true; - } - - case SDL_JOYAXISMOTION: - { - InputDevice i = InputDevice(DEVICE_JOY1 + event.jaxis.which); - JoystickButton neg = (JoystickButton)(JOY_LEFT+2*event.jaxis.axis); - JoystickButton pos = (JoystickButton)(JOY_RIGHT+2*event.jaxis.axis); - INPUTFILTER->ButtonPressed(DeviceInput(i, neg), event.jaxis.value < -16000); - INPUTFILTER->ButtonPressed(DeviceInput(i, pos), event.jaxis.value > +16000); - return true; - } - - case SDL_JOYHATMOTION: - { - InputDevice i = InputDevice(DEVICE_JOY1 + event.jhat.which); - INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_UP), !!(event.jhat.value & SDL_HAT_UP)); - INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_DOWN), !!(event.jhat.value & SDL_HAT_DOWN)); - INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_LEFT), !!(event.jhat.value & SDL_HAT_LEFT)); - INPUTFILTER->ButtonPressed(DeviceInput(i, JOY_HAT_RIGHT), !!(event.jhat.value & SDL_HAT_RIGHT)); - return true; - } - } - return false; -} - diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index 2ff4db21eb..c46b7fa150 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -12,21 +12,15 @@ #include "SDL_utils.h" #include "arch/arch.h" -struct _SDL_Joystick; -typedef struct _SDL_Joystick SDL_Joystick; - class RageInput { vector Devices; - vector Joysticks; - public: RageInput(); ~RageInput(); void Update( float fDeltaTime ); - bool FeedSDLEvent(const SDL_Event &event); }; extern RageInput* INPUTMAN; // global and accessable from anywhere in our program