mirror of
https://github.com/zeldaret/oot.git
synced 2024-11-10 19:20:13 +00:00
Track XML extraction time (#826)
* extracted-assets.json * delete `.extracted-assets.json` in distclean * Move `rm .extracted-assets.json` to `assetclean`
This commit is contained in:
parent
201c9ec1cd
commit
45012658d3
3 changed files with 51 additions and 18 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -47,6 +47,7 @@ graphs/
|
||||||
*.mtl
|
*.mtl
|
||||||
*.fbx
|
*.fbx
|
||||||
!*_custom*
|
!*_custom*
|
||||||
|
.extracted-assets.json
|
||||||
|
|
||||||
# Per-user configuration
|
# Per-user configuration
|
||||||
.python-version
|
.python-version
|
||||||
|
|
3
Makefile
3
Makefile
|
@ -183,7 +183,8 @@ clean:
|
||||||
|
|
||||||
assetclean:
|
assetclean:
|
||||||
$(RM) -r $(ASSET_BIN_DIRS)
|
$(RM) -r $(ASSET_BIN_DIRS)
|
||||||
$(RM) -r build/assets
|
$(RM) -r build/assets
|
||||||
|
$(RM) -r .extracted-assets.json
|
||||||
|
|
||||||
distclean: clean assetclean
|
distclean: clean assetclean
|
||||||
$(RM) -r baserom/
|
$(RM) -r baserom/
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
from multiprocessing import Pool, cpu_count, Event
|
from multiprocessing import Pool, cpu_count, Event, Manager
|
||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
|
|
||||||
# Returns True if outFile doesn't exists
|
EXTRACTED_ASSETS_NAMEFILE = ".extracted-assets.json"
|
||||||
# or if inFile has been modified after the last modification of outFile
|
|
||||||
def checkTouchedFile(inFile: str, outFile: str) -> bool:
|
def SignalHandler(sig, frame):
|
||||||
if not os.path.exists(outFile):
|
print(f'Signal {sig} received. Aborting...')
|
||||||
return True
|
mainAbort.set()
|
||||||
return os.path.getmtime(inFile) > os.path.getmtime(outFile)
|
# Don't exit immediately to update the extracted assets file.
|
||||||
|
|
||||||
def Extract(xmlPath, outputPath, outputSourcePath):
|
def Extract(xmlPath, outputPath, outputSourcePath):
|
||||||
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)
|
ExtractFile(xmlPath, outputPath, outputSourcePath, 1, 0)
|
||||||
|
@ -47,23 +50,37 @@ def ExtractFunc(fullPath):
|
||||||
objectName += "_scene"
|
objectName += "_scene"
|
||||||
|
|
||||||
if not globalForce:
|
if not globalForce:
|
||||||
cFile = os.path.join(outPath, objectName + ".c")
|
if fullPath in globalExtractedAssetsTracker:
|
||||||
hFile = os.path.join(outPath, objectName + ".h")
|
timestamp = globalExtractedAssetsTracker[fullPath]["timestamp"]
|
||||||
if not checkTouchedFile(fullPath, cFile) and not checkTouchedFile(fullPath, hFile):
|
modificationTime = int(os.path.getmtime(fullPath) * (10**9))
|
||||||
return
|
if modificationTime < timestamp:
|
||||||
|
# XML has not been modified since last extraction.
|
||||||
|
return
|
||||||
|
|
||||||
|
currentTimeStamp = time.time_ns()
|
||||||
|
|
||||||
if isScene:
|
if isScene:
|
||||||
ExtractScene(fullPath, outPath, outSourcePath)
|
ExtractScene(fullPath, outPath, outSourcePath)
|
||||||
else:
|
else:
|
||||||
Extract(fullPath, outPath, outSourcePath)
|
Extract(fullPath, outPath, outSourcePath)
|
||||||
|
|
||||||
def initializeWorker(force: bool, abort, unaccounted: bool):
|
if not globalAbort.is_set():
|
||||||
|
# Only update timestamp on succesful extractions
|
||||||
|
if fullPath not in globalExtractedAssetsTracker:
|
||||||
|
globalExtractedAssetsTracker[fullPath] = globalManager.dict()
|
||||||
|
globalExtractedAssetsTracker[fullPath]["timestamp"] = currentTimeStamp
|
||||||
|
|
||||||
|
def initializeWorker(force: bool, abort, unaccounted: bool, extractedAssetsTracker: dict, manager):
|
||||||
global globalForce
|
global globalForce
|
||||||
global globalAbort
|
global globalAbort
|
||||||
global globalUnaccounted
|
global globalUnaccounted
|
||||||
|
global globalExtractedAssetsTracker
|
||||||
|
global globalManager
|
||||||
globalForce = force
|
globalForce = force
|
||||||
globalAbort = abort
|
globalAbort = abort
|
||||||
globalUnaccounted = unaccounted
|
globalUnaccounted = unaccounted
|
||||||
|
globalExtractedAssetsTracker = extractedAssetsTracker
|
||||||
|
globalManager = manager
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = argparse.ArgumentParser(description="baserom asset extractor")
|
parser = argparse.ArgumentParser(description="baserom asset extractor")
|
||||||
|
@ -72,17 +89,25 @@ def main():
|
||||||
parser.add_argument("-u", "--unaccounted", help="Enables ZAPD unaccounted detector warning system.", action="store_true")
|
parser.add_argument("-u", "--unaccounted", help="Enables ZAPD unaccounted detector warning system.", action="store_true")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
abort = Event()
|
global mainAbort
|
||||||
|
mainAbort = Event()
|
||||||
|
manager = Manager()
|
||||||
|
signal.signal(signal.SIGINT, SignalHandler)
|
||||||
|
|
||||||
|
extractedAssetsTracker = manager.dict()
|
||||||
|
if os.path.exists(EXTRACTED_ASSETS_NAMEFILE):
|
||||||
|
with open(EXTRACTED_ASSETS_NAMEFILE) as f:
|
||||||
|
extractedAssetsTracker.update(json.load(f, object_hook=manager.dict))
|
||||||
|
|
||||||
asset_path = args.single
|
asset_path = args.single
|
||||||
if asset_path is not None:
|
if asset_path is not None:
|
||||||
# Always force if -s is used.
|
# Always force if -s is used.
|
||||||
initializeWorker(True, abort, args.unaccounted)
|
initializeWorker(True, mainAbort, args.unaccounted, extractedAssetsTracker, manager)
|
||||||
fullPath = os.path.join("assets", "xml", asset_path + ".xml")
|
fullPath = os.path.join("assets", "xml", asset_path + ".xml")
|
||||||
ExtractFunc(fullPath)
|
ExtractFunc(fullPath)
|
||||||
else:
|
else:
|
||||||
xmlFiles = []
|
xmlFiles = []
|
||||||
for currentPath, folders, files in os.walk(os.path.join("assets", "xml")):
|
for currentPath, _, files in os.walk(os.path.join("assets", "xml")):
|
||||||
for file in files:
|
for file in files:
|
||||||
fullPath = os.path.join(currentPath, file)
|
fullPath = os.path.join(currentPath, file)
|
||||||
if file.endswith(".xml"):
|
if file.endswith(".xml"):
|
||||||
|
@ -90,10 +115,16 @@ def main():
|
||||||
|
|
||||||
numCores = cpu_count()
|
numCores = cpu_count()
|
||||||
print("Extracting assets with " + str(numCores) + " CPU cores.")
|
print("Extracting assets with " + str(numCores) + " CPU cores.")
|
||||||
with Pool(numCores, initializer=initializeWorker, initargs=(args.force, abort, args.unaccounted)) as p:
|
with Pool(numCores, initializer=initializeWorker, initargs=(args.force, mainAbort, args.unaccounted, extractedAssetsTracker, manager)) as p:
|
||||||
p.map(ExtractFunc, xmlFiles)
|
p.map(ExtractFunc, xmlFiles)
|
||||||
|
|
||||||
if abort.is_set():
|
with open(EXTRACTED_ASSETS_NAMEFILE, 'w', encoding='utf-8') as f:
|
||||||
|
serializableDict = dict()
|
||||||
|
for xml, data in extractedAssetsTracker.items():
|
||||||
|
serializableDict[xml] = dict(data)
|
||||||
|
json.dump(dict(serializableDict), f, ensure_ascii=False, indent=4)
|
||||||
|
|
||||||
|
if mainAbort.is_set():
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Reference in a new issue