]> git.tdb.fi Git - libs/game.git/commitdiff
Add flags for declaring ordering between systems
authorMikko Rasa <tdb@tdb.fi>
Wed, 7 Dec 2022 09:56:51 +0000 (11:56 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 7 Dec 2022 09:57:15 +0000 (11:57 +0200)
source/game/system.h

index e3d71171c1e19aa8e31da854aa007737885774ce..8c9c8b1316428258c2c4e3f84858386a75f73a20 100644 (file)
@@ -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<typename T>
 inline void System::declare_dependency(DependencyFlags flags)
 {
-       if(!std::is_base_of_v<Component, T>)
+       if((flags&DATA_MASK) && !std::is_base_of_v<Component, T>)
+               throw std::invalid_argument("System::declare_dependency");
+       if((flags&ORDER_MASK) && !std::is_base_of_v<System, T>)
                throw std::invalid_argument("System::declare_dependency");
 
        const Reflection::ClassBase &type = stage.get_reflector().get_or_create_class<T>();
@@ -85,6 +91,8 @@ inline void System::declare_dependency(DependencyFlags flags)
 
        if(i!=dependencies.end())
                flags = static_cast<DependencyFlags>(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;