public void TransferData_Split(int minX, int minY, int maxX, int maxY) { int maxChunkX = maxX / TransferSize; int maxChunkY = maxY / TransferSize; int minChunkX = minX / TransferSize; int minChunkY = minY / TransferSize; for (int chunkY = minChunkY; chunkY <= maxChunkY; chunkY++) { for (int chunkX = minChunkX; chunkX <= maxChunkX; chunkX++) { if (dispInfo.generationList == null) { dispInfo.generationList = Enumerable.Repeat(-1, (worldMgr.worldData.width / TransferSize) * (worldMgr.worldData.height / TransferSize)).ToArray(); } int currentChunkNum_Session = 0; try { currentChunkNum_Session = dispInfo.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX]; } catch (System.Exception ex) { Debug.Log(chunkX + " " + TransferSize + " " + minY + " " + worldMgr.worldData.width + " " + chunkY + " " + TransferSize + " " + minX); } int currentChunkNum_System = 0; if (worldMgr.generationList.Length < chunkY * (worldMgr.worldData.width / TransferSize) + chunkX) { currentChunkNum_System = worldMgr.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX]; } if (currentChunkNum_Session != currentChunkNum_System) { EachTerrainTileData[] result = new EachTerrainTileData[TransferSize * TransferSize]; for (int y = 0; y < TransferSize; y++) { for (int x = 0; x < TransferSize; x++) { try { WorldDataConst.EachTerrainData sourceItem = worldMgr.worldData.terrainList[((chunkY * TransferSize) + y) * worldMgr.worldData.width + chunkX * TransferSize + x]; EachTerrainTileData item = new EachTerrainTileData(); item.type = sourceItem.type; item.x = sourceItem.x; item.y = sourceItem.y; result[y * TransferSize + x] = item; } catch (System.Exception ex) { Debug.Log(ex.StackTrace); Debug.Log(chunkX + " " + TransferSize + " " + minY + " " + worldMgr.worldData.width + " " + chunkY + " " + TransferSize + " " + minX); } } } TargetTransfer(connectionToClient, chunkY * TransferSize + minY, chunkX * TransferSize + minX, TransferSize, TransferSize, result); dispInfo.generationList[chunkY * (worldMgr.worldData.width / TransferSize) + chunkX] = currentChunkNum_System; } } } }
public void UpdateMap() { UpdateMapInfoContainer dispContainer; DateTime start = DateTime.Now; if (updateList4Disp != null) { while (updateList4Disp.TryDequeue(out dispContainer)) { while (dispContainer.nextReadIndex < dispContainer.tiles.Length) { EachTerrainTileData eachtile = dispContainer.tiles[dispContainer.nextReadIndex]; if (eachtile != null) { WorldDataConst.TileType currentTileType = eachtile.type; Vector3Int currentPos = new Vector3Int(eachtile.x, eachtile.y, 0); if ( (player.groundTilemap.GetTile(currentPos) == null) || (!player.groundTilemap.GetTile(currentPos).Equals(currentTileType)) ) { if ((currentTileType == WorldDataConst.TileType.FIELD)) { player.groundTilemap.SetTile(currentPos, field); } else { player.groundTilemap.SetTile(currentPos, sea); } } } dispContainer.nextReadIndex++; DateTime current = DateTime.Now; if ((current - start).TotalMilliseconds > 100) { current = start; break; } } if (dispContainer.nextReadIndex < dispContainer.tiles.Length) { updateList4Disp.Enqueue(dispContainer); break; } } } }