X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgame%2Fsystemscheduler.h;fp=source%2Fgame%2Fsystemscheduler.h;h=2ab4804f6293d080a7962c1fc3ffb891ea3ad2df;hb=e4f03880d49bdbe0c7269be0f40f23b197bcea77;hp=0000000000000000000000000000000000000000;hpb=423b49f2857f8e1597b652bfd41dbf3ae45f7ec5;p=libs%2Fgame.git diff --git a/source/game/systemscheduler.h b/source/game/systemscheduler.h new file mode 100644 index 0000000..2ab4804 --- /dev/null +++ b/source/game/systemscheduler.h @@ -0,0 +1,54 @@ +#ifndef MSP_GAME_SYSTEMSCHEDULER_H_ +#define MSP_GAME_SYSTEMSCHEDULER_H_ + +#include +#include "reflection.h" + +namespace Msp::Game { + +class System; + +class scheduling_error: public std::logic_error +{ +public: + scheduling_error(const std::string &w): logic_error(w) { } +}; + +class SystemScheduler +{ +public: + struct Group + { + std::vector systems; + }; + +private: + struct GraphNode + { + System *system = nullptr; + Reflection::ClassBase *type = nullptr; + std::vector predecessors; + unsigned scheduled_order = 0; + }; + + Reflection::Reflector &reflector; + std::vector nodes; + std::vector groups; + +public: + SystemScheduler(Reflection::Reflector &); + + void add_system(System &); + void remove_system(System &); + void schedule(); +private: + static int get_order(const GraphNode &, const GraphNode &); + static int get_explicit_order(const GraphNode &, const GraphNode &); + static int get_data_order(const GraphNode &, const GraphNode &); +public: + const std::vector &get_groups() const { return groups; } +}; + +} // namespace Msp::Game + +#endif