diff options
-rw-r--r-- | Makefile | 6 | ||||
-rw-r--r-- | sprite.h | 6 |
2 files changed, 9 insertions, 3 deletions
@@ -12,7 +12,7 @@ sprite_allfiles := $(wildcard src/sprites/*) sprite_fnames := $(filter %.png,$(sprite_allfiles)) sprite_skipped := $(filter-out %.png,$(sprite_allfiles)) sprite_obj := $(patsubst src/sprites/%.png,build/sprites/%.o,$(sprite_fnames)) -sprite_externs := $(shell echo $$(for f in $(sprite_obj); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/extern const unsigned char &[];/'; done)) +sprite_externs := $(shell echo $$(for f in $(sprite_obj); do basename $$f | sed 's/\.[^.]*$$//' | sed 's/.*/extern const Sprite &;/'; done)) base_src := $(wildcard *_base.cpp) base_src += library.cpp main.cpp @@ -80,10 +80,10 @@ build/sprites/%.o: build/sprites/%.cpp build/sprites/%.cpp: src/sprites/%.png echo Generating for sprite $* mkdir -p $(dir $@) - printf "const unsigned char $*[]={\n%s, 0\n};\nconst unsigned int _$*_len=%d;\n" "$$(xxd -i <"$<")" $$(stat -f '%z' "$<") >"$@" + printf "#include \"sprite.h\"\n\nstatic const unsigned char data[]={\n%s, 0\n};\n\nSprite $*=(Sprite){.image=data,.image_len=%d};\n" "$$(xxd -i <"$<")" $$(stat -f '%z' "$<") >"$@" build/sprites.h: echo Collecting generated sprite files mkdir -p $(dir $@) - echo "$(sprite_externs)" >"$@" + printf "#include \"sprite.h\"\n\n$(sprite_externs)\n" >"$@" test -z "$(sprite_skipped)" || printf "\x1B[1mWARNING: skipped files in src/sprites: $(notdir $(sprite_skipped))\x1B[0m\n" diff --git a/sprite.h b/sprite.h new file mode 100644 index 0000000..e901c9a --- /dev/null +++ b/sprite.h @@ -0,0 +1,6 @@ +#pragma once + +struct Sprite{ + const unsigned char *image; + unsigned int image_len; +}; |