From fd19b4e5d883115524da6799ee22b29ee7f46df4 Mon Sep 17 00:00:00 2001 From: Misa Date: Sun, 6 Sep 2020 04:28:09 -0700 Subject: [PATCH] Hoist Enter/Esc presses out of player entity for-loop The hooks to bring up the map screen, pause screen, quit from Super Gravitron, restart Time Trial, and commit suicide have now been hoisted out of the for-loop that checked for a player entity. None of these actions require a player entity, and there's no good reason to take away your control from any of these actions, especially being able to quit to the menu. The only actions inside the for-loop now are activating a terminal and activating a teleporter, both of which require a player entity to be standing in front of a terminal or teleporter, and both of which have good reasons to be temporarily disabled. --- desktop_version/src/Input.cpp | 184 ++++++++++++++++++---------------- 1 file changed, 99 insertions(+), 85 deletions(-) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 81ab2f47..10f77730 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -1793,18 +1793,23 @@ void gameinput() #endif //Entity type 0 is player controled + bool has_control = false; + bool enter_pressed = game.press_map && !game.mapheld; + bool enter_already_processed = false; for (size_t ie = 0; ie < obj.entities.size(); ++ie) { if (obj.entities[ie].rule == 0) { if (game.hascontrol && game.deathseq == -1 && game.lifeseq <= 5) { - if (game.press_map && !game.mapheld) + has_control = true; + if (enter_pressed) { game.mapheld = true; if (game.activetele && game.readytotele > 20 && !game.intimetrial) { + enter_already_processed = true; if(int(std::abs(obj.entities[ie].vx))<=1 && int(obj.entities[ie].vy)==0) { //wait! space station 2 debug thingy @@ -1881,6 +1886,7 @@ void gameinput() } else if (game.activeactivity > -1) { + enter_already_processed = true; if((int(std::abs(obj.entities[ie].vx))<=1) && (int(obj.entities[ie].vy) == 0) ) { script.load(obj.blocks[game.activeactivity].script); @@ -1888,74 +1894,6 @@ void gameinput() game.activeactivity = -1; } } - else if (game.swnmode == 1 && game.swngame == 1) - { - //quitting the super gravitron - game.mapheld = true; - //Quit menu, same conditions as in game menu - game.gamestate = MAPMODE; - game.gamesaved = false; - graphics.resumegamemode = false; - game.menupage = 20; // The Map Page - BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); - graphics.menuoffset = 240; //actually this should count the roomname - graphics.oldmenuoffset = 240; - if (map.extrarow) - { - graphics.menuoffset -= 10; - graphics.oldmenuoffset -= 10; - } - } - else if (game.intimetrial && graphics.fademode==0) - { - //Quick restart of time trial - graphics.fademode = 2; - game.completestop = true; - music.fadeout(); - game.quickrestartkludge = true; - } - else if (graphics.fademode==0) - { - //Normal map screen, do transition later - game.gamestate = MAPMODE; - map.cursordelay = 0; - map.cursorstate = 0; - game.gamesaved = false; - graphics.resumegamemode = false; - game.menupage = 0; // The Map Page - BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); - graphics.menuoffset = 240; //actually this should count the roomname - graphics.oldmenuoffset = 240; - if (map.extrarow) - { - graphics.menuoffset -= 10; - graphics.oldmenuoffset -= 10; - } - } - } - - if ((key.isDown(27) || key.isDown(game.controllerButton_esc)) && (!map.custommode || map.custommodeforreal)) - { - game.mapheld = true; - //Quit menu, same conditions as in game menu - game.gamestate = MAPMODE; - game.gamesaved = false; - graphics.resumegamemode = false; - game.menupage = 30; // Pause screen - - BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); - graphics.menuoffset = 240; //actually this should count the roomname - graphics.oldmenuoffset = 240; - if (map.extrarow) - { - graphics.menuoffset -= 10; - graphics.oldmenuoffset -= 10; - } - } - - if ((key.isDown(SDLK_r) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners! - { - game.deathseq = 30; } if (game.press_left) @@ -2036,24 +1974,100 @@ void gameinput() } } } - else - { - //Simple detection of keypresses outside player control, will probably scrap this (expand on - //advance text function) - if (!game.press_action) - { - game.jumppressed = 0; - game.jumpheld = false; - } - - if (game.press_action && !game.jumpheld) - { - game.jumppressed = 5; - game.jumpheld = true; - } - } } } + + if (!has_control) + { + //Simple detection of keypresses outside player control, will probably scrap this (expand on + //advance text function) + if (!game.press_action) + { + game.jumppressed = 0; + game.jumpheld = false; + } + + if (game.press_action && !game.jumpheld) + { + game.jumppressed = 5; + game.jumpheld = true; + } + } + + // Continuation of Enter processing. The rest of the if-tree runs only if + // enter_pressed && !enter_already_pressed + if (!enter_pressed || enter_already_processed) + { + // Do nothing + } + else if (game.swnmode == 1 && game.swngame == 1) + { + //quitting the super gravitron + game.mapheld = true; + //Quit menu, same conditions as in game menu + game.gamestate = MAPMODE; + game.gamesaved = false; + graphics.resumegamemode = false; + game.menupage = 20; // The Map Page + BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); + graphics.menuoffset = 240; //actually this should count the roomname + graphics.oldmenuoffset = 240; + if (map.extrarow) + { + graphics.menuoffset -= 10; + graphics.oldmenuoffset -= 10; + } + } + else if (game.intimetrial && graphics.fademode==0) + { + //Quick restart of time trial + graphics.fademode = 2; + game.completestop = true; + music.fadeout(); + game.quickrestartkludge = true; + } + else if (graphics.fademode==0) + { + //Normal map screen, do transition later + game.gamestate = MAPMODE; + map.cursordelay = 0; + map.cursorstate = 0; + game.gamesaved = false; + graphics.resumegamemode = false; + game.menupage = 0; // The Map Page + BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); + graphics.menuoffset = 240; //actually this should count the roomname + graphics.oldmenuoffset = 240; + if (map.extrarow) + { + graphics.menuoffset -= 10; + graphics.oldmenuoffset -= 10; + } + } + + if ((key.isDown(27) || key.isDown(game.controllerButton_esc)) && (!map.custommode || map.custommodeforreal)) + { + game.mapheld = true; + //Quit menu, same conditions as in game menu + game.gamestate = MAPMODE; + game.gamesaved = false; + graphics.resumegamemode = false; + game.menupage = 30; // Pause screen + + BlitSurfaceStandard(graphics.menubuffer,NULL,graphics.backBuffer, NULL); + graphics.menuoffset = 240; //actually this should count the roomname + graphics.oldmenuoffset = 240; + if (map.extrarow) + { + graphics.menuoffset -= 10; + graphics.oldmenuoffset -= 10; + } + } + + if (game.deathseq == -1 && (key.isDown(SDLK_r) || key.isDown(game.controllerButton_restart)) && !game.nodeathmode)// && map.custommode) //Have fun glitchrunners! + { + game.deathseq = 30; + } } void mapmenuactionpress();