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

This commit is contained in:
zicodxx 2011-02-02 01:36:43 +01:00
parent 5f096e322a
commit 5aa0939b73
19 changed files with 860 additions and 1362 deletions

View file

@ -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

View file

@ -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,

View file

@ -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

View file

@ -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];

View file

@ -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

View file

@ -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,

View file

@ -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;
}

View file

@ -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; i++ ) {
key_data.keybuffer[i] = 0;
key_data.time_pressed[i] = 0;
//Clear the unicode buffer
for (i=0; i<KEY_BUFFER_SIZE; i++ )
unicode_frame_buffer[i] = '\0';
}
for (i=0; i<256; i++ ) {
if (key_ismodlck(i) == KEY_ISLCK && keystate[key_properties[i].sym] && !GameArg.CtlNoStickyKeys) // do not flush status of sticky keys
{
keyd_pressed[i] = 1;
key_data.keys[i].state = 0;
key_data.keys[i].last_state = 1;
key_data.keys[i].timewentdown = timer_query();
key_data.keys[i].downcount=1;
key_data.keys[i].upcount=0;
key_data.keys[i].timehelddown = 1;
key_data.state[i] = 0;
}
else
{
keyd_pressed[i] = 0;
key_data.keys[i].state = 1;
key_data.keys[i].last_state = 0;
key_data.keys[i].timewentdown = timer_query();
key_data.keys[i].downcount=0;
key_data.keys[i].upcount=0;
key_data.keys[i].timehelddown = 0;
key_data.state[i] = 1;
}
}
}
int add_one(int n)
{
n++;
if ( n >= 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();
}

View file

@ -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; i++) {
Mouse.buttons[i].pressed=0;
Mouse.buttons[i].time_went_down=timer_query();
Mouse.buttons[i].time_held_down=0;
Mouse.buttons[i].num_ups=0;
Mouse.buttons[i].num_downs=0;
}
for (i=0; i<MOUSE_MAX_BUTTONS; i++)
Mouse.button_state[i]=0;
Mouse.delta_x = 0;
Mouse.delta_y = 0;
Mouse.delta_z = 0;
@ -230,7 +213,7 @@ int mouse_get_btns()
// event_poll();
for (i=0; i<MOUSE_MAX_BUTTONS; i++ ) {
if (Mouse.buttons[i].pressed)
if (Mouse.button_state[i])
status |= flag;
flag <<= 1;
}
@ -238,48 +221,6 @@ int mouse_get_btns()
return status;
}
// Returns how long this button has been down since last call.
fix64 mouse_button_down_time(int button)
{
fix64 time_down, time;
if (button < 0 || button >= 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
{

View file

@ -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

View file

@ -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;

View file

@ -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)) {

View file

@ -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<Controls.cycle_primary_count;i++)
CyclePrimary ();
Controls.cycle_primary_count = 0;
}
if (Controls.cycle_secondary_count)
if (Controls.cycle_secondary_count > 0)
{
for (i=0;i<Controls.cycle_secondary_count;i++)
CycleSecondary ();
Controls.cycle_secondary_count = 0;
}
if (Controls.select_weapon_count)
{
do_weapon_select(Controls.select_weapon_count>4?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;

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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];

View file

@ -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:

View file

@ -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:

View file

@ -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;