private void RunUpdate(ref SensorDetectingNode node) { var sensor = node.Sensor; sensor.DetectedCells.Clear(); var start = node.Position.Position; sensor.LastDetectedCenter = start; var fwd = node.Tr.ForwardDirection2D(); var ls = World.Get <LineOfSightSystem>(); for (int i = 0; i < DirectionsExtensions.Length2D; i++) { var dir = (Directions)i; var maxRowDistance = dir == fwd ? sensor.MaxVisionDistance : sensor.MaxHearDistance; var adjacent = dir.Adjacent(); ShadowFloodFill.CheckRow( ref sensor.DetectedCells, start, start, maxRowDistance, new[] { adjacent[0].ToPoint3(), adjacent[1].ToPoint3() }, dir.ToPoint3()); } for (int i = 0; i < _occupyNodes.Max; i++) { if (_occupyNodes.IsInvalid(i)) { continue; } var visible = _occupyNodes[i]; if (visible.Entity == node.Entity) { continue; } if (!sensor.DetectedCells.Contains(visible.Position)) { continue; } var isVision = true; if (CheckVision) { ls.CanSeeOrHear(node.Entity, visible.Entity, out isVision); } sensor.AddWatch(visible.Entity, isVision); } for (int w = sensor.WatchTargets.Count - 1; w >= 0; w--) { if (sensor.WatchTargets[w].Target == null) { sensor.RemoveWatch(sensor.WatchTargets[w]); continue; } sensor.WatchTargets[w].LastSensedTurnCount++; if (sensor.WatchTargets[w].LastSensedTurnCount > MaxTurnsNpcVisible) { sensor.RemoveWatch(sensor.WatchTargets[w]); } } }
public void UpdateSenses() { //var watch = new System.Diagnostics.Stopwatch(); //watch.Start(); //ShadowFloodFill.GetVisiblePoints(Tr.position.ToCellGridP3(), MaxHearDistance, UpdateCellMapVisible, CurrentList.Contains); //watch.Stop(); //Debug.LogFormat("Found {0} in {1}" ,CurrentList.Count, watch.Elapsed.TotalMilliseconds); var owner = this.GetEntity(); var start = owner.Get <GridPosition>().Value; var fwd = owner.Get <TransformComponent>().ForwardDirection2D(); for (int i = 0; i < DirectionsExtensions.Length2D; i++) { var dir = (Directions)i; var maxRowDistance = dir == fwd ? MaxVisionDistance : MaxHearDistance; var adjacent = dir.Adjacent(); ShadowFloodFill.CheckRow( start, start, maxRowDistance, UpdateCellMapVisible, Cells.Contains, new[] { adjacent[0].ToPoint3(), adjacent[1].ToPoint3() }, dir.ToPoint3()); } UpdateWatchTargets(); OnUpdate?.Invoke(); }
public void OnPeriodicUpdate() { if (_visibleNodes == null) { _visibleNodes = EntityController.GetNodeList <UnitOccupyingCellNode>(); } if (_sensorList == null) { _sensorList = EntityController.GetNodeList <SensorDetectingNode>(); } if (_visibleNodes == null || _sensorList == null || !Game.GameActive || Game.Paused) { return; } var ls = World.Get <LineOfSightSystem>(); for (int n = 0; n < _sensorList.Count; n++) { var node = _sensorList[n]; var sensor = node.Sensor.c; sensor.DetectedCells.Clear(); var start = node.Position.c.Position; sensor.LastDetectedCenter = start; var fwd = node.Entity.Tr.ForwardDirection2D(); for (int i = 0; i < DirectionsExtensions.Length2D; i++) { var dir = (Directions)i; var maxRowDistance = dir == fwd ? sensor.MaxVisionDistance : sensor.MaxHearDistance; var adjacent = dir.Adjacent(); ShadowFloodFill.CheckRow(ref sensor.DetectedCells, start, start, maxRowDistance, new[] { adjacent[0].ToPoint3(), adjacent[1].ToPoint3() }, dir.ToPoint3()); } for (int i = 0; i < _visibleNodes.Count; i++) { var visible = _visibleNodes[i]; if (visible.Entity == node.Entity) { continue; } if (!sensor.DetectedCells.Contains(visible.Position.c)) { continue; } var isVision = true; if (CheckVision) { ls.CanSeeOrHear(node.Entity, visible.Entity, out isVision); } sensor.AddWatch(visible.Entity, isVision); } for (int w = sensor.WatchTargets.Count - 1; w >= 0; w--) { if (sensor.WatchTargets[w].Target == null) { sensor.RemoveWatch(sensor.WatchTargets[w]); continue; } sensor.WatchTargets[w].LastSensedTurnCount++; if (sensor.WatchTargets[w].LastSensedTurnCount > MaxTurnsNpcVisible) { sensor.RemoveWatch(sensor.WatchTargets[w]); } } } }