"Fixed" a stupid input workaround. It doesn't depend on keyboard anymore.

This commit is contained in:
Andrew "Akari" Alexeyew 2012-08-17 21:58:23 +03:00
parent dae46d363a
commit 536b5b7f09
12 changed files with 61 additions and 30 deletions

View file

@ -232,6 +232,22 @@ char* gamepad_devicename(int id) {
return (char*)SDL_JoystickName(id);
}
int gamepad_buttonpressed(int btn) {
return SDL_JoystickGetButton(gamepad.device, btn);
}
int gamepad_gamekeypressed(int key) {
if(!gamepad.initialized)
return 0;
// this sucks
int i; for(i = CONFIG_GPKEY_FIRST; i <= CONFIG_GPKEY_LAST; ++i)
if(key == config_gpkey2key(i) && gamepad_buttonpressed(tconfig.intval[i]))
return 1;
return 0;
}
void gamepad_init_bare(void) {
if(gamepad.initialized)
return;

View file

@ -18,6 +18,9 @@ int gamepad_devicecount(void);
char* gamepad_devicename(int);
void gamepad_event(SDL_Event*, EventHandler, EventFlags, void*);
int gamepad_buttonpressed(int btn);
int gamepad_gamekeypressed(int key);
// shitty workaround for the options menu. Used to list devices while the gamepad subsystem is off.
// only initializes the SDL subsystem so you can use gamepad_devicecount/gamepad_devicename.
// if gamepad has been initialized already, these do nothing.

View file

@ -241,3 +241,9 @@ void stralloc(char **dest, char *src) {
*dest = malloc(strlen(src)+1);
strcpy(*dest, src);
}
// Inputdevice-agnostic method of checking whether a game control is pressed.
// ALWAYS use this instead of SDL_GetKeyState if you need it.
int gamekeypressed(int key) {
return SDL_GetKeyState(NULL)[tconfig.intval[key]] || gamepad_gamekeypressed(key);
}

View file

@ -152,6 +152,7 @@ double psin(double);
int strendswith(char *s, char *e);
char* difficulty_name(Difficulty diff);
void stralloc(char **dest, char *src);
int gamekeypressed(int key);
#define SIGN(x) ((x > 0) - (x < 0))

View file

@ -35,7 +35,7 @@ void restart_game(void *arg);
void create_gameover_menu(MenuData *m) {
create_menu(m);
m->flags = MF_Transient;
m->flags = MF_Transient | MF_AlwaysProcessInput;
m->transition = NULL;
m->context = "Game Over";

View file

@ -23,7 +23,7 @@ void restart_game(void *arg) {
void create_ingame_menu(MenuData *m) {
create_menu(m);
m->flags = MF_Abortable | MF_Transient;
m->flags = MF_Abortable | MF_Transient | MF_AlwaysProcessInput;
m->transition = NULL;
add_menu_entry(m, "Return to Game", return_to_game, NULL);
add_menu_entry(m, "Restart the Game", restart_game, NULL)->transition = TransFadeBlack;

View file

@ -140,7 +140,7 @@ int menu_loop(MenuData *menu, void (*input)(MenuData*), void (*draw)(MenuData*),
while(menu->state != MS_Dead) {
menu_logic(menu);
if(menu->state != MS_FadeOut) {
if(menu->state != MS_FadeOut || menu->flags & MF_AlwaysProcessInput) {
if(input)
input(menu);
else

View file

@ -43,6 +43,7 @@ enum MenuFlag {
MF_InstantSelect = 4,
MF_ManualDrawTransition = 8, // the menu will not call draw_transition() automatically
MF_AlwaysProcessInput = 16 // the menu will process input even during fadeouts
};
enum MenuState{

View file

@ -11,8 +11,7 @@
#include "projectile.h"
#include "global.h"
#include "plrmodes.h"
#include "menu/gameovermenu.h"
#include "menu/ingamemenu.h"
#include "stage.h"
void init_player(Player* plr) {
memset(plr, 0, sizeof(Player));
@ -210,11 +209,8 @@ void player_realdeath(Player *plr) {
if(plr->bombs < PLR_START_BOMBS)
plr->bombs = PLR_START_BOMBS;
if(plr->lifes-- == 0 && global.replaymode != REPLAY_PLAY) {
MenuData m;
create_gameover_menu(&m);
ingame_menu_loop(&m);
}
if(plr->lifes-- == 0 && global.replaymode != REPLAY_PLAY)
stage_gameover();
}
void player_death(Player *plr) {
@ -327,7 +323,7 @@ int player_applymovement_gamepad(Player *plr) {
return True;
}
void player_applymovement(Player* plr) {
void player_applymovement(Player *plr) {
if(plr->deathtime < -1)
return;
@ -362,21 +358,22 @@ void player_applymovement(Player* plr) {
if(direction)
player_move(&global.plr, direction);
// workaround
// TODO: FIX THIS FOR GAMEPAD SOMEHOW
if(global.replaymode == REPLAY_RECORD && !global.dialog && !tconfig.intval[GAMEPAD_ENABLED]) {
Uint8 *keys = SDL_GetKeyState(NULL);
}
void player_input_workaround(Player *plr) {
if(!global.dialog) {
int shot = gamekeypressed(KEY_SHOT);
int focus = gamekeypressed(KEY_FOCUS);
if(!keys[tconfig.intval[KEY_SHOT]] && plr->fire) {
if(!shot && plr->fire) {
player_event(plr, EV_RELEASE, KEY_SHOT);
replay_event(&global.replay, EV_RELEASE, KEY_SHOT);
} else if(keys[tconfig.intval[KEY_SHOT]] && !plr->fire) {
} else if(shot && !plr->fire) {
player_event(plr, EV_PRESS, KEY_SHOT);
replay_event(&global.replay, EV_PRESS, KEY_SHOT);
}
if(!keys[tconfig.intval[KEY_FOCUS]] && plr->focus > 0) {
if(!focus && plr->focus > 0) {
player_event(plr, EV_RELEASE, KEY_FOCUS);
replay_event(&global.replay, EV_RELEASE, KEY_FOCUS);
}

View file

@ -87,5 +87,6 @@ void player_graze(Player*, complex, int);
void player_setmoveflag(Player* plr, int key, int mode);
void player_event(Player* plr,int type, int key);
void player_applymovement(Player* plr);
void player_input_workaround(Player *plr);
#endif

View file

@ -15,6 +15,7 @@
#include "config.h"
#include "player.h"
#include "menu/ingamemenu.h"
#include "menu/gameovermenu.h"
#include "taisei_err.h"
StageInfo stages[] = {
@ -52,12 +53,18 @@ void stage_start(void) {
global.plr.deathtime = -1;
}
void stage_ingamemenu(void) {
void stage_pause(void) {
MenuData menu;
create_ingame_menu(&menu);
ingame_menu_loop(&menu);
}
void stage_gameover(void) {
MenuData m;
create_gameover_menu(&m);
ingame_menu_loop(&m);
}
void stage_input_event(EventType type, int key, void *arg) {
switch(type) {
case E_PlrKeyDown:
@ -83,7 +90,7 @@ void stage_input_event(EventType type, int key, void *arg) {
break;
case E_Pause:
stage_ingamemenu();
stage_pause();
break;
case E_PlrAxisLR:
@ -102,7 +109,7 @@ void stage_input_event(EventType type, int key, void *arg) {
void stage_replay_event(EventType type, int state, void *arg) {
if(type == E_Pause)
stage_ingamemenu();
stage_pause();
}
void replay_input(void) {
@ -141,17 +148,13 @@ void stage_input(void) {
handle_events(stage_input_event, EF_Game, NULL);
// workaround
// TODO: FIX THIS FOR GAMEPAD SOMEHOW
if(global.dialog && global.dialog->skip && !tconfig.intval[GAMEPAD_ENABLED]) {
Uint8 *keys = SDL_GetKeyState(NULL);
if(!keys[tconfig.intval[KEY_SKIP]]) {
global.dialog->skip = False;
replay_event(&global.replay, EV_RELEASE, KEY_SKIP);
}
if(global.dialog && global.dialog->skip && !gamekeypressed(KEY_SKIP)) {
global.dialog->skip = False;
replay_event(&global.replay, EV_RELEASE, KEY_SKIP);
}
player_applymovement(&global.plr);
player_input_workaround(&global.plr);
}
void draw_hud(void) {

View file

@ -59,4 +59,7 @@ void stage4_loop(void);
void stage5_loop(void);
void stage6_loop(void);
void stage_pause(void);
void stage_gameover(void);
#endif