|
Grail (C++)
1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
3 #ifndef GRAIL_AI_ENTITY_H
4 #define GRAIL_AI_ENTITY_H
7 #include "Blackboard.hh"
8 #include "EntityToken.hh"
21 enum class ProcessingStatus
28 enum class RegistrationStatus
61 AIEntity(
const std::string& name =
"");
81 void SetReasoner(std::unique_ptr<Reasoner> newReasoner);
138 void AddSharedBlackboard(
const std::string& name, std::shared_ptr<Blackboard>& sharedBlackboard);
176 void SetId(
size_t id);
177 size_t GetId()
const;
178 const std::string& GetName()
const;
179 std::string GetCurrentBehaviorName()
const;
186 virtual void Update(
float deltaTime);
188 std::unique_ptr<Reasoner> reasoner;
189 std::map<std::string, std::shared_ptr<Blackboard>> sharedBlackboards{};
192 void SelectBehavior();
193 void ExecuteBehavior(
float deltaTime);
194 void SuspendPreviousBehavior();
195 void SetupNextBehavior(std::unique_ptr<Behavior> behavior);
197 bool ChangeProcessingStatus(ProcessingStatus newStatus);
198 ProcessingStatus GetProcessingStatus()
const;
200 bool ChangeRegistrationStatus(RegistrationStatus newStatus);
201 RegistrationStatus GetRegistrationStatus()
const;
206 inline static size_t nextEntityId = 0;
207 std::unique_ptr<Behavior> stagedBehavior =
nullptr;
208 std::unique_ptr<Behavior> currentBehavior =
nullptr;
209 std::unique_ptr<Behavior> suspendedBehavior =
nullptr;
211 mutable std::thread::id threadId{};
212 mutable bool isAcquired{
false};
213 mutable std::mutex entityUpdateMutex{};
214 mutable std::mutex entityAcquireMutex{};
215 mutable std::mutex behaviorMutex{};
216 mutable std::mutex stagingMutex{};
217 mutable std::mutex reasonerMutex{};
218 float entityDeltaTime{0.f};
219 std::vector<IReasonerChangeObserver*> reasonerChangeObservers{};
221 ProcessingStatus processingStatus = ProcessingStatus::FREE;
222 RegistrationStatus registrationStatus = RegistrationStatus::NOT_REGISTERED;
227 #endif //GRAIL_AI_ENTITY_H
AIEntity(const std::string &name="")
AIEntity - Constructs an AIEntity with the given name.
Definition: AIEntity.cpp:14
Blackboard & GetBlackboard()
GetBlackboard.
Definition: AIEntity.cpp:306
The AIEntity class - Defines a basic object which can execute behaviors.
Definition: AIEntity.hh:50
The AIManager class - Manages registered entities and shared blackboards.
Definition: AIManager.hh:32
void SetReasoner(std::unique_ptr< Reasoner > newReasoner)
SetReasoner.
Definition: AIEntity.cpp:28
The Reasoner class - Entity's "brain", assigns them behaviors chosen by user-defined algorithms.
Definition: Reasoner.hh:21
virtual void Update(float deltaTime)
Update - User defined method. Should in some way update entity's state.
Definition: AIEntity.cpp:141
Definition: GrailStateSnapshotGenerator.h:14
std::unique_ptr< Reasoner > TakeOwnershipOfReasoner()
GetCurrentReasoner.
Definition: AIEntity.cpp:63
std::unique_ptr< Behavior > MoveSuspendedBehavior()
GetPreviousBehavior.
Definition: AIEntity.cpp:58
The Blackboard class - grail's universal data container.
Definition: Blackboard.hh:15
void AddSharedBlackboard(const std::string &name, std::shared_ptr< Blackboard > &sharedBlackboard)
AddSharedBlackboard - Inserts pair of key and blackboard into container of shared blackboards.
Definition: AIEntity.cpp:117
const Behavior * GetCurrentBehavior() const
GetCurrentBehavior.
Definition: AIEntity.cpp:43
bool HasStagedBehavior() const
HasStagedBehavior - checks whether this entity has behavior awaiting its execution.
Definition: AIEntity.cpp:106
Definition: AIEntity.hh:38
A high-level abstraction of actions in the game.
Definition: Behavior.hh:22
void RemoveReasonerChangeObserver(IReasonerChangeObserver *observer)
RemoveReasonerChangeObserver - Removes a reasoner change observer so it won't be notified of reasoner...
Definition: AIEntity.cpp:314
std::unique_ptr< Behavior > GetUniqueCurrentBehavior()
GetUniqueCurrentBehavior.
Definition: AIEntity.cpp:53
Definition: EntityToken.hh:8
void StageBehavior(std::unique_ptr< Behavior > behavior)
StageBehavior - Finishes the current behavior and starts a new one.
Definition: AIEntity.cpp:74
static void ResetNextID(const size_t nextId=0)
ResetNextID - Resets taken entity IDs. Useful when a game has ended but entities were not destroyed,...
Definition: AIEntity.cpp:23
void RemoveSharedBlackboard(const std::string &name)
RemoveSharedBlackboard - Removes shared blackboard entry.
Definition: AIEntity.cpp:122
void AddReasonerChangeObserver(IReasonerChangeObserver *observer)
AddReasonerChangeObserver - Adds a reasoner change observer that will be notified via calling OnReaso...
Definition: AIEntity.cpp:309
std::shared_ptr< Blackboard > GetSharedBlackboard(const std::string &name) const
GetSharedBlackboard - Gets shared blackboard identified by given key.
Definition: AIEntity.cpp:131
bool HasActiveBehavior() const
HasActiveBehavior - Checks whether current behavior is not nullptr.
Definition: AIEntity.cpp:112