protected override void OnForcedCleanUp() { instance = null; partitioner.FreeResources(); partitioner = null; solidChangedLayer = null; liquidChangedLayer = null; digDestroyedLayer = null; fogOfWarChangedLayer = null; decorProviderLayer = null; attackableEntitiesLayer = null; fetchChoreLayer = null; pickupablesLayer = null; pickupablesChangedLayer = null; gasConduitsLayer = null; liquidConduitsLayer = null; solidConduitsLayer = null; noisePolluterLayer = null; validNavCellChangedLayer = null; dirtyNavCellUpdateLayer = null; trapsLayer = null; floorSwitchActivatorLayer = null; floorSwitchActivatorChangedLayer = null; objectLayers = null; }
protected override void OnSpawn() { base.OnSpawn(); _spawned = true; Debug.Log($"[MultiIO] ConduitIO.OnSpawn() -> ConduitType: {ConduitType.ToString()} CellOffset: {CellOffset.x + "," + CellOffset.y}"); portCell = GetPortCell(); MultiIOExtensions.RegisterPort(portCell, this); //Register an event listener for any changes to the grid at the location of this port. ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(int)GetConduitObjectLayer()]; partitionerEntry = GameScenePartitioner.Instance.Add("ConduitIO.OnSpawn", _parent, portCell, layer, delegate { UpdateConduitExistsStatus(); }); //Register this conduit to the relevant network. Allows the network to determine flow direction. IUtilityNetworkMgr networkManager = GetNetworkManager(); _networkItem = new FlowUtilityNetwork.NetworkItem(ConduitType, EndpointType, portCell, _parent); networkManager.AddToNetworks(portCell, _networkItem, EndpointType != Endpoint.Conduit); if (UseConduitUpdater) { GetConduitManager().AddConduitUpdater(ConduitTick, FlowPriority); } UpdateConduitExistsStatus(true); }
public void GatherEntries(int x, int y, int width, int height, ScenePartitionerLayer layer, object event_data, List <ScenePartitionerEntry> gathered_entries, int query_id) { Extents nodeExtents = GetNodeExtents(x, y, width, height); int num = Math.Min(nodeExtents.y + nodeExtents.height, nodes.GetLength(1)); int num2 = Math.Max(nodeExtents.y, 0); int num3 = Math.Max(nodeExtents.x, 0); int num4 = Math.Min(nodeExtents.x + nodeExtents.width, nodes.GetLength(2)); int layer2 = layer.layer; for (int i = num2; i < num; i++) { for (int j = num3; j < num4; j++) { int count = nodes[layer2, i, j].entries.Count; for (int k = 0; k < count; k++) { ScenePartitionerEntry scenePartitionerEntry = nodes[layer2, i, j].entries[k]; if (scenePartitionerEntry != null && scenePartitionerEntry.queryId != queryId) { if (scenePartitionerEntry.obj == null) { nodes[layer2, i, j].entries[k] = null; } else if (x + width - 1 >= scenePartitionerEntry.x && x <= scenePartitionerEntry.x + scenePartitionerEntry.width - 1 && y + height - 1 >= scenePartitionerEntry.y && y <= scenePartitionerEntry.y + scenePartitionerEntry.height - 1) { scenePartitionerEntry.queryId = queryId; gathered_entries.Add(scenePartitionerEntry); } } } } } }
protected override void OnSpawn() { base.OnSpawn(); ScenePartitionerLayer scenePartitionerLayer = null; Building component = GetComponent <Building>(); utilityCell = component.GetUtilityOutputCell(); conduitType = component.Def.OutputConduitType; switch (component.Def.OutputConduitType) { case ConduitType.Gas: scenePartitionerLayer = GameScenePartitioner.Instance.gasConduitsLayer; break; case ConduitType.Liquid: scenePartitionerLayer = GameScenePartitioner.Instance.liquidConduitsLayer; break; case ConduitType.Solid: scenePartitionerLayer = GameScenePartitioner.Instance.solidConduitsLayer; break; } UpdateConnectionState(true); UpdatePipeRoomState(true); if (scenePartitionerLayer != null) { partitionerEntry = GameScenePartitioner.Instance.Add("RequireOutputs", base.gameObject, utilityCell, scenePartitionerLayer, delegate { UpdateConnectionState(false); }); } GetConduitFlow().AddConduitUpdater(UpdatePipeState, ConduitFlowPriority.First); }
public void Iterate <IteratorType>(int cell, int radius, ScenePartitionerLayer layer, ref IteratorType iterator) where IteratorType : Iterator { int x = 0; int y = 0; Grid.CellToXY(cell, out x, out y); Iterate(x - radius, y - radius, radius * 2, radius * 2, layer, ref iterator); }
public void TriggerEvent(int cell, ScenePartitionerLayer layer, object event_data) { int x = 0; int y = 0; Grid.CellToXY(cell, out x, out y); TriggerEvent(x, y, 1, 1, layer, event_data); }
public HandleVector <int> .Handle Add(string name, object obj, int cell, ScenePartitionerLayer layer, Action <object> event_callback) { int x = 0; int y = 0; Grid.CellToXY(cell, out x, out y); return(Add(name, obj, x, y, 1, 1, layer, event_callback)); }
public void TriggerEvent(int x, int y, int width, int height, ScenePartitionerLayer layer, object event_data) { ListPool <ScenePartitionerEntry, ScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, ScenePartitioner> .Allocate(); GatherEntries(x, y, width, height, layer, event_data, pooledList); RunLayerGlobalEvent(x, y, width, height, layer, event_data); RunEntries(pooledList, event_data); pooledList.Recycle(); }
private void RunLayerGlobalEvent(HashSet <int> cells, ScenePartitionerLayer layer, object event_data) { if (layer.OnEvent != null) { foreach (int cell in cells) { layer.OnEvent(cell, event_data); } } }
protected override void OnSpawn() { base.OnSpawn(); this.utilityCell = base.GetComponent <Building>().GetUtilityOutputCell(); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12]; this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, new Action <object>(this.OnConduitConnectionChanged)); this.GetConduitManager().AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Last); this.OnConduitConnectionChanged(null); }
protected override void OnSpawn() { base.OnSpawn(); utilityCell = GetComponent <Building>().GetUtilityOutputCell(); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(conduitType != ConduitType.Gas) ? 16 : 12]; partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, utilityCell, layer, OnConduitConnectionChanged); GetConduitManager().AddConduitUpdater(ConduitUpdate, ConduitFlowPriority.Last); OnConduitConnectionChanged(null); }
private void RunLayerGlobalEvent(List <int> cells, ScenePartitionerLayer layer, object event_data) { if (layer.OnEvent != null) { for (int i = 0; i < cells.Count; i++) { layer.OnEvent(cells[i], event_data); } } }
protected override void OnSpawn() { base.OnSpawn(); utilityCell = building.GetUtilityInputCell(); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[20]; partitionerEntry = GameScenePartitioner.Instance.Add("SolidConduitConsumer.OnSpawn", base.gameObject, utilityCell, layer, OnConduitConnectionChanged); GetConduitFlow().AddConduitUpdater(ConduitUpdate, ConduitFlowPriority.Default); OnConduitConnectionChanged(null); }
protected override void OnSpawn() { Debug.LogWarning("ConduitConsumer - OnSpawn"); base.OnSpawn(); this.utilityCell = this.building.GetUtilityInputCell(); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12]; this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, this.OnConduitConnectionChanged); this.GetConduitManager().AddConduitUpdater(this.ConduitUpdate, ConduitFlowPriority.Default); this.OnConduitConnectionChanged(null); }
public void Iterate <IteratorType>(int x, int y, int width, int height, ScenePartitionerLayer layer, ref IteratorType iterator) where IteratorType : Iterator { ListPool <ScenePartitionerEntry, GameScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, GameScenePartitioner> .Allocate(); Instance.GatherEntries(x, y, width, height, layer, pooledList); for (int i = 0; i < ((List <ScenePartitionerEntry>)pooledList).Count; i++) { ScenePartitionerEntry scenePartitionerEntry = ((List <ScenePartitionerEntry>)pooledList)[i]; iterator.Iterate(scenePartitionerEntry.obj); } pooledList.Recycle(); }
/// <summary> /// Adds a light's scene change partitioner to a layer. /// </summary> /// <param name="instance">The light to add.</param> /// <param name="minCoords">The coordinates of the upper left corner.</param> /// <param name="rad">The light "radius" (square).</param> /// <param name="layer">The layer to add it on.</param> /// <returns>A handle to the change partitioner, or InvalidHandle if it could not be /// added.</returns> private static IntHandle AddToLayer(Light2D instance, Vector2I minCoords, int rad, ScenePartitionerLayer layer) { var handle = IntHandle.InvalidHandle; if (ADD_TO_LAYER?.Invoke(instance, new object[] { minCoords, 2 * rad, 2 * rad, layer }) is IntHandle newHandle) { handle = newHandle; } return(handle); }
public ScenePartitionerLayer CreateMask(HashedString name) { foreach (ScenePartitionerLayer layer in layers) { if (layer.name == name) { return(layer); } } ScenePartitionerLayer scenePartitionerLayer = new ScenePartitionerLayer(name, layers.Count); layers.Add(scenePartitionerLayer); DebugUtil.Assert(layers.Count <= nodes.GetLength(0)); return(scenePartitionerLayer); }
protected override void OnSpawn() { base.OnSpawn(); this.utilityCell = this.GetInputCell(); IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.conduitType); this.networkItem = new FlowUtilityNetwork.NetworkItem(this.conduitType, Endpoint.Sink, this.utilityCell, base.gameObject); networkManager.AddToNetworks(this.utilityCell, this.networkItem, true); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12]; this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, new Action <object>(this.OnConduitConnectionChanged)); this.GetConduitManager().AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Default); this.OnConduitConnectionChanged(null); }
public void TriggerEvent(HashSet <int> cells, ScenePartitionerLayer layer, object event_data) { ListPool <ScenePartitionerEntry, ScenePartitioner> .PooledList pooledList = ListPool <ScenePartitionerEntry, ScenePartitioner> .Allocate(); queryId++; foreach (int cell in cells) { int x = 0; int y = 0; Grid.CellToXY(cell, out x, out y); GatherEntries(x, y, 1, 1, layer, event_data, pooledList, queryId); } RunLayerGlobalEvent(cells, layer, event_data); RunEntries(pooledList, event_data); pooledList.Recycle(); }
protected override void OnSpawn() { base.OnSpawn(); inputCell = building.GetUtilityInputCell(); outputCell = building.GetUtilityOutputCell(); int cell = Grid.PosToCell(base.transform.GetPosition()); CellOffset rotatedOffset = building.GetRotatedOffset(portInfo.offset); filteredCell = Grid.OffsetCell(cell, rotatedOffset); IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(portInfo.conduitType); itemFilter = new FlowUtilityNetwork.NetworkItem(portInfo.conduitType, Endpoint.Source, filteredCell, base.gameObject); networkManager.AddToNetworks(filteredCell, itemFilter, true); GetComponent <ConduitConsumer>().isConsuming = false; OnFilterChanged(filterable.SelectedTag); filterable.onFilterChanged += OnFilterChanged; ConduitFlow flowManager = Conduit.GetFlowManager(portInfo.conduitType); flowManager.AddConduitUpdater(OnConduitTick, ConduitFlowPriority.Default); GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, filterStatusItem, this); UpdateConduitExistsStatus(); UpdateConduitBlockedStatus(); ScenePartitionerLayer scenePartitionerLayer = null; switch (portInfo.conduitType) { case ConduitType.Gas: scenePartitionerLayer = GameScenePartitioner.Instance.gasConduitsLayer; break; case ConduitType.Liquid: scenePartitionerLayer = GameScenePartitioner.Instance.liquidConduitsLayer; break; case ConduitType.Solid: scenePartitionerLayer = GameScenePartitioner.Instance.solidConduitsLayer; break; } if (scenePartitionerLayer != null) { partitionerEntry = GameScenePartitioner.Instance.Add("ElementFilterConduitExists", base.gameObject, filteredCell, scenePartitionerLayer, delegate { UpdateConduitExistsStatus(); }); } }
private void RunLayerGlobalEvent(int x, int y, int width, int height, ScenePartitionerLayer layer, object event_data) { if (layer.OnEvent != null) { for (int i = y; i < y + height; i++) { for (int j = x; j < x + width; j++) { int num = Grid.XYToCell(j, i); if (Grid.IsValidCell(num)) { layer.OnEvent(num, event_data); } } } } }
protected override void OnSpawn() { base.OnSpawn(); var building = base.GetComponent <Building>(); this.utilityCell = building.GetCellWithOffset(building.Orientation == Orientation.Neutral ? this.conduitOffset : this.conduitOffsetFlipped); IUtilityNetworkMgr networkManager = Conduit.GetNetworkManager(this.conduitType); this.networkItem = new FlowUtilityNetwork.NetworkItem(this.conduitType, Endpoint.Source, this.utilityCell, base.gameObject); networkManager.AddToNetworks(this.utilityCell, this.networkItem, true); ScenePartitionerLayer layer = GameScenePartitioner.Instance.objectLayers[(this.conduitType != ConduitType.Gas) ? 16 : 12]; this.partitionerEntry = GameScenePartitioner.Instance.Add("ConduitConsumer.OnSpawn", base.gameObject, this.utilityCell, layer, new Action <object>(this.OnConduitConnectionChanged)); this.GetConduitManager().AddConduitUpdater(new Action <float>(this.ConduitUpdate), ConduitFlowPriority.Default); this.OnConduitConnectionChanged(null); }
private FastGroupProber(ScenePartitionerLayer mask) { added = new List <int>(256); alreadyDirty = new HashSet <int>(); cells = new int[Grid.CellCount]; destroyed = false; dirtyCells = new ConcurrentQueue <int>(); this.mask = mask; probers = new ConcurrentDictionary <object, ReachableCells>(2, 64); removed = new HashSet <int>(); toDestroy = new Queue <object>(8); toDo = new Queue <ReachabilityMonitor.Instance>(); trigger = new AutoResetEvent(false); // Start the task var thread = new Thread(ProcessLoop) { IsBackground = true, Name = "Group Prober Updater", Priority = ThreadPriority. BelowNormal }; Util.ApplyInvariantCultureToThread(thread); thread.Start(); }
protected override void OnPrefabInit() { Debug.Assert((UnityEngine.Object)instance == (UnityEngine.Object)null); instance = this; partitioner = new ScenePartitioner(16, 64, Grid.WidthInCells, Grid.HeightInCells); solidChangedLayer = partitioner.CreateMask("SolidChanged"); liquidChangedLayer = partitioner.CreateMask("LiquidChanged"); digDestroyedLayer = partitioner.CreateMask("DigDestroyed"); fogOfWarChangedLayer = partitioner.CreateMask("FogOfWarChanged"); decorProviderLayer = partitioner.CreateMask("DecorProviders"); attackableEntitiesLayer = partitioner.CreateMask("FactionedEntities"); fetchChoreLayer = partitioner.CreateMask("FetchChores"); pickupablesLayer = partitioner.CreateMask("Pickupables"); pickupablesChangedLayer = partitioner.CreateMask("PickupablesChanged"); gasConduitsLayer = partitioner.CreateMask("GasConduit"); liquidConduitsLayer = partitioner.CreateMask("LiquidConduit"); solidConduitsLayer = partitioner.CreateMask("SolidConduit"); noisePolluterLayer = partitioner.CreateMask("NoisePolluters"); validNavCellChangedLayer = partitioner.CreateMask("validNavCellChangedLayer"); dirtyNavCellUpdateLayer = partitioner.CreateMask("dirtyNavCellUpdateLayer"); trapsLayer = partitioner.CreateMask("trapsLayer"); floorSwitchActivatorLayer = partitioner.CreateMask("FloorSwitchActivatorLayer"); floorSwitchActivatorChangedLayer = partitioner.CreateMask("FloorSwitchActivatorChangedLayer"); collisionLayer = partitioner.CreateMask("Collision"); lure = partitioner.CreateMask("Lure"); plants = partitioner.CreateMask("Plants"); industrialBuildings = partitioner.CreateMask("IndustrialBuildings"); completeBuildings = partitioner.CreateMask("CompleteBuildings"); prioritizableObjects = partitioner.CreateMask("PrioritizableObjects"); objectLayers = new ScenePartitionerLayer[39]; for (int i = 0; i < 39; i++) { ObjectLayer objectLayer = (ObjectLayer)i; objectLayers[i] = partitioner.CreateMask(new HashedString(objectLayer.ToString())); } }
public ScenePartitionerEntry(string name, object obj, int x, int y, int width, int height, ScenePartitionerLayer layer, ScenePartitioner partitioner, Action <object> event_callback) { if (x >= 0 && y >= 0 && width >= 0 && height >= 0) { goto IL_0025; } goto IL_0025; IL_0025: this.x = x; this.y = y; this.width = width; this.height = height; this.layer = layer.layer; this.partitioner = partitioner; eventCallback = event_callback; this.obj = obj; }
private HandleVector <int> .Handle AddToLayer(Vector2I xy_min, int width, int height, ScenePartitionerLayer layer) { return(GameScenePartitioner.Instance.Add("Light2D", base.gameObject, xy_min.x, xy_min.y, width, height, layer, OnWorldChanged)); }
public void GatherEntries(Extents extents, ScenePartitionerLayer layer, List <ScenePartitionerEntry> gathered_entries) { GatherEntries(extents.x, extents.y, extents.width, extents.height, layer, gathered_entries); }
/// <summary> /// Adds a light's scene change partitioner to a layer. /// </summary> /// <param name="instance">The light to add.</param> /// <param name="extents">The extents that this light occupies.</param> /// <param name="layer">The layer to add it on.</param> /// <returns>A handle to the change partitioner, or InvalidHandle if it could not be /// added.</returns> private static IntHandle AddToLayer(Light2D instance, Extents extents, ScenePartitionerLayer layer) { return(ADD_TO_LAYER.Invoke(instance, extents, layer)); }
public void GatherEntries(int x_bottomLeft, int y_bottomLeft, int width, int height, ScenePartitionerLayer layer, List <ScenePartitionerEntry> gathered_entries) { partitioner.GatherEntries(x_bottomLeft, y_bottomLeft, width, height, layer, null, gathered_entries); }
public void GatherEntries(int x, int y, int width, int height, ScenePartitionerLayer layer, object event_data, List <ScenePartitionerEntry> gathered_entries) { GatherEntries(x, y, width, height, layer, event_data, gathered_entries, ++queryId); }