Esempio n. 1
0
    private byte[][] TileInChunksMessages(World world,
                                          byte tile,
                                          int size = 128)
    {
        int x = tile % 16;
        int y = tile / 16;

        Color[] colors = world.tileset.GetPixels(x * 32, y * 32, 32, 32);
        byte[] bytes = colors.Select(c => world.ColorToPalette(c, true)).ToArray();
        byte[] chunk;

        int offset = 0;

        var messages = new List<byte[]>();

        while (bytes.Any())
        {
            chunk = bytes.Take(size).ToArray();
            bytes = bytes.Skip(size).ToArray();

            var writer = new NetworkWriter();
            writer.Write((byte) Type.TileChunk);
            writer.Write(tile);
            writer.Write(offset);
            writer.WriteBytesFull(CrunchBytes(chunk));

            messages.Add(writer.AsArray());

            offset += size;
        }

        return messages.ToArray();
    }
Esempio n. 2
0
    private byte[][] AvatarInChunksMessages(World world,
                                            World.Avatar avatar,
                                            int size = 128)
    {
        Color32[] colors = avatar.graphic.texture.GetPixels32();
        byte[] bytes = colors.Select(c => world.ColorToPalette(c, true)).ToArray();
        byte[] chunk;

        int offset = 0;

        var messages = new List<byte[]>();

        while (bytes.Any())
        {
            chunk = bytes.Take(size).ToArray();
            bytes = bytes.Skip(size).ToArray();

            var writer = new NetworkWriter();
            writer.Write((byte) Type.AvatarChunk);
            writer.Write(avatar.id);
            writer.Write(offset);
            writer.WriteBytesFull(CrunchBytes(chunk));

            messages.Add(writer.AsArray());

            offset += size;
        }

        return messages.ToArray();
    }