Changeset 2812


Ignore:
Timestamp:
Jul 23, 2013, 9:39:21 PM (4 years ago)
Author:
lolbot
Message:

fixed 10 files out of 2754:

  • removed 386 CR characters
  • removed 4 trailing whitespaces
  • replaced 189 tabs with spaces
Location:
trunk
Files:
9 edited

Legend:

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

    r2810 r2812  
    216216    new Cube();
    217217
    218     controller = new Controller(KEY_MAX, AXIS_MAX); 
     218    controller = new Controller(KEY_MAX, AXIS_MAX);
    219219    controller->GetKey(KEY_MANUAL_ROTATION).Bind("Keyboard", "Space");
    220220    controller->GetKey(KEY_DRAG_MESH).Bind("Mouse", "ButtonLeft");
  • trunk/demos/tutorial/11_fractal.cpp

    r2810 r2812  
    176176        rcmplx worldmouse = m_center + rcmplx(ScreenToWorldOffset(m_mousepos));
    177177
    178                 uint32_t buttons = 0;
     178        uint32_t buttons = 0;
    179179        //uint32_t buttons = Input::GetMouseButtons();
    180180#if !defined __CELLOS_LV2__ && !defined _XBOX
  • trunk/src/input/controller.cpp

    r2810 r2812  
    2525void KeyBinding::Bind(const char* device_name, const char* key_name)
    2626{
    27         m_device = InputDevice::Get(device_name);
    28         if (!m_device)
    29         {
    30                 Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name);
    31                 return;
    32         }
     27    m_device = InputDevice::Get(device_name);
     28    if (!m_device)
     29    {
     30        Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name);
     31        return;
     32    }
    3333
    34         m_keyindex = m_device->GetKeyIndex(key_name);
     34    m_keyindex = m_device->GetKeyIndex(key_name);
    3535
    36         if (m_keyindex < 0)
    37         {
    38                 Log::Warn("Trying to bind controller to key %s.%s which doesn't exist", device_name, key_name);
    39         }
     36    if (m_keyindex < 0)
     37    {
     38        Log::Warn("Trying to bind controller to key %s.%s which doesn't exist", device_name, key_name);
     39    }
    4040}
    4141
     
    4545void AxisBinding::Bind(const char* device_name, const char* axis_name)
    4646{
    47         m_device = InputDevice::Get(device_name);
    48         if (!m_device)
    49         {
    50                 Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name);
    51                 return;
    52         }
     47    m_device = InputDevice::Get(device_name);
     48    if (!m_device)
     49    {
     50        Log::Warn("Trying to bind controller to device %s which doesn't exist", device_name);
     51        return;
     52    }
    5353
    54         m_axisindex = m_device->GetAxisIndex(axis_name);
     54    m_axisindex = m_device->GetAxisIndex(axis_name);
    5555
    56         if (m_axisindex < 0)
    57         {
    58                 Log::Warn("Trying to bind controller to axis %s.%s which doesn't exist", device_name, axis_name);
    59         }
     56    if (m_axisindex < 0)
     57    {
     58        Log::Warn("Trying to bind controller to axis %s.%s which doesn't exist", device_name, axis_name);
     59    }
    6060}
    6161
     
    6868Controller::Controller(int nb_keys, int nb_axis)
    6969{
    70         m_gamegroup = GAMEGROUP_BEFORE;
    71         m_nb_keys = nb_keys;
    72         m_nb_axis = nb_axis;
    73         m_keys = new KeyBinding[m_nb_keys];
    74         m_axis = new AxisBinding[m_nb_axis];
    75         m_activate_nextframe = false;
    76         m_deactivate_nextframe = false;
    77         m_active = false;
    78         controllers.Push(this);
     70    m_gamegroup = GAMEGROUP_BEFORE;
     71    m_nb_keys = nb_keys;
     72    m_nb_axis = nb_axis;
     73    m_keys = new KeyBinding[m_nb_keys];
     74    m_axis = new AxisBinding[m_nb_axis];
     75    m_activate_nextframe = false;
     76    m_deactivate_nextframe = false;
     77    m_active = false;
     78    controllers.Push(this);
    7979}
    8080
    8181Controller::~Controller()
    8282{
    83         for (int i = 0; i < controllers.Count(); ++i)
    84         {
    85                 if (controllers[i] == this)
    86                 {
    87                         controllers.Remove(i);
    88                         break;
    89                 }
    90         }
     83    for (int i = 0; i < controllers.Count(); ++i)
     84    {
     85        if (controllers[i] == this)
     86        {
     87            controllers.Remove(i);
     88            break;
     89        }
     90    }
    9191}
    9292
    9393void Controller::TickGame(float seconds)
    9494{
    95         Entity::TickGame(seconds);
     95    Entity::TickGame(seconds);
    9696
    97         for (int i = 0; i < m_nb_keys; ++i)
    98         {
    99                 m_keys[i].Update();
    100         }
     97    for (int i = 0; i < m_nb_keys; ++i)
     98    {
     99        m_keys[i].Update();
     100    }
    101101
    102         for (int i = 0; i < m_nb_axis; ++i)
    103         {
    104                 m_axis[i].Update();
    105         }
     102    for (int i = 0; i < m_nb_axis; ++i)
     103    {
     104        m_axis[i].Update();
     105    }
    106106
    107         if (m_activate_nextframe)
    108                 m_active = true;
     107    if (m_activate_nextframe)
     108        m_active = true;
    109109
    110         if (m_deactivate_nextframe)
    111                 m_active = false;
     110    if (m_deactivate_nextframe)
     111        m_active = false;
    112112
    113         m_activate_nextframe = false;
    114         m_deactivate_nextframe = false;
     113    m_activate_nextframe = false;
     114    m_deactivate_nextframe = false;
    115115}
    116116
    117117void Controller::Activate()
    118118{
    119         m_activate_nextframe = true;
    120         m_deactivate_nextframe = false;
     119    m_activate_nextframe = true;
     120    m_deactivate_nextframe = false;
    121121}
    122122
    123123void Controller::Deactivate()
    124124{
    125         m_deactivate_nextframe = true;
    126         m_activate_nextframe = false;
     125    m_deactivate_nextframe = true;
     126    m_activate_nextframe = false;
    127127}
    128128
    129129Array<Controller*> Controller::DeactivateAll()
    130130{
    131         Array<Controller*> result;
     131    Array<Controller*> result;
    132132
    133         for (int i = 0; i < controllers.Count(); ++i)
    134         {
    135                 if (controllers[i]->m_active || controllers[i]->m_activate_nextframe)
    136                 {
    137                         result.Push(controllers[i]);
    138                         controllers[i]->Deactivate();
    139                 }
    140         }
     133    for (int i = 0; i < controllers.Count(); ++i)
     134    {
     135        if (controllers[i]->m_active || controllers[i]->m_activate_nextframe)
     136        {
     137            result.Push(controllers[i]);
     138            controllers[i]->Deactivate();
     139        }
     140    }
    141141
    142         return result;
     142    return result;
    143143}
    144144
  • trunk/src/input/controller.h

    r2810 r2812  
    2222{
    2323public:
    24         KeyBinding() : m_current(false), m_previous(false), m_device(nullptr) {}
     24    KeyBinding() : m_current(false), m_previous(false), m_device(nullptr) {}
    2525
    26         bool IsDown() const { return m_current; }
    27         bool IsUp() const { return !m_current; }
    28         bool IsPressed() const { return m_current && !m_previous; }
    29         bool IsReleased() const { return !m_current && m_previous; }
     26    bool IsDown() const { return m_current; }
     27    bool IsUp() const { return !m_current; }
     28    bool IsPressed() const { return m_current && !m_previous; }
     29    bool IsReleased() const { return !m_current && m_previous; }
    3030
    31         void Bind(const char* device_name, const char* key_name);
     31    void Bind(const char* device_name, const char* key_name);
    3232
    3333protected:
    34         void Update() { m_previous = m_current; m_current = m_device ? m_device->GetKey(m_keyindex) : false; }
     34    void Update() { m_previous = m_current; m_current = m_device ? m_device->GetKey(m_keyindex) : false; }
    3535
    36         const InputDevice* m_device;
    37         int m_keyindex;
    38         bool m_current;
    39         bool m_previous;
     36    const InputDevice* m_device;
     37    int m_keyindex;
     38    bool m_current;
     39    bool m_previous;
    4040
    41         friend class Controller;
     41    friend class Controller;
    4242};
    4343
     
    4545{
    4646public:
    47         AxisBinding() : m_current(0.0f), m_previous(0.0f), m_device(nullptr) {}
     47    AxisBinding() : m_current(0.0f), m_previous(0.0f), m_device(nullptr) {}
    4848
    49         float GetValue() const { return m_current; }
    50         float GetDelta() const { return m_current - m_previous; }
     49    float GetValue() const { return m_current; }
     50    float GetDelta() const { return m_current - m_previous; }
    5151
    52         void Bind(const char* device_name, const char* axis_name);
     52    void Bind(const char* device_name, const char* axis_name);
    5353
    5454protected:
    55         void Update() { m_previous = m_current; m_current = m_device ? m_device->GetAxis(m_axisindex) : 0.0f; }
     55    void Update() { m_previous = m_current; m_current = m_device ? m_device->GetAxis(m_axisindex) : 0.0f; }
    5656
    57         const InputDevice* m_device;
    58         int m_axisindex;
    59         float m_current;
    60         float m_previous;
     57    const InputDevice* m_device;
     58    int m_axisindex;
     59    float m_current;
     60    float m_previous;
    6161
    62         friend class Controller;
     62    friend class Controller;
    6363};
    6464
     
    6767{
    6868public:
    69         Controller(int nb_keys, int nb_axis);
    70         ~Controller();
     69    Controller(int nb_keys, int nb_axis);
     70    ~Controller();
    7171
    72         virtual void TickGame(float seconds);
     72    virtual void TickGame(float seconds);
    7373
    74         /** Activate the controller on next frame */
    75         void Activate();
    76         /** Deactivate the controller on next frame */
    77         void Deactivate();
    78         /** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */
    79         static Array<Controller*> DeactivateAll();
     74    /** Activate the controller on next frame */
     75    void Activate();
     76    /** Deactivate the controller on next frame */
     77    void Deactivate();
     78    /** Deactivate every active controller on next frame and return an array of deactivated (previously active) controllers */
     79    static Array<Controller*> DeactivateAll();
    8080
    81         KeyBinding& GetKey(int index) { ASSERT(index >= 0 && index < m_nb_keys); return m_keys[index]; }
    82         AxisBinding& GetAxis(int index) { ASSERT(index >= 0 && index < m_nb_axis); return m_axis[index]; }
    83  
     81    KeyBinding& GetKey(int index) { ASSERT(index >= 0 && index < m_nb_keys); return m_keys[index]; }
     82    AxisBinding& GetAxis(int index) { ASSERT(index >= 0 && index < m_nb_axis); return m_axis[index]; }
     83
    8484protected:
    85         KeyBinding* m_keys;
    86         AxisBinding* m_axis;
    87         int m_nb_keys;
    88         int m_nb_axis;
    89        
     85    KeyBinding* m_keys;
     86    AxisBinding* m_axis;
     87    int m_nb_keys;
     88    int m_nb_axis;
     89
    9090private:
    91         static Array<Controller*> controllers;
    92         bool m_activate_nextframe;
    93         bool m_deactivate_nextframe;
    94         bool m_active;
     91    static Array<Controller*> controllers;
     92    bool m_activate_nextframe;
     93    bool m_deactivate_nextframe;
     94    bool m_active;
    9595};
    9696
  • trunk/src/input/inputdevice.h

    r2810 r2812  
    5656    /** Get an input device by its name */
    5757    static InputDevice* Get(const char* name) { return GetDevice(name); }
    58         /** Set whether the mouse cursor should be captured. */
    59         static void CaptureMouse(bool activated) { m_capturemouse = activated; }
     58    /** Set whether the mouse cursor should be captured. */
     59    static void CaptureMouse(bool activated) { m_capturemouse = activated; }
    6060
    6161protected:
    62         // TODO: hide all of this in a InputDeviceData?
     62    // TODO: hide all of this in a InputDeviceData?
    6363
    6464    String m_name;
     
    7575    Array<vec2, ivec2> m_cursors;
    7676
    77         static bool m_capturemouse;
     77    static bool m_capturemouse;
    7878
    7979    InputDevice(const char* name) : m_name(name)
  • trunk/src/input/inputdevice_internal.h

    r2810 r2812  
    3030
    3131    void SetKey(int index, bool state) { m_keys[index] = state; }
    32         void SetAxis(int index, float value) { m_axis[index].m1 = value; }
    33         void SetCursor(int index, const vec2& position, const ivec2& pixel) { m_cursors[index].m1 = position; m_cursors[index].m2 = pixel; }
     32    void SetAxis(int index, float value) { m_axis[index].m1 = value; }
     33    void SetCursor(int index, const vec2& position, const ivec2& pixel) { m_cursors[index].m1 = position; m_cursors[index].m2 = pixel; }
    3434
    35         static bool GetMouseCapture() { return m_capturemouse; }
     35    static bool GetMouseCapture() { return m_capturemouse; }
    3636
    37         static InputDeviceInternal* CreateStandardKeyboard();
     37    static InputDeviceInternal* CreateStandardKeyboard();
    3838    static InputDeviceInternal* CreateStandardMouse();
    3939};
  • trunk/src/platform/d3d9/d3d9input.cpp

    r2810 r2812  
    6060            continue;
    6161#if defined LOL_INPUT_V2
    62                 // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX...
    63                 InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
    64                 for (int j = 0; j < 4; ++j)
    65                         stick->AddAxis(String::Printf("Axis%d", j+1).C());
    66                 for (int j = 0; j < 16; ++j)
    67                         stick->AddKey(String::Printf("Button%d", j+1).C());
     62        // TODO: we can put more friendly name here, such as LeftAxisX, ButtonX...
     63        InputDeviceInternal* stick = new InputDeviceInternal(String::Printf("Joystick%d", i+1).C());
     64        for (int j = 0; j < 4; ++j)
     65            stick->AddAxis(String::Printf("Axis%d", j+1).C());
     66        for (int j = 0; j < 16; ++j)
     67            stick->AddKey(String::Printf("Button%d", j+1).C());
    6868
    69                 m_data->m_joysticks.Push(i, stick);
     69        m_data->m_joysticks.Push(i, stick);
    7070#else
    7171        Stick *stick = Input::CreateStick();
     
    8787    {
    8888#if defined LOL_INPUT_V2
    89                 delete m_data->m_joysticks[0].m2;
     89        delete m_data->m_joysticks[0].m2;
    9090#else
    91                 Input::DestroyStick(m_data->m_joysticks[0].m2);
     91        Input::DestroyStick(m_data->m_joysticks[0].m2);
    9292#endif // LOL_INPUT_V2
    93                 m_data->m_joysticks.Remove(0);
     93        m_data->m_joysticks.Remove(0);
    9494    }
    9595#endif
     
    120120        for (int b = 0; b < 16; b++)
    121121#if defined LOL_INPUT_V2
    122                         m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
     122            m_data->m_joysticks[i].m2->SetKey(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
    123123#else
    124                         m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
     124            m_data->m_joysticks[i].m2->SetButton(b, ((uint16_t)(state.Gamepad.wButtons) >> b) & 1);
    125125#endif // LOL_INPUT_V2
    126         }
     126    }
    127127#endif
    128128}
  • trunk/src/platform/sdl/sdlapp.cpp

    r2810 r2812  
    6868
    6969#   ifdef LOL_INPUT_V2
    70         const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
    71         int screen_w = vidinfo->current_w;
    72         int screen_h = vidinfo->current_h;
     70    const SDL_VideoInfo* vidinfo = SDL_GetVideoInfo();
     71    int screen_w = vidinfo->current_w;
     72    int screen_h = vidinfo->current_h;
    7373#   endif
    7474
     
    8585    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
    8686#   ifdef LOL_INPUT_V2
    87         // TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode
     87    // TODO: when implementing fullscreen, be sure to overwrite screen_w and screen_h with the value of vidinfo after the call to SDL_SetVideoMode
    8888#   endif
    8989    SDL_Surface *video = SDL_SetVideoMode(res.x, res.y, 0, SDL_OPENGL);
     
    113113    new SdlInput(video->w, video->h, screen_w, screen_h);
    114114#   else
    115         new SdlInput();
     115    new SdlInput();
    116116#   endif
    117117#endif
  • trunk/src/platform/sdl/sdlinput.cpp

    r2811 r2812  
    5454        m_prevmouse(ivec2(0)),
    5555        m_app_w((float)app_w),
    56         m_app_h((float)app_h), 
     56        m_app_h((float)app_h),
    5757        m_screen_w((float)screen_w),
    5858        m_screen_h((float)screen_h)
     
    240240
    241241#   if !SDL_FORCE_POLL_JOYSTICK
    242 #        ifdef LOL_INPUT_V2
     242#    ifdef LOL_INPUT_V2
    243243        case SDL_JOYAXISMOTION:
    244244            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
     
    249249            m_joysticks[event.jbutton.which].m2->SetKey(event.jbutton.button, event.jbutton.state);
    250250            break;
    251 #        else // !LOL_INPUT_V2
     251#    else // !LOL_INPUT_V2
    252252        case SDL_JOYAXISMOTION:
    253253            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
     
    258258            m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state);
    259259            break;
    260 #        endif // LOL_INPUT_V2
     260#    endif // LOL_INPUT_V2
    261261#   endif
    262262        }
     
    291291#   else // !LOL_INPUT_V2
    292292    Input::SetMousePos(mouse);
    293 #       endif // LOL_INPUT_V2
     293#    endif // LOL_INPUT_V2
    294294
    295295#   if SDL_VERSION_ATLEAST(1,3,0)
     
    300300
    301301    int keyindex = 0;
    302 #       ifdef LOL_INPUT_V2
    303 #       define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0);
    304 #       if !defined SDLK_WORLD_0
    305 #        define KEY_DISABLE_WORLD
     302#    ifdef LOL_INPUT_V2
     303#    define KEY_FUNC(name, index) m_keyboard->SetKey(keyindex++, sdlstate[index] != 0);
     304#    if !defined SDLK_WORLD_0
     305#    define KEY_DISABLE_WORLD
    306306#   endif // !SDLK_WORLD_0
    307 #       include "input/keys.h"
    308 #       undef KEY_FUNC
    309 #       else // !LOL_INPUT_V2
     307#    include "input/keys.h"
     308#    undef KEY_FUNC
     309#    else // !LOL_INPUT_V2
    310310
    311311    /* Send the whole keyboard state to the input system */
     
    555555
    556556    UNUSED(seconds);
    557 #       endif // LOL_INPUT_V2
     557#    endif // LOL_INPUT_V2
    558558
    559559#endif // USE_SDL
Note: See TracChangeset for help on using the changeset viewer.