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

input: some refactoring in the action bindings.

File:
1 edited

Legend:

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

    r1888 r1897  
    1919#include <cstring>
    2020#include <string.h>
     21
    2122#include "core.h"
     23
    2224#include "lol/math/vector.h"
    2325#include "input/stick.h"
     
    2628{
    2729
    28 typedef std::string ACTION_TYPE;
    29 static inline int ACTION_CMP(ACTION_TYPE a, ACTION_TYPE b) { return a.compare(b) == 0; }
     30typedef std::string Action;
     31static inline int ACTION_CMP(Action a, Action b) { return a.compare(b) == 0; }
    3032
    3133class WorldEntity;
     
    328330struct ActionSetting
    329331{
    330     ACTION_TYPE                m_action;
    331     float                    m_buffering_time;
    332     float                    m_buffered_since;
    333 
    334     ActionSetting(ACTION_TYPE NewAction) :
    335         m_action(NewAction),
     332    Action m_action;
     333    float m_buffering_time;
     334    float m_buffered_since;
     335
     336    ActionSetting(Action NewAction)
     337      : m_action(NewAction),
    336338        m_buffering_time(.0f),
    337339        m_buffered_since(.0f)
     
    341343struct ButtonSetting
    342344{
    343     Key                        m_raw_button;
    344     Array<ActionSetting>    m_associated_action_list;
     345    Key m_raw_button;
     346    Array<ActionSetting> m_associated_action_list;
    345347
    346348    ButtonSetting(Key NewRawButton)
    347         : m_raw_button(NewRawButton) { }
    348     int GetActionSettingIdx(ACTION_TYPE SearchAction);
     349      : m_raw_button(NewRawButton)
     350    { }
     351
     352    int GetActionSettingIdx(Action SearchAction);
    349353};
    350354
    351355class InputTracker : public Entity
    352356{
    353 
    354357    friend class Input;
    355358
     
    358361
    359362private:
    360     Array<uint8_t>            m_input_status;
    361     Array<ButtonSetting>    m_input_assocation_list;
    362 
    363     int                        GetButtonSettingIdx(struct Key Button);
    364     int                        GetCurrentButtonStatus(struct Key Button);
    365     int                        GetPreviousButtonStatus(struct Key Button);
    366     void                    UpdateActionStatus(float seconds);
     363    Array<uint8_t> m_input_status;
     364    Array<ButtonSetting> m_input_assocation_list;
     365
     366    int GetButtonSettingIdx(struct Key k);
     367    int GetCurrentButtonStatus(struct Key k);
     368    int GetPreviousButtonStatus(struct Key k);
     369    void UpdateActionStatus(float seconds);
    367370
    368371protected:
    369     virtual char const *    GetName()
     372    virtual char const * GetName()
    370373    {
    371374        return "<InputTracker>";
    372375    }
    373     virtual void            TickGame(float seconds)
     376    virtual void TickGame(float seconds)
    374377    {
    375378        Entity::TickGame(seconds);
     
    378381    }
    379382
    380     void                    LinkActionToKey(ACTION_TYPE Action, struct Key Button);
    381     void                    UnlinkAction(ACTION_TYPE Action);
    382     int                        GetStatus(ACTION_TYPE Action);
    383     bool                    WasPressed(ACTION_TYPE Action);
    384     bool                    WasReleased(ACTION_TYPE Action);
     383    void LinkActionToKey(Action a, struct Key k);
     384    void UnlinkAction(Action a);
     385    int GetStatus(Action a);
     386    bool WasPressed(Action a);
     387    bool WasReleased(Action a);
    385388
    386389    //You should probably use the Action System
    387     int                        GetStatus(Key Button);
    388     bool                    WasPressed(Key Button);
    389     bool                    WasReleased(Key Button);
     390    int GetStatus(Key k);
     391    bool WasPressed(Key k);
     392    bool WasReleased(Key k);
    390393};
    391394
     
    393396{
    394397private:
    395     static InputTracker*        m_input_tracker;
    396 
    397     static bool                    CheckInputTrackerInit()
     398    static InputTracker* m_input_tracker;
     399
     400    static bool CheckInputTrackerInit()
    398401    {
    399402        if (Input::m_input_tracker)
     
    414417
    415418    /* Action management */
    416     static void LinkActionToKey(ACTION_TYPE Action, struct Key Button);
    417     static void UnlinkAction(ACTION_TYPE Action);
    418     static int GetStatus(ACTION_TYPE Action);
    419     static bool    WasPressed(ACTION_TYPE Action);
    420     static bool WasReleased(ACTION_TYPE Action);
     419    static void LinkActionToKey(Action a, struct Key k);
     420    static void UnlinkAction(Action a);
     421    static int GetStatus(Action a);
     422    static bool WasPressed(Action a);
     423    static bool WasReleased(Action a);
    421424
    422425    /* Raw Button management. You should use actions. */
    423     static int GetStatus(Key Button);
    424     static bool    WasPressed(Key Button);
    425     static bool WasReleased(Key Button);
     426    static int GetStatus(Key k);
     427    static bool WasPressed(Key k);
     428    static bool WasReleased(Key k);
    426429
    427430    /* Entities can subscribe to events */
Note: See TracChangeset for help on using the changeset viewer.