Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
BaseSystem.hpp
1 // Copyright (C) 2017 Jérôme Leclercq
2 // This file is part of the "Nazara Development Kit"
3 // For conditions of distribution and use, see copyright notice in Prerequesites.hpp
4 
5 #pragma once
6 
7 #ifndef NDK_BASESYSTEM_HPP
8 #define NDK_BASESYSTEM_HPP
9 
10 #include <Nazara/Core/Bitset.hpp>
11 #include <NDK/EntityList.hpp>
12 
13 namespace Ndk
14 {
15  class World;
16 
17  class NDK_API BaseSystem
18  {
19  friend class Sdk;
20  friend Entity;
21  friend World;
22 
23  public:
24  inline BaseSystem(SystemIndex systemId);
25  BaseSystem(const BaseSystem&) = delete;
26  BaseSystem(BaseSystem&&) noexcept = default;
27  virtual ~BaseSystem();
28 
29  inline void Enable(bool enable = true);
30 
31  bool Filters(const Entity* entity) const;
32 
33  inline const EntityList& GetEntities() const;
34  inline float GetFixedUpdateRate() const;
35  inline SystemIndex GetIndex() const;
36  inline float GetMaximumUpdateRate() const;
37  inline int GetUpdateOrder() const;
38  inline World& GetWorld() const;
39 
40  inline bool IsEnabled() const;
41 
42  inline bool HasEntity(const Entity* entity) const;
43 
44  inline void SetFixedUpdateRate(float updatePerSecond);
45  inline void SetMaximumUpdateRate(float updatePerSecond);
46  void SetUpdateOrder(int updateOrder);
47 
48  inline void Update(float elapsedTime);
49 
50  BaseSystem& operator=(const BaseSystem&) = delete;
51  BaseSystem& operator=(BaseSystem&&) noexcept = default;
52 
53  protected:
54  template<typename ComponentType> void Excludes();
55  template<typename ComponentType1, typename ComponentType2, typename... Rest> void Excludes();
56  inline void ExcludesComponent(ComponentIndex index);
57 
58  static SystemIndex GetNextIndex();
59 
60  template<typename ComponentType> void Requires();
61  template<typename ComponentType1, typename ComponentType2, typename... Rest> void Requires();
62  inline void RequiresComponent(ComponentIndex index);
63 
64  template<typename ComponentType> void RequiresAny();
65  template<typename ComponentType1, typename ComponentType2, typename... Rest> void RequiresAny();
66  inline void RequiresAnyComponent(ComponentIndex index);
67 
68  virtual void OnUpdate(float elapsedTime) = 0;
69 
70  private:
71  inline void AddEntity(Entity* entity);
72 
73  virtual void OnEntityAdded(Entity* entity);
74  virtual void OnEntityRemoved(Entity* entity);
75  virtual void OnEntityValidation(Entity* entity, bool justAdded);
76 
77  inline void RemoveEntity(Entity* entity);
78 
79  inline void SetWorld(World* world) noexcept;
80 
81  inline void ValidateEntity(Entity* entity, bool justAdded);
82 
83  static inline bool Initialize();
84  static inline void Uninitialize();
85 
86  Nz::Bitset<> m_excludedComponents;
87  mutable Nz::Bitset<> m_filterResult;
88  Nz::Bitset<> m_requiredAnyComponents;
89  Nz::Bitset<> m_requiredComponents;
90  EntityList m_entities;
91  SystemIndex m_systemIndex;
92  World* m_world;
93  bool m_updateEnabled;
94  float m_fixedUpdateRate;
95  float m_maxUpdateRate;
96  float m_updateCounter;
97  int m_updateOrder;
98 
99  static SystemIndex s_nextIndex;
100  };
101 }
102 
103 #include <NDK/BaseSystem.inl>
104 
105 #endif // NDK_BASESYSTEM_HPP
TODO: For now is unable to display different color in the history, it needs a RichTextDrawer to do so...
Definition: Algorithm.hpp:12
NDK class that represents an entity in a world.
Definition: Entity.hpp:28
NDK class that represents the software development kit, a set of tools made to ease the conception of...
Definition: Sdk.hpp:14
NDK class that represents the common base of all systems.
Definition: BaseSystem.hpp:17
NDK class that represents a set of entities to help performing batch operations.
Definition: EntityList.hpp:16
NDK class that represents a world.
Definition: World.hpp:25
Core class that represents a set of bits.
Definition: Bitset.hpp:22