use c shape files

This commit is contained in:
Alex Bates 2024-01-19 21:56:07 +00:00
parent bfe9a42b06
commit 8dceac971a
2 changed files with 24 additions and 20 deletions

View File

@ -486,7 +486,6 @@ class Configure:
skip_outputs: Set[str], skip_outputs: Set[str],
non_matching: bool, non_matching: bool,
modern_gcc: bool, modern_gcc: bool,
c_maps: bool = False,
): ):
assert self.linker_entries is not None assert self.linker_entries is not None
@ -1039,21 +1038,21 @@ class Configure:
}, },
asset_deps=[f"mapfs/tex/{name}"], asset_deps=[f"mapfs/tex/{name}"],
) )
elif name.endswith("_shape_built"): elif name.endswith("_shape"):
base_name = name[:-6] base_name = name[:-6]
raw_bin_path = self.resolve_asset_path(f"assets/x/mapfs/geom/{base_name}.bin")
bin_path = bin_path.parent / "geom" / (base_name + ".bin")
if c_maps: # Backwards-compatibility: if there is a .bin file, use that
# raw bin -> c -> o -> elf -> objcopy -> final bin file path_deprecated = self.resolve_asset_path(path.with_suffix(".bin"))
c_file_path = (bin_path.parent / "geom" / base_name).with_suffix(".c") if path_deprecated.is_file():
o_path = bin_path.parent / "geom" / (base_name + ".o") print(f"warning: {name} has a .bin file, which is deprecated. use a .c file instead.")
elf_path = bin_path.parent / "geom" / (base_name + ".elf") print(bin_path, path_deprecated)
build(bin_path, [path_deprecated], "cp")
build(c_file_path, [raw_bin_path], "shape") else:
o_path = bin_path.with_suffix(".o")
elf_path = bin_path.with_suffix(".elf")
build( build(
o_path, o_path,
[c_file_path], [path],
"cc" if not modern_gcc else "cc_modern", "cc" if not modern_gcc else "cc_modern",
variables={ variables={
"cflags": "", "cflags": "",
@ -1063,8 +1062,6 @@ class Configure:
) )
build(elf_path, [o_path], "shape_ld") build(elf_path, [o_path], "shape_ld")
build(bin_path, [elf_path], "shape_objcopy") build(bin_path, [elf_path], "shape_objcopy")
else:
build(bin_path, [raw_bin_path], "cp")
compress = True compress = True
out_dir = out_dir / "geom" out_dir = out_dir / "geom"
@ -1399,7 +1396,7 @@ if __name__ == "__main__":
sys.path.append(str((ROOT / "tools/splat_ext").resolve())) sys.path.append(str((ROOT / "tools/splat_ext").resolve()))
configure.split(not args.no_split_assets, args.split_code, args.shift, args.debug) configure.split(not args.no_split_assets, args.split_code, args.shift, args.debug)
configure.write_ninja(ninja, skip_files, non_matching, args.modern_gcc, args.c_maps) configure.write_ninja(ninja, skip_files, non_matching, args.modern_gcc)
all_rom_oks.append(str(configure.rom_ok_path())) all_rom_oks.append(str(configure.rom_ok_path()))

View File

@ -12,6 +12,9 @@ import yaml as yaml_loader
import n64img.image import n64img.image
from tex_archives import TexArchive from tex_archives import TexArchive
sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "build")) # terrible
from mapfs.shape import ShapeFile
script_dir = Path(os.path.dirname(os.path.realpath(__file__))) script_dir = Path(os.path.dirname(os.path.realpath(__file__)))
@ -49,15 +52,13 @@ def parse_palette(data):
return palette return palette
def add_file_ext(name: str, linker: bool = False) -> str: def add_file_ext(name: str) -> str:
if name.startswith("party_"): if name.startswith("party_"):
return "party/" + name + ".png" return "party/" + name + ".png"
elif name.endswith("_hit"): elif name.endswith("_hit"):
return "geom/" + name + ".bin" return "geom/" + name + ".bin"
elif name.endswith("_shape"): elif name.endswith("_shape"):
if linker: return "geom/" + name + ".c"
name += "_built"
return "geom/" + name + ".bin"
elif name.endswith("_tex"): elif name.endswith("_tex"):
return "tex/" + name + ".bin" return "tex/" + name + ".bin"
elif name.endswith("_bg"): elif name.endswith("_bg"):
@ -213,6 +214,12 @@ class N64SegPm_map_data(N64Segment):
elif name.endswith("_tex"): elif name.endswith("_tex"):
TexArchive.extract(bytes, fs_dir / "tex" / name) TexArchive.extract(bytes, fs_dir / "tex" / name)
elif name.endswith("_shape"):
map_name = name[:-6]
shape = ShapeFile(map_name, bytes)
shape.digest()
with open(path, "w") as f:
shape.write_to_c(f)
else: else:
assert path is not None assert path is not None
with open(path, "wb") as f: with open(path, "wb") as f:
@ -231,7 +238,7 @@ class N64SegPm_map_data(N64Segment):
src_paths = [] src_paths = []
for name, file in self.files.items(): for name, file in self.files.items():
src_paths.append(fs_dir / add_file_ext(name, linker=True)) src_paths.append(fs_dir / add_file_ext(name))
if file.get("dump_raw", False): if file.get("dump_raw", False):
src_paths.append(fs_dir / f"{name}.raw.dat") src_paths.append(fs_dir / f"{name}.raw.dat")