public void UnloadChunk(int2 chunkPosition) { if (loadedChunks.TryGetValue(chunkPosition, out var chunkContainer)) { loadedChunks.Remove(chunkPosition); } }
public int2 Rotate(int2 position, ItemRotation rotation) { return(rotation switch { ItemRotation.Clockwise => int2(position.y, Width - 1 - position.x), ItemRotation.Reversed => int2(Width - 1 - position.x, Height - 1 - position.y), ItemRotation.CounterClockwise => int2(Height - 1 - position.y, position.x), _ => int2(position.x, position.y) });
void LateUpdate() { var size = int2(Screen.width, Screen.height); if (_init || size.x != _size.x || size.y != _size.y) { _init = false; _size = size; if (_mapTexture != null) { ReleaseTextures(); } _mapTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.Default); MapOverlayCamera.targetTexture = _mapTexture; OverlayDisplay.material.SetTexture("_DetailTex", _mapTexture); _gravityTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat); GravityCamera.targetTexture = _gravityTexture; GravityDisplay.material.SetTexture("_DetailTex", _gravityTexture); _tintTexture = new RenderTexture(_size.x / 2, _size.y / 2, 0, RenderTextureFormat.RGB111110Float); TintCamera.targetTexture = _tintTexture; TintDisplay.material.SetTexture("_DetailTex", _tintTexture); _influenceTexture = new RenderTexture(_size.x, _size.y, 0, RenderTextureFormat.RFloat); InfluenceCamera.targetTexture = _influenceTexture; InfluenceDisplay.material.SetTexture("_DetailTex", _influenceTexture); } var pos = ((Vector2)Position).Flatland(1); MapOverlayCamera.transform.position = pos; MapOverlayCamera.orthographicSize = _size.y * Scale * .5f; GravityCamera.transform.position = pos; GravityCamera.orthographicSize = _size.y * Scale * .5f; GravityDisplay.material.SetFloat("_Scale", Scale / 2); TintCamera.transform.position = pos; TintCamera.orthographicSize = _size.y * Scale * .5f; InfluenceCamera.transform.position = pos; InfluenceCamera.orthographicSize = _size.y * Scale * .5f; GameManager.ZoneRenderer.SetIconSize(IconSize * Scale); }
public void SetChunkAtPosition(int2 position, T chunk) { if (position.Equals(int2(0, 0))) { Value = chunk; } else if (position.Equals(int2(0, 1))) { North = chunk; } else if (position.Equals(int2(1, 1))) { NorthEast = chunk; } else if (position.Equals(int2(1, 0))) { East = chunk; } else if (position.Equals(int2(1, -1))) { SouthEast = chunk; } else if (position.Equals(int2(0, -1))) { South = chunk; } else if (position.Equals(int2(-1, -1))) { SouthWest = chunk; } else if (position.Equals(int2(-1, 0))) { West = chunk; } else if (position.Equals(int2(-1, 1))) { NorthWest = chunk; } else { throw new ArgumentException("Wrong argument bro", nameof(position)); } }
public readonly T ChunkFromPosition(int2 position) { if (position.Equals(int2(0, 0))) { return(Value); } if (position.Equals(int2(0, 1))) { return(North); } if (position.Equals(int2(1, 1))) { return(NorthEast); } if (position.Equals(int2(1, 0))) { return(East); } if (position.Equals(int2(1, -1))) { return(SouthEast); } if (position.Equals(int2(0, -1))) { return(South); } if (position.Equals(int2(-1, -1))) { return(SouthWest); } if (position.Equals(int2(-1, 0))) { return(West); } if (position.Equals(int2(-1, 1))) { return(NorthWest); } throw new ArgumentException("Wrong argument bro", nameof(position)); }
public static int2 int2(int2 xy) { return(new int2(xy)); }
public static uint hash(int2 v) { return(csum(asuint(v) * uint2(0x5F17300Du, 0x670D6809u)) + 0x7AF32C49u); }
public static bool any(int2 a) { return(a.x != 0 || a.y != 0); }
public DebuggerProxy(int2 v) { x = v.x; y = v.y; }
public static Vector3Int AsVector3Int(this int2 me, int z = 0) { return(new Vector3Int(me.x, me.y, z)); }
protected InventoryEventData(PointerEventData pointerEventData, int2 position) { PointerEventData = pointerEventData; Position = position; }
public static int2 clamp(int2 x, int2 a, int2 b) { return(max(a, min(b, x))); }
public static int2 shuffle(int2 a, int2 b, ShuffleComponent x, ShuffleComponent y) { return(int2( select_shuffle_component(a, b, x), select_shuffle_component(a, b, y))); }
public static int2 select(int2 a, int2 b, bool2 c) { return(new int2(c.x ? b.x : a.x, c.y ? b.y : a.y)); }
public static int2 mad(int2 a, int2 b, int2 c) { return(a * b + c); }
public static int2 select(int2 a, int2 b, bool c) { return(c ? b : a); }
public static bool all(int2 a) { return(a.x != 0 && a.y != 0); }
public float2(int2 val) { x = val.x; y = val.y; }
public static uint2 hash_wide(int2 v) { return((asuint(v) * uint2(0xAE131389u, 0x5D1B165Bu)) + 0x87096CD7u); }
public void LoadChunk(int2 chunkPosition) { if (allChunks.TryGetValue(chunkPosition, out var existingChunkContainer)) { loadedChunks.Add(chunkPosition, existingChunkContainer); return; } var chunkRenderer = Instantiate(chunkPrefab, transform, true); chunkRenderer.transform.position = ChunkScale * new Vector3(chunkPosition.x, chunkPosition.y); chunkRenderer.transform.localScale = new Vector3(ChunkScale, ChunkScale, 1); var outputRenderTexture = new RenderTexture(ChunkSize, ChunkSize, 32) { enableRandomWrite = true, useMipMap = false, filterMode = FilterMode.Point }; outputRenderTexture.Create(); var chunk = new Chunk(Allocator.Persistent); var cellsComputeBuffer = new ComputeBuffer(chunk.Cells.Length, SizeOfCell); chunkRenderer.SetTexture(outputRenderTexture); if (chunkPosition.y == 0) { for (var cellX = 0; cellX < ChunkSize; cellX++) { for (var cellY = 0; cellY < ChunkSize; cellY++) { chunk.SetCell(int2(cellX, cellY), (Random.value > 0.5f) ? Cell.EmptyCell : SandCellImplementation.CreateSandCell(ref random)); } } } else if (chunkPosition.y < 0) { for (var cellX = 0; cellX < ChunkSize; cellX++) { for (var cellY = 0; cellY < ChunkSize; cellY++) { chunk.SetCell(int2(cellX, cellY), SandCellImplementation.CreateSandCell(ref random)); } } } var chunkContainer = new ChunkContainer { Chunk = chunk, ChunkBehaviour = chunkRenderer, CellsComputeBuffer = cellsComputeBuffer, OutputRenderTexture = outputRenderTexture }; allChunks.Add(chunkPosition, chunkContainer); loadedChunks.Add(chunkPosition, chunkContainer); }
public static int shuffle(int2 a, int2 b, ShuffleComponent x) { return(select_shuffle_component(a, b, x)); }
public InventoryCargoEventData(PointerEventData pointerEventData, int2 position, EquippedCargoBay cargoBay) : base(pointerEventData, position) { CargoBay = cargoBay; }
public bool ChunkIsLoaded(int2 chunkPosition) { return(loadedChunks.ContainsKey(chunkPosition)); }
public static Vector2Int AsVector2Int(this int2 me) { return(*(Vector2Int *)&me); }
public static int2 abs(int2 a) { return(max(-a, a)); }
public InventoryEntityEventData(PointerEventData pointerEventData, int2 position, Entity entity) : base(pointerEventData, position) { Entity = entity; }
public void Execute() { var sandCellImplementation = new SandCellImplementation(); var waterCellImplementation = new WaterCellImplementation(); var shouldGoReverse = frameCount % 2 == 0; // var shouldGoReverse2 = frameCount % 2 == 0; // var shouldGoReverse = random.NextBool(); // var shouldGoReverse2 = random.NextBool(); // var hasDirtyRect = false; // int? minCellPositionX = null; // int? minCellPositionY = null; // int? maxCellPositionX = null; // int? maxCellPositionY = null; // // void CheckForDirtyRect(Cell cell, int2 cellPosition) // { // if (cell.isStale) return; // // hasDirtyRect = true; // // if (!minCellPositionX.HasValue || cellPosition.x < minCellPositionX.Value) // { // minCellPositionX = cellPosition.x; // } // // if (!minCellPositionY.HasValue || cellPosition.y < minCellPositionY.Value) // { // minCellPositionY = cellPosition.y; // } // // if (!maxCellPositionX.HasValue || cellPosition.x > maxCellPositionX.Value) // { // maxCellPositionX = cellPosition.x; // } // // if (!maxCellPositionY.HasValue || cellPosition.y < maxCellPositionY.Value) // { // maxCellPositionY = cellPosition.y; // } // } // // for (var chunkX = -1; chunkX < 2; chunkX++) // { // for (var chunkY = -1; chunkY < 2; chunkY++) // { // if (chunkX == 0 && chunkY == 0) continue; // // var chunkPosition = int2(chunkX, chunkY); // var chunk = chunkWithNeighbors.ChunkFromPosition(chunkPosition); // // if (chunk.IsOutOfBounds) continue; // // if (chunkX == 1 && chunkY == 1) // { // var cell = chunk.GetCell(int2(0, 0)); // CheckForDirtyRect(cell , int2(0, 0)); // } // else if (chunkX == 1 && chunkY == -1) // { // var cell = chunk.GetCell(int2(0, ChunkSize - 1)); // CheckForDirtyRect(cell , int2(0, ChunkSize - 1)); // } // else if (chunkX == -1 && chunkY == 1) // { // var cell = chunk.GetCell(int2(ChunkSize - 1, 0)); // CheckForDirtyRect(cell , int2(ChunkSize - 1, 0)); // } // else if (chunkX == -1 && chunkY == -1) // { // var cell = chunk.GetCell(int2(ChunkSize - 1, ChunkSize - 1)); // CheckForDirtyRect(cell , int2(ChunkSize - 1, ChunkSize - 1)); // } // else if (chunkY == -1) // { // for (var x = 0; x < ChunkSize; x++) // { // var cell = chunk.GetCell(int2(x, ChunkSize - 1)); // CheckForDirtyRect(cell , int2(x, ChunkSize - 1)); // } // } // else if (chunkY == 1) // { // for (var x = 0; x < ChunkSize; x++) // { // var cell = chunk.GetCell(int2(x, 0)); // CheckForDirtyRect(cell , int2(x, 0)); // } // } // else if (chunkX == -1) // { // for (var y = 0; y < ChunkSize; y++) // { // var cell = chunk.GetCell(int2(ChunkSize - 1, y)); // CheckForDirtyRect(cell , int2(ChunkSize - 1, y)); // } // } // else if (chunkX == 1) // { // for (var y = 0; y < ChunkSize; y++) // { // var cell = chunk.GetCell(int2(0, y)); // CheckForDirtyRect(cell , int2(0, y)); // } // } // } // } // for (var x = 0; x < ChunkSize; x++) // { // for (var y = 0; y < ChunkSize; y++) // { // var cellPosition = new int2(x, y); // var cell = chunkWithNeighbors.Value.GetCell(cellPosition); // // if (cell.isStale) continue; // hasDirtyRect = true; // // if (!minCellPositionX.HasValue || cellPosition.x < minCellPositionX.Value) // { // minCellPositionX = cellPosition.x; // } // // if (!minCellPositionY.HasValue || cellPosition.y < minCellPositionY.Value) // { // minCellPositionY = cellPosition.y; // } // // if (!maxCellPositionX.HasValue || cellPosition.x > maxCellPositionX.Value) // { // maxCellPositionX = cellPosition.x; // } // // if (!maxCellPositionY.HasValue || cellPosition.y > maxCellPositionY.Value) // { // maxCellPositionY = cellPosition.y; // } // } // } // // // if (!hasDirtyRect) return; // var minCellPosition = max(int2(minCellPositionX.Value, minCellPositionY.Value) - int2(1), int2(0)); // var maxCellPosition = min(int2(maxCellPositionX.Value, maxCellPositionY.Value) + int2(1), int2(ChunkSize)); // var minCellPercentage = ((float2) minCellPosition) / (float)ChunkSize; // var maxCellPercentage = ((float2) maxCellPosition) / (float)ChunkSize; var minCellPosition = int2(0); var maxCellPosition = int2(ChunkSize); // var a = new Rect( // chunkPosition.x - (chunkScale / 2),// + (minCellPercentage.x * chunkScale), // chunkPosition.y - (chunkScale / 2) + chunkScale - (minCellPercentage.x * chunkScale),// - (maxCellPercentage.y * chunkScale), // chunkScale,// * maxCellPercentage.x, // chunkScale// * maxCellPercentage.y // ); // // drawingCommands.PushLineWidth(0.5f); // drawingCommands.PushDuration(simulationStep * 50); // drawingCommands.WireRectangle(a, Color.red); // drawingCommands.PopLineWidth(); // drawingCommands.PopDuration(); // for (var x = shouldGoReverse ? ChunkSize - 1 : 0; shouldGoReverse ? x >= 0 : x < ChunkSize; x += (shouldGoReverse ? -1 : 1)) for (var x = shouldGoReverse ? maxCellPosition.x - 1 : minCellPosition.x; shouldGoReverse?x >= minCellPosition.x : x < maxCellPosition.x; x += (shouldGoReverse ? -1 : 1)) { // for (var y = 0; y < ChunkSize; y++) for (var y = maxCellPosition.y - 1; y >= minCellPosition.y; y--) // for (var y = ChunkSize - 1; y >= 0; y--) // for (var y = shouldGoReverse2 ? ChunkSize - 1 : 0; shouldGoReverse2 ? y >= 0 : y < ChunkSize; y += (shouldGoReverse2 ? -1 : 1)) { var cellPosition = new int2(x, y); var cell = chunkWithNeighbors.Value.GetCell(cellPosition); if (cell.type == CellType.None) { continue; } if (cell.clock == frameCount) { continue; } cell.clock = frameCount; chunkWithNeighbors.Value.SetCell(cellPosition, cell); if (cell.type == CellType.Sand) { // cell.isStale = false; // chunkWithNeighbors.Value.SetCell(cellPosition, cell); if (sandCellImplementation.Update(chunkWithNeighbors, cellPosition, random)) { } else { // cell.isStale = true; // chunkWithNeighbors.Value.SetCell(cellPosition, cell); } } else if (cell.type == CellType.Water) { // cell.isStale = false; if (waterCellImplementation.Update(chunkWithNeighbors, cellPosition, random)) { } else { // cell.isStale = true; // chunkWithNeighbors.Value.SetCell(cellPosition, cell); } } } } }
public static int2 min(int2 a, int2 b) { return(new int2(min(a.x, b.x), min(a.y, b.y))); }
public static int2 max(int2 a, int2 b) { return(new int2(max(a.x, b.x), max(a.y, b.y))); }
public static int2x4 int2x4(int2 c0, int2 c1, int2 c2, int2 c3) { return(new int2x4(c0, c1, c2, c3)); }