Unhardcode some worldmap data addresses
This commit is contained in:
parent
5a29fa0922
commit
9a5435f01f
|
@ -96,15 +96,13 @@ var worldmaps = [WorldMap.new(), WorldMap.new(), WorldMap.new(), WorldMap.new(),
|
||||||
|
|
||||||
var worldmap_block_properties = []
|
var worldmap_block_properties = []
|
||||||
var worldmap_block_pathings = []
|
var worldmap_block_pathings = []
|
||||||
func load_worldmap_block_properties(buffer: StreamPeerBuffer):
|
func load_worldmap_block_properties(data: Dictionary): # TODO: replace this with a struct definition
|
||||||
buffer.seek(0x0FEA00)
|
for world_ts in data.worldmap_block_properties: # 3
|
||||||
for world_ts in 3:
|
|
||||||
var ts_properties = PoolIntArray()
|
var ts_properties = PoolIntArray()
|
||||||
var ts_pathings = PoolIntArray()
|
var ts_pathings = PoolIntArray()
|
||||||
for block in 0xC0:
|
for properties in world_ts:
|
||||||
var properties := buffer.get_u16() + (buffer.get_u8() << 16)
|
|
||||||
ts_properties.append(properties)
|
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
|
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)
|
ts_pathings.append(pathings)
|
||||||
worldmap_block_properties.append(ts_properties)
|
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]
|
worldmaps[4].block_pathing = worldmap_block_pathings[2]
|
||||||
|
|
||||||
|
|
||||||
func load_worldmaps(buffer: StreamPeerBuffer):
|
func load_worldmaps(data: Dictionary, buffer: StreamPeerBuffer):
|
||||||
var chunk_addresses = PoolIntArray()
|
var offset1: int = Common.SNES_PSX_addresses.worldmap_compressed_tilesets.SNES
|
||||||
chunk_addresses.resize(0x500) # 5 worldmaps * 256 chunks
|
var offset2: int = Common.SNES_PSX_addresses.worldmap_compressed_tilesets2.SNES
|
||||||
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
|
|
||||||
|
|
||||||
for worldmap_id in 5: # Bartz World, Galuf World, Combined World, Underwater Galuf World, Underwater Combined World
|
for worldmap_id in 5: # Bartz World, Galuf World, Combined World, Underwater Galuf World, Underwater Combined World
|
||||||
# Worldmap chunks have a basic compression.
|
# Worldmap chunks have a basic compression.
|
||||||
# Repeated blocks along a row are run-length-encoded (RLE)
|
# Repeated blocks along a row are run-length-encoded (RLE)
|
||||||
# Certain blocks (mountains) expand to 1x3
|
# Certain blocks (mountains) expand to 1x3
|
||||||
|
var chunk_addresses: Array = data.ptrs_worldmap_tilesets[worldmap_id]
|
||||||
var blockmap = PoolByteArray()
|
var blockmap = PoolByteArray()
|
||||||
# blockmap.resize(WorldMap.block_height * WorldMap.block_width) # Try this later if performance is a problem
|
# 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):
|
for chunk_id in 0x100:
|
||||||
buffer.seek(chunk_addresses[chunk_id])
|
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
|
var chunk_size := 0
|
||||||
while chunk_size < 256:
|
while chunk_size < 256:
|
||||||
# var b: int = (blockmap.size() % 16) + (16 * (chunk_id % 12)); # For debugging the map shader against blocks
|
# 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[3].block_tile_ids = worldmap_block_tile_ids[2]
|
||||||
worldmaps[4].block_tile_ids = worldmap_block_tile_ids[2]
|
worldmaps[4].block_tile_ids = worldmap_block_tile_ids[2]
|
||||||
|
|
||||||
func load_snes_rom(buffer: StreamPeerBuffer):
|
func load_snes_rom(data: Dictionary, buffer: StreamPeerBuffer):
|
||||||
load_worldmap_block_properties(buffer)
|
load_worldmap_block_properties(data)
|
||||||
load_worldmaps(buffer)
|
load_worldmaps(data, buffer)
|
||||||
|
|
|
@ -100,7 +100,7 @@ func load_snes_rom_from_bytes(bytes: PoolByteArray) -> void:
|
||||||
yield(_on_loader_loading_stage_updated('Loading battle backgrounds', 'SpriteLoader'), 'completed')
|
yield(_on_loader_loading_stage_updated('Loading battle backgrounds', 'SpriteLoader'), 'completed')
|
||||||
SpriteLoader.load_battle_bgs(self.snes_data, self.snes_buffer)
|
SpriteLoader.load_battle_bgs(self.snes_data, self.snes_buffer)
|
||||||
yield(_on_loader_loading_stage_updated('Loading map data', 'MapLoader'), 'completed')
|
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')
|
yield(_on_loader_loading_stage_updated('Finished loading!', 'RomLoader'), 'completed')
|
||||||
emit_signal('rom_loaded')
|
emit_signal('rom_loaded')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue