#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"
currentsector = NULL;
game_pause = false;
+ Scripting::TimeScheduler::instance->set_pause(game_pause);
statistics_backdrop.reset(new Surface("images/engine/menu/score-backdrop.png"));
GameSession::restart_level()
{
game_pause = false;
+ Scripting::TimeScheduler::instance->set_pause(game_pause);
end_sequence = 0;
main_controller->reset();
delete playback_demo_stream;
delete demo_controller;
+ if (game_pause) {
+ game_pause = false;
+ Scripting::TimeScheduler::instance->set_pause(game_pause);
+ }
+
current_ = NULL;
}
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);
}
}
// end of pause mode?
if(!Menu::current() && game_pause) {
game_pause = false;
+ Scripting::TimeScheduler::instance->set_pause(game_pause);
}
// playback a demo?
TimeScheduler* TimeScheduler::instance = NULL;
-TimeScheduler::TimeScheduler()
+TimeScheduler::TimeScheduler() : paused(false), last_update(0), internal_time(0)
{
}
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);
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);
std::push_heap(schedule.begin(), schedule.end());
}
+void
+TimeScheduler::set_pause(bool paused)
+{
+ this->paused = paused;
+}
+
}
static TimeScheduler* instance;
+ void set_pause(bool paused);
+
private:
struct ScheduleEntry {
/// weak reference to the squirrel vm object
typedef std::vector<ScheduleEntry> ScheduleHeap;
ScheduleHeap schedule;
+ bool paused;
+ float last_update;
+ float internal_time;
};
}