move start and target to env

master
Christopher 2020-06-23 16:24:33 +02:00
parent ddad4d9370
commit 054c8dc459
3 changed files with 8 additions and 117 deletions

View File

@ -193,56 +193,6 @@ namespace OpenSim.Modules.PathFinding
}
}
private void removeAllTargets(ScriptRequestData requestData)
{
lock(m_environments)
{
try
{
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
if (_env != null)
{
List<PathNode> _nodes = _env.Nodes.FindAll(X => X.Target == true);
foreach (PathNode thisNode in _nodes)
{
thisNode.Target = false;
}
}
}
catch (Exception _error)
{
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
}
}
}
private void removeAllStarts(ScriptRequestData requestData)
{
lock (m_environments)
{
try
{
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
if (_env != null)
{
List<PathNode> _nodes = _env.Nodes.FindAll(X => X.Start == true);
foreach (PathNode thisNode in _nodes)
{
thisNode.Start = false;
}
}
}
catch (Exception _error)
{
m_scriptModule.DispatchReply(requestData.ScriptID, 19860, _error.Message, requestData.RequestID.ToString());
}
}
}
private void setPositionData(ScriptRequestData requestData, Vector3 position, int walkable, int isTarget, int isStart)
{
lock(m_environments)
@ -253,17 +203,11 @@ namespace OpenSim.Modules.PathFinding
if (_env != null)
{
if (isTarget == 1)
removeAllTargets(requestData);
if (isStart == 1)
removeAllStarts(requestData);
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)position.X && X.PositionY == (int)position.Y);
if (_node == null)
{
_node = new PathNode((int)position.X, (int)position.Y, false, false, false);
_node = new PathNode((int)position.X, (int)position.Y, false);
_env.Nodes.Add(_node);
}
@ -274,16 +218,10 @@ namespace OpenSim.Modules.PathFinding
_node.Walkable = false;
if (isTarget == 1)
_node.Target = true;
if (isTarget == 0)
_node.Target = false;
_env.Target = _node;
if (isStart == 1)
_node.Start = true;
if (isStart == 0)
_node.Start = false;
_env.Start = _node;
return;
}
@ -380,48 +318,13 @@ namespace OpenSim.Modules.PathFinding
}
}
private PathNode getStartNode(ScriptRequestData requestData)
{
lock (m_environments)
{
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
if (_env != null)
{
PathNode _startNode = _env.Nodes.Find(X => X.Start == true);
return _startNode;
}
}
return null;
}
private PathNode getTargetNode(ScriptRequestData requestData)
{
lock (m_environments)
{
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
if (_env != null)
{
PathNode _startNode = _env.Nodes.Find(X => X.Target == true);
return _startNode;
}
}
return null;
}
private void generatePath(ScriptRequestData requestData)
{
lock (m_environments)
{
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
PathNode _startNode = getStartNode(requestData);
PathNode _targetNode = getTargetNode(requestData);
if(_startNode != null && _targetNode != null)
if(_env.Start != null && _env.Target != null)
{
GridSize _pathFindingGridSize = new GridSize(_env.Size, _env.Size);
Roy_T.AStar.Primitives.Size _pathFindingCellSize = new Roy_T.AStar.Primitives.Size(Distance.FromMeters(1), Distance.FromMeters(1));
@ -441,7 +344,7 @@ namespace OpenSim.Modules.PathFinding
}
PathFinder pathFinder = new PathFinder();
Path _pathFindingPath = pathFinder.FindPath(new GridPosition(_startNode.PositionX, _startNode.PositionY), new GridPosition(_targetNode.PositionX, _targetNode.PositionY), _pathFindingGrid);
Path _pathFindingPath = pathFinder.FindPath(new GridPosition(_env.Start.PositionX, _env.Start.PositionY), new GridPosition(_env.Target.PositionX, _env.Target.PositionY), _pathFindingGrid);
String _pathString = "";
int lastX = 0;
@ -496,9 +399,6 @@ namespace OpenSim.Modules.PathFinding
if (!thisNode.Walkable)
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Black);
if (thisNode.Target)
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Blue);
}
_bitmap.Save(requestData.EnvironmentID + ".png");

View File

@ -14,6 +14,9 @@ namespace OpenSim.Modules.PathFinding
public int Size = 0;
public int LastTimeUsed = 0;
public PathNode Start = null;
public PathNode Target = null;
private List<PathNode> m_nodes = new List<PathNode>();
public List<PathNode> Nodes
{

View File

@ -12,8 +12,6 @@ namespace OpenSim.Modules.PathFinding
public int PositionY = 0;
public bool Walkable = false;
public bool Target = false;
public bool Start = false;
public int f_cost = 99999;
@ -32,15 +30,5 @@ namespace OpenSim.Modules.PathFinding
Walkable = isWalkable;
}
public PathNode(int positionX, int positionY, bool isWalkable, bool isTarget, bool isStart)
{
PositionX = positionX;
PositionY = positionY;
Walkable = isWalkable;
Target = isTarget;
Start = isStart;
}
}
}