Clownacy / ClownMapEd

Sonic the Hedgehog sprite editor, portable clone of Xenowhirl's SonMapEd.
GNU Affero General Public License v3.0
20 stars 1 forks source link

Support for loading/writing Hivebrain's MapMacros #3

Open OrionNavattan opened 7 months ago

OrionNavattan commented 7 months ago

At this point, these are the only mappings that this program doesn't yet support. Hivebrain's format is similar to the MainMemory's SpritePiece, albeit with an emphasis on human readability:

; x pos, y pos, dimensions, tile, optional x flip, y flip, priority, and palette options
piece   $10, -$30, 2x2, $5D, xflip, pal2 

Looking at the source of libsonassmd, I get the impression that the program converts macro mappings to binary by assembling them if the presence of a copy of MainMemory's macros in assembler.cpp is any indication. I've prepared a file with the macros required to assemble HB's format, and can provide it to help you get started. That said, there is one significant caveat with regards to writing mapping files in this format: the labels used within the mapping files must remain unchanged, as they are referenced in animation scripts. There is also a possible caveat with handling DPLCs, but I'll leave that for later.

Clownacy commented 7 months ago

Geez, so much for settling on a single universal format.

Because of the need to preserve labels, addressing this may have to wait until I make libsonassmd bypass the assembler and parse mappings directly. Those macros of your could help, though I'd like to license them however I want so I may have to write them myself from scratch like I did with MainMemory's.

OrionNavattan commented 7 months ago

It's nice to have a more human-readable format, but alas it makes supporting everything more complicated. xD

Parsing the mappings directly is probably the way to go, though the way Hivebrain has implemented them, the DPLC files explicitly depend on the mapping files (the index tables are synchronized via macro), so they would need to be loaded simultaneously. The DPLCs themselves have a interesting caveat: the individual frames are all separate files rather than a single blob, and the DPLCs are generated via macro rather than hard-coded. This may pose an issue while loading the DPLCs, but will simplify generating them (simply writing a macro argument rather than calculating the DPLCs). This feature is only implemented in the HB 2022 disasm for the moment, but I plan to extend it to my Sonic 2 disasm in time, and I suspect it'll be added to Sonic 1 Squared.

Anyhow, I've put together a file with all of the macros required to assemble this format, which hopefully should illustrate how it works. https://gist.github.com/OrionNavattan/6e0a6be89096d2b9593557f759b214ef

cvghivebrain commented 6 months ago

Sonic 1-squared actually uses yet another format, inline DPLCs which eliminate the need for a second index. Here's an example:

https://github.com/cvghivebrain/Sonic1sq/blob/main/Objects/Giant%20Ring%20%5BMappings%5D.asm

Don't worry about adding support for that though. It'll probably only ever be used in my hacks.

Brainulator9 commented 6 months ago

Maybe just allow the user to set their own mapping macro format as need be?