static void Main(string[] args) { List <int> list = new List <int>(); list.Add(34); list.Add(4); //list.Remove(4); DynamicArray <int> dynamicArray = new DynamicArray <int>(list); dynamicArray.Add(3); dynamicArray.Add(3); dynamicArray.AddRange(list); dynamicArray.AddRange(list); //dynamicArray.Add(333); //dynamicArray.Add(366); //dynamicArray.Remove(333); //Console.WriteLine(dynamicArray.Capacity); for (int i = 0; i < dynamicArray.Length; i++) { //Console.WriteLine(dynamicArray[i]); } Console.WriteLine(); dynamicArray.Insert(1, 666); for (int i = 0; i < dynamicArray.Length; i++) { //Console.WriteLine(dynamicArray[i]); } foreach (var item in dynamicArray) { Console.WriteLine(item); } }
public static bool Prefix(bool _debugPrints, string _savePath) { ItemSerializer.savePath = _savePath; ItemSerializer.debugPrints = true; List <PlaceableItem> originalItemList = new List <PlaceableItem>(Singleton <BuildingController> .Instance.allItemsArray.array); List <PlaceableItem> itemsUsingDefaultSerializationSystem = new List <PlaceableItem>(); List <PlaceableItem> itemsUsingCustomSerializationSystem = new List <PlaceableItem>(); foreach (PlaceableItem pl in originalItemList) { if (pl == null) { continue; } bool isModded = ActivePlaceableItemCreators.HasCreatorFromEnum(pl.itemType); bool usesCustomSerializer = ActivePlaceableItemCreators.GetCreatorFromEnum(pl.itemType) is IACMFPlaceableItemCustomSerializationSystem; if (isModded && usesCustomSerializer) { itemsUsingCustomSerializationSystem.Add(pl); } else { itemsUsingDefaultSerializationSystem.Add(pl); } } DynamicArray <PlaceableItem> itemsToUseDefaultSerialisationBehaviour = new DynamicArray <PlaceableItem>(256); itemsToUseDefaultSerialisationBehaviour.AddRange(itemsUsingDefaultSerializationSystem.ToArray()); ItemSerializer.SerializeItems(itemsToUseDefaultSerialisationBehaviour); PlaceableItemSerializer.SerializePlaceableItemsUsingCustomSerializationSystem(ItemSerializer.savePath, itemsUsingCustomSerializationSystem); return(false); }
static void Main(string[] args) { try { using (var f = File.Open("storage.txt", FileMode.Open)) { byte[] buf = new byte[5]; DynamicArray contents = new DynamicArray(); int read; do { read = f.Read(buf, 0, buf.Length); contents.AddRange(buf, read); }while (read != 0); var text = Encoding.UTF8.GetString(contents.ToArray()); Console.WriteLine(text); } } catch (FileNotFoundException e) { Console.Write("файлът не е намерен: "); Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine("Неочаквана грешка" + e.Message); } Console.ReadLine(); }
static void Main(string[] args) { int[] arr = new int[] { 1, 2, 3, 4, 5, 5 }; var dynamic = new DynamicArray <int>(arr); dynamic.Add(1); foreach (var item in dynamic) { Console.Write($"{item} "); } Console.WriteLine(); dynamic.AddRange(new int[] { 3, 2, 1 }); foreach (var item in dynamic) { Console.Write($"{item} "); } Console.WriteLine(); dynamic.Capacity -= 10; foreach (var item in dynamic) { Console.Write($"{item} "); } Console.WriteLine(); dynamic.Insert(55, -1); foreach (var item in dynamic) { Console.Write($"{item} "); } Console.WriteLine(); Console.WriteLine(dynamic[-0]); Console.WriteLine(dynamic.ToString()); }
static void Main(string[] args) { CycledDynamicArray <int> item = new CycledDynamicArray <int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }; DynamicArray <int> c = new DynamicArray <int>(100); DynamicArray <int> item2 = new DynamicArray <int>() { 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 10 }; DynamicArray <int> a = new DynamicArray <int> (20); a.Add(1); a.Add(2); a.Add(3); a.AddRange(item2); item2.Capacity = 100; var g = item2.ToArray(); //Console.WriteLine(a.IsInsert(3, 99999)); //Console.WriteLine(a.IsInsert(1, 10000)); // c = (DynamicArray <int>)a.Clone(); foreach (var item1 in c) { Console.Write($"{item1} "); } Console.ReadLine(); }
public void AddRangeTest() { int i; DynamicArray<int> testArr = new DynamicArray<int>(4); int[] A = new int[] { 1, 2, 3, 4, 5 }; testArr.AddRange(A); for (i = 0; i < 5; i++) { Assert.AreEqual(testArr[i], i + 1); } Assert.AreEqual(testArr.Length, 5); }
public void AddRangeMoreThanCapacity() { int[] a = { 28, 98, 89, 25, 43 }; DynamicArray<int> Arr = new DynamicArray<int>(2); Arr.Add(68); Arr.Add(73); Arr.AddRange(a); Assert.AreEqual(Arr.Length, 7); Assert.AreEqual(Arr.Capacity, 8); Assert.AreEqual(Arr[2], 28); Assert.AreEqual(Arr[6], 43); }
public void TestMethod1() { try { DynamicArray<int> m1 = new DynamicArray<int>(); DynamicArray<int> m2 = new DynamicArray<int>(9); int[] arr = new[] { 1, 2, 3, 4, 5 }; DynamicArray<int> m3 = new DynamicArray<int>(arr); var a = m3.Length; Assert.AreEqual(a, 5); var b = m3.Capacity; Assert.AreEqual(b, 5); m3.Add(6); var a1 = m3.Length; Assert.AreEqual(a1, 6); var b1 = m3.Capacity; Assert.AreEqual(b1, 10); int[] arr1 = new[] { 7, 8, 9, 10, 11, 12 }; m3.AddRange(arr1); var a3 = m3.Length; Assert.AreEqual(a3, 12); var b3 = m3.Capacity; Assert.AreEqual(b3, 20); var flag1 = m3.Remove(7); var a4 = m3.Length; Assert.AreEqual(a4, 11); Assert.AreEqual(flag1, true); //m3.Insert(26,14); //Попытка вставить вне границ массива m3.Insert(6, 7); var b4 = m3[6]; Assert.AreEqual(b4, 7); int k = 1; foreach (var elem in m3) { var a5 = elem; Assert.AreEqual(a5, k); k++; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Assert.AreEqual(0, 1); } }
public void AddRangeTest() { int i; DynamicArray <int> testArr = new DynamicArray <int>(4); int[] A = new int[] { 1, 2, 3, 4, 5 }; testArr.AddRange(A); for (i = 0; i < 5; i++) { Assert.AreEqual(testArr[i], i + 1); } Assert.AreEqual(testArr.Length, 5); }
public void AddRangeTest() { int i; int[] A = new int[] { 1, 2, 3, 4 }; int[] B = new int[] { 5, 6, 7, 8 , 9}; DynamicArray<int> testArr = new DynamicArray<int>(A); testArr.AddRange(B); for (i = 0; i < 9; i++) { Assert.AreEqual(testArr[i], i+1); } Assert.AreEqual(testArr.Length, 9); }
public void TestAddRangeMethodWithIncCapacity() { DynamicArray<int> m2 = new DynamicArray<int>(2); int[] arr1 = new[] { 7, 8, 9, 10, 11, 12 }; m2.AddRange(arr1); var a1 = m2.Length; Assert.AreEqual(a1, 6); var b1 = m2.Capacity; Assert.AreEqual(b1, 8); var a3 = m2[5]; Assert.AreEqual(a3, 12); }
public void AddRangeMoreThanCapacity() { int[] a = { 28, 98, 89, 25, 43 }; DynamicArray <int> Arr = new DynamicArray <int>(2); Arr.Add(68); Arr.Add(73); Arr.AddRange(a); Assert.AreEqual(Arr.Length, 7); Assert.AreEqual(Arr.Capacity, 8); Assert.AreEqual(Arr[2], 28); Assert.AreEqual(Arr[6], 43); }
public void AddRangeTest() { int n = 5; int[] arr = new int[] { 1, 2, 3 }; DynamicArray <int> data = new DynamicArray <int>(n); data.AddRange(arr); Assert.AreEqual(data.Capacity, 5); Assert.AreEqual(data.Length, 3); Assert.AreEqual(data[2], 3); }
public void TestMethod1() { try { DynamicArray<int> arr1 = new DynamicArray<int>(); DynamicArray<int> arr2 = new DynamicArray<int>(20); int[] arr3 = new[] { 1, 2, 3, 4, 5 }; DynamicArray<int> arr4 = new DynamicArray<int>(arr3); var a = arr4.Length; Assert.AreEqual(a, 5); var b = arr4.Capacity; Assert.AreEqual(b, 5); arr4.Add(6); var a1 = arr4.Length; Assert.AreEqual(a1, 6); var b1 = arr4.Capacity; Assert.AreEqual(b1, 10); int[] arr31 = new[] { 7, 8, 9, 10, 11, 12 }; arr4.AddRange(arr31); var a3 = arr4.Length; Assert.AreEqual(a3, 12); var b3 = arr4.Capacity; Assert.AreEqual(b3, 20); var flag1 = arr4.Remove(7); var a4 = arr4.Length; Assert.AreEqual(a4, 11); Assert.AreEqual(flag1, true); arr4.Insert(6, 7); var b4 = arr4[6]; Assert.AreEqual(b4, 7); int k = 1; foreach (var elem in arr4) { var a5 = elem; Assert.AreEqual(a5, k); k++; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); Assert.AreEqual(0, 1); } }
public void AddRangeTest() { int i; int[] A = new int[] { 1, 2, 3, 4 }; int[] B = new int[] { 5, 6, 7, 8, 9 }; DynamicArray <int> testArr = new DynamicArray <int>(A); testArr.AddRange(B); for (i = 0; i < 9; i++) { Assert.AreEqual(testArr[i], i + 1); } Assert.AreEqual(testArr.Length, 9); }
public void AddRangeInFullListTest() { int n = 5; int[] arr = new int[] { 1, 2, 3 }; DynamicArray <int> data = new DynamicArray <int>(n); for (int i = 0; i < n; i++) { data.Add(i); } data.AddRange(arr); Assert.AreEqual(data.Capacity, 10); Assert.AreEqual(data.Length, 8); Assert.AreEqual(data[7], 3); }
public void TestAddRangeCorrectElements() { m_DynamicArray.Add(1); m_DynamicArray.Add(2); var otherArray = new DynamicArray <int>(); otherArray.Add(3); otherArray.Add(4); m_DynamicArray.AddRange(otherArray); Assert.AreEqual(1, m_DynamicArray[0]); Assert.AreEqual(2, m_DynamicArray[1]); Assert.AreEqual(3, m_DynamicArray[2]); Assert.AreEqual(4, m_DynamicArray[3]); Assert.AreEqual(4, m_DynamicArray.size); }
public void TestAddRangeMethod() { var dynamicArr = new DynamicArray <int>(); var tmpArr = new int[10]; for (int i = 0; i < 10; i++) { if (i < 5) { dynamicArr.Add(i); } tmpArr[i] = i; } dynamicArr.AddRange(tmpArr); Assert.AreEqual(0, dynamicArr[5]); }
public void Update(float dt) { if (m_thermometersToSimulateIndex < m_thermometersToSimulate.Count) { double period = MathUtils.Max(5.0 / (double)m_thermometersToSimulate.Count, 1.0); if (m_subsystemTime.PeriodicGameTimeEvent(period, 0.0)) { Point3 point = m_thermometersToSimulate.Array[m_thermometersToSimulateIndex]; SimulateThermometer(point.X, point.Y, point.Z, invalidateTerrainOnChange: true); m_thermometersToSimulateIndex++; } } else if (m_thermometersByPoint.Count > 0) { m_thermometersToSimulateIndex = 0; m_thermometersToSimulate.Clear(); m_thermometersToSimulate.AddRange(m_thermometersByPoint.Keys); } }
public void TestAddRangeOutOfSpaceKeepPreviousElements() { var smallDynamicArray = new DynamicArray <int>(2); smallDynamicArray[0] = 1; smallDynamicArray[1] = 2; var otherArray = new DynamicArray <int>(); otherArray.Add(3); otherArray.Add(4); smallDynamicArray.AddRange(otherArray); Assert.AreEqual(1, smallDynamicArray[0]); Assert.AreEqual(2, smallDynamicArray[1]); Assert.AreEqual(3, smallDynamicArray[2]); Assert.AreEqual(4, smallDynamicArray[3]); Assert.AreEqual(4, smallDynamicArray.size); }
public EditMemeryDialogB(MemoryBankData memoryBankData, Action onCancel) { memory = memoryBankData; Data.Clear(); Data.AddRange(memory.Data); CanvasWidget canvasWidget = new CanvasWidget() { Size = new Vector2(600f, float.PositiveInfinity), HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center }; RectangleWidget rectangleWidget = new RectangleWidget() { FillColor = new Color(0, 0, 0, 255), OutlineColor = new Color(128, 128, 128, 128), OutlineThickness = 2 }; StackPanelWidget stackPanel = new StackPanelWidget() { Direction = LayoutDirection.Vertical }; LabelWidget labelWidget = new LabelWidget() { Text = "M 板编辑器", HorizontalAlignment = WidgetAlignment.Center, Margin = new Vector2(0, 10) }; StackPanelWidget stackPanelWidget = new StackPanelWidget() { Direction = LayoutDirection.Horizontal, HorizontalAlignment = WidgetAlignment.Near, VerticalAlignment = WidgetAlignment.Near, Margin = new Vector2(10f, 10f) }; Children.Add(canvasWidget); canvasWidget.Children.Add(rectangleWidget); canvasWidget.Children.Add(stackPanel); stackPanel.Children.Add(labelWidget); stackPanel.Children.Add(stackPanelWidget); stackPanelWidget.Children.Add(initData()); stackPanelWidget.Children.Add(initButton()); MainView = stackPanel; this.onCancel = onCancel; lastvalue = memory.Read(0); }
public void AddRangeTest() { DynamicArray <int> array = new DynamicArray <int>(); List <int> list = new List <int>(); for (int i = 0; i < DEFAULT_STEPS_COUNT; i++) { int len = RandomTestsUtils.Random.Next(10); int[] collection = new int[len]; for (int j = 0; j < len; j++) { collection[j] = RandomTestsUtils.Random.Next(); } array.AddRange(collection); list.AddRange(collection); if (!HaveEqualsElements(array, list)) { Assert.Fail(); } } }
{ // Демонстрация работы с DynamicArray, написано ужасно, но как лучше не знаю. static void Main() { Console.WriteLine("Демонстрация работы бибоиотеки Dynamic_Array"); DynamicArray <int> da = new DynamicArray <int>(); Console.WriteLine($"Создание экземпляра DynamicArray конструктором без параметров, вместимость: {da.Capacity}"); DynamicArray <int> da2 = new DynamicArray <int>(4); Console.WriteLine($"Создание экземпляра DynamicArray конструктором с параметром 4, вместимость: {da2.Capacity}"); List <int> lst1 = new List <int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; DynamicArray <int> da3 = new DynamicArray <int>(lst1); Console.WriteLine($"Создание экземпляра DynamicArray конструктором принимающим на вход другую коллекцию IEnumerable\n" + $"Длина коллекции List: {lst1.Count}, вместимость: {lst1.Capacity}, содержимое: {string.Join(", ", lst1)};\n" + $"Длина коллекции DynamicArray: {da3.Count}, вместимость: {da3.Capacity}, содержимое: {da3}"); Console.WriteLine("Метод Add, позволяющий добавлять в конец массива новые данные. При нехватке места для добавления элемента массив удваивается: "); int count = 1; while (count < 6) { da2.Add(count); Console.WriteLine($"Колличество элементов: {da2.Count}, вместимость: {da2.Capacity}, коллекция {da2}"); count++; } Console.WriteLine($"Метод AddRange добавляющий в конец массива содержимое коллекции IEnumerable. Содержимое коллекции da2 до добавления lst1: {da2}, вместимость: {da2.Capacity}"); da2.AddRange(lst1); Console.WriteLine($"Метод AddRange добавляющий в конец массива содержимое коллекции IEnumerable. Содержимое коллекции da2 после добавления lst1: {da2}, вместимость: {da2.Capacity}"); da2.Remove(5); Console.WriteLine($"Метод Remove удаляющий из коллекции пепрвое вхождение заданного элемента (5). Содержимое коллекции da2 после удаления 5: {da2}, вместимость: {da2.Capacity}"); da2.Insert(4, 5); da2.Insert(4, 5); Console.WriteLine($"Метод Insert, позволяющую вставить объект по нужному индексу Содержимое коллекции da2 после двойного добавления 5: {da2}, вместимость: {da2.Capacity}"); Console.WriteLine($"Свйойство Lenght - получение колличества элементов (В данном случае Count): {da2.Count}, вместимость: {da2.Capacity}"); Console.WriteLine("Реализация IEnumerable и Ienumerable<T>"); foreach (int i in da3) { Console.WriteLine(i); } Console.WriteLine("Реализация доступа по индексу"); for (int i = 0; i < da3.Count; i++) { Console.WriteLine(da3[i]); } try { Console.WriteLine(da3[10]); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine($"Демонстрация ошибки при доступе мимо индекса: {ex.Message}"); } Console.WriteLine("Доступ к элементам с конца, при использовании отрицательного индекса:"); count = -1; while (count >= da3.Count * -1) { Console.WriteLine($"Индекс: {count}; содержимое: {da3[count]}"); count--; } Console.WriteLine($"Метод ToArray возввращающий обычный массив: {string.Join(", ", da3.ToArray())}"); DynamicArray <int> da4 = da3.Clone() as DynamicArray <int>; Console.WriteLine($"Реализация интерфейса IClonable: {string.Join(", ", da4)}"); Console.WriteLine($"Перегрузка оператора Equals: {da3.Equals(da4)}, ==, {da3 == da4}"); CycledDynamicArray <int> cycledArray = new CycledDynamicArray <int>(da3); Console.WriteLine("Массив CycledDynamicArray на базе DynamicArray с зацикленным итератором:"); count = 0; foreach (int i in cycledArray) { Console.WriteLine(i); count++; if (count > 30) { break; } } Console.WriteLine("Перерыв"); count = 0; foreach (int i in cycledArray) { Console.WriteLine(i); count++; if (count > 30) { break; } } Console.WriteLine("Демонстрация работы метода расширения ToDynamicArray:"); List <int> list1 = new List <int> { 1, 2, 3 }; List <int> list2 = new List <int> { 4, 5, 6 }; DynamicArray <int> customArray = list1.Concat(list2).ToDynamicArray(); foreach (int i in customArray) { Console.WriteLine("!" + i); } DynamicArray <int> da5 = new DynamicArray <int>(new int[] { 7, 7, 7 }); int[] mass = da3.ToArray(); da5.CopyTo(mass, 6); Console.WriteLine($"Работа метода CopyTo: {string.Join(", ", mass)}"); // Работа с InsertWithFeedback: Console.WriteLine(da5.InsertWithFeedback(4, 1)); Console.WriteLine(da5); Console.ReadLine(); }
public Widget initButton() { StackPanelWidget stack = new StackPanelWidget() { Direction = LayoutDirection.Vertical }; for (int i = 0; i < 6; i++) { StackPanelWidget stackPanelWidget = new StackPanelWidget() { Direction = LayoutDirection.Horizontal }; for (int j = 0; j < 3; j++) { int cc = i * 3 + j; if (cc < 15) { int pp = cc + 1; stackPanelWidget.Children.Add(makeFuncButton(string.Format("{0}", MemoryBankData.m_hexChars[pp]), delegate() { AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); if (!isSetPos) { Write(clickpos, (byte)pp); //写入数据 lastvalue = pp; clickpos += 1; //自动加1 if (clickpos >= 255) { clickpos = 0; } isclick = true; } else { //处于设定位置模式 if (setPosN == 0) { clickpos = 16 * pp; } else if (setPosN == 1) { clickpos += pp; } setPosN += 1; if (setPosN == 2) { if (clickpos > 0xff) { clickpos = 0; } setPosN = 0; isclick = true; isSetPos = false; } } })); } else if (cc == 15) { stackPanelWidget.Children.Add(makeFuncButton(string.Format("{0}", MemoryBankData.m_hexChars[0]), delegate() { AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); if (!isSetPos) { Write(clickpos, (byte)0); //写入数据 lastvalue = 0; clickpos += 1; //自动加1 if (clickpos >= 255) { clickpos = 0; } isclick = true; } else { //处于设定位置模式 if (setPosN == 0) { clickpos = 0; } else if (setPosN == 1) { clickpos += 0; } setPosN += 1; if (setPosN == 2) { if (clickpos > 0xff) { clickpos = 0; } setPosN = 0; isclick = true; isSetPos = false; } } })); continue; } else if (cc == 16) { stackPanelWidget.Children.Add(makeFuncButton("清零", delegate() { AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); for (int ai = 0; ai < Data.Count; ai++) { Write(ai, 0); } isclick = true; })); continue; } else if (cc == 17) { stackPanelWidget.Children.Add(makeFuncButton("转置", delegate() { AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); DynamicArray <byte> tmp = new DynamicArray <byte>(); tmp.AddRange(Data); tmp.Count = 256; for (int c = 0; c < 16; c++) { for (int d = 0; d < 16; d++) { Write(c + d * 16, tmp[c * 16 + d]); } } clickpos = 0; isclick = true; })); continue; } } stack.Children.Add(stackPanelWidget); } LabelWidget labelWidget = new LabelWidget() { FontScale = 0.8f, Text = "输入全部数据:", HorizontalAlignment = WidgetAlignment.Center, Margin = new Vector2(0f, 10f), Color = Color.DarkGray }; stack.Children.Add(labelWidget); stack.Children.Add(makeTextBox(delegate(TextBoxWidget textBoxWidget) { LoadString(textBoxWidget.Text); isclick = true; }, memory.SaveString(false))); stack.Children.Add(makeButton("保存数据", delegate() { for (int i = 0; i < Data.Count; i++) { memory.Write(i, Data[i]); } onCancel?.Invoke(); AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); DialogsManager.HideDialog(this); })); stack.Children.Add(makeButton("取消", delegate() { AudioManager.PlaySound("Audio/UI/ButtonClick", 1f, 0f, 0f); DialogsManager.HideDialog(this); isclick = true; })); return(stack); }
/// <summary> /// Updates the cell streaming for a <see cref="Camera"/> /// </summary> /// <param name="camera">The <see cref="Camera"/></param> public void UpdateCellStreaming(Camera camera) { if (!isInitialized) { return; } var cameraPosition = camera.transform.position; if (!debugDisplay.freezeStreaming) { m_FrozenCameraPosition = cameraPosition; } // Cell position in cell space is the top left corner. So we need to shift the camera position by half a cell to make things comparable. var cameraPositionCellSpace = (m_FrozenCameraPosition - m_Transform.posWS) / MaxBrickSize() - Vector3.one * 0.5f; ComputeCellCameraDistance(cameraPositionCellSpace, m_ToBeLoadedCells); ComputeCellCameraDistance(cameraPositionCellSpace, m_LoadedCells); m_ToBeLoadedCells.QuickSort(); m_LoadedCells.QuickSort(); // This is only a rough budget estimate at first. // It doesn't account for fragmentation. int indexChunkBudget = m_Index.GetRemainingChunkCount(); int shChunkBudget = m_Pool.GetRemainingChunkCount(); if (m_SupportStreaming) { bool budgetReached = false; while (m_TempCellToLoadList.size < m_NumberOfCellsLoadedPerFrame && m_TempCellToLoadList.size < m_ToBeLoadedCells.size && !budgetReached) { // Enough memory, we can safely load the cell. var cellInfo = m_ToBeLoadedCells[m_TempCellToLoadList.size]; budgetReached = !TryLoadCell(cellInfo, ref shChunkBudget, ref indexChunkBudget, m_TempCellToLoadList); } // Budget reached. We need to figure out if we can safely unload other cells to make room. if (budgetReached) { int pendingUnloadCount = 0; bool canUnloadCell = true; while (canUnloadCell && m_TempCellToLoadList.size < m_NumberOfCellsLoadedPerFrame && m_TempCellToLoadList.size < m_ToBeLoadedCells.size) { if (m_LoadedCells.size - pendingUnloadCount == 0) { canUnloadCell = false; break; } var furthestLoadedCell = m_LoadedCells[m_LoadedCells.size - pendingUnloadCount - 1]; var closestUnloadedCell = m_ToBeLoadedCells[m_TempCellToLoadList.size]; // Redundant work. Maybe store during first sort pass? float furthestLoadedCellDistance = Vector3.Distance(furthestLoadedCell.cell.position, cameraPositionCellSpace); float closestUnloadedCellDistance = Vector3.Distance(closestUnloadedCell.cell.position, cameraPositionCellSpace); // The most distant loaded cell is further than the closest unloaded cell, we can unload it. if (furthestLoadedCellDistance > closestUnloadedCellDistance) { pendingUnloadCount++; UnloadCell(furthestLoadedCell); shChunkBudget += furthestLoadedCell.cell.shChunkCount; indexChunkBudget += furthestLoadedCell.cell.indexChunkCount; m_TempCellToUnloadList.Add(furthestLoadedCell); TryLoadCell(closestUnloadedCell, ref shChunkBudget, ref indexChunkBudget, m_TempCellToLoadList); } else { // We are in a "stable" state, all the closest cells are loaded within the budget. canUnloadCell = false; } } if (pendingUnloadCount > 0) { m_LoadedCells.RemoveRange(m_LoadedCells.size - pendingUnloadCount, pendingUnloadCount); RecomputeMinMaxLoadedCellPos(); } } } else { int cellCountToLoad = Mathf.Min(m_NumberOfCellsLoadedPerFrame, m_ToBeLoadedCells.size); for (int i = 0; i < cellCountToLoad; ++i) { var cellInfo = m_ToBeLoadedCells[m_TempCellToLoadList.size]; // m_TempCellToLoadList.size get incremented in TryLoadCell TryLoadCell(cellInfo, ref shChunkBudget, ref indexChunkBudget, m_TempCellToLoadList); } } // Remove the cells we successfully loaded. m_ToBeLoadedCells.RemoveRange(0, m_TempCellToLoadList.size); m_LoadedCells.AddRange(m_TempCellToLoadList); m_ToBeLoadedCells.AddRange(m_TempCellToUnloadList); m_TempCellToLoadList.Clear(); m_TempCellToUnloadList.Clear(); }
static void Main(string[] args) { DynamicArray <int> array = new DynamicArray <int>(); array.Add(1); array.Add(2); array.Add(3); array.Add(4); array.Add(5); array.Add(6); array.Add(7); array.Add(8); WriteLine("Исходный массив:"); foreach (var item in array) { Write(item + " "); } WriteLine(); WriteLine("Свойство Capacity: " + array.Capacity); WriteLine("Свойство Length: " + array.Length); WriteLine(); WriteLine("Применение Add:"); array.Add(9); foreach (var item in array) { Write(item + " "); } WriteLine(); WriteLine("Свойство Capacity: " + array.Capacity); WriteLine("Свойство Length: " + array.Length); WriteLine(); WriteLine("Применение AddRange:"); array.AddRange(new int[] { 10, 11 }); foreach (var item in array) { Console.Write(item + " "); } WriteLine(); WriteLine("Свойство Capacity: " + array.Capacity); WriteLine("Свойство Length: " + array.Length); WriteLine(); WriteLine("Применение Remove:"); array.Remove(9); foreach (var item in array) { Write(item + " "); } WriteLine(); WriteLine("Свойство Capacity: " + array.Capacity); WriteLine("Свойство Length: " + array.Length); WriteLine(); WriteLine("Применение Insert:"); array.Insert(2, 5); foreach (var item in array) { Write(item + " "); } WriteLine(); WriteLine("Свойство Capacity: " + array.Capacity); WriteLine("Свойство Length: " + array.Length); WriteLine(); WriteLine("Применение ToArray:"); int[] array2 = array.ToArray(); for (int i = 0; i < array2.Length; i++) { Write(array2[i] + " "); } WriteLine(); ReadKey(); }
public bool MoveToFreeSpace() { Vector3 boxSize = BoxSize; Vector3 position = base.Position; for (int i = 0; i < m_freeSpaceOffsets.Length; i++) { Vector3?vector = null; Vector3 vector2 = position + m_freeSpaceOffsets[i]; if (Terrain.ToCell(vector2) != Terrain.ToCell(position)) { continue; } BoundingBox box = new BoundingBox(vector2 - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), vector2 + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f)); box.Min += new Vector3(0.01f, MaxSmoothRiseHeight + 0.01f, 0.01f); box.Max -= new Vector3(0.01f); m_collisionBoxes.Clear(); FindTerrainCollisionBoxes(box, m_collisionBoxes); m_collisionBoxes.AddRange(m_movingBlocksCollisionBoxes); m_collisionBoxes.AddRange(m_bodiesCollisionBoxes); if (!IsColliding(box, m_collisionBoxes)) { vector = vector2; } else { m_stoppedTime = 0f; CollisionBox pushingCollisionBox; float num = CalculatePushBack(box, 0, m_collisionBoxes, out pushingCollisionBox); CollisionBox pushingCollisionBox2; float num2 = CalculatePushBack(box, 1, m_collisionBoxes, out pushingCollisionBox2); CollisionBox pushingCollisionBox3; float num3 = CalculatePushBack(box, 2, m_collisionBoxes, out pushingCollisionBox3); float num4 = num * num; float num5 = num2 * num2; float num6 = num3 * num3; List <Vector3> list = new List <Vector3>(); if (num4 <= num5 && num4 <= num6) { list.Add(vector2 + new Vector3(num, 0f, 0f)); if (num5 <= num6) { list.Add(vector2 + new Vector3(0f, num2, 0f)); list.Add(vector2 + new Vector3(0f, 0f, num3)); } else { list.Add(vector2 + new Vector3(0f, 0f, num3)); list.Add(vector2 + new Vector3(0f, num2, 0f)); } } else if (num5 <= num4 && num5 <= num6) { list.Add(vector2 + new Vector3(0f, num2, 0f)); if (num4 <= num6) { list.Add(vector2 + new Vector3(num, 0f, 0f)); list.Add(vector2 + new Vector3(0f, 0f, num3)); } else { list.Add(vector2 + new Vector3(0f, 0f, num3)); list.Add(vector2 + new Vector3(num, 0f, 0f)); } } else { list.Add(vector2 + new Vector3(0f, 0f, num3)); if (num4 <= num5) { list.Add(vector2 + new Vector3(num, 0f, 0f)); list.Add(vector2 + new Vector3(0f, num2, 0f)); } else { list.Add(vector2 + new Vector3(0f, num2, 0f)); list.Add(vector2 + new Vector3(num, 0f, 0f)); } } foreach (Vector3 item in list) { box = new BoundingBox(item - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), item + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f)); box.Min += new Vector3(0.02f, MaxSmoothRiseHeight + 0.02f, 0.02f); box.Max -= new Vector3(0.02f); m_collisionBoxes.Clear(); FindTerrainCollisionBoxes(box, m_collisionBoxes); m_collisionBoxes.AddRange(m_movingBlocksCollisionBoxes); m_collisionBoxes.AddRange(m_bodiesCollisionBoxes); if (!IsColliding(box, m_collisionBoxes)) { vector = item; break; } } } if (vector.HasValue) { base.Position = vector.Value; return(true); } } return(false); }
public static void ConsoleInterface() { var array = new DynamicArray <int>(); var list = new List <int>(); Console.WriteLine("List elements: "); for (int i = 0; i < 10; i++) { list.Add(i % 3 + 1); Console.Write(list[i] + ","); } for (int i = 0; i < 10; i++) { array.Add(i % 4 + 1); Console.WriteLine("Adding " + array[i] + ":" + Environment.NewLine + "Dynamic array length: " + array.Length + Environment.NewLine + "Dynamic array capacity: " + array.Capacity); } Console.WriteLine(Environment.NewLine + "Dynamic array elements: "); foreach (var item in array) { Console.Write(item + ","); } Console.WriteLine(Environment.NewLine + "Array after removing item = 1:"); if (array.Remove(1)) { Console.WriteLine("Success!"); } else { Console.WriteLine("There is no such item!"); } foreach (var item in array) { Console.Write(item + ","); } Console.WriteLine("Dynamic array length: " + array.Length + Environment.NewLine + "Dynamic array capacity: " + array.Capacity); Console.WriteLine("Adding a list to the dynamic array:"); array.AddRange(list); foreach (var item in array) { Console.Write(item + ","); } Console.WriteLine("Dynamic array length: " + array.Length + Environment.NewLine + "Dynamic array capacity: " + array.Capacity); Console.WriteLine(Environment.NewLine + "Array after insertion of item = 9 at 9th position:"); if (array.Insert(9, 9)) { Console.WriteLine("Success!"); } else { Console.WriteLine("Failure!"); } foreach (var item in array) { Console.Write(item + ","); } Console.WriteLine("Dynamic array length: " + array.Length + Environment.NewLine + "Dynamic array capacity: " + array.Capacity); }