hotkey overhaul; should increase sdl performance

This commit is contained in:
punkrockguy318 2008-11-13 18:23:17 +00:00
parent 0a5f20c034
commit a29c8f25a4
3 changed files with 104 additions and 90 deletions

View File

@ -147,6 +147,76 @@ _keyonly(int a)
static int g_fkbEnabled = 0; static int g_fkbEnabled = 0;
// key definitions
int cheatMenuKey;
int loadLuaKey;
int renderBgKey;
int saveStateKey;
int loadStateKey;
int resetKey;
int screenshotKey;
int pauseKey;
int decreaseSpeedKey;
int increaseSpeedKey;
int frameAdvanceKey;
int powerKey;
int bindStateKey;
int frameAdvanceLagSkipKey;
int quitKey;
int stateKey[10];
int movieToggleFrameDisplayKey;
int lagCounterDisplayKey;
void setHotKeys()
{
g_config->getOption("SDL.Hotkeys.CheatMenu", &cheatMenuKey);
#ifdef _S9XLUA_H
g_config->getOption("SDL.Hotkeys.LoadLua", &loadLuaKey);
#endif
g_config->getOption("SDL.Hotkeys.RenderBG", &renderBgKey);
g_config->getOption("SDL.Hotkeys.SaveState", &saveStateKey);
g_config->getOption("SDL.Hotkeys.LoadState", &loadStateKey);
g_config->getOption("SDL.Hotkeys.Reset", &resetKey);
g_config->getOption("SDL.Hotkeys.Screenshot", &screenshotKey);
g_config->getOption("SDL.Hotkeys.Pause", &pauseKey);
g_config->getOption("SDL.Hotkeys.IncreaseSpeed", &increaseSpeedKey);
g_config->getOption("SDL.Hotkeys.DecreaseSpeed", &decreaseSpeedKey);
g_config->getOption("SDL.Hotkeys.FrameAdvance", &frameAdvanceKey);
g_config->getOption("SDL.Hotkeys.Power", &powerKey);
g_config->getOption("SDL.Hotkeys.Pause", &bindStateKey);
g_config->getOption("SDL.Hotkeys.FrameAdvanceLagSkip", &frameAdvanceLagSkipKey);
g_config->getOption("SDL.Hotkeys.Quit", &quitKey);
g_config->getOption("SDL.Hotkeys.SelectState0", &stateKey[0]);
g_config->getOption("SDL.Hotkeys.SelectState1", &stateKey[1]);
g_config->getOption("SDL.Hotkeys.SelectState2", &stateKey[2]);
g_config->getOption("SDL.Hotkeys.SelectState3", &stateKey[3]);
g_config->getOption("SDL.Hotkeys.SelectState4", &stateKey[4]);
g_config->getOption("SDL.Hotkeys.SelectState5", &stateKey[5]);
g_config->getOption("SDL.Hotkeys.SelectState6", &stateKey[6]);
g_config->getOption("SDL.Hotkeys.SelectState7", &stateKey[7]);
g_config->getOption("SDL.Hotkeys.SelectState8", &stateKey[8]);
g_config->getOption("SDL.Hotkeys.SelectState9", &stateKey[9]);
g_config->getOption("SDL.Hotkeys.LagCounterDisplay", &lagCounterDisplayKey);
g_config->getOption("SDL.Hotkeys.MovieToggleFrameDisplay", &movieToggleFrameDisplayKey);
/*
config->addOption(prefix + "FrameAdvance", SDLK_BACKSLASH);
config->addOption(prefix + "Power", 0);
config->addOption(prefix + "BindState", SDLK_F2);
config->addOption(prefix + "FrameAdvanceLagSkip", SDLK_F6);
config->addOption(prefix + "LagCounterDisplay", SDLK_F8);
config->addOption(prefix + "SelectState0", SDLK_0);
config->addOption(prefix + "SelectState1", SDLK_1);
config->addOption(prefix + "SelectState2", SDLK_2);
config->addOption(prefix + "SelectState3", SDLK_3);
config->addOption(prefix + "SelectState4", SDLK_4);
config->addOption(prefix + "SelectState5", SDLK_5);
config->addOption(prefix + "SelectState6", SDLK_6);
config->addOption(prefix + "SelectState7", SDLK_7);
config->addOption(prefix + "SelectState8", SDLK_8);
config->addOption(prefix + "SelectState9", SDLK_9);*/
return;
}
/*** /***
* This function opens a file chooser dialog and returns the filename the * This function opens a file chooser dialog and returns the filename the
* user selected. * user selected.
@ -217,7 +287,7 @@ std::string GetFilename(const char* title)
static void static void
KeyboardCommands() KeyboardCommands()
{ {
int is_shift, is_alt, key; int is_shift, is_alt;
char* movie_fname = ""; char* movie_fname = "";
// get the keyboard input // get the keyboard input
g_keyState = SDL_GetKeyState(NULL); g_keyState = SDL_GetKeyState(NULL);
@ -238,8 +308,7 @@ KeyboardCommands()
is_shift = KEY(LEFTSHIFT) | KEY(RIGHTSHIFT); is_shift = KEY(LEFTSHIFT) | KEY(RIGHTSHIFT);
is_alt = KEY(LEFTALT) | KEY(RIGHTALT); is_alt = KEY(LEFTALT) | KEY(RIGHTALT);
g_config->getOption("SDL.Hotkeys.RenderBG", &key); if(_keyonly(renderBgKey)) {
if(_keyonly(key)) {
if(is_shift) { if(is_shift) {
FCEUI_SetRenderPlanes(true, false); FCEUI_SetRenderPlanes(true, false);
} else { } else {
@ -259,32 +328,28 @@ KeyboardCommands()
} }
// Famicom disk-system games // Famicom disk-system games
if(gametype==GIT_FDS) { if(gametype==GIT_FDS)
{
if(keyonly(F6)) { if(keyonly(F6)) {
FCEUI_FDSSelect(); FCEUI_FDSSelect();
} }
if(keyonly(F8)) { if(keyonly(F8)) {
FCEUI_FDSInsert(); FCEUI_FDSInsert();
} }
} }
if(_keyonly(screenshotKey)) {
g_config->getOption("SDL.Hotkeys.Screenshot", &key);
if(_keyonly(key)) {
FCEUI_SaveSnapshot(); FCEUI_SaveSnapshot();
} }
// if not NES Sound Format // if not NES Sound Format
if(gametype != GIT_NSF) { if(gametype != GIT_NSF) {
if(_keyonly(cheatMenuKey)) {
g_config->getOption("SDL.Hotkeys.CheatMenu", &key);
if(_keyonly(key)) {
DoCheatSeq(); DoCheatSeq();
} }
g_config->getOption("SDL.Hotkeys.SaveState", &key); // f5 (default) save key, hold shift to save movie
if(_keyonly(key)) { if(_keyonly(saveStateKey)) {
if(is_shift) { if(is_shift) {
movie_fname = const_cast<char*>(FCEU_MakeFName(FCEUMKF_MOVIE, 0, 0).c_str()); movie_fname = const_cast<char*>(FCEU_MakeFName(FCEUMKF_MOVIE, 0, 0).c_str());
FCEUI_printf("Recording movie to %s\n", movie_fname); FCEUI_printf("Recording movie to %s\n", movie_fname);
@ -294,9 +359,8 @@ KeyboardCommands()
} }
} }
g_config->getOption("SDL.Hotkeys.LoadState", &key);
// f7 to load state, Shift-f7 to load movie // f7 to load state, Shift-f7 to load movie
if(_keyonly(key)) { if(_keyonly(loadStateKey)) {
if(is_shift) { if(is_shift) {
FCEUI_StopMovie(); FCEUI_StopMovie();
std::string fname; std::string fname;
@ -320,26 +384,24 @@ KeyboardCommands()
} }
g_config->getOption("SDL.Hotkeys.DecreaseSpeed", &key); if(_keyonly(decreaseSpeedKey)) {
if(_keyonly(key)) {
DecreaseEmulationSpeed(); DecreaseEmulationSpeed();
} }
g_config->getOption("SDL.Hotkeys.IncreaseSpeed", &key);
if(_keyonly(key)) { if(_keyonly(increaseSpeedKey)) {
IncreaseEmulationSpeed(); IncreaseEmulationSpeed();
} }
if(keyonly(BACKSPACE)) { if(_keyonly(movieToggleFrameDisplayKey)) {
FCEUI_MovieToggleFrameDisplay(); FCEUI_MovieToggleFrameDisplay();
} }
g_config->getOption("SDL.Hotkeys.Pause", &key);
if(_keyonly(key)) { if(_keyonly(pauseKey)) {
FCEUI_ToggleEmulationPause(); FCEUI_ToggleEmulationPause();
} }
g_config->getOption("SDL.Hotkeys.FrameAdvance", &key);
static bool frameAdvancing = false; static bool frameAdvancing = false;
if(g_keyState[key]) if(g_keyState[frameAdvanceKey])
{ {
if(frameAdvancing == false) if(frameAdvancing == false)
{ {
@ -356,21 +418,18 @@ KeyboardCommands()
//} //}
} }
g_config->getOption("SDL.Hotkeys.Reset", &key); if(_keyonly(resetKey)) {
if(_keyonly(key)) {
FCEUI_ResetNES(); FCEUI_ResetNES();
} }
g_config->getOption("SDL.Hotkeys.Power", &key); if(_keyonly(powerKey)) {
if(_keyonly(key)) {
FCEUI_PowerNES(); FCEUI_PowerNES();
} }
g_config->getOption("SDL.Hotkeys.Quit", &key);
if(_keyonly(key)) { if(_keyonly(quitKey)) {
FCEUI_CloseGame(); FCEUI_CloseGame();
} }
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
g_config->getOption("SDL.Hotkeys.LoadLua", &key); if(_keyonly(loadLuaKey)) {
if(_keyonly(key)) {
std::string fname; std::string fname;
fname = GetFilename("Open LUA script..."); fname = GetFilename("Open LUA script...");
if(fname != "") if(fname != "")
@ -378,72 +437,23 @@ KeyboardCommands()
} }
#endif #endif
std::string opt = "SDL.Hotkeys.SelectState0"; for(int i=0; i<10; i++)
g_config->getOption(opt, &key); if(_keyonly(stateKey[i]))
if(_keyonly(key)) FCEUI_SelectState(i, 1);
FCEUI_SelectState(0,1);
opt = "SDL.Hotkeys.SelectState1"; if(_keyonly(bindStateKey)) {
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(1,1);
opt = "SDL.Hotkeys.SelectState2";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(2,1);
opt = "SDL.Hotkeys.SelectState3";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(3,1);
opt = "SDL.Hotkeys.SelectState4";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(4,1);
opt = "SDL.Hotkeys.SelectState5";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(5,1);
opt = "SDL.Hotkeys.SelectState6";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(6,1);
opt = "SDL.Hotkeys.SelectState7";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(7,1);
opt = "SDL.Hotkeys.SelectState8";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(8,1);
opt = "SDL.Hotkeys.SelectState9";
g_config->getOption(opt, &key);
if(_keyonly(key))
FCEUI_SelectState(9,1);
g_config->getOption("SDL.Hotkeys.BindState", &key);
if(_keyonly(key)) {
bindSavestate ^= 1; bindSavestate ^= 1;
FCEUI_DispMessage("Savestate binding to movie %sabled.", FCEUI_DispMessage("Savestate binding to movie %sabled.",
bindSavestate ? "en" : "dis"); bindSavestate ? "en" : "dis");
} }
g_config->getOption("SDL.Hotkeys.FrameAdvanceLagSkip", &key); if(_keyonly(frameAdvanceLagSkipKey)) {
if(_keyonly(key)) {
frameAdvanceLagSkip ^= 1; frameAdvanceLagSkip ^= 1;
FCEUI_DispMessage("Skipping lag in Frame Advance %sabled.", FCEUI_DispMessage("Skipping lag in Frame Advance %sabled.",
frameAdvanceLagSkip ? "en" : "dis"); frameAdvanceLagSkip ? "en" : "dis");
} }
g_config->getOption("SDL.Hotkeys.LagCounterDisplay", &key); if(_keyonly(lagCounterDisplayKey)) {
if(_keyonly(key)) {
lagCounterDisplay ^= 1; lagCounterDisplay ^= 1;
} }

View File

@ -15,6 +15,7 @@ typedef struct {
extern CFGSTRUCT InputConfig[]; extern CFGSTRUCT InputConfig[];
extern ARGPSTRUCT InputArgs[]; extern ARGPSTRUCT InputArgs[];
void ParseGIInput(FCEUGI *GI); void ParseGIInput(FCEUGI *GI);
void setHotKeys();
#define BUTTC_KEYBOARD 0x00 #define BUTTC_KEYBOARD 0x00
#define BUTTC_JOYSTICK 0x01 #define BUTTC_JOYSTICK 0x01

View File

@ -559,6 +559,9 @@ SDL_GL_LoadLibrary(0);
} }
#endif #endif
// load the hotkeys from the config life
setHotKeys();
// load the specified game // load the specified game
error = LoadGame(argv[romIndex]); error = LoadGame(argv[romIndex]);
if(error != 1) { if(error != 1) {