|
Grail (C++)
1.3.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);
136 void AddSharedBlackboard(
const std::string& name, std::shared_ptr<Blackboard>& sharedBlackboard);
174 void SetId(
size_t id);
175 size_t GetId()
const;
176 const std::string& GetName()
const;
177 std::string GetCurrentBehaviorName()
const;
184 virtual void Update(
float deltaTime);
186 std::unique_ptr<Reasoner> reasoner;
187 std::map<std::string, std::shared_ptr<Blackboard>> sharedBlackboards{};
190 void SelectBehavior();
191 void ExecuteBehavior(
float deltaTime);
192 void SuspendPreviousBehavior();
193 void SetupNextBehavior(std::unique_ptr<Behavior> behavior);
195 bool ChangeProcessingStatus(ProcessingStatus newStatus);
196 ProcessingStatus GetProcessingStatus()
const;
198 bool ChangeRegistrationStatus(RegistrationStatus newStatus);
199 RegistrationStatus GetRegistrationStatus()
const;
205 inline static size_t nextEntityId = 0;
206 std::unique_ptr<Behavior> stagedBehavior =
nullptr;
207 std::unique_ptr<Behavior> currentBehavior =
nullptr;
208 std::unique_ptr<Behavior> suspendedBehavior =
nullptr;
210 mutable std::thread::id threadId{};
211 mutable bool isAcquired{
false};
212 mutable std::mutex entityUpdateMutex{};
213 mutable std::mutex entityAcquireMutex{};
214 mutable std::mutex behaviorMutex{};
215 mutable std::mutex stagingMutex{};
216 float entityDeltaTime{0.f};
217 std::vector<IReasonerChangeObserver*> reasonerChangeObservers{};
219 ProcessingStatus processingStatus = ProcessingStatus::FREE;
220 RegistrationStatus registrationStatus = RegistrationStatus::NOT_REGISTERED;
225 #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:288
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:129
Definition: GrailStateSnapshotGenerator.h:14
std::unique_ptr< Behavior > MoveSuspendedBehavior()
GetPreviousBehavior.
Definition: AIEntity.cpp:52
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:105
const Behavior * GetCurrentBehavior() const
GetCurrentBehavior.
Definition: AIEntity.cpp:37
bool HasStagedBehavior() const
HasStagedBehavior - checks whether this entity has behavior awaiting its execution.
Definition: AIEntity.cpp:94
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:296
std::unique_ptr< Behavior > GetUniqueCurrentBehavior()
GetUniqueCurrentBehavior.
Definition: AIEntity.cpp:47
Definition: EntityToken.hh:8
void StageBehavior(std::unique_ptr< Behavior > behavior)
StageBehavior - Finishes the current behavior and starts a new one.
Definition: AIEntity.cpp:62
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:110
void AddReasonerChangeObserver(IReasonerChangeObserver *observer)
AddReasonerChangeObserver - Adds a reasoner change observer that will be notified via calling OnReaso...
Definition: AIEntity.cpp:291
std::shared_ptr< Blackboard > GetSharedBlackboard(const std::string &name) const
GetSharedBlackboard - Gets shared blackboard identified by given key.
Definition: AIEntity.cpp:119
std::unique_ptr< Reasoner > & GetCurrentReasoner()
GetCurrentReasoner.
Definition: AIEntity.cpp:57
bool HasActiveBehavior() const
HasActiveBehavior - Checks whether current behavior is not nullptr.
Definition: AIEntity.cpp:100