~ubuntu-branches/ubuntu/utopic/blender/utopic-proposed

« back to all changes in this revision

Viewing changes to source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp

  • Committer: Package Import Robot
  • Author(s): Matthias Klose
  • Date: 2014-02-19 11:24:23 UTC
  • mfrom: (14.2.23 sid)
  • Revision ID: package-import@ubuntu.com-20140219112423-rkmaz2m7ha06d4tk
Tags: 2.69-3ubuntu1
* Merge with Debian; remaining changes:
  - Configure without OpenImageIO on armhf, as it is not available on
    Ubuntu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
#include "SCA_Joystick.h"
40
40
#include "SCA_JoystickPrivate.h"
41
41
 
 
42
#include "BLI_path_util.h"
 
43
 
42
44
SCA_Joystick::SCA_Joystick(short int index)
43
45
        :
44
46
        m_joyindex(index),
88
90
        if (m_refCount == 0) 
89
91
        {
90
92
                int i;
 
93
 
91
94
                /* The video subsystem is required for joystick input to work. However,
92
 
                 * when GHOST is running under SDL, video is initialized elsewhere.
93
 
                 * Do this once only. */
 
95
                 * when GHOST is running under SDL, video is initialized elsewhere. We
 
96
                 * also need to set the videodriver to dummy, and do it here to avoid
 
97
                 * interfering with addons that may use SDL too.
 
98
                 *
 
99
                 * We also init SDL once only. */
94
100
#  ifdef WITH_GHOST_SDL
95
 
                if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1 ) {
 
101
                int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1 );
96
102
#  else
97
 
                if (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) == -1 ) {
 
103
                /* set and restore environment variable */
 
104
                char *videodriver = getenv("SDL_VIDEODRIVER");
 
105
                BLI_setenv("SDL_VIDEODRIVER", "dummy");
 
106
 
 
107
                int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) != -1 );
 
108
 
 
109
                BLI_setenv("SDL_VIDEODRIVER", videodriver);
98
110
#  endif
 
111
 
 
112
                if (!success) {
99
113
                        JOYSTICK_ECHO("Error-Initializing-SDL: " << SDL_GetError());
100
114
                        return NULL;
101
115
                }
278
292
{
279
293
#ifdef WITH_SDL
280
294
        if (m_isinit) {
 
295
#if SDL_VERSION_ATLEAST(2, 0, 0)
 
296
                if (SDL_JoystickGetAttached(m_private->m_joystick)) {
 
297
#else
281
298
                if (SDL_JoystickOpened(m_joyindex)) {
 
299
#endif
282
300
                        JOYSTICK_ECHO("Closing-joystick " << m_joyindex);
283
301
                        SDL_JoystickClose(m_private->m_joystick);
284
302
                }
290
308
int SCA_Joystick::Connected(void)
291
309
{
292
310
#ifdef WITH_SDL
293
 
        if (m_isinit && SDL_JoystickOpened(m_joyindex))
 
311
        if (m_isinit
 
312
#if SDL_VERSION_ATLEAST(2, 0, 0)
 
313
                && SDL_JoystickGetAttached(m_private->m_joystick))
 
314
#else
 
315
            && SDL_JoystickOpened(m_joyindex))
 
316
#endif
294
317
                return 1;
295
318
#endif
296
319
        return 0;
328
351
const char *SCA_Joystick::GetName()
329
352
{
330
353
#ifdef WITH_SDL
 
354
#if SDL_VERSION_ATLEAST(2, 0, 0)
 
355
        return SDL_JoystickName(m_private->m_joystick);
 
356
#else
331
357
        return SDL_JoystickName(m_joyindex);
 
358
#endif
332
359
#else /* WITH_SDL */
333
360
        return "";
334
361
#endif /* WITH_SDL */