diff --git a/.gitignore b/.gitignore index 3af78ce..432d6a2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /shrooms-vb /shrooms-vb.exe -.vscode \ No newline at end of file +.vscode +output \ No newline at end of file diff --git a/assets.h b/assets.h index 01b59af..3d8d26d 100644 --- a/assets.h +++ b/assets.h @@ -3,10 +3,10 @@ #include -extern const uint8_t asset_lefteye_start; -const uint8_t *LEFT_EYE_DEFAULT = &asset_lefteye_start; +extern const uint8_t _binary_assets_lefteye_bin_start; +const uint8_t *LEFT_EYE_DEFAULT = &_binary_assets_lefteye_bin_start; -extern const uint8_t asset_righteye_start; -const uint8_t *RIGHT_EYE_DEFAULT = &asset_righteye_start; +extern const uint8_t _binary_assets_righteye_bin_start; +const uint8_t *RIGHT_EYE_DEFAULT = &_binary_assets_righteye_bin_start; #endif diff --git a/assets/assets.s b/assets/assets.s deleted file mode 100644 index 686c221..0000000 --- a/assets/assets.s +++ /dev/null @@ -1,15 +0,0 @@ -.section .note.GNU-stack,"",@progbits -.section .bindata, "a", @progbits - -.global asset_lefteye_start -.type asset_lefteye_start, @object -.global asset_righteye_start -.type asset_righteye_start, @object - -.section .bindata -.balign 64 -asset_lefteye_start: - .incbin "assets/lefteye.bin" -.balign 64 -asset_righteye_start: - .incbin "assets/righteye.bin" diff --git a/graphics.c b/graphics.c index 4eb15b7..9aa589c 100644 --- a/graphics.c +++ b/graphics.c @@ -23,15 +23,15 @@ int gfxInit(GraphicsContext *gfx) { return 1; } - gfx->winSurface = SDL_GetWindowSurface(gfx->window); - if (!gfx->winSurface) { - fprintf(stderr, "Error getting surface: %s\n", SDL_GetError()); + gfx->renderer = SDL_CreateRenderer(gfx->window, -1, 0); + if (!gfx->renderer) { + fprintf(stderr, "Error creating renderer: %s\n", SDL_GetError()); goto cleanup_window; } - gfx->renderer = SDL_GetRenderer(gfx->window); - if (!gfx->renderer) { - fprintf(stderr, "Error getting renderer: %s\n", SDL_GetError()); + gfx->winSurface = SDL_GetWindowSurface(gfx->window); + if (!gfx->winSurface) { + fprintf(stderr, "Error getting surface: %s\n", SDL_GetError()); goto cleanup_window; } diff --git a/makefile b/makefile index 85f346f..4b50bb5 100644 --- a/makefile +++ b/makefile @@ -1,19 +1,42 @@ CC?=gcc +LD?=ld SHROOMSFLAGS=shrooms-vb-core/core/vb.c -I shrooms-vb-core/core -SDL2FLAGS=$(shell pkg-config sdl2 --cflags --libs) +SDL2FLAGS=$(shell pkg-config sdl2 --cflags --libs) -mconsole -.PHONY: clean +.PHONY: clean build clean: -ifeq ($(OS),WINDOWS_NT) - @del shrooms-vb.exe -else - @rm -f shrooms-vb -endif + @rm -rf shrooms-vb output -build: - @$(CC) audio.c cli.c controller.c game.c graphics.c main.c assets/assets.s -I . \ - $(SHROOMSFLAGS) $(SDL2FLAGS) \ - -D POSIX_C_SOURCE=199309L \ - -o shrooms-vb \ - -O3 -fno-strict-aliasing \ - -Werror -std=c90 -Wall -Wextra -Wpedantic \ No newline at end of file +CFILES := $(foreach dir,./,$(notdir $(wildcard $(dir)/*.c))) +BINFILES := $(foreach dir,assets/,$(notdir $(wildcard $(dir)/*.bin))) + +COBJS := $(CFILES:%.c=output/%.o) +SHROOMSOBJS := output/vb.o +BINOBJS := $(BINFILES:%.bin=output/%.o) + +OFILES := $(COBJS) $(SHROOMSOBJS) $(BINOBJS) + +output/%.o: %.c + @mkdir -p output + @$(CC) -c -o $@ $< -I . \ + -I shrooms-vb-core/core $(SDL2FLAGS) \ + -D _POSIX_C_SOURCE=199309L \ + -O3 -flto -fno-strict-aliasing \ + -Werror -std=c11 -Wall -Wextra -Wpedantic + +output/vb.o: shrooms-vb-core/core/vb.c + @mkdir -p output + @$(CC) -c -o $@ $< -I . \ + -I shrooms-vb-core/core $(SDL2FLAGS) \ + -D _POSIX_C_SOURCE=199309L \ + -O3 -flto -fno-strict-aliasing \ + -Werror -std=c11 -Wall -Wextra -Wpedantic + +output/%.o: assets/%.bin + @mkdir -p output + @$(LD) -r -b binary -o $@ $< + +shrooms-vb: $(OFILES) + @$(CC) -o $@ $(OFILES) $(SDL2FLAGS) -flto + +build: shrooms-vb \ No newline at end of file