Ignore:
Timestamp:
Aug 9, 2012, 11:44:52 PM (10 years ago)
Author:
sam
Message:

input: switch SDL joystick handling mode to polling, because we won't get
any events if there is no X window.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/platform/sdl/sdlinput.cpp

    r1692 r1709  
    2424#include "sdlinput.h"
    2525
     26/* We force joystick polling because no events are received when
     27 * there is no SDL display (eg. on the Raspberry Pi). */
     28#define SDL_FORCE_POLL_JOYSTICK 1
     29
    2630namespace lol
    2731{
     
    5458    SDL_Init(SDL_INIT_TIMER | SDL_INIT_JOYSTICK);
    5559
     60#   if SDL_FORCE_POLL_JOYSTICK
     61    SDL_JoystickEventState(SDL_QUERY);
     62#   else
     63    SDL_JoystickEventState(SDL_ENABLE);
     64#   endif
     65
    5666    /* Register all the joysticks we can find, and let the input
    5767     * system decide what it wants to track. */
    58     SDL_JoystickEventState(SDL_ENABLE);
    5968    for (int i = 0; i < SDL_NumJoysticks(); i++)
    6069    {
     
    126135    ivec2 mouse = SdlInputData::GetMousePos();;
    127136    Input::SetMousePos(mouse);
     137
     138#   if SDL_FORCE_POLL_JOYSTICK
     139    /* Pump all joystick events because no event is coming to us. */
     140    SDL_JoystickUpdate();
     141    for (int j = 0; j < m_joysticks.Count(); j++)
     142    {
     143        for (int i = 0; i < SDL_JoystickNumButtons(m_joysticks[j].m1); i++)
     144            m_joysticks[j].m2->SetButton(i, SDL_JoystickGetButton(m_joysticks[j].m1, i));
     145        for (int i = 0; i < SDL_JoystickNumAxes(m_joysticks[j].m1); i++)
     146            m_joysticks[j].m2->SetAxis(i, (float)SDL_JoystickGetAxis(m_joysticks[j].m1, i) / 32768.f);
     147    }
     148#   endif
    128149
    129150    /* Handle keyboard and WM events */
     
    154175        }
    155176
     177#   if !SDL_FORCE_POLL_JOYSTICK
    156178        case SDL_JOYAXISMOTION:
    157179            m_joysticks[event.jaxis.which].m2->SetAxis(event.jaxis.axis, (float)event.jaxis.value / 32768.f);
     
    162184            m_joysticks[event.jbutton.which].m2->SetButton(event.jbutton.button, event.jbutton.state);
    163185            break;
     186#   endif
    164187        }
    165188    }
Note: See TracChangeset for help on using the changeset viewer.