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
#include "Headers/DivideRecast.h"
#include "Waypoints/Headers/WaypointGraph.h"

namespace Divide {
namespace AI {
namespace Navigation {
    static const U8  DT_TILECACHE_NULL_AREA     = 0;
    static const U8  DT_TILECACHE_WALKABLE_AREA = 63;
    static const U16 DT_TILECACHE_NULL_IDX      = 0xffff;

    DivideRecast::DivideRecast()
    {
        // Setup the default query filter
        _filter = MemoryManager_NEW dtQueryFilter();
        _filter->setIncludeFlags(0xFFFF);    // Include all
        _filter->setExcludeFlags(0);         // Exclude none
        // Area flags for polys to consider in search, and their cost
        // TODO have a way of configuring the filter
        _filter->setAreaCost(SAMPLE_POLYAREA_GROUND, 1.0f);       
        _filter->setAreaCost(DT_TILECACHE_WALKABLE_AREA, 1.0f);
        
        // Init path store. MaxVertex 0 means empty path slot
        for(I32 i = 0; i < MAX_PATHSLOT; i++) {
            _pathStore[i].MaxVertex = 0;
            _pathStore[i].Target = 0;
        }
    }

    DivideRecast::~DivideRecast()
    {
        MemoryManager::DELETE( _filter );
    }

    PathErrorCode DivideRecast::FindPath(const NavigationMesh& navMesh, 
                                         const vec3<F32>& startPos, 
                                         const vec3<F32>& endPos, 
                                         I32 pathSlot,
                                         I32 target) {
        
        const F32* pStartPos = &startPos[0];
        const F32* pEndPos = &endPos[0];
        const F32* extents = &navMesh.getExtents()[0];
        const dtNavMeshQuery& navQuery = navMesh.getNavQuery();

        dtStatus status;
        dtPolyRef StartPoly;
        dtPolyRef EndPoly;
        dtPolyRef PolyPath[MAX_PATHPOLY];
        F32 StraightPath[MAX_PATHVERT * 3];
        F32 StartNearest[3];
        F32 EndNearest[3];
        I32 nPathCount = 0;
        I32 nVertCount=0;

        // find the start polygon
        status = navQuery.findNearestPoly(pStartPos, extents, _filter, &StartPoly, StartNearest) ;
        if((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK)) 
            return PATH_ERROR_NO_NEAREST_POLY_START; // couldn't find a polygon

        // find the end polygon
        status = navQuery.findNearestPoly(pEndPos, extents, _filter, &EndPoly, EndNearest) ;
        if((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK))
            return PATH_ERROR_NO_NEAREST_POLY_END; // couldn't find a polygon

        status = navQuery.findPath(StartPoly, 
                                   EndPoly, 
                                   StartNearest, 
                                   EndNearest, 
                                   _filter,
                                   PolyPath, 
                                   &nPathCount, 
                                   MAX_PATHPOLY) ;
        if ((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK)) {
            return PATH_ERROR_COULD_NOT_CREATE_PATH; // couldn't create a path
        }

        if (nPathCount == 0) {
            return PATH_ERROR_COULD_NOT_FIND_PATH; // couldn't find a path
        }
        status = navQuery.findStraightPath(StartNearest, 
                                           EndNearest, 
                                           PolyPath, 
                                           nPathCount, 
                                           StraightPath, 
                                           nullptr, 
                                           nullptr, 
                                           &nVertCount, 
                                           MAX_PATHVERT) ;
        if ((status&DT_FAILURE) || (status&DT_STATUS_DETAIL_MASK)) {
            return PATH_ERROR_NO_STRAIGHT_PATH_CREATE; // couldn't create a path
        }

        if (nVertCount == 0) {
            return PATH_ERROR_NO_STRAIGHT_PATH_FIND; // couldn't find a path
        }
        // At this point we have our path.  Copy it to the path store
        I32 nIndex=0 ;
        for(I32 nVert = 0; nVert < nVertCount; nVert++) {
            _pathStore[pathSlot].PosX[nVert]=StraightPath[nIndex++];
            _pathStore[pathSlot].PosY[nVert]=StraightPath[nIndex++];
            _pathStore[pathSlot].PosZ[nVert]=StraightPath[nIndex++];

           //PRINT_FN("Path Vert %i, %f %f %f", nVert, m_PathStore[pathSlot].PosX[nVert],
           //                                          m_PathStore[pathSlot].PosY[nVert],
           //                                          m_PathStore[pathSlot].PosZ[nVert]) ;
        }
   
        _pathStore[pathSlot].MaxVertex=nVertCount;
        _pathStore[pathSlot].Target=target;

        return PATH_ERROR_NONE;
    }

    vectorImpl<vec3<F32> > DivideRecast::getPath(I32 pathSlot) {
       
        vectorImpl<vec3<F32> > result;
        if(pathSlot < 0 || pathSlot >= MAX_PATHSLOT || _pathStore[pathSlot].MaxVertex <= 0)
            return result;

        PATHDATA *path = &(_pathStore[pathSlot]);
        result.reserve(path->MaxVertex);
        for(I32 i = 0; i < path->MaxVertex; i++) {
            result.push_back(vec3<F32>(path->PosX[i], path->PosY[i], path->PosZ[i]));
        }

        return result;
    }

    I32 DivideRecast::getTarget(I32 pathSlot) {
        if(pathSlot < 0 || pathSlot >= MAX_PATHSLOT)
            return 0;
        
        return _pathStore[pathSlot].Target;
    }

    /// Random number generator implementation used by getRandomNavMeshPoint method.
    static F32 frand() {
        return (F32)rand()/(F32)RAND_MAX;
    }

    bool DivideRecast::getRandomNavMeshPoint(const NavigationMesh& navMesh, vec3<F32>& resultPt){
        if (navMesh.getNavQuery().getAttachedNavMesh() == nullptr) {
            return false;
        }
        dtPolyRef resultPoly;
        navMesh.getNavQuery().findRandomPoint(_filter, frand, &resultPoly, resultPt._v);

        return true;
    }

    bool DivideRecast::getRandomPointAroundCircle(const NavigationMesh& navMesh, 
                                                  const vec3<F32>& centerPosition,
                                                  F32 radius, 
                                                  const vec3<F32>& extents,
                                                  vec3<F32>& resultPt, 
                                                  U8 maxIters) {
        const dtNavMeshQuery& query = navMesh.getNavQuery();
        if (query.getAttachedNavMesh() == nullptr) {
            return false;
        }
        F32 radiusSq = radius * radius;

        dtPolyRef resultPoly;
        findNearestPolyOnNavmesh(navMesh, centerPosition, extents, resultPt, resultPoly);
        U8 i = 0;
        for (i = 0; i < maxIters; ++i) {
            query.findRandomPointAroundCircle(resultPoly, 
                                              centerPosition._v,
                                              radius, 
                                              _filter, 
                                              frand,  
                                              &resultPoly, 
                                              resultPt._v);
            if (centerPosition.distanceSquared(resultPt) <= radiusSq) {
                break;
            }
        }
        return (i != maxIters);
    }

    bool DivideRecast::findNearestPointOnNavmesh(const NavigationMesh& navMesh, 
                                                 const vec3<F32>& position, 
                                                 const vec3<F32>& extents, 
                                                 F32 delta, 
                                                 vec3<F32>& resultPt, 
                                                 dtPolyRef &resultPoly) {
        if (findNearestPolyOnNavmesh(navMesh, position, extents, resultPt, resultPoly) ){
            if (position.distanceSquared(resultPt) > (delta * delta)) {
                if (findNearestPolyOnNavmesh(navMesh, 
                                             position,
                                             &navMesh.getExtents()[0], 
                                             resultPt, 
                                             resultPoly)) {
                    if (position.distanceSquared(resultPt) <= (delta * delta)) {
                        return true;
                    }
                }
            }
            return true;
        }
        return false;
    }

    bool DivideRecast::findNearestPolyOnNavmesh(const NavigationMesh& navMesh, 
                                                const vec3<F32>& position, 
                                                const vec3<F32>& extents, 
                                                vec3<F32>& resultPt, 
                                                dtPolyRef &resultPoly) {
        if(navMesh.getNavQuery().getAttachedNavMesh() == nullptr){
            resultPt.set(VECTOR3_ZERO);
            return false;
        }

        dtStatus status = navMesh.getNavQuery().findNearestPoly(position._v, 
                                                                extents._v,
                                                                _filter, 
                                                                &resultPoly, 
                                                                resultPt._v);
        if ((status & DT_FAILURE) || (status & DT_STATUS_DETAIL_MASK)) {
            return false; // couldn't find a polygon
        }
        return true;
    }
}; //namespace Navigation
}; //namespace AI
}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/AI/PathFinding/DivideRecast.cpp

Diff revisions: vs.
Revision Author Commited Message
337 Diff Diff IonutCava picture IonutCava Wed 17 Dec, 2014 17:25:16 +0000

[Ionut]
- Replaced all tabs with 4 spaces (some spacing may be off now. no way to check all the files.)
- Moved implementation details for ParamHandler, BoundingBox, BoundingSphere and ProfileTimer to proper .inl and .cpp files. (more to follow)
- Update all forward declared enums with the required storage type (as requested by the C++11 standard)

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)

325 Diff Diff IonutCava picture IonutCava Wed 17 Sep, 2014 20:06:13 +0000

[Ionut]
- Reworked transform system:
— Parent transform chain system moved from Transform class to the PhysicsComponent
— PhysicsComponent now returns all transform values needed both global and local (still needs heavy optimization and caching)

- Reworked SceneGraph node management:
— Proper ref counting of SceneNodes and proper removing of resource (ResourceCache is now empty on destruction, as it should be)
— Removed parent transform tracking as that’s the PhysicsComponent’s responsibility
— Only nodes loaded via the ResourceCache are allowed to be added to the SceneGraph (added proper loaders for Impostors, Sky, etc)

- Optimized some of the math classes (mat4, mat3)

324 Diff Diff IonutCava picture IonutCava Sun 14 Sep, 2014 14:01:39 +0000

[Ionut]
- New memory management system (no custom allocators in this commit)
— Memory tracer to detect memory leaks on shutdown (from: https://www.relisoft.com/book/tech/9new.html)
— SAFE_DELETE_XYZ are now inline template functions not macros
— ASSERTION system now supports logging and message boxes and continue on error configurable for each build type
— Fixed a lot of memory leaks detected by the new system (some still remain)

- Added SRGB support (part 1)
— Albedo textures are loaded as SRGB (make sure resources are SRGB)
— Shaders output gamma corrected colors
— Moved terrain textures back to 2 array system (albedo and normal maps, albedo maps using a SRGB sampler)

- Sky is now loaded via the ResourceCache system
- Added include safeguards in shader atoms

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)

317 Diff Diff IonutCava picture IonutCava Tue 26 Aug, 2014 22:08:06 +0000

[Ionut]
- More AI Work

315 Diff Diff IonutCava picture IonutCava Mon 25 Aug, 2014 15:23:33 +0000

[Ionut]
- Update ReCast to the latest version available on GitHub
- Improved nav mesh target point selection
- Added basic “go to enemy flag” logic for the WarScene teams

314 Diff Diff IonutCava picture IonutCava Sun 24 Aug, 2014 19:54:33 +0000

[Ionut]
- More AI work
- Added some needed audio dlls

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

249 k1ngp1n picture k1ngp1n Mon 31 Mar, 2014 20:42:31 +0000

[Ionut] [[BR]]
- Migrated to platform toolset v100 [[BR]]
- Updated boost to 1.55 [[BR]]
- Moved from “NULL” to “nullptr” [[BR]]
- DevIL is now linked dynamically [[BR]]