public void AddOrder(Order order) { if (ordersForLaterTurn.Ptr == null) { ordersForLaterTurn = NativeEnumerable <Order> .Create(UnsafeUtilityEx.Malloc <Order>(16, Allocator.Persistent), 16); UnsafeUtility.MemClear(ordersForLaterTurn.Ptr + 1, 15 * sizeof(Order)); } else if (ordersForLaterTurnCount == ordersForLaterTurn.Length) { var newEnumerable = NativeEnumerable <Order> .Create(UnsafeUtilityEx.Malloc <Order>(ordersForLaterTurnCount << 1, Allocator.Persistent), ordersForLaterTurnCount << 1); UnsafeUtilityEx.MemCpy(newEnumerable.Ptr, ordersForLaterTurn.Ptr, ordersForLaterTurnCount); UnsafeUtility.MemClear(newEnumerable.Ptr + ordersForLaterTurnCount + 1, (ordersForLaterTurnCount - 1) * sizeof(Order)); ordersForLaterTurn.Dispose(Allocator.Persistent); ordersForLaterTurn = newEnumerable; } ordersForLaterTurn[ordersForLaterTurnCount++] = order; }
public Board(int2 size) { var count = size.x * size.y; #if DEBUG if (math.any(size < 0)) { throw new ArgumentOutOfRangeException(size.x + ", " + size.y + " should not be less than 0!"); } #endif if (math.any(size == 0)) { Cells = default; return; } Cells = NativeEnumerable <Cell> .Create(UnsafeUtilityEx.Malloc <Cell>(count, Allocator.Persistent), count); UnsafeUtility.MemClear(Cells.Ptr, count * sizeof(Cell)); }
public Power(PowerId powerId, int capacity) { if (capacity < 0) { throw new ArgumentOutOfRangeException(capacity + " should not be less than 0!"); } if (capacity == 0) { this = default; PowerId = powerId; return; } PowerId = powerId; knownPowerFlags = 1U << (int)powerId.Value; NextUnitId = default; TeamCount = default; SpeciesTypes = NativeEnumerable <SpeciesType> .Create((SpeciesType *)Malloc(capacity), capacity); UnsafeUtility.MemClear(SpeciesTypes.Ptr, CalcCapacityByteLength(capacity)); UnitIds = NativeEnumerable <UnitId> .Create((UnitId *)(SpeciesTypes.Ptr + capacity), capacity); UnitTypes = NativeEnumerable <UnitType> .Create((UnitType *)(UnitIds.Ptr + capacity), capacity); InitialCounts = NativeEnumerable <UnitInitialCount> .Create((UnitInitialCount *)(UnitTypes.Ptr + capacity), capacity); TotalHps = NativeEnumerable <UnitTotalHp> .Create((UnitTotalHp *)(InitialCounts.Ptr + capacity), capacity); Statuses = NativeEnumerable <UnitStatus> .Create((UnitStatus *)(TotalHps.Ptr + capacity), capacity); Positions = NativeEnumerable <UnitPosition> .Create((UnitPosition *)(Statuses.Ptr + capacity), capacity); MovePowers = NativeEnumerable <UnitMovePower> .Create((UnitMovePower *)(Positions.Ptr + capacity), capacity); Destinations = NativeEnumerable <UnitDestination> .Create((UnitDestination *)(MovePowers.Ptr + capacity), capacity); MiscellaneousData = NativeEnumerable <ulong> .Create((ulong *)(Destinations.Ptr + capacity), capacity); MiscellaneousData2 = NativeEnumerable <ulong> .Create((ulong *)(MiscellaneousData.Ptr + capacity), capacity); GenerationTurns = NativeEnumerable <TurnId> .Create((TurnId *)(MiscellaneousData2.Ptr + capacity), capacity); }