From 348fef6c64a55585b25aa5eae9534d7ad38195cd Mon Sep 17 00:00:00 2001 From: Forest Belton Date: Wed, 29 Sep 2021 14:26:22 -0400 Subject: [PATCH] Move collision into a binary file --- gbsdk/rules.mk | 2 +- scripts/generate_map.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/gbsdk/rules.mk b/gbsdk/rules.mk index fba758e..a04ec36 100644 --- a/gbsdk/rules.mk +++ b/gbsdk/rules.mk @@ -160,7 +160,7 @@ $(BUILD)/assets/%.1bpp: assets/%.png # Special hack to place a ret instruction at the end of the GSINIT section. # This has to be linked last, as that ensures that this fragment is at the end of the "GSINIT" section. $(BUILD)/gsinit.end.o: - @/bin/echo -e 'SECTION FRAGMENT "GSINIT", ROMX, BANK[1]\n ret' | rgbasm - -o $@ + @printf 'SECTION FRAGMENT "GSINIT", ROMX, BANK[1]\n ret' | rgbasm - -o $@ clean: @rm -rf $(BUILD) $(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym diff --git a/scripts/generate_map.py b/scripts/generate_map.py index 935e239..799edb3 100644 --- a/scripts/generate_map.py +++ b/scripts/generate_map.py @@ -24,7 +24,7 @@ Point = Tuple[int, int] def generate_coll_map( in_path: pathlib.Path, width: int, height: int, compress: bool = False -) -> Tuple[str, Point, Point]: +) -> Tuple[bytes, Point, Point]: png = Image.open(in_path).convert("RGB") if png.width % 8 != 0 or png.height % 8 != 0: abort(f"file '{in_path}' has invalid dimensions (should be multiple of 8)") @@ -69,7 +69,7 @@ def generate_coll_map( if spawn is None: abort(f"no spawn point located") - return format_bytes(out_bytes, width=width), spawn, camera + return bytes(out_bytes), spawn, camera def format_bytes(data: bytes, width: int = 16) -> str: @@ -115,10 +115,14 @@ def generate_map(pngfile: str, compress: bool = False) -> None: ) collpath = pngpath.parent / pngpath.name.replace(".png", "_coll.png") + collpath_out = pngpath.parent / f"{section}.collision" coll_map, spawn, camera = generate_coll_map( collpath, width, height, compress=compress ) + with open(collpath_out, "wb") as outf: + outf.write(coll_map) + tiles_size = os.path.getsize(tilepath) with open(incpath, "w") as outf: @@ -140,11 +144,7 @@ extern map_t map_{section}; MAP_ASSET({section}_tiles, "{section}.tiles"); MAP_ASSET({section}_map, "{section}.tilemap"); -//MAP_ASSET({section}_collision, "{section}.collision"); - -const uint8_t {section}_collision[] = {{ -{coll_map} -}}; +MAP_ASSET({section}_collision, "{section}.collision"); const map_t map_{section} = {{ (uint16_t)&{section}_tiles[0],