X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fstage.cpp;h=3888410a43c8bc976034b753693b56ab35f16d72;hb=e4f03880d49bdbe0c7269be0f40f23b197bcea77;hp=43446bd9d8e7af9ba6d03f5fd13d9a49d2e72d42;hpb=a99b57a74252fd3de649d544d070b747f91fcf4d;p=libs%2Fgame.git diff --git a/source/game/stage.cpp b/source/game/stage.cpp index 43446bd..3888410 100644 --- a/source/game/stage.cpp +++ b/source/game/stage.cpp @@ -1,4 +1,6 @@ #include "stage.h" +#include +#include #include "accessguard.h" #include "camera.h" #include "root.h" @@ -13,7 +15,8 @@ Stage::Stage(Reflection::Reflector &f, DataFile::Collection &r): resources(r), event_source(event_bus), event_observer(event_bus), - root(std::make_unique(*this)) + root(std::make_unique(*this)), + scheduler(reflector) { event_observer.observe([this](auto &e){ if(!active_camera) @@ -28,7 +31,9 @@ Stage::~Stage() void Stage::remove_system(System &s) { + scheduler.remove_system(s); erase_if(systems, [&s](auto &p){ return p.get()==&s; }); + pending_reschedule = true; } void Stage::set_active_camera(Handle c) @@ -55,15 +60,29 @@ void Stage::synthesize_initial_events(Handle entity, EventObserver &targ void Stage::tick(Time::TimeDelta dt) { + if(pending_reschedule) + { + scheduler.schedule(); + pending_reschedule = false; + } + { #ifdef DEBUG - AccessGuard::BlockForScope _block;; + AccessGuard::BlockForScope _block; #endif - for(const auto &s: systems) - { - System::Activator act(*s); - s->tick(dt); - } + for(const SystemScheduler::Group &g: scheduler.get_groups()) + for(System *s: g.systems) + { + System::Activator act(*s); + try + { + s->tick(dt); + } + catch(const invalid_access &exc) + { + throw invalid_access(format("%s by %s", exc.what(), Debug::demangle(typeid(*s).name()))); + } + } } for(const auto &s: systems)