From b22b1e6c9c420259fcbc87cd44d9c82db2f8ad0a Mon Sep 17 00:00:00 2001 From: dingo Date: Thu, 18 Dec 2025 11:33:12 -0500 Subject: [PATCH] Dungeon Tile RLE Missing --- scripts/autoload/game_state.gd | 46 ++++++++++++++++++++++++++++++++-- scripts/autoload/network.gd | 5 ++++ 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/scripts/autoload/game_state.gd b/scripts/autoload/game_state.gd index d220d8a..56743fa 100644 --- a/scripts/autoload/game_state.gd +++ b/scripts/autoload/game_state.gd @@ -178,8 +178,13 @@ func _handle_dungeon_enter(data: Dictionary): dungeon.width = int(data.get("width", data.get("Width", 0))) dungeon.height = int(data.get("height", data.get("Height", 0))) - var tiles_data = data.get("tiles", data.get("Tiles", "")) - _parse_tiles(tiles_data) + # Check for RLE tiles first, fallback to legacy format + var tiles_rle = data.get("tilesRLE", data.get("TilesRLE", "")) + if not tiles_rle.is_empty(): + _parse_tiles_rle(tiles_rle) + else: + var tiles_data = data.get("tiles", data.get("Tiles", "")) + _parse_tiles(tiles_data) var spawn = data.get("spawn", data.get("Spawn", {})) self_player = { @@ -229,6 +234,43 @@ func _parse_tiles(tiles_string: String): if x >= dungeon.width: break dungeon.tiles[x][y] = 0 if row[x] == "." else 1 +func _parse_tiles_rle(rle_string: String): + # RLE format: "tile,count;tile,count;..." + # Decode into a flat array first, then reshape to 2D + dungeon.tiles = [] + if rle_string.is_empty(): + return + + # Initialize 2D array + for x in range(dungeon.width): + dungeon.tiles.append([]) + for y in range(dungeon.height): + dungeon.tiles[x].append(0) + + # Decode RLE + var flat_tiles: Array[int] = [] + var runs = rle_string.split(";") + + for run in runs: + if run.is_empty(): + continue + var parts = run.split(",") + if parts.size() != 2: + continue + var tile_value = int(parts[0]) + var count = int(parts[1]) + for i in range(count): + flat_tiles.append(tile_value) + + # Convert flat array to 2D (row-major order: y then x) + var idx = 0 + for y in range(dungeon.height): + for x in range(dungeon.width): + if idx < flat_tiles.size(): + dungeon.tiles[x][y] = flat_tiles[idx] + idx += 1 + + print("[GameState] Parsed RLE tiles: %d values for %dx%d grid" % [flat_tiles.size(), dungeon.width, dungeon.height]) func _handle_dungeon_state(data: Dictionary): # Check dungeon phase first diff --git a/scripts/autoload/network.gd b/scripts/autoload/network.gd index b674484..eb8457e 100644 --- a/scripts/autoload/network.gd +++ b/scripts/autoload/network.gd @@ -50,6 +50,11 @@ func connect_to_server() -> Error: # Reset socket for fresh connection socket = WebSocketPeer.new() + # Increase buffer sizes for large dungeon data + socket.inbound_buffer_size = 8 * 1024 * 1024 # 8MB + socket.outbound_buffer_size = 1024 * 1024 # 1MB + socket.max_queued_packets = 4096 + print("[Network] Attempting connection to: ", SERVER_URL) var err = socket.connect_to_url(SERVER_URL)