diff --git a/source/simulation2/components/CCmpPathfinder_Vertex.cpp b/source/simulation2/components/CCmpPathfinder_Vertex.cpp
index 6ed042c..de491f7 100644
a
|
b
|
static void AddTerrainEdges(std::vector<Edge>& edges, std::vector<Vertex>& verte
|
361 | 361 | } |
362 | 362 | } |
363 | 363 | |
364 | | // XXX rewrite this stuff |
365 | | |
| 364 | bool Edge1, Edge2, a, b; |
| 365 | int Start1, Start2; |
366 | 366 | for (int j = j0; j < j1; ++j) |
367 | 367 | { |
368 | | std::vector<u16> segmentsR; |
369 | | std::vector<u16> segmentsL; |
| 368 | Edge1 = false; Edge2 = false; Start1 = 0; Start2 = 0; |
370 | 369 | |
371 | 370 | for (int i = i0; i <= i1; ++i) |
372 | 371 | { |
373 | | bool a = IS_PASSABLE(grid.get(i, j+1), passClass); |
374 | | bool b = IS_PASSABLE(grid.get(i, j), passClass); |
375 | | if (a && !b) |
376 | | segmentsL.push_back(i); |
377 | | if (b && !a) |
378 | | segmentsR.push_back(i); |
379 | | } |
| 372 | a = IS_PASSABLE(grid.get(i, j+1), passClass); |
| 373 | b = IS_PASSABLE(grid.get(i, j), passClass); |
380 | 374 | |
381 | | if (!segmentsR.empty()) |
382 | | { |
383 | | segmentsR.push_back(0); // sentinel value to simplify the loop |
384 | | u16 ia = segmentsR[0]; |
385 | | u16 ib = ia + 1; |
386 | | for (size_t n = 1; n < segmentsR.size(); ++n) |
| 375 | if (b && Edge1) // top edge ends here |
387 | 376 | { |
388 | | if (segmentsR[n] == ib) |
389 | | ++ib; |
390 | | else |
391 | | { |
392 | | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(ia), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
393 | | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(ib), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
394 | | edges.emplace_back(Edge{ v0, v1 }); |
395 | | |
396 | | ia = segmentsR[n]; |
397 | | ib = ia + 1; |
398 | | } |
| 377 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 378 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(Start1), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 379 | edges.emplace_back(Edge{ v0, v1 }); |
| 380 | Edge1 = false; |
399 | 381 | } |
400 | | } |
401 | | |
402 | | if (!segmentsL.empty()) |
403 | | { |
404 | | segmentsL.push_back(0); // sentinel value to simplify the loop |
405 | | u16 ia = segmentsL[0]; |
406 | | u16 ib = ia + 1; |
407 | | for (size_t n = 1; n < segmentsL.size(); ++n) |
| 382 | else if (a && !b && !Edge1) // top edge begins here |
408 | 383 | { |
409 | | if (segmentsL[n] == ib) |
410 | | ++ib; |
411 | | else |
412 | | { |
413 | | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(ib), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
414 | | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(ia), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
415 | | edges.emplace_back(Edge{ v0, v1 }); |
| 384 | Start1 = i; |
| 385 | Edge1 = true; |
| 386 | } |
416 | 387 | |
417 | | ia = segmentsL[n]; |
418 | | ib = ia + 1; |
419 | | } |
| 388 | if (a && Edge2) // bottom edge ends here |
| 389 | { |
| 390 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(Start2), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 391 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 392 | edges.emplace_back(Edge{ v0, v1 }); |
| 393 | Edge2 = false; |
| 394 | } |
| 395 | else if (b && !a && !Edge2) // bottom edge begins here |
| 396 | { |
| 397 | Start2 = i; |
| 398 | Edge2 = true; |
420 | 399 | } |
421 | 400 | } |
| 401 | if (Edge1) // end remaining edges |
| 402 | { |
| 403 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i1+1), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 404 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(Start1), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 405 | edges.emplace_back(Edge{ v0, v1 }); |
| 406 | } |
| 407 | if (Edge2) |
| 408 | { |
| 409 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(Start2), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 410 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i1+1), fixed::FromInt(j+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 411 | edges.emplace_back(Edge{ v0, v1 }); |
| 412 | } |
422 | 413 | } |
423 | | |
424 | 414 | for (int i = i0; i < i1; ++i) |
425 | 415 | { |
426 | | std::vector<u16> segmentsU; |
427 | | std::vector<u16> segmentsD; |
| 416 | Edge1 = false; Edge2 = false; Start1 = 0; Start2 = 0; |
428 | 417 | |
429 | 418 | for (int j = j0; j <= j1; ++j) |
430 | 419 | { |
431 | | bool a = IS_PASSABLE(grid.get(i+1, j), passClass); |
432 | | bool b = IS_PASSABLE(grid.get(i, j), passClass); |
433 | | if (a && !b) |
434 | | segmentsU.push_back(j); |
435 | | if (b && !a) |
436 | | segmentsD.push_back(j); |
437 | | } |
| 420 | a = IS_PASSABLE(grid.get(i+1, j), passClass); |
| 421 | b = IS_PASSABLE(grid.get(i, j), passClass); |
438 | 422 | |
439 | | if (!segmentsU.empty()) |
440 | | { |
441 | | segmentsU.push_back(0); // sentinel value to simplify the loop |
442 | | u16 ja = segmentsU[0]; |
443 | | u16 jb = ja + 1; |
444 | | for (size_t n = 1; n < segmentsU.size(); ++n) |
| 423 | if (a && Edge1) // left edge ends here |
445 | 424 | { |
446 | | if (segmentsU[n] == jb) |
447 | | ++jb; |
448 | | else |
449 | | { |
450 | | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(ja)).Multiply(Pathfinding::NAVCELL_SIZE); |
451 | | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(jb)).Multiply(Pathfinding::NAVCELL_SIZE); |
452 | | edges.emplace_back(Edge{ v0, v1 }); |
453 | | |
454 | | ja = segmentsU[n]; |
455 | | jb = ja + 1; |
456 | | } |
| 425 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(Start1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 426 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(j)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 427 | edges.emplace_back(Edge{ v0, v1 }); |
| 428 | Edge1 = false; |
457 | 429 | } |
458 | | } |
459 | | |
460 | | if (!segmentsD.empty()) |
461 | | { |
462 | | segmentsD.push_back(0); // sentinel value to simplify the loop |
463 | | u16 ja = segmentsD[0]; |
464 | | u16 jb = ja + 1; |
465 | | for (size_t n = 1; n < segmentsD.size(); ++n) |
| 430 | else if (b && !a && !Edge1) // left edge begins here |
466 | 431 | { |
467 | | if (segmentsD[n] == jb) |
468 | | ++jb; |
469 | | else |
470 | | { |
471 | | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(jb)).Multiply(Pathfinding::NAVCELL_SIZE); |
472 | | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(ja)).Multiply(Pathfinding::NAVCELL_SIZE); |
473 | | edges.emplace_back(Edge{ v0, v1 }); |
| 432 | Start1 = j; |
| 433 | Edge1 = true; |
| 434 | } |
474 | 435 | |
475 | | ja = segmentsD[n]; |
476 | | jb = ja + 1; |
477 | | } |
| 436 | if (b && Edge2) // right edge ends here |
| 437 | { |
| 438 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(j)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 439 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(Start2)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 440 | edges.emplace_back(Edge{ v0, v1 }); |
| 441 | Edge2 = false; |
| 442 | } |
| 443 | else if (a && !b && !Edge2) // right edge begins here |
| 444 | { |
| 445 | Start2 = j; |
| 446 | Edge2 = true; |
478 | 447 | } |
479 | 448 | } |
| 449 | if (Edge1) |
| 450 | { |
| 451 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(Start1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 452 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(j1+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 453 | edges.emplace_back(Edge{ v0, v1 }); |
| 454 | } |
| 455 | if (Edge2) // end remaining edges |
| 456 | { |
| 457 | CFixedVector2D v0 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(j1+1)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 458 | CFixedVector2D v1 = CFixedVector2D(fixed::FromInt(i+1), fixed::FromInt(Start2)).Multiply(Pathfinding::NAVCELL_SIZE); |
| 459 | edges.emplace_back(Edge{ v0, v1 }); |
| 460 | } |
480 | 461 | } |
481 | 462 | } |
482 | 463 | |