GlPortal Class Reference  0.1.1
Source code documentation of the free and open 3D action puzzle game.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
System.hpp
Go to the documentation of this file.
1 #ifndef RADIX_SYSTEM_HPP
2 #define RADIX_SYSTEM_HPP
3 
4 #include <type_traits>
5 
7 
8 namespace radix {
9 
10 using SystemTypeId = std::size_t;
11 
13 
15 template<typename T> struct _SystemTypeId { static SystemTypeId id; };
16 template<typename T> SystemTypeId _SystemTypeId<T>::id { getNewSystemTypeId() };
19 class World;
20 
21 class System {
22 protected:
24 
25 public:
27 
31  template<typename T> inline static TypeId getTypeId() {
32  static_assert(std::is_base_of<System, T>::value, "T must be a System");
33  return _SystemTypeId<typename std::remove_cv<T>::type>::id;
34  }
35 
36  System(World &w) : world(w) {}
37 
38  virtual const char* getName() const = 0;
39  virtual TypeId getTypeId() const = 0;
40  virtual bool runsBefore(const System&) { return false; }
41  virtual bool runsAfter(const System&) { return false; }
42  virtual void update(TDelta dtime) = 0;
43 };
44 
46  static SystemTypeId lastId(0);
47  return lastId++;
48 }
49 
50 }
51 
52 #endif /* RADIX_SYSTEM_HPP */
virtual bool runsBefore(const System &)
Definition: System.hpp:40
virtual void update(TDelta dtime)=0
Definition: GameController.hpp:7
Definition: System.hpp:21
System(World &w)
Definition: System.hpp:36
std::size_t SystemTypeId
Definition: System.hpp:10
World & world
Definition: System.hpp:23
Definition: TimeDelta.hpp:8
virtual bool runsAfter(const System &)
Definition: System.hpp:41
SystemTypeId getNewSystemTypeId()
Definition: System.hpp:45
SystemTypeId TypeId
Definition: System.hpp:26
Definition: World.hpp:32
virtual const char * getName() const =0
static TypeId getTypeId()
Gets a component's type ID.
Definition: System.hpp:31