~ubuntu-branches/ubuntu/trusty/libsdl1.2/trusty

« back to all changes in this revision

Viewing changes to src/joystick/SDL_joystick.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2009-12-08 01:50:15 UTC
  • mfrom: (2.1.6 experimental)
  • Revision ID: james.westby@ubuntu.com-20091208015015-mr68dcbbctrhi5at
Tags: 1.2.14-1ubuntu1
* Merge from Debian experimental, remaining changes:
  + debian/control:
    + add libglu1-mesa-dev as a build dependency, so SDL gets built
      with OpenGL support (LP: #328932)
    - dropped build-depends on libarts1-dev, libartsc0-dev. These
      packages will disappear as part of the arts removal
      (LP: #320915)
    - Removed Package: libsdl1.2debian-arts section entirely
    - dropped depends on libsdl1.2debian-arts (= ${binary:Version})
      for libsdl1.2-debian
    - dropped recommends on libartsc0-dev for libsdl1.2-dev
    - Remove svgalib support.
  + debian/rules:
    + set --enable-arts-shared=no and --enable-arts=no in confflags
    - removed --disable-audio-arts from udeb_confflags
    - dropped arts from FLAVOURS=
    + Link using -Wl,-Bsymbolic-functions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
    SDL - Simple DirectMedia Layer
3
 
    Copyright (C) 1997-2006 Sam Lantinga
 
3
    Copyright (C) 1997-2009 Sam Lantinga
4
4
 
5
5
    This library is free software; you can redistribute it and/or
6
6
    modify it under the terms of the GNU Lesser General Public
112
112
 
113
113
        /* Create and initialize the joystick */
114
114
        joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick));
115
 
        if ( joystick != NULL ) {
116
 
                SDL_memset(joystick, 0, (sizeof *joystick));
117
 
                joystick->index = device_index;
118
 
                if ( SDL_SYS_JoystickOpen(joystick) < 0 ) {
119
 
                        SDL_free(joystick);
120
 
                        joystick = NULL;
121
 
                } else {
122
 
                        if ( joystick->naxes > 0 ) {
123
 
                                joystick->axes = (Sint16 *)SDL_malloc
124
 
                                        (joystick->naxes*sizeof(Sint16));
125
 
                        }
126
 
                        if ( joystick->nhats > 0 ) {
127
 
                                joystick->hats = (Uint8 *)SDL_malloc
128
 
                                        (joystick->nhats*sizeof(Uint8));
129
 
                        }
130
 
                        if ( joystick->nballs > 0 ) {
131
 
                                joystick->balls = (struct balldelta *)SDL_malloc
132
 
                                  (joystick->nballs*sizeof(*joystick->balls));
133
 
                        }
134
 
                        if ( joystick->nbuttons > 0 ) {
135
 
                                joystick->buttons = (Uint8 *)SDL_malloc
136
 
                                        (joystick->nbuttons*sizeof(Uint8));
137
 
                        }
138
 
                        if ( ((joystick->naxes > 0) && !joystick->axes)
139
 
                          || ((joystick->nhats > 0) && !joystick->hats)
140
 
                          || ((joystick->nballs > 0) && !joystick->balls)
141
 
                          || ((joystick->nbuttons > 0) && !joystick->buttons)) {
142
 
                                SDL_OutOfMemory();
143
 
                                SDL_JoystickClose(joystick);
144
 
                                joystick = NULL;
145
 
                        }
146
 
                        if ( joystick->axes ) {
147
 
                                SDL_memset(joystick->axes, 0,
148
 
                                        joystick->naxes*sizeof(Sint16));
149
 
                        }
150
 
                        if ( joystick->hats ) {
151
 
                                SDL_memset(joystick->hats, 0,
152
 
                                        joystick->nhats*sizeof(Uint8));
153
 
                        }
154
 
                        if ( joystick->balls ) {
155
 
                                SDL_memset(joystick->balls, 0,
156
 
                                  joystick->nballs*sizeof(*joystick->balls));
157
 
                        }
158
 
                        if ( joystick->buttons ) {
159
 
                                SDL_memset(joystick->buttons, 0,
160
 
                                        joystick->nbuttons*sizeof(Uint8));
161
 
                        }
162
 
                }
163
 
        }
164
 
        if ( joystick ) {
165
 
                /* Add joystick to list */
166
 
                ++joystick->ref_count;
167
 
                SDL_Lock_EventThread();
168
 
                for ( i=0; SDL_joysticks[i]; ++i )
169
 
                        /* Skip to next joystick */;
170
 
                SDL_joysticks[i] = joystick;
171
 
                SDL_Unlock_EventThread();
172
 
        }
 
115
        if ( !joystick ) {
 
116
                return(NULL);
 
117
        }
 
118
 
 
119
        SDL_memset(joystick, 0, (sizeof *joystick));
 
120
        joystick->index = device_index;
 
121
        if ( SDL_SYS_JoystickOpen(joystick) < 0 ) {
 
122
                SDL_free(joystick);
 
123
                return(NULL);
 
124
        }
 
125
 
 
126
        if ( joystick->naxes > 0 ) {
 
127
                joystick->axes = (Sint16 *)SDL_malloc
 
128
                        (joystick->naxes*sizeof(Sint16));
 
129
        }
 
130
        if ( joystick->nhats > 0 ) {
 
131
                joystick->hats = (Uint8 *)SDL_malloc
 
132
                        (joystick->nhats*sizeof(Uint8));
 
133
        }
 
134
        if ( joystick->nballs > 0 ) {
 
135
                joystick->balls = (struct balldelta *)SDL_malloc
 
136
                        (joystick->nballs*sizeof(*joystick->balls));
 
137
        }
 
138
        if ( joystick->nbuttons > 0 ) {
 
139
                joystick->buttons = (Uint8 *)SDL_malloc
 
140
                        (joystick->nbuttons*sizeof(Uint8));
 
141
        }
 
142
        if ( ((joystick->naxes > 0) && !joystick->axes)
 
143
          || ((joystick->nhats > 0) && !joystick->hats)
 
144
          || ((joystick->nballs > 0) && !joystick->balls)
 
145
          || ((joystick->nbuttons > 0) && !joystick->buttons)) {
 
146
                SDL_OutOfMemory();
 
147
                SDL_JoystickClose(joystick);
 
148
                return(NULL);
 
149
        }
 
150
 
 
151
        if ( joystick->axes ) {
 
152
                SDL_memset(joystick->axes, 0,
 
153
                        joystick->naxes*sizeof(Sint16));
 
154
        }
 
155
        if ( joystick->hats ) {
 
156
                SDL_memset(joystick->hats, 0,
 
157
                        joystick->nhats*sizeof(Uint8));
 
158
        }
 
159
        if ( joystick->balls ) {
 
160
                SDL_memset(joystick->balls, 0,
 
161
                        joystick->nballs*sizeof(*joystick->balls));
 
162
        }
 
163
        if ( joystick->buttons ) {
 
164
                SDL_memset(joystick->buttons, 0,
 
165
                        joystick->nbuttons*sizeof(Uint8));
 
166
        }
 
167
 
 
168
        /* Add joystick to list */
 
169
        ++joystick->ref_count;
 
170
        SDL_Lock_EventThread();
 
171
        for ( i=0; SDL_joysticks[i]; ++i )
 
172
                /* Skip to next joystick */ ;
 
173
        SDL_joysticks[i] = joystick;
 
174
        SDL_Unlock_EventThread();
 
175
 
173
176
        return(joystick);
174
177
}
175
178
 
373
376
        /* Remove joystick from list */
374
377
        for ( i=0; SDL_joysticks[i]; ++i ) {
375
378
                if ( joystick == SDL_joysticks[i] ) {
376
 
                        SDL_memcpy(&SDL_joysticks[i], &SDL_joysticks[i+1],
 
379
                        SDL_memmove(&SDL_joysticks[i], &SDL_joysticks[i+1],
377
380
                               (SDL_numjoysticks-i)*sizeof(joystick));
378
381
                        break;
379
382
                }