From: Mikko Rasa Date: Tue, 25 Oct 2022 21:16:04 +0000 (+0300) Subject: Add stage activation and events X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=f90804b7a1042a1266cbe3075631e4fcc18b9a8a;p=libs%2Fgame.git Add stage activation and events --- diff --git a/source/game/director.cpp b/source/game/director.cpp index 741965b..28d86e7 100644 --- a/source/game/director.cpp +++ b/source/game/director.cpp @@ -7,12 +7,25 @@ using namespace std; namespace Msp::Game { +Director::Director(): + event_source(event_bus) +{ } + Stage &Director::create_stage() { stages.emplace_back(std::make_unique()); + event_source.emit(std::ref(*stages.back())); return *stages.back(); } +void Director::activate_stage(Stage &s) +{ + if(active_stage) + event_source.emit(std::ref(s)); + active_stage = &s; + event_source.emit(std::ref(s)); +} + void Director::tick() { Time::TimeStamp now = Time::now(); diff --git a/source/game/director.h b/source/game/director.h index 24ef634..9d221b0 100644 --- a/source/game/director.h +++ b/source/game/director.h @@ -5,6 +5,9 @@ #include #include #include +#include "eventbus.h" +#include "events.h" +#include "eventsource.h" namespace Msp::Game { @@ -12,8 +15,14 @@ class Stage; class Director { +public: + using EventSource = Game::EventSource; + private: + EventBus event_bus; + EventSource event_source; std::vector> stages; + Stage *active_stage = nullptr; Time::TimeStamp last_tick; Time::TimeDelta stepsize = Time::sec/60; Time::TimeDelta backlog; @@ -21,7 +30,9 @@ private: unsigned max_backlog_steps = 600; public: + Director(); Stage &create_stage(); + void activate_stage(Stage &); void tick(); }; diff --git a/source/game/events.h b/source/game/events.h index 15988e5..98a6ff0 100644 --- a/source/game/events.h +++ b/source/game/events.h @@ -7,6 +7,7 @@ namespace Msp::Game { class Component; class Entity; +class Stage; namespace Events { @@ -30,6 +31,21 @@ struct ComponentDestroyed Handle component; }; +struct StageCreated +{ + Stage &stage; +}; + +struct StageActivated +{ + Stage &stage; +}; + +struct StageDeactivated +{ + Stage &stage; +}; + } // namespace Events } // namespace Msp::Game