comparison src/haptic/SDL_haptic.c @ 2477:97f75ea43a93 gsoc2008_force_feedback

Starting to add infrastructure to handle haptic effects.
author Edgar Simo <bobbens@gmail.com>
date Mon, 30 Jun 2008 16:48:16 +0000
parents 242d8a668ebb
children 4fd783e0f34b
comparison
equal deleted inserted replaced
2476:242d8a668ebb 2477:97f75ea43a93
95 SDL_SetError("There are %d haptic devices available", SDL_numhaptics); 95 SDL_SetError("There are %d haptic devices available", SDL_numhaptics);
96 return NULL; 96 return NULL;
97 } 97 }
98 98
99 /* If the haptic is already open, return it */ 99 /* If the haptic is already open, return it */
100 for (i = 0; SDL_haptics[i]; ++i) { 100 for (i=0; SDL_haptics[i]; i++) {
101 if (device_index == SDL_haptics[i]->index) { 101 if (device_index == SDL_haptics[i]->index) {
102 haptic = SDL_haptics[i]; 102 haptic = SDL_haptics[i];
103 ++haptic->ref_count; 103 ++haptic->ref_count;
104 return haptic; 104 return haptic;
105 } 105 }
106 } 106 }
107 107
108 /* Create and initialize the haptic */ 108 /* Create the haptic device */
109 haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic)); 109 haptic = (SDL_Haptic *) SDL_malloc((sizeof *haptic));
110 if (haptic != NULL) { 110 if (haptic == NULL) {
111 SDL_memset(haptic, 0, (sizeof *haptic)); 111 SDL_OutOfMemory();
112 haptic->index = device_index; 112 return NULL;
113 if (SDL_SYS_HapticOpen(haptic) < 0) { 113 }
114 SDL_free(haptic); 114
115 haptic = NULL; 115 /* Initialize the haptic device */
116 } 116 SDL_memset(haptic, 0, (sizeof *haptic));
117 } 117 haptic->index = device_index;
118 if (haptic) { 118 if (SDL_SYS_HapticOpen(haptic) < 0) {
119 /* Add haptic to list */ 119 SDL_free(haptic);
120 ++haptic->ref_count; 120 return NULL;
121 for (i = 0; SDL_haptics[i]; ++i) 121 }
122 /* Skip to next haptic */ ; 122
123 SDL_haptics[i] = haptic; 123 /* Add haptic to list */
124 } 124 ++haptic->ref_count;
125 for (i = 0; SDL_haptics[i]; ++i)
126 /* Skip to next haptic */ ;
127 SDL_haptics[i] = haptic;
128
125 return haptic; 129 return haptic;
126 } 130 }
127 131
128 132
129 /* 133 /*
190 if (SDL_haptics != NULL) { 194 if (SDL_haptics != NULL) {
191 SDL_free(SDL_haptics); 195 SDL_free(SDL_haptics);
192 SDL_haptics = NULL; 196 SDL_haptics = NULL;
193 } 197 }
194 } 198 }
199
200
201 /*
202 * Creates a new haptic effect.
203 */
204 int
205 SDL_HapticNewEffect(SDL_Haptic * haptic, SDL_HapticEffect * effect)
206 {
207 int i;
208
209 /* Check for device validity. */
210 if (!ValidHaptic(&haptic)) {
211 return -1;
212 }
213
214 /* See if there's a free slot */
215 for (i=0; i<haptic->neffects; i++) {
216 if (haptic->effects[i].hweffect == NULL) {
217
218 /* Now let the backend create the real effect */
219 if (SDL_SYS_HapticNewEffect(haptic,&haptic->effects[i]) != 0) {
220 return -1; /* Backend failed to create effect */
221 }
222 return i;
223 }
224 }
225
226 SDL_SetError("Haptic device has no free space left.");
227 return -1;
228 }
229
230 /*
231 * Runs the haptic effect on the device.
232 */
233 int
234 SDL_HapticRunEffect(SDL_Haptic * haptic, int effect)
235 {
236 if (!ValidHaptic(&haptic)) {
237 return -1;
238 }
239 }
240
241 /*
242 * Gets rid of a haptic effect.
243 */
244 void
245 SDL_HapticDestroyEffect(SDL_Haptic * haptic, int effect)
246 {
247 if (!ValidHaptic(&haptic)) {
248 return;
249 }
250 }
251
252