X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fsystem.h;h=4d39e301762d2981ce629c8ce51676a1370fe810;hb=12c863fc1bc5456a4b3aceacc88904d76bd1d8bb;hp=e3d71171c1e19aa8e31da854aa007737885774ce;hpb=ffbfe95f51058c4de3c898b1a02e2fadba2b8134;p=libs%2Fgame.git diff --git a/source/game/system.h b/source/game/system.h index e3d7117..4d39e30 100644 --- a/source/game/system.h +++ b/source/game/system.h @@ -5,12 +5,13 @@ #include #include "accessguard.h" #include "component.h" +#include "mspgame_api.h" #include "reflection.h" #include "stage.h" namespace Msp::Game { -class System +class MSPGAME_API System { public: enum DependencyFlags @@ -20,11 +21,18 @@ public: READ_FRESH = 3, WRITE = 4, UPDATE = READ_OLD | WRITE, - CHAINED_UPDATE = READ_FRESH | WRITE + CHAINED_UPDATE = READ_FRESH | WRITE, + DATA_MASK = 7, + RUN_BEFORE = 8, + RUN_AFTER = 16, + ORDER_MASK = 24 }; - struct Dependency + class Dependency { + friend class System; + + private: DependencyFlags flags = NO_DEPENDENCY; const Reflection::ClassBase &type; void (*prepare)(Stage &) = nullptr; @@ -32,7 +40,11 @@ public: void (*unblock)(DependencyFlags) = nullptr; void (*block)(DependencyFlags) = nullptr; + public: Dependency(const Reflection::ClassBase &t): type(t) { } + + DependencyFlags get_flags() const { return flags; } + const Reflection::ClassBase &get_type() const { return type; } }; class Activator: public NonCopyable @@ -63,6 +75,8 @@ protected: void declare_dependency(DependencyFlags); public: + const std::vector &get_dependencies() const { return dependencies; } + void begin_tick(); virtual void tick(Time::TimeDelta) = 0; void end_tick(); @@ -77,7 +91,9 @@ protected: template inline void System::declare_dependency(DependencyFlags flags) { - if(!std::is_base_of_v) + if((flags&DATA_MASK) && !std::is_base_of_v) + throw std::invalid_argument("System::declare_dependency"); + if((flags&ORDER_MASK) && !std::is_base_of_v) throw std::invalid_argument("System::declare_dependency"); const Reflection::ClassBase &type = stage.get_reflector().get_or_create_class(); @@ -85,6 +101,8 @@ inline void System::declare_dependency(DependencyFlags flags) if(i!=dependencies.end()) flags = static_cast(flags|i->flags); + if((flags&RUN_BEFORE) && (flags&RUN_AFTER)) + throw std::logic_error("conflicting order flags"); Dependency &dep = (i!=dependencies.end() ? *i : dependencies.emplace_back(type)); dep.flags = flags;