namespace Msp::Game {
+Director::Director():
+ event_source(event_bus)
+{ }
+
Stage &Director::create_stage()
{
stages.emplace_back(std::make_unique<Stage>());
+ event_source.emit<Events::StageCreated>(std::ref(*stages.back()));
return *stages.back();
}
+void Director::activate_stage(Stage &s)
+{
+ if(active_stage)
+ event_source.emit<Events::StageDeactivated>(std::ref(s));
+ active_stage = &s;
+ event_source.emit<Events::StageActivated>(std::ref(s));
+}
+
void Director::tick()
{
Time::TimeStamp now = Time::now();
#include <vector>
#include <msp/time/timedelta.h>
#include <msp/time/timestamp.h>
+#include "eventbus.h"
+#include "events.h"
+#include "eventsource.h"
namespace Msp::Game {
class Director
{
+public:
+ using EventSource = Game::EventSource<Events::StageCreated, Events::StageActivated, Events::StageDeactivated>;
+
private:
+ EventBus event_bus;
+ EventSource event_source;
std::vector<std::unique_ptr<Stage>> stages;
+ Stage *active_stage = nullptr;
Time::TimeStamp last_tick;
Time::TimeDelta stepsize = Time::sec/60;
Time::TimeDelta backlog;
unsigned max_backlog_steps = 600;
public:
+ Director();
Stage &create_stage();
+ void activate_stage(Stage &);
void tick();
};