00001 /* InputFilter - Checks RageInput and generates a list of InputEvents, representing button presses, releases, and repeats. */ 00002 00003 #ifndef INPUTFILTER_H 00004 #define INPUTFILTER_H 00005 00006 #include "RageInputDevice.h" 00007 00008 enum InputEventType 00009 { 00010 /* The device was just pressed. */ 00011 IET_FIRST_PRESS, 00012 00013 /* The device is auto-repeating. These events are guaranteed to be sent only between 00014 * IET_FIRST_PRESS and IET_RELEASE pairs. */ 00015 IET_SLOW_REPEAT, 00016 IET_FAST_REPEAT, 00017 00018 /* The device is no longer pressed. Exactly one IET_RELEASE event will be sent 00019 * for each IET_FIRST_PRESS. */ 00020 IET_RELEASE, 00021 00022 /* The depression level of a button has changed. Read di.level to find the new 00023 * value. This can be sent outside of a IET_FIRST_PRESS/IET_RELEASE pair, since 00024 * a button/axis can have a non-zero level (eg. outside the axis dead zone) without 00025 * being high enough to count as a press. */ 00026 IET_LEVEL_CHANGED 00027 }; 00028 00029 struct InputEvent : public DeviceInput 00030 { 00031 InputEvent() { type=IET_FIRST_PRESS; }; 00032 InputEvent( InputDevice d, int b, InputEventType t ): DeviceInput(d, b) { type=t; }; 00033 InputEvent( DeviceInput di, InputEventType t ): DeviceInput(di) { type=t; }; 00034 00035 InputEventType type; 00036 }; 00037 00038 typedef vector<InputEvent> InputEventArray; 00039 00040 class RageMutex; 00041 class InputFilter 00042 { 00043 struct ButtonState 00044 { 00045 bool m_BeingHeld; 00046 float m_fSecsHeld; 00047 float m_Level, m_LastLevel; 00048 }; 00049 ButtonState m_ButtonState[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS]; 00050 00051 InputEventArray queue; 00052 RageMutex *queuemutex; 00053 00054 public: 00055 void ButtonPressed( DeviceInput di, bool Down ); 00056 void ResetDevice( InputDevice dev ); 00057 00058 InputFilter(); 00059 ~InputFilter(); 00060 void Reset(); 00061 void Update(float fDeltaTime); 00062 00063 void SetRepeatRate( float fSlowDelay, float fSlowRate, float fFastDelay, float fFastRate ); 00064 void ResetRepeatRate(); 00065 void ResetKeyRepeat( DeviceInput di ); 00066 00067 bool IsBeingPressed( DeviceInput di ); 00068 float GetSecsHeld( DeviceInput di ); 00069 00070 void GetInputEvents( InputEventArray &array ); 00071 }; 00072 00073 00074 extern InputFilter* INPUTFILTER; // global and accessable from anywhere in our program 00075 00076 00077 #endif 00078 00079 /* 00080 * (c) 2001-2004 Chris Danford 00081 * All rights reserved. 00082 * 00083 * Permission is hereby granted, free of charge, to any person obtaining a 00084 * copy of this software and associated documentation files (the 00085 * "Software"), to deal in the Software without restriction, including 00086 * without limitation the rights to use, copy, modify, merge, publish, 00087 * distribute, and/or sell copies of the Software, and to permit persons to 00088 * whom the Software is furnished to do so, provided that the above 00089 * copyright notice(s) and this permission notice appear in all copies of 00090 * the Software and that both the above copyright notice(s) and this 00091 * permission notice appear in supporting documentation. 00092 * 00093 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00094 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00095 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00096 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00097 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00098 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00099 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00100 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00101 * PERFORMANCE OF THIS SOFTWARE. 00102 */