public int ListPool() { string stringToAdd = _stringToAdd; int count = 0; using ListPool <string> list = new ListPool <string>(N); for (int i = 0; i < N; i += 8) { list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); list.Add(stringToAdd); } foreach (string item in list) { count += item.Length; } return(count); }
public void Apply() { _voronoiMesh.SetVertices(_vertices); ListPool <Vector3> .Add(_vertices); _voronoiMesh.SetTriangles(_triangles, 0); ListPool <int> .Add(_triangles); if (UseUV) { _voronoiMesh.SetUVs(0, _uvs); ListPool <Vector2> .Add(_uvs); } if (UseColors) { _voronoiMesh.SetColors(_colors); ListPool <Color> .Add(_colors); } _voronoiMesh.RecalculateNormals(); if (UseCollider) { _meshCollider.sharedMesh = _voronoiMesh; } }
private HexCell GetErosionTarget(HexCell cell) { List <HexCell> candidates = ListPool <HexCell> .Get(); int erodibleElevation = cell.Elevation - 2; for (HexDirection d = HexDirection.NE; d <= HexDirection.NW; d++) { HexCell neighbor = cell.GetNeighbor(d); if (neighbor && neighbor.Elevation <= erodibleElevation) { candidates.Add(neighbor); } } if (candidates.Count == 0) { Debug.LogError("No erosion candidates found"); ListPool <HexCell> .Add(candidates); return(cell); } HexCell target = candidates[Random.Range(0, candidates.Count)]; ListPool <HexCell> .Add(candidates); return(target); }
public void Apply() { hexMesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); if (useCellData) { hexMesh.SetColors(cellWeights); ListPool <Color> .Add(cellWeights); hexMesh.SetUVs(2, cellIndices); ListPool <Vector3> .Add(cellIndices); } if (useUVCoordinates) { hexMesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); } if (useUV2Coordinates) { hexMesh.SetUVs(1, uv2s); ListPool <Vector2> .Add(uv2s); } hexMesh.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); //hexMesh.RecalculateNormals(); hexMesh.RecalculateNormals(60); //use better recalculate normals function if (useCollider) { meshCollider.sharedMesh = hexMesh; } }
public override void Update() { cell = Grid.InvalidCell; int num = 2147483647; ListPool <int, MingleCellSensor> .PooledList pooledList = ListPool <int, MingleCellSensor> .Allocate(); int num2 = 50; foreach (int mingleCell in Game.Instance.mingleCellTracker.mingleCells) { if (brain.IsCellClear(mingleCell)) { int navigationCost = navigator.GetNavigationCost(mingleCell); if (navigationCost != -1) { if (mingleCell == Grid.InvalidCell || navigationCost < num) { cell = mingleCell; num = navigationCost; } if (navigationCost < num2) { pooledList.Add(mingleCell); } } } } if (pooledList.Count > 0) { cell = pooledList[Random.Range(0, pooledList.Count)]; } pooledList.Recycle(); }
public void Apply() { _hexagonMesh.SetVertices(_vertices); ListPool <Vector3> .Add(_vertices); if (useColors) { _hexagonMesh.SetColors(_colors); ListPool <Color> .Add(_colors); } if (useUvCoordinates) { _hexagonMesh.SetUVs(0, _uvCoordinates); ListPool <Vector2> .Add(_uvCoordinates); } if (useUv2Coordinates) { _hexagonMesh.SetUVs(1, _uv2Coordinates); ListPool <Vector2> .Add(_uv2Coordinates); } _hexagonMesh.SetTriangles(_triangles, 0); ListPool <int> .Add(_triangles); _hexagonMesh.RecalculateNormals(); if (isCollidable) { _meshCollider.sharedMesh = _hexagonMesh; } }
public void Apply() { meshz.SetVertices(vertices); ListPool <Vector3> .Add(vertices); if (useColor) { meshz.SetColors(colors); ListPool <Color> .Add(colors); } if (useTerrainTypes) { meshz.SetUVs(1, terrainTypes); } meshz.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); if (useUVCoordinates) { meshz.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); } meshz.RecalculateNormals(); if (useCollider) { meshCollider.sharedMesh = meshz; } }
public static Unit Load(BinaryReader reader) { UnitType type = (UnitType)reader.ReadInt32(); float orientation = reader.ReadSingle(); List <Command> tCommand = ListPool <Command> .Get(); Unit ret = null; switch (type) { case UnitType.PERSON: ret = Human.Load(reader); break; } if (ret) { ret.orientation = orientation; ret.type = type; /* * if (acting) * foreach (Command i in tCommand) { * ret.AddCommand(i); * } */ } tCommand.Clear(); ListPool <Command> .Add(tCommand); return(ret); }
public void Apply() { mesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); mesh.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); if (useCellData) { mesh.SetColors(cellWeights); ListPool <Color> .Add(cellWeights); mesh.SetUVs(2, cellIndices); ListPool <Vector3> .Add(cellIndices); } if (useUVCoordinates) { mesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); } if (useUV2Coordinates) { mesh.SetUVs(1, uv2s); ListPool <Vector2> .Add(uv2s); } mesh.RecalculateNormals(); if (useCollider) { localCollider.sharedMesh = mesh; } }
public void Sim33ms(float dt) { ListPool <Bubble, BubbleManager> .PooledList pooledList = ListPool <Bubble, BubbleManager> .Allocate(); ListPool <Bubble, BubbleManager> .PooledList pooledList2 = ListPool <Bubble, BubbleManager> .Allocate(); foreach (Bubble bubble in bubbles) { Bubble item = bubble; item.position += item.velocity * dt; item.elapsedTime += dt; int num = Grid.PosToCell(item.position); if (!Grid.IsVisiblyInLiquid(item.position) || Grid.Element[num].id == item.element) { pooledList2.Add(item); } else { pooledList.Add(item); } } foreach (Bubble item2 in pooledList2) { Bubble current2 = item2; int gameCell = Grid.PosToCell(current2.position); SimMessages.AddRemoveSubstance(gameCell, current2.element, CellEventLogger.Instance.FallingWaterAddToSim, current2.mass, current2.temperature, byte.MaxValue, 0, true, -1); } bubbles.Clear(); bubbles.AddRange(pooledList); pooledList2.Recycle(); pooledList.Recycle(); }
/// <summary> /// 应用网格数据 /// </summary> public void Apply() { if (cellIndices != null && cellIndices.Count != vertices.Count) { Debug.Log(vertices.Count + ":" + cellIndices.Count); } hexMesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); // 归还给列表池 if (useUVCoordinates) { hexMesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); // 归还给列表池 } if (useUV2Coordinates) { hexMesh.SetUVs(1, uv2s); ListPool <Vector2> .Add(uv2s); // 归还给列表池 } if (useCellData) { hexMesh.SetColors(cellWeights); ListPool <Color> .Add(cellWeights); hexMesh.SetUVs(2, cellIndices); // 存储在texcoord2中 ListPool <Vector3> .Add(cellIndices); } hexMesh.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); // 归还给列表池 hexMesh.RecalculateNormals(); meshCollider.sharedMesh = hexMesh; }
private void ClearFinishedSongs() { if (activeSongs.Count > 0) { ListPool <string, MusicManager> .PooledList pooledList = ListPool <string, MusicManager> .Allocate(); foreach (KeyValuePair <string, SongInfo> activeSong in activeSongs) { SongInfo value = activeSong.Value; FMOD.Studio.EventInstance ev = value.ev; ev.getPlaybackState(out value.musicPlaybackState); if (value.musicPlaybackState == PLAYBACK_STATE.STOPPED || value.musicPlaybackState == PLAYBACK_STATE.STOPPING) { pooledList.Add(activeSong.Key); foreach (string item in value.songsOnHold) { SetSongParameter(item, "interrupted_dimmed", 0f, true); } value.songsOnHold.Clear(); } } foreach (string item2 in pooledList) { activeSongs.Remove(item2); } pooledList.Recycle(); } }
public static List <ElementEntry> CollectElementsFromYAML() { List <ElementEntry> list = new List <ElementEntry>(); ListPool <FileHandle, ElementLoader> .PooledList pooledList = ListPool <FileHandle, ElementLoader> .Allocate(); FileSystem.GetFiles(FileSystem.Normalize(path), "*.yaml", pooledList); ListPool <YamlIO.Error, ElementLoader> .PooledList errors = ListPool <YamlIO.Error, ElementLoader> .Allocate(); foreach (FileHandle item in pooledList) { FileHandle file = item; ElementEntryCollection elementEntryCollection = YamlIO.LoadFile <ElementEntryCollection>(file.full_path, delegate(YamlIO.Error error, bool force_log_as_warning) { error.file = file; errors.Add(error); }, null); if (elementEntryCollection != null) { list.AddRange(elementEntryCollection.elements); } } pooledList.Recycle(); if ((UnityEngine.Object)Global.Instance != (UnityEngine.Object)null && Global.Instance.modManager != null) { Global.Instance.modManager.HandleErrors(errors); } errors.Recycle(); return(list); }
private void AddMassToWorlIfPossible() { ListPool <int, EntombedItemManager> .PooledList pooledList = ListPool <int, EntombedItemManager> .Allocate(); for (int i = 0; i < cells.Count; i++) { int num = cells[i]; if (Grid.Solid[num] && Grid.Element[num].id == (SimHashes)elementIds[i]) { pooledList.Add(i); } } pooledList.Sort(); pooledList.Reverse(); foreach (int item2 in pooledList) { Item item = GetItem(item2); RemoveItem(item2); if (item.mass > 1.401298E-45f) { SimMessages.AddRemoveSubstance(item.cell, ElementLoader.FindElementByHash((SimHashes)item.elementId).idx, CellEventLogger.Instance.ElementConsumerSimUpdate, item.mass, item.temperature, item.diseaseIdx, item.diseaseCount, true, -1); } } pooledList.Recycle(); }
public void Apply() { hexMesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); if (useColors) { hexMesh.SetColors(colors); ListPool <Color> .Add(colors); } if (useUVCoordinates) { hexMesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); } if (useUV2Coordinates) { hexMesh.SetUVs(1, uv2s); ListPool <Vector2> .Add(uv2s); } hexMesh.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); hexMesh.RecalculateNormals(); if (useCollider) { meshCollider.sharedMesh = hexMesh; } }
private IEnumerator InitializeAvailableCars() { using ListPool <PlayableCar> availableCars = ListPool <PlayableCar> .Rent(); availableCars.Add(_vanPlayableCar); yield return(CheckDlc1(availableCars)); }
//------------------------EROSION------------------------------- void ErodeLand() { List <HexCell> erodibleCells = ListPool <HexCell> .Get(); for (int i = 0; i < cellCount; i++) { HexCell cell = grid.GetCell(i); if (IsErodible(cell)) { erodibleCells.Add(cell); } } int targetErodibleCells = (int)(erodibleCells.Count * (100 - erosionPercentage) * 0.01f); while (erodibleCells.Count > targetErodibleCells) { int index = Random.Range(0, erodibleCells.Count); HexCell cell = erodibleCells[index]; HexCell targetCell = GetErosionTarget(cell); cell.Elevation -= 1; targetCell.Elevation += 1; if (!IsErodible(cell)) { erodibleCells[index] = erodibleCells[erodibleCells.Count - 1]; erodibleCells.RemoveAt(erodibleCells.Count - 1); } for (HexDirection d = HexDirection.NE; d <= HexDirection.NW; d++) { HexCell neighbor = cell.GetNeighbor(d); if (neighbor && neighbor.Elevation == cell.Elevation + 2 && !erodibleCells.Contains(neighbor)) { erodibleCells.Add(neighbor); } } if (IsErodible(targetCell) && !erodibleCells.Contains(targetCell)) { erodibleCells.Add(targetCell); } for (HexDirection d = HexDirection.NE; d <= HexDirection.NW; d++) { HexCell neighbor = targetCell.GetNeighbor(d); if (neighbor && neighbor != cell && neighbor.Elevation == targetCell.Elevation + 1 && !IsErodible(neighbor)) { erodibleCells.Remove(neighbor); } } } ListPool <HexCell> .Add(erodibleCells); }
public void Apply() { cubeMesh.subMeshCount = 2; cubeMesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); cubeMesh.SetTriangles(triangles1, 0); ListPool <int> .Add(triangles1); cubeMesh.SetTriangles(triangles2, 1); ListPool <int> .Add(triangles2); cubeMesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); cubeMesh.RecalculateNormals(); if (useCollider) { meshCollider.sharedMesh = null; meshCollider.sharedMesh = cubeMesh; } }
private ChoreType Add(string id, string[] chore_groups, string urge, string[] interrupt_exclusion, string name, string status_message, string tooltip, bool skip_implicit_priority_change, int explicit_priority = -1, string report_name = null) { ListPool <Tag, ChoreTypes> .PooledList pooledList = ListPool <Tag, ChoreTypes> .Allocate(); for (int i = 0; i < interrupt_exclusion.Length; i++) { pooledList.Add(TagManager.Create(interrupt_exclusion[i])); } if (explicit_priority == -1) { explicit_priority = nextImplicitPriority; } ChoreType choreType = new ChoreType(id, this, chore_groups, urge, name, status_message, tooltip, pooledList, nextImplicitPriority, explicit_priority); pooledList.Recycle(); if (!skip_implicit_priority_change) { nextImplicitPriority -= 100; } if (report_name != null) { choreType.reportName = report_name; } return(choreType); }
protected override void OnSpawn() { base.OnSpawn(); RegisterInGrid(true); SetGridRestrictions(null, DefaultPermission); foreach (KeyValuePair <Ref <KPrefabID>, Permission> savedPermission in savedPermissions) { SetGridRestrictions(savedPermission.Key.Get(), savedPermission.Value); } ListPool <Tuple <MinionAssignablesProxy, Permission>, AccessControl> .PooledList pooledList = ListPool <Tuple <MinionAssignablesProxy, Permission>, AccessControl> .Allocate(); for (int num = savedPermissions.Count - 1; num >= 0; num--) { KPrefabID kPrefabID = savedPermissions[num].Key.Get(); if ((Object)kPrefabID != (Object)null) { MinionIdentity component = kPrefabID.GetComponent <MinionIdentity>(); if ((Object)component != (Object)null) { pooledList.Add(new Tuple <MinionAssignablesProxy, Permission>(component.assignableProxy.Get(), savedPermissions[num].Value)); savedPermissions.RemoveAt(num); ClearGridRestrictions(kPrefabID); } } } foreach (Tuple <MinionAssignablesProxy, Permission> item in pooledList) { SetPermission(item.first, item.second); } pooledList.Recycle(); SetStatusItem(); }
public void ListPool() { for (int i = 0; i < N - 1; i++) { _listPool.Add(i); } }
public void Apply() { _hexMesh.SetVertices(_vertices); ListPool <Vector3> .Add(_vertices); if (UseColors) { _hexMesh.SetColors(_colors); ListPool <Color> .Add(_colors); } if (UseUVCoordinates) { _hexMesh.SetUVs(0, _uvs); ListPool <Vector2> .Add(_uvs); } if (UseUV2Coordinates) { _hexMesh.SetUVs(1, _uv2s); ListPool <Vector2> .Add(_uv2s); } _hexMesh.SetTriangles(_triangles, 0); ListPool <int> .Add(_triangles); _hexMesh.RecalculateNormals(); if (UseCollider) { MeshCollider.sharedMesh = _hexMesh; } }
public void Apply() { // 在应用网格数据后我们不再需要它们,因此我们可以将它们添加到池中 hexMesh.SetVertices(vertices); ListPool <Vector3> .Add(vertices); // 河流颜色使用噪音贴图 if (useColors) { hexMesh.SetColors(colors); ListPool <Color> .Add(colors); } // 地形不需要UV坐标,只有河流用得到 if (useUVCoordinates) { hexMesh.SetUVs(0, uvs); ListPool <Vector2> .Add(uvs); } // 处理河口以及水面相接的UV坐标 if (useUV2Coordinates) { hexMesh.SetUVs(1, uv2s); ListPool <Vector2> .Add(uv2s); } hexMesh.SetTriangles(triangles, 0); ListPool <int> .Add(triangles); hexMesh.RecalculateNormals(); // 河流不需要碰撞器 if (useCollider) { meshCollider.sharedMesh = hexMesh; } }
public void OnSolidChanged(List <int> solid_changed_cells) { ListPool <int, EntombedItemManager> .PooledList pooledList = ListPool <int, EntombedItemManager> .Allocate(); foreach (int solid_changed_cell in solid_changed_cells) { if (!Grid.Solid[solid_changed_cell]) { pooledList.Add(solid_changed_cell); } } ListPool <int, EntombedItemManager> .PooledList pooledList2 = ListPool <int, EntombedItemManager> .Allocate(); for (int i = 0; i < cells.Count; i++) { int num = cells[i]; foreach (int item in pooledList) { if (num == item) { pooledList2.Add(i); break; } } } pooledList.Recycle(); SpawnObjects(pooledList2); pooledList2.Recycle(); }
IEnumerator <WaitForEndOfFrame> CreateRivers() { List <TriCell> riverOrigins = ListPool <TriCell> .Get(); for (int i = 0; i < cellCount; i++) { TriCell cell = grid.GetCell(i); if (cell.IsUnderwater) { continue; } ClimateData data = climate[i]; float weight = (float)(cell.Elevation) / (float)(elevationMaximum); //grid.labels[i].text = weight.ToString("F"); if (weight > 0.75f) { riverOrigins.Add(cell); riverOrigins.Add(cell); } if (weight > 0.5f) { riverOrigins.Add(cell); } if (weight > 0.25f) { riverOrigins.Add(cell); } } int riverBudget = Mathf.RoundToInt(landCells * riverPercentage * 0.01f); int overflowChecker = 0; while (riverBudget > 0 && riverOrigins.Count > 0) { if (overflowChecker++ > 1000) { Debug.Log("checking river stack overflowed"); break; } int index = Random.Range(0, riverOrigins.Count); int lastIndex = riverOrigins.Count - 1; TriCell origin = riverOrigins[index]; riverOrigins[index] = riverOrigins[lastIndex]; riverOrigins.RemoveAt(lastIndex); if (!origin.HasRiver) { riverBudget -= CreateRiver(origin); } yield return(null); } if (riverBudget > 0) { Debug.LogWarning("Failed to use up river budget."); } ListPool <TriCell> .Add(riverOrigins); }
private void StashItems() { for (int i = 0; i < _currentImageListItems.Count; i++) { _imageListItemsPool.Add(_currentImageListItems[i]); } _currentImageListItems.Clear(); }
public void ListPool() { using var list = new ListPool <int>(N); for (int i = 0; i < N; i++) { list.Add(i); } }
IEnumerator TravelPath() { Vector3 a, b, c = pathToTravel[0].Position; yield return(LookAt(pathToTravel[1].Position)); Grid.DecreaseVisibility(currentTravelLocation ? currentTravelLocation : this.pathToTravel[0], visionRange); float t = Time.deltaTime * travelSpeed; for (int i = 1; i < pathToTravel.Count; i++) { currentTravelLocation = pathToTravel[i]; a = c; b = pathToTravel[i - 1].Position; c = (b + currentTravelLocation.Position) * 0.5f; Grid.IncreaseVisibility(currentTravelLocation, visionRange); for (; t < 1f; t += Time.deltaTime * travelSpeed) { transform.localPosition = Bezier.GetPoint(a, b, c, t); Vector3 d = Bezier.GetDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } Grid.DecreaseVisibility(currentTravelLocation, visionRange); t -= 1f; } currentTravelLocation = null; a = c; b = location.Position; c = b; Grid.IncreaseVisibility(location, visionRange); for (; t < 1f; t += Time.deltaTime * travelSpeed) { transform.localPosition = Bezier.GetPoint(a, b, c, t); Vector3 d = Bezier.GetDerivative(a, b, c, t); d.y = 0f; transform.localRotation = Quaternion.LookRotation(d); yield return(null); } transform.localPosition = location.Position; orientation = transform.localRotation.eulerAngles.y; ListPool <HexCell> .Add(pathToTravel); pathToTravel = null; }
public void Add(ScriptDefineInfo info) { using ListPool <ScriptDefineInfo> defines = ListPool <ScriptDefineInfo> .Rent(availableScriptingDefines); defines.Add(info); availableScriptingDefines = defines.ToArray(); EditorUtility.SetDirty(this); }
static void CreateState(int min, int max) { wasAddToState = new bool[RegionCount]; for (int i = 0; i < RegionCount; i++) { if (!wasAddToState[i] && !regions[i].iswater && states.Count < MapMetrics.CustomStateCount - 1) { List <int> l = ListPool <int> .Get(); AddRegions(i, l, Random.Range(min, max)); State stat = new State(); foreach (int rg in l) { stat.regions.Add(regions[rg]); regions[rg].owner = stat; } states.Add(stat); ListPool <int> .Add(l); } } string[] names = Resources.Load <TextAsset>("Textes/States").text.Split('\n'); List <Color> normcolor = SaveLoad.ReadColorList(); int n = normcolor.Count; int[] idstate = new int[n]; for (int i = 0; i < n; i++) { idstate[i] = i; } for (int i = n - 1; i > 1; i--) { int j = Random.Range(0, i); int a = idstate[i]; idstate[i] = idstate[j]; idstate[j] = a; } int k = 0; foreach (var state in states) { state.mainColor = normcolor[idstate[k]]; state.name = names[idstate[k]].TrimEnd('\r'); state.flag = Resources.Load <Texture2D>("FlagTexture/(" + idstate[k] + ")"); if (state.regions.Count > 0) { state.Capital = state.regions[0]; } else { Debug.LogErrorFormat("states[{0}] without regions!", k); } state.fraction = (FractionType)(k % 2); k++; state.defaultLeader(); } }