INCGFX: in-source arguments for gbagfx#2283
Conversation
GriffinRichards
left a comment
There was a problem hiding this comment.
Incredible, this is a huge change. This makes what's happening when we include graphics in the code so much more obvious, in my opinion. So many common pitfalls relate back to our hiding things in Make rules.
Re: should we default the arguments string to empty string, yes I think so (especially if INCGFX_#("path", "extension"); would result in an error). My thought is 99% of the time that someone downstream is adding an asset, either they don't need any additional arguments, or they're adding a spritesheet to a list of existing spritesheets (which either way will have examples of how to use their -mwidth and -mheight arguments). Adding the empty strings in other cases I think would just be more work / more chances for making a mistake.
| if (!CheckIdentifier("INCGFX_")) | ||
| return; | ||
|
|
||
| std::string idents[3] = { "INCGFX_U8", "INCGFX_U16", "INCGFX_U32" }; |
There was a problem hiding this comment.
I think either we support the equivalent of INCBIN_S with INCGFX_S or we just get rid of INCBIN_S.
There was a problem hiding this comment.
Hmm! I can't think of any use for signed graphics files, so I'm leaning towards cutting INCBIN_S. There's no uses of it in the repo atm, and the only theoretical use I can come up with is audio... which would probably be handled by the assembler.
| RaiseError("expected ')'"); | ||
| m_pos++; | ||
|
|
||
| // WARNING: This must stay in-sync with 'tools/scaninc/source_file.cpp'. |
There was a problem hiding this comment.
Yeesh. preproc and scaninc should probably share some form of library code. Could we maybe track this with an issue on GitHub too? I know they don't get much attention, but it's a little more visibility at least.
There was a problem hiding this comment.
Yeah, it's a real pain in the butt! A library makes sense, or perhaps preproc could absorb scaninc or vice-versa. I think now we have .d files preproc could do the job of populating them at the point the source file is processed, rather than requiring a whole separate scaninc pass that finds all the dependencies up-front... 🤔
There was a problem hiding this comment.
Ah, actually preproc can't populate the .d files because of generated files. I mean, it could but that would preproc to invoke make on all the files that don't exist but are included (via #include, INCBIN, or INCGFX). So library or perhaps merging the two tools and having, common-tool preproc and common-tool scaninc.
In any case, I'll raise an issue for it because that's not something I want to look at doing right now.
There was a problem hiding this comment.
Yeah that's a full additional task that shouldn't hold this up
I'll make it so :) |
|
Pushed the changes:
Could I have the chance to rebase before this is merged? I'm trying to keep the commits separate so that a downstream project can skip the migration commit. |
The signed INCBINs are unused, I assume they were once for audio data but that is handled in assembly now.
'INCGFX' is like 'INCBIN' except that it specifies the arguments to pass to 'gbagfx' which alleviates the user-unfriendliness caused by catch-all rules. Specifically, users frequently forget to add to 'spritesheet_rules.mk' when adding object event graphics, and then the built '.4bpp' file is not invalidated when the add their rule so they have to 'touch' the source file or similar. The built artifacts are placed in 'build/assets'.
The exact command used to migrate source files was: git ls-files | grep 'src/.*\.[ch]$' | xargs grep -l INCBIN | xargs python3 migrate_incgfx.py The Makefile rules were cleaned up manually by looking for graphics rules and keeping only those ending with '\' (what the migration script calls a "Multi-line rule"). You may think some of wallpaper rules could be removed, but they're inputs for the '@cat $^ >$@' rules which are currently unable to be migrated to 'INCGFX'.
INCGFXis likeINCBINexcept that it specifies the arguments to pass togbagfxwhich alleviates the user-unfriendliness caused by catch-all rules.Specifically, users frequently forget to add to
spritesheet_rules.mkwhen adding object event graphics which leads to garbled graphics in-game (but not in Porymap which displays them correctly). Also the built.4bppfile is not invalidated when the add their rule tospritesheet_rules.mkso they have totouchthe source file or similar to un-garble their graphics.The built artifacts are placed in
build/assetsso that they can be shared between agbcc builds and modern builds.The
INCBIN⇒INCGFXmigration was done automatically with migrate_incgfx.py. The exact command was:The
graphics_file_rules.mkwere cleaned up manually. Mostly the kept rules are non-gbagfxrules, but there are a few rules where the outputs are used as inputs to other rules and those were kept for sanity's sake.Notes for pokeemerald maintainers:
INCGFXcould handle multiple inputs so that the various@cat $^ >$@rules and their dependencies could be removed fromgraphics_file_rules.mk.-mwidthand-mheighton all object eventINCGFXs insrc/data/object_events/object_event_graphics.hto future-proof against adding more frames.INCGFX's third argument should be optional because it's somewhat-frequently"". On the other hand, maybe it's better to be explicit because that makes the translation to a recipe more obvious, and it simplifies the code.Notes for downstream projects:
INCBINstill exists and I have no plans to remove it. Downstream projects can continue usingINCBINandgraphics_file_rules.mk/spritesheet_rules.mkif they prefer.Notes for Expansion maintainers:
tools/preproc/c_file.cpp:TryConvertIncgfxintroduces new calls tostd::printfwhich must be replaced with plainprintfonupcoming(andmasterafter 1.16 is released) due to preproc: (shared) COMPOUND_STRING rh-hideout/pokeemerald-expansion#9086.migrate_incgfx.pycorrectly migrates all theINCBINs introduced in Expansion, and vendor it as a migration script. We should also double-check that it doesn't get confused on a dirty repository (e.g. one with.4bpps and.gbapals).*.mks, but as mentioned above I don't have one of those and did the changes by hand. Those rules are harmless, so they don't have to be removed.