diff --git a/scripts/loaders/MapLoader.gd b/scripts/loaders/MapLoader.gd index 33bce99..2fec119 100644 --- a/scripts/loaders/MapLoader.gd +++ b/scripts/loaders/MapLoader.gd @@ -96,15 +96,13 @@ var worldmaps = [WorldMap.new(), WorldMap.new(), WorldMap.new(), WorldMap.new(), var worldmap_block_properties = [] var worldmap_block_pathings = [] -func load_worldmap_block_properties(buffer: StreamPeerBuffer): - buffer.seek(0x0FEA00) - for world_ts in 3: +func load_worldmap_block_properties(data: Dictionary): # TODO: replace this with a struct definition + for world_ts in data.worldmap_block_properties: # 3 var ts_properties = PoolIntArray() var ts_pathings = PoolIntArray() - for block in 0xC0: - var properties := buffer.get_u16() + (buffer.get_u8() << 16) + for properties in world_ts: ts_properties.append(properties) - var pathings := properties >> 16 # First 8 pathable flags map directly + var pathings: int = properties >> 16 # First 8 pathable flags map directly pathings |= (((properties >> 12) & 0xF) ^ 0xF) << 8 # Next 4 flags (can land) are taken from high bits of second byte and inverted ts_pathings.append(pathings) worldmap_block_properties.append(ts_properties) @@ -116,23 +114,23 @@ func load_worldmap_block_properties(buffer: StreamPeerBuffer): worldmaps[4].block_pathing = worldmap_block_pathings[2] -func load_worldmaps(buffer: StreamPeerBuffer): - var chunk_addresses = PoolIntArray() - chunk_addresses.resize(0x500) # 5 worldmaps * 256 chunks - buffer.seek(0x0FE000) - for id in range(0, 0x434): - chunk_addresses[id] = buffer.get_u16() + 0x070000 - for id in range(0x434, 0x500): - chunk_addresses[id] = buffer.get_u16() + 0x080000 +func load_worldmaps(data: Dictionary, buffer: StreamPeerBuffer): + var offset1: int = Common.SNES_PSX_addresses.worldmap_compressed_tilesets.SNES + var offset2: int = Common.SNES_PSX_addresses.worldmap_compressed_tilesets2.SNES for worldmap_id in 5: # Bartz World, Galuf World, Combined World, Underwater Galuf World, Underwater Combined World # Worldmap chunks have a basic compression. # Repeated blocks along a row are run-length-encoded (RLE) # Certain blocks (mountains) expand to 1x3 + var chunk_addresses: Array = data.ptrs_worldmap_tilesets[worldmap_id] var blockmap = PoolByteArray() # blockmap.resize(WorldMap.block_height * WorldMap.block_width) # Try this later if performance is a problem - for chunk_id in range(worldmap_id*0x100, (worldmap_id+1)*0x100): - buffer.seek(chunk_addresses[chunk_id]) + for chunk_id in 0x100: + var bank = offset1 + if worldmap_id >= 0x4 and chunk_id >= 0x34: # Chunks 0x434 up to 0x500 are in the next bank + bank = offset2 + + buffer.seek(bank + chunk_addresses[chunk_id]) var chunk_size := 0 while chunk_size < 256: # var b: int = (blockmap.size() % 16) + (16 * (chunk_id % 12)); # For debugging the map shader against blocks @@ -161,6 +159,6 @@ func update_worldmap_block_tile_ids(worldmap_block_tile_ids: Array): worldmaps[3].block_tile_ids = worldmap_block_tile_ids[2] worldmaps[4].block_tile_ids = worldmap_block_tile_ids[2] -func load_snes_rom(buffer: StreamPeerBuffer): - load_worldmap_block_properties(buffer) - load_worldmaps(buffer) +func load_snes_rom(data: Dictionary, buffer: StreamPeerBuffer): + load_worldmap_block_properties(data) + load_worldmaps(data, buffer) diff --git a/scripts/loaders/RomLoader.gd b/scripts/loaders/RomLoader.gd index b2b6875..c730839 100644 --- a/scripts/loaders/RomLoader.gd +++ b/scripts/loaders/RomLoader.gd @@ -100,7 +100,7 @@ func load_snes_rom_from_bytes(bytes: PoolByteArray) -> void: yield(_on_loader_loading_stage_updated('Loading battle backgrounds', 'SpriteLoader'), 'completed') SpriteLoader.load_battle_bgs(self.snes_data, self.snes_buffer) yield(_on_loader_loading_stage_updated('Loading map data', 'MapLoader'), 'completed') - MapLoader.load_snes_rom(self.snes_buffer) + MapLoader.load_snes_rom(self.snes_data, self.snes_buffer) yield(_on_loader_loading_stage_updated('Finished loading!', 'RomLoader'), 'completed') emit_signal('rom_loaded')