Browse Source

Move collision into a binary file

master
Forest Belton 3 years ago
parent
commit
348fef6c64
2 changed files with 8 additions and 8 deletions
  1. +1
    -1
      gbsdk/rules.mk
  2. +7
    -7
      scripts/generate_map.py

+ 1
- 1
gbsdk/rules.mk View File

@ -160,7 +160,7 @@ $(BUILD)/assets/%.1bpp: assets/%.png
# Special hack to place a ret instruction at the end of the GSINIT section. # 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. # This has to be linked last, as that ensures that this fragment is at the end of the "GSINIT" section.
$(BUILD)/gsinit.end.o: $(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: clean:
@rm -rf $(BUILD) $(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym @rm -rf $(BUILD) $(PROJECT_NAME).$(ROM_EXTENSION) $(PROJECT_NAME).map $(PROJECT_NAME).sym

+ 7
- 7
scripts/generate_map.py View File

@ -24,7 +24,7 @@ Point = Tuple[int, int]
def generate_coll_map( def generate_coll_map(
in_path: pathlib.Path, width: int, height: int, compress: bool = False 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") png = Image.open(in_path).convert("RGB")
if png.width % 8 != 0 or png.height % 8 != 0: if png.width % 8 != 0 or png.height % 8 != 0:
abort(f"file '{in_path}' has invalid dimensions (should be multiple of 8)") 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: if spawn is None:
abort(f"no spawn point located") 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: 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 = pngpath.parent / pngpath.name.replace(".png", "_coll.png")
collpath_out = pngpath.parent / f"{section}.collision"
coll_map, spawn, camera = generate_coll_map( coll_map, spawn, camera = generate_coll_map(
collpath, width, height, compress=compress collpath, width, height, compress=compress
) )
with open(collpath_out, "wb") as outf:
outf.write(coll_map)
tiles_size = os.path.getsize(tilepath) tiles_size = os.path.getsize(tilepath)
with open(incpath, "w") as outf: with open(incpath, "w") as outf:
@ -140,11 +144,7 @@ extern map_t map_{section};
MAP_ASSET({section}_tiles, "{section}.tiles"); MAP_ASSET({section}_tiles, "{section}.tiles");
MAP_ASSET({section}_map, "{section}.tilemap"); 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} = {{ const map_t map_{section} = {{
(uint16_t)&{section}_tiles[0], (uint16_t)&{section}_tiles[0],

Loading…
Cancel
Save