1 #ifndef GRAIL_AI_MANAGER_H
2 #define GRAIL_AI_MANAGER_H
5 #include "SynchronizedEntityContainer.h"
6 #include "EntityGroup.h"
12 #include <condition_variable>
28 virtual void OnEntityRemoved(
const AIManager& manager,
size_t entityId) = 0;
60 void RegisterAIEntity(
const std::shared_ptr<AIEntity>& entity,
int priority);
68 void RegisterAIEntity(
const std::shared_ptr<AIEntity>& entity,
const std::shared_ptr<AIEntity>& parent,
int priorityOffset = 1);
76 void RegisterEntityGroup(
const std::shared_ptr<EntityGroup>& entityGroup,
int priority);
77 void RemoveEntityGroup(
const std::shared_ptr<EntityGroup>& entityGroup);
79 bool ContainsEntity(
const AIEntity& entity)
const;
98 const std::vector<std::pair<std::shared_ptr<AIEntity>,
int>>& GetEntities()
const;
99 const std::vector<std::shared_ptr<EntityGroup>>& GetEntityGroups()
const;
100 const std::map<std::string, std::shared_ptr<Blackboard>>& GetSharedBlackboards()
const;
103 void RequestProcessingEntities();
104 void ThreadUpdate(std::size_t
id);
106 void RemoveEntities();
107 void RegisterEntity(
const std::shared_ptr<AIEntity>& entity,
int priority);
108 std::shared_ptr<EntityGroup>& RegisterEntityGroup(
const std::string& groupName,
110 const std::vector<std::pair<std::shared_ptr<AIEntity>,
int>>& entityPriorityPairs,
111 const std::map<std::string, std::shared_ptr<Blackboard>>& nameBlackboardPairs);
113 std::vector<std::pair<std::shared_ptr<AIEntity>,
int>> entities{};
114 std::set<const AIEntity*> entitiesToRemove{};
115 std::map<std::string, std::shared_ptr<Blackboard>> sharedBlackboards{};
118 std::atomic<bool> shouldTerminateWorkers = { 0 };
120 std::vector<std::thread> threads{};
121 std::mutex blackboardMutex{};
122 std::mutex entityRemovalMutex{};
124 size_t nextEntityId = 0;
125 size_t nextEntityGroupId = 0;
126 std::vector<std::shared_ptr<EntityGroup>> entityGroups{};
127 std::vector<IEntityChangeObserver*> entityChangeObservers{};
128 std::shared_ptr<EntityGroup> ungroupedEntities;
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:39
The AIManager class - Manages registered entities and shared blackboards.
Definition: AIManager.hh:35
void RemoveAIEntity(const AIEntity *entity)
RemoveAIEntity - Manager caches given entity. Later on all cached entities will be unregistered from ...
Definition: AIManager.cpp:166
void UpdateReasoners()
UpdateReasoners - Lets registered entities think by updating their reasoner.
Definition: AIManager.cpp:75
void RegisterAIEntity(const std::shared_ptr< AIEntity > &entity, int priority)
RegisterAIEntity - Manager registers entity with given priority.
Definition: AIManager.cpp:110
Blackboard & CreateBlackboard(const std::string &name)
CreateBlackboard - Constructs blackboard owned by this manager.
Definition: AIManager.cpp:245
void SubscribeToBlackboard(const std::string &blackboardName, AIEntity &entity)
SubscribeToBlackboard - Subscribed given entity to blackboard identified by blackboard name and owned...
Definition: AIManager.cpp:253
AIManager(std::size_t threadsNumber=0)
AIManager - Constructs manager and spawns worker threads defined by parameter. If threadsNumber equal...
Definition: AIManager.cpp:9
void UpdateEntities(float deltaTime)
UpdateEntities - Updates entities and their assigned behaviors.
Definition: AIManager.cpp:96
The Blackboard class - grail's universal data container.
Definition: Blackboard.hh:21
Definition: AIManager.hh:18
Definition: SynchronizedEntityContainer.h:13