Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

InputMapper.h

Go to the documentation of this file.
00001 /* InputMapper - Holds user-chosen input preferences and saves it between sessions. */ 00002 00003 #ifndef INPUTMAPPER_H 00004 #define INPUTMAPPER_H 00005 00006 #include "RageInputDevice.h" 00007 #include "GameInput.h" 00008 #include "MenuInput.h" 00009 #include "StyleInput.h" 00010 #include "GameConstantsAndTypes.h" 00011 00012 00013 00014 const int NUM_GAME_TO_DEVICE_SLOTS = 3; // three device inputs may map to one game input 00015 00016 00017 class InputMapper 00018 { 00019 public: 00020 InputMapper(); 00021 ~InputMapper(); 00022 00023 void ReadMappingsFromDisk(); 00024 void SaveMappingsToDisk(); 00025 00026 void ClearAllMappings(); 00027 00028 void SetInputMap( DeviceInput DeviceI, GameInput GameI, int iSlotIndex ); 00029 void ClearFromInputMap( DeviceInput DeviceI ); 00030 void ClearFromInputMap( GameInput GameI, int iSlotIndex ); 00031 00032 void AddDefaultMappingsForCurrentGameIfUnmapped(); 00033 void AutoMapJoysticksForCurrentGame(); 00034 00035 bool IsMapped( DeviceInput DeviceI ); 00036 bool IsMapped( GameInput GameI ); 00037 00038 bool DeviceToGame( DeviceInput DeviceI, GameInput& GameI ); // return true if there is a mapping from device to pad 00039 bool GameToDevice( GameInput GameI, int iSoltNum, DeviceInput& DeviceI ); // return true if there is a mapping from pad to device 00040 00041 void GameToStyle( GameInput GameI, StyleInput &StyleI ); 00042 void StyleToGame( StyleInput StyleI, GameInput &GameI ); 00043 00044 void GameToMenu( GameInput GameI, MenuInput &MenuI ); 00045 void MenuToGame( MenuInput MenuI, GameInput GameIout[4] ); 00046 00047 float GetSecsHeld( GameInput GameI ); 00048 float GetSecsHeld( MenuInput MenuI ); 00049 float GetSecsHeld( StyleInput StyleI ); 00050 00051 bool IsButtonDown( GameInput GameI ); 00052 bool IsButtonDown( MenuInput MenuI ); 00053 bool IsButtonDown( StyleInput StyleI ); 00054 00055 void ResetKeyRepeat( GameInput GameI ); 00056 void ResetKeyRepeat( MenuInput MenuI ); 00057 void ResetKeyRepeat( StyleInput StyleI ); 00058 00059 struct Mapping { 00060 bool IsEndMarker() const { return iSlotIndex==-1; } 00061 00062 int iSlotIndex; // -1 == end marker 00063 int deviceButton; 00064 GameButton gb; 00065 /* If this is true, this is an auxilliary mapping assigned to the second 00066 * player. If two of the same device are found, and the device has secondary 00067 * entries, the later entries take precedence. This way, if a Pump pad is 00068 * found, it'll map P1 to the primary pad and P2 to the secondary pad. 00069 * (We can't tell if a slave pad is actually there.) Then, if a second primary 00070 * is found (DEVICE_PUMP2), 2P will be mapped to it. 00071 * 00072 * This isn't well-tested; I only have one Pump pad. */ 00073 bool SecondController; 00074 }; 00075 00076 void ApplyMapping( const Mapping *maps, GameController gc, InputDevice device ); 00077 00078 protected: 00079 // all the DeviceInputs that map to a GameInput 00080 DeviceInput m_GItoDI[MAX_GAME_CONTROLLERS][MAX_GAME_BUTTONS][NUM_GAME_TO_DEVICE_SLOTS]; 00081 00082 // lookup for efficiency from a DeviceInput to a GameInput 00083 // This is repopulated every time m_PItoDI changes by calling UpdateTempDItoPI(). 00084 GameInput m_tempDItoGI[NUM_INPUT_DEVICES][MAX_DEVICE_BUTTONS]; 00085 void UpdateTempDItoGI(); 00086 }; 00087 00088 00089 extern InputMapper* INPUTMAPPER; // global and accessable from anywhere in our program 00090 00091 00092 #endif 00093 00094 /* 00095 * (c) 2001-2003 Chris Danford 00096 * All rights reserved. 00097 * 00098 * Permission is hereby granted, free of charge, to any person obtaining a 00099 * copy of this software and associated documentation files (the 00100 * "Software"), to deal in the Software without restriction, including 00101 * without limitation the rights to use, copy, modify, merge, publish, 00102 * distribute, and/or sell copies of the Software, and to permit persons to 00103 * whom the Software is furnished to do so, provided that the above 00104 * copyright notice(s) and this permission notice appear in all copies of 00105 * the Software and that both the above copyright notice(s) and this 00106 * permission notice appear in supporting documentation. 00107 * 00108 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00109 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00110 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF 00111 * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS 00112 * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT 00113 * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS 00114 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 00115 * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00116 * PERFORMANCE OF THIS SOFTWARE. 00117 */

Generated on Thu Jan 27 20:57:22 2005 for StepMania by doxygen 1.3.7