Skip to content

Commit

Permalink
use c shape files
Browse files Browse the repository at this point in the history
  • Loading branch information
bates64 committed Jan 19, 2024
1 parent bfe9a42 commit 8dceac9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
27 changes: 12 additions & 15 deletions tools/build/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ def write_ninja(
skip_outputs: Set[str],
non_matching: bool,
modern_gcc: bool,
c_maps: bool = False,
):
assert self.linker_entries is not None

Expand Down Expand Up @@ -1039,21 +1038,21 @@ def build(
},
asset_deps=[f"mapfs/tex/{name}"],
)
elif name.endswith("_shape_built"):
elif name.endswith("_shape"):
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:
# raw bin -> c -> o -> elf -> objcopy -> final bin file
c_file_path = (bin_path.parent / "geom" / base_name).with_suffix(".c")
o_path = bin_path.parent / "geom" / (base_name + ".o")
elf_path = bin_path.parent / "geom" / (base_name + ".elf")

build(c_file_path, [raw_bin_path], "shape")
# Backwards-compatibility: if there is a .bin file, use that
path_deprecated = self.resolve_asset_path(path.with_suffix(".bin"))
if path_deprecated.is_file():
print(f"warning: {name} has a .bin file, which is deprecated. use a .c file instead.")
print(bin_path, path_deprecated)
build(bin_path, [path_deprecated], "cp")
else:
o_path = bin_path.with_suffix(".o")
elf_path = bin_path.with_suffix(".elf")
build(
o_path,
[c_file_path],
[path],
"cc" if not modern_gcc else "cc_modern",
variables={
"cflags": "",
Expand All @@ -1063,8 +1062,6 @@ def build(
)
build(elf_path, [o_path], "shape_ld")
build(bin_path, [elf_path], "shape_objcopy")
else:
build(bin_path, [raw_bin_path], "cp")

compress = True
out_dir = out_dir / "geom"
Expand Down Expand Up @@ -1399,7 +1396,7 @@ def make_current(self, ninja: ninja_syntax.Writer):
sys.path.append(str((ROOT / "tools/splat_ext").resolve()))

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()))

Expand Down
17 changes: 12 additions & 5 deletions tools/splat_ext/pm_map_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import n64img.image
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__)))


Expand Down Expand Up @@ -49,15 +52,13 @@ def unpack_color(data):
return palette


def add_file_ext(name: str, linker: bool = False) -> str:
def add_file_ext(name: str) -> str:
if name.startswith("party_"):
return "party/" + name + ".png"
elif name.endswith("_hit"):
return "geom/" + name + ".bin"
elif name.endswith("_shape"):
if linker:
name += "_built"
return "geom/" + name + ".bin"
return "geom/" + name + ".c"
elif name.endswith("_tex"):
return "tex/" + name + ".bin"
elif name.endswith("_bg"):
Expand Down Expand Up @@ -213,6 +214,12 @@ def split(self, rom_bytes):

elif name.endswith("_tex"):
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:
assert path is not None
with open(path, "wb") as f:
Expand All @@ -231,7 +238,7 @@ def get_linker_entries(self):

src_paths = []
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):
src_paths.append(fs_dir / f"{name}.raw.dat")

Expand Down

0 comments on commit 8dceac9

Please sign in to comment.