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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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{
Note: See TracChangeset for help on using the changeset viewer.