#include "stage.h"
+#include <msp/debug/demangle.h>
+#include <msp/strings/format.h>
#include "accessguard.h"
#include "camera.h"
#include "root.h"
resources(r),
event_source(event_bus),
event_observer(event_bus),
- root(std::make_unique<Root>(*this))
+ root(std::make_unique<Root>(*this)),
+ scheduler(reflector)
{
event_observer.observe<Events::ComponentCreated>([this](auto &e){
if(!active_camera)
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<Camera> c)
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)
- 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)