Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
DivideCrowd.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
32/*
33 OgreCrowd
34 ---------
35
36 Copyright (c) 2012 Jonas Hauquier
37
38 Additional contributions by:
39
40 - mkultra333
41 - Paul Wilson
42
43 Sincere thanks and to:
44
45 - Mikko Mononen (developer of Recast navigation libraries)
46
47 Permission is hereby granted, free of charge, to any person obtaining a copy
48 of this software and associated documentation files (the "Software"), to
49 deal
50 in the Software without restriction, including without limitation the rights
51 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
52 copies of the Software, and to permit persons to whom the Software is
53 furnished to do so, subject to the following conditions:
54
55 The above copyright notice and this permission notice shall be included in
56 all copies or substantial portions of the Software.
57
58 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
59 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
60 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
61 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
62 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
63 FROM,
64 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
65 THE SOFTWARE.
66
67*/
68
69#pragma once
70#ifndef DVD_CROWD_H_
71#define DVD_CROWD_H_
72
73#include "recastnavigation/DetourCrowd.h"
75
86namespace Divide {
87namespace AI {
88namespace Navigation {
89
90class NavigationMesh;
91
92class DivideDtCrowd final : public NonCopyable {
93 public:
105 [[nodiscard]] I32 addAgent(const vec3<F32>& position, F32 maxSpeed, F32 acceleration);
107 [[nodiscard]] const dtCrowdAgent* getAgent(const I32 id) const { return _crowd->getAgent(id); }
109 void removeAgent(I32 idx);
117 void setMoveTarget(const vec3<F32>& position, bool adjust);
125 void setMoveTarget(I32 agentID, const vec3<F32>& position, bool adjust);
131 [[nodiscard]] bool requestVelocity(I32 agentID, const vec3<F32>& velocity) const;
134 [[nodiscard]] bool stopAgent(I32 agentID) const;
146 [[nodiscard]] static vec3<F32> calcVel(const vec3<F32>& position, const vec3<F32>& target, D64 speed);
147 [[nodiscard]] static F32 getDistanceToGoal(const dtCrowdAgent* agent, F32 maxRange);
148 [[nodiscard]] static bool destinationReached(const dtCrowdAgent* agent, F32 maxDistanceFromTarget);
161 void update(U64 deltaTimeUS);
166 [[nodiscard]] F32 getAgentHeight() const noexcept { return Attorney::NavigationMeshCrowd::getConfigParams(*_recast).getAgentHeight(); }
171 [[nodiscard]] F32 getAgentRadius() const noexcept { return Attorney::NavigationMeshCrowd::getConfigParams(*_recast).getAgentRadius(); }
173 [[nodiscard]] I32 getNbAgents() const noexcept { return _activeAgents; }
175 [[nodiscard]] const NavigationMesh& getNavMesh() const noexcept { return *_recast; }
177 [[nodiscard]] bool isValidNavMesh() const;
179 void setNavMesh(NavigationMesh* navMesh) noexcept { _recast = navMesh; }
181 [[nodiscard]] I32 getMaxNbAgents() const { return _crowd->getAgentCount(); }
183 [[nodiscard]] void getActiveAgents( vector<dtCrowdAgent*>& agentsOut ) const;
185 [[nodiscard]] vector<I32> getActiveAgentIDs() const;
188 [[nodiscard]] vec3<F32> getLastDestination() const noexcept { return vec3<F32>(_targetPos); }
190 dtCrowd* _crowd = nullptr;
194 dtPolyRef _targetRef = 0u;
196 F32 _targetPos[3]{0.f, 0.f, 0.f};
198 static constexpr I32 AGENT_MAX_TRAIL = 64;
200 static constexpr I32 MAX_AGENTS = 128;
202 struct AgentTrail {
205 };
209 dtCrowdAgentDebugInfo _agentDebug;
211 dtObstacleAvoidanceDebugData* _vod = nullptr;
213 bool _anticipateTurns = true;
214 bool _optimizeVis = true;
215 bool _optimizeTopo = true;
217 bool _separation = false;
220
221 protected:
233 static void calcVel(F32* velocity, const F32* position, const F32* target, F32 speed);
234
235 private:
238}; // DivideDtCrowd
239
240} // Navigation
241} // namespace AI
242} // namespace Divide
243
244#endif //DVD_CROWD_H_
static const NavigationMeshConfig & getConfigParams(const NavigationMesh &navMesh) noexcept
Definition: NavMesh.h:245
I32 _activeAgents
Number of (active) agents in the crowd.
Definition: DivideCrowd.h:237
vec3< F32 > getLastDestination() const noexcept
Definition: DivideCrowd.h:188
void setMoveTarget(const vec3< F32 > &position, bool adjust)
bool _anticipateTurns
Agent configuration parameters.
Definition: DivideCrowd.h:213
static bool destinationReached(const dtCrowdAgent *agent, F32 maxDistanceFromTarget)
const dtCrowdAgent * getAgent(const I32 id) const
Retrieve agent with specified ID from the crowd.
Definition: DivideCrowd.h:107
void setNavMesh(NavigationMesh *navMesh) noexcept
Change the navigation mesh for this crowd.
Definition: DivideCrowd.h:179
I32 getMaxNbAgents() const
The maximum number of agents that are allowed in this crowd.
Definition: DivideCrowd.h:181
vector< I32 > getActiveAgentIDs() const
Get the IDs of all (active) agents in this crowd.
bool isValidNavMesh() const
Check if the navMesh is valid.
F32 getAgentHeight() const noexcept
Definition: DivideCrowd.h:166
static constexpr I32 AGENT_MAX_TRAIL
Max pathlength for calculated paths.
Definition: DivideCrowd.h:198
AgentTrail _trails[MAX_AGENTS]
Definition: DivideCrowd.h:206
static vec3< F32 > calcVel(const vec3< F32 > &position, const vec3< F32 > &target, D64 speed)
dtPolyRef _targetRef
The latest set target or destination section in the recast navmesh.
Definition: DivideCrowd.h:194
void removeAgent(I32 idx)
Remove agent with specified ID from the crowd.
bool stopAgent(I32 agentID) const
const NavigationMesh & getNavMesh() const noexcept
Get the navigation mesh associated with this crowd.
Definition: DivideCrowd.h:175
F32 getAgentRadius() const noexcept
Definition: DivideCrowd.h:171
dtCrowd * _crowd
Reference to the DetourCrowd object that is wrapped.
Definition: DivideCrowd.h:190
static F32 getDistanceToGoal(const dtCrowdAgent *agent, F32 maxRange)
bool requestVelocity(I32 agentID, const vec3< F32 > &velocity) const
NavigationMesh * _recast
Reference to the Recast/Detour wrapper object for Divide.
Definition: DivideCrowd.h:192
dtObstacleAvoidanceDebugData * _vod
Parameters for obstacle avoidance of DetourCrowd steering.
Definition: DivideCrowd.h:211
static constexpr I32 MAX_AGENTS
Max number of agents allowed in this crowd.
Definition: DivideCrowd.h:200
I32 addAgent(const vec3< F32 > &position, F32 maxSpeed, F32 acceleration)
dtCrowdAgentDebugInfo _agentDebug
Definition: DivideCrowd.h:209
I32 getNbAgents() const noexcept
The number of (active) agents in this crowd.
Definition: DivideCrowd.h:173
void getActiveAgents(vector< dtCrowdAgent * > &agentsOut) const
Get all (active) agents in this crowd.
F32 _targetPos[3]
The latest set target or destination position.
Definition: DivideCrowd.h:196
F32 getAgentRadius() const noexcept
F32 getAgentHeight() const noexcept
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
eastl::vector< Type > vector
Definition: Vector.h:42
double D64
uint64_t U64
Stores the calculated paths for each agent in the crowd.
Definition: DivideCrowd.h:202