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