From bc833631e2762290ad1be0f661b21ce07ead524e Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 16 Feb 2003 02:25:22 +0000 Subject: [PATCH] add InputHandler abstraction --- stepmania/src/RageInput.cpp | 21 ++++++++----------- stepmania/src/RageInput.h | 7 ++----- .../src/arch/InputHandler/InputHandler.h | 4 ++-- .../InputHandler/InputHandler_Win32_Pump.cpp | 14 ++++++------- .../InputHandler/InputHandler_Win32_Pump.h | 8 +++---- stepmania/src/arch/arch.cpp | 7 +++++++ stepmania/src/arch/arch.h | 5 ++++- stepmania/src/arch/arch_Win32.h | 2 ++ 8 files changed, 37 insertions(+), 31 deletions(-) diff --git a/stepmania/src/RageInput.cpp b/stepmania/src/RageInput.cpp index 57ce4d7a1a..1106e14dac 100644 --- a/stepmania/src/RageInput.cpp +++ b/stepmania/src/RageInput.cpp @@ -14,6 +14,7 @@ #include "SDL_utils.h" #include "RageLog.h" #include "InputFilter.h" +#include "arch/InputHandler/InputHandler.h" RageInput* INPUTMAN = NULL; // globally accessable input device @@ -54,28 +55,24 @@ RageInput::RageInput() } SDL_JoystickEventState( SDL_ENABLE ); - // - // Init pump - // - m_Pump = new PumpPadDevice; + /* Init optional devices. */ + MakeInputHandlers(Devices); } RageInput::~RageInput() { - // - // De-init pump - // - delete m_Pump; + /* Delete optional devices. */ + for(unsigned i = 0; i < Devices.size(); ++i) + delete Devices[i]; SDL_QuitSubSystem( SDL_INIT_JOYSTICK ); } void RageInput::Update( float fDeltaTime ) { - // - // Update Pump - // - m_Pump->Update(); + /* Update optional devices. */ + for(unsigned i = 0; i < Devices.size(); ++i) + Devices[i]->Update(fDeltaTime); } bool RageInput::FeedSDLEvent(const SDL_Event &event) diff --git a/stepmania/src/RageInput.h b/stepmania/src/RageInput.h index 1e72ceeeee..0d86f2e173 100644 --- a/stepmania/src/RageInput.h +++ b/stepmania/src/RageInput.h @@ -10,13 +10,11 @@ #include "RageInputDevice.h" #include "SDL_utils.h" - -#include "arch/InputHandler/InputHandler_Win32_Pump.h" +#include "arch/arch.h" class RageInput { - /* Structure for reading Pump pads: */ - PumpPadDevice *m_Pump; + vector Devices; public: RageInput(); @@ -28,7 +26,6 @@ public: extern RageInput* INPUTMAN; // global and accessable from anywhere in our program - #endif /* * Copyright (c) 2001-2003 by the person(s) listed below. All rights reserved. diff --git a/stepmania/src/arch/InputHandler/InputHandler.h b/stepmania/src/arch/InputHandler/InputHandler.h index c9f25a0c36..742b0b1a01 100644 --- a/stepmania/src/arch/InputHandler/InputHandler.h +++ b/stepmania/src/arch/InputHandler/InputHandler.h @@ -15,11 +15,11 @@ * be used by RageInputFeeders. */ -class RageInputFeeder +class InputHandler { public: virtual void Update(float fDeltaTime) { } - virtual ~RageInputFeeder() { } + virtual ~InputHandler() { } }; #endif diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp index 68d7c25aa4..07acc04706 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.cpp @@ -12,7 +12,7 @@ #pragma comment(lib, "ddk/setupapi.lib") #pragma comment(lib, "ddk/hid.lib") -struct PumpPadDevice::dev_t { +struct InputHandler_Win32_Pump::dev_t { dev_t(); ~dev_t(); HANDLE h; @@ -112,20 +112,20 @@ HANDLE USB::OpenUSB (int VID, int PID, int num) } -PumpPadDevice::dev_t::dev_t() +InputHandler_Win32_Pump::dev_t::dev_t() { ZeroMemory( &ov, sizeof(ov) ); pending=false; h = INVALID_HANDLE_VALUE; } -PumpPadDevice::dev_t::~dev_t() +InputHandler_Win32_Pump::dev_t::~dev_t() { if(h != INVALID_HANDLE_VALUE) CloseHandle(h); } -PumpPadDevice::PumpPadDevice() +InputHandler_Win32_Pump::InputHandler_Win32_Pump() { const int pump_usb_vid = 0x0d2f, pump_usb_pid = 0x0001; @@ -139,12 +139,12 @@ PumpPadDevice::PumpPadDevice() } } -PumpPadDevice::~PumpPadDevice() +InputHandler_Win32_Pump::~InputHandler_Win32_Pump() { delete[] dev; } -int PumpPadDevice::dev_t::GetPadEvent() +int InputHandler_Win32_Pump::dev_t::GetPadEvent() { int ret; @@ -179,7 +179,7 @@ int PumpPadDevice::dev_t::GetPadEvent() return buf; } -void PumpPadDevice::Update() +void InputHandler_Win32_Pump::Update(float fDeltaTime) { static const int bits[] = { /* P1 */ (1<<9), (1<<12), (1<<13), (1<<11), (1<<10), diff --git a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h index 39fccc5ac4..a236d8a68f 100644 --- a/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h +++ b/stepmania/src/arch/InputHandler/InputHandler_Win32_Pump.h @@ -3,16 +3,16 @@ #include "InputHandler.h" -class PumpPadDevice: RageInputFeeder +class InputHandler_Win32_Pump: public InputHandler { struct dev_t; /* MYOB */ dev_t *dev; public: - void Update(); - PumpPadDevice(); - ~PumpPadDevice(); + void Update(float fDeltaTime); + InputHandler_Win32_Pump(); + ~InputHandler_Win32_Pump(); }; diff --git a/stepmania/src/arch/arch.cpp b/stepmania/src/arch/arch.cpp index 5fac8d7bab..8ac0392a7e 100644 --- a/stepmania/src/arch/arch.cpp +++ b/stepmania/src/arch/arch.cpp @@ -21,6 +21,13 @@ LoadingWindow *MakeLoadingWindow() { return new ARCH_LOADING_WINDOW; } ErrorDialog *MakeErrorDialog() { return new ARCH_ERROR_DIALOG; } ArchHooks *MakeArchHooks() { return new ARCH_HOOKS; } +void MakeInputHandlers(vector &Add) +{ +#if defined(WIN32) + Add.push_back(new InputHandler_Win32_Pump); +#endif +} + /* Err, this is ugly--breaks arch encapsulation. Hmm. */ RageSoundDriver *MakeRageSoundDriver(CString drivers) { diff --git a/stepmania/src/arch/arch.h b/stepmania/src/arch/arch.h index e42c9556ea..c63823e979 100644 --- a/stepmania/src/arch/arch.h +++ b/stepmania/src/arch/arch.h @@ -6,12 +6,15 @@ class ErrorDialog; class LoadingWindow; class RageSoundDriver; class ArchHooks; +class InputHandler; ErrorDialog *MakeErrorDialog(); LoadingWindow *MakeLoadingWindow(); -RageSoundDriver *MakeRageSoundDriver(CString drivers); ArchHooks *MakeArchHooks(); +void MakeInputHandlers(vector &Add); +RageSoundDriver *MakeRageSoundDriver(CString drivers); + /* Define the default list of sound drivers for each arch. */ #if defined(WIN32) #define DEFAULT_SOUND_DRIVER_LIST "DirectSound,DirectSound-sw,WaveOut" diff --git a/stepmania/src/arch/arch_Win32.h b/stepmania/src/arch/arch_Win32.h index 15de1293c2..87b126df09 100644 --- a/stepmania/src/arch/arch_Win32.h +++ b/stepmania/src/arch/arch_Win32.h @@ -6,6 +6,8 @@ #include "ErrorDialog/ErrorDialog_Win32.h" #include "ArchHooks/ArchHooks_Win32.h" +#include "InputHandler/InputHandler_Win32_Pump.h" + #include "Sound/RageSoundDriver_DSound.h" #include "Sound/RageSoundDriver_DSound_Software.h" #include "Sound/RageSoundDriver_WaveOut.h"