From 5aa0939b732d4eeaa3df1a4bbd05845be1850e66 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Wed, 2 Feb 2011 01:36:43 +0100 Subject: [PATCH] Added event types for all input actions; Rewrote kconfig code to work with events; static defined inputs will not trigger kconfig-mapped inputs anymore; Simplified keyboard, mouse and joystick code a lot due to event-based handling; Added function to toggle SDL key repeats on and off; Put timer_update() to event_process; Removed return when event_poll() is idle to get cursor hiding to work again; Added a small delay between cursoe hiding and re-enabling to cursor will not accidentially enable by SDL event centering cursor while hiding --- CHANGELOG.txt | 4 + arch/include/event.h | 5 + arch/include/joy.h | 9 +- arch/include/key.h | 40 +- arch/include/mouse.h | 4 - arch/sdl/event.c | 10 +- arch/sdl/joy.c | 175 ++---- arch/sdl/key.c | 284 +++------ arch/sdl/mouse.c | 77 +-- main/automap.c | 21 +- main/endlevel.c | 19 +- main/game.c | 16 +- main/gamecntl.c | 110 ++-- main/inferno.c | 10 - main/kconfig.c | 1386 +++++++++++++++++------------------------- main/kconfig.h | 24 +- main/multi.c | 5 + main/newmenu.c | 4 + main/slew.c | 19 +- 19 files changed, 860 insertions(+), 1362 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index c87e34d7a..24dc1d427 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,5 +1,9 @@ D1X-Rebirth Changelog +20110202 +-------- +arch/include/event.h, arch/include/joy.h, arch/include/key.h, arch/include/mouse.h, arch/sdl/event.c, arch/sdl/joy.c, arch/sdl/key.c, arch/sdl/mouse.c, main/automap.c, main/endlevel.c, main/game.c, main/gamecntl.c, main/inferno.c, main/kconfig.c, main/kconfig.h, main/multi.c, main/newmenu.c, main/slew.c: Added event types for all input actions; Rewrote kconfig code to work with events; static defined inputs will not trigger kconfig-mapped inputs anymore; Simplified keyboard, mouse and joystick code a lot due to event-based handling; Added function to toggle SDL key repeats on and off; Put timer_update() to event_process; Removed return when event_poll() is idle to get cursor hiding to work again; Added a small delay between cursoe hiding and re-enabling to cursor will not accidentially enable by SDL event centering cursor while hiding + 20110126 -------- arc/sdl/event.c: In event_process() check for wind->next before sending EVENT_WINDOW_DRAW in case drawing will free wind diff --git a/arch/include/event.h b/arch/include/event.h index 6a3c2a489..41df96208 100644 --- a/arch/include/event.h +++ b/arch/include/event.h @@ -8,12 +8,17 @@ typedef enum event_type EVENT_IDLE = 0, EVENT_QUIT, + EVENT_JOYSTICK_BUTTON_DOWN, + EVENT_JOYSTICK_BUTTON_UP, + EVENT_JOYSTICK_MOVED, + EVENT_MOUSE_BUTTON_DOWN, EVENT_MOUSE_BUTTON_UP, EVENT_MOUSE_DOUBLE_CLICKED, // editor only for now EVENT_MOUSE_MOVED, EVENT_KEY_COMMAND, + EVENT_KEY_RELEASE, EVENT_WINDOW_ACTIVATED, EVENT_WINDOW_DEACTIVATED, diff --git a/arch/include/joy.h b/arch/include/joy.h index 52d76bc62..aa8dec7f4 100644 --- a/arch/include/joy.h +++ b/arch/include/joy.h @@ -10,6 +10,8 @@ #include "pstypes.h" #include "fix.h" +struct d_event; + #define MAX_JOYSTICKS 8 #define MAX_AXES_PER_JOYSTICK 128 #define MAX_BUTTONS_PER_JOYSTICK 128 @@ -20,11 +22,8 @@ extern int joy_num_axes; // set to Joystick.n_axes. solve different? extern void joy_init(); extern void joy_close(); -extern fix joy_get_button_down_time(int btn); -extern int joy_get_button_down_cnt(int btn); -extern void joystick_read_raw_axis(int *axis); +extern void event_joystick_get_axis(struct d_event *event, int *axis, int *value); extern void joy_flush(); -extern int joy_get_button_state(int btn); -extern int joy_get_scaled_reading(int raw); +extern int event_joystick_get_button(struct d_event *event); #endif // _JOY_H diff --git a/arch/include/key.h b/arch/include/key.h index 5afe4e656..3e40d92e1 100644 --- a/arch/include/key.h +++ b/arch/include/key.h @@ -34,59 +34,23 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. extern void key_init(); extern void key_close(); -//========================================================================== -// These are configuration parameters to setup how the buffer works. -// set keyd_buffer_type to 0 for no key buffering. -// set it to 1 and it will buffer scancodes. -extern unsigned char keyd_buffer_type; - -// keyd_editor_mode... 0=game mode, 1=editor mode. -// Editor mode makes key_down_time always return 0 if modifiers are down. -extern unsigned char keyd_editor_mode; - // Time in seconds when last key was pressed... extern fix64 keyd_time_when_last_pressed; // Stores Unicode values registered in one event_loop call unsigned char unicode_frame_buffer[KEY_BUFFER_SIZE]; -//========================================================================== -// These are the "buffered" keypress routines. Use them by setting the -// "keyd_buffer_type" variable. - -extern void key_putkey (unsigned short); // simulates a keystroke extern void key_flush(); // Clears the 256 char buffer -extern int key_checkch(); // Returns 1 if a char is waiting -extern int key_getch(); // Gets key if one waiting other waits for one. -extern int key_inkey(); // Gets key if one, other returns 0. extern int event_key_get(d_event *event); // Get the keycode from the EVENT_KEY_COMMAND event -extern int key_peekkey(); // Same as inkey, but doesn't remove key from buffer. - +extern int event_key_get_raw(d_event *event); // same as above but without mod states extern unsigned char key_ascii(); -extern void key_debug(); // Does an INT3 - -//========================================================================== -// These are the unbuffered routines. Index by the keyboard scancode. - // Set to 1 if the key is currently down, else 0 extern volatile unsigned char keyd_pressed[]; extern volatile unsigned char keyd_last_pressed; extern volatile unsigned char keyd_last_released; -// Returns the seconds this key has been down since last call. -extern fix64 key_down_time(int scancode); - -// Returns number of times key has went from up to down since last call. -extern unsigned int key_down_count(int scancode); - -// Returns number of times key has went from down to up since last call. -extern unsigned int key_up_count(int scancode); - -// Clears the times & counts used by the above functions -// Took out... use key_flush(); -//void key_clear_times(); -//void key_clear_counts(); +extern void key_toggle_repeat(int enable); extern char * key_text[256]; diff --git a/arch/include/mouse.h b/arch/include/mouse.h index 8e0204ddc..ac493d2a4 100644 --- a/arch/include/mouse.h +++ b/arch/include/mouse.h @@ -43,9 +43,5 @@ extern void mouse_get_pos( int *x, int *y, int *z ); extern void mouse_get_delta( int *dx, int *dy, int *dz ); extern void event_mouse_get_delta(struct d_event *event, int *dx, int *dy, int *dz); extern int mouse_get_btns(); -extern void mouse_set_pos( int x, int y); -extern fix64 mouse_button_down_time(int button); -extern int mouse_button_down_count(int button); -extern int mouse_button_state(int button); #endif diff --git a/arch/sdl/event.c b/arch/sdl/event.c index 587f2f97b..78ff3c575 100644 --- a/arch/sdl/event.c +++ b/arch/sdl/event.c @@ -21,7 +21,7 @@ extern void mouse_button_handler(SDL_MouseButtonEvent *mbe); extern void mouse_motion_handler(SDL_MouseMotionEvent *mme); extern void joy_button_handler(SDL_JoyButtonEvent *jbe); extern void joy_hat_handler(SDL_JoyHatEvent *jhe); -extern void joy_axis_handler(SDL_JoyAxisEvent *jae); +extern int joy_axis_handler(SDL_JoyAxisEvent *jae); extern void mouse_cursor_autohide(); extern void mouse_toggle_cursor(int activate); @@ -59,12 +59,15 @@ void event_poll() case SDL_JOYBUTTONDOWN: case SDL_JOYBUTTONUP: joy_button_handler((SDL_JoyButtonEvent *)&event); + idle = 0; break; case SDL_JOYAXISMOTION: - joy_axis_handler((SDL_JoyAxisEvent *)&event); + if (joy_axis_handler((SDL_JoyAxisEvent *)&event)) + idle = 0; break; case SDL_JOYHATMOTION: joy_hat_handler((SDL_JoyHatEvent *)&event); + idle = 0; break; case SDL_JOYBALLMOTION: break; @@ -83,7 +86,6 @@ void event_poll() event.type = EVENT_IDLE; event_send(&event); - return; } mouse_cursor_autohide(); @@ -140,6 +142,8 @@ void event_process(void) d_event event; window *wind = window_get_front(); + timer_update(); + event_poll(); // send input events first // Doing this prevents problems when a draw event can create a newmenu, diff --git a/arch/sdl/joy.c b/arch/sdl/joy.c index 7f00c884b..3a94acfba 100644 --- a/arch/sdl/joy.c +++ b/arch/sdl/joy.c @@ -22,31 +22,30 @@ extern char *joyaxis_text[]; //from kconfig.c int num_joysticks = 0; int joy_num_axes = 0; -struct joybutton { - int state; - int last_state; - fix64 time_went_down; - int num_downs; - int num_ups; -}; - -struct joyaxis { - int value; - int min_val; - int center_val; - int max_val; -}; - /* This struct is a "virtual" joystick, which includes all the axes * and buttons of every joystick found. */ static struct joyinfo { int n_axes; int n_buttons; - struct joyaxis axes[JOY_MAX_AXES]; - struct joybutton buttons[JOY_MAX_BUTTONS]; + int axis_value[JOY_MAX_AXES]; + ubyte button_state[JOY_MAX_BUTTONS]; + ubyte button_last_state[JOY_MAX_BUTTONS]; // for HAT movement only } Joystick; +typedef struct d_event_joystickbutton +{ + event_type type; + int button; +} d_event_joystickbutton; + +typedef struct d_event_joystick_moved +{ + event_type type; // EVENT_JOYSTICK_MOVED + int axis; + int value; +} d_event_joystick_moved; + /* This struct is an array, with one entry for each physical joystick * found. */ @@ -63,62 +62,74 @@ static struct { void joy_button_handler(SDL_JoyButtonEvent *jbe) { int button; + d_event_joystickbutton event; button = SDL_Joysticks[jbe->which].button_map[jbe->button]; - Joystick.buttons[button].state = jbe->state; + Joystick.button_state[button] = jbe->state; - switch (jbe->type) { - case SDL_JOYBUTTONDOWN: - Joystick.buttons[button].time_went_down = timer_query(); - Joystick.buttons[button].num_downs++; - break; - case SDL_JOYBUTTONUP: - Joystick.buttons[button].num_ups++; - break; - } + event.type = (jbe->type == SDL_JOYBUTTONDOWN) ? EVENT_JOYSTICK_BUTTON_DOWN : EVENT_JOYSTICK_BUTTON_UP; + event.button = button; + con_printf(CON_DEBUG, "Sending event %s, button %d\n", (jbe->type == SDL_JOYBUTTONDOWN) ? "EVENT_JOYSTICK_BUTTON_DOWN" : "EVENT_JOYSTICK_JOYSTICK_UP", event.button); + event_send((d_event *)&event); } void joy_hat_handler(SDL_JoyHatEvent *jhe) { int hat = SDL_Joysticks[jhe->which].hat_map[jhe->hat]; int hbi; + d_event_joystickbutton event; //Save last state of the hat-button - Joystick.buttons[hat ].last_state = Joystick.buttons[hat ].state; - Joystick.buttons[hat+1].last_state = Joystick.buttons[hat+1].state; - Joystick.buttons[hat+2].last_state = Joystick.buttons[hat+2].state; - Joystick.buttons[hat+3].last_state = Joystick.buttons[hat+3].state; + Joystick.button_last_state[hat ] = Joystick.button_state[hat ]; + Joystick.button_last_state[hat+1] = Joystick.button_state[hat+1]; + Joystick.button_last_state[hat+2] = Joystick.button_state[hat+2]; + Joystick.button_last_state[hat+3] = Joystick.button_state[hat+3]; //get current state of the hat-button - Joystick.buttons[hat ].state = ((jhe->value & SDL_HAT_UP)>0); - Joystick.buttons[hat+1].state = ((jhe->value & SDL_HAT_RIGHT)>0); - Joystick.buttons[hat+2].state = ((jhe->value & SDL_HAT_DOWN)>0); - Joystick.buttons[hat+3].state = ((jhe->value & SDL_HAT_LEFT)>0); + Joystick.button_state[hat ] = ((jhe->value & SDL_HAT_UP)>0); + Joystick.button_state[hat+1] = ((jhe->value & SDL_HAT_RIGHT)>0); + Joystick.button_state[hat+2] = ((jhe->value & SDL_HAT_DOWN)>0); + Joystick.button_state[hat+3] = ((jhe->value & SDL_HAT_LEFT)>0); //determine if a hat-button up or down event based on state and last_state for(hbi=0;hbi<4;hbi++) { - if( !Joystick.buttons[hat+hbi].last_state && Joystick.buttons[hat+hbi].state) //last_state up, current state down + if( !Joystick.button_last_state[hat+hbi] && Joystick.button_state[hat+hbi]) //last_state up, current state down { - Joystick.buttons[hat+hbi].time_went_down - = timer_query(); - Joystick.buttons[hat+hbi].num_downs++; + event.type = EVENT_JOYSTICK_BUTTON_DOWN; + event.button = hat+hbi; + con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_DOWN, button %d\n", event.button); + event_send((d_event *)&event); } - else if(Joystick.buttons[hat+hbi].last_state && !Joystick.buttons[hat+hbi].state) //last_state down, current state up + else if(Joystick.button_last_state[hat+hbi] && !Joystick.button_state[hat+hbi]) //last_state down, current state up { - Joystick.buttons[hat+hbi].num_ups++; + event.type = EVENT_JOYSTICK_BUTTON_UP; + event.button = hat+hbi; + con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_BUTTON_UP, button %d\n", event.button); + event_send((d_event *)&event); } } } -void joy_axis_handler(SDL_JoyAxisEvent *jae) +int joy_axis_handler(SDL_JoyAxisEvent *jae) { int axis; + d_event_joystick_moved event; axis = SDL_Joysticks[jae->which].axis_map[jae->axis]; - - Joystick.axes[axis].value = jae->value; + + // inaccurate stick is inaccurate. SDL might send SDL_JoyAxisEvent even if the value is the same as before. + if (Joystick.axis_value[axis] == jae->value/256) + return 0; + + event.type = EVENT_JOYSTICK_MOVED; + event.axis = axis; + event.value = Joystick.axis_value[axis] = jae->value/256; + con_printf(CON_DEBUG, "Sending event EVENT_JOYSTICK_MOVED, axis: %d, value: %d\n",event.axis, event.value); + event_send((d_event *)&event); + + return 1; } @@ -223,54 +234,12 @@ void joy_close() d_free(joybutton_text[Joystick.n_buttons]); } -int joy_get_button_down_cnt( int btn ) +void event_joystick_get_axis(d_event *event, int *axis, int *value) { - int num_downs; + Assert(event->type == EVENT_JOYSTICK_MOVED); - if (!num_joysticks || btn < 0 || btn >= JOY_MAX_BUTTONS) - return 0; - -// event_poll(); - - num_downs = Joystick.buttons[btn].num_downs; - Joystick.buttons[btn].num_downs = 0; - - return num_downs; -} - -fix joy_get_button_down_time(int btn) -{ - fix time = F0_0; - - if (!num_joysticks || btn < 0 || btn >= JOY_MAX_BUTTONS) - return 0; - -// event_poll(); - - switch (Joystick.buttons[btn].state) { - case SDL_PRESSED: - time = timer_query() - Joystick.buttons[btn].time_went_down; - Joystick.buttons[btn].time_went_down = timer_query(); - break; - case SDL_RELEASED: - time = 0; - break; - } - - return time; -} - -void joystick_read_raw_axis( int * axis ) -{ - int i; - - if (!num_joysticks) - return; - -// event_poll(); - - for (i = 0; i < Joystick.n_axes; i++) - axis[i] = Joystick.axes[i].value; + *axis = ((d_event_joystick_moved *)event)->axis; + *value = ((d_event_joystick_moved *)event)->value; } void joy_flush() @@ -280,28 +249,12 @@ void joy_flush() if (!num_joysticks) return; - for (i = 0; i < Joystick.n_buttons; i++) { - Joystick.buttons[i].time_went_down = 0; - Joystick.buttons[i].num_downs = 0; - Joystick.buttons[i].state = SDL_RELEASED; - } - + for (i = 0; i < Joystick.n_buttons; i++) + Joystick.button_state[i] = SDL_RELEASED; } -int joy_get_button_state( int btn ) +int event_joystick_get_button(d_event *event) { - if (!num_joysticks) - return 0; - - if(btn >= Joystick.n_buttons) - return 0; - -// event_poll(); - - return Joystick.buttons[btn].state; -} - -int joy_get_scaled_reading( int raw ) -{ - return raw/256; + Assert((event->type == EVENT_JOYSTICK_BUTTON_DOWN) || (event->type == EVENT_JOYSTICK_BUTTON_UP)); + return ((d_event_joystickbutton *)event)->button; } diff --git a/arch/sdl/key.c b/arch/sdl/key.c index 9afab75eb..f6542cb67 100644 --- a/arch/sdl/key.c +++ b/arch/sdl/key.c @@ -23,27 +23,14 @@ static unsigned char Installed = 0; //-------- Variable accessed by outside functions --------- int keyd_repeat = 0; // 1 = use repeats, 0 no repeats -unsigned char keyd_editor_mode; volatile unsigned char keyd_last_pressed; volatile unsigned char keyd_last_released; volatile unsigned char keyd_pressed[256]; fix64 keyd_time_when_last_pressed; unsigned char unicode_frame_buffer[KEY_BUFFER_SIZE] = { '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0', '\0' }; -typedef struct Key_info { - ubyte state; // state of key 1 == down, 0 == up - ubyte last_state; // previous state of key - fix64 timewentdown; // simple counter incremented each time in interrupt and key is down - fix64 timehelddown; // counter to tell how long key is down -- gets reset to 0 by key routines - ubyte downcount; // number of key counts key was down - ubyte upcount; // number of times key was released -} Key_info; - typedef struct keyboard { - unsigned short keybuffer[KEY_BUFFER_SIZE]; - Key_info keys[256]; - fix64 time_pressed[KEY_BUFFER_SIZE]; - unsigned int keyhead, keytail; + ubyte state[256]; } keyboard; static keyboard key_data; @@ -315,7 +302,7 @@ key_props key_properties[256] = { typedef struct d_event_keycommand { - event_type type; // EVENT_KEY_COMMAND + event_type type; // EVENT_KEY_COMMAND/RELEASE int keycode; } d_event_keycommand; @@ -375,97 +362,74 @@ unsigned char key_ascii() void key_handler(SDL_KeyboardEvent *event) { - ubyte state; - int i, keycode, event_keysym=-1, key_state; - Key_info *key; - unsigned char temp; - int key_command = 0; + int keycode, event_keysym=-1, key_state; // Read SDLK symbol and state event_keysym = event->keysym.sym; - key_state = (event->state == SDL_PRESSED); + key_state = (event->state == SDL_PRESSED)?1:0; // fill the unicode frame-related unicode buffer if (key_state && event->keysym.unicode > 31 && event->keysym.unicode < 255) + { + int i = 0; for (i = 0; i < KEY_BUFFER_SIZE; i++) if (unicode_frame_buffer[i] == '\0') { unicode_frame_buffer[i] = event->keysym.unicode; break; } - - //===================================================== - - for (i = 255; i >= 0; i--) { - keycode = i; - key = &(key_data.keys[keycode]); - - if (key_properties[i].sym == event_keysym) - state = key_state; - else - state = key->last_state; - - if ( key->last_state == state ) { - if (state) { - keyd_last_pressed = keycode; - keyd_time_when_last_pressed = timer_query(); - } - } else { - if (state) { - keyd_last_pressed = keycode; - keyd_pressed[keycode] = 1; - key->downcount += state; - key->state = 1; - key->timewentdown = keyd_time_when_last_pressed = timer_query(); - } else { - keyd_pressed[keycode] = 0; - keyd_last_released = keycode; - key->upcount += key->state; - key->state = 0; - key->timehelddown += timer_query() - key->timewentdown; - } - } - if ( (state && !key->last_state) || (state && key->last_state && keyd_repeat && !key_ismodlck(i)) ) { - if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) - keycode |= KEY_SHIFTED; - if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT]) - keycode |= KEY_ALTED; - if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]) - keycode |= KEY_CTRLED; - if ( keyd_pressed[KEY_DELETE] ) - keycode |= KEY_DEBUGGED; - if ( keyd_pressed[KEY_LMETA] || keyd_pressed[KEY_RMETA]) - keycode |= KEY_METAED; - - key_command = keycode; - - temp = key_data.keytail+1; - if ( temp >= KEY_BUFFER_SIZE ) temp=0; - if (temp!=key_data.keyhead) { - key_data.keybuffer[key_data.keytail] = keycode; - key_data.time_pressed[key_data.keytail] = keyd_time_when_last_pressed; - key_data.keytail = temp; - } - } - key->last_state = state; } - // We allowed the key to be added to the queue for now, - // because there are still input loops without associated windows - if (key_command || unicode_frame_buffer[0] != '\0') + //===================================================== + for (keycode = 255; keycode > 0; keycode--) + if (key_properties[keycode].sym == event_keysym) + break; + + if (keycode == 0) + return; + + /* + * process the key if: + * - it's a valid key AND + * - if the keystate has changed OR + * - key state same as last one and game accepts key repeats but keep out mod/lock keys + */ + if (key_state != keyd_pressed[keycode] || (keyd_repeat && !key_ismodlck(keycode))) { d_event_keycommand event; - - event.type = EVENT_KEY_COMMAND; - event.keycode = key_command; - con_printf(CON_DEBUG, "Sending event EVENT_KEY_COMMAND: %s %s %s %s %s %s\n", - (key_command & KEY_METAED) ? "META" : "", - (key_command & KEY_DEBUGGED) ? "DEBUG" : "", - (key_command & KEY_CTRLED) ? "CTRL" : "", - (key_command & KEY_ALTED) ? "ALT" : "", - (key_command & KEY_SHIFTED) ? "SHIFT" : "", - key_properties[key_command & 0xff].key_text - ); + + // now update the key props + if (key_state) { + keyd_last_pressed = keycode; + keyd_pressed[keycode] = key_data.state[keycode] = 1; + } else { + keyd_pressed[keycode] = key_data.state[keycode] = 0; + } + + if ( keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]) + keycode |= KEY_SHIFTED; + if ( keyd_pressed[KEY_LALT] || keyd_pressed[KEY_RALT]) + keycode |= KEY_ALTED; + if ( keyd_pressed[KEY_LCTRL] || keyd_pressed[KEY_RCTRL]) + keycode |= KEY_CTRLED; + if ( keyd_pressed[KEY_DELETE] ) + keycode |= KEY_DEBUGGED; + if ( keyd_pressed[KEY_LMETA] || keyd_pressed[KEY_RMETA]) + keycode |= KEY_METAED; + + // We allowed the key to be added to the queue for now, + // because there are still input loops without associated windows + event.type = key_state?EVENT_KEY_COMMAND:EVENT_KEY_RELEASE; + event.keycode = keycode; + con_printf(CON_DEBUG, "Sending event %s: %s %s %s %s %s %s\n", + (key_state) ? "EVENT_KEY_COMMAND": "EVENT_KEY_RELEASE", + (keycode & KEY_METAED) ? "META" : "", + (keycode & KEY_DEBUGGED) ? "DEBUG" : "", + (keycode & KEY_CTRLED) ? "CTRL" : "", + (keycode & KEY_ALTED) ? "ALT" : "", + (keycode & KEY_SHIFTED) ? "SHIFT" : "", + key_properties[keycode & 0xff].key_text + ); event_send((d_event *)&event); } } @@ -483,8 +447,7 @@ void key_init() Installed=1; SDL_EnableUNICODE(1); - if (SDL_EnableKeyRepeat(KEY_REPEAT_DELAY, KEY_REPEAT_INTERVAL) == 0) - keyd_repeat = 1; + key_toggle_repeat(1); keyd_time_when_last_pressed = timer_query(); @@ -503,139 +466,54 @@ void key_flush() if (!Installed) key_init(); - key_data.keyhead = key_data.keytail = 0; - - //Clear the keyboard buffer - for (i=0; i= KEY_BUFFER_SIZE ) - n=0; - return n; -} - -int key_checkch() -{ - int is_one_waiting = 0; -// event_poll(); - if (key_data.keytail!=key_data.keyhead) - is_one_waiting = 1; - return is_one_waiting; -} - -int key_inkey() -{ - int key = 0; - if (!Installed) - key_init(); -// event_poll(); - if (key_data.keytail!=key_data.keyhead) { - key = key_data.keybuffer[key_data.keyhead]; - key_data.keyhead = add_one(key_data.keyhead); - } - - return key; -} - int event_key_get(d_event *event) { - Assert(event->type == EVENT_KEY_COMMAND); + Assert(event->type == EVENT_KEY_COMMAND || event->type == EVENT_KEY_RELEASE); return ((d_event_keycommand *)event)->keycode; } -int key_peekkey() +// same as above but without mod states +int event_key_get_raw(d_event *event) { - int key = 0; -// event_poll(); - if (key_data.keytail!=key_data.keyhead) - key = key_data.keybuffer[key_data.keyhead]; - - return key; + int keycode = ((d_event_keycommand *)event)->keycode; + Assert(event->type == EVENT_KEY_COMMAND || event->type == EVENT_KEY_RELEASE); + if ( keycode & KEY_SHIFTED ) keycode &= ~KEY_SHIFTED; + if ( keycode & KEY_ALTED ) keycode &= ~KEY_ALTED; + if ( keycode & KEY_CTRLED ) keycode &= ~KEY_CTRLED; + if ( keycode & KEY_DEBUGGED ) keycode &= ~KEY_DEBUGGED; + if ( keycode & KEY_METAED ) keycode &= ~KEY_METAED; + return keycode; } -int key_getch() +void key_toggle_repeat(int enable) { - int dummy=0; - - if (!Installed) - return 0; -// return getch(); - - while (!key_checkch()) - dummy++; - return key_inkey(); -} - -// Returns the number of seconds this key has been down since last call. -fix64 key_down_time(int scancode) -{ - fix64 time_down, time; - -// event_poll(); - if ((scancode<0)|| (scancode>255)) return 0; - - if (!keyd_pressed[scancode]) { - time_down = key_data.keys[scancode].timehelddown; - key_data.keys[scancode].timehelddown = 0; - } else { - time = timer_query(); - time_down = time - key_data.keys[scancode].timewentdown; - key_data.keys[scancode].timewentdown = time; + if (enable) + { + if (SDL_EnableKeyRepeat(KEY_REPEAT_DELAY, KEY_REPEAT_INTERVAL) == 0) + keyd_repeat = 1; } - - return time_down; -} - -unsigned int key_down_count(int scancode) -{ - int n; -// event_poll(); - if ((scancode<0)|| (scancode>255)) return 0; - - n = key_data.keys[scancode].downcount; - key_data.keys[scancode].downcount = 0; - - return n; -} - -unsigned int key_up_count(int scancode) -{ - int n; -// event_poll(); - if ((scancode<0)|| (scancode>255)) return 0; - - n = key_data.keys[scancode].upcount; - key_data.keys[scancode].upcount = 0; - - return n; + else + { + SDL_EnableKeyRepeat(0, 0); + keyd_repeat = 0; + } + key_flush(); } diff --git a/arch/sdl/mouse.c b/arch/sdl/mouse.c index e351c3538..4980709ea 100644 --- a/arch/sdl/mouse.c +++ b/arch/sdl/mouse.c @@ -13,16 +13,8 @@ #include "mouse.h" #include "playsave.h" -struct mousebutton { - ubyte pressed; - fix64 time_went_down; - fix64 time_held_down; - uint num_downs; - uint num_ups; -}; - static struct mouseinfo { - struct mousebutton buttons[MOUSE_MAX_BUTTONS]; + ubyte button_state[MOUSE_MAX_BUTTONS]; int delta_x, delta_y, delta_z, old_delta_x, old_delta_y; int x,y,z; int cursor_enabled; @@ -86,9 +78,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe) if (mbe->state == SDL_PRESSED) { d_event_mouse_moved event2 = { EVENT_MOUSE_MOVED, 0, 0, 0 }; - Mouse.buttons[button].pressed = 1; - Mouse.buttons[button].time_went_down = timer_query(); - Mouse.buttons[button].num_downs++; + Mouse.button_state[button] = 1; if (button == MBTN_Z_UP) { Mouse.delta_z += Z_SENSITIVITY; @@ -107,9 +97,7 @@ void mouse_button_handler(SDL_MouseButtonEvent *mbe) event_send((d_event *)&event2); } } else { - Mouse.buttons[button].pressed = 0; - Mouse.buttons[button].time_held_down += timer_query() - Mouse.buttons[button].time_went_down; - Mouse.buttons[button].num_ups++; + Mouse.button_state[button] = 0; } event.type = (mbe->state == SDL_PRESSED) ? EVENT_MOUSE_BUTTON_DOWN : EVENT_MOUSE_BUTTON_UP; @@ -157,13 +145,8 @@ void mouse_flush() // clears all mice events... // event_poll(); - for (i=0; i= MOUSE_MAX_BUTTONS) - return 0; - - if (!Mouse.buttons[button].pressed) { - time_down = Mouse.buttons[button].time_held_down; - Mouse.buttons[button].time_held_down = 0; - } else { - time = timer_query(); - time_down = time - Mouse.buttons[button].time_held_down; - Mouse.buttons[button].time_held_down = time; - } - return time_down; -} - -// Returns how many times this button has went down since last call -int mouse_button_down_count(int button) -{ - int count; - - if (button < 0 || button >= MOUSE_MAX_BUTTONS) - return 0; - - count = Mouse.buttons[button].num_downs; - Mouse.buttons[button].num_downs = 0; - - return count; -} - -// Returns 1 if this button is currently down -int mouse_button_state(int button) -{ - if (button < 0 || button >= MOUSE_MAX_BUTTONS) - return 0; - - return Mouse.buttons[button].pressed; -} - void mouse_toggle_cursor(int activate) { Mouse.cursor_enabled = (activate && !GameArg.CtlNoMouse); @@ -291,13 +232,17 @@ void mouse_toggle_cursor(int activate) void mouse_cursor_autohide() { int show = SDL_ShowCursor(SDL_QUERY); + static fix64 hidden_time = 0; if (Mouse.cursor_enabled) { - if ( (Mouse.cursor_time + (F1_0*2)) >= timer_query() && !show) + if ( (Mouse.cursor_time + (F1_0*2)) >= timer_query() && hidden_time + (F1_0/2) < timer_query() && !show) SDL_ShowCursor(SDL_ENABLE); else if ( (Mouse.cursor_time + (F1_0*2)) < timer_query() && show) + { SDL_ShowCursor(SDL_DISABLE); + hidden_time = timer_query(); + } } else { diff --git a/main/automap.c b/main/automap.c index 9977ad857..114692830 100644 --- a/main/automap.c +++ b/main/automap.c @@ -437,9 +437,9 @@ int automap_idle(window *wind, d_event *event, automap *am) return 1; } - controls_read_all(1); - - if ( Controls.automap_down_count ) { + if ( Controls.automap_count > 0) + { + Controls.automap_count = 0; if (am->leave_mode==0) { window_close(wind); @@ -447,13 +447,14 @@ int automap_idle(window *wind, d_event *event, automap *am) } } - if ( Controls.fire_primary_down_count ) { + if ( Controls.fire_primary_count > 0) { // Reset orientation am->viewDist = ZOOM_DEFAULT; am->tangles.p = PITCH_DEFAULT; am->tangles.h = 0; am->tangles.b = 0; am->view_target = Objects[Players[Player_num].objnum].pos; + Controls.fire_primary_count = 0; } am->viewDist -= Controls.forward_thrust_time*ZOOM_SPEED_FACTOR; @@ -514,16 +515,27 @@ int automap_handler(window *wind, d_event *event, automap *am) case EVENT_WINDOW_ACTIVATED: game_flush_inputs(); event_toggle_focus(1); + key_toggle_repeat(0); break; case EVENT_WINDOW_DEACTIVATED: event_toggle_focus(0); + key_toggle_repeat(1); break; + case EVENT_JOYSTICK_BUTTON_UP: + case EVENT_JOYSTICK_BUTTON_DOWN: + case EVENT_JOYSTICK_MOVED: + case EVENT_MOUSE_BUTTON_UP: + case EVENT_MOUSE_BUTTON_DOWN: + case EVENT_MOUSE_MOVED: case EVENT_KEY_COMMAND: + case EVENT_KEY_RELEASE: + kconfig_read_controls(event, 1); return automap_key_command(wind, event, am); case EVENT_IDLE: + kconfig_read_controls(event, 1); return automap_idle(wind, event, am); break; @@ -533,6 +545,7 @@ int automap_handler(window *wind, d_event *event, automap *am) case EVENT_WINDOW_CLOSE: event_toggle_focus(0); + key_toggle_repeat(1); #ifdef OGL gr_free_bitmap_data(&am->automap_background); #endif diff --git a/main/endlevel.c b/main/endlevel.c index 29991a316..0861253d4 100644 --- a/main/endlevel.c +++ b/main/endlevel.c @@ -1223,13 +1223,20 @@ int _do_slew_movement(object *obj, int check_keys ) vm_vec_zero(&obj->phys_info.velocity); if (check_keys) { - obj->phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7)); - obj->phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS)); - obj->phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2)); + obj->phys_info.velocity.x += VEL_SPEED * keyd_pressed[KEY_PAD9] * FrameTime; + obj->phys_info.velocity.x -= VEL_SPEED * keyd_pressed[KEY_PAD7] * FrameTime; + obj->phys_info.velocity.y += VEL_SPEED * keyd_pressed[KEY_PADMINUS] * FrameTime; + obj->phys_info.velocity.y -= VEL_SPEED * keyd_pressed[KEY_PADPLUS] * FrameTime; + obj->phys_info.velocity.z += VEL_SPEED * keyd_pressed[KEY_PAD8] * FrameTime; + obj->phys_info.velocity.z -= VEL_SPEED * keyd_pressed[KEY_PAD2] * FrameTime; - rotang.pitch = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED; - rotang.bank = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED; - rotang.head = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED; + rotang.pitch = rotang.bank = rotang.head = 0; + rotang.pitch += keyd_pressed[KEY_LBRACKET] * FrameTime / ROT_SPEED; + rotang.pitch -= keyd_pressed[KEY_RBRACKET] * FrameTime / ROT_SPEED; + rotang.bank += keyd_pressed[KEY_PAD1] * FrameTime / ROT_SPEED; + rotang.bank -= keyd_pressed[KEY_PAD3] * FrameTime / ROT_SPEED; + rotang.head += keyd_pressed[KEY_PAD6] * FrameTime / ROT_SPEED; + rotang.head -= keyd_pressed[KEY_PAD4] * FrameTime / ROT_SPEED; } else rotang.pitch = rotang.bank = rotang.head = 0; diff --git a/main/game.c b/main/game.c index e2b11795c..89735cf11 100644 --- a/main/game.c +++ b/main/game.c @@ -852,7 +852,8 @@ void check_rear_view() if (Newdemo_state == ND_STATE_PLAYBACK) return; - if ( Controls.rear_view_down_count ) { //key/button has gone down + if ( Controls.rear_view_count > 0) { //key/button has gone down + Controls.rear_view_count = 0; if (Rear_view) { Rear_view = 0; @@ -874,7 +875,7 @@ void check_rear_view() } } else - if (Controls.rear_view_down_state) { + if (Controls.rear_view_state) { if (leave_mode == 0 && (timer_query() - entry_time) > LEAVE_TIME) leave_mode = 1; @@ -1004,6 +1005,7 @@ int game_handler(window *wind, d_event *event, void *data) set_screen_mode(SCREEN_GAME); event_toggle_focus(1); + key_toggle_repeat(0); game_flush_inputs(); if (time_paused) @@ -1029,13 +1031,18 @@ int game_handler(window *wind, d_event *event, void *data) palette_save(); event_toggle_focus(0); + key_toggle_repeat(1); break; + case EVENT_JOYSTICK_BUTTON_UP: + case EVENT_JOYSTICK_BUTTON_DOWN: + case EVENT_JOYSTICK_MOVED: case EVENT_MOUSE_BUTTON_UP: case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_MOVED: case EVENT_KEY_COMMAND: - case EVENT_IDLE: // EVENT_IDLE will be removed once all input events are in place + case EVENT_KEY_RELEASE: + case EVENT_IDLE: return ReadControls(event); case EVENT_WINDOW_DRAW: @@ -1075,6 +1082,7 @@ int game_handler(window *wind, d_event *event, void *data) show_menus(); Game_wind = NULL; event_toggle_focus(0); + key_toggle_repeat(1); break; case EVENT_WINDOW_CLOSED: @@ -1274,7 +1282,7 @@ void GameProcessFrame(void) void FireLaser() { - Global_laser_firing_count = Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count * (Controls.fire_primary_state || Controls.fire_primary_down_count); + Global_laser_firing_count = Controls.fire_primary_state?Weapon_info[Primary_weapon_to_weapon_info[Primary_weapon]].fire_count:0; if ((Primary_weapon == FUSION_INDEX) && (Global_laser_firing_count)) { if ((Players[Player_num].energy < F1_0*2) && (Auto_fire_fusion_cannon_time == 0)) { diff --git a/main/gamecntl.c b/main/gamecntl.c index 595038263..dc238f2d2 100644 --- a/main/gamecntl.c +++ b/main/gamecntl.c @@ -146,7 +146,7 @@ void play_test_sound(void); #define key_isfunc(k) (((k&0xff)>=KEY_F1 && (k&0xff)<=KEY_F10) || (k&0xff)==KEY_F11 || (k&0xff)==KEY_F12) void update_vcr_state(); -void do_weapon_stuff(void); +void do_weapon_n_item_stuff(void); // Control Functions @@ -167,39 +167,48 @@ void update_vcr_state(void) Newdemo_vcr_state = ND_STATE_PLAYBACK; } -void do_weapon_stuff() +void do_weapon_n_item_stuff() { int i; - if (Controls.fire_flare_down_count) + if (Controls.fire_flare_count > 0) + { + Controls.fire_flare_count = 0; if (allowed_to_fire_flare()) Flare_create(ConsoleObject); + } - if (allowed_to_fire_missile()) - Global_missile_firing_count += Weapon_info[Secondary_weapon_to_weapon_info[Secondary_weapon]].fire_count * (Controls.fire_secondary_state || Controls.fire_secondary_down_count); + if (allowed_to_fire_missile() && Controls.fire_secondary_state) + Global_missile_firing_count += Weapon_info[Secondary_weapon_to_weapon_info[Secondary_weapon]].fire_count; if (Global_missile_firing_count) { do_missile_firing(0); Global_missile_firing_count--; } - if (Controls.cycle_primary_count) + if (Controls.cycle_primary_count > 0) { for (i=0;i 0) { for (i=0;i4?Controls.select_weapon_count-5:Controls.select_weapon_count,Controls.select_weapon_count>4?1:0); + Controls.select_weapon_count = 0; } - if (Global_missile_firing_count < 0) Global_missile_firing_count = 0; // Drop proximity bombs. - if (Controls.drop_bomb_down_count) { - while (Controls.drop_bomb_down_count--) + if (Controls.drop_bomb_count > 0) { + while (Controls.drop_bomb_count--) do_missile_firing(1); } } @@ -229,7 +238,6 @@ int pause_handler(window *wind, d_event *event, char *msg) { case EVENT_WINDOW_ACTIVATED: game_flush_inputs(); - event_toggle_focus(0); break; case EVENT_KEY_COMMAND: @@ -263,7 +271,6 @@ int pause_handler(window *wind, d_event *event, char *msg) break; case EVENT_WINDOW_CLOSE: - event_toggle_focus(1); songs_resume(); d_free(msg); break; @@ -326,16 +333,22 @@ int HandleEndlevelKey(int key) return 0; } -int HandleDeathKey(int key) +int HandleDeathInput(d_event *event) { - if (Player_exploded && !key_isfunc(key) && key) - Death_sequence_aborted = 1; //Any key but func or modifier aborts + if (event->type == EVENT_KEY_COMMAND) + { + int key = event_key_get(event); - if (key == KEY_ESC) { - if (ConsoleObject->flags & OF_EXPLODING) - Death_sequence_aborted = 1; + if (Player_exploded && !key_isfunc(key) && key) + Death_sequence_aborted = 1; //Any key but func or modifier aborts + if (key == KEY_ESC) + if (ConsoleObject->flags & OF_EXPLODING) + Death_sequence_aborted = 1; } + if (Player_exploded && (event->type == EVENT_JOYSTICK_BUTTON_UP || event->type == EVENT_MOUSE_BUTTON_UP)) + Death_sequence_aborted = 1; + if (Death_sequence_aborted) { game_flush_inputs(); @@ -1349,52 +1362,18 @@ int ReadControls(d_event *event) Player_fired_laser_this_frame=-1; - if (!Endlevel_sequence) //this was taken out of the if statement by WraithX - { - - if ( (Newdemo_state == ND_STATE_PLAYBACK) -#ifdef NETWORK - || multi_sending_message || multi_defining_message -#endif - ) // WATCH OUT!!! WEIRD CODE ABOVE!!! - memset( &Controls, 0, sizeof(control_info) ); - else - controls_read_all(0); //NOTE LINK TO ABOVE!!! - - check_rear_view(); - - // If automap key pressed, enable automap unless you are in network mode, control center destroyed and < 10 seconds left - if ( Controls.automap_down_count && !((Game_mode & GM_MULTI) && Control_center_destroyed && (Countdown_seconds_left < 10))) - { - do_automap(0); - return 1; - } - - do_weapon_stuff(); - } - if (Player_exploded) { - if (exploding_flag==0) { exploding_flag = 1; // When player starts exploding, clear all input devices... game_flush_inputs(); - } else { - int i; - - for (i=0; i < JOY_MAX_BUTTONS; i++ ) - if (joy_get_button_down_cnt(i) > 0) Death_sequence_aborted = 1; - - for (i = 0; i < MOUSE_MAX_BUTTONS; i++) - if (mouse_button_down_count(i) > 0) Death_sequence_aborted = 1; - - if (Death_sequence_aborted) - game_flush_inputs(); } } else { exploding_flag=0; } + if (Player_is_dead) + return HandleDeathInput(event); - if (Newdemo_state == ND_STATE_PLAYBACK ) + if (Newdemo_state == ND_STATE_PLAYBACK) update_vcr_state(); if (event->type == EVENT_KEY_COMMAND) @@ -1442,9 +1421,26 @@ int ReadControls(d_event *event) if (call_default_handler(event)) return 1; + } - if (Player_is_dead) - return HandleDeathKey(key); + if (!Endlevel_sequence && !Player_is_dead && (Newdemo_state != ND_STATE_PLAYBACK)) + { + kconfig_read_controls(event, 0); + + check_rear_view(); + + // If automap key pressed, enable automap unless you are in network mode, control center destroyed and < 10 seconds left + if ( Controls.automap_count > 0 ) + { + Controls.automap_count = 0; + if (!((Game_mode & GM_MULTI) && Control_center_destroyed && (Countdown_seconds_left < 10))) + { + do_automap(0); + return 1; + } + } + + do_weapon_n_item_stuff(); } return 0; diff --git a/main/inferno.c b/main/inferno.c index f23770bd2..719557507 100644 --- a/main/inferno.c +++ b/main/inferno.c @@ -41,7 +41,6 @@ char copyright[] = "DESCENT COPYRIGHT (C) 1994,1995 PARALLAX SOFTWARE CORPORAT #include "console.h" #include "gr.h" #include "key.h" -#include "timer.h" #include "3d.h" #include "bm.h" #include "inferno.h" @@ -175,8 +174,6 @@ void print_commandline_help() printf( "\n\n"); } -#define key_ismod(k) ((k&0xff)==KEY_LALT || (k&0xff)==KEY_RALT || (k&0xff)==KEY_LSHIFT || (k&0xff)==KEY_RSHIFT || (k&0xff)==KEY_LCTRL || (k&0xff)==KEY_RCTRL || (k&0xff)==KEY_LMETA || (k&0xff)==KEY_RMETA) - int Quitting = 0; // Default event handler for everything except the editor @@ -184,8 +181,6 @@ int standard_handler(d_event *event) { int key; - timer_update(); - if (Quitting) { window *wind = window_get_front(); @@ -224,11 +219,6 @@ int standard_handler(d_event *event) case EVENT_KEY_COMMAND: key = event_key_get(event); - // Don't let modifier(s) on their own do something unless we explicitly want that - // (e.g. if it's a game control like fire primary) - if (key_ismod(key)) - return 1; - switch (key) { #ifdef macintosh diff --git a/main/kconfig.c b/main/kconfig.c index 7fa8092b3..6283d3268 100644 --- a/main/kconfig.c +++ b/main/kconfig.c @@ -80,6 +80,11 @@ fix Cruise_speed=0; #define BT_JOY_BUTTON 3 #define BT_JOY_AXIS 4 #define BT_INVERT 5 +#define STATE_BIT1 1 +#define STATE_BIT2 2 +#define STATE_BIT3 4 +#define STATE_BIT4 8 +#define STATE_BIT5 16 char *btype_text[] = { "BT_KEY", "BT_MOUSE_BUTTON", "BT_MOUSE_AXIS", "BT_JOY_BUTTON", "BT_JOY_AXIS", "BT_INVERT" }; @@ -95,18 +100,20 @@ typedef struct kc_item { char *text; ubyte type; ubyte value; // what key,button,etc + ubyte *ci_state_ptr; + int state_bit; + ubyte *ci_count_ptr; } kc_item; -int Num_items=23; - typedef struct kc_menu { window *wind; kc_item *items; char *title; - int nitems; - int citem; - int old_axis[JOY_MAX_AXES]; + int nitems; + int citem; + int old_jaxis[JOY_MAX_AXES]; + int old_maxis[3]; ubyte changing; ubyte q_fade_i; // for flashing the question mark ubyte mouse_state; @@ -121,177 +128,177 @@ ubyte DefaultKeySettingsD1X[MAX_D1X_CONTROLS] = { 0x2,0xff,0xff,0x3,0xff,0xff,0x // id, x, y, w1, w2, u, d, l, r, text, type, value kc_item kc_keyboard[NUM_KEY_CONTROLS] = { - { 0, 15, 49, 71, 26, 43, 2, 49, 1,"Pitch forward", BT_KEY, 255 }, - { 1, 15, 49,100, 26, 48, 3, 0, 24,"Pitch forward", BT_KEY, 255 }, - { 2, 15, 57, 71, 26, 0, 4, 25, 3,"Pitch backward", BT_KEY, 255 }, - { 3, 15, 57,100, 26, 1, 5, 2, 26,"Pitch backward", BT_KEY, 255 }, - { 4, 15, 65, 71, 26, 2, 6, 27, 5,"Turn left", BT_KEY, 255 }, - { 5, 15, 65,100, 26, 3, 7, 4, 28,"Turn left", BT_KEY, 255 }, - { 6, 15, 73, 71, 26, 4, 8, 29, 7,"Turn right", BT_KEY, 255 }, - { 7, 15, 73,100, 26, 5, 9, 6, 34,"Turn right", BT_KEY, 255 }, - { 8, 15, 85, 71, 26, 6, 10, 35, 9,"Slide on", BT_KEY, 255 }, - { 9, 15, 85,100, 26, 7, 11, 8, 36,"Slide on", BT_KEY, 255 }, - { 10, 15, 93, 71, 26, 8, 12, 37, 11,"Slide left", BT_KEY, 255 }, - { 11, 15, 93,100, 26, 9, 13, 10, 44,"Slide left", BT_KEY, 255 }, - { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255 }, - { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255 }, - { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255 }, - { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255 }, - { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255 }, - { 17, 15,117,100, 26, 15, 19, 16, 38,"Slide down", BT_KEY, 255 }, - { 18, 15,129, 71, 26, 16, 20, 39, 19,"Bank on", BT_KEY, 255 }, - { 19, 15,129,100, 26, 17, 21, 18, 40,"Bank on", BT_KEY, 255 }, - { 20, 15,137, 71, 26, 18, 22, 41, 21,"Bank left", BT_KEY, 255 }, - { 21, 15,137,100, 26, 19, 23, 20, 42,"Bank left", BT_KEY, 255 }, - { 22, 15,145, 71, 26, 20, 46, 43, 23,"Bank right", BT_KEY, 255 }, - { 23, 15,145,100, 26, 21, 47, 22, 46,"Bank right", BT_KEY, 255 }, - { 24,158, 49, 83, 26, 49, 26, 1, 25,"Fire primary", BT_KEY, 255 }, - { 25,158, 49,112, 26, 42, 27, 24, 2,"Fire primary", BT_KEY, 255 }, - { 26,158, 57, 83, 26, 24, 28, 3, 27,"Fire secondary", BT_KEY, 255 }, - { 27,158, 57,112, 26, 25, 29, 26, 4,"Fire secondary", BT_KEY, 255 }, - { 28,158, 65, 83, 26, 26, 34, 5, 29,"Fire flare", BT_KEY, 255 }, - { 29,158, 65,112, 26, 27, 35, 28, 6,"Fire flare", BT_KEY, 255 }, - { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255 }, - { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255 }, - { 32,158,113, 83, 26, 30, 38, 15, 33,"Reverse", BT_KEY, 255 }, - { 33,158,113,112, 26, 31, 39, 32, 16,"Reverse", BT_KEY, 255 }, - { 34,158, 73, 83, 26, 28, 36, 7, 35,"Drop bomb", BT_KEY, 255 }, - { 35,158, 73,112, 26, 29, 37, 34, 8,"Drop bomb", BT_KEY, 255 }, - { 36,158, 85, 83, 26, 34, 44, 9, 37,"Rear view", BT_KEY, 255 }, - { 37,158, 85,112, 26, 35, 45, 36, 10,"Rear view", BT_KEY, 255 }, - { 38,158,125, 83, 26, 32, 40, 17, 39,"Cruise faster", BT_KEY, 255 }, - { 39,158,125,112, 26, 33, 41, 38, 18,"Cruise faster", BT_KEY, 255 }, - { 40,158,133, 83, 26, 38, 42, 19, 41,"Cruise slower", BT_KEY, 255 }, - { 41,158,133,112, 26, 39, 43, 40, 20,"Cruise slower", BT_KEY, 255 }, - { 42,158,141, 83, 26, 40, 25, 21, 43,"Cruise off", BT_KEY, 255 }, - { 43,158,141,112, 26, 41, 0, 42, 22,"Cruise off", BT_KEY, 255 }, - { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255 }, - { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255 }, - { 46, 15,157, 71, 26, 22, 48, 23, 47,"Cycle Primary", BT_KEY, 255 }, - { 47, 15,157,100, 26, 23, 49, 46, 48,"Cycle Primary", BT_KEY, 255 }, - { 48, 15,165, 71, 26, 46, 1, 47, 49,"Cycle Second.", BT_KEY, 255 }, - { 49, 15,165,100, 26, 47, 24, 48, 0,"Cycle Second.", BT_KEY, 255 }, + { 0, 15, 49, 71, 26, 43, 2, 49, 1,"Pitch forward", BT_KEY, 255, &Controls.pitch_forward_state, STATE_BIT1, NULL }, + { 1, 15, 49,100, 26, 48, 3, 0, 24,"Pitch forward", BT_KEY, 255, &Controls.pitch_forward_state, STATE_BIT2, NULL }, + { 2, 15, 57, 71, 26, 0, 4, 25, 3,"Pitch backward", BT_KEY, 255, &Controls.pitch_backward_state, STATE_BIT1, NULL }, + { 3, 15, 57,100, 26, 1, 5, 2, 26,"Pitch backward", BT_KEY, 255, &Controls.pitch_backward_state, STATE_BIT2, NULL }, + { 4, 15, 65, 71, 26, 2, 6, 27, 5,"Turn left", BT_KEY, 255, &Controls.heading_left_state, STATE_BIT1, NULL }, + { 5, 15, 65,100, 26, 3, 7, 4, 28,"Turn left", BT_KEY, 255, &Controls.heading_left_state, STATE_BIT2, NULL }, + { 6, 15, 73, 71, 26, 4, 8, 29, 7,"Turn right", BT_KEY, 255, &Controls.heading_right_state, STATE_BIT1, NULL }, + { 7, 15, 73,100, 26, 5, 9, 6, 34,"Turn right", BT_KEY, 255, &Controls.heading_right_state, STATE_BIT2, NULL }, + { 8, 15, 85, 71, 26, 6, 10, 35, 9,"Slide on", BT_KEY, 255, &Controls.slide_on_state, STATE_BIT1, NULL }, + { 9, 15, 85,100, 26, 7, 11, 8, 36,"Slide on", BT_KEY, 255, &Controls.slide_on_state, STATE_BIT2, NULL }, + { 10, 15, 93, 71, 26, 8, 12, 37, 11,"Slide left", BT_KEY, 255, &Controls.slide_left_state, STATE_BIT1, NULL }, + { 11, 15, 93,100, 26, 9, 13, 10, 44,"Slide left", BT_KEY, 255, &Controls.slide_left_state, STATE_BIT2, NULL }, + { 12, 15,101, 71, 26, 10, 14, 45, 13,"Slide right", BT_KEY, 255, &Controls.slide_right_state, STATE_BIT1, NULL }, + { 13, 15,101,100, 26, 11, 15, 12, 30,"Slide right", BT_KEY, 255, &Controls.slide_right_state, STATE_BIT2, NULL }, + { 14, 15,109, 71, 26, 12, 16, 31, 15,"Slide up", BT_KEY, 255, &Controls.slide_up_state, STATE_BIT1, NULL }, + { 15, 15,109,100, 26, 13, 17, 14, 32,"Slide up", BT_KEY, 255, &Controls.slide_up_state, STATE_BIT2, NULL }, + { 16, 15,117, 71, 26, 14, 18, 33, 17,"Slide down", BT_KEY, 255, &Controls.slide_down_state, STATE_BIT1, NULL }, + { 17, 15,117,100, 26, 15, 19, 16, 38,"Slide down", BT_KEY, 255, &Controls.slide_down_state, STATE_BIT2, NULL }, + { 18, 15,129, 71, 26, 16, 20, 39, 19,"Bank on", BT_KEY, 255, &Controls.bank_on_state, STATE_BIT1, NULL }, + { 19, 15,129,100, 26, 17, 21, 18, 40,"Bank on", BT_KEY, 255, &Controls.bank_on_state, STATE_BIT2, NULL }, + { 20, 15,137, 71, 26, 18, 22, 41, 21,"Bank left", BT_KEY, 255, &Controls.bank_left_state, STATE_BIT1, NULL }, + { 21, 15,137,100, 26, 19, 23, 20, 42,"Bank left", BT_KEY, 255, &Controls.bank_left_state, STATE_BIT2, NULL }, + { 22, 15,145, 71, 26, 20, 46, 43, 23,"Bank right", BT_KEY, 255, &Controls.bank_right_state, STATE_BIT1, NULL }, + { 23, 15,145,100, 26, 21, 47, 22, 46,"Bank right", BT_KEY, 255, &Controls.bank_right_state, STATE_BIT2, NULL }, + { 24,158, 49, 83, 26, 49, 26, 1, 25,"Fire primary", BT_KEY, 255, &Controls.fire_primary_state, STATE_BIT1, &Controls.fire_primary_count }, + { 25,158, 49,112, 26, 42, 27, 24, 2,"Fire primary", BT_KEY, 255, &Controls.fire_primary_state, STATE_BIT2, &Controls.fire_primary_count }, + { 26,158, 57, 83, 26, 24, 28, 3, 27,"Fire secondary", BT_KEY, 255, &Controls.fire_secondary_state, STATE_BIT1, &Controls.fire_secondary_count }, + { 27,158, 57,112, 26, 25, 29, 26, 4,"Fire secondary", BT_KEY, 255, &Controls.fire_secondary_state, STATE_BIT2, &Controls.fire_secondary_count }, + { 28,158, 65, 83, 26, 26, 34, 5, 29,"Fire flare", BT_KEY, 255, NULL, 0, &Controls.fire_flare_count }, + { 29,158, 65,112, 26, 27, 35, 28, 6,"Fire flare", BT_KEY, 255, NULL, 0, &Controls.fire_flare_count }, + { 30,158,105, 83, 26, 44, 32, 13, 31,"Accelerate", BT_KEY, 255, &Controls.accelerate_state, STATE_BIT1, NULL }, + { 31,158,105,112, 26, 45, 33, 30, 14,"Accelerate", BT_KEY, 255, &Controls.accelerate_state, STATE_BIT2, NULL }, + { 32,158,113, 83, 26, 30, 38, 15, 33,"Reverse", BT_KEY, 255, &Controls.reverse_state, STATE_BIT1, NULL }, + { 33,158,113,112, 26, 31, 39, 32, 16,"Reverse", BT_KEY, 255, &Controls.reverse_state, STATE_BIT2, NULL }, + { 34,158, 73, 83, 26, 28, 36, 7, 35,"Drop bomb", BT_KEY, 255, NULL, 0, &Controls.drop_bomb_count }, + { 35,158, 73,112, 26, 29, 37, 34, 8,"Drop bomb", BT_KEY, 255, NULL, 0, &Controls.drop_bomb_count }, + { 36,158, 85, 83, 26, 34, 44, 9, 37,"Rear view", BT_KEY, 255, &Controls.rear_view_state, STATE_BIT1, &Controls.rear_view_count }, + { 37,158, 85,112, 26, 35, 45, 36, 10,"Rear view", BT_KEY, 255, &Controls.rear_view_state, STATE_BIT2, &Controls.rear_view_count }, + { 38,158,125, 83, 26, 32, 40, 17, 39,"Cruise faster", BT_KEY, 255, &Controls.cruise_plus_state, STATE_BIT1, NULL }, + { 39,158,125,112, 26, 33, 41, 38, 18,"Cruise faster", BT_KEY, 255, &Controls.cruise_plus_state, STATE_BIT2, NULL }, + { 40,158,133, 83, 26, 38, 42, 19, 41,"Cruise slower", BT_KEY, 255, &Controls.cruise_minus_state, STATE_BIT1, NULL }, + { 41,158,133,112, 26, 39, 43, 40, 20,"Cruise slower", BT_KEY, 255, &Controls.cruise_minus_state, STATE_BIT2, NULL }, + { 42,158,141, 83, 26, 40, 25, 21, 43,"Cruise off", BT_KEY, 255, NULL, 0, &Controls.cruise_off_count }, + { 43,158,141,112, 26, 41, 0, 42, 22,"Cruise off", BT_KEY, 255, NULL, 0, &Controls.cruise_off_count }, + { 44,158, 93, 83, 26, 36, 30, 11, 45,"Automap", BT_KEY, 255, &Controls.automap_state, STATE_BIT1, &Controls.automap_count }, + { 45,158, 93,112, 26, 37, 31, 44, 12,"Automap", BT_KEY, 255, &Controls.automap_state, STATE_BIT2, &Controls.automap_count }, + { 46, 15,157, 71, 26, 22, 48, 23, 47,"Cycle Primary", BT_KEY, 255, NULL, 0, &Controls.cycle_primary_count }, + { 47, 15,157,100, 26, 23, 49, 46, 48,"Cycle Primary", BT_KEY, 255, NULL, 0, &Controls.cycle_primary_count }, + { 48, 15,165, 71, 26, 46, 1, 47, 49,"Cycle Second.", BT_KEY, 255, NULL, 0, &Controls.cycle_secondary_count }, + { 49, 15,165,100, 26, 47, 24, 48, 0,"Cycle Second.", BT_KEY, 255, NULL, 0, &Controls.cycle_secondary_count }, }; kc_item kc_joystick[NUM_JOYSTICK_CONTROLS] = { - { 0, 22, 46, 82, 26, 15, 1, 24, 29,"Fire primary", BT_JOY_BUTTON, 255 }, - { 1, 22, 54, 82, 26, 0, 4, 34, 30,"Fire secondary", BT_JOY_BUTTON, 255 }, - { 2, 22, 78, 82, 26, 26, 3, 37, 31,"Accelerate", BT_JOY_BUTTON, 255 }, - { 3, 22, 86, 82, 26, 2, 25, 38, 32,"Reverse", BT_JOY_BUTTON, 255 }, - { 4, 22, 62, 82, 26, 1, 26, 35, 33,"Fire flare", BT_JOY_BUTTON, 255 }, - { 5,174, 46, 74, 26, 23, 6, 29, 34,"Slide on", BT_JOY_BUTTON, 255 }, - { 6,174, 54, 74, 26, 5, 7, 30, 35,"Slide left", BT_JOY_BUTTON, 255 }, - { 7,174, 62, 74, 26, 6, 8, 33, 36,"Slide right", BT_JOY_BUTTON, 255 }, - { 8,174, 70, 74, 26, 7, 9, 43, 37,"Slide up", BT_JOY_BUTTON, 255 }, - { 9,174, 78, 74, 26, 8, 10, 31, 38,"Slide down", BT_JOY_BUTTON, 255 }, - { 10,174, 86, 74, 26, 9, 11, 32, 39,"Bank on", BT_JOY_BUTTON, 255 }, - { 11,174, 94, 74, 26, 10, 12, 42, 40,"Bank left", BT_JOY_BUTTON, 255 }, - { 12,174,102, 74, 26, 11, 44, 28, 41,"Bank right", BT_JOY_BUTTON, 255 }, - { 13, 22,154, 51, 26, 47, 15, 47, 14,"Pitch U/D", BT_JOY_AXIS, 255 }, - { 14, 22,154, 99, 8, 27, 16, 13, 17,"Pitch U/D", BT_INVERT, 255 }, - { 15, 22,162, 51, 26, 13, 0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255 }, - { 16, 22,162, 99, 8, 14, 29, 15, 19,"Turn L/R", BT_INVERT, 255 }, - { 17,164,154, 58, 26, 28, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255 }, - { 18,164,154,106, 8, 45, 20, 17, 15,"Slide L/R", BT_INVERT, 255 }, - { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255 }, - { 20,164,162,106, 8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255 }, - { 21,164,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255 }, - { 22,164,170,106, 8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255 }, - { 23,164,178, 58, 26, 21, 5, 22, 24,"Throttle", BT_JOY_AXIS, 255 }, - { 24,164,178,106, 8, 22, 34, 23, 0,"Throttle", BT_INVERT, 255 }, - { 25, 22, 94, 82, 26, 3, 27, 39, 42,"Rear view", BT_JOY_BUTTON, 255 }, - { 26, 22, 70, 82, 26, 4, 2, 36, 43,"Drop bomb", BT_JOY_BUTTON, 255 }, - { 27, 22,102, 82, 26, 25, 14, 40, 28,"Automap", BT_JOY_BUTTON, 255 }, - { 28, 22,102,111, 26, 42, 17, 27, 12,"Automap", BT_JOY_BUTTON, 255 }, - { 29, 22, 46,111, 26, 16, 30, 0, 5,"Fire primary", BT_JOY_BUTTON, 255 }, - { 30, 22, 54,111, 26, 29, 33, 1, 6,"Fire secondary", BT_JOY_BUTTON, 255 }, - { 31, 22, 78,111, 26, 43, 32, 2, 9,"Accelerate", BT_JOY_BUTTON, 255 }, - { 32, 22, 86,111, 26, 31, 42, 3, 10,"Reverse", BT_JOY_BUTTON, 255 }, - { 33, 22, 62,111, 26, 30, 43, 4, 7,"Fire flare", BT_JOY_BUTTON, 255 }, - { 34,174, 46,104, 26, 24, 35, 5, 1,"Slide on", BT_JOY_BUTTON, 255 }, - { 35,174, 54,104, 26, 34, 36, 6, 4,"Slide left", BT_JOY_BUTTON, 255 }, - { 36,174, 62,104, 26, 35, 37, 7, 26,"Slide right", BT_JOY_BUTTON, 255 }, - { 37,174, 70,104, 26, 36, 38, 8, 2,"Slide up", BT_JOY_BUTTON, 255 }, - { 38,174, 78,104, 26, 37, 39, 9, 3,"Slide down", BT_JOY_BUTTON, 255 }, - { 39,174, 86,104, 26, 38, 40, 10, 25,"Bank on", BT_JOY_BUTTON, 255 }, - { 40,174, 94,104, 26, 39, 41, 11, 27,"Bank left", BT_JOY_BUTTON, 255 }, - { 41,174,102,104, 26, 40, 46, 12, 44,"Bank right", BT_JOY_BUTTON, 255 }, - { 42, 22, 94,111, 26, 32, 28, 25, 11,"Rear view", BT_JOY_BUTTON, 255 }, - { 43, 22, 70,111, 26, 33, 31, 26, 8,"Drop bomb", BT_JOY_BUTTON, 255 }, - { 44,174,110, 74, 26, 12, 45, 41, 46,"Cycle Primary", BT_JOY_BUTTON, 255 }, - { 45,174,118, 74, 26, 44, 18, 46, 47,"Cycle Secondary", BT_JOY_BUTTON, 255 }, - { 46,174,110,104, 26, 41, 47, 44, 45,"Cycle Primary", BT_JOY_BUTTON, 255 }, - { 47,174,118,104, 26, 46, 13, 45, 13,"Cycle Secondary", BT_JOY_BUTTON, 255 }, + { 0, 22, 46, 82, 26, 15, 1, 24, 29,"Fire primary", BT_JOY_BUTTON, 255, &Controls.fire_primary_state, STATE_BIT3, &Controls.fire_primary_count }, + { 1, 22, 54, 82, 26, 0, 4, 34, 30,"Fire secondary", BT_JOY_BUTTON, 255, &Controls.fire_secondary_state, STATE_BIT3, &Controls.fire_secondary_count }, + { 2, 22, 78, 82, 26, 26, 3, 37, 31,"Accelerate", BT_JOY_BUTTON, 255, &Controls.accelerate_state, STATE_BIT3, NULL }, + { 3, 22, 86, 82, 26, 2, 25, 38, 32,"Reverse", BT_JOY_BUTTON, 255, &Controls.reverse_state, STATE_BIT3, NULL }, + { 4, 22, 62, 82, 26, 1, 26, 35, 33,"Fire flare", BT_JOY_BUTTON, 255, NULL, 0, &Controls.fire_flare_count }, + { 5,174, 46, 74, 26, 23, 6, 29, 34,"Slide on", BT_JOY_BUTTON, 255, &Controls.slide_on_state, STATE_BIT3, NULL }, + { 6,174, 54, 74, 26, 5, 7, 30, 35,"Slide left", BT_JOY_BUTTON, 255, &Controls.slide_left_state, STATE_BIT3, NULL }, + { 7,174, 62, 74, 26, 6, 8, 33, 36,"Slide right", BT_JOY_BUTTON, 255, &Controls.slide_right_state, STATE_BIT3, NULL }, + { 8,174, 70, 74, 26, 7, 9, 43, 37,"Slide up", BT_JOY_BUTTON, 255, &Controls.slide_up_state, STATE_BIT3, NULL }, + { 9,174, 78, 74, 26, 8, 10, 31, 38,"Slide down", BT_JOY_BUTTON, 255, &Controls.slide_down_state, STATE_BIT3, NULL }, + { 10,174, 86, 74, 26, 9, 11, 32, 39,"Bank on", BT_JOY_BUTTON, 255, &Controls.bank_on_state, STATE_BIT3, NULL }, + { 11,174, 94, 74, 26, 10, 12, 42, 40,"Bank left", BT_JOY_BUTTON, 255, &Controls.bank_left_state, STATE_BIT3, NULL }, + { 12,174,102, 74, 26, 11, 44, 28, 41,"Bank right", BT_JOY_BUTTON, 255, &Controls.bank_right_state, STATE_BIT3, NULL }, + { 13, 22,154, 51, 26, 47, 15, 47, 14,"Pitch U/D", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 14, 22,154, 99, 8, 27, 16, 13, 17,"Pitch U/D", BT_INVERT, 255, NULL, 0, NULL }, + { 15, 22,162, 51, 26, 13, 0, 18, 16,"Turn L/R", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 16, 22,162, 99, 8, 14, 29, 15, 19,"Turn L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 17,164,154, 58, 26, 28, 19, 14, 18,"Slide L/R", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 18,164,154,106, 8, 45, 20, 17, 15,"Slide L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 19,164,162, 58, 26, 17, 21, 16, 20,"Slide U/D", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 20,164,162,106, 8, 18, 22, 19, 21,"Slide U/D", BT_INVERT, 255, NULL, 0, NULL }, + { 21,164,170, 58, 26, 19, 23, 20, 22,"Bank L/R", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 22,164,170,106, 8, 20, 24, 21, 23,"Bank L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 23,164,178, 58, 26, 21, 5, 22, 24,"Throttle", BT_JOY_AXIS, 255, NULL, 0, NULL }, + { 24,164,178,106, 8, 22, 34, 23, 0,"Throttle", BT_INVERT, 255, NULL, 0, NULL }, + { 25, 22, 94, 82, 26, 3, 27, 39, 42,"Rear view", BT_JOY_BUTTON, 255, &Controls.rear_view_state, STATE_BIT3, &Controls.rear_view_count }, + { 26, 22, 70, 82, 26, 4, 2, 36, 43,"Drop bomb", BT_JOY_BUTTON, 255, NULL, 0, &Controls.drop_bomb_count }, + { 27, 22,102, 82, 26, 25, 14, 40, 28,"Automap", BT_JOY_BUTTON, 255, &Controls.automap_state, STATE_BIT3, &Controls.automap_count }, + { 28, 22,102,111, 26, 42, 17, 27, 12,"Automap", BT_JOY_BUTTON, 255, &Controls.automap_state, STATE_BIT4, &Controls.automap_count }, + { 29, 22, 46,111, 26, 16, 30, 0, 5,"Fire primary", BT_JOY_BUTTON, 255, &Controls.fire_primary_state, STATE_BIT4, &Controls.fire_primary_count }, + { 30, 22, 54,111, 26, 29, 33, 1, 6,"Fire secondary", BT_JOY_BUTTON, 255, &Controls.fire_secondary_state, STATE_BIT4, &Controls.fire_secondary_count }, + { 31, 22, 78,111, 26, 43, 32, 2, 9,"Accelerate", BT_JOY_BUTTON, 255, &Controls.accelerate_state, STATE_BIT4, NULL }, + { 32, 22, 86,111, 26, 31, 42, 3, 10,"Reverse", BT_JOY_BUTTON, 255, &Controls.reverse_state, STATE_BIT4, NULL }, + { 33, 22, 62,111, 26, 30, 43, 4, 7,"Fire flare", BT_JOY_BUTTON, 255, NULL, 0, &Controls.fire_flare_count }, + { 34,174, 46,104, 26, 24, 35, 5, 1,"Slide on", BT_JOY_BUTTON, 255, &Controls.slide_on_state, STATE_BIT4, NULL }, + { 35,174, 54,104, 26, 34, 36, 6, 4,"Slide left", BT_JOY_BUTTON, 255, &Controls.slide_left_state, STATE_BIT4, NULL }, + { 36,174, 62,104, 26, 35, 37, 7, 26,"Slide right", BT_JOY_BUTTON, 255, &Controls.slide_right_state, STATE_BIT4, NULL }, + { 37,174, 70,104, 26, 36, 38, 8, 2,"Slide up", BT_JOY_BUTTON, 255, &Controls.slide_up_state, STATE_BIT4, NULL }, + { 38,174, 78,104, 26, 37, 39, 9, 3,"Slide down", BT_JOY_BUTTON, 255, &Controls.slide_down_state, STATE_BIT4, NULL }, + { 39,174, 86,104, 26, 38, 40, 10, 25,"Bank on", BT_JOY_BUTTON, 255, &Controls.bank_on_state, STATE_BIT4, NULL }, + { 40,174, 94,104, 26, 39, 41, 11, 27,"Bank left", BT_JOY_BUTTON, 255, &Controls.bank_left_state, STATE_BIT4, NULL }, + { 41,174,102,104, 26, 40, 46, 12, 44,"Bank right", BT_JOY_BUTTON, 255, &Controls.bank_right_state, STATE_BIT4, NULL }, + { 42, 22, 94,111, 26, 32, 28, 25, 11,"Rear view", BT_JOY_BUTTON, 255, &Controls.rear_view_state, STATE_BIT4, &Controls.rear_view_count }, + { 43, 22, 70,111, 26, 33, 31, 26, 8,"Drop bomb", BT_JOY_BUTTON, 255, NULL, 0, &Controls.drop_bomb_count }, + { 44,174,110, 74, 26, 12, 45, 41, 46,"Cycle Primary", BT_JOY_BUTTON, 255, NULL, 0, &Controls.cycle_primary_count }, + { 45,174,118, 74, 26, 44, 18, 46, 47,"Cycle Secondary", BT_JOY_BUTTON, 255, NULL, 0, &Controls.cycle_secondary_count }, + { 46,174,110,104, 26, 41, 47, 44, 45,"Cycle Primary", BT_JOY_BUTTON, 255, NULL, 0, &Controls.cycle_primary_count }, + { 47,174,118,104, 26, 46, 13, 45, 13,"Cycle Secondary", BT_JOY_BUTTON, 255, NULL, 0, &Controls.cycle_secondary_count }, }; kc_item kc_mouse[NUM_MOUSE_CONTROLS] = { - { 0, 25, 46, 85, 26, 19, 1, 20, 5,"Fire primary", BT_MOUSE_BUTTON, 255 }, - { 1, 25, 54, 85, 26, 0, 4, 5, 6,"Fire secondary", BT_MOUSE_BUTTON, 255 }, - { 2, 25, 78, 85, 26, 26, 3, 8, 9,"Accelerate", BT_MOUSE_BUTTON, 255 }, - { 3, 25, 86, 85, 26, 2, 25, 9, 10,"Reverse", BT_MOUSE_BUTTON, 255 }, - { 4, 25, 62, 85, 26, 1, 26, 6, 7,"Fire flare", BT_MOUSE_BUTTON, 255 }, - { 5,180, 46, 59, 26, 23, 6, 0, 1,"Slide on", BT_MOUSE_BUTTON, 255 }, - { 6,180, 54, 59, 26, 5, 7, 1, 4,"Slide left", BT_MOUSE_BUTTON, 255 }, - { 7,180, 62, 59, 26, 6, 8, 4, 26,"Slide right", BT_MOUSE_BUTTON, 255 }, - { 8,180, 70, 59, 26, 7, 9, 26, 2,"Slide up", BT_MOUSE_BUTTON, 255 }, - { 9,180, 78, 59, 26, 8, 10, 2, 3,"Slide down", BT_MOUSE_BUTTON, 255 }, - { 10,180, 86, 59, 26, 9, 11, 3, 25,"Bank on", BT_MOUSE_BUTTON, 255 }, - { 11,180, 94, 59, 26, 10, 12, 25, 27,"Bank left", BT_MOUSE_BUTTON, 255 }, - { 12,180,102, 59, 26, 11, 22, 27, 28,"Bank right", BT_MOUSE_BUTTON, 255 }, - { 13, 25,154, 58, 26, 24, 15, 28, 14,"Pitch U/D", BT_MOUSE_AXIS, 255 }, - { 14, 25,154,106, 8, 28, 16, 13, 21,"Pitch U/D", BT_INVERT, 255 }, - { 15, 25,162, 58, 26, 13, 17, 22, 16,"Turn L/R", BT_MOUSE_AXIS, 255 }, - { 16, 25,162,106, 8, 14, 18, 15, 23,"Turn L/R", BT_INVERT, 255 }, - { 17, 25,170, 58, 26, 15, 19, 24, 18,"Slide L/R", BT_MOUSE_AXIS, 255 }, - { 18, 25,170,106, 8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255 }, - { 19, 25,178, 58, 26, 17, 0, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255 }, - { 20, 25,178,106, 8, 18, 21, 19, 0,"Slide U/D", BT_INVERT, 255 }, - { 21,180,154, 58, 26, 20, 23, 14, 22,"Bank L/R", BT_MOUSE_AXIS, 255 }, - { 22,180,154,106, 8, 12, 24, 21, 15,"Bank L/R", BT_INVERT, 255 }, - { 23,180,162, 58, 26, 21, 5, 16, 24,"Throttle", BT_MOUSE_AXIS, 255 }, - { 24,180,162,106, 8, 22, 13, 23, 17,"Throttle", BT_INVERT, 255 }, - { 25, 25, 94, 85, 26, 3, 27, 10, 11,"Rear view", BT_MOUSE_BUTTON, 255 }, - { 26, 25, 70, 85, 26, 4, 2, 7, 8,"Drop bomb", BT_MOUSE_BUTTON, 255 }, - { 27, 25,102, 85, 26, 25, 28, 11, 12,"Cycle Primary", BT_MOUSE_BUTTON, 255 }, - { 28, 25,110, 85, 26, 27, 14, 12, 13,"Cycle Secondary", BT_MOUSE_BUTTON, 255 }, + { 0, 25, 46, 85, 26, 19, 1, 20, 5,"Fire primary", BT_MOUSE_BUTTON, 255, &Controls.fire_primary_state, STATE_BIT5, &Controls.fire_primary_count }, + { 1, 25, 54, 85, 26, 0, 4, 5, 6,"Fire secondary", BT_MOUSE_BUTTON, 255, &Controls.fire_secondary_state, STATE_BIT5, &Controls.fire_secondary_count }, + { 2, 25, 78, 85, 26, 26, 3, 8, 9,"Accelerate", BT_MOUSE_BUTTON, 255, &Controls.accelerate_state, STATE_BIT5, NULL }, + { 3, 25, 86, 85, 26, 2, 25, 9, 10,"Reverse", BT_MOUSE_BUTTON, 255, &Controls.reverse_state, STATE_BIT5, NULL }, + { 4, 25, 62, 85, 26, 1, 26, 6, 7,"Fire flare", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.fire_flare_count }, + { 5,180, 46, 59, 26, 23, 6, 0, 1,"Slide on", BT_MOUSE_BUTTON, 255, &Controls.slide_on_state, STATE_BIT5, NULL }, + { 6,180, 54, 59, 26, 5, 7, 1, 4,"Slide left", BT_MOUSE_BUTTON, 255, &Controls.slide_left_state, STATE_BIT5, NULL }, + { 7,180, 62, 59, 26, 6, 8, 4, 26,"Slide right", BT_MOUSE_BUTTON, 255, &Controls.slide_right_state, STATE_BIT5, NULL }, + { 8,180, 70, 59, 26, 7, 9, 26, 2,"Slide up", BT_MOUSE_BUTTON, 255, &Controls.slide_up_state, STATE_BIT5, NULL }, + { 9,180, 78, 59, 26, 8, 10, 2, 3,"Slide down", BT_MOUSE_BUTTON, 255, &Controls.slide_down_state, STATE_BIT5, NULL }, + { 10,180, 86, 59, 26, 9, 11, 3, 25,"Bank on", BT_MOUSE_BUTTON, 255, &Controls.bank_on_state, STATE_BIT5, NULL }, + { 11,180, 94, 59, 26, 10, 12, 25, 27,"Bank left", BT_MOUSE_BUTTON, 255, &Controls.bank_left_state, STATE_BIT5, NULL }, + { 12,180,102, 59, 26, 11, 22, 27, 28,"Bank right", BT_MOUSE_BUTTON, 255, &Controls.bank_right_state, STATE_BIT5, NULL }, + { 13, 25,154, 58, 26, 24, 15, 28, 14,"Pitch U/D", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 14, 25,154,106, 8, 28, 16, 13, 21,"Pitch U/D", BT_INVERT, 255, NULL, 0, NULL }, + { 15, 25,162, 58, 26, 13, 17, 22, 16,"Turn L/R", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 16, 25,162,106, 8, 14, 18, 15, 23,"Turn L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 17, 25,170, 58, 26, 15, 19, 24, 18,"Slide L/R", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 18, 25,170,106, 8, 16, 20, 17, 19,"Slide L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 19, 25,178, 58, 26, 17, 0, 18, 20,"Slide U/D", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 20, 25,178,106, 8, 18, 21, 19, 0,"Slide U/D", BT_INVERT, 255, NULL, 0, NULL }, + { 21,180,154, 58, 26, 20, 23, 14, 22,"Bank L/R", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 22,180,154,106, 8, 12, 24, 21, 15,"Bank L/R", BT_INVERT, 255, NULL, 0, NULL }, + { 23,180,162, 58, 26, 21, 5, 16, 24,"Throttle", BT_MOUSE_AXIS, 255, NULL, 0, NULL }, + { 24,180,162,106, 8, 22, 13, 23, 17,"Throttle", BT_INVERT, 255, NULL, 0, NULL }, + { 25, 25, 94, 85, 26, 3, 27, 10, 11,"Rear view", BT_MOUSE_BUTTON, 255, &Controls.rear_view_state, STATE_BIT5, &Controls.rear_view_count }, + { 26, 25, 70, 85, 26, 4, 2, 7, 8,"Drop bomb", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.drop_bomb_count }, + { 27, 25,102, 85, 26, 25, 28, 11, 12,"Cycle Primary", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.cycle_primary_count }, + { 28, 25,110, 85, 26, 27, 14, 12, 13,"Cycle Secondary", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.cycle_secondary_count }, }; kc_item kc_d1x[NUM_D1X_CONTROLS] = { - { 0, 15, 69,142, 26, 29, 3, 29, 1,"LASER CANNON", BT_KEY, 255 }, - { 1, 15, 69,200, 26, 27, 4, 0, 2,"LASER CANNON", BT_JOY_BUTTON, 255 }, - { 2, 15, 69,258, 26, 28, 5, 1, 3,"LASER CANNON", BT_MOUSE_BUTTON, 255 }, - { 3, 15, 77,142, 26, 0, 6, 2, 4,"VULCAN CANNON", BT_KEY, 255 }, - { 4, 15, 77,200, 26, 1, 7, 3, 5,"VULCAN CANNON", BT_JOY_BUTTON, 255 }, - { 5, 15, 77,258, 26, 2, 8, 4, 6,"VULCAN CANNON", BT_MOUSE_BUTTON, 255 }, - { 6, 15, 85,142, 26, 3, 9, 5, 7,"SPREADFIRE CANNON", BT_KEY, 255 }, - { 7, 15, 85,200, 26, 4, 10, 6, 8,"SPREADFIRE CANNON", BT_JOY_BUTTON, 255 }, - { 8, 15, 85,258, 26, 5, 11, 7, 9,"SPREADFIRE CANNON", BT_MOUSE_BUTTON, 255 }, - { 9, 15, 93,142, 26, 6, 12, 8, 10,"PLASMA CANNON", BT_KEY, 255 }, - { 10, 15, 93,200, 26, 7, 13, 9, 11,"PLASMA CANNON", BT_JOY_BUTTON, 255 }, - { 11, 15, 93,258, 26, 8, 14, 10, 12,"PLASMA CANNON", BT_MOUSE_BUTTON, 255 }, - { 12, 15,101,142, 26, 9, 15, 11, 13,"FUSION CANNON", BT_KEY, 255 }, - { 13, 15,101,200, 26, 10, 16, 12, 14,"FUSION CANNON", BT_JOY_BUTTON, 255 }, - { 14, 15,101,258, 26, 11, 17, 13, 15,"FUSION CANNON", BT_JOY_BUTTON, 255 }, - { 15, 15,109,142, 26, 12, 18, 14, 16,"CONCUSSION MISSILE", BT_KEY, 255 }, - { 16, 15,109,200, 26, 13, 19, 15, 17,"CONCUSSION MISSILE", BT_JOY_BUTTON, 255 }, - { 17, 15,109,258, 26, 14, 20, 16, 18,"CONCUSSION MISSILE", BT_MOUSE_BUTTON, 255 }, - { 18, 15,117,142, 26, 15, 21, 17, 19,"HOMING MISSILE", BT_KEY, 255 }, - { 19, 15,117,200, 26, 16, 22, 18, 20,"HOMING MISSILE", BT_JOY_BUTTON, 255 }, - { 20, 15,117,258, 26, 17, 23, 19, 21,"HOMING MISSILE", BT_MOUSE_BUTTON, 255 }, - { 21, 15,125,142, 26, 18, 24, 20, 22,"PROXIMITY BOMB", BT_KEY, 255 }, - { 22, 15,125,200, 26, 19, 25, 21, 23,"PROXIMITY BOMB", BT_JOY_BUTTON, 255 }, - { 23, 15,125,258, 26, 20, 26, 22, 24,"PROXIMITY BOMB", BT_MOUSE_BUTTON, 255 }, - { 24, 15,133,142, 26, 21, 27, 23, 25,"SMART MISSILE", BT_KEY, 255 }, - { 25, 15,133,200, 26, 22, 28, 24, 26,"SMART MISSILE", BT_JOY_BUTTON, 255 }, - { 26, 15,133,258, 26, 23, 29, 25, 27,"SMART MISSILE", BT_MOUSE_BUTTON, 255 }, - { 27, 15,141,142, 26, 24, 1, 26, 28,"MEGA MISSILE", BT_KEY, 255 }, - { 28, 15,141,200, 26, 25, 2, 27, 29,"MEGA MISSILE", BT_JOY_BUTTON, 255 }, - { 29, 15,141,258, 26, 26, 0, 28, 0,"MEGA MISSILE", BT_MOUSE_BUTTON, 255 }, + { 0, 15, 69,142, 26, 29, 3, 29, 1,"LASER CANNON", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 1, 15, 69,200, 26, 27, 4, 0, 2,"LASER CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 2, 15, 69,258, 26, 28, 5, 1, 3,"LASER CANNON", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 3, 15, 77,142, 26, 0, 6, 2, 4,"VULCAN CANNON", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 4, 15, 77,200, 26, 1, 7, 3, 5,"VULCAN CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 5, 15, 77,258, 26, 2, 8, 4, 6,"VULCAN CANNON", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 6, 15, 85,142, 26, 3, 9, 5, 7,"SPREADFIRE CANNON", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 7, 15, 85,200, 26, 4, 10, 6, 8,"SPREADFIRE CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 8, 15, 85,258, 26, 5, 11, 7, 9,"SPREADFIRE CANNON", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 9, 15, 93,142, 26, 6, 12, 8, 10,"PLASMA CANNON", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 10, 15, 93,200, 26, 7, 13, 9, 11,"PLASMA CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 11, 15, 93,258, 26, 8, 14, 10, 12,"PLASMA CANNON", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 12, 15,101,142, 26, 9, 15, 11, 13,"FUSION CANNON", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 13, 15,101,200, 26, 10, 16, 12, 14,"FUSION CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 14, 15,101,258, 26, 11, 17, 13, 15,"FUSION CANNON", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 15, 15,109,142, 26, 12, 18, 14, 16,"CONCUSSION MISSILE", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 16, 15,109,200, 26, 13, 19, 15, 17,"CONCUSSION MISSILE", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 17, 15,109,258, 26, 14, 20, 16, 18,"CONCUSSION MISSILE", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 18, 15,117,142, 26, 15, 21, 17, 19,"HOMING MISSILE", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 19, 15,117,200, 26, 16, 22, 18, 20,"HOMING MISSILE", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 20, 15,117,258, 26, 17, 23, 19, 21,"HOMING MISSILE", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 21, 15,125,142, 26, 18, 24, 20, 22,"PROXIMITY BOMB", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 22, 15,125,200, 26, 19, 25, 21, 23,"PROXIMITY BOMB", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 23, 15,125,258, 26, 20, 26, 22, 24,"PROXIMITY BOMB", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 24, 15,133,142, 26, 21, 27, 23, 25,"SMART MISSILE", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 25, 15,133,200, 26, 22, 28, 24, 26,"SMART MISSILE", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 26, 15,133,258, 26, 23, 29, 25, 27,"SMART MISSILE", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 27, 15,141,142, 26, 24, 1, 26, 28,"MEGA MISSILE", BT_KEY, 255, NULL, 0, &Controls.select_weapon_count }, + { 28, 15,141,200, 26, 25, 2, 27, 29,"MEGA MISSILE", BT_JOY_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, + { 29, 15,141,258, 26, 26, 0, 28, 0,"MEGA MISSILE", BT_MOUSE_BUTTON, 255, NULL, 0, &Controls.select_weapon_count }, }; void kc_drawitem( kc_item *item, int is_current ); -void kc_change_key( kc_menu *menu, kc_item * item ); -void kc_change_joybutton( kc_menu *menu, kc_item * item ); +void kc_change_key( kc_menu *menu, d_event *event, kc_item * item ); +void kc_change_joybutton( kc_menu *menu, d_event *event, kc_item * item ); void kc_change_mousebutton( kc_menu *menu, d_event *event, kc_item * item ); -void kc_change_joyaxis( kc_menu *menu, kc_item * item ); -void kc_change_mouseaxis( kc_menu *menu, kc_item * item ); +void kc_change_joyaxis( kc_menu *menu, d_event *event, kc_item * item ); +void kc_change_mouseaxis( kc_menu *menu, d_event *event, kc_item * item ); void kc_change_invert( kc_menu *menu, kc_item * item ); #ifdef TABLE_CREATION @@ -561,11 +568,6 @@ void kconfig_start_changing(kc_menu *menu) gr_set_fontcolor( BM_XRGB(28,28,28), -1 ); menu->q_fade_i = 0; // start question mark flasher - - game_flush_inputs(); - if (menu->items[menu->citem].type == BT_JOY_AXIS) - joystick_read_raw_axis( menu->old_axis ); - menu->changing = 1; } @@ -614,7 +616,6 @@ int kconfig_mouse(window *wind, d_event *event, kc_menu *menu) { // Click out of changing mode - kreatordxx menu->changing = 0; - game_flush_inputs(); rval = 1; } } @@ -796,7 +797,6 @@ int kconfig_handler(window *wind, d_event *event, kc_menu *menu) { case EVENT_WINDOW_ACTIVATED: game_flush_inputs(); - event_toggle_focus(0); break; case EVENT_WINDOW_DEACTIVATED: @@ -824,38 +824,48 @@ int kconfig_handler(window *wind, d_event *event, kc_menu *menu) menu->mouse_state = (event->type == EVENT_MOUSE_BUTTON_DOWN); return kconfig_mouse(wind, event, menu); + case EVENT_MOUSE_MOVED: + if (menu->changing && menu->items[menu->citem].type == BT_MOUSE_AXIS) kc_change_mouseaxis(menu, event, &menu->items[menu->citem]); + else + event_mouse_get_delta( event, &menu->old_maxis[0], &menu->old_maxis[1], &menu->old_maxis[2]); + break; + + case EVENT_JOYSTICK_BUTTON_DOWN: + if (menu->changing && menu->items[menu->citem].type == BT_JOY_BUTTON) kc_change_joybutton(menu, event, &menu->items[menu->citem]); + break; + + case EVENT_JOYSTICK_MOVED: + if (menu->changing && menu->items[menu->citem].type == BT_JOY_AXIS) kc_change_joyaxis(menu, event, &menu->items[menu->citem]); + else + { + int axis, value; + event_joystick_get_axis( event, &axis, &value ); + menu->old_jaxis[axis] = value; + } + break; + case EVENT_KEY_COMMAND: - return kconfig_key_command(wind, event, menu); + { + int rval = kconfig_key_command(wind, event, menu); + if (rval) + return rval; + if (menu->changing && menu->items[menu->citem].type == BT_KEY) kc_change_key(menu, event, &menu->items[menu->citem]); + return 0; + } case EVENT_IDLE: kconfig_mouse(wind, event, menu); - + break; + + case EVENT_WINDOW_DRAW: if (menu->changing) timer_delay(f0_1/10); else timer_delay2(50); - - if (menu->changing) - { - switch( menu->items[menu->citem].type ) - { - case BT_KEY: kc_change_key( menu, &menu->items[menu->citem] ); break; - case BT_MOUSE_AXIS: kc_change_mouseaxis( menu, &menu->items[menu->citem] ); break; - case BT_JOY_BUTTON: kc_change_joybutton( menu, &menu->items[menu->citem] ); break; - case BT_JOY_AXIS: kc_change_joyaxis( menu, &menu->items[menu->citem] ); break; - } - - if (!menu->changing) - game_flush_inputs(); - } - break; - - case EVENT_WINDOW_DRAW: kconfig_draw(menu); break; case EVENT_WINDOW_CLOSE: - //event_toggle_focus(1); // No cursor recentering d_free(menu); // Update save values... @@ -980,133 +990,114 @@ void kc_drawquestion( kc_menu *menu, kc_item *item ) gr_string( x, FSPACY(item->y), "?" ); } -void kc_change_key( kc_menu *menu, kc_item * item ) +void kc_change_key( kc_menu *menu, d_event *event, kc_item * item ) { - int i,n,f; + int i,n; ubyte keycode = 255; - for (i=0; i<256; i++ ) { - if (keyd_pressed[i] && (strlen(key_text[i])>0)) { - f = 0; - for (n=0; n<(GameArg.CtlNoStickyKeys?sizeof(system_keys)-3:sizeof(system_keys)); n++ ) - if ( system_keys[n] == i ) - f=1; - if (!f) - keycode=i; - } - } + Assert(event->type == EVENT_KEY_COMMAND); + keycode = event_key_get_raw(event); - if (keycode != 255) { - for (i=0; initems; i++ ) { - n = item - menu->items; - if ( (i!=n) && (menu->items[i].type==BT_KEY) && (menu->items[i].value==keycode) ) { - menu->items[i].value = 255; - } + if (strlen(key_text[keycode])<=0) + return; + + for (n=0; n<(GameArg.CtlNoStickyKeys?sizeof(system_keys)-3:sizeof(system_keys)); n++ ) + if ( system_keys[n] == keycode ) + return; + + for (i=0; initems; i++ ) + { + n = item - menu->items; + if ( (i!=n) && (menu->items[i].type==BT_KEY) && (menu->items[i].value==keycode) ) + { + menu->items[i].value = 255; } - item->value = keycode; - menu->changing = 0; } + item->value = keycode; + menu->changing = 0; } -void kc_change_joybutton( kc_menu *menu, kc_item * item ) +void kc_change_joybutton( kc_menu *menu, d_event *event, kc_item * item ) { - int n,i; - ubyte code = 255; + int n,i,button = 255; - for (i = 0; i < JOY_MAX_BUTTONS; i++) + Assert(event->type == EVENT_JOYSTICK_BUTTON_DOWN); + button = event_joystick_get_button(event); + + for (i=0; initems; i++ ) { - if ( joy_get_button_state(i) ) - { - code = i; - menu->changing = 0; - } - } - if (code!=255) { - for (i=0; initems; i++ ) { - n = item - menu->items; - if ( (i!=n) && (menu->items[i].type==BT_JOY_BUTTON) && (menu->items[i].value==code) ) { - menu->items[i].value = 255; - } - } - item->value = code; - menu->changing = 0; + n = item - menu->items; + if ( (i!=n) && (menu->items[i].type==BT_JOY_BUTTON) && (menu->items[i].value==button) ) + menu->items[i].value = 255; } + item->value = button; + menu->changing = 0; } void kc_change_mousebutton( kc_menu *menu, d_event *event, kc_item * item ) { - int n,i,b; + int n,i,button; - b = event_mouse_get_button(event); + Assert(event->type == EVENT_MOUSE_BUTTON_DOWN); + button = event_mouse_get_button(event); for (i=0; initems; i++) { n = item - menu->items; - if ( (i!=n) && (menu->items[i].type==BT_MOUSE_BUTTON) && (menu->items[i].value==b) ) + if ( (i!=n) && (menu->items[i].type==BT_MOUSE_BUTTON) && (menu->items[i].value==button) ) menu->items[i].value = 255; } - - item->value = b; + item->value = button; menu->changing = 0; } -void kc_change_joyaxis( kc_menu *menu, kc_item * item ) +void kc_change_joyaxis( kc_menu *menu, d_event *event, kc_item * item ) { - int axis[JOY_MAX_AXES]; - int numaxis = joy_num_axes; - int n,i; + int i, n, axis, value; + + Assert(event->type == EVENT_JOYSTICK_MOVED); + event_joystick_get_axis( event, &axis, &value ); + + if ( abs(value-menu->old_jaxis[axis])<32 ) + return; + con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", axis); + + for (i=0; initems; i++ ) + { + n = item - menu->items; + if ( (i!=n) && (menu->items[i].type==BT_JOY_AXIS) && (menu->items[i].value==axis) ) + menu->items[i].value = 255; + } + item->value = axis; + menu->changing = 0; +} + +void kc_change_mouseaxis( kc_menu *menu, d_event *event, kc_item * item ) +{ + int i, n, dx, dy, dz; ubyte code = 255; - joystick_read_raw_axis( axis ); + Assert(event->type == EVENT_MOUSE_MOVED); + event_mouse_get_delta( event, &dx, &dy, &dz ); + if ( abs(dx)>5 ) code = 0; + if ( abs(dy)>5 ) code = 1; + if ( abs(dz)>5 ) code = 2; - for (i=0; iold_axis[i])>4096 ) + if (code!=255) + { + for (i=0; initems; i++ ) { - code = i; - con_printf(CON_DEBUG, "Axis Movement detected: Axis %i\n", i); - } - } - if (code!=255) { - for (i=0; initems; i++ ) { n = item - menu->items; - if ( (i!=n) && (menu->items[i].type==BT_JOY_AXIS) && (menu->items[i].value==code) ) { + if ( (i!=n) && (menu->items[i].type==BT_MOUSE_AXIS) && (menu->items[i].value==code) ) menu->items[i].value = 255; - } - } - - item->value = code; - menu->changing = 0; - } -} - -void kc_change_mouseaxis( kc_menu *menu, kc_item * item ) -{ - int i,n; - ubyte code = 255; - int dx,dy,dz; - - mouse_get_delta( &dx, &dy, &dz ); - if ( abs(dx)>20 ) code = 0; - if ( abs(dy)>20 ) code = 1; - if ( abs(dz)>20 ) code = 2; - - if (code!=255) { - for (i=0; initems; i++ ) { - n = item - menu->items; - if ( (i!=n) && (menu->items[i].type==BT_MOUSE_AXIS) && (menu->items[i].value==code) ) { - menu->items[i].value = 255; - } } item->value = code; menu->changing = 0; } } - void kc_change_invert( kc_menu *menu, kc_item * item ) { - game_flush_inputs(); - if (item->value) item->value = 0; else @@ -1134,194 +1125,182 @@ void kconfig(int n, char * title) } } - - -void controls_read_all(int automap_flag) +void kconfig_read_controls(d_event *event, int automap_flag) { - int i = 0, slide_on = 0, bank_on = 0, mouse_buttons = 0, use_mouse = 0, use_joystick = 0, speed_factor = 1; - fix k0, k1, k2, k3, kp, k4, k5, k6, k7, kh; + int i = 0, j = 0, speed_factor = Game_turbo_mode?2:1; + static fix64 mouse_delta_time = 0; - if (Game_turbo_mode) - speed_factor = 2; - - Controls.vertical_thrust_time=0; - Controls.sideways_thrust_time=0; - Controls.bank_time=0; - Controls.forward_thrust_time=0; - Controls.rear_view_down_count=0; - Controls.rear_view_down_state=0; - Controls.fire_primary_down_count=0; - Controls.fire_primary_state=0; - Controls.fire_secondary_state=0; - Controls.fire_secondary_down_count=0; - Controls.fire_flare_down_count=0; - Controls.drop_bomb_down_count=0; - Controls.automap_down_count=0; - Controls.automap_state=0; - Controls.cycle_primary_count=0; - Controls.cycle_secondary_count=0; +#ifndef NDEBUG + // --- Don't do anything if in debug mode --- + if ( keyd_pressed[KEY_DELETE] ) + { + memset( &Controls, 0, sizeof(control_info) ); + return; + } +#endif - //--------- Read Joystick ----------- - if ( PlayerCfg.ControlType & CONTROL_USING_JOYSTICK ) { - joystick_read_raw_axis( Controls.raw_joy_axis ); + Controls.pitch_time = Controls.vertical_thrust_time = Controls.heading_time = Controls.sideways_thrust_time = Controls.bank_time = Controls.forward_thrust_time = 0; - for (i = 0; i < joy_num_axes; i++) + switch (event->type) + { + case EVENT_KEY_COMMAND: + case EVENT_KEY_RELEASE: + for (i = 0; i < NUM_KEY_CONTROLS; i++) + { + if (kc_keyboard[i].value < 255 && kc_keyboard[i].value == event_key_get_raw(event)) + { + if (kc_keyboard[i].ci_state_ptr != NULL) + { + if (event->type==EVENT_KEY_COMMAND) + *kc_keyboard[i].ci_state_ptr |= kc_keyboard[i].state_bit; + else + *kc_keyboard[i].ci_state_ptr &= ~kc_keyboard[i].state_bit; + } + if (kc_keyboard[i].ci_count_ptr != NULL && event->type==EVENT_KEY_COMMAND) + *kc_keyboard[i].ci_count_ptr += 1; + } + } + if (!automap_flag && event->type == EVENT_KEY_COMMAND) + for (i = 0, j = 0; i < 28; i += 3, j++) + if (kc_d1x[i].value < 255 && kc_d1x[i].value == event_key_get_raw(event)) + { + Controls.select_weapon_count = j; + break; + } + break; + case EVENT_JOYSTICK_BUTTON_DOWN: + case EVENT_JOYSTICK_BUTTON_UP: + if (!(PlayerCfg.ControlType & CONTROL_USING_JOYSTICK)) + break; + for (i = 0; i < NUM_JOYSTICK_CONTROLS; i++) + { + if (kc_joystick[i].value < 255 && kc_joystick[i].type == BT_JOY_BUTTON && kc_joystick[i].value == event_joystick_get_button(event)) + { + if (kc_joystick[i].ci_state_ptr != NULL) + { + if (event->type==EVENT_JOYSTICK_BUTTON_DOWN) + *kc_joystick[i].ci_state_ptr |= kc_joystick[i].state_bit; + else + *kc_joystick[i].ci_state_ptr &= ~kc_joystick[i].state_bit; + } + if (kc_joystick[i].ci_count_ptr != NULL && event->type==EVENT_JOYSTICK_BUTTON_DOWN) + *kc_joystick[i].ci_count_ptr += 1; + } + } + if (!automap_flag && event->type == EVENT_JOYSTICK_BUTTON_DOWN) + for (i = 1, j = 0; i < 29; i += 3, j++) + if (kc_d1x[i].value < 255 && kc_d1x[i].value == event_joystick_get_button(event)) + { + Controls.select_weapon_count = j; + break; + } + break; + case EVENT_MOUSE_BUTTON_DOWN: + case EVENT_MOUSE_BUTTON_UP: + if (!(PlayerCfg.ControlType & CONTROL_USING_MOUSE)) + break; + for (i = 0; i < NUM_MOUSE_CONTROLS; i++) + { + if (kc_mouse[i].value < 255 && kc_mouse[i].type == BT_MOUSE_BUTTON && kc_mouse[i].value == event_mouse_get_button(event)) + { + if (kc_mouse[i].ci_state_ptr != NULL) + { + if (event->type==EVENT_MOUSE_BUTTON_DOWN) + *kc_mouse[i].ci_state_ptr |= kc_mouse[i].state_bit; + else + *kc_mouse[i].ci_state_ptr &= ~kc_mouse[i].state_bit; + } + if (kc_mouse[i].ci_count_ptr != NULL && event->type==EVENT_MOUSE_BUTTON_DOWN) + *kc_mouse[i].ci_count_ptr += 1; + } + } + if (!automap_flag && event->type == EVENT_MOUSE_BUTTON_DOWN) + for (i = 2, j = 0; i < 30; i += 3, j++) + if (kc_d1x[i].value < 255 && kc_d1x[i].value == event_mouse_get_button(event)) + { + Controls.select_weapon_count = j; + break; + } + break; + case EVENT_JOYSTICK_MOVED: { - int joy_null_value = 0; + int axis = 0, value = 0, joy_null_value = 0; + if (!(PlayerCfg.ControlType & CONTROL_USING_JOYSTICK)) + break; + event_joystick_get_axis(event, &axis, &value); - Controls.raw_joy_axis[i] = joy_get_scaled_reading( Controls.raw_joy_axis[i] ); + Controls.raw_joy_axis[axis] = value; - if (i == kc_joystick[13].value) // Pitch U/D Deadzone + if (axis == kc_joystick[13].value) // Pitch U/D Deadzone joy_null_value = PlayerCfg.JoystickDead[1]*8; - if (i == kc_joystick[15].value) // Turn L/R Deadzone + if (axis == kc_joystick[15].value) // Turn L/R Deadzone joy_null_value = PlayerCfg.JoystickDead[0]*8; - if (i == kc_joystick[17].value) // Slide L/R Deadzone + if (axis == kc_joystick[17].value) // Slide L/R Deadzone joy_null_value = PlayerCfg.JoystickDead[2]*8; - if (i == kc_joystick[19].value) // Slide U/D Deadzone + if (axis == kc_joystick[19].value) // Slide U/D Deadzone joy_null_value = PlayerCfg.JoystickDead[3]*8; - if (i == kc_joystick[21].value) // Bank Deadzone + if (axis == kc_joystick[21].value) // Bank Deadzone joy_null_value = PlayerCfg.JoystickDead[4]*8; - if (i == kc_joystick[23].value) // Throttle - default deadzone + if (axis == kc_joystick[23].value) // Throttle - default deadzone joy_null_value = 20; - if (Controls.raw_joy_axis[i] > joy_null_value) - Controls.raw_joy_axis[i] = ((Controls.raw_joy_axis[i]-joy_null_value)*128)/(128-joy_null_value); - else if (Controls.raw_joy_axis[i] < -joy_null_value) - Controls.raw_joy_axis[i] = ((Controls.raw_joy_axis[i]+joy_null_value)*128)/(128-joy_null_value); + if (Controls.raw_joy_axis[axis] > joy_null_value) + Controls.raw_joy_axis[axis] = ((Controls.raw_joy_axis[axis]-joy_null_value)*128)/(128-joy_null_value); + else if (Controls.raw_joy_axis[axis] < -joy_null_value) + Controls.raw_joy_axis[axis] = ((Controls.raw_joy_axis[axis]+joy_null_value)*128)/(128-joy_null_value); else - Controls.raw_joy_axis[i] = 0; - Controls.joy_axis[i] = (Controls.raw_joy_axis[i]*FrameTime)/128; + Controls.raw_joy_axis[axis] = 0; + Controls.joy_axis[axis] = (Controls.raw_joy_axis[axis]*FrameTime)/128; + break; } - use_joystick=1; - } else { - for (i = 0; i < joy_num_axes; i++) - Controls.joy_axis[i] = 0; - use_joystick=0; - } - - if ( PlayerCfg.ControlType & CONTROL_USING_MOUSE) { - //--------- Read Mouse ----------- - if (PlayerCfg.MouseFlightSim) + case EVENT_MOUSE_MOVED: { - int ax[3]; - mouse_get_delta( &ax[0], &ax[1], &ax[2] ); - for (i = 0; i <= 2; i++) + if (!(PlayerCfg.ControlType & CONTROL_USING_MOUSE)) + break; + if (PlayerCfg.MouseFlightSim) { - int mouse_null_value = (i==2?16:PlayerCfg.MouseFSDead*8); - Controls.raw_mouse_axis[i] += ax[i]; - if (Controls.raw_mouse_axis[i] < -MOUSEFS_DELTA_RANGE) - Controls.raw_mouse_axis[i] = -MOUSEFS_DELTA_RANGE; - if (Controls.raw_mouse_axis[i] > MOUSEFS_DELTA_RANGE) - Controls.raw_mouse_axis[i] = MOUSEFS_DELTA_RANGE; - if (Controls.raw_mouse_axis[i] > mouse_null_value) - Controls.mouse_axis[i] = (((Controls.raw_mouse_axis[i]-mouse_null_value)*MOUSEFS_DELTA_RANGE)/(MOUSEFS_DELTA_RANGE-mouse_null_value)*FrameTime)/MOUSEFS_DELTA_RANGE; - else if (Controls.raw_mouse_axis[i] < -mouse_null_value) - Controls.mouse_axis[i] = (((Controls.raw_mouse_axis[i]+mouse_null_value)*MOUSEFS_DELTA_RANGE)/(MOUSEFS_DELTA_RANGE-mouse_null_value)*FrameTime)/MOUSEFS_DELTA_RANGE; - else - Controls.mouse_axis[i] = 0; + int ax[3]; + event_mouse_get_delta( event, &ax[0], &ax[1], &ax[2] ); + for (i = 0; i <= 2; i++) + { + int mouse_null_value = (i==2?16:PlayerCfg.MouseFSDead*8); + Controls.raw_mouse_axis[i] += ax[i]; + if (Controls.raw_mouse_axis[i] < -MOUSEFS_DELTA_RANGE) + Controls.raw_mouse_axis[i] = -MOUSEFS_DELTA_RANGE; + if (Controls.raw_mouse_axis[i] > MOUSEFS_DELTA_RANGE) + Controls.raw_mouse_axis[i] = MOUSEFS_DELTA_RANGE; + if (Controls.raw_mouse_axis[i] > mouse_null_value) + Controls.mouse_axis[i] = (((Controls.raw_mouse_axis[i]-mouse_null_value)*MOUSEFS_DELTA_RANGE)/(MOUSEFS_DELTA_RANGE-mouse_null_value)*FrameTime)/MOUSEFS_DELTA_RANGE; + else if (Controls.raw_mouse_axis[i] < -mouse_null_value) + Controls.mouse_axis[i] = (((Controls.raw_mouse_axis[i]+mouse_null_value)*MOUSEFS_DELTA_RANGE)/(MOUSEFS_DELTA_RANGE-mouse_null_value)*FrameTime)/MOUSEFS_DELTA_RANGE; + else + Controls.mouse_axis[i] = 0; + } } + else if (mouse_delta_time < timer_query()) + { + event_mouse_get_delta( event, &Controls.raw_mouse_axis[0], &Controls.raw_mouse_axis[1], &Controls.raw_mouse_axis[2] ); + Controls.mouse_axis[0] = (Controls.raw_mouse_axis[0]*FrameTime)/15; + Controls.mouse_axis[1] = (Controls.raw_mouse_axis[1]*FrameTime)/15; + Controls.mouse_axis[2] = (Controls.raw_mouse_axis[2]*FrameTime); + mouse_delta_time = timer_query() + (F1_0/30); + } + break; } - else if (FixedStep & EPS30) // as the mouse won't get delta in each frame (at high FPS) and we have a capped movement, read time-based - { - mouse_get_delta( &Controls.raw_mouse_axis[0], &Controls.raw_mouse_axis[1], &Controls.raw_mouse_axis[2] ); - Controls.mouse_axis[0] = (Controls.raw_mouse_axis[0]*FrameTime)/25; - Controls.mouse_axis[1] = (Controls.raw_mouse_axis[1]*FrameTime)/25; - Controls.mouse_axis[2] = (Controls.raw_mouse_axis[2]*FrameTime); - } - mouse_buttons = mouse_get_btns(); - use_mouse=1; - } else { - Controls.mouse_axis[0] = 0; - Controls.mouse_axis[1] = 0; - Controls.mouse_axis[2] = 0; - mouse_buttons = 0; - use_mouse=0; + case EVENT_IDLE: + default: + if (!PlayerCfg.MouseFlightSim && mouse_delta_time < timer_query()) + Controls.mouse_axis[0] = Controls.mouse_axis[1] = Controls.mouse_axis[2] = 0; + break; } - - //--------- Read primary weapon select ------------- - if (!Player_is_dead && !automap_flag) + //------------ Read pitch_time ----------- + if ( !Controls.slide_on_state ) { - //----------------Weapon 1---------------- - if ( (key_down_count(kc_d1x[0].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[1].value)) || (use_mouse && mouse_button_down_count(kc_d1x[2].value)) ) - do_weapon_select(0,0); - //----------------Weapon 2---------------- - if ( (key_down_count(kc_d1x[3].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[4].value)) || (use_mouse && mouse_button_down_count(kc_d1x[5].value)) ) - do_weapon_select(1,0); - //----------------Weapon 3---------------- - if ( (key_down_count(kc_d1x[6].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[7].value)) || (use_mouse && mouse_button_down_count(kc_d1x[8].value)) ) - do_weapon_select(2,0); - //----------------Weapon 4---------------- - if ( (key_down_count(kc_d1x[9].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[10].value)) || (use_mouse && mouse_button_down_count(kc_d1x[11].value)) ) - do_weapon_select(3,0); - //----------------Weapon 5---------------- - if ( (key_down_count(kc_d1x[12].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[13].value)) || (use_mouse && mouse_button_down_count(kc_d1x[14].value)) ) - do_weapon_select(4,0); - - //--------- Read secondary weapon select ---------- - //----------------Weapon 6---------------- - if ( (key_down_count(kc_d1x[15].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[16].value)) || (use_mouse && mouse_button_down_count(kc_d1x[17].value)) ) - do_weapon_select(0,1); - //----------------Weapon 7---------------- - if ( (key_down_count(kc_d1x[18].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[19].value)) || (use_mouse && mouse_button_down_count(kc_d1x[20].value)) ) - do_weapon_select(1,1); - //----------------Weapon 8---------------- - if ( (key_down_count(kc_d1x[21].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[22].value)) || (use_mouse && mouse_button_down_count(kc_d1x[23].value)) ) - do_weapon_select(2,1); - //----------------Weapon 9---------------- - if ( (key_down_count(kc_d1x[24].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[25].value)) || (use_mouse && mouse_button_down_count(kc_d1x[26].value)) ) - do_weapon_select(3,1); - //----------------Weapon 0---------------- - if ( (key_down_count(kc_d1x[27].value) && !((keyd_pressed[KEY_LSHIFT] || keyd_pressed[KEY_RSHIFT]))) || - (use_joystick && joy_get_button_down_cnt(kc_d1x[28].value)) || (use_mouse && mouse_button_down_count(kc_d1x[29].value)) ) - do_weapon_select(4,1); - }//end "if (!Player_is_dead)" - WraithX - -//------------- Read slide_on ------------- - - // From keyboard... - if ( kc_keyboard[8].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[8].value ]; - if ( kc_keyboard[9].value < 255 ) slide_on |= keyd_pressed[ kc_keyboard[9].value ]; - // From joystick... - if ((use_joystick)&&(kc_joystick[5].value<255)) slide_on |= joy_get_button_state( kc_joystick[5].value ); - if ((use_joystick)&&(kc_joystick[34].value<255)) slide_on |= joy_get_button_state( kc_joystick[34].value ); - // From mouse... - if ((use_mouse)&&(kc_mouse[5].value<255)) slide_on |= mouse_buttons & (1< 0) { @@ -1331,136 +1310,57 @@ void controls_read_all(int automap_flag) if (Controls.pitch_time > 0) Controls.pitch_time = 0; Controls.pitch_time += kp; - // From joystick... - if ( (use_joystick)&&(kc_joystick[13].value < 255 )) { - if ( !kc_joystick[14].value ) // If not inverted... - Controls.pitch_time -= (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[1])/8; - else - Controls.pitch_time += (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[1])/8; - } - + if ( !kc_joystick[14].value ) // If not inverted... + Controls.pitch_time -= (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[1])/8; + else + Controls.pitch_time += (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[1])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[13].value < 255) ) { - if ( !kc_mouse[14].value ) // If not inverted... - Controls.pitch_time -= (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[1])/8; - else - Controls.pitch_time += (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[1])/8; - } - } else { - Controls.pitch_time = 0; + if ( !kc_mouse[14].value ) // If not inverted... + Controls.pitch_time -= (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[1])/8; + else + Controls.pitch_time += (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[1])/8; } + else Controls.pitch_time = 0; - - // done so that dead players can't move - if (!Player_is_dead) - { //----------- Read vertical_thrust_time ----------------- - - if ( slide_on ) { - k0 = speed_factor*key_down_time( kc_keyboard[0].value ); - k1 = speed_factor*key_down_time( kc_keyboard[1].value ); - k2 = speed_factor*key_down_time( kc_keyboard[2].value ); - k3 = speed_factor*key_down_time( kc_keyboard[3].value ); - - // From keyboard... - if ( kc_keyboard[0].value < 255 ) Controls.vertical_thrust_time += k0; - if ( kc_keyboard[1].value < 255 ) Controls.vertical_thrust_time += k1; - if ( kc_keyboard[2].value < 255 ) Controls.vertical_thrust_time -= k2; - if ( kc_keyboard[3].value < 255 ) Controls.vertical_thrust_time -= k3; - - // From joystick... - if ((use_joystick)&&( kc_joystick[13].value < 255 )) { - if ( !kc_joystick[14].value ) // If not inverted... - Controls.vertical_thrust_time += (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[3])/8; - else - Controls.vertical_thrust_time -= (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[3])/8; - } - - // From mouse... - if ( (use_mouse)&&(kc_mouse[13].value < 255 )) { - if ( !kc_mouse[14].value ) // If not inverted... - Controls.vertical_thrust_time -= (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[3])/8; - else - Controls.vertical_thrust_time += (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[3])/8; - } - } - - // From keyboard... - if ( kc_keyboard[14].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[14].value ); - if ( kc_keyboard[15].value < 255 ) Controls.vertical_thrust_time += speed_factor*key_down_time( kc_keyboard[15].value ); - if ( kc_keyboard[16].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[16].value ); - if ( kc_keyboard[17].value < 255 ) Controls.vertical_thrust_time -= speed_factor*key_down_time( kc_keyboard[17].value ); - + if ( Controls.slide_on_state ) + { + // From keyboard/buttons... + if ( Controls.pitch_forward_state ) Controls.vertical_thrust_time += speed_factor*FrameTime; + if ( Controls.pitch_backward_state ) Controls.vertical_thrust_time -= speed_factor*FrameTime; // From joystick... - if ((use_joystick)&&( kc_joystick[19].value < 255 )) { - if ( !kc_joystick[20].value ) // If not inverted... - Controls.vertical_thrust_time -= (Controls.joy_axis[kc_joystick[19].value]*PlayerCfg.JoystickSens[3])/8; - else - Controls.vertical_thrust_time += (Controls.joy_axis[kc_joystick[19].value]*PlayerCfg.JoystickSens[3])/8; - } - - // From joystick buttons - if ( (use_joystick)&&(kc_joystick[8].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_joystick[8].value ); - if ( (use_joystick)&&(kc_joystick[37].value < 255 )) Controls.vertical_thrust_time += joy_get_button_down_time( kc_joystick[37].value ); - if ( (use_joystick)&&(kc_joystick[9].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_joystick[9].value ); - if ( (use_joystick)&&(kc_joystick[38].value < 255 )) Controls.vertical_thrust_time -= joy_get_button_down_time( kc_joystick[38].value ); - - // From mouse buttons - if ( (use_mouse)&&(kc_mouse[8].value < 255 )) Controls.vertical_thrust_time += mouse_button_down_time( kc_mouse[8].value ); - if ( (use_mouse)&&(kc_mouse[9].value < 255 )) Controls.vertical_thrust_time -= mouse_button_down_time( kc_mouse[9].value ); - + if ( !kc_joystick[14].value ) // If not inverted... + Controls.vertical_thrust_time += (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[3])/8; + else + Controls.vertical_thrust_time -= (Controls.joy_axis[kc_joystick[13].value]*PlayerCfg.JoystickSens[3])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[19].value < 255 )) { - if ( !kc_mouse[20].value ) // If not inverted... - Controls.vertical_thrust_time += (Controls.mouse_axis[kc_mouse[19].value]*PlayerCfg.MouseSens[3])/8; - else - Controls.vertical_thrust_time -= (Controls.mouse_axis[kc_mouse[19].value]*PlayerCfg.MouseSens[3])/8; - } - - //--------Read Cycle Primary Key------------------ - - if (kc_keyboard[46].value<255) - Controls.cycle_primary_count=key_down_count(kc_keyboard[46].value); - if (kc_keyboard[47].value<255) - Controls.cycle_primary_count+=key_down_count(kc_keyboard[47].value); - if ((use_joystick)&&(kc_joystick[44].value < 255 )) - Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_joystick[44].value); - if ((use_joystick)&&(kc_joystick[46].value < 255 )) - Controls.cycle_primary_count+=joy_get_button_down_cnt(kc_joystick[46].value); - if ((use_mouse)&&(kc_mouse[27].value < 255 )) - Controls.cycle_primary_count += mouse_button_down_count(kc_mouse[27].value); - - - //--------Read Cycle Secondary Key------------------ - - if (kc_keyboard[48].value<255) - Controls.cycle_secondary_count=key_down_count(kc_keyboard[48].value); - if (kc_keyboard[49].value<255) - Controls.cycle_secondary_count+=key_down_count(kc_keyboard[49].value); - if ((use_joystick)&&(kc_joystick[45].value < 255 )) - Controls.cycle_secondary_count+=joy_get_button_down_cnt(kc_joystick[45].value); - if ((use_joystick)&&(kc_joystick[47].value < 255 )) - Controls.cycle_secondary_count+=joy_get_button_down_cnt(kc_joystick[47].value); - if ((use_mouse)&&(kc_mouse[28].value < 255 )) - Controls.cycle_secondary_count += mouse_button_down_count(kc_mouse[28].value); + if ( !kc_mouse[14].value ) // If not inverted... + Controls.vertical_thrust_time -= (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[3])/8; + else + Controls.vertical_thrust_time += (Controls.mouse_axis[kc_mouse[13].value]*PlayerCfg.MouseSens[3])/8; } + // From keyboard/buttons... + if ( Controls.slide_up_state ) Controls.vertical_thrust_time += speed_factor*FrameTime/2; + if ( Controls.slide_down_state ) Controls.vertical_thrust_time -= speed_factor*FrameTime/2; + // From joystick... + if ( !kc_joystick[20].value ) // If not inverted... + Controls.vertical_thrust_time += (Controls.joy_axis[kc_joystick[19].value]*PlayerCfg.JoystickSens[3])/8; + else + Controls.vertical_thrust_time -= (Controls.joy_axis[kc_joystick[19].value]*PlayerCfg.JoystickSens[3])/8; + // From mouse... + if ( !kc_mouse[20].value ) // If not inverted... + Controls.vertical_thrust_time += (Controls.mouse_axis[kc_mouse[19].value]*PlayerCfg.MouseSens[3])/8; + else + Controls.vertical_thrust_time -= (Controls.mouse_axis[kc_mouse[19].value]*PlayerCfg.MouseSens[3])/8; -//---------- Read heading_time ----------- - - if (!slide_on && !bank_on) { - kh = 0; - k4 = speed_factor*key_down_time( kc_keyboard[4].value ); - k5 = speed_factor*key_down_time( kc_keyboard[5].value ); - k6 = speed_factor*key_down_time( kc_keyboard[6].value ); - k7 = speed_factor*key_down_time( kc_keyboard[7].value ); - - // From keyboard... - if ( kc_keyboard[4].value < 255 ) kh -= k4; - if ( kc_keyboard[5].value < 255 ) kh -= k5; - if ( kc_keyboard[6].value < 255 ) kh += k6; - if ( kc_keyboard[7].value < 255 ) kh += k7; - + //---------- Read heading_time ----------- + if (!Controls.slide_on_state && !Controls.bank_on_state) + { + int kh = 0; + // From keyboard/buttons... + if ( Controls.heading_right_state ) kh += speed_factor*FrameTime; + if ( Controls.heading_left_state ) kh -= speed_factor*FrameTime; if (kh == 0) Controls.heading_time = 0; else if (kh > 0) { @@ -1470,306 +1370,118 @@ void controls_read_all(int automap_flag) if (Controls.heading_time > 0) Controls.heading_time = 0; Controls.heading_time += kh; - // From joystick... - if ( (use_joystick)&&(kc_joystick[15].value < 255 )) { - if ( !kc_joystick[16].value ) // If not inverted... - Controls.heading_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[0])/8; - else - Controls.heading_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[0])/8; - } - + if ( !kc_joystick[16].value ) // If not inverted... + Controls.heading_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[0])/8; + else + Controls.heading_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[0])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[15].value < 255 )) { - if ( !kc_mouse[16].value ) // If not inverted... - Controls.heading_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[0])/8; - else - Controls.heading_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[0])/8; - } - } else { - Controls.heading_time = 0; + if ( !kc_mouse[16].value ) // If not inverted... + Controls.heading_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[0])/8; + else + Controls.heading_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[0])/8; } + else Controls.heading_time = 0; - // done so that dead players can't move - if (!Player_is_dead) - { //----------- Read sideways_thrust_time ----------------- - - if ( slide_on ) { - k0 = speed_factor*key_down_time( kc_keyboard[4].value ); - k1 = speed_factor*key_down_time( kc_keyboard[5].value ); - k2 = speed_factor*key_down_time( kc_keyboard[6].value ); - k3 = speed_factor*key_down_time( kc_keyboard[7].value ); - - // From keyboard... - if ( kc_keyboard[4].value < 255 ) Controls.sideways_thrust_time -= k0; - if ( kc_keyboard[5].value < 255 ) Controls.sideways_thrust_time -= k1; - if ( kc_keyboard[6].value < 255 ) Controls.sideways_thrust_time += k2; - if ( kc_keyboard[7].value < 255 ) Controls.sideways_thrust_time += k3; - - // From joystick... - if ( (use_joystick)&&(kc_joystick[15].value < 255 )) { - if ( !kc_joystick[16].value ) // If not inverted... - Controls.sideways_thrust_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[2])/8; - else - Controls.sideways_thrust_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[2])/8; - } - - // From mouse... - if ( (use_mouse)&&(kc_mouse[15].value < 255 )) { - if ( !kc_mouse[16].value ) // If not inverted... - Controls.sideways_thrust_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[2])/8; - else - Controls.sideways_thrust_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[2])/8; - } - } - - // From keyboard... - if ( kc_keyboard[10].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[10].value ); - if ( kc_keyboard[11].value < 255 ) Controls.sideways_thrust_time -= speed_factor*key_down_time( kc_keyboard[11].value ); - if ( kc_keyboard[12].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[12].value ); - if ( kc_keyboard[13].value < 255 ) Controls.sideways_thrust_time += speed_factor*key_down_time( kc_keyboard[13].value ); - + if ( Controls.slide_on_state ) + { + // From keyboard/buttons... + if ( Controls.heading_right_state ) Controls.sideways_thrust_time += speed_factor*FrameTime; + if ( Controls.heading_left_state ) Controls.sideways_thrust_time -= speed_factor*FrameTime; // From joystick... - if ( (use_joystick)&&(kc_joystick[17].value < 255 )) { - if ( !kc_joystick[18].value ) // If not inverted... - Controls.sideways_thrust_time += (Controls.joy_axis[kc_joystick[17].value]*PlayerCfg.JoystickSens[2])/8; - else - Controls.sideways_thrust_time -= (Controls.joy_axis[kc_joystick[17].value]*PlayerCfg.JoystickSens[2])/8; - } - - // From joystick buttons - if ( (use_joystick)&&(kc_joystick[6].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_joystick[6].value ); - if ( (use_joystick)&&(kc_joystick[35].value < 255 )) Controls.sideways_thrust_time -= joy_get_button_down_time( kc_joystick[35].value ); - if ( (use_joystick)&&(kc_joystick[7].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_joystick[7].value ); - if ( (use_joystick)&&(kc_joystick[36].value < 255 )) Controls.sideways_thrust_time += joy_get_button_down_time( kc_joystick[36].value ); - - // From mouse buttons - if ( (use_mouse)&&(kc_mouse[6].value < 255 )) Controls.sideways_thrust_time -= mouse_button_down_time( kc_mouse[6].value ); - if ( (use_mouse)&&(kc_mouse[7].value < 255 )) Controls.sideways_thrust_time += mouse_button_down_time( kc_mouse[7].value ); - + if ( !kc_joystick[16].value ) // If not inverted... + Controls.sideways_thrust_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[2])/8; + else + Controls.sideways_thrust_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[2])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[17].value < 255 )) { - if ( !kc_mouse[18].value ) // If not inverted... - Controls.sideways_thrust_time += (Controls.mouse_axis[kc_mouse[17].value]*PlayerCfg.MouseSens[2])/8; - else - Controls.sideways_thrust_time -= (Controls.mouse_axis[kc_mouse[17].value]*PlayerCfg.MouseSens[2])/8; - } + if ( !kc_mouse[16].value ) // If not inverted... + Controls.sideways_thrust_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[2])/8; + else + Controls.sideways_thrust_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[2])/8; } - -//----------- Read bank_time ----------------- - - if ( bank_on ) { - k0 = speed_factor*key_down_time( kc_keyboard[4].value ); - k1 = speed_factor*key_down_time( kc_keyboard[5].value ); - k2 = speed_factor*key_down_time( kc_keyboard[6].value ); - k3 = speed_factor*key_down_time( kc_keyboard[7].value ); - - // From keyboard... - if ( kc_keyboard[4].value < 255 ) Controls.bank_time += k0; - if ( kc_keyboard[5].value < 255 ) Controls.bank_time += k1; - if ( kc_keyboard[6].value < 255 ) Controls.bank_time -= k2; - if ( kc_keyboard[7].value < 255 ) Controls.bank_time -= k3; - - // From joystick... - if ( (use_joystick)&&(kc_joystick[15].value < 255) ) { - if ( !kc_joystick[16].value ) // If not inverted... - Controls.bank_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[4])/8; - else - Controls.bank_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[4])/8; - } - - // From mouse... - if ( (use_mouse)&&(kc_mouse[15].value < 255 )) { - if ( !kc_mouse[16].value ) // If not inverted... - Controls.bank_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[4])/8; - else - Controls.bank_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[4])/8; - } - } - - // From keyboard... - if ( kc_keyboard[20].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[20].value ); - if ( kc_keyboard[21].value < 255 ) Controls.bank_time += speed_factor*key_down_time( kc_keyboard[21].value ); - if ( kc_keyboard[22].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[22].value ); - if ( kc_keyboard[23].value < 255 ) Controls.bank_time -= speed_factor*key_down_time( kc_keyboard[23].value ); - + // From keyboard/buttons... + if ( Controls.slide_left_state ) Controls.sideways_thrust_time -= speed_factor*FrameTime; + if ( Controls.slide_right_state ) Controls.sideways_thrust_time += speed_factor*FrameTime; // From joystick... - if ( (use_joystick)&&(kc_joystick[21].value < 255) ) { - if ( !kc_joystick[22].value ) // If not inverted... - Controls.bank_time -= Controls.joy_axis[kc_joystick[21].value]; - else - Controls.bank_time += Controls.joy_axis[kc_joystick[21].value]; - } - - // From joystick buttons - if ( (use_joystick)&&(kc_joystick[11].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_joystick[11].value ); - if ( (use_joystick)&&(kc_joystick[40].value < 255 )) Controls.bank_time += joy_get_button_down_time( kc_joystick[40].value ); - if ( (use_joystick)&&(kc_joystick[12].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_joystick[12].value ); - if ( (use_joystick)&&(kc_joystick[41].value < 255 )) Controls.bank_time -= joy_get_button_down_time( kc_joystick[41].value ); - - // From mouse buttons - if ( (use_mouse)&&(kc_mouse[11].value < 255 )) Controls.bank_time += mouse_button_down_time( kc_mouse[11].value ); - if ( (use_mouse)&&(kc_mouse[12].value < 255 )) Controls.bank_time -= mouse_button_down_time( kc_mouse[12].value ); - + if ( !kc_joystick[18].value ) // If not inverted... + Controls.sideways_thrust_time += (Controls.joy_axis[kc_joystick[17].value]*PlayerCfg.JoystickSens[2])/8; + else + Controls.sideways_thrust_time -= (Controls.joy_axis[kc_joystick[17].value]*PlayerCfg.JoystickSens[2])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[21].value < 255 )) { - if ( !kc_mouse[22].value ) // If not inverted... - Controls.bank_time += Controls.mouse_axis[kc_mouse[21].value]; - else - Controls.bank_time -= Controls.mouse_axis[kc_mouse[21].value]; - } + if ( !kc_mouse[18].value ) // If not inverted... + Controls.sideways_thrust_time += (Controls.mouse_axis[kc_mouse[17].value]*PlayerCfg.MouseSens[2])/8; + else + Controls.sideways_thrust_time -= (Controls.mouse_axis[kc_mouse[17].value]*PlayerCfg.MouseSens[2])/8; - // done so that dead players can't move - if (!Player_is_dead) + //----------- Read bank_time ----------------- + if ( Controls.bank_on_state ) { - //----------- Read forward_thrust_time ------------- - - // From keyboard... - if ( kc_keyboard[30].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[30].value ); - if ( kc_keyboard[31].value < 255 ) Controls.forward_thrust_time += speed_factor*key_down_time( kc_keyboard[31].value ); - if ( kc_keyboard[32].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[32].value ); - if ( kc_keyboard[33].value < 255 ) Controls.forward_thrust_time -= speed_factor*key_down_time( kc_keyboard[33].value ); - + // From keyboard/buttons... + if ( Controls.heading_left_state ) Controls.bank_time += speed_factor*FrameTime; + if ( Controls.heading_right_state ) Controls.bank_time -= speed_factor*FrameTime; // From joystick... - if ( (use_joystick)&&(kc_joystick[23].value < 255 )) { - if ( !kc_joystick[24].value ) // If not inverted... - Controls.forward_thrust_time -= Controls.joy_axis[kc_joystick[23].value]; - else - Controls.forward_thrust_time += Controls.joy_axis[kc_joystick[23].value]; - } - - // From joystick buttons - if ( (use_joystick)&&(kc_joystick[2].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_joystick[2].value ); - if ( (use_joystick)&&(kc_joystick[31].value < 255 )) Controls.forward_thrust_time += joy_get_button_down_time( kc_joystick[31].value ); - if ( (use_joystick)&&(kc_joystick[3].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_joystick[3].value ); - if ( (use_joystick)&&(kc_joystick[32].value < 255 )) Controls.forward_thrust_time -= joy_get_button_down_time( kc_joystick[32].value ); - + if ( !kc_joystick[16].value ) // If not inverted... + Controls.bank_time -= (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[4])/8; + else + Controls.bank_time += (Controls.joy_axis[kc_joystick[15].value]*PlayerCfg.JoystickSens[4])/8; // From mouse... - if ( (use_mouse)&&(kc_mouse[23].value < 255 )) { - if ( !kc_mouse[24].value ) // If not inverted... - Controls.forward_thrust_time -= Controls.mouse_axis[kc_mouse[23].value]; - else - Controls.forward_thrust_time += Controls.mouse_axis[kc_mouse[23].value]; - } - - // From mouse buttons - if ( (use_mouse)&&(kc_mouse[2].value < 255 )) Controls.forward_thrust_time += mouse_button_down_time( kc_mouse[2].value ); - if ( (use_mouse)&&(kc_mouse[3].value < 255 )) Controls.forward_thrust_time -= mouse_button_down_time( kc_mouse[3].value ); - - //----------- Read fire_primary_down_count - if (kc_keyboard[24].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[24].value); - if (kc_keyboard[25].value < 255 ) Controls.fire_primary_down_count += key_down_count(kc_keyboard[25].value); - if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_joystick[0].value); - if ((use_joystick)&&(kc_joystick[29].value < 255 )) Controls.fire_primary_down_count += joy_get_button_down_cnt(kc_joystick[29].value); - - if ((use_mouse)&&(kc_mouse[0].value < 255 )) Controls.fire_primary_down_count += mouse_button_down_count(kc_mouse[0].value); - - //----------- Read fire_primary_state - if (kc_keyboard[24].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[24].value]; - if (kc_keyboard[25].value < 255 ) Controls.fire_primary_state |= keyd_pressed[kc_keyboard[25].value]; - if ((use_joystick)&&(kc_joystick[0].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_joystick[0].value); - if ((use_joystick)&&(kc_joystick[29].value < 255 )) Controls.fire_primary_state |= joy_get_button_state(kc_joystick[29].value); - - if ((use_mouse)&&(kc_mouse[0].value < 255) ) Controls.fire_primary_state |= mouse_button_state(kc_mouse[0].value); - - //----------- Read fire_secondary_down_count - if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[26].value); - if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_down_count += key_down_count(kc_keyboard[27].value); - if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_joystick[1].value); - if ((use_joystick)&&(kc_joystick[30].value < 255 )) Controls.fire_secondary_down_count += joy_get_button_down_cnt(kc_joystick[30].value); - if ((use_mouse)&&(kc_mouse[1].value < 255 )) Controls.fire_secondary_down_count += mouse_button_down_count(kc_mouse[1].value); - - //----------- Read fire_secondary_state - if (kc_keyboard[26].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[26].value]; - if (kc_keyboard[27].value < 255 ) Controls.fire_secondary_state |= keyd_pressed[kc_keyboard[27].value]; - if ((use_joystick)&&(kc_joystick[1].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_joystick[1].value); - if ((use_joystick)&&(kc_joystick[30].value < 255 )) Controls.fire_secondary_state |= joy_get_button_state(kc_joystick[30].value); - if ((use_mouse)&&(kc_mouse[1].value < 255) ) Controls.fire_secondary_state |= mouse_button_state(kc_mouse[1].value); - - //----------- Read fire_flare_down_count - if (kc_keyboard[28].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[28].value); - if (kc_keyboard[29].value < 255 ) Controls.fire_flare_down_count += key_down_count(kc_keyboard[29].value); - if ((use_joystick)&&(kc_joystick[4].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_joystick[4].value); - if ((use_joystick)&&(kc_joystick[33].value < 255 )) Controls.fire_flare_down_count += joy_get_button_down_cnt(kc_joystick[33].value); - if ((use_mouse)&&(kc_mouse[4].value < 255 )) Controls.fire_flare_down_count += mouse_button_down_count(kc_mouse[4].value); - - //----------- Read drop_bomb_down_count - if (kc_keyboard[34].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[34].value); - if (kc_keyboard[35].value < 255 ) Controls.drop_bomb_down_count += key_down_count(kc_keyboard[35].value); - if ((use_joystick)&&(kc_joystick[26].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_joystick[26].value); - if ((use_joystick)&&(kc_joystick[43].value < 255 )) Controls.drop_bomb_down_count += joy_get_button_down_cnt(kc_joystick[43].value); - if ((use_mouse)&&(kc_mouse[26].value < 255 )) Controls.drop_bomb_down_count += mouse_button_down_count(kc_mouse[26].value); - - //----------- Read rear_view_down_count - if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[36].value); - if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_count += key_down_count(kc_keyboard[37].value); - if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_joystick[25].value); - if ((use_joystick)&&(kc_joystick[42].value < 255 )) Controls.rear_view_down_count += joy_get_button_down_cnt(kc_joystick[42].value); - - if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_count += mouse_button_down_count(kc_mouse[25].value); - - //----------- Read rear_view_down_state - if (kc_keyboard[36].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[36].value]; - if (kc_keyboard[37].value < 255 ) Controls.rear_view_down_state |= keyd_pressed[kc_keyboard[37].value]; - if ((use_joystick)&&(kc_joystick[25].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_joystick[25].value); - if ((use_joystick)&&(kc_joystick[42].value < 255 )) Controls.rear_view_down_state |= joy_get_button_state(kc_joystick[42].value); - if ((use_mouse)&&(kc_mouse[25].value < 255 )) Controls.rear_view_down_state |= mouse_button_state(kc_mouse[25].value); - - }//end "if" added by WraithX - -//----------- Read automap_down_count - if (kc_keyboard[44].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[44].value); - if (kc_keyboard[45].value < 255 ) Controls.automap_down_count += key_down_count(kc_keyboard[45].value); - if ((use_joystick)&&(kc_joystick[27].value < 255 )) Controls.automap_down_count += joy_get_button_down_cnt(kc_joystick[27].value); - if ((use_joystick)&&(kc_joystick[28].value < 255 )) Controls.automap_down_count += joy_get_button_down_cnt(kc_joystick[28].value); - -//----------- Read automap_state - if (kc_keyboard[44].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[44].value]; - if (kc_keyboard[45].value < 255 ) Controls.automap_state |= keyd_pressed[kc_keyboard[45].value]; - - -//----------- Read stupid-cruise-control-type of throttle. - { - if ( kc_keyboard[38].value < 255 ) Cruise_speed += speed_factor*key_down_time( kc_keyboard[38].value )*80; - if ( kc_keyboard[39].value < 255 ) Cruise_speed += speed_factor*key_down_time( kc_keyboard[39].value )*80; - if ( kc_keyboard[40].value < 255 ) Cruise_speed -= speed_factor*key_down_time( kc_keyboard[40].value )*80; - if ( kc_keyboard[41].value < 255 ) Cruise_speed -= speed_factor*key_down_time( kc_keyboard[41].value )*80; - if ( (kc_keyboard[42].value < 255) && (key_down_count(kc_keyboard[42].value)) ) - Cruise_speed = 0; - if ( (kc_keyboard[43].value < 255) && (key_down_count(kc_keyboard[43].value)) ) - Cruise_speed = 0; - - if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100); - if (Cruise_speed < 0 ) Cruise_speed = 0; - - if (Controls.forward_thrust_time==0) - Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100; + if ( !kc_mouse[16].value ) // If not inverted... + Controls.bank_time += (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[4])/8; + else + Controls.bank_time -= (Controls.mouse_axis[kc_mouse[15].value]*PlayerCfg.MouseSens[4])/8; } -//----------- Clamp values between -FrameTime and FrameTime + // From keyboard/buttons... + if ( Controls.bank_left_state ) Controls.bank_time += speed_factor*FrameTime; + if ( Controls.bank_right_state ) Controls.bank_time -= speed_factor*FrameTime; + // From joystick... + if ( !kc_joystick[22].value ) // If not inverted... + Controls.bank_time -= Controls.joy_axis[kc_joystick[21].value]; + else + Controls.bank_time += Controls.joy_axis[kc_joystick[21].value]; + // From mouse... + if ( !kc_mouse[22].value ) // If not inverted... + Controls.bank_time += Controls.mouse_axis[kc_mouse[21].value]; + else + Controls.bank_time -= Controls.mouse_axis[kc_mouse[21].value]; + + //----------- Read forward_thrust_time ------------- + // From keyboard/buttons... + if ( Controls.accelerate_state ) Controls.forward_thrust_time += speed_factor*FrameTime; + if ( Controls.reverse_state ) Controls.forward_thrust_time -= speed_factor*FrameTime; + // From joystick... + if ( !kc_joystick[24].value ) // If not inverted... + Controls.forward_thrust_time -= Controls.joy_axis[kc_joystick[23].value]; + else + Controls.forward_thrust_time += Controls.joy_axis[kc_joystick[23].value]; + // From mouse... + if ( !kc_mouse[24].value ) // If not inverted... + Controls.forward_thrust_time -= Controls.mouse_axis[kc_mouse[23].value]; + else + Controls.forward_thrust_time += Controls.mouse_axis[kc_mouse[23].value]; + + //----------- Read cruise-control-type of throttle. + if ( Controls.cruise_plus_state ) Cruise_speed += speed_factor*FrameTime*80; + if ( Controls.cruise_minus_state ) Cruise_speed -= speed_factor*FrameTime*80; + if ( Controls.cruise_off_count > 0 ) Controls.cruise_off_count = Cruise_speed = 0; + if (Cruise_speed > i2f(100) ) Cruise_speed = i2f(100); + if (Cruise_speed < 0 ) Cruise_speed = 0; + if (Controls.forward_thrust_time==0) Controls.forward_thrust_time = fixmul(Cruise_speed,FrameTime)/100; + + //----------- Clamp values between -FrameTime and FrameTime if (Controls.pitch_time > FrameTime/2 ) Controls.pitch_time = FrameTime/2; if (Controls.heading_time > FrameTime ) Controls.heading_time = FrameTime; if (Controls.pitch_time < -FrameTime/2 ) Controls.pitch_time = -FrameTime/2; if (Controls.heading_time < -FrameTime ) Controls.heading_time = -FrameTime; - if (Controls.vertical_thrust_time > FrameTime ) Controls.vertical_thrust_time = FrameTime; if (Controls.sideways_thrust_time > FrameTime ) Controls.sideways_thrust_time = FrameTime; if (Controls.bank_time > FrameTime ) Controls.bank_time = FrameTime; if (Controls.forward_thrust_time > FrameTime ) Controls.forward_thrust_time = FrameTime; - if (Controls.vertical_thrust_time < -FrameTime ) Controls.vertical_thrust_time = -FrameTime; if (Controls.sideways_thrust_time < -FrameTime ) Controls.sideways_thrust_time = -FrameTime; if (Controls.bank_time < -FrameTime ) Controls.bank_time = -FrameTime; if (Controls.forward_thrust_time < -FrameTime ) Controls.forward_thrust_time = -FrameTime; - - -//--------- Don't do anything if in debug mode -#ifndef NDEBUG - if ( keyd_pressed[KEY_DELETE] ) { - memset( &Controls, 0, sizeof(control_info) ); - } -#endif } void reset_cruise(void) diff --git a/main/kconfig.h b/main/kconfig.h index f5d59439f..28eabb6c2 100644 --- a/main/kconfig.h +++ b/main/kconfig.h @@ -23,6 +23,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define _KCONFIG_H #include "config.h" +#include "event.h" #include "key.h" #include "joy.h" #include "mouse.h" @@ -35,18 +36,25 @@ typedef struct _control_info { fix sideways_thrust_time; fix bank_time; fix forward_thrust_time; - ubyte rear_view_down_count; - ubyte rear_view_down_state; - ubyte fire_primary_down_count; + ubyte pitch_forward_state, pitch_backward_state; + ubyte heading_left_state, heading_right_state; + ubyte slide_on_state, slide_left_state, slide_right_state, slide_up_state, slide_down_state; + ubyte bank_on_state, bank_left_state, bank_right_state; + ubyte accelerate_state, reverse_state; + ubyte cruise_plus_state, cruise_minus_state, cruise_off_count; + ubyte rear_view_state; + ubyte rear_view_count; ubyte fire_primary_state; + ubyte fire_primary_count; ubyte fire_secondary_state; - ubyte fire_secondary_down_count; - ubyte fire_flare_down_count; - ubyte drop_bomb_down_count; - ubyte automap_down_count; + ubyte fire_secondary_count; + ubyte fire_flare_count; + ubyte drop_bomb_count; ubyte automap_state; + ubyte automap_count; ubyte cycle_primary_count; ubyte cycle_secondary_count; + ubyte select_weapon_count; } control_info; #define CONTROL_USING_JOYSTICK 1 @@ -60,7 +68,7 @@ typedef struct _control_info { #define MAX_CONTROLS 50 extern control_info Controls; -extern void controls_read_all(int automap_flag); +extern void kconfig_read_controls(d_event *event, int automap_flag); extern void kconfig(int n, char *title); extern ubyte DefaultKeySettingsD1X[MAX_D1X_CONTROLS]; diff --git a/main/multi.c b/main/multi.c index c44db9d62..c7e5059db 100644 --- a/main/multi.c +++ b/main/multi.c @@ -1019,6 +1019,7 @@ multi_define_macro(int key) } if (multi_defining_message) { + key_toggle_repeat(1); multi_message_index = 0; Network_message[multi_message_index] = 0; } @@ -1128,6 +1129,7 @@ multi_send_message_start() multi_sending_message = 1; multi_message_index = 0; Network_message[multi_message_index] = 0; + key_toggle_repeat(1); } } @@ -1144,6 +1146,7 @@ void multi_send_message_end() multi_message_index = 0; multi_sending_message = 0; + key_toggle_repeat(0); if (!strnicmp (Network_message,"kick:",5) && (Game_mode & GM_NETWORK)) { @@ -1249,6 +1252,7 @@ void multi_define_macro_end() multi_message_index = 0; multi_defining_message = 0; + key_toggle_repeat(0); game_flush_inputs(); } @@ -1260,6 +1264,7 @@ int multi_message_input_sub(int key) case KEY_ESC: multi_sending_message = 0; multi_defining_message = 0; + key_toggle_repeat(0); game_flush_inputs(); return 1; case KEY_LEFT: diff --git a/main/newmenu.c b/main/newmenu.c index 1c800ccbe..6c146e572 100644 --- a/main/newmenu.c +++ b/main/newmenu.c @@ -1492,10 +1492,12 @@ int newmenu_handler(window *wind, d_event *event, newmenu *menu) case EVENT_WINDOW_ACTIVATED: game_flush_inputs(); event_toggle_focus(0); + key_toggle_repeat(1); break; case EVENT_WINDOW_DEACTIVATED: //event_toggle_focus(1); // No cursor recentering + key_toggle_repeat(0); menu->mouse_state = 0; break; @@ -2075,10 +2077,12 @@ int listbox_handler(window *wind, d_event *event, listbox *lb) case EVENT_WINDOW_ACTIVATED: game_flush_inputs(); event_toggle_focus(0); + key_toggle_repeat(1); break; case EVENT_WINDOW_DEACTIVATED: //event_toggle_focus(1); // No cursor recentering + key_toggle_repeat(0); break; case EVENT_MOUSE_BUTTON_DOWN: diff --git a/main/slew.c b/main/slew.c index 26ebbd42d..f76f793d9 100644 --- a/main/slew.c +++ b/main/slew.c @@ -181,13 +181,20 @@ int do_slew_movement(object *obj, int check_keys ) if (check_keys) { if (Function_mode == FMODE_EDITOR) { - obj->mtype.phys_info.velocity.x += VEL_SPEED * (key_down_time(KEY_PAD9) - key_down_time(KEY_PAD7)); - obj->mtype.phys_info.velocity.y += VEL_SPEED * (key_down_time(KEY_PADMINUS) - key_down_time(KEY_PADPLUS)); - obj->mtype.phys_info.velocity.z += VEL_SPEED * (key_down_time(KEY_PAD8) - key_down_time(KEY_PAD2)); + obj->mtype.phys_info.velocity.x += VEL_SPEED * keyd_pressed[KEY_PAD9] * FrameTime; + obj->mtype.phys_info.velocity.x -= VEL_SPEED * keyd_pressed[KEY_PAD7] * FrameTime; + obj->mtype.phys_info.velocity.y += VEL_SPEED * keyd_pressed[KEY_PADMINUS] * FrameTime; + obj->mtype.phys_info.velocity.y -= VEL_SPEED * keyd_pressed[KEY_PADPLUS] * FrameTime; + obj->mtype.phys_info.velocity.z += VEL_SPEED * keyd_pressed[KEY_PAD8] * FrameTime; + obj->mtype.phys_info.velocity.z -= VEL_SPEED * keyd_pressed[KEY_PAD2] * FrameTime; - rotang.p = (key_down_time(KEY_LBRACKET) - key_down_time(KEY_RBRACKET))/ROT_SPEED ; - rotang.b = (key_down_time(KEY_PAD1) - key_down_time(KEY_PAD3))/ROT_SPEED; - rotang.h = (key_down_time(KEY_PAD6) - key_down_time(KEY_PAD4))/ROT_SPEED; + rotang.p = rotang.b = rotang.h = 0; + rotang.p += keyd_pressed[KEY_LBRACKET] * FrameTime / ROT_SPEED; + rotang.p -= keyd_pressed[KEY_RBRACKET] * FrameTime / ROT_SPEED; + rotang.b += keyd_pressed[KEY_PAD1] * FrameTime / ROT_SPEED; + rotang.b -= keyd_pressed[KEY_PAD3] * FrameTime / ROT_SPEED; + rotang.h += keyd_pressed[KEY_PAD6] * FrameTime / ROT_SPEED; + rotang.h -= keyd_pressed[KEY_PAD4] * FrameTime / ROT_SPEED; } else { obj->mtype.phys_info.velocity.x += VEL_SPEED * Controls.sideways_thrust_time;