Exemplo n.º 1
0
 public override int GetHashCode()
 {
     return(
         min.GetHashCode() ^
         (max.GetHashCode() << 2)
         );
 }
Exemplo n.º 2
0
    public override int GetHashCode()
    {
        int h1 = v1.GetHashCode();
        int h2 = v2.GetHashCode();

        return(h1 ^ (h1 << 7) ^ (h1 >> 11) ^ (h2 << 13) ^ (h2 >> 17) ^ (h2 << 19));
    }
Exemplo n.º 3
0
    public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
    {
        if (sprites.Length == 0)
        {
            return;
        }


        tileData.colliderType = Tile.ColliderType.Grid;

        Random.InitState(position.GetHashCode());
        int total = sprites.Sum(x => x.probability);

        int[] indices     = new int[total];
        int   spriteIndex = 0;
        int   indiceIndex = 0;

        foreach (var s in sprites)
        {
            //indiceIndex
            for (int index = 0; index < s.probability; index++)
            {
                indices[indiceIndex++] = spriteIndex;
            }
            //spriteIndex += s.probability;
            spriteIndex++;
        }
        int random     = Mathf.FloatToHalf(Random.value * total);
        int finalIndex = indices[Mathf.Clamp(random % total, 0, total - 1)];

        tileData.sprite = sprites[Mathf.Clamp(finalIndex, 0, sprites.Length - 1)].sprite;
    }
Exemplo n.º 4
0
    public override void GenerateStructures(Chunk chunk)
    {
        int minX = chunk.pos.x - structure.negX;
        int maxX = chunk.pos.x + Env.ChunkSize + structure.posX;
        int minZ = chunk.pos.z - structure.negZ;
        int maxZ = chunk.pos.z + Env.ChunkSize + structure.posZ;

        for (int x = minX; x < maxX; x++)
        {
            for (int z = minZ; z < maxZ; z++)
            {
                Vector3Int pos         = new Vector3Int(x, 0, z);
                float      chanceAtPos = Randomization.Random(pos.GetHashCode(), 44, true);

                if (chance > chanceAtPos)
                {
                    if (Randomization.Random(pos.Add(1, 0, 0).GetHashCode(), 44, true) > chanceAtPos &&
                        Randomization.Random(pos.Add(-1, 0, 0).GetHashCode(), 44, true) > chanceAtPos &&
                        Randomization.Random(pos.Add(0, 0, 1).GetHashCode(), 44, true) > chanceAtPos &&
                        Randomization.Random(pos.Add(0, 0, -1).GetHashCode(), 44, true) > chanceAtPos)
                    {
                        int height = terrainGen.GenerateTerrainForBlockColumn(chunk, x, z, true);
                        structure.Build(world, chunk, new Vector3Int(x, height, z), this);
                    }
                }
            }
        }
    }
 /// <inheritdoc />
 public override int GetHashCode()
 {
     unchecked
     {
         return((From.GetHashCode() * 397) ^ To.GetHashCode());
     }
 }
Exemplo n.º 6
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = bounds.GetHashCode();
         hashCode = (hashCode * 397) ^ chunkPos.GetHashCode();
         hashCode = (hashCode * 397) ^ id;
         return(hashCode);
     }
 }
Exemplo n.º 7
0
    // public int GetHashCode(Vector3 v) => v.GetHashCode();

    public int GetHashCode(Vector3 v)
    {
        var vInt = new Vector3Int(
            Mathf.RoundToInt(v.x),
            Mathf.RoundToInt(v.y),
            Mathf.RoundToInt(v.z)
            );

        return(vInt.GetHashCode());
    }
Exemplo n.º 8
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 13;
         hash = (hash * 7) + min.GetHashCode();
         hash = (hash * 7) + max.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 9
0
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = From.GetHashCode();
         hashCode = (hashCode * 397) ^ To.GetHashCode();
         hashCode = (hashCode * 397) ^ Length;
         return(hashCode);
     }
 }
Exemplo n.º 10
0
        public override int GetHashCode()
        {
            unchecked
            {
                int hash = 17;
                hash = hash * 23 * pos.GetHashCode();
                hash = hash * 23 * time.GetHashCode();

                return(hash);
            }
        }
Exemplo n.º 11
0
    public override int GetHeight(Chunk chunk, int x, int z, int heightSoFar, float strength)
    {
        var   lpos      = new Vector3Int(x, heightSoFar + 1, z);
        float posChance = Randomization.Random(lpos.GetHashCode(), 200);

        if (chance > posChance)
        {
            return(heightSoFar + 1);
        }

        return(heightSoFar);
    }
Exemplo n.º 12
0
 public override int GetHashCode()
 {
     //REF SRC: https://stackoverflow.com/questions/7813687/right-way-to-implement-gethashcode-for-this-struct
     unchecked          // Overflow is fine, just wrap
     {
         int hash = 17; //prime numbers!
         hash = hash * 23 + localPosition.GetHashCode();
         hash = hash * 23 + chunkData.ChunkID.GetHashCode();
         hash = hash * 23 + lv.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 13
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hash = 17;
         hash = hash * 23 * pos.GetHashCode();
         hash = hash * 23 * block.type.GetHashCode();
         hash = hash * 23 * materialID.GetHashCode();
         hash = hash * 23 * side.GetHashCode();
         hash = hash * 23 * light.GetHashCode();
         return(hash);
     }
 }
Exemplo n.º 14
0
        internal int GetBakingHashCode()
        {
            int hash = maxCellPosition.GetHashCode();

            hash = hash * 23 + minCellPosition.GetHashCode();
            hash = hash * 23 + globalBounds.GetHashCode();
            hash = hash * 23 + bands.GetHashCode();
            hash = hash * 23 + cellSizeInBricks.GetHashCode();
            hash = hash * 23 + simplificationLevels.GetHashCode();
            hash = hash * 23 + minDistanceBetweenProbes.GetHashCode();

            return(hash);
        }
Exemplo n.º 15
0
    public override int GenerateLayer(Chunk chunk, int x, int z, int heightSoFar, float strength)
    {
        var   lpos      = new Vector3Int(x, heightSoFar + 1, z);
        float posChance = Randomization.Random(lpos.GetHashCode(), 200);

        if (chance > posChance)
        {
            SetBlocks(chunk, x, z, heightSoFar, heightSoFar + 1, blockToPlace);

            return(heightSoFar + 1);
        }

        return(heightSoFar);
    }
Exemplo n.º 16
0
        public override Sprite GetApplicableSprite(Vector3Int position, ITilemap tilemap)
        {
            int      hash = position.GetHashCode();
            OctoMask mask = tilemap.GetOctoMask(position, t => t.EqualsEX(this));

            if (randomize_with_position)
            {
                hash = hash.AbsorbObjectHash(tilemap.GetComponent <Transform>().GetSpacarPosition());
            }

            return(cache.Fetch(mask)
                   .PickACongruent(hash, t => t.GetWeight())
                   .IfNotNull(t => t.GetSprite()));
        }
Exemplo n.º 17
0
    public override int GetHashCode()
    {
        int hashCode = -1850914395;

        hashCode = hashCode * -1521134295 + offset.GetHashCode();
        hashCode = hashCode * -1521134295 + frequency.GetHashCode();
        hashCode = hashCode * -1521134295 + heighFactor.GetHashCode();
        hashCode = hashCode * -1521134295 + heightExponential.GetHashCode();
        hashCode = hashCode * -1521134295 + noiseIterations.GetHashCode();
        hashCode = hashCode * -1521134295 + waterLevel.GetHashCode();
        hashCode = hashCode * -1521134295 + snowLevel.GetHashCode();
        hashCode = hashCode * -1521134295 + treeChance.GetHashCode();
        hashCode = hashCode * -1521134295 + size.GetHashCode();
        return(hashCode);
    }
Exemplo n.º 18
0
        public Rect GetTexture(Chunk chunk, Vector3Int localPos, Vector3Int globalPos, Direction direction)
        {
            if (usesConnectedTextures)
            {
                int blockType = chunk.world.blocks.Get(globalPos).Type;

                bool wn = ConnectedTextures.IsSame(chunk, globalPos, -1, 1, direction, blockType);
                bool n  = ConnectedTextures.IsSame(chunk, globalPos, 0, 1, direction, blockType);
                bool ne = ConnectedTextures.IsSame(chunk, globalPos, 1, 1, direction, blockType);
                bool w  = ConnectedTextures.IsSame(chunk, globalPos, -1, 0, direction, blockType);
                bool e  = ConnectedTextures.IsSame(chunk, globalPos, 1, 0, direction, blockType);
                bool es = ConnectedTextures.IsSame(chunk, globalPos, 1, -1, direction, blockType);
                bool s  = ConnectedTextures.IsSame(chunk, globalPos, 0, -1, direction, blockType);
                bool sw = ConnectedTextures.IsSame(chunk, globalPos, -1, -1, direction, blockType);

                return(connectedTextures[ConnectedTextures.GetTexture(n, e, s, w, wn, ne, es, sw)]);
            }

            if (textures.Count == 1)
            {
                return(textures[0]);
            }

            if (textures.Count > 1)
            {
                int hash = localPos.GetHashCode();
                if (hash < 0)
                {
                    hash *= -1;
                }

                float randomNumber = (hash % 100) / 100f;
                randomNumber *= textures.Count;

                return(textures[(int)randomNumber]);
            }


            Debug.LogError("There were no textures for " + textureName);
            return(new Rect());
        }
Exemplo n.º 19
0
 public override int GetHashCode()
 {
     return(position.GetHashCode());
 }
Exemplo n.º 20
0
 public override int GetHashCode()
 {
     return(Index.GetHashCode());
 }
Exemplo n.º 21
0
 public override int GetHashCode()
 {
     return(-172710810 + GridPosition.GetHashCode());
 }
Exemplo n.º 22
0
 public override int GetHashCode()
 {
     return(Index.GetHashCode() ^ (Axis.GetHashCode() << 2));
 }
Exemplo n.º 23
0
 public override int GetHashCode()
 {
     return(1206833562 + position.GetHashCode());
 }
Exemplo n.º 24
0
 public override int GetHashCode() => position.GetHashCode();
Exemplo n.º 25
0
    public override void GetTileData(Vector3Int position, ITilemap tilemap, ref TileData tileData)
    {
        Transform root  = tilemap.GetComponent <Tilemap>().transform.parent;
        Tilemap   floor = null;

        if (root != null)
        {
            Transform floorGo = root.Find(LevelBrush.k_FloorLayerName);
            if (floorGo != null)
            {
                floor = floorGo.GetComponent <Tilemap>();
            }
        }

        if (spriteSlots.Length < 13)
        {
            return;
        }
        int mask = (HasWall(position + Vector3Int.up, tilemap, floor) ? 1 : 0)
                   + (HasWall(position + Vector3Int.right, tilemap, floor) ? 2 : 0)
                   + (HasWall(position + Vector3Int.down, tilemap, floor) ? 4 : 0)
                   + (HasWall(position + Vector3Int.left, tilemap, floor) ? 8 : 0);

        int mask2 = (!HasWall(position + new Vector3Int(1, 1, 0), tilemap, floor) ? 1 : 0)
                    + (!HasWall(position + new Vector3Int(1, -1, 0), tilemap, floor) ? 2 : 0)
                    + (!HasWall(position + new Vector3Int(-1, -1, 0), tilemap, floor) ? 4 : 0)
                    + (!HasWall(position + new Vector3Int(-1, 1, 0), tilemap, floor) ? 8 : 0);

        SpriteSlot slot = spriteSlots[4];

        switch (mask)
        {
        case  3: slot = spriteSlots[6]; break;

        case  6: slot = spriteSlots[0]; break;

        case  7: slot = spriteSlots[3]; break;

        case  9: slot = spriteSlots[8]; break;

        case 11: slot = spriteSlots[7]; break;

        case 12: slot = spriteSlots[2]; break;

        case 13: slot = spriteSlots[5]; break;

        case 14: slot = spriteSlots[1]; break;

        case 15:
            switch (mask2)
            {
            case 1: slot = spriteSlots[11]; break;

            case 2: slot = spriteSlots[9]; break;

            case 4: slot = spriteSlots[10]; break;

            case 8: slot = spriteSlots[12]; break;
            }
            break;
        }

        if (slot.sprites.Count > 0)
        {
            Random.InitState(position.GetHashCode());
            int total = slot.sprites.Sum(x => x.probability);

            int[] indices     = new int[total];
            int   spriteIndex = 0;
            int   indiceIndex = 0;
            foreach (var s in slot.sprites)
            {
                for (int index = 0; index < s.probability; index++)
                {
                    indices[indiceIndex++] = spriteIndex;
                }
                spriteIndex++;
            }
            int random     = Mathf.FloatToHalf(Random.value * total);
            int finalIndex = indices[Mathf.Clamp(random % total, 0, total - 1)];
            tileData.sprite = slot.sprites[Mathf.Clamp(finalIndex, 0, slot.sprites.Count - 1)].sprite;
        }
        tileData.flags        = TileFlags.LockAll;
        tileData.colliderType = mask != 15 ? Tile.ColliderType.Grid : Tile.ColliderType.None;
    }
Exemplo n.º 26
0
 public override int GetHashCode()
 {
     return(Index.GetHashCode() + IsActive.GetHashCode() + IsOccupied.GetHashCode());
 }
Exemplo n.º 27
0
        public static void BuildCrossMesh(Chunk chunk, Vector3Int localPos, Vector3Int globalPos, TextureCollection texture, bool useOffset = true)
        {
            float halfBlock = (Env.BlockSize / 2) + Env.BlockFacePadding;

            float blockHeight = 1;
            float offsetX     = 0;
            float offsetZ     = 0;

            //Using the block positions hash is much better for random numbers than saving the offset and height in the block data
            if (useOffset)
            {
                int hash = localPos.GetHashCode();
                if (hash < 0)
                {
                    hash *= -1;
                }

                blockHeight = halfBlock * 2 * (hash % 100) / 100f;

                hash *= 39;
                if (hash < 0)
                {
                    hash *= -1;
                }

                offsetX = (halfBlock * (hash % 100) / 100f) - (halfBlock / 2);

                hash *= 39;
                if (hash < 0)
                {
                    hash *= -1;
                }

                offsetZ = (halfBlock * (hash % 100) / 100f) - (halfBlock / 2);
            }

            //Converting the position to a vector adjusts it based on block size and gives us real world coordinates for x, y and z
            Vector3 vPos = localPos;

            vPos += new Vector3(offsetX, 0, offsetZ);

            {
                VertexData[]      vertexData      = chunk.pools.PopVertexDataArray(4);
                VertexDataFixed[] vertexDataFixed = chunk.pools.PopVertexDataFixedArray(4);
                {
                    for (int i = 0; i < 4; i++)
                    {
                        vertexData[i] = chunk.pools.PopVertexData();
                    }

                    vertexData[0].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock);
                    vertexData[1].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock);
                    vertexData[2].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock);
                    vertexData[3].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock);
                    BlockUtils.PrepareTexture(chunk, localPos, globalPos, vertexData, Direction.north, texture);
                    BlockUtils.SetColors(vertexData, 1, 1, 1, 1, 1);

                    for (int i = 0; i < 4; i++)
                    {
                        vertexDataFixed[i] = VertexDataUtils.ClassToStruct(vertexData[i]);
                    }
                    chunk.GeometryHandler.Batcher.AddFace(vertexDataFixed);

                    for (int i = 0; i < 4; i++)
                    {
                        chunk.pools.PushVertexData(vertexData[i]);
                    }
                }
                chunk.pools.PushVertexDataFixedArray(vertexDataFixed);
                chunk.pools.PushVertexDataArray(vertexData);
            }

            {
                VertexData[]      vertexData      = chunk.pools.PopVertexDataArray(4);
                VertexDataFixed[] vertexDataFixed = chunk.pools.PopVertexDataFixedArray(4);
                {
                    for (int i = 0; i < 4; i++)
                    {
                        vertexData[i] = chunk.pools.PopVertexData();
                    }

                    vertexData[0].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z - halfBlock);
                    vertexData[1].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock);
                    vertexData[2].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock);
                    vertexData[3].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z + halfBlock);
                    BlockUtils.PrepareTexture(chunk, localPos, globalPos, vertexData, Direction.north, texture);
                    BlockUtils.SetColors(vertexData, 1, 1, 1, 1, 1);

                    for (int i = 0; i < 4; i++)
                    {
                        vertexDataFixed[i] = VertexDataUtils.ClassToStruct(vertexData[i]);
                    }
                    chunk.GeometryHandler.Batcher.AddFace(vertexDataFixed);

                    for (int i = 0; i < 4; i++)
                    {
                        chunk.pools.PushVertexData(vertexData[i]);
                    }
                }
                chunk.pools.PushVertexDataFixedArray(vertexDataFixed);
                chunk.pools.PushVertexDataArray(vertexData);
            }

            {
                VertexData[]      vertexData      = chunk.pools.PopVertexDataArray(4);
                VertexDataFixed[] vertexDataFixed = chunk.pools.PopVertexDataFixedArray(4);
                {
                    for (int i = 0; i < 4; i++)
                    {
                        vertexData[i] = chunk.pools.PopVertexData();
                    }

                    vertexData[0].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock);
                    vertexData[1].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock);
                    vertexData[2].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock);
                    vertexData[3].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock);
                    BlockUtils.PrepareTexture(chunk, localPos, globalPos, vertexData, Direction.north, texture);
                    BlockUtils.SetColors(vertexData, 1, 1, 1, 1, 1);

                    for (int i = 0; i < 4; i++)
                    {
                        vertexDataFixed[i] = VertexDataUtils.ClassToStruct(vertexData[i]);
                    }
                    chunk.GeometryHandler.Batcher.AddFace(vertexDataFixed);

                    for (int i = 0; i < 4; i++)
                    {
                        chunk.pools.PushVertexData(vertexData[i]);
                    }
                }
                chunk.pools.PushVertexDataFixedArray(vertexDataFixed);
                chunk.pools.PushVertexDataArray(vertexData);
            }

            {
                VertexData[]      vertexData      = chunk.pools.PopVertexDataArray(4);
                VertexDataFixed[] vertexDataFixed = chunk.pools.PopVertexDataFixedArray(4);
                {
                    for (int i = 0; i < 4; i++)
                    {
                        vertexData[i] = chunk.pools.PopVertexData();
                    }

                    vertexData[0].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock, vPos.z - halfBlock);
                    vertexData[1].Vertex = new Vector3(vPos.x - halfBlock, vPos.y - halfBlock + blockHeight, vPos.z - halfBlock);
                    vertexData[2].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock + blockHeight, vPos.z + halfBlock);
                    vertexData[3].Vertex = new Vector3(vPos.x + halfBlock, vPos.y - halfBlock, vPos.z + halfBlock);
                    BlockUtils.PrepareTexture(chunk, localPos, globalPos, vertexData, Direction.north, texture);
                    BlockUtils.SetColors(vertexData, 1, 1, 1, 1, 1);

                    for (int i = 0; i < 4; i++)
                    {
                        vertexDataFixed[i] = VertexDataUtils.ClassToStruct(vertexData[i]);
                    }
                    chunk.GeometryHandler.Batcher.AddFace(vertexDataFixed);

                    for (int i = 0; i < 4; i++)
                    {
                        chunk.pools.PushVertexData(vertexData[i]);
                    }
                }
                chunk.pools.PushVertexDataFixedArray(vertexDataFixed);
                chunk.pools.PushVertexDataArray(vertexData);
            }
        }
Exemplo n.º 28
0
 public override int GetHashCode()
 {
     return(position.GetHashCode() ^ cost.GetHashCode() ^ parent.GetHashCode());
 }