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