Skip to content

Commit

Permalink
Potential fix for #60
Browse files Browse the repository at this point in the history
Removed need for reflection in snj serialization
  • Loading branch information
Robmaister committed Jul 5, 2016
1 parent fe177a2 commit e492005
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 400 deletions.
113 changes: 35 additions & 78 deletions Source/SharpNav.Examples/ExampleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,8 @@ private void GeneratePathfinding()
List<NavPolyId> visited = new List<NavPolyId>(16);
NavPoint startPoint = new NavPoint(path[0], iterPos);
navMeshQuery.MoveAlongSurface(ref startPoint, ref moveTgt, out result, visited);
npolys = FixupCorridor(path, MAX_POLYS, visited);
path.FixupCorridor(visited);
npolys = path.Count;
float h = 0;
navMeshQuery.GetPolyHeight(path[0], result, ref h);
result.Y = h;
Expand Down Expand Up @@ -649,39 +650,39 @@ private void VMad(ref SVector3 dest, SVector3 v1, SVector3 v2, float s)
dest.Z = v1.Z + v2.Z * s;
}

private bool GetSteerTarget(NavMeshQuery navMeshQuery, SVector3 startPos, SVector3 endPos, float minTargetDist, SharpNav.Pathfinding.Path path,
ref SVector3 steerPos, ref StraightPathFlags steerPosFlag, ref NavPolyId steerPosRef)
{
StraightPath steerPath = new StraightPath();
navMeshQuery.FindStraightPath(startPos, endPos, path, steerPath, 0);
int nsteerPath = steerPath.Count;
if (nsteerPath == 0)
return false;

//find vertex far enough to steer to
int ns = 0;
while (ns < nsteerPath)
{
if ((steerPath[ns].Flags & StraightPathFlags.OffMeshConnection) != 0 ||
!InRange(steerPath[ns].Point.Position, startPos, minTargetDist, 1000.0f))
break;

ns++;
}

//failed to find good point to steer to
if (ns >= nsteerPath)
return false;

steerPos = steerPath[ns].Point.Position;
steerPos.Y = startPos.Y;
steerPosFlag = steerPath[ns].Flags;
if (steerPosFlag == StraightPathFlags.None && ns == (nsteerPath - 1))
steerPosFlag = StraightPathFlags.End; // otherwise seeks path infinitely!!!
steerPosRef = steerPath[ns].Point.Polygon;

return true;
}
private bool GetSteerTarget(NavMeshQuery navMeshQuery, SVector3 startPos, SVector3 endPos, float minTargetDist, SharpNav.Pathfinding.Path path,
ref SVector3 steerPos, ref StraightPathFlags steerPosFlag, ref NavPolyId steerPosRef)
{
StraightPath steerPath = new StraightPath();
navMeshQuery.FindStraightPath(startPos, endPos, path, steerPath, 0);
int nsteerPath = steerPath.Count;
if (nsteerPath == 0)
return false;

//find vertex far enough to steer to
int ns = 0;
while (ns < nsteerPath)
{
if ((steerPath[ns].Flags & StraightPathFlags.OffMeshConnection) != 0 ||
!InRange(steerPath[ns].Point.Position, startPos, minTargetDist, 1000.0f))
break;

ns++;
}

//failed to find good point to steer to
if (ns >= nsteerPath)
return false;

steerPos = steerPath[ns].Point.Position;
steerPos.Y = startPos.Y;
steerPosFlag = steerPath[ns].Flags;
if (steerPosFlag == StraightPathFlags.None && ns == (nsteerPath - 1))
steerPosFlag = StraightPathFlags.End; // otherwise seeks path infinitely!!!
steerPosRef = steerPath[ns].Point.Polygon;

return true;
}

private bool InRange(SVector3 v1, SVector3 v2, float r, float h)
{
Expand All @@ -691,50 +692,6 @@ private bool InRange(SVector3 v1, SVector3 v2, float r, float h)
return (dx * dx + dz * dz) < (r * r) && Math.Abs(dy) < h;
}

private int FixupCorridor(Path path, int maxPath, List<NavPolyId> visited)
{
int furthestPath = -1;
int furthestVisited = -1;

//find furhtest common polygon
for (int i = path.Count - 1; i >= 0; i--)
{
bool found = false;
for (int j = visited.Count - 1; j >= 0; j--)
{
if (path[i] == visited[j])
{
furthestPath = i;
furthestVisited = j;
found = true;
}
}

if (found)
break;
}

//if no intersection found, return current path
if (furthestPath == -1 || furthestVisited == -1)
return path.Count;

//concatenate paths
//adjust beginning of the buffer to include the visited
int req = visited.Count - furthestVisited;
int orig = Math.Min(furthestPath + 1, path.Count);
int size = Math.Max(0, path.Count - orig);
if (req + size > maxPath)
size = maxPath - req;
for (int i = 0; i < size; i++)
path[req + i] = path[orig + i];

//store visited
for (int i = 0; i < req; i++)
path[i] = visited[(visited.Count - 1) - i];

return req + size;
}

private void GenerateCrowd()
{
if (!hasGenerated || navMeshQuery == null)
Expand Down
242 changes: 0 additions & 242 deletions Source/SharpNav.Examples/PlyModel.cs

This file was deleted.

1 change: 0 additions & 1 deletion Source/SharpNav.Examples/SharpNav.Examples.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
<ItemGroup>
<Compile Include="AgentCylinder.cs" />
<Compile Include="Camera.cs" />
<Compile Include="PlyModel.cs" />
<Compile Include="ExampleWindow.cs" />
<Compile Include="ExampleWindow.Drawing.cs" />
<Compile Include="ExampleWindow.UI.cs" />
Expand Down
Loading

0 comments on commit e492005

Please sign in to comment.