From: Mikko Rasa Date: Wed, 7 Dec 2022 09:56:51 +0000 (+0200) Subject: Add flags for declaring ordering between systems X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=423b49f2857f8e1597b652bfd41dbf3ae45f7ec5;p=libs%2Fgame.git Add flags for declaring ordering between systems --- diff --git a/source/game/system.h b/source/game/system.h index e3d7117..8c9c8b1 100644 --- a/source/game/system.h +++ b/source/game/system.h @@ -20,7 +20,11 @@ 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 @@ -77,7 +81,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 +91,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;