From: Christoph Sommer Date: Mon, 16 Apr 2007 17:17:53 +0000 (+0000) Subject: Scripting scheduler is now paused while pause menu is shown X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=dd793c93ac07637402de084f20c0e17d57fb069e;p=supertux.git Scripting scheduler is now paused while pause menu is shown SVN-Revision: 4985 --- diff --git a/src/game_session.cpp b/src/game_session.cpp index 9a6565e16..b9b7510b7 100644 --- a/src/game_session.cpp +++ b/src/game_session.cpp @@ -73,6 +73,7 @@ #include "object/endsequence_walkleft.hpp" #include "object/endsequence_fireworks.hpp" #include "direction.hpp" +#include "scripting/time_scheduler.hpp" // the engine will be run with a logical framerate of 64fps. // We chose 64fps here because it is a power of 2, so 1/64 gives an "even" @@ -97,6 +98,7 @@ GameSession::GameSession(const std::string& levelfile_, Statistics* statistics) currentsector = NULL; game_pause = false; + Scripting::TimeScheduler::instance->set_pause(game_pause); statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png")); @@ -115,6 +117,7 @@ void GameSession::restart_level() { game_pause = false; + Scripting::TimeScheduler::instance->set_pause(game_pause); end_sequence = 0; main_controller->reset(); @@ -165,6 +168,11 @@ GameSession::~GameSession() delete playback_demo_stream; delete demo_controller; + if (game_pause) { + game_pause = false; + Scripting::TimeScheduler::instance->set_pause(game_pause); + } + current_ = NULL; } @@ -297,9 +305,11 @@ GameSession::toggle_pause() Menu::set_current(game_menu.get()); game_menu->set_active_item(MNID_CONTINUE); game_pause = true; + Scripting::TimeScheduler::instance->set_pause(game_pause); } else { Menu::set_current(NULL); game_pause = false; + Scripting::TimeScheduler::instance->set_pause(game_pause); } } @@ -339,6 +349,7 @@ 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? diff --git a/src/scripting/time_scheduler.cpp b/src/scripting/time_scheduler.cpp index d28308b2f..41a4d6f4b 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() +TimeScheduler::TimeScheduler() : paused(false), last_update(0), internal_time(0) { } @@ -42,7 +42,10 @@ TimeScheduler::~TimeScheduler() void TimeScheduler::update(float time) { - while(!schedule.empty() && schedule.front().wakeup_time < time) { + if (!paused) internal_time+=(time - last_update); + last_update = time; + + while(!schedule.empty() && schedule.front().wakeup_time < internal_time) { HSQOBJECT thread_ref = schedule.front().thread_ref; sq_pushobject(global_vm, thread_ref); @@ -88,7 +91,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; + entry.wakeup_time = time - (last_update - internal_time); sq_addref(global_vm, & entry.thread_ref); sq_pop(global_vm, 2); @@ -97,4 +100,10 @@ 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 d26cb763b..c431f14e8 100644 --- a/src/scripting/time_scheduler.hpp +++ b/src/scripting/time_scheduler.hpp @@ -41,6 +41,8 @@ public: static TimeScheduler* instance; + void set_pause(bool paused); + private: struct ScheduleEntry { /// weak reference to the squirrel vm object @@ -57,6 +59,9 @@ private: typedef std::vector ScheduleHeap; ScheduleHeap schedule; + bool paused; + float last_update; + float internal_time; }; }