cepheid

An Aurora 4X clone
Log | Files | Refs | README

commit b748758ddecacec251d11c8024253225f1543035
parent 26b02f144f89012c6d7659aaa9233997ddbc71f4
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 19 Nov 2022 22:46:15 +0000

Speed up builds by creating .o for each included file

Diffstat:
MMakefile | 4++--
Mdata/Makefile | 30+++++++++++++++++++++---------
Msrc/data.c | 45+++++++++++----------------------------------
3 files changed, 34 insertions(+), 45 deletions(-)

diff --git a/Makefile b/Makefile @@ -4,7 +4,7 @@ DBLIB = $(DBDIR)/db.o DBTOOL = $(DBDIR)/dbtool SRCDIR = src SRC = $(shell find $(SRCDIR) -name "*.c") styles/$(STYLE).c data/dirs.c -OBJ = $(SRC:.c=.o) +OBJ = $(SRC:.c=.o) $(shell find $(DATADIR) -name "*.o" | grep -v 'dirs\.o') BIN = cepheid RAYLIB = -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 LDFLAGS = $(RAYLIB) $(DBLIB) @@ -42,7 +42,7 @@ data-clean: @cd $(DATADIR); make clean tags: $(SRC) - ctags -R . + ctags --exclude=data/*.h --exclude=data/icons/*.h -R . # ignore generated headers sloccount: diff --git a/data/Makefile b/data/Makefile @@ -1,8 +1,9 @@ FONTS = $(shell find . -name "*.ttf") ICONS = $(shell find icons -name "*.png") -HEADERS = $(FONTS:.ttf=.h) $(ICONS:.png=.h) +OBJ = $(FONTS:.ttf=.o) $(ICONS:.png=.o) splash.o +HEADERS = $(OBJ:.o=.h) -all: $(HEADERS) dirs.c +all: $(OBJ) $(HEADERS) dirs.c sol: worlds.tsv worlds-parse.awk rm -rf sol @@ -11,7 +12,8 @@ sol: worlds.tsv worlds-parse.awk printf "x\t0\n" >> sol/index printf "y\t0\n" >> sol/index -dirs.c: sol +dirs.c: dirs.h +dirs.h: sol ./dir2h.sh sol # Thanks Jonathan @@ -20,12 +22,22 @@ worlds.tsv: sed 's/ *\t/\t/g' | \ ./worlds-order.awk > $@ -.ttf.h: - xxd -i < $< > $@ -.png.h: - xxd -i < $< > $@ +VAR = `echo $< | sed 's~.*/~~;s/\./_/g'` +SVAR = $(VAR)_size +.ttf.c .png.c: + @echo "Creating $@ from $<" + @echo "#include <stddef.h>" > $@ + @echo "unsigned char $(VAR)[] = {" >> $@ + @xxd -i < $< >> $@ + @echo "};" >> $@ + @echo "size_t $(SVAR) = sizeof($(VAR));" >> $@ + +.ttf.h .png.h: + @echo "Creating $@" + @echo "extern unsigned char $(VAR)[];" > $@ + @echo "extern size_t $(SVAR);" >> $@ clean: - rm -rf $(HEADERS) sol + rm -rf $(HEADERS) $(OBJ) sol -.SUFFIXES: .h .ttf .png +.SUFFIXES: .c .o .h .ttf .png diff --git a/src/data.c b/src/data.c @@ -1,6 +1,15 @@ #include <raylib.h> #include "main.h" +#include "../data/DejaVuSansMono.h" +#include "../data/icons/tactical.h" +#include "../data/icons/colonies.h" +#include "../data/icons/bodies.h" +#include "../data/icons/fleet.h" +#include "../data/icons/design.h" +#include "../data/icons/sys.h" +#include "../data/icons/settings.h" + #define IMAGE(name) \ static Image raw_image_##name; \ Texture image_##name @@ -14,48 +23,16 @@ IMAGE(design); IMAGE(sys); IMAGE(settings); -unsigned char DejaVuSansMono_ttf[] = { -#include "../data/DejaVuSansMono.h" -}; - -unsigned char tactical_png[] = { -#include "../data/icons/tactical.h" -}; - -unsigned char colonies_png[] = { -#include "../data/icons/colonies.h" -}; - -unsigned char bodies_png[] = { -#include "../data/icons/bodies.h" -}; - -unsigned char fleet_png[] = { -#include "../data/icons/fleet.h" -}; - -unsigned char design_png[] = { -#include "../data/icons/design.h" -}; - -unsigned char sys_png[] = { -#include "../data/icons/sys.h" -}; - -unsigned char settings_png[] = { -#include "../data/icons/settings.h" -}; - #define IMAGE_LOAD(name) \ raw_image_##name = LoadImageFromMemory(".png", \ - name##_png, sizeof(name##_png)); \ + name##_png, name##_png_size); \ image_##name = LoadTextureFromImage(raw_image_##name); \ UnloadImage(raw_image_##name) void data_load(void) { font = LoadFontFromMemory(".ttf", DejaVuSansMono_ttf, - sizeof(DejaVuSansMono_ttf), FONT_SIZE, NULL, 0); + DejaVuSansMono_ttf_size, FONT_SIZE, NULL, 0); charpx = MeasureTextEx(font, ".", FONT_SIZE, FONT_SIZE/10).x + FONT_SIZE/10; /* one step per IMAGE_LOAD() */ IMAGE_LOAD(tactical);