move start and target to env
parent
ddad4d9370
commit
054c8dc459
|
@ -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)
|
private void setPositionData(ScriptRequestData requestData, Vector3 position, int walkable, int isTarget, int isStart)
|
||||||
{
|
{
|
||||||
lock(m_environments)
|
lock(m_environments)
|
||||||
|
@ -253,17 +203,11 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
if (_env != null)
|
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);
|
PathNode _node = _env.Nodes.Find(X => X.PositionX == (int)position.X && X.PositionY == (int)position.Y);
|
||||||
|
|
||||||
if (_node == null)
|
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);
|
_env.Nodes.Add(_node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,16 +218,10 @@ namespace OpenSim.Modules.PathFinding
|
||||||
_node.Walkable = false;
|
_node.Walkable = false;
|
||||||
|
|
||||||
if (isTarget == 1)
|
if (isTarget == 1)
|
||||||
_node.Target = true;
|
_env.Target = _node;
|
||||||
|
|
||||||
if (isTarget == 0)
|
|
||||||
_node.Target = false;
|
|
||||||
|
|
||||||
if (isStart == 1)
|
if (isStart == 1)
|
||||||
_node.Start = true;
|
_env.Start = _node;
|
||||||
|
|
||||||
if (isStart == 0)
|
|
||||||
_node.Start = false;
|
|
||||||
|
|
||||||
return;
|
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)
|
private void generatePath(ScriptRequestData requestData)
|
||||||
{
|
{
|
||||||
lock (m_environments)
|
lock (m_environments)
|
||||||
{
|
{
|
||||||
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
Environment _env = m_environments.Find(X => X.ID == requestData.EnvironmentID);
|
||||||
|
|
||||||
PathNode _startNode = getStartNode(requestData);
|
if(_env.Start != null && _env.Target != null)
|
||||||
PathNode _targetNode = getTargetNode(requestData);
|
|
||||||
|
|
||||||
if(_startNode != null && _targetNode != null)
|
|
||||||
{
|
{
|
||||||
GridSize _pathFindingGridSize = new GridSize(_env.Size, _env.Size);
|
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));
|
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();
|
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 = "";
|
String _pathString = "";
|
||||||
int lastX = 0;
|
int lastX = 0;
|
||||||
|
@ -496,9 +399,6 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
if (!thisNode.Walkable)
|
if (!thisNode.Walkable)
|
||||||
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Black);
|
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Black);
|
||||||
|
|
||||||
if (thisNode.Target)
|
|
||||||
_bitmap.SetPixel(thisNode.PositionX, thisNode.PositionY, Color.Blue);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_bitmap.Save(requestData.EnvironmentID + ".png");
|
_bitmap.Save(requestData.EnvironmentID + ".png");
|
||||||
|
|
|
@ -14,6 +14,9 @@ namespace OpenSim.Modules.PathFinding
|
||||||
public int Size = 0;
|
public int Size = 0;
|
||||||
public int LastTimeUsed = 0;
|
public int LastTimeUsed = 0;
|
||||||
|
|
||||||
|
public PathNode Start = null;
|
||||||
|
public PathNode Target = null;
|
||||||
|
|
||||||
private List<PathNode> m_nodes = new List<PathNode>();
|
private List<PathNode> m_nodes = new List<PathNode>();
|
||||||
public List<PathNode> Nodes
|
public List<PathNode> Nodes
|
||||||
{
|
{
|
||||||
|
|
|
@ -12,8 +12,6 @@ namespace OpenSim.Modules.PathFinding
|
||||||
public int PositionY = 0;
|
public int PositionY = 0;
|
||||||
|
|
||||||
public bool Walkable = false;
|
public bool Walkable = false;
|
||||||
public bool Target = false;
|
|
||||||
public bool Start = false;
|
|
||||||
|
|
||||||
public int f_cost = 99999;
|
public int f_cost = 99999;
|
||||||
|
|
||||||
|
@ -32,15 +30,5 @@ namespace OpenSim.Modules.PathFinding
|
||||||
|
|
||||||
Walkable = isWalkable;
|
Walkable = isWalkable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public PathNode(int positionX, int positionY, bool isWalkable, bool isTarget, bool isStart)
|
|
||||||
{
|
|
||||||
PositionX = positionX;
|
|
||||||
PositionY = positionY;
|
|
||||||
|
|
||||||
Walkable = isWalkable;
|
|
||||||
Target = isTarget;
|
|
||||||
Start = isStart;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue