1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-27 07:07:09 +00:00

Fix extract_baserom with non-forking multiprocessing (#572)

Co-authored-by: zelda2774 <zelda2774@invalid>
This commit is contained in:
zelda2774 2020-12-28 23:19:48 +01:00 committed by GitHub
parent 86898891da
commit ed17c81a33
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,15 +1,13 @@
#!/usr/bin/python3
import os;
import sys;
import struct;
from multiprocessing import Pool
from multiprocessing import cpu_count
import os
import sys
import struct
from multiprocessing import Pool, cpu_count
ROM_FILE_NAME = 'baserom.z64'
FILE_TABLE_OFFSET = 0x12F70
FILE_COUNT = 1532
FILE_NAMES = [
'makerom',
@ -1546,6 +1544,12 @@ FILE_NAMES = [
'softsprite_matrix_static',
]
romData = None
def initialize_worker(rom_data):
global romData
romData = rom_data
def read_uint32_be(offset):
return struct.unpack('>I', romData[offset:offset+4])[0]
@ -1580,21 +1584,25 @@ def ExtractFunc(i):
#####################################################################
try:
os.mkdir('baserom')
except:
pass
def main():
try:
os.mkdir('baserom')
except:
pass
# read baserom data
try:
with open(ROM_FILE_NAME, 'rb') as f:
romData = f.read()
except IOError:
print('failed to read file' + ROM_FILE_NAME)
sys.exit(1)
# read baserom data
try:
with open(ROM_FILE_NAME, 'rb') as f:
rom_data = f.read()
except IOError:
print('failed to read file' + ROM_FILE_NAME)
sys.exit(1)
# extract files
numCores = cpu_count()
print("Extracting baserom with " + str(numCores) + " CPU cores.")
p = Pool(numCores)
p.map(ExtractFunc, range(0, FILE_COUNT))
# extract files
num_cores = cpu_count()
print("Extracting baserom with " + str(num_cores) + " CPU cores.")
with Pool(num_cores, initialize_worker, (rom_data,)) as p:
p.map(ExtractFunc, range(len(FILE_NAMES)))
if __name__ == "__main__":
main()