/// <summary> /// Deserializes an IMapManager and ITileDefinitionManager from a properly formatted NetMessage. /// </summary> /// <param name="message">The message containing a serialized map and tileDefines.</param> private void HandleTileMap(MsgMap message) { Debug.Assert(_netManager.IsClient, "Why is the server calling this?"); GridsReceived++; var mapIndex = message.MapIndex; var gridIndex = message.GridIndex; _defManager.RegisterServerTileMapping(message); var chunkSize = message.ChunkSize; var chunkCount = message.ChunkDefs.Length; if (!_mapManager.TryGetMap(mapIndex, out IMap map)) { map = _mapManager.CreateMap(mapIndex); } if (!map.GridExists(gridIndex)) { _mapManager.GetMap(mapIndex).CreateGrid(gridIndex, chunkSize); } IMapGrid grid = _mapManager.GetMap(mapIndex).GetGrid(gridIndex); for (var i = 0; i < chunkCount; ++i) { var chunkPos = new MapGrid.Indices(message.ChunkDefs[i].X, message.ChunkDefs[i].Y); var chunk = grid.GetChunk(chunkPos); var counter = 0; for (ushort x = 0; x < chunk.ChunkSize; x++) { for (ushort y = 0; y < chunk.ChunkSize; y++) { chunk.SetTile(x, y, (Tile)message.ChunkDefs[i].Tiles[counter]); counter++; } } } if (GridsReceived == GridsToReceive) { IoCManager.Resolve <IEntityManager>().MapsInitialized = true; } }