[Change] Improve key handling to avoid situations where pilot gets
"blocked".
This commit is contained in:
parent
ae91853484
commit
cc33574b5e
79
src/input.c
79
src/input.c
@ -209,7 +209,7 @@ void input_exit(void) {
|
|||||||
static void input_keyConvGen(void) {
|
static void input_keyConvGen(void) {
|
||||||
SDLKey k;
|
SDLKey k;
|
||||||
|
|
||||||
for(k == SDLK_FIRST; k < SDLK_LAST; k++)
|
for(k = SDLK_FIRST; k < SDLK_LAST; k++)
|
||||||
keyconv[k] = SDL_GetKeyName(k);
|
keyconv[k] = SDL_GetKeyName(k);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -339,36 +339,46 @@ static void input_key(int keynum, double value, int kabs) {
|
|||||||
|
|
||||||
if(value == KEY_PRESS) input_accelLast = t;
|
if(value == KEY_PRESS) input_accelLast = t;
|
||||||
}
|
}
|
||||||
|
/* Afterburning. */
|
||||||
else if(KEY("afterburn") && INGAME() && NOHYP()) {
|
else if(KEY("afterburn") && INGAME() && NOHYP()) {
|
||||||
if(value == KEY_PRESS) player_afterburn();
|
if(value == KEY_PRESS)
|
||||||
else if(value == KEY_RELEASE) player_afterburnOver();
|
player_afterburn();
|
||||||
|
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_AFTERBURNER))
|
||||||
|
player_afterburnOver();
|
||||||
}
|
}
|
||||||
/* Turning left. */
|
/* Turning left. */
|
||||||
else if(KEY("left")) {
|
else if(KEY("left")) {
|
||||||
/* Set flags for facing correction. */
|
if(kabs)
|
||||||
if(value == KEY_PRESS) {
|
player_turn = -value;
|
||||||
player_abortAutonav(NULL);
|
else {
|
||||||
player_setFlag(PLAYER_TURN_LEFT);
|
/* Set flags for facing correction. */
|
||||||
|
if(value == KEY_PRESS) {
|
||||||
|
player_abortAutonav(NULL);
|
||||||
|
player_setFlag(PLAYER_TURN_LEFT);
|
||||||
|
}
|
||||||
|
else if(value == KEY_RELEASE)
|
||||||
|
player_rmFlag(PLAYER_TURN_LEFT);
|
||||||
|
player_turn -= value;
|
||||||
}
|
}
|
||||||
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_LEFT); }
|
/* Make sure the value is sane. */
|
||||||
|
if(player_turn < -1.) player_turn = -1.;
|
||||||
if(kabs) { player_turn = -value; }
|
|
||||||
else { player_turn -= value; }
|
|
||||||
if(player_turn < -1.) player_turn = -1.; /* Make sure value is sane. */
|
|
||||||
}
|
}
|
||||||
/* Turning right. */
|
/* Turning right. */
|
||||||
else if(KEY("right")) {
|
else if(KEY("right")) {
|
||||||
/* Set flags for facing correction. */
|
if(kabs)
|
||||||
if(value == KEY_PRESS) {
|
player_turn = value;
|
||||||
player_abortAutonav(NULL);
|
else {
|
||||||
player_setFlag(PLAYER_TURN_RIGHT);
|
/* Set flags for facing correction. */
|
||||||
|
if(value == KEY_PRESS) {
|
||||||
|
player_abortAutonav(NULL);
|
||||||
|
player_setFlag(PLAYER_TURN_RIGHT);
|
||||||
|
}
|
||||||
|
else if(value == KEY_RELEASE)
|
||||||
|
player_rmFlag(PLAYER_TURN_RIGHT);
|
||||||
|
player_turn += value;
|
||||||
}
|
}
|
||||||
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_TURN_RIGHT); }
|
/* Make sure the value is sane. */
|
||||||
|
if(player_turn > 1.) player_turn = 1.;
|
||||||
if(kabs) { player_turn = value; }
|
|
||||||
else { player_turn += value; }
|
|
||||||
|
|
||||||
if(player_turn < -1.) { player_turn = -1.; } /* Make sure value is sane. */
|
|
||||||
}
|
}
|
||||||
/* Turn around to face vel. */
|
/* Turn around to face vel. */
|
||||||
else if(KEY("reverse")) {
|
else if(KEY("reverse")) {
|
||||||
@ -376,7 +386,7 @@ static void input_key(int keynum, double value, int kabs) {
|
|||||||
player_abortAutonav(NULL);
|
player_abortAutonav(NULL);
|
||||||
player_setFlag(PLAYER_REVERSE);
|
player_setFlag(PLAYER_REVERSE);
|
||||||
}
|
}
|
||||||
else if(value == KEY_RELEASE) {
|
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_REVERSE)) {
|
||||||
player_rmFlag(PLAYER_REVERSE);
|
player_rmFlag(PLAYER_REVERSE);
|
||||||
player_turn = 0; /* Turning corrections. */
|
player_turn = 0; /* Turning corrections. */
|
||||||
if(player_isFlag(PLAYER_TURN_LEFT)) { player_turn -= 1; }
|
if(player_isFlag(PLAYER_TURN_LEFT)) { player_turn -= 1; }
|
||||||
@ -410,7 +420,7 @@ static void input_key(int keynum, double value, int kabs) {
|
|||||||
player_abortAutonav(NULL);
|
player_abortAutonav(NULL);
|
||||||
player_setFlag(PLAYER_FACE);
|
player_setFlag(PLAYER_FACE);
|
||||||
}
|
}
|
||||||
else if(value == KEY_RELEASE) {
|
else if((value == KEY_RELEASE) && player_isFlag(PLAYER_FACE)) {
|
||||||
player_rmFlag(PLAYER_FACE);
|
player_rmFlag(PLAYER_FACE);
|
||||||
|
|
||||||
/* Turning corrections. */
|
/* Turning corrections. */
|
||||||
@ -441,8 +451,12 @@ static void input_key(int keynum, double value, int kabs) {
|
|||||||
}
|
}
|
||||||
/* Shooting secondary weapon. */
|
/* Shooting secondary weapon. */
|
||||||
else if(KEY("secondary") && NOHYP()) {
|
else if(KEY("secondary") && NOHYP()) {
|
||||||
if(value == KEY_PRESS) { player_setFlag(PLAYER_SECONDARY); }
|
if(value == KEY_PRESS) {
|
||||||
else if(value == KEY_RELEASE) { player_rmFlag(PLAYER_SECONDARY); }
|
player_abortAutonav(NULL);
|
||||||
|
player_setFlag(PLAYER_SECONDARY);
|
||||||
|
}
|
||||||
|
else if(value == KEY_RELEASE)
|
||||||
|
player_rmFlag(PLAYER_SECONDARY);
|
||||||
}
|
}
|
||||||
/* Selecting secondary weapon. */
|
/* Selecting secondary weapon. */
|
||||||
else if(KEY("secondary_next") && INGAME()) {
|
else if(KEY("secondary_next") && INGAME()) {
|
||||||
@ -569,11 +583,16 @@ static void input_keyevent(int event, SDLKey key, SDLMod mod) {
|
|||||||
|
|
||||||
mod &= ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE); /* We want to ignore "global" modifiers. */
|
mod &= ~(KMOD_CAPS | KMOD_NUM | KMOD_MODE); /* We want to ignore "global" modifiers. */
|
||||||
|
|
||||||
for(i = 0; strcmp(keybindNames[i], "end"); i++)
|
for(i = 0; strcmp(keybindNames[i], "end"); i++) {
|
||||||
if((input_keybinds[i]->type == KEYBIND_KEYBOARD) &&
|
if((input_keybinds[i]->type == KEYBIND_KEYBOARD) &&
|
||||||
(input_keybinds[i]->key == key) &&
|
(input_keybinds[i]->key == key)) {
|
||||||
((input_keybinds[i]->mod == mod) || (input_keybinds[i]->mod == KMOD_ALL)))
|
if((input_keybinds[i]->mod == mod) ||
|
||||||
input_key(i, event, 0);
|
(input_keybinds[i]->mod == KMOD_ALL) ||
|
||||||
|
(event == KEY_RELEASE)) /**< Release always gets through. */
|
||||||
|
input_key(i, event, 0);
|
||||||
|
/* No break so all keys get pressed if needed. */
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user