From: Matthias Braun Date: Mon, 16 Apr 2007 18:39:00 +0000 (+0000) Subject: make game_session do main_loop->set_speed(0) on pause, reverted TimeScheduler changes X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9d05abe97c11bec660967594ca889f89338ab343;p=supertux.git make game_session do main_loop->set_speed(0) on pause, reverted TimeScheduler changes SVN-Revision: 4989 --- diff --git a/src/game_session.cpp b/src/game_session.cpp index b9b7510b7..e966fbc3c 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -98,7 +98,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) currentsector = NULL; game_pause = false; - Scripting::TimeScheduler::instance->set_pause(game_pause); + speed_before_pause = main_loop->get_speed(); statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png")); @@ -117,7 +117,6 @@ void GameSession::restart_level() { game_pause = false; - Scripting::TimeScheduler::instance->set_pause(game_pause); end_sequence = 0; main_controller->reset(); @@ -168,11 +167,6 @@ GameSession::~GameSession() delete playback_demo_stream; delete demo_controller; - if (game_pause) { - game_pause = false; - Scripting::TimeScheduler::instance->set_pause(game_pause); - } - current_ = NULL; } @@ -285,7 +279,9 @@ GameSession::on_escape_press() if(currentsector->player->is_dying() || end_sequence) { // Let the timers run out, we fast-forward them to force past a sequence - if (end_sequence) end_sequence->stop(); + if (end_sequence) + end_sequence->stop(); + currentsector->player->dying_timer.start(FLT_EPSILON); return; // don't let the player open the menu, when he is dying } @@ -301,15 +297,16 @@ GameSession::on_escape_press() void GameSession::toggle_pause() { - if(Menu::current() == NULL) { + if(!game_pause) { + speed_before_pause = main_loop->get_speed(); + main_loop->set_speed(0); Menu::set_current(game_menu.get()); game_menu->set_active_item(MNID_CONTINUE); game_pause = true; - Scripting::TimeScheduler::instance->set_pause(game_pause); } else { + main_loop->set_speed(speed_before_pause); Menu::set_current(NULL); game_pause = false; - Scripting::TimeScheduler::instance->set_pause(game_pause); } } @@ -349,7 +346,6 @@ GameSession::process_events() // end of pause mode? if(!Menu::current() && game_pause) { game_pause = false; - Scripting::TimeScheduler::instance->set_pause(game_pause); } // playback a demo? @@ -489,9 +485,9 @@ GameSession::update(float elapsed_time) currentsector->update(elapsed_time); } else { if (!end_sequence->is_tux_stopped()) { - currentsector->update(elapsed_time/2); + currentsector->update(elapsed_time); } else { - end_sequence->update(elapsed_time/2); + end_sequence->update(elapsed_time); } } } @@ -599,39 +595,25 @@ GameSession::start_sequence(const std::string& sequencename) } // abort if a sequence is already playing - if (end_sequence) return; + if (end_sequence) + return; if (sequencename == "endsequence") { - - // Determine walking direction for Tux - /*float xst = 1.f, xend = 2.f; - for(std::vector::iterator i = currentsector->gameobjects.begin(); i != currentsector->gameobjects.end(); i++) { - SequenceTrigger* st = dynamic_cast(*i); - if(!st) - continue; - if(st->get_sequence_name() == "stoptux") - xend = st->get_pos().x; - else if(st->get_sequence_name() == "endsequence") - xst = st->get_pos().y; - } - - if (xst > xend) { - end_sequence = new EndSequenceWalkLeft(); - } else { - end_sequence = new EndSequenceWalkRight(); - }*/ if (currentsector->get_players()[0]->physic.get_velocity_x() < 0) { end_sequence = new EndSequenceWalkLeft(); } else { end_sequence = new EndSequenceWalkRight(); } - } - else if (sequencename == "fireworks") end_sequence = new EndSequenceFireworks(); - else { + } else if (sequencename == "fireworks") { + end_sequence = new EndSequenceFireworks(); + } else { log_warning << "Unknown sequence '" << sequencename << "'. Ignoring." << std::endl; return; } + /* slow down the game for end-sequence */ + main_loop->set_speed(0.5f); + currentsector->add_object(end_sequence); end_sequence->start(); diff --git a/src/game_session.hpp b/src/game_session.hpp index ae2a80ae2..fdb8f4f96 100644 --- a/src/game_session.hpp +++ b/src/game_session.hpp @@ -114,7 +114,8 @@ private: EndSequence* end_sequence; - bool game_pause; + bool game_pause; + float speed_before_pause; std::string levelfile; diff --git a/src/mainloop.cpp b/src/mainloop.cpp index 0a2daebde..314de1576 100644 --- a/src/mainloop.cpp +++ b/src/mainloop.cpp @@ -109,6 +109,12 @@ MainLoop::set_speed(float speed) this->speed = speed; } +float +MainLoop::get_speed() const +{ + return speed; +} + void MainLoop::draw_fps(DrawingContext& context, float fps_fps) { diff --git a/src/mainloop.hpp b/src/mainloop.hpp index 244c63f9f..e9fa1a11a 100644 --- a/src/mainloop.hpp +++ b/src/mainloop.hpp @@ -38,6 +38,7 @@ public: void exit_screen(ScreenFade* fade = NULL); void quit(ScreenFade* fade = NULL); void set_speed(float speed); + float get_speed() const; /** * requests that a screenshot be taken after the next frame has been rendered diff --git a/src/scripting/time_scheduler.cpp b/src/scripting/time_scheduler.cpp index 41a4d6f4b..d28308b2f 100644 --- a/src/scripting/time_scheduler.cpp +++ b/src/scripting/time_scheduler.cpp @@ -31,7 +31,7 @@ namespace Scripting TimeScheduler* TimeScheduler::instance = NULL; -TimeScheduler::TimeScheduler() : paused(false), last_update(0), internal_time(0) +TimeScheduler::TimeScheduler() { } @@ -42,10 +42,7 @@ TimeScheduler::~TimeScheduler() void TimeScheduler::update(float time) { - if (!paused) internal_time+=(time - last_update); - last_update = time; - - while(!schedule.empty() && schedule.front().wakeup_time < internal_time) { + while(!schedule.empty() && schedule.front().wakeup_time < time) { HSQOBJECT thread_ref = schedule.front().thread_ref; sq_pushobject(global_vm, thread_ref); @@ -91,7 +88,7 @@ TimeScheduler::schedule_thread(HSQUIRRELVM scheduled_vm, float time) sq_pop(global_vm, 2); throw SquirrelError(global_vm, "Couldn't get thread weakref from vm"); } - entry.wakeup_time = time - (last_update - internal_time); + entry.wakeup_time = time; sq_addref(global_vm, & entry.thread_ref); sq_pop(global_vm, 2); @@ -100,10 +97,4 @@ TimeScheduler::schedule_thread(HSQUIRRELVM scheduled_vm, float time) std::push_heap(schedule.begin(), schedule.end()); } -void -TimeScheduler::set_pause(bool paused) -{ - this->paused = paused; -} - } diff --git a/src/scripting/time_scheduler.hpp b/src/scripting/time_scheduler.hpp index c431f14e8..d26cb763b 100644 --- a/src/scripting/time_scheduler.hpp +++ b/src/scripting/time_scheduler.hpp @@ -41,8 +41,6 @@ public: static TimeScheduler* instance; - void set_pause(bool paused); - private: struct ScheduleEntry { /// weak reference to the squirrel vm object @@ -59,9 +57,6 @@ private: typedef std::vector ScheduleHeap; ScheduleHeap schedule; - bool paused; - float last_update; - float internal_time; }; }