Changeset 1785


Ignore:
Timestamp:
Aug 21, 2012, 6:38:40 PM (11 years ago)
Author:
touky
Message:

Added InputTracker test initPhysTest

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/entity.h

    r1768 r1785  
    4747        GAMEGROUP_DEFAULT,
    4848                GAMEGROUP_AFTER,
    49                 GAMEGROUP_AFTER_POST,
     49                GAMEGROUP_AFTER_0,
     50                GAMEGROUP_AFTER_1,
    5051
    5152                // Must be the last element
  • trunk/src/input/input.cpp

    r1753 r1785  
    3232 */
    3333
    34 Array<ButtonSetting>    Input::InputAssocationList;
     34InputTracker*                   Input::m_input_tracker = NULL;
    3535
    3636static class InputData
     
    6060
    6161static InputData * const data = &inputdata;
     62
     63/*
     64 * InputTracker class
     65 */
     66
     67InputTracker::InputTracker()
     68{
     69        m_gamegroup = GAMEGROUP_BEFORE;
     70
     71        Ticker::Ref(this);
     72}
     73
     74//Internal : Updates the action status & timers
     75void InputTracker::UpdateActionStatus(float seconds)
     76{
     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);
     83
     84                for (int j = 0; j < CurIT.m_associated_action_list.Count(); j++)
     85                {
     86                        ActionSetting &CurAS = CurIT.m_associated_action_list[j];
     87
     88                        if (CurAS.BufferedSince <= CurAS.BufferingTime)
     89                                CurAS.BufferedSince += seconds;
     90
     91                        if (CurIT.m_current_status && CurAS.BufferingTime >= .0f)
     92                                CurAS.BufferedSince = .0f;
     93                }
     94        }
     95
     96}
     97
     98//Helps link a software input Action-Id to an hardware input Button-Id.
     99void InputTracker::LinkActionIdToButtonId(int ActionId, int ButtonId)
     100{
     101        int ITIdx = GetButtonSettingIdx(ButtonId);
     102        if (ITIdx == -1)
     103        {
     104                ITIdx = m_input_assocation_list.Count();
     105                m_input_assocation_list << ButtonSetting(ButtonId);
     106        }
     107
     108        ButtonSetting &CurIT = m_input_assocation_list[ITIdx];
     109
     110        int ASIdx = CurIT.GetActionSettingIdx(ActionId);
     111        if (ASIdx == -1)
     112        {
     113                ASIdx = CurIT.m_associated_action_list.Count();
     114                CurIT.m_associated_action_list << ActionSetting(ActionId);
     115        }
     116}
     117
     118//Helps unlink a software input Action-Id to an hardware input Button-Id.
     119void InputTracker::UnlinkActionId(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(ActionId);
     125                if (ASIdx != -1)
     126                        CurIT.m_associated_action_list.Remove(ASIdx);
     127        }
     128}
     129
     130//Returns the current status of a given action
     131int InputTracker::GetActionStatus(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(ActionId);
     137                if (ASIdx != -1)
     138                {
     139                        ActionSetting &CurAS = CurIT.m_associated_action_list[ASIdx];
     140
     141                        if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime)
     142                                return 1;
     143                        return 0;
     144                }
     145        }
     146        return 0;
     147}
     148
     149//Returns TRUE if action status when from Active to Inactive this frame
     150bool InputTracker::WasActionJustReleased(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(ActionId);
     156                if (ASIdx != -1)
     157                {
     158                        if (!CurIT.m_current_status && CurIT.m_previous_status)
     159                                return true;
     160                        return false;
     161                }
     162        }
     163        return false;
     164}
    62165
    63166/*
     
    116219}
    117220
    118 //--
    119 
    120 //---
    121 //Internal : Updates the action status & timers
    122 void Input::UpdateActionStatus(float seconds)
    123 {
    124         for (int i = 0; i < InputAssocationList.Count(); i++)
    125         {
    126                 ButtonSetting &CurIT = InputAssocationList[i];
    127 
    128                 CurIT.PrevStatus = CurIT.CurStatus;
    129                 CurIT.CurStatus = Input::GetButtonState(CurIT.RawButtonId);
    130 
    131                 for (int j = 0; j < CurIT.AssociatedActionList.Count(); j++)
    132                 {
    133                         ActionSetting &CurAS = CurIT.AssociatedActionList[j];
    134 
    135                         if (CurAS.BufferedSince <= CurAS.BufferingTime)
    136                                 CurAS.BufferedSince += seconds;
    137 
    138                         if (CurIT.CurStatus && CurAS.BufferingTime >= .0f)
    139                                 CurAS.BufferedSince = .0f;
    140                 }
    141         }
    142 
    143 }
    144 
    145221//Helps link a software input Action-Id to an hardware input Button-Id.
    146222void Input::LinkActionIdToButtonId(int ActionId, int ButtonId)
    147223{
    148         int ITIdx = GetButtonSettingIdx(ButtonId);
    149         if (ITIdx == -1)
    150         {
    151                 ITIdx = InputAssocationList.Count();
    152                 InputAssocationList << ButtonSetting(ButtonId);
    153         }
    154 
    155         ButtonSetting &CurIT = InputAssocationList[ITIdx];
    156 
    157         int ASIdx = CurIT.GetActionSettingIdx(ActionId);
    158         if (ASIdx == -1)
    159         {
    160                 ASIdx = CurIT.AssociatedActionList.Count();
    161                 CurIT.AssociatedActionList << ActionSetting(ActionId);
    162         }
     224        if (CheckInputTrackerInit())
     225                Input::m_input_tracker->LinkActionIdToButtonId(ActionId, ButtonId);
    163226}
    164227
     
    166229void Input::UnlinkActionId(int ActionId)
    167230{
    168         for (int i = 0; i < InputAssocationList.Count(); i++)
    169         {
    170                 ButtonSetting &CurIT = InputAssocationList[i];
    171                 int ASIdx = CurIT.GetActionSettingIdx(ActionId);
    172                 if (ASIdx != -1)
    173                         CurIT.AssociatedActionList.Remove(ASIdx);
    174         }
     231        if (CheckInputTrackerInit())
     232                Input::m_input_tracker->UnlinkActionId(ActionId);
    175233}
    176234
     
    178236int Input::GetActionStatus(int ActionId)
    179237{
    180         for (int i = 0; i < InputAssocationList.Count(); i++)
    181         {
    182                 ButtonSetting &CurIT = InputAssocationList[i];
    183                 int ASIdx = CurIT.GetActionSettingIdx(ActionId);
    184                 if (ASIdx != -1)
    185                 {
    186                         ActionSetting &CurAS = CurIT.AssociatedActionList[ASIdx];
    187                        
    188                         if (CurAS.BufferingTime >= .0f && CurAS.BufferedSince <= CurAS.BufferingTime)
    189                                 return 1;
    190                         return 0;
    191                 }
    192         }
     238        if (CheckInputTrackerInit())
     239                return Input::m_input_tracker->GetActionStatus(ActionId);
    193240        return 0;
    194241}
     
    197244bool Input::WasActionJustReleased(int ActionId)
    198245{
    199         for (int i = 0; i < InputAssocationList.Count(); i++)
    200         {
    201                 ButtonSetting &CurIT = InputAssocationList[i];
    202                 int ASIdx = CurIT.GetActionSettingIdx(ActionId);
    203                 if (ASIdx != -1)
    204                 {
    205                         if (!CurIT.CurStatus && CurIT.PrevStatus)
    206                                 return true;
    207                         return false;
    208                 }
    209         }
     246        if (CheckInputTrackerInit())
     247                return Input::m_input_tracker->WasActionJustReleased(ActionId);
    210248        return false;
    211249}
  • trunk/src/input/input.h

    r1768 r1785  
    1818
    1919#include <cstring>
     20#include "core.h"
    2021#include "lol/math/vector.h"
    2122#include "input/stick.h"
     
    2627class WorldEntity;
    2728
    28 //Partial Key reap-off of the SDLK enum
    29 #define LOLK_UNKNOWN = 0;
    30 
    31 #define LOLK_RETURN = '\r';
    32 #define LOLK_ESCAPE = '\033';
    33 #define LOLK_BACKSPACE = '\b';
    34 #define LOLK_TAB = '\t';
    35 #define LOLK_SPACE = ' ';
    36 #define LOLK_EXCLAIM = '!';
    37 #define LOLK_QUOTEDBL = '"';
    38 #define LOLK_HASH = '#';
    39 #define LOLK_PERCENT = '%';
    40 #define LOLK_DOLLAR = '$';
    41 #define LOLK_AMPERSAND = '&';
    42 #define LOLK_QUOTE = '\'';
    43 #define LOLK_LEFTPAREN = '(';
    44 #define LOLK_RIGHTPAREN = ')';
    45 #define LOLK_ASTERISK = '*';
    46 #define LOLK_PLUS = '+';
    47 #define LOLK_COMMA = ';';
    48 #define LOLK_MINUS = '-';
    49 #define LOLK_PERIOD = '.';
    50 #define LOLK_SLASH = '/';
    51 #define LOLK_0 = '0';
    52 #define LOLK_1 = '1';
    53 #define LOLK_2 = '2';
    54 #define LOLK_3 = '3';
    55 #define LOLK_4 = '4';
    56 #define LOLK_5 = '5';
    57 #define LOLK_6 = '6';
    58 #define LOLK_7 = '7';
    59 #define LOLK_8 = '8';
    60 #define LOLK_9 = '9';
    61 #define LOLK_COLON = ':';
    62 #define LOLK_SEMICOLON = ';';
    63 #define LOLK_LESS = '<';
    64 #define LOLK_EQUALS = '=';
    65 #define LOLK_GREATER = '>';
    66 #define LOLK_QUESTION = '?';
    67 #define LOLK_AT = '@';
    68 /*
    69     Skip uppercase letters
    70     */
    71 #define LOLK_LEFTBRACKET = '[';
    72 #define LOLK_BACKSLASH = '\\';
    73 #define LOLK_RIGHTBRACKET = ']';
    74 #define LOLK_CARET = '^';
    75 #define LOLK_UNDERSCORE = '_';
    76 #define LOLK_BACKQUOTE = '`';
    77 #define LOLK_a = 'a';
    78 #define LOLK_b = 'b';
    79 #define LOLK_c = 'c';
    80 #define LOLK_d = 'd';
    81 #define LOLK_e = 'e';
    82 #define LOLK_f = 'f';
    83 #define LOLK_g = 'g';
    84 #define LOLK_h = 'h';
    85 #define LOLK_i = 'i';
    86 #define LOLK_j = 'j';
    87 #define LOLK_k = 'k';
    88 #define LOLK_l = 'l';
    89 #define LOLK_m = 'm';
    90 #define LOLK_n = 'n';
    91 #define LOLK_o = 'o';
    92 #define LOLK_p = 'p';
    93 #define LOLK_q = 'q';
    94 #define LOLK_r = 'r';
    95 #define LOLK_s = 's';
    96 #define LOLK_t = 't';
    97 #define LOLK_u = 'u';
    98 #define LOLK_v = 'v';
    99 #define LOLK_w = 'w';
    100 #define LOLK_x = 'x';
    101 #define LOLK_y = 'y';
    102 #define LOLK_z = 'z';
     29//FULL Key reap-off of the SDLK enum
     30typedef 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) */
     304typedef 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)
    103324
    104325struct ActionSetting
     
    117338struct ButtonSetting
    118339{
    119         int                                             RawButtonId;
    120         int                                             CurStatus;
    121         int                                             PrevStatus;
    122         Array<ActionSetting>    AssociatedActionList;
     340        int                                             m_raw_button_id;
     341        int                                             m_current_status;
     342        int                                             m_previous_status;
     343        Array<ActionSetting>    m_associated_action_list;
    123344
    124345        ButtonSetting(int NewRawButtonId)
    125346        {
    126347                memset(this, 0, sizeof(ButtonSetting));
    127                 RawButtonId = NewRawButtonId;
     348                m_raw_button_id = NewRawButtonId;
    128349        }
    129350        int GetActionSettingIdx(int ActionId)
    130351        {
    131                 for (int i = 0; i < AssociatedActionList.Count(); i++)
    132                         if (AssociatedActionList[i].ActionId == ActionId)
     352                for (int i = 0; i < m_associated_action_list.Count(); i++)
     353                        if (m_associated_action_list[i].ActionId == ActionId)
    133354                                return i;
    134355                return -1;
    135356        }
     357};
     358
     359class InputTracker : public Entity
     360{
     361
     362        friend class Input;
     363
     364public:
     365        InputTracker();
     366
     367private:
     368        Array<ButtonSetting>    m_input_assocation_list;
     369
     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);
     379
     380protected:
     381        virtual void                    TickGame(float seconds)
     382        {
     383                UpdateActionStatus(seconds);
     384        }
     385
     386        void                                    LinkActionIdToButtonId(int ActionId, int ButtonId);
     387        void                                    UnlinkActionId(int ActionId);
     388        int                                             GetActionStatus(int ActionId);
     389        bool                                    WasActionJustReleased(int ActionId);
    136390};
    137391
     
    139393{
    140394private:
    141         static Array<ButtonSetting>     InputAssocationList;
    142 
    143         static int GetButtonSettingIdx(int ButtonId)
    144         {
    145                 for (int i = 0; i < InputAssocationList.Count(); i++)
    146                         if (InputAssocationList[i].RawButtonId == ButtonId)
    147                                 return i;
    148                 return -1;
    149         }
    150 
    151         static void UpdateActionStatus(float seconds);
     395        static InputTracker*            m_input_tracker;
     396
     397        static bool                                     CheckInputTrackerInit()
     398        {
     399                if (Input::m_input_tracker)
     400                        return true;
     401
     402                Input::m_input_tracker = new InputTracker();
     403                return true;
     404        }
    152405
    153406public:
     
    160413    static int GetButtonState(int button);
    161414
    162         //Action management
     415        /* Action management */
    163416        static void LinkActionIdToButtonId(int ActionId, int ButtonId);
    164417        static void UnlinkActionId(int ActionId);
     
    175428    static void UnsetMouseButton(int index);
    176429
    177     /*
    178      * Joystick handling
    179      */
    180 
     430    /* Joystick handling */
    181431    static Stick *CreateStick();
    182432    static void DestroyStick(Stick *stick);
  • trunk/test/BtPhysTest.cpp

    r1768 r1785  
    5757#define USE_CHARACTER   1
    5858
     59enum 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};
     67
    5968BtPhysTest::BtPhysTest(bool editor)
    6069{
     
    162171                m_character_list << NewPhyobj;
    163172                Ticker::Ref(NewPhyobj);
     173
     174
     175                Input::LinkActionIdToButtonId(IPT_MOVE_FORWARD,                 LOLK_UP);
     176                Input::LinkActionIdToButtonId(IPT_MOVE_BACKWARD,                LOLK_DOWN);
     177                Input::LinkActionIdToButtonId(IPT_MOVE_STRAFE_LEFT,             LOLK_LEFT);
     178                Input::LinkActionIdToButtonId(IPT_MOVE_STRAFE_RIGHT,    LOLK_RIGHT);
     179                Input::LinkActionIdToButtonId(IPT_MOVE_JUMP,                    LOLK_SPACE);
    164180
    165181                //NewPhyobj->GetCharacter()->AttachTo(BasePhyobj->GetPhysic(), true, true);
     
    301317                        EasyCharacterController* Character = (EasyCharacterController*)PhysObj->GetCharacter();
    302318                        mat4 CtlrMx = Character->GetTransform();
    303 
    304                         int HMovement = Input::GetButtonState(275 /*SDLK_RIGHT*/) - Input::GetButtonState(276 /*SDLK_LEFT*/);
    305                         int VMovement = Input::GetButtonState(273 /*SDLK_UP*/) - Input::GetButtonState(274 /*SDLK_DOWN*/);
    306                         int RMovement = Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);
     319                       
     320                        int HMovement = Input::GetActionStatus(IPT_MOVE_STRAFE_LEFT) - Input::GetActionStatus(IPT_MOVE_STRAFE_RIGHT);
     321                        int VMovement = Input::GetActionStatus(IPT_MOVE_FORWARD) - Input::GetActionStatus(IPT_MOVE_BACKWARD);
     322                        int RMovement = 0;//Input::GetButtonState(280 /*SDLK_PAGEUP*/) - Input::GetButtonState(281 /*SDLK_PAGEDOWN*/);
    307323                        vec3 CharMove = vec3((float)VMovement * seconds * 4.f, (float)RMovement * seconds * 10.f, (float)HMovement * seconds * 4.f);
    308324
     325                        if (Input::WasActionJustReleased(IPT_MOVE_JUMP))
     326                                Character->Jump();
    309327                        Character->SetMovementForFrame(CharMove);
    310328
  • trunk/test/PhysicObject.h

    r1768 r1785  
    235235        EasyMesh *GetMesh() { return &m_mesh; }
    236236        EasyPhysic *GetPhysic() { return m_physics; }
    237         EasyPhysic *GetCharacter() { return m_character; }
     237        EasyCharacterController *GetCharacter() { return m_character; }
    238238
    239239        ~PhysicsObject()
  • trunk/test/Physics/Include/EasyCharacterController.h

    r1782 r1785  
    5050                m_base_is_updating(false),
    5151                m_base_cached_movement(vec3(0.f)),
    52                 m_frame_cached_movement(vec3(0.f))
     52                m_frame_cached_movement(vec3(0.f)),
     53                m_walk_velocity(vec3(0.f)),
     54                m_current_velocity(vec3(0.f))
    5355        {
    5456                m_gamegroup = GAMEGROUP_EZP_CHAR_CTRLR;
    5557                m_up_axis = 1;
    5658                m_gravity = vec3(.0f, -9.81f, .0f);
     59                m_walk_velocity_damping = 0.2f;
    5760        }
    5861        ~EasyCharacterController()
     
    6669        virtual void RemoveFromSimulation(class Simulation* current_simulation);
    6770        virtual void SetMovementForFrame(vec3 const &MoveQuantity);
     71        virtual void Jump();
    6872
    6973        virtual void SetTransform(const lol::vec3& base_location, const lol::quat& base_rotation);
     
    8589        vec3                                                    m_base_cached_movement;
    8690        vec3                                                    m_frame_cached_movement;
     91
     92        //----
     93        float                                                   m_walk_velocity_damping;
     94
     95        //----
    8796        vec3                                                    m_gravity;
    88         vec3                                                    m_velocity;
     97
     98        //----
     99        vec3                                                    m_walk_velocity;
     100        vec3                                                    m_current_velocity;
    89101
    90102#else  // NO PHYSIC IMPLEMENTATION
  • trunk/test/Physics/Include/LolBtPhysicsIntegration.h

    r1768 r1785  
    2323        //"_ENT_" means that this is a group for Entities that use EasyPhysic primitives.
    2424        //"_EZP_" means that this is a group for EasyPhysic primitives.
    25 #define GAMEGROUP_ENT_PLATFORM          GAMEGROUP_BEFORE
    26 #define GAMEGROUP_ENT_MAIN                      GAMEGROUP_DEFAULT
    27 #define GAMEGROUP_EZP_CHAR_CTRLR        GAMEGROUP_AFTER
    28 #define GAMEGROUP_SIMULATION            GAMEGROUP_AFTER_POST
     25#define GAMEGROUP_ENT_INPUT                     GAMEGROUP_BEFORE
     26#define GAMEGROUP_ENT_PLATFORM          GAMEGROUP_DEFAULT
     27#define GAMEGROUP_ENT_MAIN                      GAMEGROUP_AFTER
     28#define GAMEGROUP_EZP_CHAR_CTRLR        GAMEGROUP_AFTER_0
     29#define GAMEGROUP_SIMULATION            GAMEGROUP_AFTER_1
    2930
    3031#ifdef HAVE_PHYS_USE_BULLET
  • trunk/test/Physics/Src/EasyCharacterController.cpp

    r1782 r1785  
    9191}
    9292
     93void EasyCharacterController::Jump()
     94{
     95        m_character->jump();
     96}
     97
    9398//Set movement for this frame
    9499void EasyCharacterController::SetMovementForFrame(vec3 const &MoveQuantity)
     
    126131        Entity::TickGame(seconds);
    127132
    128         int IterationsNb = (int)(seconds / m_owner_simulation->m_timestep);
    129         float NewSeconds = IterationsNb * m_owner_simulation->m_timestep;
    130         m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / NewSeconds, NewSeconds);
    131         m_base_cached_movement = vec3(.0f);
     133        //Send final velocity in Bullet
     134        {
     135                int IterationsNb = (int)(seconds / m_owner_simulation->m_timestep);
     136                float NewSeconds = IterationsNb * m_owner_simulation->m_timestep;
     137                m_character->setVelocityForTimeInterval(LOL2BT_VEC3(LOL2BT_UNIT * (m_base_cached_movement + m_frame_cached_movement)) / NewSeconds, NewSeconds);
     138                m_base_cached_movement = vec3(.0f);
     139        }
    132140}
    133141
Note: See TracChangeset for help on using the changeset viewer.