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
/*
   Copyright (c) 2016 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.

 */

//
// Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
//
// This software is provided 'as-is', without any express or implied
// warranty.  In no event will the authors be held liable for any damages
// arising from the use of this software.
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
// 1. The origin of this software must not be misrepresented; you must not
//    claim that you wrote the original software. If you use this software
//    in a product, an acknowledgment in the product documentation would be
//    appreciated but is not required.
// 2. Altered source versions must be plainly marked as such, and must not be
//    misrepresented as being the original software.
// 3. This notice may not be removed or altered from any source distribution.
//
// Changes, Additions and Refactoring : Copyright (c) 2010-2011 Lethal Concept,
// LLC
// Changes, Additions and Refactoring Author: Simon Wittenberg (MD)
// The above license is fully inherited.
//
// T3D 1.1 NavMesh class and supporting methods.
// Daniel Buckmaster, 2011
// With huge thanks to:
//    Lethal Concept http://www.lethalconcept.com/
//    Mikko Mononen http://code.google.com/p/recastnavigation/
//

#ifndef _NAVIGATION_MESH_H_
#define _NAVIGATION_MESH_H_

#include "Platform/Threading/Headers/Task.h"

#include "NavMeshConfig.h"
#include "NavMeshLoader.h"
#include "NavMeshContext.h"

namespace Divide {

class PlatformContext;

FWD_DECLARE_MANAGED_CLASS(SceneGraphNode);

namespace AI {
namespace Navigation {

static const I32 NAVMESHSET_MAGIC =
    'M' << 24 | 'S' << 16 | 'E' << 8 | 'T';  //'MSET';
static const I32 NAVMESHSET_VERSION = 1;

struct NavMeshSetHeader {
    I32 magic;
    I32 version;
    I32 numTiles;
    F32 extents[3];
    dtNavMeshParams params;
};

struct NavMeshTileHeader {
    dtTileRef tileRef;
    I32 dataSize;
};

/// @class NavigationMesh
/// Represents a set of bounds within which a Recast navigation mesh is
/// generated.
class NavMeshDebugDraw;
class DivideDtCrowd;

namespace Attorney {
    class NavigationMeshCrowd;
};

class NavigationMesh : public GUIDWrapper /*,public SceneObject */ {
    friend class Attorney::NavigationMeshCrowd;

   protected:
    enum class RenderMode : U32 {
        RENDER_NAVMESH = 0,
        RENDER_CONTOURS,
        RENDER_POLYMESH,
        RENDER_DETAILMESH,
        RENDER_PORTALS,
    };

   public:
    typedef std::function<void(NavigationMesh*)> CreationCallback;

    inline void setFileName(const stringImpl& fileName) {
        _fileName.append(fileName);
    }
    /// Initiates the NavigationMesh build process, which includes notifying the
    /// clients and posting a task.
    bool build(SceneGraphNode& sgn,
               CreationCallback creationCompleteCallback, bool threaded = true);
    /// Save the NavigationMesh to a file.
    bool save(SceneGraphNode& sgn);
    /// Load a saved NavigationMesh from a file.
    bool load(SceneGraphNode& sgn);
    /// Unload the navmesh reverting the instance to an empty container
    bool unload();
    /// Called once per frame with the time diff between this and the last frame
    void update(const U64 deltaTime);
    /// Render the debug mesh if debug drawing is enabled
    void draw(RenderSubPassCmds& subPassesInOut);
    inline void debugDraw(bool state) { _debugDraw = state; }
    inline bool debugDraw() const { return _debugDraw; }

    inline void setRenderMode(const RenderMode& mode) { _renderMode = mode; }
    inline void setRenderConnections(bool state) { _renderConnections = state; }

    inline const vec3<F32>& getExtents() const { return _extents; }

    inline const dtNavMeshQuery& getNavQuery() const { return *_navQuery; }

    bool getRandomPosition(vec3<F32>& result) const;

    bool getClosestPosition(const vec3<F32>& destination,
                            const vec3<F32>& extents, F32 delta,
                            vec3<F32>& result) const;

    bool getRandomPositionInCircle(const vec3<F32>& center, F32 radius,
                                   const vec3<F32>& extents, vec3<F32>& result,
                                   U8 maxIters = 15) const;

    NavigationMesh(PlatformContext& context);
    ~NavigationMesh();

   private:
    /// Initiates the build process in a separate thread.
    bool buildThreaded();
    /// Stop the threaded build process;
    void stopThreadedBuild();
    /// Runs the build process. Not threadsafe,. so take care to synchronise
    /// calls to this method properly!
    bool buildProcess();
    /// Used for multithreaded loading
    void buildInternal(const std::atomic_bool& stopRequested);
    /// Generates a navigation mesh for the collection of objects in this
    /// mesh. Returns true if successful. Stores the created mesh in tnm.
    bool generateMesh();
    /// Performs the Recast part of the build process.
    bool createPolyMesh(rcConfig& cfg, NavModelData& data,
                        rcContextDivide* ctx);
    /// Performs the Detour part of the build process.
    bool createNavigationMesh(dtNavMeshCreateParams& params);
    /// Load nav mesh configuration from file
    bool loadConfigFromFile();
    /// Create a navigation mesh query to help in pathfinding.
    bool createNavigationQuery(U32 maxNodes = 2048);
    /// Create a unique mesh name using the given root node
    stringImpl generateMeshName(SceneGraphNode& sgn);
   private:
    bool _saveIntermediates;
    NavigationMeshConfig _configParams;
    /// @name NavigationMesh build
    /// @{
    /// Do we build in a separate thread?
    bool _buildThreaded;
    /// @name Intermediate data
    /// @{
    rcHeightfield* _heightField;
    rcCompactHeightfield* _compactHeightField;
    rcContourSet* _countourSet;
    rcPolyMesh* _polyMesh;
    rcPolyMeshDetail* _polyMeshDetail;
    dtNavMesh* _navMesh;
    dtNavMesh* _tempNavMesh;
    /// Free all stored working data.
    /// @param freeAll Force all data to be freed, retain none.
    void freeIntermediates(bool freeAll);
    /// @}

    /// A thread for us to update in.
    I64 _buildJobGUID;
    /// A mutex for accessing our actual NavigationMesh.
    std::mutex _navigationMeshLock;
    /// A simple flag to say we are building.
    std::atomic<bool> _building;
    /// A callback function to call after building is complete
    CreationCallback _loadCompleteClbk;
    /// Data file to store this nav mesh in. (From engine executable dir.)
    stringImpl _fileName;
    /// Configuration file
    stringImpl _configFile;
    /// NavMesh extents
    vec3<F32> _extents;
    ///  Query object used for this mesh
    dtNavMeshQuery* _navQuery;
    /// SceneGraphNode from which to build
    SceneGraphNode* _sgn;
    std::atomic<bool> _debugDraw;
    bool _renderConnections;
    RenderMode _renderMode;
    /// DebugDraw interface
    NavMeshDebugDraw* _debugDrawInterface;
};

namespace Attorney {
class NavigationMeshCrowd {
   private:
    static dtNavMesh* getNavigationMesh(NavigationMesh& navMesh) {
        return navMesh._navMesh;
    }
    static const NavigationMeshConfig& getConfigParams(
        NavigationMesh& navMesh) {
        return navMesh._configParams;
    }
    friend class Divide::AI::Navigation::DivideDtCrowd;
};
};  // namespace Attorney
};  // namespace Navigation
};  // namespace AI
};  // namespace Divide

#endif

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

Diff revisions: vs.
Revision Author Commited Message
804 Diff Diff IonutCava picture IonutCava Thu 01 Dec, 2016 17:20:59 +0000

[IonutCava]
- Singleton elimination update Part I: get it to compile
— The following classes are no longer Singletons: GFXDevice, GL_API, DX_API, SFXWrapper, FmodWrapper, SDLWrapper, ALWrapper, PXDevice, InputInterface, RenderPassManager, SceneManager and ResourceManager;
— Refactor system to a Context / Component based implementation (Pass relevant context to objects: e.g. GFXDevice object to Textures, GUI to GUIElements, etc)
— Make devices and managers components of the kernel
— Allow multiple Resource caches to co-exist. This may prove useful for later when a more fragmented memory model is need (per frame / per scene / global caches / etc)

  • next steps: part II – cleanup/refactor new code, part III – optimise code, part IV – remove remaining Singletons (e.g. Application, ParamHandler, FrameListenerManager, Recast, PostFX and DebugInterface)
777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

740 Diff Diff IonutCava picture IonutCava Sat 25 Jun, 2016 17:09:50 +0000

[IonutCava]
- More scene changing related fixes
- GUIDWrapper is now a core feature instead of a utility

713 Diff Diff IonutCava picture IonutCava Wed 25 May, 2016 15:43:38 +0000

[IonutCava]
- Removed all unique_ptr’s from the code with classic new/delete pairs. They were seriously not needed.
- Added the concept of SceneComponent to scene specific classes: aiManager, lightPool, sceneGraph, physicsInterface etc
— This allowed the removal of the global GET_ACTIVE_SCENEGRAPH call;

710 Diff Diff IonutCava picture IonutCava Fri 20 May, 2016 16:24:40 +0000

[IonutCava]
- Code cleanup
- Initial work on Scene loading and unloading with and without unloading assets:
— Need to change AIManager from a Singleton to a per-scene component

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

662 Diff Diff IonutCava picture IonutCava Mon 28 Mar, 2016 18:46:06 +0000

[Ionut]
- stopRequested param for Task callbacks should be an atomic const reference
- DebugInterface thread safety updates
- Initial code for locked Tasks (tasks that can’t be reset)

659 Diff Diff IonutCava picture IonutCava Thu 17 Mar, 2016 16:28:19 +0000

[IonutCava]
- Refactor threadpool/task system:
— Simpler, faster code
— callback functions should handle their own looping logic
— Allow room for future implementation of parent <-> children dependencies of tasks

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

589 IonutCava picture IonutCava Tue 01 Dec, 2015 13:51:59 +0000

[IonutCava]
- Cleanup some indirections to improve cache locality