From 054c8dc459a228bd165767ebaae5a421d0b75c9c Mon Sep 17 00:00:00 2001 From: Christopher Date: Tue, 23 Jun 2020 16:24:33 +0200 Subject: [PATCH] move start and target to env --- src/BasicPathFinding.cs | 110 ++-------------------------------------- src/Environment.cs | 3 ++ src/PathNode.cs | 12 ----- 3 files changed, 8 insertions(+), 117 deletions(-) diff --git a/src/BasicPathFinding.cs b/src/BasicPathFinding.cs index b4fefe6..d624d38 100644 --- a/src/BasicPathFinding.cs +++ b/src/BasicPathFinding.cs @@ -192,56 +192,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 _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 _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) { @@ -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"); diff --git a/src/Environment.cs b/src/Environment.cs index b25ec47..a012df7 100644 --- a/src/Environment.cs +++ b/src/Environment.cs @@ -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 m_nodes = new List(); public List Nodes { diff --git a/src/PathNode.cs b/src/PathNode.cs index 292e03f..3e2c224 100644 --- a/src/PathNode.cs +++ b/src/PathNode.cs @@ -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; - } } }