Example #1
0
 public Block(Nybble2 data, byte r, byte g, byte b)
 {
     Data = data;
     R    = r;
     G    = g;
     B    = b;
 }
Example #2
0
 public Block(byte material, byte health, byte r, byte g, byte b)
 {
     Data = new Nybble2(material, health);
     R    = r;
     G    = g;
     B    = b;
 }
        public void LoadServerTerrain(NetBuffer data)
        {
            SetTerrain(new FixedTerrain(Renderer));

            DashCMD.WriteStandard("[MPWorld] Loading server world...");

            ushort numChunks    = data.ReadUInt16();
            Chunk  currentChunk = null;
            int    blockI       = 0;
            int    ci           = 0;

            while (ci <= numChunks && data.Position < data.Data.Length)
            {
                byte type = data.ReadByte();

                if (type == 0) // New Chunk
                {
                    int ix = data.ReadInt16();
                    int iy = data.ReadInt16();
                    int iz = data.ReadInt16();

                    if (currentChunk != null)
                    {
                        currentChunk.BakeColors();
                    }

                    IndexPosition ipos = new IndexPosition(ix, iy, iz);
                    currentChunk = new Chunk(Terrain, ipos, AceOfSpades.Terrain.ChunkToWorldCoords(ipos));
                    currentChunk.InitBlocks(Chunk.HSIZE, Chunk.VSIZE, Chunk.HSIZE);
                    currentChunk.State   = ChunkState.Unlit;
                    currentChunk.IsDirty = true;
                    Terrain.Chunks.TryAdd(ipos, currentChunk);

                    blockI = 0;
                    ci++;
                }
                else if (type == 1) // Block section
                {
                    ushort  numBlocks = data.ReadUInt16();
                    byte    d = data.ReadByte();
                    Nybble2 n = new Nybble2(d);
                    byte    r, g, b;
                    byte    mat = n.Lower;

                    if (mat == Block.CUSTOM.Material)
                    {
                        r = data.ReadByte();
                        g = data.ReadByte();
                        b = data.ReadByte();
                    }
                    else
                    {
                        if (mat == Block.GRASS.Material)
                        {
                            r = Block.GRASS.R;
                            g = Block.GRASS.G;
                            b = Block.GRASS.B;
                        }
                        else
                        {
                            r = Block.STONE.R;
                            g = Block.STONE.G;
                            b = Block.STONE.B;
                        }
                    }

                    Block block = new Block(n, r, g, b);

                    for (int i = 0; i < numBlocks; i++)
                    {
                        int z = blockI % Chunk.HSIZE;
                        int y = (blockI / Chunk.HSIZE) % Chunk.VSIZE;
                        int x = blockI / (Chunk.VSIZE * Chunk.HSIZE);

                        currentChunk.Blocks[z, y, x] = block;
                        blockI++;
                    }
                }
            }

            if (currentChunk != null)
            {
                currentChunk.BakeColors();
            }

            Terrain.CreatedFromFile();
        }
        public WorldDescription Load(Stream stream)
        {
            FixedTerrain terrain = new FixedTerrain(MasterRenderer.Instance);

            using (BinaryReader reader = new BinaryReader(stream))
            {
                ushort numChunks    = reader.ReadUInt16();
                Chunk  currentChunk = null;
                int    blockI       = 0;
                int    ci           = 0;

                while (ci <= numChunks && reader.BaseStream.Position < reader.BaseStream.Length)
                {
                    byte type = reader.ReadByte();

                    if (type == 0) // New Chunk
                    {
                        int ix = reader.ReadInt16();
                        int iy = reader.ReadInt16();
                        int iz = reader.ReadInt16();

                        IndexPosition ipos = new IndexPosition(ix, iy, iz);
                        currentChunk = new Chunk(terrain, ipos, AceOfSpades.Terrain.ChunkToWorldCoords(ipos));
                        currentChunk.InitBlocks(Chunk.HSIZE, Chunk.VSIZE, Chunk.HSIZE);
                        currentChunk.State   = ChunkState.Unlit;
                        currentChunk.IsDirty = true;
                        terrain.Chunks.TryAdd(ipos, currentChunk);

                        blockI = 0;
                        ci++;
                    }
                    else if (type == 1) // Block section
                    {
                        ushort  numBlocks = reader.ReadUInt16();
                        byte    d = reader.ReadByte();
                        Nybble2 n = new Nybble2(d);
                        byte    mat = n.Lower;
                        byte    r = 255, g = 255, b = 255;
                        if (mat != Block.AIR.Material)
                        {
                            r = reader.ReadByte();
                            g = reader.ReadByte();
                            b = reader.ReadByte();
                        }

                        Block block = new Block(n, r, g, b);

                        for (int i = 0; i < numBlocks; i++)
                        {
                            int z = blockI % Chunk.HSIZE;
                            int y = (blockI / Chunk.HSIZE) % Chunk.VSIZE;
                            int x = blockI / (Chunk.VSIZE * Chunk.HSIZE);

                            currentChunk.Blocks[z, y, x] = block;
                            blockI++;
                        }
                    }
                }

                if (currentChunk != null)
                {
                    currentChunk.BakeColors();
                }
            }

            return(new WorldDescription(terrain));
        }
Example #5
0
 public Block(byte material)
 {
     Data = new Nybble2(material, 5);
     R    = G = B = 0;
 }