Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
AIEntity.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31#pragma once
32#ifndef DVD_AI_ENTITY_H_
33#define DVD_AI_ENTITY_H_
34
36
37struct dtCrowdAgent;
38
39namespace Divide {
40
41class SceneGraphNode;
42
43class NPC;
44namespace AI {
45class AITeam;
46class AIProcessor;
47class Order;
48enum class AIMsg : U8;
49
50namespace Navigation {
51 class DivideRecast;
52 class DivideDtCrowd;
53}
54
55namespace Attorney {
56 class AIEntityAITeam;
57}
58
60class AIEntity final : public GUIDWrapper {
62 public:
63 enum class PresetAgentRadius : U8 {
68 COUNT
69 };
70
71 AIEntity( NPC* parent, const vec3<F32>& currentPosition, std::string_view name);
72 ~AIEntity() override;
73
74 void load( const vec3<F32>& currentPosition );
75 void unload();
76
77 [[nodiscard]] bool addSensor(SensorType type);
78 [[nodiscard]] bool setAndSurrenderAIProcessor(AIProcessor* processor);
79
80 void sendMessage(AIEntity& receiver, AIMsg msg, const std::any& msg_content);
81 void receiveMessage(AIEntity& sender, AIMsg msg, const std::any& msg_content);
82 void processMessage(AIEntity& sender, AIMsg msg, const std::any& msg_content);
83
84 [[nodiscard]] Sensor* getSensor(SensorType type);
85
86 [[nodiscard]] AITeam* getTeam() const noexcept { return _teamPtr; }
87 [[nodiscard]] U32 getTeamID() const;
88 [[nodiscard]] const string& name() const noexcept { return _name; }
89
90 [[nodiscard]] NPC* getUnitRef() const noexcept { return _unitRef; }
91
94 [[nodiscard]] I32 getAgentID() const noexcept { return _agentID; }
96 [[nodiscard]] const dtCrowdAgent* getAgent() const noexcept { return _agent; }
97 [[nodiscard]] bool isAgentLoaded() const noexcept { return _agentID >= 0; }
99 void resetCrowd();
101 [[nodiscard]] F32 getAgentHeight() const noexcept;
103 [[nodiscard]] F32 getAgentRadius() const noexcept;
105 [[nodiscard]] PresetAgentRadius getAgentRadiusCategory() const noexcept { return _agentRadiusCategory; }
112 [[nodiscard]] bool updateDestination(const vec3<F32>& destination, bool updatePreviousPath = false);
114 [[nodiscard]] const vec3<F32>& getDestination() const noexcept;
116 [[nodiscard]] bool destinationReached() const;
118 [[nodiscard]] bool setPosition(const vec3<F32>& position);
121 [[nodiscard]] const vec3<F32>& getPosition() const noexcept;
124 [[nodiscard]] F32 getMaxSpeed() const noexcept;
127 [[nodiscard]] F32 getMaxAcceleration() const noexcept;
139 void setVelocity(const vec3<F32>& velocity);
141 void moveForward();
143 void moveBackwards();
146 void stop();
149 [[nodiscard]] vec3<F32> getVelocity() const noexcept;
151 [[nodiscard]] F32 getSpeed() const noexcept { return getVelocity().length(); }
153 [[nodiscard]] bool isMoving() const noexcept { return !_stopped || !IS_ZERO(getSpeed()); }
154
155 [[nodiscard]] string toString() const;
156
157 protected:
161 void updatePosition(U64 deltaTimeUS);
168 void setDestination(const vec3<F32>& destination) noexcept;
169
170 void setTeamPtr(AITeam* teamPtr);
171 [[nodiscard]] bool processInput(U64 deltaTimeUS);
172 [[nodiscard]] bool processData(U64 deltaTimeUS);
173 [[nodiscard]] bool update(U64 deltaTimeUS);
174
175 private:
176 string _name;
178 std::unique_ptr<AIProcessor> _processor;
179
182
192 const dtCrowdAgent* _agent;
194
209};
210
211namespace Attorney {
213 static void setTeamPtr(AIEntity& entity, AITeam* const teamPtr) {
214 entity.setTeamPtr(teamPtr);
215 }
216 static bool processInput(AIEntity& entity, const U64 deltaTimeUS) {
217 return entity.processInput(deltaTimeUS);
218 }
219 static bool processData(AIEntity& entity, const U64 deltaTimeUS) {
220 return entity.processData(deltaTimeUS);
221 }
222 static bool update(AIEntity& entity, const U64 deltaTimeUS) {
223 return entity.update(deltaTimeUS);
224 }
225 friend class AI::AITeam;
226};
227} // namespace Attorney
228} // namespace AI
229} // namespace Divide
230
231#endif //DVD_AI_ENTITY_H_
Based on OgreCrowd.
Definition: AIEntity.h:60
hashMap< SensorType, std::unique_ptr< Sensor > > SensorMap
Definition: AIEntity.h:183
const string & name() const noexcept
Definition: AIEntity.h:88
bool setAndSurrenderAIProcessor(AIProcessor *processor)
Definition: AIEntity.cpp:139
bool updateDestination(const vec3< F32 > &destination, bool updatePreviousPath=false)
Definition: AIEntity.cpp:314
bool update(U64 deltaTimeUS)
Definition: AIEntity.cpp:173
void resetCrowd()
Update the crowding system.
Definition: AIEntity.cpp:213
vec3< F32 > _currentPosition
Definition: AIEntity.h:202
F32 _previousDistanceToTarget
Definition: AIEntity.h:205
bool isMoving() const noexcept
Returns true if this character is moving.
Definition: AIEntity.h:153
bool _stopped
True if this character is stopped.
Definition: AIEntity.h:208
F32 getAgentRadius() const noexcept
The radius of the agent for this character.
Definition: AIEntity.cpp:209
bool processData(U64 deltaTimeUS)
Definition: AIEntity.cpp:163
bool isAgentLoaded() const noexcept
Definition: AIEntity.h:97
F32 getMaxAcceleration() const noexcept
Definition: AIEntity.cpp:426
void processMessage(AIEntity &sender, AIMsg msg, const std::any &msg_content)
Definition: AIEntity.cpp:100
void moveBackwards()
Manually control the character moving it backwards.
Definition: AIEntity.cpp:388
void setTeamPtr(AITeam *teamPtr)
Definition: AIEntity.cpp:197
void updatePosition(U64 deltaTimeUS)
Definition: AIEntity.cpp:267
U32 getTeamID() const
Definition: AIEntity.cpp:188
void receiveMessage(AIEntity &sender, AIMsg msg, const std::any &msg_content)
Definition: AIEntity.cpp:94
string toString() const
Definition: AIEntity.cpp:431
I32 getAgentID() const noexcept
Definition: AIEntity.h:94
const dtCrowdAgent * _agent
The agent controlling this character.
Definition: AIEntity.h:192
F32 getSpeed() const noexcept
The current speed this character is traveling at.
Definition: AIEntity.h:151
vec3< F32 > _destination
Definition: AIEntity.h:201
vec3< F32 > getVelocity() const noexcept
Definition: AIEntity.cpp:417
void setVelocity(const vec3< F32 > &velocity)
Definition: AIEntity.cpp:396
F32 getAgentHeight() const noexcept
The height of the agent for this character.
Definition: AIEntity.cpp:205
bool processInput(U64 deltaTimeUS)
Definition: AIEntity.cpp:152
SharedMutex _managerQueryMutex
Definition: AIEntity.h:181
F32 getMaxSpeed() const noexcept
Definition: AIEntity.cpp:421
Navigation::DivideDtCrowd * _detourCrowd
Crowd in which the agent of this character is.
Definition: AIEntity.h:190
const dtCrowdAgent * getAgent() const noexcept
The agent that steers this character within the crowd.
Definition: AIEntity.h:96
bool setPosition(const vec3< F32 > &position)
Place agent at new position.
Definition: AIEntity.cpp:228
void sendMessage(AIEntity &receiver, AIMsg msg, const std::any &msg_content)
Definition: AIEntity.cpp:85
const vec3< F32 > & getPosition() const noexcept
Definition: AIEntity.cpp:349
void setDestination(const vec3< F32 > &destination) noexcept
Definition: AIEntity.cpp:371
bool destinationReached() const
Returns true when this agent has reached its set destination.
Definition: AIEntity.cpp:362
AITeam * getTeam() const noexcept
Definition: AIEntity.h:86
bool addSensor(SensorType type)
Definition: AIEntity.cpp:117
~AIEntity() override
Definition: AIEntity.cpp:39
SharedMutex _updateMutex
Definition: AIEntity.h:180
const vec3< F32 > & getDestination() const noexcept
The destination set for this agent.
Definition: AIEntity.cpp:353
std::unique_ptr< AIProcessor > _processor
Definition: AIEntity.h:178
Sensor * getSensor(SensorType type)
Definition: AIEntity.cpp:108
PresetAgentRadius _agentRadiusCategory
Definition: AIEntity.h:193
void moveForward()
Manually control the character moving it forward.
Definition: AIEntity.cpp:380
PresetAgentRadius getAgentRadiusCategory() const noexcept
The radius category of this character.
Definition: AIEntity.h:105
vec3< F32 > _currentVelocity
Definition: AIEntity.h:203
SensorMap _sensorList
Definition: AIEntity.h:184
NPC * getUnitRef() const noexcept
Definition: AIEntity.h:90
Provides a scene-level AI implementation.
Definition: AIProcessor.h:46
static bool update(AIEntity &entity, const U64 deltaTimeUS)
Definition: AIEntity.h:222
static void setTeamPtr(AIEntity &entity, AITeam *const teamPtr)
Definition: AIEntity.h:213
static bool processInput(AIEntity &entity, const U64 deltaTimeUS)
Definition: AIEntity.h:216
static bool processData(AIEntity &entity, const U64 deltaTimeUS)
Definition: AIEntity.h:219
Utility class that adds basic GUID management to objects.
Definition: GUIDWrapper.h:44
NPC base class. Every character in the game is an NPC by default except the Player.
Definition: NPC.h:46
T length() const noexcept
return the vector's length
Definition: MathVectors.h:747
SensorType
Definition: Sensor.h:39
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
bool load() override
bool IS_ZERO(const T X) noexcept
int32_t I32
uint8_t U8
std::shared_mutex SharedMutex
Definition: SharedMutex.h:43
hashAlg::unordered_map< K, V, HashFun, Predicate > hashMap
Definition: HashMap.h:55
Project & parent
Definition: DefaultScene.h:41
uint32_t U32
uint64_t U64