Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 389 vs 390 for /trunk/Source Code/AI/PathFinding/NavMeshes/NavMeshLoader.cpp

Diff revisions: vs.
  @@ -36,19 +36,22 @@
36 36 cont = true;
37 37 break; // multi row
38 38 case '\n': {
39 - if (start) break;
39 + if (start)
40 + break;
40 41 done = true;
41 42 } break;
42 43 case '\r':
43 44 break;
44 45 case '\t':
45 46 case ' ':
46 - if (start) break;
47 + if (start)
48 + break;
47 49 default: {
48 50 start = false;
49 51 cont = false;
50 52 row[n++] = c;
51 - if (n >= len - 1) done = true;
53 + if (n >= len - 1)
54 + done = true;
52 55 } break;
53 56 }
54 57 }
  @@ -60,26 +63,31 @@
60 63 I32 j = 0;
61 64 while (*row != '\0') {
62 65 // Skip initial white space
63 - while (*row != '\0' && (*row == ' ' || *row == '\t')) row++;
66 + while (*row != '\0' && (*row == ' ' || *row == '\t'))
67 + row++;
64 68 char* s = row;
65 69 // Find vertex delimiter and terminated the string there for conversion.
66 70 while (*row != '\0' && *row != ' ' && *row != '\t') {
67 - if (*row == '/') *row = '\0';
71 + if (*row == '/')
72 + *row = '\0';
68 73 row++;
69 74 }
70 75
71 - if (*s == '\0') continue;
76 + if (*s == '\0')
77 + continue;
72 78
73 79 I32 vi = atoi(s);
74 80 data[j++] = vi < 0 ? vi + vcnt : vi - 1;
75 - if (j >= n) return j;
81 + if (j >= n)
82 + return j;
76 83 }
77 84 return j;
78 85 }
79 86
80 87 bool loadMeshFile(NavModelData& outData, const char* filename) {
81 88 FILE* fp = fopen(filename, "rb");
82 - if (!fp) return false;
89 + if (!fp)
90 + return false;
83 91
84 92 outData.setName(filename);
85 93 fseek(fp, 0, SEEK_END);
  @@ -108,12 +116,14 @@
108 116 row[0] = '\0';
109 117 src = parseRow(src, srcEnd, row, sizeof(row) / sizeof(char));
110 118 // Skip comments
111 - if (row[0] == '#') continue;
119 + if (row[0] == '#')
120 + continue;
112 121
113 122 if (row[0] == 'v' && row[1] != 'n' && row[1] != 't') {
114 123 // Vertex pos
115 124 result = sscanf(row + 1, "%f %f %f", &x, &y, &z);
116 - if (result != 0) addVertex(&outData, vec3<F32>(x, y, z));
125 + if (result != 0)
126 + addVertex(&outData, vec3<F32>(x, y, z));
117 127 }
118 128 if (row[0] == 'f') {
119 129 // Faces
  @@ -166,16 +176,19 @@
166 176 }
167 177
168 178 bool saveMeshFile(const NavModelData& inData, const char* filename) {
169 - if (!inData.getVertCount() || !inData.getTriCount()) return false;
179 + if (!inData.getVertCount() || !inData.getTriCount())
180 + return false;
170 181
171 182 // Create the file if it doesn't exists
172 183 FILE* fp = nullptr;
173 184 fopen_s(&fp, filename, "w");
174 - if (fp) fclose(fp);
185 + if (fp)
186 + fclose(fp);
175 187
176 188 std::ofstream myfile;
177 189 myfile.open(filename);
178 - if (!myfile.is_open()) return false;
190 + if (!myfile.is_open())
191 + return false;
179 192
180 193 F32* vstart = inData._vertices;
181 194 I32* tstart = inData._triangles;
  @@ -194,7 +207,8 @@
194 207 return true;
195 208 }
196 209
197 - NavModelData mergeModels(NavModelData& a, NavModelData& b,
210 + NavModelData mergeModels(NavModelData& a,
211 + NavModelData& b,
198 212 bool delOriginals /* = false*/) {
199 213 NavModelData mergedData;
200 214 if (a.getVerts() || b.getVerts()) {
  @@ -208,7 +222,8 @@
208 222 I32 totalVertCt = (a.getVertCount() + b.getVertCount());
209 223 I32 newCap = 8;
210 224
211 - while (newCap < totalVertCt) newCap *= 2;
225 + while (newCap < totalVertCt)
226 + newCap *= 2;
212 227
213 228 mergedData._vertices = MemoryManager_NEW F32[newCap * 3];
214 229 mergedData._vertexCapacity = newCap;
  @@ -222,7 +237,8 @@
222 237 I32 totalTriCt = (a.getTriCount() + b.getTriCount());
223 238 newCap = 8;
224 239
225 - while (newCap < totalTriCt) newCap *= 2;
240 + while (newCap < totalTriCt)
241 + newCap *= 2;
226 242
227 243 mergedData._triangles = MemoryManager_NEW I32[newCap * 3];
228 244 mergedData._triangleCapacity = newCap;
  @@ -276,8 +292,10 @@
276 292 modelData->_vertexCount++;
277 293 }
278 294
279 - void addTriangle(NavModelData* modelData, const vec3<U32>& triangleIndices,
280 - U32 triangleIndexOffset, const SamplePolyAreas& areaType) {
295 + void addTriangle(NavModelData* modelData,
296 + const vec3<U32>& triangleIndices,
297 + U32 triangleIndexOffset,
298 + const SamplePolyAreas& areaType) {
281 299 if (modelData->getTriCount() + 1 > modelData->_triangleCapacity) {
282 300 modelData->_triangleCapacity = !modelData->_triangleCapacity
283 301 ? 8
  @@ -309,7 +327,8 @@
309 327 assert(sgn != nullptr);
310 328
311 329 if (sgn->getComponent<NavigationComponent>()->navigationContext() !=
312 - NavigationComponent::NavigationContext::NODE_IGNORE && // Ignore if specified
330 + NavigationComponent::NavigationContext::NODE_IGNORE && // Ignore if
331 + // specified
313 332 box.getHeight() > 0.05f) // Skip small objects
314 333 {
315 334 SceneNode* sn = sgn->getNode();
  @@ -318,14 +337,13 @@
318 337 U32 ignoredNodeType = to_uint(SceneNodeType::TYPE_ROOT) |
319 338 to_uint(SceneNodeType::TYPE_LIGHT) |
320 339 to_uint(SceneNodeType::TYPE_PARTICLE_EMITTER) |
321 - to_uint(SceneNodeType::TYPE_TRIGGER) |
322 - to_uint(SceneNodeType::TYPE_SKY) |
340 + to_uint(SceneNodeType::TYPE_TRIGGER) |
341 + to_uint(SceneNodeType::TYPE_SKY) |
323 342 to_uint(SceneNodeType::TYPE_VEGETATION_GRASS);
324 343
325 - U32 allowedNodeType =
326 - to_uint(SceneNodeType::TYPE_WATER) |
327 - to_uint(SceneNodeType::TYPE_OBJECT3D) |
328 - to_uint(SceneNodeType::TYPE_VEGETATION_TREES);
344 + U32 allowedNodeType = to_uint(SceneNodeType::TYPE_WATER) |
345 + to_uint(SceneNodeType::TYPE_OBJECT3D) |
346 + to_uint(SceneNodeType::TYPE_VEGETATION_TREES);
329 347
330 348 if (!bitCompare(allowedNodeType, to_uint(nodeType))) {
331 349 if (!bitCompare(ignoredNodeType, to_uint(nodeType))) {
  @@ -336,15 +354,16 @@
336 354 }
337 355
338 356 if (nodeType == SceneNodeType::TYPE_OBJECT3D) {
339 - Object3D::ObjectType crtType = dynamic_cast<Object3D*>(sn)->getObjectType();
340 - if (crtType == Object3D::ObjectType::TEXT_3D ||
341 - crtType == Object3D::ObjectType::MESH ||
357 + Object3D::ObjectType crtType =
358 + dynamic_cast<Object3D*>(sn)->getObjectType();
359 + if (crtType == Object3D::ObjectType::TEXT_3D ||
360 + crtType == Object3D::ObjectType::MESH ||
342 361 crtType == Object3D::ObjectType::FLYWEIGHT) {
343 - goto next;
362 + goto next;
344 363 }
345 364 }
346 365
347 - MeshDetailLevel level = MeshDetailLevel::DETAIL_ABSOLUTE;
366 + MeshDetailLevel level = MeshDetailLevel::MAXIMUM;
348 367 VertexBuffer* geometry = nullptr;
349 368 SamplePolyAreas areaType = SamplePolyAreas::SAMPLE_AREA_OBSTACLE;
350 369
  @@ -352,15 +371,16 @@
352 371 case SceneNodeType::TYPE_WATER: {
353 372 if (!sgn->getComponent<NavigationComponent>()
354 373 ->navMeshDetailOverride())
355 - level = MeshDetailLevel::DETAIL_BOUNDINGBOX;
374 + level = MeshDetailLevel::BOUNDINGBOX;
356 375 areaType = SamplePolyAreas::SAMPLE_POLYAREA_WATER;
357 376 } break;
358 377 case SceneNodeType::TYPE_OBJECT3D: {
359 378 // Check if we need to override detail level
360 379 if (!sgn->getComponent<NavigationComponent>()
361 380 ->navMeshDetailOverride() &&
362 - sgn->usageContext() == SceneGraphNode::UsageContext::NODE_STATIC) {
363 - level = MeshDetailLevel::DETAIL_BOUNDINGBOX;
381 + sgn->usageContext() ==
382 + SceneGraphNode::UsageContext::NODE_STATIC) {
383 + level = MeshDetailLevel::BOUNDINGBOX;
364 384 }
365 385 if (dynamic_cast<Object3D*>(sn)->getObjectType() ==
366 386 Object3D::ObjectType::TERRAIN) {
  @@ -383,7 +403,7 @@
383 403
384 404 U32 currentTriangleIndexOffset = outData.getVertCount();
385 405
386 - if (level == MeshDetailLevel::DETAIL_ABSOLUTE) {
406 + if (level == MeshDetailLevel::MAXIMUM) {
387 407 if (nodeType == SceneNodeType::TYPE_OBJECT3D) {
388 408 geometry = dynamic_cast<Object3D*>(sn)->getGeometryVB();
389 409 } else /*nodeType == TYPE_WATER*/ {
  @@ -402,7 +422,8 @@
402 422 dynamic_cast<Object3D*>(sn)->getTriangles();
403 423 if (nodeType != SceneNodeType::TYPE_OBJECT3D ||
404 424 (nodeType == SceneNodeType::TYPE_OBJECT3D &&
405 - dynamic_cast<Object3D*>(sn)->getObjectType() != Object3D::ObjectType::TERRAIN)) {
425 + dynamic_cast<Object3D*>(sn)->getObjectType() !=
426 + Object3D::ObjectType::TERRAIN)) {
406 427 mat4<F32> nodeTransform =
407 428 sgn->getComponent<PhysicsComponent>()->getWorldMatrix();
408 429 for (U32 i = 0; i < vertices.size(); ++i) {
  @@ -422,7 +443,7 @@
422 443 addTriangle(&outData, triangles[i], currentTriangleIndexOffset,
423 444 areaType);
424 445 }
425 - } else if (level == MeshDetailLevel::DETAIL_BOUNDINGBOX) {
446 + } else if (level == MeshDetailLevel::BOUNDINGBOX) {
426 447 const vec3<F32>* vertices = box.getPoints();
427 448
428 449 for (U32 i = 0; i < 8; i++) {
  @@ -440,7 +461,7 @@
440 461 }
441 462 }
442 463 } else {
443 - Console::errorfn(Locale::get("ERROR_RECAST_DETAIL_LEVEL"), level);
464 + Console::errorfn(Locale::get("ERROR_RECAST_LEVEL"), level);
444 465 }
445 466
446 467 Console::printfn(Locale::get("NAV_MESH_ADD_NODE"),