| @@ -46,7 +46,8 @@ protected: | |||||
| GAMEGROUP_BEFORE = 0, | GAMEGROUP_BEFORE = 0, | ||||
| GAMEGROUP_DEFAULT, | GAMEGROUP_DEFAULT, | ||||
| GAMEGROUP_AFTER, | GAMEGROUP_AFTER, | ||||
| GAMEGROUP_AFTER_POST, | |||||
| GAMEGROUP_AFTER_0, | |||||
| GAMEGROUP_AFTER_1, | |||||
| // Must be the last element | // Must be the last element | ||||
| GAMEGROUP_END | GAMEGROUP_END | ||||
| @@ -31,7 +31,7 @@ namespace lol | |||||
| * Input implementation class | * Input implementation class | ||||
| */ | */ | ||||
| Array<ButtonSetting> Input::InputAssocationList; | |||||
| InputTracker* Input::m_input_tracker = NULL; | |||||
| static class InputData | static class InputData | ||||
| { | { | ||||
| @@ -60,6 +60,109 @@ inputdata; | |||||
| static InputData * const data = &inputdata; | static InputData * const data = &inputdata; | ||||
| /* | |||||
| * InputTracker class | |||||
| */ | |||||
| InputTracker::InputTracker() | |||||
| { | |||||
| m_gamegroup = GAMEGROUP_BEFORE; | |||||
| Ticker::Ref(this); | |||||
| } | |||||
| //Internal : Updates the action status & timers | |||||
| void InputTracker::UpdateActionStatus(float seconds) | |||||
| { | |||||
| 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 (CurIT.m_current_status && CurAS.BufferingTime >= .0f) | |||||
| CurAS.BufferedSince = .0f; | |||||
| } | |||||
| } | |||||
| } | |||||
| //Helps link a software input Action-Id to an hardware input Button-Id. | |||||
| void InputTracker::LinkActionIdToButtonId(int ActionId, int ButtonId) | |||||
| { | |||||
| int ITIdx = GetButtonSettingIdx(ButtonId); | |||||
| if (ITIdx == -1) | |||||
| { | |||||
| ITIdx = m_input_assocation_list.Count(); | |||||
| m_input_assocation_list << ButtonSetting(ButtonId); | |||||
| } | |||||
| ButtonSetting &CurIT = m_input_assocation_list[ITIdx]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx == -1) | |||||
| { | |||||
| ASIdx = CurIT.m_associated_action_list.Count(); | |||||
| CurIT.m_associated_action_list << ActionSetting(ActionId); | |||||
| } | |||||
| } | |||||
| //Helps unlink a software input Action-Id to an hardware input Button-Id. | |||||
| void InputTracker::UnlinkActionId(int ActionId) | |||||
| { | |||||
| for (int i = 0; i < m_input_assocation_list.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = m_input_assocation_list[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| CurIT.m_associated_action_list.Remove(ASIdx); | |||||
| } | |||||
| } | |||||
| //Returns the current status of a given action | |||||
| int InputTracker::GetActionStatus(int ActionId) | |||||
| { | |||||
| for (int i = 0; i < m_input_assocation_list.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = m_input_assocation_list[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| { | |||||
| ActionSetting &CurAS = CurIT.m_associated_action_list[ASIdx]; | |||||
| if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime) | |||||
| return 1; | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| //Returns TRUE if action status when from Active to Inactive this frame | |||||
| bool InputTracker::WasActionJustReleased(int ActionId) | |||||
| { | |||||
| for (int i = 0; i < m_input_assocation_list.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = m_input_assocation_list[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| { | |||||
| if (!CurIT.m_current_status && CurIT.m_previous_status) | |||||
| return true; | |||||
| return false; | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /* | /* | ||||
| * Public Input class | * Public Input class | ||||
| */ | */ | ||||
| @@ -115,98 +218,33 @@ int Input::GetButtonState(int button) | |||||
| #endif | #endif | ||||
| } | } | ||||
| //-- | |||||
| //--- | |||||
| //Internal : Updates the action status & timers | |||||
| void Input::UpdateActionStatus(float seconds) | |||||
| { | |||||
| for (int i = 0; i < InputAssocationList.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = InputAssocationList[i]; | |||||
| CurIT.PrevStatus = CurIT.CurStatus; | |||||
| CurIT.CurStatus = Input::GetButtonState(CurIT.RawButtonId); | |||||
| for (int j = 0; j < CurIT.AssociatedActionList.Count(); j++) | |||||
| { | |||||
| ActionSetting &CurAS = CurIT.AssociatedActionList[j]; | |||||
| if (CurAS.BufferedSince <= CurAS.BufferingTime) | |||||
| CurAS.BufferedSince += seconds; | |||||
| if (CurIT.CurStatus && CurAS.BufferingTime >= .0f) | |||||
| CurAS.BufferedSince = .0f; | |||||
| } | |||||
| } | |||||
| } | |||||
| //Helps link a software input Action-Id to an hardware input Button-Id. | //Helps link a software input Action-Id to an hardware input Button-Id. | ||||
| void Input::LinkActionIdToButtonId(int ActionId, int ButtonId) | void Input::LinkActionIdToButtonId(int ActionId, int ButtonId) | ||||
| { | { | ||||
| int ITIdx = GetButtonSettingIdx(ButtonId); | |||||
| if (ITIdx == -1) | |||||
| { | |||||
| ITIdx = InputAssocationList.Count(); | |||||
| InputAssocationList << ButtonSetting(ButtonId); | |||||
| } | |||||
| ButtonSetting &CurIT = InputAssocationList[ITIdx]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx == -1) | |||||
| { | |||||
| ASIdx = CurIT.AssociatedActionList.Count(); | |||||
| CurIT.AssociatedActionList << ActionSetting(ActionId); | |||||
| } | |||||
| if (CheckInputTrackerInit()) | |||||
| Input::m_input_tracker->LinkActionIdToButtonId(ActionId, ButtonId); | |||||
| } | } | ||||
| //Helps unlink a software input Action-Id to an hardware input Button-Id. | //Helps unlink a software input Action-Id to an hardware input Button-Id. | ||||
| void Input::UnlinkActionId(int ActionId) | void Input::UnlinkActionId(int ActionId) | ||||
| { | { | ||||
| for (int i = 0; i < InputAssocationList.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = InputAssocationList[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| CurIT.AssociatedActionList.Remove(ASIdx); | |||||
| } | |||||
| if (CheckInputTrackerInit()) | |||||
| Input::m_input_tracker->UnlinkActionId(ActionId); | |||||
| } | } | ||||
| //Returns the current status of a given action | //Returns the current status of a given action | ||||
| int Input::GetActionStatus(int ActionId) | int Input::GetActionStatus(int ActionId) | ||||
| { | { | ||||
| for (int i = 0; i < InputAssocationList.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = InputAssocationList[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| { | |||||
| ActionSetting &CurAS = CurIT.AssociatedActionList[ASIdx]; | |||||
| if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime) | |||||
| return 1; | |||||
| return 0; | |||||
| } | |||||
| } | |||||
| if (CheckInputTrackerInit()) | |||||
| return Input::m_input_tracker->GetActionStatus(ActionId); | |||||
| return 0; | return 0; | ||||
| } | } | ||||
| //Returns TRUE if action status when from Active to Inactive this frame | //Returns TRUE if action status when from Active to Inactive this frame | ||||
| bool Input::WasActionJustReleased(int ActionId) | bool Input::WasActionJustReleased(int ActionId) | ||||
| { | { | ||||
| for (int i = 0; i < InputAssocationList.Count(); i++) | |||||
| { | |||||
| ButtonSetting &CurIT = InputAssocationList[i]; | |||||
| int ASIdx = CurIT.GetActionSettingIdx(ActionId); | |||||
| if (ASIdx != -1) | |||||
| { | |||||
| if (!CurIT.CurStatus && CurIT.PrevStatus) | |||||
| return true; | |||||
| return false; | |||||
| } | |||||
| } | |||||
| if (CheckInputTrackerInit()) | |||||
| return Input::m_input_tracker->WasActionJustReleased(ActionId); | |||||
| return false; | return false; | ||||
| } | } | ||||
| @@ -17,6 +17,7 @@ | |||||
| #define __LOL_INPUT_INPUT_H__ | #define __LOL_INPUT_INPUT_H__ | ||||
| #include <cstring> | #include <cstring> | ||||
| #include "core.h" | |||||
| #include "lol/math/vector.h" | #include "lol/math/vector.h" | ||||
| #include "input/stick.h" | #include "input/stick.h" | ||||
| @@ -25,81 +26,301 @@ namespace lol | |||||
| class WorldEntity; | class WorldEntity; | ||||
| //Partial Key reap-off of the SDLK enum | |||||
| #define LOLK_UNKNOWN = 0; | |||||
| #define LOLK_RETURN = '\r'; | |||||
| #define LOLK_ESCAPE = '\033'; | |||||
| #define LOLK_BACKSPACE = '\b'; | |||||
| #define LOLK_TAB = '\t'; | |||||
| #define LOLK_SPACE = ' '; | |||||
| #define LOLK_EXCLAIM = '!'; | |||||
| #define LOLK_QUOTEDBL = '"'; | |||||
| #define LOLK_HASH = '#'; | |||||
| #define LOLK_PERCENT = '%'; | |||||
| #define LOLK_DOLLAR = '$'; | |||||
| #define LOLK_AMPERSAND = '&'; | |||||
| #define LOLK_QUOTE = '\''; | |||||
| #define LOLK_LEFTPAREN = '('; | |||||
| #define LOLK_RIGHTPAREN = ')'; | |||||
| #define LOLK_ASTERISK = '*'; | |||||
| #define LOLK_PLUS = '+'; | |||||
| #define LOLK_COMMA = ';'; | |||||
| #define LOLK_MINUS = '-'; | |||||
| #define LOLK_PERIOD = '.'; | |||||
| #define LOLK_SLASH = '/'; | |||||
| #define LOLK_0 = '0'; | |||||
| #define LOLK_1 = '1'; | |||||
| #define LOLK_2 = '2'; | |||||
| #define LOLK_3 = '3'; | |||||
| #define LOLK_4 = '4'; | |||||
| #define LOLK_5 = '5'; | |||||
| #define LOLK_6 = '6'; | |||||
| #define LOLK_7 = '7'; | |||||
| #define LOLK_8 = '8'; | |||||
| #define LOLK_9 = '9'; | |||||
| #define LOLK_COLON = ':'; | |||||
| #define LOLK_SEMICOLON = ';'; | |||||
| #define LOLK_LESS = '<'; | |||||
| #define LOLK_EQUALS = '='; | |||||
| #define LOLK_GREATER = '>'; | |||||
| #define LOLK_QUESTION = '?'; | |||||
| #define LOLK_AT = '@'; | |||||
| /* | |||||
| Skip uppercase letters | |||||
| */ | |||||
| #define LOLK_LEFTBRACKET = '['; | |||||
| #define LOLK_BACKSLASH = '\\'; | |||||
| #define LOLK_RIGHTBRACKET = ']'; | |||||
| #define LOLK_CARET = '^'; | |||||
| #define LOLK_UNDERSCORE = '_'; | |||||
| #define LOLK_BACKQUOTE = '`'; | |||||
| #define LOLK_a = 'a'; | |||||
| #define LOLK_b = 'b'; | |||||
| #define LOLK_c = 'c'; | |||||
| #define LOLK_d = 'd'; | |||||
| #define LOLK_e = 'e'; | |||||
| #define LOLK_f = 'f'; | |||||
| #define LOLK_g = 'g'; | |||||
| #define LOLK_h = 'h'; | |||||
| #define LOLK_i = 'i'; | |||||
| #define LOLK_j = 'j'; | |||||
| #define LOLK_k = 'k'; | |||||
| #define LOLK_l = 'l'; | |||||
| #define LOLK_m = 'm'; | |||||
| #define LOLK_n = 'n'; | |||||
| #define LOLK_o = 'o'; | |||||
| #define LOLK_p = 'p'; | |||||
| #define LOLK_q = 'q'; | |||||
| #define LOLK_r = 'r'; | |||||
| #define LOLK_s = 's'; | |||||
| #define LOLK_t = 't'; | |||||
| #define LOLK_u = 'u'; | |||||
| #define LOLK_v = 'v'; | |||||
| #define LOLK_w = 'w'; | |||||
| #define LOLK_x = 'x'; | |||||
| #define LOLK_y = 'y'; | |||||
| #define LOLK_z = 'z'; | |||||
| //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) | |||||
| struct ActionSetting | struct ActionSetting | ||||
| { | { | ||||
| @@ -116,39 +337,71 @@ struct ActionSetting | |||||
| struct ButtonSetting | struct ButtonSetting | ||||
| { | { | ||||
| int RawButtonId; | |||||
| int CurStatus; | |||||
| int PrevStatus; | |||||
| Array<ActionSetting> AssociatedActionList; | |||||
| int m_raw_button_id; | |||||
| int m_current_status; | |||||
| int m_previous_status; | |||||
| Array<ActionSetting> m_associated_action_list; | |||||
| ButtonSetting(int NewRawButtonId) | ButtonSetting(int NewRawButtonId) | ||||
| { | { | ||||
| memset(this, 0, sizeof(ButtonSetting)); | memset(this, 0, sizeof(ButtonSetting)); | ||||
| RawButtonId = NewRawButtonId; | |||||
| m_raw_button_id = NewRawButtonId; | |||||
| } | } | ||||
| int GetActionSettingIdx(int ActionId) | int GetActionSettingIdx(int ActionId) | ||||
| { | { | ||||
| for (int i = 0; i < AssociatedActionList.Count(); i++) | |||||
| if (AssociatedActionList[i].ActionId == ActionId) | |||||
| for (int i = 0; i < m_associated_action_list.Count(); i++) | |||||
| if (m_associated_action_list[i].ActionId == ActionId) | |||||
| return i; | return i; | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| }; | }; | ||||
| class Input | |||||
| class InputTracker : public Entity | |||||
| { | { | ||||
| friend class Input; | |||||
| public: | |||||
| InputTracker(); | |||||
| private: | private: | ||||
| static Array<ButtonSetting> InputAssocationList; | |||||
| Array<ButtonSetting> m_input_assocation_list; | |||||
| static int GetButtonSettingIdx(int ButtonId) | |||||
| int GetButtonSettingIdx(int ButtonId) | |||||
| { | { | ||||
| for (int i = 0; i < InputAssocationList.Count(); i++) | |||||
| if (InputAssocationList[i].RawButtonId == 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 i; | ||||
| return -1; | return -1; | ||||
| } | } | ||||
| static void UpdateActionStatus(float seconds); | |||||
| void UpdateActionStatus(float seconds); | |||||
| protected: | |||||
| virtual void TickGame(float seconds) | |||||
| { | |||||
| UpdateActionStatus(seconds); | |||||
| } | |||||
| void LinkActionIdToButtonId(int ActionId, int ButtonId); | |||||
| void UnlinkActionId(int ActionId); | |||||
| int GetActionStatus(int ActionId); | |||||
| bool WasActionJustReleased(int ActionId); | |||||
| }; | |||||
| class Input | |||||
| { | |||||
| private: | |||||
| static InputTracker* m_input_tracker; | |||||
| static bool CheckInputTrackerInit() | |||||
| { | |||||
| if (Input::m_input_tracker) | |||||
| return true; | |||||
| Input::m_input_tracker = new InputTracker(); | |||||
| return true; | |||||
| } | |||||
| public: | public: | ||||
| @@ -159,7 +412,7 @@ public: | |||||
| //BH : Shouldn't use this | //BH : Shouldn't use this | ||||
| static int GetButtonState(int button); | static int GetButtonState(int button); | ||||
| //Action management | |||||
| /* Action management */ | |||||
| static void LinkActionIdToButtonId(int ActionId, int ButtonId); | static void LinkActionIdToButtonId(int ActionId, int ButtonId); | ||||
| static void UnlinkActionId(int ActionId); | static void UnlinkActionId(int ActionId); | ||||
| static int GetActionStatus(int ActionId); | static int GetActionStatus(int ActionId); | ||||
| @@ -174,10 +427,7 @@ public: | |||||
| static void SetMouseButton(int index); | static void SetMouseButton(int index); | ||||
| static void UnsetMouseButton(int index); | static void UnsetMouseButton(int index); | ||||
| /* | |||||
| * Joystick handling | |||||
| */ | |||||
| /* Joystick handling */ | |||||
| static Stick *CreateStick(); | static Stick *CreateStick(); | ||||
| static void DestroyStick(Stick *stick); | static void DestroyStick(Stick *stick); | ||||
| @@ -56,6 +56,15 @@ int gNumObjects = 64; | |||||
| #define USE_ROTATION 0 | #define USE_ROTATION 0 | ||||
| #define USE_CHARACTER 1 | #define USE_CHARACTER 1 | ||||
| enum eInputAction | |||||
| { | |||||
| IPT_MOVE_FORWARD, | |||||
| IPT_MOVE_BACKWARD, | |||||
| IPT_MOVE_STRAFE_LEFT, | |||||
| IPT_MOVE_STRAFE_RIGHT, | |||||
| IPT_MOVE_JUMP, | |||||
| }; | |||||
| BtPhysTest::BtPhysTest(bool editor) | BtPhysTest::BtPhysTest(bool editor) | ||||
| { | { | ||||
| m_loop_value = .0f; | m_loop_value = .0f; | ||||
| @@ -162,6 +171,13 @@ BtPhysTest::BtPhysTest(bool editor) | |||||
| m_character_list << NewPhyobj; | m_character_list << NewPhyobj; | ||||
| Ticker::Ref(NewPhyobj); | 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); | |||||
| //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); | //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true); | ||||
| } | } | ||||
| @@ -300,12 +316,14 @@ void BtPhysTest::TickGame(float seconds) | |||||
| PhysicsObject* PhysObj = m_character_list[i]; | PhysicsObject* PhysObj = m_character_list[i]; | ||||
| EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); | EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter(); | ||||
| mat4 CtlrMx = Character->GetTransform(); | mat4 CtlrMx = Character->GetTransform(); | ||||
| int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/); | |||||
| int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/); | |||||
| int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/); | |||||
| int HMovement = Input::GetActionStatus(IPT_MOVE_STRAFE_LEFT) - Input::GetActionStatus(IPT_MOVE_STRAFE_RIGHT); | |||||
| 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); | vec3 CharMove = vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f); | ||||
| if (Input::WasActionJustReleased(IPT_MOVE_JUMP)) | |||||
| Character->Jump(); | |||||
| Character->SetMovementForFrame(CharMove); | Character->SetMovementForFrame(CharMove); | ||||
| RayCastResult HitResult; | RayCastResult HitResult; | ||||
| @@ -234,7 +234,7 @@ public: | |||||
| EasyMesh *GetMesh() { return &m_mesh; } | EasyMesh *GetMesh() { return &m_mesh; } | ||||
| EasyPhysic *GetPhysic() { return m_physics; } | EasyPhysic *GetPhysic() { return m_physics; } | ||||
| EasyPhysic *GetCharacter() { return m_character; } | |||||
| EasyCharacterController *GetCharacter() { return m_character; } | |||||
| ~PhysicsObject() | ~PhysicsObject() | ||||
| { | { | ||||
| @@ -49,11 +49,14 @@ public: | |||||
| m_step_height(.0f), | m_step_height(.0f), | ||||
| m_base_is_updating(false), | m_base_is_updating(false), | ||||
| m_base_cached_movement(vec3(0.f)), | m_base_cached_movement(vec3(0.f)), | ||||
| m_frame_cached_movement(vec3(0.f)) | |||||
| m_frame_cached_movement(vec3(0.f)), | |||||
| m_walk_velocity(vec3(0.f)), | |||||
| m_current_velocity(vec3(0.f)) | |||||
| { | { | ||||
| m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR; | m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR; | ||||
| m_up_axis = 1; | m_up_axis = 1; | ||||
| m_gravity = vec3(.0f, -9.81f, .0f); | m_gravity = vec3(.0f, -9.81f, .0f); | ||||
| m_walk_velocity_damping = 0.2f; | |||||
| } | } | ||||
| ~EasyCharacterController() | ~EasyCharacterController() | ||||
| { | { | ||||
| @@ -65,6 +68,7 @@ public: | |||||
| virtual void AddToSimulation(class Simulation* current_simulation); | virtual void AddToSimulation(class Simulation* current_simulation); | ||||
| virtual void RemoveFromSimulation(class Simulation* current_simulation); | virtual void RemoveFromSimulation(class Simulation* current_simulation); | ||||
| virtual void SetMovementForFrame(vec3 const &MoveQuantity); | virtual void SetMovementForFrame(vec3 const &MoveQuantity); | ||||
| virtual void Jump(); | |||||
| virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation); | virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation); | ||||
| protected: | protected: | ||||
| @@ -84,8 +88,16 @@ protected: | |||||
| bool m_base_is_updating; | bool m_base_is_updating; | ||||
| vec3 m_base_cached_movement; | vec3 m_base_cached_movement; | ||||
| vec3 m_frame_cached_movement; | vec3 m_frame_cached_movement; | ||||
| //---- | |||||
| float m_walk_velocity_damping; | |||||
| //---- | |||||
| vec3 m_gravity; | vec3 m_gravity; | ||||
| vec3 m_velocity; | |||||
| //---- | |||||
| vec3 m_walk_velocity; | |||||
| vec3 m_current_velocity; | |||||
| #else // NO PHYSIC IMPLEMENTATION | #else // NO PHYSIC IMPLEMENTATION | ||||
| @@ -22,10 +22,11 @@ namespace lol | |||||
| //Override Gamegroups names for Physic-useage | //Override Gamegroups names for Physic-useage | ||||
| //"_ENT_" means that this is a group for Entities that use EasyPhysic primitives. | //"_ENT_" means that this is a group for Entities that use EasyPhysic primitives. | ||||
| //"_EZP_" means that this is a group for EasyPhysic primitives. | //"_EZP_" means that this is a group for EasyPhysic primitives. | ||||
| #define GAMEGROUP_ENT_PLATFORM GAMEGROUP_BEFORE | |||||
| #define GAMEGROUP_ENT_MAIN GAMEGROUP_DEFAULT | |||||
| #define GAMEGROUP_EZP_CHAR_CTRLR GAMEGROUP_AFTER | |||||
| #define GAMEGROUP_SIMULATION GAMEGROUP_AFTER_POST | |||||
| #define GAMEGROUP_ENT_INPUT GAMEGROUP_BEFORE | |||||
| #define GAMEGROUP_ENT_PLATFORM GAMEGROUP_DEFAULT | |||||
| #define GAMEGROUP_ENT_MAIN GAMEGROUP_AFTER | |||||
| #define GAMEGROUP_EZP_CHAR_CTRLR GAMEGROUP_AFTER_0 | |||||
| #define GAMEGROUP_SIMULATION GAMEGROUP_AFTER_1 | |||||
| #ifdef HAVE_PHYS_USE_BULLET | #ifdef HAVE_PHYS_USE_BULLET | ||||
| @@ -90,6 +90,11 @@ void EasyCharacterController::RemoveFromSimulation(class Simulation* current_sim | |||||
| } | } | ||||
| } | } | ||||
| void EasyCharacterController::Jump() | |||||
| { | |||||
| m_character->jump(); | |||||
| } | |||||
| //Set movement for this frame | //Set movement for this frame | ||||
| void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity) | void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity) | ||||
| { | { | ||||
| @@ -125,10 +130,13 @@ void EasyCharacterController::TickGame(float seconds) | |||||
| { | { | ||||
| Entity::TickGame(seconds); | Entity::TickGame(seconds); | ||||
| int IterationsNb = (int)(seconds / m_owner_simulation->m_timestep); | |||||
| float NewSeconds = IterationsNb * m_owner_simulation->m_timestep; | |||||
| m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / NewSeconds, NewSeconds); | |||||
| m_base_cached_movement = vec3(.0f); | |||||
| //Send final velocity in Bullet | |||||
| { | |||||
| int IterationsNb = (int)(seconds / m_owner_simulation->m_timestep); | |||||
| float NewSeconds = IterationsNb * m_owner_simulation->m_timestep; | |||||
| m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / NewSeconds, NewSeconds); | |||||
| m_base_cached_movement = vec3(.0f); | |||||
| } | |||||
| } | } | ||||
| #endif // HAVE_PHYS_USE_BULLET | #endif // HAVE_PHYS_USE_BULLET | ||||