Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*
   Copyright (c) 2018 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

/*
    OgreCrowd
    ---------

    Copyright (c) 2012 Jonas Hauquier

    Additional contributions by:

    - mkultra333
    - Paul Wilson

    Sincere thanks and to:

    - Mikko Mononen (developer of Recast navigation libraries)

    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to
   deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
   FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.

*/

#ifndef _DIVIDE_CROWD_H_
#define _DIVIDE_CROWD_H_

#include "Core/Math/Headers/MathMatrices.h"
#include "DetourCrowd/Include/DetourCrowd.h"
#include "../NavMeshes/Headers/NavMesh.h"
#include "Core/TemplateLibraries/Headers/Vector.h"

/**
  * Divide wrapper around Ogre wrapper around DetourCrowd.
  * Controls a crowd of agents that can steer to avoid each other and follow
  * individual paths.
  *
  * This class is largely based on the CrowdTool used in the original
  *RecastNavigation
  * demo.
  **/

namespace Divide {
namespace AI {
namespace Navigation {

class NavigationMesh;

class DivideDtCrowd : public NonCopyable {
   public:
    /**
      * Initialize a detour crowd that will manage agents on the specified
      * recast navmesh. It does not matter how this navmesh is constructed
      * (either with OgreRecast directly or with DetourTileCache).
      * Parameters such as agent dimensions will be taken from the specified
      * recast component.
      **/
    DivideDtCrowd(NavigationMesh* navMesh);
    ~DivideDtCrowd();
    /// Add an agent to the crowd: Returns ID of created agent
    /// (-1 if maximum agents is already created)
    I32 addAgent(const vec3<F32>& position, F32 maxSpeed, F32 acceleration);
    /// Retrieve agent with specified ID from the crowd.
    inline const dtCrowdAgent* getAgent(I32 id) const {
        return _crowd->getAgent(id);
    }
    /// Remove agent with specified ID from the crowd.
    void removeAgent(const I32 idx);
    /**
      * Set global destination or target for all agents in the crowd.
      * Setting adjust to true will try to adjust the current calculated path
      * of the agents slightly to end at the new destination, avoiding the need
      * to calculate a completely new path. This only works if the destination
      *is
      * close to the previously set one, for example when chasing a moving
      *entity.
      **/
    void setMoveTarget(const vec3<F32>& position, bool adjust);
    /**
      * Set target or destination for an individual agent.
      * Setting adjust to true will try to adjust the current calculated path
      * of the agent slightly to end at the new destination, avoiding the need
      * to calculate a completely new path. This only works if the destination
      *is
      * close to the previously set one, for example when chasing a moving
      *entity.
      **/
    void setMoveTarget(I32 agentID, const vec3<F32>& position, bool adjust);
    /**
      * Request a specified velocity for the agent with specified index.
      * Requesting a velocity means manually controlling an agent.
      * Returns true if the request was successful.
      **/
    bool requestVelocity(I32 agentID, const vec3<F32>& velocity);
    /// Cancels any request for the specified agent, making it stop.
    /// Returns true if the request was successul.
    bool stopAgent(I32 agentID);
    /**
      * Helper that calculates the needed velocity to steer an agent to a target
      *destination.
      * Parameters:
      *     position    is the current position of the agent
      *     target      is the target destination to reach
      *     speed       is the (max) speed the agent can travel at
      * Returns the calculated velocity.
      *
      * This function can be used together with requestMoveVelocity to achieve
      *the functionality
      * of adjustMoveTarget function.
      **/
    static vec3<F32> calcVel(const vec3<F32>& position, const vec3<F32>& target,
                             D64 speed);
    static F32 getDistanceToGoal(const dtCrowdAgent* agent, const F32 maxRange);
    static bool destinationReached(const dtCrowdAgent* agent,
                                   const F32 maxDistanceFromTarget);
    /**
      * Update method for the crowd manager. Will calculate new positions for
      *moving agents.
      * Call this method in your frameloop every frame to make your agents move.
      *
      * DetourCrowd uses sampling based local steering to calculate a velocity
      *vector for each
      * agent. The calculation time of this is limited to the number of agents
      *in the crowd and
      * the sampling amount (which is a constant).
      *
      * Additionally pathfinding tasks are queued and the number of computations
      *is limited, to
      * limit the maximum amount of time spent for preparing a frame. This can
      *have as consequence
      * that some agents will only start to move after a few frames, when their
      *paths are calculated.
      **/
    void update(const U64 deltaTimeUS);
    /// The height of agents in this crowd. All agents in a crowd have the same
    /// height, and height is
    /// determined by the agent height parameter with which the navmesh is
    /// build.
    inline D64 getAgentHeight() const {
        return Attorney::NavigationMeshCrowd::getConfigParams(*_recast)
            .getAgentHeight();
    }
    /// The radius of agents in this crowd. All agents in a crowd have the same
    /// radius, and radius
    /// determined by the agent radius parameter with which the navmesh is
    /// build.
    inline D64 getAgentRadius() const {
        return Attorney::NavigationMeshCrowd::getConfigParams(*_recast)
            .getAgentRadius();
    }
    /// The number of (active) agents in this crowd.
    inline I32 getNbAgents() const { return _activeAgents; }
    /// Get the navigation mesh associated with this crowd
    inline const NavigationMesh& getNavMesh() { return *_recast; }
    /// Check if the navMesh is valid
    bool isValidNavMesh() const;
    /// Change the navigation mesh for this crowd
    inline void setNavMesh(NavigationMesh* navMesh) { _recast = navMesh; }
    /// The maximum number of agents that are allowed in this crowd.
    inline I32 getMaxNbAgents() const { return _crowd->getAgentCount(); }
    /// Get all (active) agents in this crowd.
    vectorImpl<dtCrowdAgent*> getActiveAgents(void);
    /// Get the IDs of all (active) agents in this crowd.
    vectorImpl<I32> getActiveAgentIDs(void);
    /// The last set destination for the crowd.
    /// This is the destination that will be assigned to newly added agents.
    inline vec3<F32> getLastDestination() const {
        return vec3<F32>(_targetPos);
    }
    /// Reference to the DetourCrowd object that is wrapped.
    dtCrowd* _crowd;
    /// Reference to the Recast/Detour wrapper object for Divide.
    NavigationMesh* _recast;
    /// The latest set target or destination section in the recast navmesh.
    dtPolyRef _targetRef;
    /// The latest set target or destination position.
    F32 _targetPos[3];
    /// Max pathlength for calculated paths.
    static const I32 AGENT_MAX_TRAIL = 64;
    /// Max number of agents allowed in this crowd.
    static const I32 MAX_AGENTS = 128;
    /// Stores the calculated paths for each agent in the crowd.
    struct AgentTrail {
        F32 trail[AGENT_MAX_TRAIL * 3];
        I32 htrail;
    };
    AgentTrail _trails[MAX_AGENTS];
    /// Debug info object used in the original recast/detour demo, not used in
    /// this application.
    dtCrowdAgentDebugInfo _agentDebug;
    /// Parameters for obstacle avoidance of DetourCrowd steering.
    dtObstacleAvoidanceDebugData* _vod;
    /// Agent configuration parameters
    bool _anticipateTurns;
    bool _optimizeVis;
    bool _optimizeTopo;
    bool _obstacleAvoidance;
    bool _separation;
    F32 _obstacleAvoidanceType;
    F32 _separationWeight;

   protected:
    /**
      * Helper to calculate the needed velocity to steer an agent to a target
      *destination.
      * Parameters:
      *     velocity    is the return parameter, the calculated velocity
      *     position    is the current position of the agent
      *     target      is the target destination to reach
      *     speed       is the (max) speed the agent can travel at
      *
      * This function can be used together with requestMoveVelocity to achieve
      *the functionality
      * of the old adjustMoveTarget function.
      **/
    static void calcVel(F32* velocity, const F32* position, const F32* target,
                        const F32 speed);

   private:
    /// Number of (active) agents in the crowd.
    I32 _activeAgents;
};  // DivideDtCrowd

};  // Navigation
};  // namespace AI
};  // namespace Divide
#endif

Commits for Divide-Framework/trunk/Source Code/AI/PathFinding/Headers/DivideCrowd.h

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

968 Diff Diff IonutCava picture IonutCava Tue 07 Nov, 2017 17:32:31 +0000

[Ionut]
- Consistent naming between timing variables

923 Diff Diff IonutCava picture IonutCava Tue 01 Aug, 2017 22:23:24 +0000

[Ionut]
- Add (hack) new GL 4.6 KHR_NO_ERROR flag for non-GPU validated builds
- Disable GPU debug messages by default. Re-enabled only via a command line argument: “--enableGPUMessageGroups”.
- Cleanup GL texture and sampler binding
- Rework hash map insert and emplace
- Update SDL to 2.0.5

898 Diff Diff IonutCava picture IonutCava Thu 22 Jun, 2017 22:05:34 +0000

[IonutCava]
- Use vectorImpl instead of vector in the few remaining places it wasn’t used
- Force GLIM to use the submitRenderCommand / GenericDrawCommand system
- Add basic framework for a “pushConstants” type buffer that will replace Uniform() calls
- Add some code to allow hardware query rewrite in the future

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

680 Diff Diff IonutCava picture IonutCava Thu 14 Apr, 2016 16:15:38 +0000

[IonutCava]
- Added a mat2 class (untested)
- Added static asserts to matrices, vectors and quaternions to allow only arithmetic (sans bool) data types
- Added more vector unit tests
- Added unit tests for matrices
- D32 finally renamed to D64 as the VC++ compiler is considered as the reference compiler

648 Diff Diff IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these

462 Diff Diff IonutCava picture IonutCava Wed 03 Jun, 2015 15:58:10 +0000

[Ionut]
- More Linux port work:
— Code compiles and links
— Executable launches and:
-— Failes to create a context (running on a virtual machine, so to be expected)
-— Time values are invalid (never debugged linux time code, so to be expected)
Code is now cross-platform Win32 <-> Unix

389 Diff Diff IonutCava picture IonutCava Thu 26 Mar, 2015 17:14:11 +0000

[Ionut]
- More rendering pipeline refactoring:
— Implemented temporary hack of binding a subrange of the nodebuffer to avoid using gl_BaseInstanceARB and just use gl_DrawIDARB for indexing data (works fine)
— Matrix data is only generated if we got valid rendering commands from a certain node
- Moved all *Attorney classes to an Attorney namespace
- Fixed a bug with caching uniform values in glShaderProgram
- Added some robustness checks to glUniformBuffer

358 IonutCava picture IonutCava Sun 01 Mar, 2015 22:44:38 +0000

[Ionut]
- Fixed some OpenGL initialization issues and function calls (no proper support for DSA yet)
- Cleanup up the Sound and Physics Wrappers
- Some readability improvements here and there