]> git.tdb.fi Git - libs/game.git/blob - source/game/systemscheduler.h
Decorate things which constitute the public API of the library
[libs/game.git] / source / game / systemscheduler.h
1 #ifndef MSP_GAME_SYSTEMSCHEDULER_H_
2 #define MSP_GAME_SYSTEMSCHEDULER_H_
3
4 #include <vector>
5 #include "mspgame_api.h"
6 #include "reflection.h"
7
8 namespace Msp::Game {
9
10 class System;
11
12 class MSPGAME_API scheduling_error: public std::logic_error
13 {
14 public:
15         scheduling_error(const std::string &w): logic_error(w) { }
16 };
17
18 class MSPGAME_API SystemScheduler
19 {
20 public:
21         struct Group
22         {
23                 std::vector<System *> systems;
24         };
25
26 private:
27         struct GraphNode
28         {
29                 System *system = nullptr;
30                 Reflection::ClassBase *type = nullptr;
31                 std::vector<GraphNode *> predecessors;
32                 unsigned scheduled_order = 0;
33         };
34
35         Reflection::Reflector &reflector;
36         std::vector<GraphNode> nodes;
37         std::vector<Group> groups;
38
39 public:
40         SystemScheduler(Reflection::Reflector &);
41
42         void add_system(System &);
43         void remove_system(System &);
44         void schedule();
45 private:
46         static int get_order(const GraphNode &, const GraphNode &);
47         static int get_explicit_order(const GraphNode &, const GraphNode &);
48         static int get_data_order(const GraphNode &, const GraphNode &);
49 public:
50         const std::vector<Group> &get_groups() const { return groups; }
51 };
52
53 } // namespace Msp::Game
54
55 #endif