Ignore:
Timestamp:
Sep 9, 2012, 11:47:45 PM (7 years ago)
Author:
sam
Message:

input: some refactoring in the action bindings.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/input/input.cpp

    r1888 r1897  
    3232 */
    3333
    34 InputTracker*            Input::m_input_tracker = NULL;
     34InputTracker* Input::m_input_tracker = NULL;
    3535
    3636static class InputData
     
    6565 */
    6666
    67 int ButtonSetting::GetActionSettingIdx(ACTION_TYPE SearchAction)
     67int ButtonSetting::GetActionSettingIdx(Action a)
    6868{
    6969    for (int i = 0; i < m_associated_action_list.Count(); i++)
    70         if (ACTION_CMP(m_associated_action_list[i].m_action, SearchAction))
     70        if (ACTION_CMP(m_associated_action_list[i].m_action, a))
    7171            return i;
    7272    return -1;
     
    8888
    8989//Internal
    90 int InputTracker::GetButtonSettingIdx(Key Button)
    91 {
    92     for (int i = 0; i < m_input_assocation_list.Count(); i++)
    93         if (m_input_assocation_list[i].m_raw_button == Button)
     90int InputTracker::GetButtonSettingIdx(Key k)
     91{
     92    for (int i = 0; i < m_input_assocation_list.Count(); i++)
     93        if (m_input_assocation_list[i].m_raw_button == k)
    9494            return i;
    9595    return -1;
     
    9797
    9898//-----
    99 int InputTracker::GetCurrentButtonStatus(Key Button)
    100 {
    101     if (Button < m_input_status.Count())
    102         return m_input_status[Button];
     99int InputTracker::GetCurrentButtonStatus(Key k)
     100{
     101    if (k < m_input_status.Count())
     102        return m_input_status[k];
    103103    return 0;
    104104}
    105105
    106106//-----
    107 int InputTracker::GetPreviousButtonStatus(Key Button)
    108 {
    109     if (Button < m_input_status.Count())
    110         return m_input_status[(int)Button + (int)Key::Last];
     107int InputTracker::GetPreviousButtonStatus(Key k)
     108{
     109    if (k < m_input_status.Count())
     110        return m_input_status[(int)k + (int)Key::Last];
    111111    return 0;
    112112}
     
    148148
    149149//Helps link a software input Action-Id to an hardware input Button-Id.
    150 void InputTracker::LinkActionToKey(ACTION_TYPE Action, Key Button)
    151 {
    152     int ITIdx = GetButtonSettingIdx(Button);
     150void InputTracker::LinkActionToKey(Action a, Key k)
     151{
     152    int ITIdx = GetButtonSettingIdx(k);
    153153    if (ITIdx == -1)
    154154    {
    155155        ITIdx = m_input_assocation_list.Count();
    156         m_input_assocation_list << ButtonSetting(Button);
     156        m_input_assocation_list << ButtonSetting(k);
    157157    }
    158158
    159159    ButtonSetting &CurIT = m_input_assocation_list[ITIdx];
    160160
    161     int ASIdx = CurIT.GetActionSettingIdx(Action);
     161    int ASIdx = CurIT.GetActionSettingIdx(a);
    162162    if (ASIdx == -1)
    163163    {
    164164        ASIdx = CurIT.m_associated_action_list.Count();
    165         CurIT.m_associated_action_list << ActionSetting(Action);
    166     }
    167 }
    168 
    169 //Helps unlink a software input Action-Id to an hardware input Button-Id.
    170 void InputTracker::UnlinkAction(ACTION_TYPE Action)
     165        CurIT.m_associated_action_list << ActionSetting(a);
     166    }
     167}
     168
     169//Helps unlink a software input Action-Id to an hardware input k-Id.
     170void InputTracker::UnlinkAction(Action a)
    171171{
    172172    for (int i = 0; i < m_input_assocation_list.Count(); i++)
    173173    {
    174174        ButtonSetting &CurIT = m_input_assocation_list[i];
    175         int ASIdx = CurIT.GetActionSettingIdx(Action);
     175        int ASIdx = CurIT.GetActionSettingIdx(a);
    176176        if (ASIdx != -1)
    177177            CurIT.m_associated_action_list.Remove(ASIdx);
     
    180180
    181181//Returns the current status of a given action
    182 int InputTracker::GetStatus(ACTION_TYPE Action)
     182int InputTracker::GetStatus(Action a)
    183183{
    184184    for (int i = 0; i < m_input_assocation_list.Count(); i++)
    185185    {
    186186        ButtonSetting &CurIT = m_input_assocation_list[i];
    187         int ASIdx = CurIT.GetActionSettingIdx(Action);
     187        int ASIdx = CurIT.GetActionSettingIdx(a);
    188188        if (ASIdx != -1)
    189189        {
     
    199199
    200200//Returns TRUE if action status went from Active to Inactive this frame
    201 bool InputTracker::WasReleased(ACTION_TYPE Action)
     201bool InputTracker::WasReleased(Action a)
    202202{
    203203    for (int i = 0; i < m_input_assocation_list.Count(); i++)
    204204    {
    205205        ButtonSetting &CurIT = m_input_assocation_list[i];
    206         int ASIdx = CurIT.GetActionSettingIdx(Action);
     206        int ASIdx = CurIT.GetActionSettingIdx(a);
    207207        if (ASIdx != -1)
    208208        {
     
    218218
    219219//Returns TRUE if action status went from Inactive to Active this frame
    220 bool InputTracker::WasPressed(ACTION_TYPE Action)
     220bool InputTracker::WasPressed(Action a)
    221221{
    222222    for (int i = 0; i < m_input_assocation_list.Count(); i++)
    223223    {
    224224        ButtonSetting &CurIT = m_input_assocation_list[i];
    225         int ASIdx = CurIT.GetActionSettingIdx(Action);
     225        int ASIdx = CurIT.GetActionSettingIdx(a);
    226226        if (ASIdx != -1)
    227227        {
     
    236236
    237237//Returns the current status of a given action
    238 int InputTracker::GetStatus(Key Button)
    239 {
    240     return GetCurrentButtonStatus(Button);
     238int InputTracker::GetStatus(Key k)
     239{
     240    return GetCurrentButtonStatus(k);
    241241}
    242242
    243243//Returns TRUE if action status went from Active to Inactive this frame
    244 bool InputTracker::WasReleased(Key Button)
    245 {
    246     if (GetPreviousButtonStatus(Button) &&
    247         !GetCurrentButtonStatus(Button))
     244bool InputTracker::WasReleased(Key k)
     245{
     246    if (GetPreviousButtonStatus(k) &&
     247        !GetCurrentButtonStatus(k))
    248248        return true;
    249249    return false;
     
    251251
    252252//Returns TRUE if action status went from Inactive to Active this frame
    253 bool InputTracker::WasPressed(Key Button)
    254 {
    255     if (!GetPreviousButtonStatus(Button) &&
    256         GetCurrentButtonStatus(Button))
     253bool InputTracker::WasPressed(Key k)
     254{
     255    if (!GetPreviousButtonStatus(k) &&
     256        GetCurrentButtonStatus(k))
    257257        return true;
    258258    return false;
     
    303303{
    304304#if defined USE_SDL
    305 #if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION >= 3
     305#   if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION >= 3
    306306    Uint8 *keystate = SDL_GetKeyboardState(NULL);
    307 #else
     307#   else
    308308    Uint8 *keystate = SDL_GetKeyState(NULL);
    309 #endif
     309#   endif
    310310    return keystate[button];
    311311#else
     
    315315
    316316//Helps link a software input Action-Id to an hardware input Button-Id.
    317 void Input::LinkActionToKey(ACTION_TYPE Action, struct Key Button)
    318 {
    319     if (CheckInputTrackerInit())
    320         Input::m_input_tracker->LinkActionToKey(Action, Button);
     317void Input::LinkActionToKey(Action a, Key k)
     318{
     319    if (CheckInputTrackerInit())
     320        Input::m_input_tracker->LinkActionToKey(a, k);
    321321}
    322322
    323323//Helps unlink a software input Action-Id to an hardware input Button-Id.
    324 void Input::UnlinkAction(ACTION_TYPE Action)
    325 {
    326     if (CheckInputTrackerInit())
    327         Input::m_input_tracker->UnlinkAction(Action);
     324void Input::UnlinkAction(Action a)
     325{
     326    if (CheckInputTrackerInit())
     327        Input::m_input_tracker->UnlinkAction(a);
    328328}
    329329
    330330//Returns the current status of a given action
    331 int Input::GetStatus(ACTION_TYPE Action)
    332 {
    333     if (CheckInputTrackerInit())
    334         return Input::m_input_tracker->GetStatus(Action);
     331int Input::GetStatus(Action a)
     332{
     333    if (CheckInputTrackerInit())
     334        return Input::m_input_tracker->GetStatus(a);
    335335    return 0;
    336336}
    337337
    338338//Returns TRUE if action status when from Active to Inactive this frame
    339 bool Input::WasPressed(ACTION_TYPE Action)
    340 {
    341     if (CheckInputTrackerInit())
    342         return Input::m_input_tracker->WasPressed(Action);
     339bool Input::WasPressed(Action a)
     340{
     341    if (CheckInputTrackerInit())
     342        return Input::m_input_tracker->WasPressed(a);
    343343    return false;
    344344}
    345345
    346346//Returns TRUE if action status when from Active to Inactive this frame
    347 bool Input::WasReleased(ACTION_TYPE Action)
    348 {
    349     if (CheckInputTrackerInit())
    350         return Input::m_input_tracker->WasReleased(Action);
     347bool Input::WasReleased(Action a)
     348{
     349    if (CheckInputTrackerInit())
     350        return Input::m_input_tracker->WasReleased(a);
    351351    return false;
    352352}
    353353
    354354//Returns the current status of a given action
    355 int Input::GetStatus(Key Button)
    356 {
    357     if (CheckInputTrackerInit())
    358         return Input::m_input_tracker->GetStatus(Button);
     355int Input::GetStatus(Key k)
     356{
     357    if (CheckInputTrackerInit())
     358        return Input::m_input_tracker->GetStatus(k);
    359359    return 0;
    360360}
    361361
    362362//Returns TRUE if action status when from Active to Inactive this frame
    363 bool Input::WasPressed(Key Button)
    364 {
    365     if (CheckInputTrackerInit())
    366         return Input::m_input_tracker->WasPressed(Button);
     363bool Input::WasPressed(Key k)
     364{
     365    if (CheckInputTrackerInit())
     366        return Input::m_input_tracker->WasPressed(k);
    367367    return false;
    368368}
    369369
    370370//Returns TRUE if action status when from Active to Inactive this frame
    371 bool Input::WasReleased(Key Button)
    372 {
    373     if (CheckInputTrackerInit())
    374         return Input::m_input_tracker->WasReleased(Button);
     371bool Input::WasReleased(Key k)
     372{
     373    if (CheckInputTrackerInit())
     374        return Input::m_input_tracker->WasReleased(k);
    375375    return false;
    376376}
Note: See TracChangeset for help on using the changeset viewer.