00001 #ifndef INPUT_HANDLER_H 00002 #define INPUT_HANDLER_H 1 00003 00004 /* 00005 * This is a simple class to handle special input devices. Update() 00006 * will be called during the input update; the derived class should 00007 * send appropriate events to InputHandler. 00008 * 00009 * Note that, if the underlying device is capable of it, you're free to 00010 * start a blocking thread; just store inputs in your class and send them 00011 * off in a batch on the next Update. This gets much more accurate timestamps; 00012 * we get events more quickly and timestamp them, instead of having a rough timing 00013 * granularity due to the framerate. 00014 * 00015 * Send input events for a specific type of device. Only one driver 00016 * for a given set of InputDevice types should be loaded for a given 00017 * arch. For example, any number of drivers may produce DEVICE_PUMPn 00018 * events, but only one may be loaded at a time. (This will be inconvenient 00019 * if, for example, we have two completely distinct methods of getting 00020 * input for the same device; we have no method to allocate device numbers. 00021 * We don't need this now; I'll write it if it becomes needed.) 00022 */ 00023 #include "RageInputDevice.h" // for InputDevice 00024 00025 class InputHandler 00026 { 00027 RageTimer m_LastUpdate; 00028 00029 public: 00030 virtual ~InputHandler() { } 00031 virtual void Update(float fDeltaTime) { } 00032 virtual void GetDevicesAndDescriptions(vector<InputDevice>& vDevicesOut, vector<CString>& vDescriptionsOut) = 0; 00033 00034 /* In Windows, some devices need to be recreated if we recreate our main window. 00035 * Override this if you need to do that. */ 00036 virtual void WindowReset() { } 00037 00038 protected: 00039 /* Convenience function: Call this to queue a received event. This may be called 00040 * in a thread. 00041 * 00042 * Important detail: If the timestamp, di.ts, is zero, then it is assumed that 00043 * this is not a threaded event handler. In that case, input is being polled, 00044 * and the actual time the button was pressed may be any time since the last 00045 * poll. In this case, ButtonPressed will pretend the button was pressed at 00046 * the midpoint since the last update, which will smooth out the error. 00047 * 00048 * Note that timestamps are set to the current time by default, so for this to 00049 * happen, you need to explicitly call di.ts.SetZero(). 00050 * 00051 * If the timestamp is set, it'll be left alone. */ 00052 void ButtonPressed( DeviceInput di, bool Down ); 00053 00054 /* Call this at the end of polling input. */ 00055 void UpdateTimer(); 00056 }; 00057 00058 #endif 00059 00060 /* 00061 * (c) 2003-2004 Glenn Maynard 00062 * All rights reserved. 00063 * 00064 * Permission is hereby granted, free of charge, to any person obtaining a 00065 * copy of this software and associated documentation files (the 00066 * "Software"), to deal in the Software without restriction, including 00067 * without limitation the rights to use, copy, modify, merge, publish, 00068 * distribute, and/or sell copies of the Software, and to permit persons to 00069 * whom the Software is furnished to do so, provided that the above 00070 * copyright notice(s) and this permission notice appear in all copies of 00071 * the Software and that both the above copyright notice(s) and this 00072 * permission notice appear in supporting documentation. 00073 * 00074 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00075 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00076 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00077 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00078 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00079 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00080 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00081 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00082 * PERFORMANCE OF THIS SOFTWARE. 00083 */