Changeset 2925


Ignore:
Timestamp:
Sep 14, 2013, 8:55:42 PM (6 years ago)
Author:
benlitz
Message:

input: added a name the controllers, and a static Get() function to easily retrieve a registered controller

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/demos/tutorial/07_input.cpp

    r2923 r2925  
    2626    InputTutorial()
    2727    {
    28         m_controller = new Controller(KEY_MAX, AXIS_MAX);
     28        m_controller = new Controller("Default", KEY_MAX, AXIS_MAX);
    2929
    3030        m_keyboard = InputDevice::Get("Keyboard");
  • trunk/src/input/controller.cpp

    r2924 r2925  
    140140Array<Controller*> Controller::controllers;
    141141
    142 Controller::Controller(int nb_keys, int nb_axis)
     142Controller::Controller(char const* name, int nb_keys, int nb_axis)
    143143{
    144144    m_gamegroup = GAMEGROUP_BEFORE;
     145    m_name = name;
    145146    m_keys.Resize(nb_keys);
    146147    m_axis.Resize(nb_axis);
     
    148149    m_deactivate_nextframe = false;
    149150    m_active = false;
     151        if (Get(name) != nullptr)
     152        {
     153                Log::Warn("a controller with this name has already been registered");
     154        }
    150155    controllers.Push(this);
    151156}
     
    163168}
    164169
     170Controller* Controller::Get(char const* name)
     171{
     172    for (int i = 0; i < controllers.Count(); ++i)
     173    {
     174        if (controllers[i]->m_name == name)
     175            return controllers[i];
     176    }
     177    return nullptr;
     178}
     179
    165180void Controller::TickGame(float seconds)
    166181{
  • trunk/src/input/controller.h

    r2924 r2925  
    7474protected:
    7575    void Update() { m_previous = m_current; m_current = IsBound() ? RetrieveCurrentValue() : 0.0f; }
    76         float RetrieveCurrentValue();
     76    float RetrieveCurrentValue();
    7777
    7878    const InputDevice* m_device;
     
    8787
    8888
    89 class Controller : Entity
     89class Controller : public Entity
    9090{
    9191public:
    92     Controller(int nb_keys, int nb_axis);
     92    Controller(char const* name, int nb_keys, int nb_axis);
    9393    ~Controller();
    9494
     
    105105    AxisBinding& GetAxis(int index) { return m_axis[index]; }
    106106
     107    static Controller* Get(char const* name);
     108
    107109protected:
    108110    Array<KeyBinding> m_keys;
     
    111113private:
    112114    static Array<Controller*> controllers;
     115    String m_name;
    113116    bool m_activate_nextframe;
    114117    bool m_deactivate_nextframe;
  • trunk/test/btphystest.cpp

    r2910 r2925  
    7373
    7474    /* Register an input controller for the keyboard */
    75     m_controller = new Controller(KEY_MAX, 0);
     75    m_controller = new Controller("Default", KEY_MAX, 0);
    7676    m_controller->GetKey(KEY_MOVE_FORWARD).Bind("Keyboard", "Up");
    7777    m_controller->GetKey(KEY_MOVE_BACK).Bind("Keyboard", "Down");
  • trunk/test/meshviewer.cpp

    r2838 r2925  
    8383    {
    8484        /* Register an input controller for the keyboard */
    85         m_controller = new Controller(KEY_MAX, 0);
     85        m_controller = new Controller("Default", KEY_MAX, 0);
    8686
    8787        m_controller->GetKey(KEY_CAM_RESET).Bind("Keyboard", "Return");
Note: See TracChangeset for help on using the changeset viewer.