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
/*
   Copyright (c) 2014 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/MathClasses.h"
#include "ReCast/DetourCrowd/Include/DetourCrowd.h"
#include "../NavMeshes/Headers/NavMesh.h"
#include <vector>


/**
  * 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:
        /**
          * 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, D32 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 deltaTime);
        /// 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 D32 getAgentHeight() const { return _recast->getConfigParams().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 D32 getAgentRadius() const { return _recast->getConfigParams().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> DivideDtCrowd::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
331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

318 Diff Diff IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)

312 Diff Diff IonutCava picture IonutCava Fri 22 Aug, 2014 22:46:19 +0000

[Ionut]
- Replaced AESOP with CPPGOAP (https://github.com/cpowell/cppgoap)
- Added a better interface to GOAP classes and objects via the AISceneImpl
- Actions, goals and orders basic infrastructure

311 Diff Diff IonutCava picture IonutCava Mon 18 Aug, 2014 21:40:52 +0000

[Ionut]
- Added a basic AESOP implementation
- Moved all AI related classes under the “AI” namespace

310 Diff Diff IonutCava picture IonutCava Sun 17 Aug, 2014 23:31:04 +0000

[Ionut]
- Some cleanups in AI related classes

233 Diff Diff k1ngp1n picture k1ngp1n Tue 14 Jan, 2014 22:24:35 +0000

[Ionut] [[BR]]
- AMD compatibility fixes [[BR]]
- More pathfinding tweaks [[BR]]

232 Diff Diff k1ngp1n picture k1ngp1n Tue 14 Jan, 2014 14:58:15 +0000

[Ionut][[BR]]
- nVidia FBO_MS fix (TexParameter calls do not work on TEXTURE_2D_MULTISAMPLE) [[BR]]
- nVidia shading issue fix (uninitialized MaterialProperties values were used for lighting) [[BR]]
- more stability fixes for nav meshes and pathfinding (may still hang sometimes [[BR]]
- Some changes to WarScene: [[BR]]
— added some obstacles [[BR]]
— added auto load nav mesh in separate thread [[BR]]
— added auto draw debug nav mesh in DEBUG [[BR]]
— added basic entity position <---> entity destination debug line rendering to get a basic idea of unit’s path [[BR]]

221 Diff Diff k1ngp1n picture k1ngp1n Wed 08 Jan, 2014 18:50:02 +0000

[Ionut] [[BR]]
- Merged branch “Shadows And Animations” back into trunk [[BR]]
- Added DoxygenGUI project file [[BR]]

  • Buggy *
186 Diff Diff k1ngp1n picture k1ngp1n Sun 24 Nov, 2013 19:14:54 +0000

[Ionut] [[BR]]
- Increased precision of internal timers (delta time stored as double and computed by the kernel) [[BR]]
- Some thread sync fixes [[BR]]
- More work on the profile timers. Added a main loop timer as an example (Kernel.cpp -> mainLoopApp) [[BR]]
- Physics update <-> SceneGraphNode transform update sync (rather primitive, but it works) [[BR]]
— Setting a position or rotation manually was overridden by the physics engine. Now, manual transform updates have a higher priority [[BR]]

185 k1ngp1n picture k1ngp1n Sat 23 Nov, 2013 19:18:16 +0000

[Ionut] [[BR]]
- More AI <-> NavMesh/Crowd integration [[BR]]
- Fixed object selection [[BR]]
— Every SceneGraphNode that has the “_isSelectable” flag set to true can now be selected with the mouse and highlighted with increased ambient [[BR]]
- Various performance optimizations [[BR]]
- Slight shadow offset modification to reduce peter-panning [[BR]]
- Added a debug-only profiling (ProfileTimer) class (unused for now) [[BR]]