Skip to content

Commit

Permalink
Improve game loading speeds somewhat
Browse files Browse the repository at this point in the history
Write file datas to the ISO in the same order they were written in vanilla, which is not the same order as the file entries. This improves performance of the game reading files for some reason.

Note that rando loading speeds are still slower than vanilla even with this change, just less so now.
  • Loading branch information
LagoLunatic committed Apr 16, 2019
1 parent e6ca75e commit 98668cb
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions wwlib/gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ def add_new_file(self, file_path):
new_file = FileEntry()
new_file.name = basename
new_file.file_path = file_path
new_file.file_data_offset = None
new_file.file_size = None
new_file.vanilla_file_data_offset = (1<<32) # Order new files to be written after vanilla files in the ISO

parent_dir = self.get_dir_file_entry(dirname)
parent_dir.children.append(new_file)
Expand Down Expand Up @@ -280,10 +283,15 @@ def export_filesystem_to_iso(self):
self.output_iso.seek(file_data_start_offset)
self.align_output_iso_to_nearest(4)

for file_entry in self.file_entries:
if file_entry.is_dir:
continue

# Instead of writing the file data in the order of file entries, write them in the order they were written in the vanilla ISO.
# This increases the speed the game loads file for some unknown reason.
file_entries_by_data_order = [
file_entry for file_entry in self.file_entries
if not file_entry.is_dir
]
file_entries_by_data_order.sort(key=lambda fe: fe.vanilla_file_data_offset)

for file_entry in file_entries_by_data_order:
current_file_start_offset = self.output_iso.tell()

if file_entry.file_path in self.changed_files:
Expand All @@ -307,11 +315,13 @@ def export_filesystem_to_iso(self):
offset_in_file += size_to_read

file_entry_offset = self.fst_offset + file_entry.file_index*0xC
file_entry.file_data_offset = current_file_start_offset
write_u32(self.output_iso, file_entry_offset+4, current_file_start_offset)
if file_entry.file_path in self.changed_files:
file_size = data_len(self.changed_files[file_entry.file_path])
else:
file_size = file_entry.file_size
file_entry.file_size = file_size
write_u32(self.output_iso, file_entry_offset+8, file_size)

self.output_iso.seek(current_file_start_offset + file_size)
Expand Down Expand Up @@ -340,6 +350,7 @@ def read(self, file_index, iso_file, file_entry_offset, fnt_offset):
self.children = []
else:
self.file_data_offset = file_data_offset_or_parent_fst_index
self.vanilla_file_data_offset = file_data_offset_or_parent_fst_index
self.file_size = file_size_or_next_fst_index
self.parent = None

Expand Down

0 comments on commit 98668cb

Please sign in to comment.