Nazara Engine  0.4
A fast, complete, cross-platform API designed for game development
EntityList.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_ENTITYLIST_HPP
8 #define NDK_ENTITYLIST_HPP
9 
10 #include <Nazara/Core/Bitset.hpp>
11 #include <NDK/Prerequesites.hpp>
12 #include <NDK/Entity.hpp>
13 
14 namespace Ndk
15 {
16  class NDK_API EntityList
17  {
18  friend Entity;
19 
20  public:
21  class iterator;
22  friend iterator;
23  using size_type = std::size_t;
24 
25  inline EntityList();
26  inline EntityList(const EntityList& entityList);
27  inline EntityList(EntityList&& entityList) noexcept;
28  inline ~EntityList();
29 
30  inline void Clear();
31 
32  inline bool Has(const Entity* entity) const;
33  inline bool Has(EntityId entity) const;
34 
35  inline void Insert(Entity* entity);
36 
37  inline void Remove(Entity* entity);
38  inline void Reserve(std::size_t entityCount);
39 
40  // STL API
41  inline iterator begin() const;
42  inline bool empty() const;
43  inline iterator end() const;
44  inline size_type size() const;
45 
46  inline EntityList& operator=(const EntityList& entityList);
47  inline EntityList& operator=(EntityList&& entityList) noexcept;
48 
49  private:
50  inline std::size_t FindNext(std::size_t currentId) const;
51  inline World* GetWorld() const;
52  inline void NotifyEntityDestruction(const Entity* entity);
53 
54  Nz::Bitset<Nz::UInt64> m_entityBits;
55  World* m_world;
56  };
57 
58  class NDK_API EntityList::iterator : public std::iterator<std::forward_iterator_tag, const EntityHandle>
59  {
60  friend EntityList;
61 
62  public:
63  inline iterator(const iterator& it);
64 
65  const EntityHandle& operator*() const;
66 
67  inline iterator& operator=(const iterator& it);
68  inline iterator& operator++();
69  inline iterator operator++(int);
70 
71  friend inline bool operator==(const iterator& lhs, const iterator& rhs);
72  friend inline bool operator!=(const iterator& lhs, const iterator& rhs);
73 
74  friend inline void swap(iterator& lhs, iterator& rhs);
75 
76  private:
77  inline iterator(const EntityList* world, std::size_t nextId);
78 
79  std::size_t m_nextEntityId;
80  const EntityList* m_list;
81  };
82 }
83 
84 #include <NDK/EntityList.inl>
85 
86 #endif // NDK_ENTITYLIST_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 a set of entities to help performing batch operations.
Definition: EntityList.hpp:16
NDK class that represents a world.
Definition: World.hpp:25