X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fstage.cpp;fp=source%2Fgame%2Fstage.cpp;h=3888410a43c8bc976034b753693b56ab35f16d72;hb=e4f03880d49bdbe0c7269be0f40f23b197bcea77;hp=7cad5bc250873b9e8c265ce3aacb617a9c8abcdb;hpb=423b49f2857f8e1597b652bfd41dbf3ae45f7ec5;p=libs%2Fgame.git diff --git a/source/game/stage.cpp b/source/game/stage.cpp index 7cad5bc..3888410 100644 --- a/source/game/stage.cpp +++ b/source/game/stage.cpp @@ -15,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) @@ -30,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) @@ -57,22 +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; #endif - for(const auto &s: systems) - { - System::Activator act(*s); - try - { - s->tick(dt); - } - catch(const invalid_access &exc) + for(const SystemScheduler::Group &g: scheduler.get_groups()) + for(System *s: g.systems) { - throw invalid_access(format("%s by %s", exc.what(), Debug::demangle(typeid(*s).name()))); + 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)