New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
/* Copyright (C) 2015 Wildfire Games.
|
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "precompiled.h"
|
|
|
|
|
|
|
|
#include "Rasterize.h"
|
|
|
|
|
|
|
|
#include "simulation2/helpers/Geometry.h"
|
|
|
|
|
|
|
|
void SimRasterize::RasterizeRectWithClearance(Spans& spans,
|
|
|
|
const ICmpObstructionManager::ObstructionSquare& shape,
|
|
|
|
entity_pos_t clearance, entity_pos_t cellSize)
|
|
|
|
{
|
2015-11-01 08:28:43 +01:00
|
|
|
// A long-standing issue with the pathfinding has been that the long-range one
|
|
|
|
// uses a AA navcell grid, while the short-range uses an accurate vector representation.
|
|
|
|
// This means we could get paths accepted by one but not both pathfinders.
|
|
|
|
// Since the new pathfinder, the short-range pathfinder's representation was usually
|
|
|
|
// encompassing the rasterisation of the long-range one for a building.
|
|
|
|
// This means that we could never get quite as close as the long-range pathfinder wanted.
|
|
|
|
// This could mean units tried going through impassable paths.
|
|
|
|
// To fix this, we need to make sure that the short-range pathfinder is always mostly
|
|
|
|
// included in the rasterisation. The easiest way is to rasterise more, thus this variable
|
|
|
|
// Since this is a very complicated subject, check out logs on 31/10/2015 for more detailled info.
|
|
|
|
// or ask wraitii about it.
|
|
|
|
// If the short-range pathfinder is sufficiently changed, this could become unnecessary and thus removed.
|
|
|
|
// A side effect is that the basic clearance has been set to 0.8, so removing this line should be done
|
|
|
|
// in parallel with setting clearance back to 1 for the default passability class (though this isn't strictly necessary).
|
|
|
|
// Also: the code detecting foundation obstruction in CcmpObstructionManager had to be changed similarly.
|
|
|
|
entity_pos_t rasterClearance = clearance + entity_pos_t::FromInt(1);
|
|
|
|
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
// Get the bounds of cells that might possibly be within the shape
|
|
|
|
// (We'll then test each of those cells more precisely)
|
2015-11-01 08:28:43 +01:00
|
|
|
CFixedVector2D halfSize(shape.hw + rasterClearance, shape.hh + rasterClearance);
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
CFixedVector2D halfBound = Geometry::GetHalfBoundingBox(shape.u, shape.v, halfSize);
|
2015-09-27 18:46:26 +02:00
|
|
|
i16 i0 = ((shape.x - halfBound.X) / cellSize).ToInt_RoundToNegInfinity();
|
|
|
|
i16 j0 = ((shape.z - halfBound.Y) / cellSize).ToInt_RoundToNegInfinity();
|
|
|
|
i16 i1 = ((shape.x + halfBound.X) / cellSize).ToInt_RoundToInfinity();
|
|
|
|
i16 j1 = ((shape.z + halfBound.Y) / cellSize).ToInt_RoundToInfinity();
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
if (j1 <= j0)
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
return; // empty bounds - this shouldn't happen
|
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
spans.reserve(j1 - j0);
|
2015-11-01 08:28:43 +01:00
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
for (i16 j = j0; j < j1; ++j)
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
{
|
2015-11-06 20:48:08 +01:00
|
|
|
// Find the min/max range of cells that are strictly inside the square+rasterClearance.
|
|
|
|
// (Since the square+rasterClearance is a convex shape, we can just test each
|
2015-09-27 18:46:26 +02:00
|
|
|
// corner of each cell is inside the shape.)
|
|
|
|
// (TODO: This potentially does a lot of redundant work.)
|
|
|
|
i16 spanI0 = std::numeric_limits<i16>::max();
|
|
|
|
i16 spanI1 = std::numeric_limits<i16>::min();
|
|
|
|
for (i16 i = i0; i < i1; ++i)
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
{
|
2015-09-27 18:46:26 +02:00
|
|
|
if (Geometry::DistanceToSquare(
|
|
|
|
CFixedVector2D(cellSize*i, cellSize*j) - CFixedVector2D(shape.x, shape.z),
|
2015-11-01 08:28:43 +01:00
|
|
|
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
{
|
2015-09-27 18:46:26 +02:00
|
|
|
continue;
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
if (Geometry::DistanceToSquare(
|
|
|
|
CFixedVector2D(cellSize*(i+1), cellSize*j) - CFixedVector2D(shape.x, shape.z),
|
2015-11-01 08:28:43 +01:00
|
|
|
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
|
2015-09-27 18:46:26 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
if (Geometry::DistanceToSquare(
|
|
|
|
CFixedVector2D(cellSize*i, cellSize*(j+1)) - CFixedVector2D(shape.x, shape.z),
|
2015-11-01 08:28:43 +01:00
|
|
|
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
|
2015-09-27 18:46:26 +02:00
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
if (Geometry::DistanceToSquare(
|
|
|
|
CFixedVector2D(cellSize*(i+1), cellSize*(j+1)) - CFixedVector2D(shape.x, shape.z),
|
2015-11-01 08:28:43 +01:00
|
|
|
shape.u, shape.v, CFixedVector2D(shape.hw, shape.hh), true) > rasterClearance)
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
{
|
2015-09-27 18:46:26 +02:00
|
|
|
continue;
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
}
|
2015-09-27 18:46:26 +02:00
|
|
|
|
|
|
|
spanI0 = std::min(spanI0, i);
|
|
|
|
spanI1 = std::max(spanI1, (i16)(i+1));
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
}
|
|
|
|
|
2015-09-27 18:46:26 +02:00
|
|
|
// Add non-empty spans onto the list
|
|
|
|
if (spanI0 < spanI1)
|
|
|
|
{
|
|
|
|
Span span = { spanI0, spanI1, j };
|
|
|
|
spans.push_back(span);
|
|
|
|
}
|
New long-range pathfinder.
Based on Philip's work located at
http://git.wildfiregames.com/gitweb/?p=0ad.git;a=shortlog;h=refs/heads/projects/philip/pathfinder
Includes code by wraitii, sanderd17 and kanetaka.
An updated version of docs/pathfinder.pdf describing the changes in
detail will be committed ASAP.
Running update-workspaces is needed after this change.
Fixes #1756.
Fixes #930, #1259, #2908, #2960, #3097
Refs #1200, #1914, #1942, #2568, #2132, #2563
This was SVN commit r16751.
2015-06-12 20:58:24 +02:00
|
|
|
}
|
|
|
|
}
|