Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use c shape files #1151

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1037,21 +1036,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 @@ -1061,8 +1060,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 @@ -1397,7 +1394,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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

todo?

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
Loading