Changeset 1789
- Timestamp:
- Aug 23, 2012, 11:47:46 AM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/input/input.cpp
r1785 r1789 62 62 63 63 /* 64 * ButtonSetting class 65 */ 66 67 int ButtonSetting::GetActionSettingIdx(ACTION_TYPE SearchAction) 68 { 69 for (int i = 0; i < m_associated_action_list.Count(); i++) 70 if (ACTION_CMP(m_associated_action_list[i].m_action, SearchAction)) 71 return i; 72 return -1; 73 } 74 75 /* 64 76 * InputTracker class 65 77 */ … … 69 81 m_gamegroup = GAMEGROUP_BEFORE; 70 82 83 for (int i = 0; i < Key::K_LAST * 2; ++i) 84 m_input_status << 0; 85 71 86 Ticker::Ref(this); 87 } 88 89 //Internal 90 int InputTracker::GetButtonSettingIdx(Key Button) 91 { 92 for (int i = 0; i < m_input_assocation_list.Count(); i++) 93 if (m_input_assocation_list[i].m_raw_button == Button) 94 return i; 95 return -1; 96 } 97 98 //----- 99 int InputTracker::GetCurrentButtonStatus(Key Button) 100 { 101 if (Button < m_input_status.Count()) 102 return m_input_status[Button]; 103 return 0; 104 } 105 106 //----- 107 int InputTracker::GetPreviousButtonStatus(Key Button) 108 { 109 if (Button < m_input_status.Count()) 110 return m_input_status[Button + Key::K_LAST]; 111 return 0; 72 112 } 73 113 … … 75 115 void InputTracker::UpdateActionStatus(float seconds) 76 116 { 77 for (int i = 0; i < m_input_assocation_list.Count(); i++) 78 { 79 ButtonSetting &CurIT = m_input_assocation_list[i]; 80 81 CurIT.m_previous_status = CurIT.m_current_status; 82 CurIT.m_current_status = Input::GetButtonState(CurIT.m_raw_button_id); 117 #if defined USE_SDL 118 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION >= 3 119 Uint8 *keystate = SDL_GetKeyboardState(NULL); 120 #else 121 Uint8 *keystate = SDL_GetKeyState(NULL); 122 #endif 123 //SOOOoooo ugly. 124 for (int i = 0; i < Key::K_LAST; ++i) 125 { 126 m_input_status[i + Key::K_LAST] = m_input_status[i]; 127 m_input_status[i] = keystate[i]; 128 } 129 #endif 130 131 for (int i = 0; i < m_input_assocation_list.Count(); i++) 132 { 133 ButtonSetting &CurIT = m_input_assocation_list[i]; 83 134 84 135 for (int j = 0; j < CurIT.m_associated_action_list.Count(); j++) … … 86 137 ActionSetting &CurAS = CurIT.m_associated_action_list[j]; 87 138 88 if (CurAS.BufferedSince <= CurAS.BufferingTime) 89 CurAS.BufferedSince += seconds; 90 91 if (CurIT.m_current_status && CurAS.BufferingTime >= .0f) 92 CurAS.BufferedSince = .0f; 139 if (CurAS.m_buffered_since <= CurAS.m_buffering_time) 140 CurAS.m_buffered_since += seconds; 141 142 if (GetCurrentButtonStatus(CurIT.m_raw_button) && 143 CurAS.m_buffering_time >= .0f) 144 CurAS.m_buffered_since = .0f; 93 145 } 94 146 } 95 96 147 } 97 148 98 149 //Helps link a software input Action-Id to an hardware input Button-Id. 99 void InputTracker::LinkAction IdToButtonId(int ActionId, int ButtonId)100 { 101 int ITIdx = GetButtonSettingIdx(Button Id);150 void InputTracker::LinkActionToKey(ACTION_TYPE Action, Key Button) 151 { 152 int ITIdx = GetButtonSettingIdx(Button); 102 153 if (ITIdx == -1) 103 154 { 104 155 ITIdx = m_input_assocation_list.Count(); 105 m_input_assocation_list << ButtonSetting(Button Id);156 m_input_assocation_list << ButtonSetting(Button); 106 157 } 107 158 108 159 ButtonSetting &CurIT = m_input_assocation_list[ITIdx]; 109 160 110 int ASIdx = CurIT.GetActionSettingIdx(Action Id);161 int ASIdx = CurIT.GetActionSettingIdx(Action); 111 162 if (ASIdx == -1) 112 163 { 113 164 ASIdx = CurIT.m_associated_action_list.Count(); 114 CurIT.m_associated_action_list << ActionSetting(Action Id);165 CurIT.m_associated_action_list << ActionSetting(Action); 115 166 } 116 167 } 117 168 118 169 //Helps unlink a software input Action-Id to an hardware input Button-Id. 119 void InputTracker::UnlinkAction Id(int ActionId)120 { 121 for (int i = 0; i < m_input_assocation_list.Count(); i++) 122 { 123 ButtonSetting &CurIT = m_input_assocation_list[i]; 124 int ASIdx = CurIT.GetActionSettingIdx(Action Id);170 void InputTracker::UnlinkAction(ACTION_TYPE Action) 171 { 172 for (int i = 0; i < m_input_assocation_list.Count(); i++) 173 { 174 ButtonSetting &CurIT = m_input_assocation_list[i]; 175 int ASIdx = CurIT.GetActionSettingIdx(Action); 125 176 if (ASIdx != -1) 126 177 CurIT.m_associated_action_list.Remove(ASIdx); … … 129 180 130 181 //Returns the current status of a given action 131 int InputTracker::Get ActionStatus(int ActionId)132 { 133 for (int i = 0; i < m_input_assocation_list.Count(); i++) 134 { 135 ButtonSetting &CurIT = m_input_assocation_list[i]; 136 int ASIdx = CurIT.GetActionSettingIdx(Action Id);182 int InputTracker::GetStatus(ACTION_TYPE Action) 183 { 184 for (int i = 0; i < m_input_assocation_list.Count(); i++) 185 { 186 ButtonSetting &CurIT = m_input_assocation_list[i]; 187 int ASIdx = CurIT.GetActionSettingIdx(Action); 137 188 if (ASIdx != -1) 138 189 { 139 190 ActionSetting &CurAS = CurIT.m_associated_action_list[ASIdx]; 140 191 141 if (CurAS. BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime)192 if (CurAS.m_buffering_time >= .0f && CurAS.m_buffered_since <= CurAS.m_buffering_time) 142 193 return 1; 143 194 return 0; … … 147 198 } 148 199 149 //Returns TRUE if action status w henfrom Active to Inactive this frame150 bool InputTracker::Was ActionJustReleased(int ActionId)151 { 152 for (int i = 0; i < m_input_assocation_list.Count(); i++) 153 { 154 ButtonSetting &CurIT = m_input_assocation_list[i]; 155 int ASIdx = CurIT.GetActionSettingIdx(Action Id);200 //Returns TRUE if action status went from Active to Inactive this frame 201 bool InputTracker::WasReleased(ACTION_TYPE Action) 202 { 203 for (int i = 0; i < m_input_assocation_list.Count(); i++) 204 { 205 ButtonSetting &CurIT = m_input_assocation_list[i]; 206 int ASIdx = CurIT.GetActionSettingIdx(Action); 156 207 if (ASIdx != -1) 157 208 { 158 if (!CurIT.m_current_status && CurIT.m_previous_status) 209 210 if (GetPreviousButtonStatus(CurIT.m_raw_button) && 211 !GetCurrentButtonStatus(CurIT.m_raw_button)) 212 return true; 213 return false; 214 } 215 } 216 return false; 217 } 218 219 //Returns TRUE if action status went from Inactive to Active this frame 220 bool InputTracker::WasPressed(ACTION_TYPE Action) 221 { 222 for (int i = 0; i < m_input_assocation_list.Count(); i++) 223 { 224 ButtonSetting &CurIT = m_input_assocation_list[i]; 225 int ASIdx = CurIT.GetActionSettingIdx(Action); 226 if (ASIdx != -1) 227 { 228 if (!GetPreviousButtonStatus(CurIT.m_raw_button) && 229 GetCurrentButtonStatus(CurIT.m_raw_button)) 230 return true; 231 return false; 232 } 233 } 234 return false; 235 } 236 237 //Returns the current status of a given action 238 int InputTracker::GetStatus(Key Button) 239 { 240 for (int i = 0; i < m_input_assocation_list.Count(); i++) 241 { 242 ButtonSetting &CurIT = m_input_assocation_list[i]; 243 244 if (Button == CurIT.m_raw_button) 245 return GetCurrentButtonStatus(CurIT.m_raw_button); 246 } 247 return 0; 248 } 249 250 //Returns TRUE if action status went from Active to Inactive this frame 251 bool InputTracker::WasReleased(Key Button) 252 { 253 for (int i = 0; i < m_input_assocation_list.Count(); i++) 254 { 255 ButtonSetting &CurIT = m_input_assocation_list[i]; 256 257 if (Button == CurIT.m_raw_button) 258 { 259 if (GetPreviousButtonStatus(CurIT.m_raw_button) && 260 !GetCurrentButtonStatus(CurIT.m_raw_button)) 261 return true; 262 return false; 263 } 264 } 265 return false; 266 } 267 268 //Returns TRUE if action status went from Inactive to Active this frame 269 bool InputTracker::WasPressed(Key Button) 270 { 271 for (int i = 0; i < m_input_assocation_list.Count(); i++) 272 { 273 ButtonSetting &CurIT = m_input_assocation_list[i]; 274 275 if (Button == CurIT.m_raw_button) 276 { 277 if (!GetPreviousButtonStatus(CurIT.m_raw_button) && 278 GetCurrentButtonStatus(CurIT.m_raw_button)) 159 279 return true; 160 280 return false; … … 220 340 221 341 //Helps link a software input Action-Id to an hardware input Button-Id. 222 void Input::LinkAction IdToButtonId(int ActionId, int ButtonId)223 { 224 if (CheckInputTrackerInit()) 225 Input::m_input_tracker->LinkAction IdToButtonId(ActionId, ButtonId);342 void Input::LinkActionToKey(ACTION_TYPE Action, struct Key Button) 343 { 344 if (CheckInputTrackerInit()) 345 Input::m_input_tracker->LinkActionToKey(Action, Button); 226 346 } 227 347 228 348 //Helps unlink a software input Action-Id to an hardware input Button-Id. 229 void Input::UnlinkAction Id(int ActionId)230 { 231 if (CheckInputTrackerInit()) 232 Input::m_input_tracker->UnlinkAction Id(ActionId);349 void Input::UnlinkAction(ACTION_TYPE Action) 350 { 351 if (CheckInputTrackerInit()) 352 Input::m_input_tracker->UnlinkAction(Action); 233 353 } 234 354 235 355 //Returns the current status of a given action 236 int Input::Get ActionStatus(int ActionId)237 { 238 if (CheckInputTrackerInit()) 239 return Input::m_input_tracker->Get ActionStatus(ActionId);356 int Input::GetStatus(ACTION_TYPE Action) 357 { 358 if (CheckInputTrackerInit()) 359 return Input::m_input_tracker->GetStatus(Action); 240 360 return 0; 241 361 } 242 362 243 363 //Returns TRUE if action status when from Active to Inactive this frame 244 bool Input::WasActionJustReleased(int ActionId) 245 { 246 if (CheckInputTrackerInit()) 247 return Input::m_input_tracker->WasActionJustReleased(ActionId); 364 bool Input::WasPressed(ACTION_TYPE Action) 365 { 366 if (CheckInputTrackerInit()) 367 return Input::m_input_tracker->WasPressed(Action); 368 return false; 369 } 370 371 //Returns TRUE if action status when from Active to Inactive this frame 372 bool Input::WasReleased(ACTION_TYPE Action) 373 { 374 if (CheckInputTrackerInit()) 375 return Input::m_input_tracker->WasReleased(Action); 376 return false; 377 } 378 379 //Returns the current status of a given action 380 int Input::GetStatus(Key Button) 381 { 382 if (CheckInputTrackerInit()) 383 return Input::m_input_tracker->GetStatus(Button); 384 return 0; 385 } 386 387 //Returns TRUE if action status when from Active to Inactive this frame 388 bool Input::WasPressed(Key Button) 389 { 390 if (CheckInputTrackerInit()) 391 return Input::m_input_tracker->WasPressed(Button); 392 return false; 393 } 394 395 //Returns TRUE if action status when from Active to Inactive this frame 396 bool Input::WasReleased(Key Button) 397 { 398 if (CheckInputTrackerInit()) 399 return Input::m_input_tracker->WasReleased(Button); 248 400 return false; 249 401 } -
trunk/src/input/input.h
r1785 r1789 18 18 19 19 #include <cstring> 20 #include <string.h> 20 21 #include "core.h" 21 22 #include "lol/math/vector.h" … … 25 26 { 26 27 28 #define ACTION_TYPE std::string 29 #define ACTION_CMP(A, B) (A.compare(B) == 0) 30 27 31 class WorldEntity; 28 32 29 //FULL Key reap-off of the SDLK enum 30 typedef enum { 31 /** @name ASCII mapped keysyms 32 * The keyboard syms have been cleverly chosen to map to ASCII 33 */ 34 /*@{*/ 35 LOLK_UNKNOWN = 0, 36 LOLK_FIRST = 0, 37 LOLK_BACKSPACE = 8, 38 LOLK_TAB = 9, 39 LOLK_CLEAR = 12, 40 LOLK_RETURN = 13, 41 LOLK_PAUSE = 19, 42 LOLK_ESCAPE = 27, 43 LOLK_SPACE = 32, 44 LOLK_EXCLAIM = 33, 45 LOLK_QUOTEDBL = 34, 46 LOLK_HASH = 35, 47 LOLK_DOLLAR = 36, 48 LOLK_AMPERSAND = 38, 49 LOLK_QUOTE = 39, 50 LOLK_LEFTPAREN = 40, 51 LOLK_RIGHTPAREN = 41, 52 LOLK_ASTERISK = 42, 53 LOLK_PLUS = 43, 54 LOLK_COMMA = 44, 55 LOLK_MINUS = 45, 56 LOLK_PERIOD = 46, 57 LOLK_SLASH = 47, 58 LOLK_0 = 48, 59 LOLK_1 = 49, 60 LOLK_2 = 50, 61 LOLK_3 = 51, 62 LOLK_4 = 52, 63 LOLK_5 = 53, 64 LOLK_6 = 54, 65 LOLK_7 = 55, 66 LOLK_8 = 56, 67 LOLK_9 = 57, 68 LOLK_COLON = 58, 69 LOLK_SEMICOLON = 59, 70 LOLK_LESS = 60, 71 LOLK_EQUALS = 61, 72 LOLK_GREATER = 62, 73 LOLK_QUESTION = 63, 74 LOLK_AT = 64, 75 /* 76 Skip uppercase letters 77 */ 78 LOLK_LEFTBRACKET = 91, 79 LOLK_BACKSLASH = 92, 80 LOLK_RIGHTBRACKET = 93, 81 LOLK_CARET = 94, 82 LOLK_UNDERSCORE = 95, 83 LOLK_BACKQUOTE = 96, 84 LOLK_a = 97, 85 LOLK_b = 98, 86 LOLK_c = 99, 87 LOLK_d = 100, 88 LOLK_e = 101, 89 LOLK_f = 102, 90 LOLK_g = 103, 91 LOLK_h = 104, 92 LOLK_i = 105, 93 LOLK_j = 106, 94 LOLK_k = 107, 95 LOLK_l = 108, 96 LOLK_m = 109, 97 LOLK_n = 110, 98 LOLK_o = 111, 99 LOLK_p = 112, 100 LOLK_q = 113, 101 LOLK_r = 114, 102 LOLK_s = 115, 103 LOLK_t = 116, 104 LOLK_u = 117, 105 LOLK_v = 118, 106 LOLK_w = 119, 107 LOLK_x = 120, 108 LOLK_y = 121, 109 LOLK_z = 122, 110 LOLK_DELETE = 127, 111 /* End of ASCII mapped keysyms */ 112 /*@}*/ 113 114 /** @name International keyboard syms */ 115 /*@{*/ 116 LOLK_WORLD_0 = 160, /* 0xA0 */ 117 LOLK_WORLD_1 = 161, 118 LOLK_WORLD_2 = 162, 119 LOLK_WORLD_3 = 163, 120 LOLK_WORLD_4 = 164, 121 LOLK_WORLD_5 = 165, 122 LOLK_WORLD_6 = 166, 123 LOLK_WORLD_7 = 167, 124 LOLK_WORLD_8 = 168, 125 LOLK_WORLD_9 = 169, 126 LOLK_WORLD_10 = 170, 127 LOLK_WORLD_11 = 171, 128 LOLK_WORLD_12 = 172, 129 LOLK_WORLD_13 = 173, 130 LOLK_WORLD_14 = 174, 131 LOLK_WORLD_15 = 175, 132 LOLK_WORLD_16 = 176, 133 LOLK_WORLD_17 = 177, 134 LOLK_WORLD_18 = 178, 135 LOLK_WORLD_19 = 179, 136 LOLK_WORLD_20 = 180, 137 LOLK_WORLD_21 = 181, 138 LOLK_WORLD_22 = 182, 139 LOLK_WORLD_23 = 183, 140 LOLK_WORLD_24 = 184, 141 LOLK_WORLD_25 = 185, 142 LOLK_WORLD_26 = 186, 143 LOLK_WORLD_27 = 187, 144 LOLK_WORLD_28 = 188, 145 LOLK_WORLD_29 = 189, 146 LOLK_WORLD_30 = 190, 147 LOLK_WORLD_31 = 191, 148 LOLK_WORLD_32 = 192, 149 LOLK_WORLD_33 = 193, 150 LOLK_WORLD_34 = 194, 151 LOLK_WORLD_35 = 195, 152 LOLK_WORLD_36 = 196, 153 LOLK_WORLD_37 = 197, 154 LOLK_WORLD_38 = 198, 155 LOLK_WORLD_39 = 199, 156 LOLK_WORLD_40 = 200, 157 LOLK_WORLD_41 = 201, 158 LOLK_WORLD_42 = 202, 159 LOLK_WORLD_43 = 203, 160 LOLK_WORLD_44 = 204, 161 LOLK_WORLD_45 = 205, 162 LOLK_WORLD_46 = 206, 163 LOLK_WORLD_47 = 207, 164 LOLK_WORLD_48 = 208, 165 LOLK_WORLD_49 = 209, 166 LOLK_WORLD_50 = 210, 167 LOLK_WORLD_51 = 211, 168 LOLK_WORLD_52 = 212, 169 LOLK_WORLD_53 = 213, 170 LOLK_WORLD_54 = 214, 171 LOLK_WORLD_55 = 215, 172 LOLK_WORLD_56 = 216, 173 LOLK_WORLD_57 = 217, 174 LOLK_WORLD_58 = 218, 175 LOLK_WORLD_59 = 219, 176 LOLK_WORLD_60 = 220, 177 LOLK_WORLD_61 = 221, 178 LOLK_WORLD_62 = 222, 179 LOLK_WORLD_63 = 223, 180 LOLK_WORLD_64 = 224, 181 LOLK_WORLD_65 = 225, 182 LOLK_WORLD_66 = 226, 183 LOLK_WORLD_67 = 227, 184 LOLK_WORLD_68 = 228, 185 LOLK_WORLD_69 = 229, 186 LOLK_WORLD_70 = 230, 187 LOLK_WORLD_71 = 231, 188 LOLK_WORLD_72 = 232, 189 LOLK_WORLD_73 = 233, 190 LOLK_WORLD_74 = 234, 191 LOLK_WORLD_75 = 235, 192 LOLK_WORLD_76 = 236, 193 LOLK_WORLD_77 = 237, 194 LOLK_WORLD_78 = 238, 195 LOLK_WORLD_79 = 239, 196 LOLK_WORLD_80 = 240, 197 LOLK_WORLD_81 = 241, 198 LOLK_WORLD_82 = 242, 199 LOLK_WORLD_83 = 243, 200 LOLK_WORLD_84 = 244, 201 LOLK_WORLD_85 = 245, 202 LOLK_WORLD_86 = 246, 203 LOLK_WORLD_87 = 247, 204 LOLK_WORLD_88 = 248, 205 LOLK_WORLD_89 = 249, 206 LOLK_WORLD_90 = 250, 207 LOLK_WORLD_91 = 251, 208 LOLK_WORLD_92 = 252, 209 LOLK_WORLD_93 = 253, 210 LOLK_WORLD_94 = 254, 211 LOLK_WORLD_95 = 255, /* 0xFF */ 212 /*@}*/ 213 214 /** @name Numeric keypad */ 215 /*@{*/ 216 LOLK_KP0 = 256, 217 LOLK_KP1 = 257, 218 LOLK_KP2 = 258, 219 LOLK_KP3 = 259, 220 LOLK_KP4 = 260, 221 LOLK_KP5 = 261, 222 LOLK_KP6 = 262, 223 LOLK_KP7 = 263, 224 LOLK_KP8 = 264, 225 LOLK_KP9 = 265, 226 LOLK_KP_PERIOD = 266, 227 LOLK_KP_DIVIDE = 267, 228 LOLK_KP_MULTIPLY = 268, 229 LOLK_KP_MINUS = 269, 230 LOLK_KP_PLUS = 270, 231 LOLK_KP_ENTER = 271, 232 LOLK_KP_EQUALS = 272, 233 /*@}*/ 234 235 /** @name Arrows + Home/End pad */ 236 /*@{*/ 237 LOLK_UP = 273, 238 LOLK_DOWN = 274, 239 LOLK_RIGHT = 275, 240 LOLK_LEFT = 276, 241 LOLK_INSERT = 277, 242 LOLK_HOME = 278, 243 LOLK_END = 279, 244 LOLK_PAGEUP = 280, 245 LOLK_PAGEDOWN = 281, 246 /*@}*/ 247 248 /** @name Function keys */ 249 /*@{*/ 250 LOLK_F1 = 282, 251 LOLK_F2 = 283, 252 LOLK_F3 = 284, 253 LOLK_F4 = 285, 254 LOLK_F5 = 286, 255 LOLK_F6 = 287, 256 LOLK_F7 = 288, 257 LOLK_F8 = 289, 258 LOLK_F9 = 290, 259 LOLK_F10 = 291, 260 LOLK_F11 = 292, 261 LOLK_F12 = 293, 262 LOLK_F13 = 294, 263 LOLK_F14 = 295, 264 LOLK_F15 = 296, 265 /*@}*/ 266 267 /** @name Key state modifier keys */ 268 /*@{*/ 269 LOLK_NUMLOCK = 300, 270 LOLK_CAPSLOCK = 301, 271 LOLK_SCROLLOCK = 302, 272 LOLK_RSHIFT = 303, 273 LOLK_LSHIFT = 304, 274 LOLK_RCTRL = 305, 275 LOLK_LCTRL = 306, 276 LOLK_RALT = 307, 277 LOLK_LALT = 308, 278 LOLK_RMETA = 309, 279 LOLK_LMETA = 310, 280 LOLK_LSUPER = 311, /**< Left "Windows" key */ 281 LOLK_RSUPER = 312, /**< Right "Windows" key */ 282 LOLK_MODE = 313, /**< "Alt Gr" key */ 283 LOLK_COMPOSE = 314, /**< Multi-key compose key */ 284 /*@}*/ 285 286 /** @name Miscellaneous function keys */ 287 /*@{*/ 288 LOLK_HELP = 315, 289 LOLK_PRINT = 316, 290 LOLK_SYSREQ = 317, 291 LOLK_BREAK = 318, 292 LOLK_MENU = 319, 293 LOLK_POWER = 320, /**< Power Macintosh power key */ 294 LOLK_EURO = 321, /**< Some european keyboards */ 295 LOLK_UNDO = 322, /**< Atari keyboard has Undo */ 296 /*@}*/ 297 298 /* Add any other keys here */ 299 300 LOLK_LAST 301 } LOLKey; 302 303 /** Enumeration of valid key mods (possibly OR'd together) */ 304 typedef enum { 305 LOLKMOD_NONE = 0x0000, 306 LOLKMOD_LSHIFT= 0x0001, 307 LOLKMOD_RSHIFT= 0x0002, 308 LOLKMOD_LCTRL = 0x0040, 309 LOLKMOD_RCTRL = 0x0080, 310 LOLKMOD_LALT = 0x0100, 311 LOLKMOD_RALT = 0x0200, 312 LOLKMOD_LMETA = 0x0400, 313 LOLKMOD_RMETA = 0x0800, 314 LOLKMOD_NUM = 0x1000, 315 LOLKMOD_CAPS = 0x2000, 316 LOLKMOD_MODE = 0x4000, 317 LOLKMOD_RESERVED = 0x8000 318 } LOLKeyMod; 319 320 #define LOLKMOD_CTRL (LOLKMOD_LCTRL|LOLKMOD_RCTRL) 321 #define LOLKMOD_SHIFT (LOLKMOD_LSHIFT|LOLKMOD_RSHIFT) 322 #define LOLKMOD_ALT (LOLKMOD_LALT|LOLKMOD_RALT) 323 #define LOLKMOD_META (LOLKMOD_LMETA|LOLKMOD_RMETA) 33 //FULL Key rip-off of the SDLK enum 34 struct Key 35 { 36 enum Value 37 { 38 /** @name ASCII mapped keysyms 39 * The keyboard syms have been cleverly chosen to map to ASCII 40 */ 41 /*@{*/ 42 K_UNKNOWN = 0, 43 K_FIRST = 0, 44 K_BACKSPACE = 8, 45 K_TAB = 9, 46 K_CLEAR = 12, 47 K_RETURN = 13, 48 K_PAUSE = 19, 49 K_ESCAPE = 27, 50 K_SPACE = 32, 51 K_EXCLAIM = 33, 52 K_QUOTEDBL = 34, 53 K_HASH = 35, 54 K_DOLLAR = 36, 55 K_AMPERSAND = 38, 56 K_QUOTE = 39, 57 K_LEFTPAREN = 40, 58 K_RIGHTPAREN = 41, 59 K_ASTERISK = 42, 60 K_PLUS = 43, 61 K_COMMA = 44, 62 K_MINUS = 45, 63 K_PERIOD = 46, 64 K_SLASH = 47, 65 K_0 = 48, 66 K_1 = 49, 67 K_2 = 50, 68 K_3 = 51, 69 K_4 = 52, 70 K_5 = 53, 71 K_6 = 54, 72 K_7 = 55, 73 K_8 = 56, 74 K_9 = 57, 75 K_COLON = 58, 76 K_SEMICOLON = 59, 77 K_LESS = 60, 78 K_EQUALS = 61, 79 K_GREATER = 62, 80 K_QUESTION = 63, 81 K_AT = 64, 82 /* 83 Skip uppercase letters 84 */ 85 K_LEFTBRACKET = 91, 86 K_BACKSLASH = 92, 87 K_RIGHTBRACKET = 93, 88 K_CARET = 94, 89 K_UNDERSCORE = 95, 90 K_BACKQUOTE = 96, 91 K_a = 97, 92 K_b = 98, 93 K_c = 99, 94 K_d = 100, 95 K_e = 101, 96 K_f = 102, 97 K_g = 103, 98 K_h = 104, 99 K_i = 105, 100 K_j = 106, 101 K_k = 107, 102 K_l = 108, 103 K_m = 109, 104 K_n = 110, 105 K_o = 111, 106 K_p = 112, 107 K_q = 113, 108 K_r = 114, 109 K_s = 115, 110 K_t = 116, 111 K_u = 117, 112 K_v = 118, 113 K_w = 119, 114 K_x = 120, 115 K_y = 121, 116 K_z = 122, 117 K_DELETE = 127, 118 /* End of ASCII mapped keysyms */ 119 /*@}*/ 120 121 /** @name International keyboard syms */ 122 /*@{*/ 123 K_WORLD_0 = 160, /* 0xA0 */ 124 K_WORLD_1 = 161, 125 K_WORLD_2 = 162, 126 K_WORLD_3 = 163, 127 K_WORLD_4 = 164, 128 K_WORLD_5 = 165, 129 K_WORLD_6 = 166, 130 K_WORLD_7 = 167, 131 K_WORLD_8 = 168, 132 K_WORLD_9 = 169, 133 K_WORLD_10 = 170, 134 K_WORLD_11 = 171, 135 K_WORLD_12 = 172, 136 K_WORLD_13 = 173, 137 K_WORLD_14 = 174, 138 K_WORLD_15 = 175, 139 K_WORLD_16 = 176, 140 K_WORLD_17 = 177, 141 K_WORLD_18 = 178, 142 K_WORLD_19 = 179, 143 K_WORLD_20 = 180, 144 K_WORLD_21 = 181, 145 K_WORLD_22 = 182, 146 K_WORLD_23 = 183, 147 K_WORLD_24 = 184, 148 K_WORLD_25 = 185, 149 K_WORLD_26 = 186, 150 K_WORLD_27 = 187, 151 K_WORLD_28 = 188, 152 K_WORLD_29 = 189, 153 K_WORLD_30 = 190, 154 K_WORLD_31 = 191, 155 K_WORLD_32 = 192, 156 K_WORLD_33 = 193, 157 K_WORLD_34 = 194, 158 K_WORLD_35 = 195, 159 K_WORLD_36 = 196, 160 K_WORLD_37 = 197, 161 K_WORLD_38 = 198, 162 K_WORLD_39 = 199, 163 K_WORLD_40 = 200, 164 K_WORLD_41 = 201, 165 K_WORLD_42 = 202, 166 K_WORLD_43 = 203, 167 K_WORLD_44 = 204, 168 K_WORLD_45 = 205, 169 K_WORLD_46 = 206, 170 K_WORLD_47 = 207, 171 K_WORLD_48 = 208, 172 K_WORLD_49 = 209, 173 K_WORLD_50 = 210, 174 K_WORLD_51 = 211, 175 K_WORLD_52 = 212, 176 K_WORLD_53 = 213, 177 K_WORLD_54 = 214, 178 K_WORLD_55 = 215, 179 K_WORLD_56 = 216, 180 K_WORLD_57 = 217, 181 K_WORLD_58 = 218, 182 K_WORLD_59 = 219, 183 K_WORLD_60 = 220, 184 K_WORLD_61 = 221, 185 K_WORLD_62 = 222, 186 K_WORLD_63 = 223, 187 K_WORLD_64 = 224, 188 K_WORLD_65 = 225, 189 K_WORLD_66 = 226, 190 K_WORLD_67 = 227, 191 K_WORLD_68 = 228, 192 K_WORLD_69 = 229, 193 K_WORLD_70 = 230, 194 K_WORLD_71 = 231, 195 K_WORLD_72 = 232, 196 K_WORLD_73 = 233, 197 K_WORLD_74 = 234, 198 K_WORLD_75 = 235, 199 K_WORLD_76 = 236, 200 K_WORLD_77 = 237, 201 K_WORLD_78 = 238, 202 K_WORLD_79 = 239, 203 K_WORLD_80 = 240, 204 K_WORLD_81 = 241, 205 K_WORLD_82 = 242, 206 K_WORLD_83 = 243, 207 K_WORLD_84 = 244, 208 K_WORLD_85 = 245, 209 K_WORLD_86 = 246, 210 K_WORLD_87 = 247, 211 K_WORLD_88 = 248, 212 K_WORLD_89 = 249, 213 K_WORLD_90 = 250, 214 K_WORLD_91 = 251, 215 K_WORLD_92 = 252, 216 K_WORLD_93 = 253, 217 K_WORLD_94 = 254, 218 K_WORLD_95 = 255, /* 0xFF */ 219 /*@}*/ 220 221 /** @name Numeric keypad */ 222 /*@{*/ 223 K_KP0 = 256, 224 K_KP1 = 257, 225 K_KP2 = 258, 226 K_KP3 = 259, 227 K_KP4 = 260, 228 K_KP5 = 261, 229 K_KP6 = 262, 230 K_KP7 = 263, 231 K_KP8 = 264, 232 K_KP9 = 265, 233 K_KP_PERIOD = 266, 234 K_KP_DIVIDE = 267, 235 K_KP_MULTIPLY = 268, 236 K_KP_MINUS = 269, 237 K_KP_PLUS = 270, 238 K_KP_ENTER = 271, 239 K_KP_EQUALS = 272, 240 /*@}*/ 241 242 /** @name Arrows + Home/End pad */ 243 /*@{*/ 244 K_UP = 273, 245 K_DOWN = 274, 246 K_RIGHT = 275, 247 K_LEFT = 276, 248 K_INSERT = 277, 249 K_HOME = 278, 250 K_END = 279, 251 K_PAGEUP = 280, 252 K_PAGEDOWN = 281, 253 /*@}*/ 254 255 /** @name Function keys */ 256 /*@{*/ 257 K_F1 = 282, 258 K_F2 = 283, 259 K_F3 = 284, 260 K_F4 = 285, 261 K_F5 = 286, 262 K_F6 = 287, 263 K_F7 = 288, 264 K_F8 = 289, 265 K_F9 = 290, 266 K_F10 = 291, 267 K_F11 = 292, 268 K_F12 = 293, 269 K_F13 = 294, 270 K_F14 = 295, 271 K_F15 = 296, 272 /*@}*/ 273 274 /** @name Key state modifier keys */ 275 /*@{*/ 276 K_NUMLOCK = 300, 277 K_CAPSLOCK = 301, 278 K_SCROLLOCK = 302, 279 K_RSHIFT = 303, 280 K_LSHIFT = 304, 281 K_RCTRL = 305, 282 K_LCTRL = 306, 283 K_RALT = 307, 284 K_LALT = 308, 285 K_RMETA = 309, 286 K_LMETA = 310, 287 K_LSUPER = 311, /**< Left "Windows" key */ 288 K_RSUPER = 312, /**< Right "Windows" key */ 289 K_MODE = 313, /**< "Alt Gr" key */ 290 K_COMPOSE = 314, /**< Multi-key compose key */ 291 /*@}*/ 292 293 /** @name Miscellaneous function keys */ 294 /*@{*/ 295 K_HELP = 315, 296 K_PRINT = 316, 297 K_SYSREQ = 317, 298 K_BREAK = 318, 299 K_MENU = 319, 300 K_POWER = 320, /**< Power Macintosh power key */ 301 K_EURO = 321, /**< Some european keyboards */ 302 K_UNDO = 322, /**< Atari keyboard has Undo */ 303 /*@}*/ 304 305 /* Add any other keys here */ 306 307 K_LAST 308 309 } 310 m_value; 311 312 //BH : Removed KMod from main enum, because I don't have any idea about handling them correctly for now. 313 /* 314 //Enumeration of valid key mods (possibly OR'd together) 315 KM_NONE = 0x0000, 316 KM_LSHIFT = 0x0001, 317 KM_RSHIFT = 0x0002, 318 KM_LCTRL = 0x0040, 319 KM_RCTRL = 0x0080, 320 KM_LALT = 0x0100, 321 KM_RALT = 0x0200, 322 KM_LMETA = 0x0400, 323 KM_RMETA = 0x0800, 324 KM_NUM = 0x1000, 325 KM_CAPS = 0x2000, 326 KM_MODE = 0x4000, 327 328 KM_RESERVED = 0x8000, 329 330 //Left/Right independent key mods definition 331 KM_CTRL = (KM_LCTRL|KM_RCTRL), 332 KM_SHIFT = (KM_LSHIFT|KM_RSHIFT), 333 KM_ALT = (KM_LALT|KM_RALT), 334 KM_META = (KM_LMETA|KM_RMETA), 335 */ 336 337 inline Key(Value v) { m_value = v; } 338 inline operator Value() { return m_value; } 339 inline bool operator==(const Key& CompareButton) { return m_value == CompareButton.m_value; } 340 }; 324 341 325 342 struct ActionSetting 326 343 { 327 int ActionId;328 float BufferingTime;329 float BufferedSince;330 331 ActionSetting( int NewActionId)332 {333 m emset(this, 0, sizeof(ActionSetting));334 ActionId = NewActionId;335 }344 ACTION_TYPE m_action; 345 float m_buffering_time; 346 float m_buffered_since; 347 348 ActionSetting(ACTION_TYPE NewAction) : 349 m_action(NewAction), 350 m_buffering_time(.0f), 351 m_buffered_since(.0f) 352 { } 336 353 }; 337 354 338 355 struct ButtonSetting 339 356 { 340 int m_raw_button_id; 341 int m_current_status; 342 int m_previous_status; 357 Key m_raw_button; 343 358 Array<ActionSetting> m_associated_action_list; 344 359 345 ButtonSetting(int NewRawButtonId) 346 { 347 memset(this, 0, sizeof(ButtonSetting)); 348 m_raw_button_id = NewRawButtonId; 349 } 350 int GetActionSettingIdx(int ActionId) 351 { 352 for (int i = 0; i < m_associated_action_list.Count(); i++) 353 if (m_associated_action_list[i].ActionId == ActionId) 354 return i; 355 return -1; 356 } 360 ButtonSetting(Key NewRawButton) 361 : m_raw_button(NewRawButton) { } 362 int GetActionSettingIdx(ACTION_TYPE SearchAction); 357 363 }; 358 364 … … 366 372 367 373 private: 374 Array<Uint8> m_input_status; 368 375 Array<ButtonSetting> m_input_assocation_list; 369 376 370 int GetButtonSettingIdx(int ButtonId) 371 { 372 for (int i = 0; i < m_input_assocation_list.Count(); i++) 373 if (m_input_assocation_list[i].m_raw_button_id == ButtonId) 374 return i; 375 return -1; 376 } 377 378 void UpdateActionStatus(float seconds); 377 int GetButtonSettingIdx(struct Key Button); 378 int GetCurrentButtonStatus(struct Key Button); 379 int GetPreviousButtonStatus(struct Key Button); 380 void UpdateActionStatus(float seconds); 379 381 380 382 protected: … … 384 386 } 385 387 386 void LinkActionIdToButtonId(int ActionId, int ButtonId); 387 void UnlinkActionId(int ActionId); 388 int GetActionStatus(int ActionId); 389 bool WasActionJustReleased(int ActionId); 388 void LinkActionToKey(ACTION_TYPE Action, struct Key Button); 389 void UnlinkAction(ACTION_TYPE Action); 390 int GetStatus(ACTION_TYPE Action); 391 bool WasPressed(ACTION_TYPE Action); 392 bool WasReleased(ACTION_TYPE Action); 393 394 //You should probably use the Action System 395 int GetStatus(Key Button); 396 bool WasPressed(Key Button); 397 bool WasReleased(Key Button); 390 398 }; 391 399 … … 414 422 415 423 /* Action management */ 416 static void LinkActionIdToButtonId(int ActionId, int ButtonId); 417 static void UnlinkActionId(int ActionId); 418 static int GetActionStatus(int ActionId); 419 static bool WasActionJustReleased(int ActionId); 424 static void LinkActionToKey(ACTION_TYPE Action, struct Key Button); 425 static void UnlinkAction(ACTION_TYPE Action); 426 static int GetStatus(ACTION_TYPE Action); 427 static bool WasPressed(ACTION_TYPE Action); 428 static bool WasReleased(ACTION_TYPE Action); 429 430 /* Raw Button management. You should use actions. */ 431 static int GetStatus(Key Button); 432 static bool WasPressed(Key Button); 433 static bool WasReleased(Key Button); 420 434 421 435 /* Entities can subscribe to events */ -
trunk/test/BtPhysTest.cpp
r1785 r1789 57 57 #define USE_CHARACTER 1 58 58 59 enum eInputAction 60 { 61 IPT_MOVE_FORWARD, 62 IPT_MOVE_BACKWARD, 63 IPT_MOVE_STRAFE_LEFT, 64 IPT_MOVE_STRAFE_RIGHT, 65 IPT_MOVE_JUMP, 66 }; 59 #define IPT_MOVE_FORWARD "Move_Forward" 60 #define IPT_MOVE_BACKWARD "Move_Backward" 61 #define IPT_MOVE_STRAFE_LEFT "Strafe_Left" 62 #define IPT_MOVE_STRAFE_RIGHT "Strafe_right" 63 #define IPT_MOVE_JUMP "Move_Jump" 67 64 68 65 BtPhysTest::BtPhysTest(bool editor) … … 173 170 174 171 175 Input::LinkAction IdToButtonId(IPT_MOVE_FORWARD, LOLK_UP);176 Input::LinkAction IdToButtonId(IPT_MOVE_BACKWARD, LOLK_DOWN);177 Input::LinkAction IdToButtonId(IPT_MOVE_STRAFE_LEFT, LOLK_LEFT);178 Input::LinkAction IdToButtonId(IPT_MOVE_STRAFE_RIGHT, LOLK_RIGHT);179 Input::LinkAction IdToButtonId(IPT_MOVE_JUMP, LOLK_SPACE);172 Input::LinkActionToKey(IPT_MOVE_FORWARD, Key::K_UP); 173 Input::LinkActionToKey(IPT_MOVE_BACKWARD, Key::K_DOWN); 174 Input::LinkActionToKey(IPT_MOVE_STRAFE_LEFT, Key::K_LEFT); 175 Input::LinkActionToKey(IPT_MOVE_STRAFE_RIGHT, Key::K_RIGHT); 176 Input::LinkActionToKey(IPT_MOVE_JUMP, Key::K_SPACE); 180 177 181 178 //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); … … 318 315 mat4 CtlrMx = Character->GetTransform(); 319 316 320 int HMovement = Input::GetActionStatus(IPT_MOVE_STRAFE_ LEFT) - Input::GetActionStatus(IPT_MOVE_STRAFE_RIGHT);317 int HMovement = Input::GetActionStatus(IPT_MOVE_STRAFE_RIGHT) - Input::GetActionStatus(IPT_MOVE_STRAFE_LEFT); 321 318 int VMovement = Input::GetActionStatus(IPT_MOVE_FORWARD) - Input::GetActionStatus(IPT_MOVE_BACKWARD); 322 319 int RMovement = 0;//Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/); 323 320 vec3 CharMove = vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f); 324 321 325 if (Input::Was ActionJustReleased(IPT_MOVE_JUMP))322 if (Input::WasReleased(IPT_MOVE_JUMP)) 326 323 Character->Jump(); 327 324 Character->SetMovementForFrame(CharMove);
Note: See TracChangeset
for help on using the changeset viewer.