private static void detectCycles(List <IObject> displayList) { if (!_detectCycles) { return; } _detectCycles = false; RenderOrderSelector comparer = new RenderOrderSelector(); Dictionary <string, List <string> > map = new Dictionary <string, List <string> >(); for (int i = 0; i < displayList.Count; i++) { for (int j = i + 1; j < displayList.Count; j++) { int result = comparer.Compare(displayList[i], displayList[j]); if (result == 0) { continue; } if (result > 0) { map.GetOrAdd(displayList[i].ID, () => new List <string>()).Add(displayList[j].ID); } else { map.GetOrAdd(displayList[j].ID, () => new List <string>()).Add(displayList[i].ID); } } } HashSet <string> visited = new HashSet <string>(); Dictionary <string, List <string> > recStack = new Dictionary <string, List <string> >(); foreach (var item in displayList) { List <string> chain = findCycle(item.ID, map, visited, recStack); if (chain != null) { Debug.WriteLine($"Cycle detected: {string.Join("=>", chain)}"); return; } } Debug.WriteLine("No cycles detected."); }
public AGSRoom(string id, IViewport viewport, IAGSEdges edges, IGameEvents gameEvents, IRoomEvents roomEvents, IGameState state, ICustomProperties properties, IRoomLimitsProvider roomLimitsProvider) { _sorter = new RenderOrderSelector { Backwards = true }; _state = state; RoomLimitsProvider = roomLimitsProvider; _gameEvents = gameEvents; Viewport = viewport; Events = roomEvents; ID = id; Objects = new AGSConcurrentHashSet <IObject> (); Areas = new List <IArea> (); ShowPlayer = true; _edges = edges; Properties = properties; gameEvents.OnRepeatedlyExecute.Subscribe(onRepeatedlyExecute); }