# Local SDL2 emulator for MissileCommand (run the game on your PC)
#
#   make          build ./missilecommand-emu
#   make run      build + launch the window
#   make smoke    headless test: 240 frames, dump the last frame to a BMP
#
CXX      ?= g++
CXXFLAGS ?= -std=gnu++17 -O2 -Wall -Wextra
SDLFLAGS := -I/usr/include/SDL2
INC      := -Isrc/shim -I../examples/MissileCommand
LIBS     := -lSDL2 -lSDL2_ttf

GAME_DIR := ../examples/MissileCommand
SHIMS    := $(wildcard src/shim/*.h) $(wildcard src/shim/driver/*.h)
EMU      := missilecommand-emu

.PHONY: all run smoke clean

all: $(EMU)

$(EMU): src/main.cpp $(GAME_DIR)/sound_engine.cpp $(GAME_DIR)/MissileCommand.ino $(SHIMS)
	$(CXX) $(CXXFLAGS) $(SDLFLAGS) $(INC) \
		src/main.cpp $(GAME_DIR)/sound_engine.cpp -o $@ $(LIBS)

run: $(EMU)
	./$(EMU)

# Headless smoke test: dummy video/audio, run N frames, save the last frame.
# Feed some keys: 'a' starts the game, arrows steer, etc. via --script.
smoke: $(EMU)
	./$(EMU) --frames 240 --dump smoke_frame.bmp

clean:
	rm -f $(EMU) smoke_frame.bmp
