X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fgame_session.cpp;h=86b38e3d972233d0345caa42cbbc55b0083f5e98;hb=81931e4d4dae892ed8ba9f4e40da335881b93484;hp=037099c32d736fa531bfc2e949980bf67ee060df;hpb=99095f57c0c103f77fe0a12624450e6f99435830;p=supertux.git diff --git a/src/game_session.cpp b/src/game_session.cpp index 037099c32..86b38e3d9 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -40,10 +40,8 @@ #include #endif -#include "app/globals.h" #include "game_session.h" #include "video/screen.h" -#include "app/setup.h" #include "gui/menu.h" #include "sector.h" #include "level.h" @@ -57,7 +55,6 @@ #include "lisp/lisp.h" #include "lisp/parser.h" #include "resources.h" -#include "app/gettext.h" #include "worldmap.h" #include "misc.h" #include "statistics.h" @@ -67,6 +64,8 @@ #include "control/codecontroller.h" #include "control/joystickkeyboardcontroller.h" #include "main.h" +#include "gameconfig.h" +#include "gettext.h" // the engine will be run with a lofical framerate of 64fps. // We choose 64fps here because it is a power of 2, so 1/64 gives an "even" @@ -217,8 +216,7 @@ GameSession::levelintro() context.do_drawing(); - SDL_Event event; - wait_for_event(event,1000,3000,true); + wait_for_event(1.0, 3.0); } /* Reset Timers */ @@ -226,7 +224,6 @@ void GameSession::start_timers() { time_left.start(level->timelimit); - Ticks::pause_init(); } void @@ -240,10 +237,8 @@ GameSession::on_escape_press() } else if (!Menu::current()) { Menu::set_current(game_menu); game_menu->set_active_item(MNID_CONTINUE); - Ticks::pause_start(); game_pause = true; } else { - Ticks::pause_stop(); game_pause = false; } } @@ -257,7 +252,6 @@ GameSession::process_events() // end of pause mode? if(!Menu::current() && game_pause) { game_pause = false; - Ticks::pause_stop(); } if (end_sequence != NO_ENDSEQUENCE) { @@ -411,7 +405,7 @@ GameSession::check_end_conditions() } void -GameSession::action(float elapsed_time) +GameSession::update(float elapsed_time) { // handle controller if(main_controller->pressed(Controller::PAUSE_MENU)) @@ -420,7 +414,7 @@ GameSession::action(float elapsed_time) // advance timers if(!currentsector->player->growing_timer.started()) { // Update Tux and the World - currentsector->action(elapsed_time); + currentsector->update(elapsed_time); } // respawning in new sector? @@ -491,7 +485,7 @@ GameSession::process_menu() { Menu* menu = Menu::current(); if(menu) { - menu->action(); + menu->update(); if(menu == game_menu) { switch (game_menu->check()) { @@ -539,14 +533,19 @@ GameSession::run() if(!game_pause) global_time += elapsed_time; - skipdraw = false; - // regulate fps ticks = SDL_GetTicks(); if(ticks > fps_nextframe_ticks) { - // don't draw all frames when we're getting too slow - skipdraw = true; + if(skipdraw == true) { + // already skipped last frame? we have to slow down the game then... + skipdraw = false; + fps_nextframe_ticks -= (Uint32) (1000.0 / LOGICAL_FPS); + } else { + // don't draw all frames when we're getting too slow + skipdraw = true; + } } else { + skipdraw = false; while(fps_nextframe_ticks > ticks) { /* just wait */ // If we really have to wait long, then do an imprecise SDL_Delay() @@ -582,9 +581,9 @@ GameSession::run() // Update the world check_end_conditions(); if (end_sequence == ENDSEQUENCE_RUNNING) - action(elapsed_time/2); + update(elapsed_time/2); else if(end_sequence == NO_ENDSEQUENCE) - action(elapsed_time); + update(elapsed_time); } else { @@ -637,6 +636,12 @@ GameSession::run() } void +GameSession::finish() +{ + exit_status = ES_LEVEL_FINISHED; +} + +void GameSession::respawn(const std::string& sector, const std::string& spawnpoint) { newsector = sector; @@ -796,8 +801,7 @@ GameSession::drawresultscreen() context.do_drawing(); - SDL_Event event; - wait_for_event(event,2000,5000,true); + wait_for_event(2.0, 5.0); } std::string slotinfo(int slot) @@ -830,33 +834,32 @@ bool process_load_game_menu() { int slot = load_game_menu->check(); - if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION) - { - std::stringstream stream; - stream << slot; - std::string slotfile = user_dir + "/save/slot" + stream.str() + ".stsg"; + if(slot == -1) + return false; + + if(load_game_menu->get_item_by_id(slot).kind != MN_ACTION) + return false; + + std::stringstream stream; + stream << slot; + std::string slotfile = user_dir + "/save/slot" + stream.str() + ".stsg"; - fadeout(256); - DrawingContext context; - context.draw_text(white_text, "Loading...", - Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT/2), CENTER_ALLIGN, LAYER_FOREGROUND1); - context.do_drawing(); + fadeout(256); + DrawingContext context; + context.draw_text(white_text, "Loading...", + Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT/2), + CENTER_ALLIGN, LAYER_FOREGROUND1); + context.do_drawing(); - WorldMapNS::WorldMap worldmap; + WorldMapNS::WorldMap worldmap; - worldmap.set_map_filename("/levels/world1/worldmap.stwm"); - // Load the game or at least set the savegame_file variable - worldmap.loadgame(slotfile); + worldmap.set_map_filename("/levels/world1/worldmap.stwm"); + // Load the game or at least set the savegame_file variable + worldmap.loadgame(slotfile); - worldmap.display(); + worldmap.display(); - Menu::set_current(main_menu); + Menu::set_current(main_menu); - Ticks::pause_stop(); - return true; - } - else - { - return false; - } + return true; }