public override void Update(float dt) { List <Entry> dataList = entries.GetDataList(); foreach (HandleVector <int> .Handle pendingRemoval in pendingRemovals) { entries.Free(pendingRemoval); } pendingRemovals.Clear(); if (batch_update_delegate != null) { batch_update_delegate(dataList, dt); } else { int count = dataList.Count; for (int i = 0; i < count; i++) { Entry value = dataList[i]; if (value.updater != null) { value.updater.Update(value.data, dt - value.lastUpdateTime); value.lastUpdateTime = 0f; dataList[i] = value; } } } }
public void Free(ref HandleVector <int> .Handle handle) { if (handle.IsValid()) { ScenePartitionerEntry data = scenePartitionerEntries.GetData(handle); data.Release(); scenePartitionerEntries.Free(handle); handle.Clear(); } }
public void Remove(T cmp) { HandleVector <int> .Handle value = HandleVector <int> .InvalidHandle; if (table.TryGetValue(cmp, out value)) { table.Remove(cmp); items.Free(value); if (this.OnRemove != null) { this.OnRemove(cmp); } } }
/// <summary> /// Triggers a refresh of rooms. Only to be called on the foreground thread! /// </summary> public void Refresh() { int maxRoomSize = TuningData <RoomProber.Tuning> .Get().maxRoomSize; lock (cavityInfos) { while (buildingChanges.TryDequeue(out int cell)) { ref var cavityID = ref cavityForCell[cell]; bool wall = RoomProber.CavityFloodFiller.IsWall(cell); bool valid = cavityID.IsValid(); if (valid == wall) { // If a wall building like a mesh door was built but did not trigger a // solid change update, then the tile will have a valid room on a wall // building, set up a solid change solidChanges.Enqueue(cell); } else if (valid) { var cavity = cavityInfos.GetData(cavityID); int cells = cavity.numCells; if (cells > 0 && cells <= maxRoomSize) { AddBuildingToRoom(cell, cavity); } } } while (destroyed.TryDequeue(out var destroyedID)) { if (destroyedID.IsValid()) { var cavity = cavityInfos.GetData(destroyedID); if (cavity != null) { DestroyRoom(cavity.room); } cavityInfos.Free(destroyedID); } } RefreshRooms(); }
private unsafe void ProcessSolidChanges() { int *ptr = stackalloc int[5]; *ptr = 0; ptr[1] = -Grid.WidthInCells; ptr[2] = -1; ptr[3] = 1; ptr[4] = Grid.WidthInCells; foreach (int solidChange in solidChanges) { for (int i = 0; i < 5; i++) { int num = solidChange + ptr[i]; if (Grid.IsValidCell(num)) { floodFillSet.Add(num); HandleVector <int> .Handle item = CellCavityID[num]; if (item.IsValid()) { CellCavityID[num] = HandleVector <int> .InvalidHandle; releasedIDs.Add(item); } } } } CavityInfo cavityInfo = CreateNewCavity(); foreach (int item2 in floodFillSet) { if (!visitedCells.Contains(item2)) { HandleVector <int> .Handle handle = CellCavityID[item2]; if (!handle.IsValid()) { CavityInfo cavityInfo2 = cavityInfo; floodFiller.Reset(cavityInfo2.handle); GameUtil.FloodFillConditional(item2, floodFiller.ShouldContinue, visitedCells, null); if (floodFiller.NumCells > 0) { cavityInfo2.numCells = floodFiller.NumCells; cavityInfo2.minX = floodFiller.MinX; cavityInfo2.minY = floodFiller.MinY; cavityInfo2.maxX = floodFiller.MaxX; cavityInfo2.maxY = floodFiller.MaxY; cavityInfo = CreateNewCavity(); } } } } if (cavityInfo.numCells == 0) { releasedIDs.Add(cavityInfo.handle); } foreach (HandleVector <int> .Handle releasedID in releasedIDs) { CavityInfo data = cavityInfos.GetData(releasedID); if (data.room != null) { ClearRoom(data.room); } cavityInfos.Free(releasedID); } RebuildDirtyCavities(visitedCells); releasedIDs.Clear(); visitedCells.Clear(); solidChanges.Clear(); floodFillSet.Clear(); }
public void UnregisterClearable(HandleVector <int> .Handle handle) { markedClearables.Free(handle); }
public void RemovePickupable(HandleVector <int> .Handle fetchable_handle) { fetchables.Free(fetchable_handle); rotUpdaters.Remove(fetchable_handle); }