Example #1
0
            public Tile this[int x, int y]
            {
                get
                {
                    Point chunkPos = new Point(
                        (int)Math.Floor((float)x / ChunkSize),
                        (int)Math.Floor((float)y / ChunkSize)
                    );
                    Chunk chunk;
                    if (mm.chunks.TryGetValue(chunkPos, out chunk))
                        return chunk.Tiles[(y - chunkPos.Y * ChunkSize) * ChunkSize + (x - chunkPos.X * ChunkSize)];
                    else
                        return default(Tile); // SPAAAAAAAAAAAAAACE!!!
                }
                set
                {
                    Point chunkPos = new Point(
                        (int)Math.Floor((float)x / ChunkSize),
                        (int)Math.Floor((float)y / ChunkSize)
                    );
                    Chunk chunk;
                    if (!mm.chunks.TryGetValue(chunkPos, out chunk))
                    {
                        if (value.IsSpace)
                            return;
                        else
                            mm.chunks[chunkPos] = chunk = new Chunk();
                    }

                    int index = (y - chunkPos.Y * ChunkSize) * ChunkSize + (x - chunkPos.X * ChunkSize);
                    Tile oldTile = chunk.Tiles[index];
                    if (oldTile == value)
                        return;

                    chunk.Tiles[index] = value;

                    if (mm.TileChanged != null)
                        mm.TileChanged(new TileRef(mm, x, y, chunk, index), oldTile);
                }
            }
Example #2
0
        public bool LoadTileMap(NetIncomingMessage message)
        {
            int version = message.ReadInt32();
            if (version != 1)
                return false; // Unsupported version.

            var tileDefMgr = IoCManager.Resolve<ITileDefinitionManager>();
            tileDefMgr.RegisterServerTileMapping(message);

            int chunkCount = message.ReadInt32();
            for (int i = 0; i < chunkCount; ++i)
            {
                int x = message.ReadInt32();
                int y = message.ReadInt32();
                var chunkPos = new Point(x, y);

                Chunk chunk;
                if (!chunks.TryGetValue(chunkPos, out chunk))
                    chunks[chunkPos] = chunk = new Chunk();

                chunk.ReceiveChunkData(message);
            }

            return true;
        }