Changeset 1709


Ignore:
Timestamp:
Aug 9, 2012, 11:44:52 PM (7 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.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/eglapp.cpp

    r1689 r1709  
    2525#endif
    2626
     27#if defined USE_SDL
     28#   if defined HAVE_SDL_SDL_H
     29#      include <SDL/SDL.h>
     30#   else
     31#      include <SDL.h>
     32#   endif
     33#endif
     34
    2735#include "core.h"
    2836#include "lolgl.h"
    2937#include "eglapp.h"
     38#if defined USE_SDL
     39#   include "platform/sdl/sdlinput.h"
     40#endif
    3041
    3142namespace lol
     
    240251#   endif
    241252
     253#   if defined USE_SDL
     254    new SdlInput();
     255#   endif
     256
    242257    /* Initialise everything */
    243258    Ticker::Setup(fps);
  • 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.