mirror of
https://github.com/zeldaret/oot.git
synced 2025-07-03 22:44:30 +00:00
Fix extract_baserom with non-forking multiprocessing (#572)
Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
parent
86898891da
commit
ed17c81a33
1 changed files with 30 additions and 22 deletions
|
@ -1,15 +1,13 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
|
|
||||||
import os;
|
import os
|
||||||
import sys;
|
import sys
|
||||||
import struct;
|
import struct
|
||||||
from multiprocessing import Pool
|
from multiprocessing import Pool, cpu_count
|
||||||
from multiprocessing import cpu_count
|
|
||||||
|
|
||||||
|
|
||||||
ROM_FILE_NAME = 'baserom.z64'
|
ROM_FILE_NAME = 'baserom.z64'
|
||||||
FILE_TABLE_OFFSET = 0x12F70
|
FILE_TABLE_OFFSET = 0x12F70
|
||||||
FILE_COUNT = 1532
|
|
||||||
|
|
||||||
FILE_NAMES = [
|
FILE_NAMES = [
|
||||||
'makerom',
|
'makerom',
|
||||||
|
@ -1546,6 +1544,12 @@ FILE_NAMES = [
|
||||||
'softsprite_matrix_static',
|
'softsprite_matrix_static',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
romData = None
|
||||||
|
|
||||||
|
|
||||||
|
def initialize_worker(rom_data):
|
||||||
|
global romData
|
||||||
|
romData = rom_data
|
||||||
|
|
||||||
def read_uint32_be(offset):
|
def read_uint32_be(offset):
|
||||||
return struct.unpack('>I', romData[offset:offset+4])[0]
|
return struct.unpack('>I', romData[offset:offset+4])[0]
|
||||||
|
@ -1580,21 +1584,25 @@ def ExtractFunc(i):
|
||||||
|
|
||||||
#####################################################################
|
#####################################################################
|
||||||
|
|
||||||
try:
|
def main():
|
||||||
os.mkdir('baserom')
|
try:
|
||||||
except:
|
os.mkdir('baserom')
|
||||||
pass
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# read baserom data
|
# read baserom data
|
||||||
try:
|
try:
|
||||||
with open(ROM_FILE_NAME, 'rb') as f:
|
with open(ROM_FILE_NAME, 'rb') as f:
|
||||||
romData = f.read()
|
rom_data = f.read()
|
||||||
except IOError:
|
except IOError:
|
||||||
print('failed to read file' + ROM_FILE_NAME)
|
print('failed to read file' + ROM_FILE_NAME)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# extract files
|
# extract files
|
||||||
numCores = cpu_count()
|
num_cores = cpu_count()
|
||||||
print("Extracting baserom with " + str(numCores) + " CPU cores.")
|
print("Extracting baserom with " + str(num_cores) + " CPU cores.")
|
||||||
p = Pool(numCores)
|
with Pool(num_cores, initialize_worker, (rom_data,)) as p:
|
||||||
p.map(ExtractFunc, range(0, FILE_COUNT))
|
p.map(ExtractFunc, range(len(FILE_NAMES)))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue