2 * Copyright (C) Volition, Inc. 1999. All rights reserved.
4 * All source code herein is the property of Volition, Inc. You may not sell
5 * or otherwise commercially exploit the source or things you created based on
14 #include "osregistry.h"
18 static int Joy_inited = 0;
19 int joy_num_sticks = 0;
20 int Dead_zone_size = 10;
21 int Cur_joystick = -1;
22 int Joy_sensitivity = 9;
24 int joy_pollrate = 1000 / 18; // poll at 18Hz
26 static int Joy_last_x_reading = 0;
27 static int Joy_last_y_reading = 0;
29 typedef struct joy_button_info {
30 int actual_state; // Set if the button is physically down
31 int state; // Set when the button goes from up to down, cleared on down to up. Different than actual_state after a flush.
35 uint last_down_check; // timestamp in milliseconds of last
40 int JOYSTICKID1 = 0; // DDOI - temporary
41 static SDL_Joystick *sdljoy;
43 joy_button_info joy_buttons[JOY_TOTAL_BUTTONS];
54 SDL_QuitSubSystem (SDL_INIT_JOYSTICK);
57 void joy_get_caps (int max)
62 for (j=0; j < JOY_NUM_AXES; j++)
63 joystick.axis_valid[j] = 0;
65 for (j=JOYSTICKID1; j<JOYSTICKID1+max; j++) {
66 joy = SDL_JoystickOpen (j);
69 nprintf (("JOYSTICK", "Joystick #%d: %s\n", j - JOYSTICKID1 + 1, SDL_JoystickName(j)));
70 if (j == Cur_joystick) {
71 for (int i = 0; i < SDL_JoystickNumAxes(joy); i++)
73 joystick.axis_valid[i] = 1;
76 SDL_JoystickClose (joy);
85 if ( joy_num_sticks < 1 ) return 0;
86 if ( (btn < 0) || (btn >= JOY_TOTAL_BUTTONS )) return 0;
88 tmp = joy_buttons[btn].state;
93 int joy_down_count(int btn, int reset_count)
97 if ( joy_num_sticks < 1 ) return 0;
98 if ( (btn < 0) || (btn >= JOY_TOTAL_BUTTONS)) return 0;
100 tmp = joy_buttons[btn].down_count;
102 joy_buttons[btn].down_count = 0;
108 float joy_down_time(int btn)
114 if ( joy_num_sticks < 1 ) return 0.0f;
115 if ( (btn < 0) || (btn >= JOY_TOTAL_BUTTONS)) return 0.0f;
116 bi = &joy_buttons[btn];
118 now = timer_get_milliseconds();
120 if ( bi->down_time == 0 && joy_down(btn) ) {
121 bi->down_time += joy_pollrate;
124 if ( (now - bi->last_down_check) > 0)
125 rval = i2fl(bi->down_time) / (now - bi->last_down_check);
130 bi->last_down_check = now;
145 if ( joy_num_sticks < 1 ) return;
147 for ( i = 0; i < JOY_TOTAL_BUTTONS; i++) {
148 bi = &joy_buttons[i];
153 bi->last_down_check = timer_get_milliseconds();
157 int joy_get_pos(int *x, int *y, int *z, int *rx)
159 int axis[JOY_NUM_AXES];
166 if (joy_num_sticks < 1) return 0;
168 joystick_read_raw_axis( 6, axis );
170 // joy_get_scaled_reading will return a value represents the joystick pos from -1 to +1
171 if (x && joystick.axis_valid[0])
172 *x = joy_get_scaled_reading(axis[0], 0);
173 if (y && joystick.axis_valid[1])
174 *y = joy_get_scaled_reading(axis[1], 1);
175 if (z && joystick.axis_valid[2])
176 *z = joy_get_unscaled_reading(axis[2], 2);
177 if (rx && joystick.axis_valid[3])
178 *rx = joy_get_scaled_reading(axis[3], 3);
181 Joy_last_x_reading = *x;
184 Joy_last_x_reading = *y;
189 int joy_get_scaled_reading(int raw, int axn)
196 int joy_get_unscaled_reading(int raw, int axn)
210 if (SDL_InitSubSystem (SDL_INIT_JOYSTICK)<0)
212 mprintf(("Could not initialize joystick\n"));
217 n = SDL_NumJoysticks ();
220 //Cur_joystick = os_config_read_unit (NULL, "CurrentJoystick", JOYSTICKID1);
226 mprintf(("No joystick driver detected\n"));
234 // Fake a calibration
235 if (joy_num_sticks > 0) {
237 for (i=0; i<4; i++) {
238 joystick.axis_min[i] = 0;
239 joystick.axis_max[i] = joystick.axis_center[i]*2;
243 return joy_num_sticks;
248 joystick_read_raw_axis( 2, joystick.axis_center );
251 int joystick_read_raw_axis(int num_axes, int *axis)
256 void joy_ff_adjust_handling(int speed)
261 void joy_ff_afterburn_off()
266 void joy_ff_afterburn_on()
271 void joy_ff_deathroll()
281 void joy_ff_explode()
286 void joy_ff_fly_by(int mag)
291 void joy_ff_mission_init(vector v)
296 void joy_ff_play_dir_effect(float x, float y)
301 void joy_ff_play_primary_shoot(int gain)
306 void joy_ff_play_reload_effect()
311 void joy_ff_play_secondary_shoot(int gain)
316 void joy_ff_play_vector_effect(vector *v, float scaler)
321 void joy_ff_stop_effects()
323 joy_ff_afterburn_off();