Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
SynchronizedEntityContainer.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SYNCHRONIZED_ENTITY_CONTAINER_H
4 #define GRAIL_SYNCHRONIZED_ENTITY_CONTAINER_H
5 
6 #include <map>
7 #include <mutex>
8 #include <set>
9 #include "AIEntity.hh"
10 
11 namespace grail
12 {
13  class AIEntity;
14 
16  {
17  public:
19 
22 
23  SynchronizedEntityContainer& operator =(const SynchronizedEntityContainer&) = delete;
25  const std::pair<std::shared_ptr<AIEntity>, int> operator [](std::size_t index);
26 
27  void SetData(const std::vector<std::pair<std::shared_ptr<AIEntity>, int>>& newData);
28  std::size_t Size();
29  void MarkDone(std::size_t index);
30  ProcessingStatus GetStatus(std::size_t index);
31  bool IsDone();
32  bool IsEntityPriorityValid(std::size_t index);
33  int GetCurrentPriority();
34 
35  private:
36  void SetNextPriority();
37  void MarkDoneNonBlocking(std::size_t index);
38 
39  std::vector<std::pair<std::shared_ptr<AIEntity>, int>> data{};
40  std::size_t dataDone{};
41  std::size_t priorityDone{};
42  std::mutex mutex{};
43 
44  int lowestPriority = {std::numeric_limits<int>::max()};
45  int highestPriority = {std::numeric_limits<int>::min()};
46  int currentPriority = {0};
47  std::map<int, std::size_t> entitiesPerPriority{};
48  };
49 }
50 
51 #endif //GRAIL_SYNCHRONIZED_ENTITY_CONTAINER_H
grail::SynchronizedEntityContainer
Definition: SynchronizedEntityContainer.h:15