Beispiel #1
0
    public void GenerateTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, MeshGenerator g)
    {
        switch (GetFace(BlockTerrain.GetData(value)))
        {
        case 1:
            g.AlphaTest.TwoSidedQuad(
                new Vector3(x, y, z),
                new Vector3(x, y + 1.0f, z),
                new Vector3(x, y + 1.0f, z + 1.0f),
                new Vector3(x, y, z + 1.0f),
                TextureSlot, map.Lookup(chunk.GetShiftValue(x, z))
                );
            break;

        case 0:
            g.AlphaTest.TwoSidedQuad(
                new Vector3(x, y, z + 1.0f),
                new Vector3(x, y + 1.0f, z + 1.0f),
                new Vector3(x + 1.0f, y + 1.0f, z + 1.0f),
                new Vector3(x + 1.0f, y, z + 1.0f),
                TextureSlot, map.Lookup(chunk.GetShiftValue(x, z))
                );
            break;

        case 3:
            g.AlphaTest.TwoSidedQuad(
                new Vector3(x + 1.0f, y, z + 1.0f),
                new Vector3(x + 1.0f, y + 1.0f, z + 1.0f),
                new Vector3(x + 1.0f, y + 1.0f, z),
                new Vector3(x + 1.0f, y, z),
                TextureSlot, map.Lookup(chunk.GetShiftValue(x, z))
                );
            break;

        case 2:
            g.AlphaTest.TwoSidedQuad(
                new Vector3(x + 1.0f, y, z),
                new Vector3(x + 1.0f, y + 1.0f, z),
                new Vector3(x, y + 1.0f, z),
                new Vector3(x, y, z),
                TextureSlot, map.Lookup(chunk.GetShiftValue(x, z))
                );
            break;

        default:
            throw new UnityException("undefined face: " + GetFace(BlockTerrain.GetData(value)));
        }
    }
Beispiel #2
0
    public unsafe void SaveChunk(BlockTerrain.Chunk chunk)
    {
        if (!chunk.isEdited)
        {
            return;
        }
        lock (locker)
        {
            Point2 p = new Point2(chunk.chunkx, chunk.chunky);
            long   value;
            if (chunkOffsets.TryGetValue(p, out value))
            {
                stream.Seek(value, SeekOrigin.Begin);
                WriteChunkHeader(stream, chunk.chunkx, chunk.chunky);

                fixed(byte *bptr = &buffer[0])
                {
                    int *iptr = (int *)bptr;

                    for (int x = 0; x < 16; x++)
                    {
                        for (int y = 0; y < 16; y++)
                        {
                            int index = BlockTerrain.GetCellIndex(15 - x, 0, y);
                            int h     = 0;
                            while (h < 128)
                            {
                                *iptr = chunk.GetCellValue(index);
                                iptr++;
                                h++;
                                index++;
                            }
                        }
                    }
                }

                stream.Write(buffer, 0, 131072);

                fixed(byte *bptr = &buffer[0])
                {
                    int *iptr = (int *)bptr;

                    for (int x = 0; x < 16; x++)
                    {
                        int index = BlockTerrain.GetShiftIndex(15 - x, 0);
                        int h     = 0;
                        while (h < 16)
                        {
                            *iptr = chunk.GetShiftValue(index);
                            iptr++;
                            h++;
                            index++;
                        }
                    }
                }

                stream.Write(buffer, 0, 1024);
            }
        }
    }
Beispiel #3
0
    public void GenerateTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, MeshGenerator g)
    {
        Vector3 v000 = new Vector3(x, y, z);
        Vector3 v001 = new Vector3(x, y, z + 1.0f);
        Vector3 v010 = new Vector3(x, y + 1.0f, z);
        Vector3 v011 = new Vector3(x, y + 1.0f, z + 1.0f);
        Vector3 v100 = new Vector3(x + 1.0f, y, z);
        Vector3 v101 = new Vector3(x + 1.0f, y, z + 1.0f);
        Vector3 v110 = new Vector3(x + 1.0f, y + 1.0f, z);
        Vector3 v111 = new Vector3(x + 1.0f, y + 1.0f, z + 1.0f);

        GreedyTerrainMesh terrainMesh = g.AlphaTest;
        int   texSlot = TextureSlot;
        Color color   = map.Lookup(chunk.GetShiftValue(x, z));

        int content = chunk.GetCellContent(x - 1, y, z);

        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v001, v011, v010, v000, texSlot, color);
        }

        content = chunk.GetCellContent(x, y - 1, z);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v000, v100, v101, v001, texSlot, color);
        }

        content = chunk.GetCellContent(x, y, z - 1);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v000, v010, v110, v100, texSlot, color);
        }

        content = chunk.GetCellContent(x + 1, y, z);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v100, v110, v111, v101, texSlot, color);
        }

        content = chunk.GetCellContent(x, y + 1, z);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v111, v110, v010, v011, texSlot, color);
        }

        content = chunk.GetCellContent(x, y, z + 1);
        if (content != BlockTerrain.NULL_BLOCK_CONTENT && content != Index && BlocksData.IsTransparent[content])
        {
            terrainMesh.NormalQuad(v101, v111, v011, v001, texSlot, color);
        }
    }
Beispiel #4
0
    public void GenerateTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, MeshGenerator g)
    {
        int   textureSlot = GetIsSmall(BlockTerrain.GetData(value)) ? 84 : 85;
        Color color       = GrassBlock.map.Lookup(chunk.GetShiftValue(x, z));

        g.AlphaTest.TwoSidedQuad(new Vector3(x, y, z),
                                 new Vector3(x + 1.0f, y, z + 1.0f),
                                 new Vector3(x + 1.0f, y + 1.0f, z + 1.0f),
                                 new Vector3(x, y + 1.0f, z),
                                 textureSlot, color);

        g.AlphaTest.TwoSidedQuad(new Vector3(x, y, z + 1.0f),
                                 new Vector3(x + 1.0f, y, z),
                                 new Vector3(x + 1.0f, y + 1.0f, z),
                                 new Vector3(x, y + 1.0f, z + 1.0f),
                                 textureSlot, color);
    }
Beispiel #5
0
    public void GenerateTerrain(int x, int y, int z, int value, int face, BlockTerrain.Chunk chunk, ref CellFace data)
    {
        switch (face)
        {
        case CellFace.TOP:
            data.TextureSlot = 0;
            data.Color       = map.Lookup(chunk.GetShiftValue(x, z));
            break;

        case CellFace.BOTTOM:
            data.TextureSlot = 2;
            data.Color       = Color.white;
            break;

        default:
            data.TextureSlot = 3;
            data.Color       = Color.white;
            break;
        }
    }
Beispiel #6
0
    public override void GenerateTerrain(int x, int y, int z, int value, BlockTerrain.Chunk chunk, MeshGenerator g)
    {
        Color color = map.Lookup(chunk.GetShiftValue(x, z));

        GenerateFluidTerrain(x, y, z, value, chunk, g.AlphaTest, color, color);
    }