diff --git a/Makefile b/Makefile index 04b285a..68f3235 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,18 @@ # To launch with debug messages: G_MESSAGES_DEBUG=all ./librefront -SRC := $(shell find src -name '*.c') -OBJ := $(patsubst src/%.c, build/%.o, $(SRC)) -DEP := $(OBJ:.o=.d) +SRC_DIR := src + +COMMON_SRC := $(shell find $(SRC_DIR)/common -name '*.c') +SERVER_SRC := $(shell find $(SRC_DIR)/server -name '*.c') +CLIENT_SRC := $(shell find $(SRC_DIR)/client -name '*.c') + +COMMON_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(COMMON_SRC)) +SERVER_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(SERVER_SRC)) +CLIENT_OBJ := $(patsubst $(SRC_DIR)/%.c, build/%.o, $(CLIENT_SRC)) + +COMMON_DEP := $(COMMON_OBJ:.o=.d) +SERVER_DEP := $(SERVER_OBJ:.o=.d) +CLIENT_DEP := $(CLIENT_OBJ:.o=.d) CC := gcc LD := gcc @@ -11,30 +21,51 @@ RM := rm -f DEBUG ?= 1 -CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP `pkg-config --cflags sdl3 sdl3-image glib-2.0` -LDFLAGS := -std=$(STD) -lm `pkg-config --libs sdl3 sdl3-image glib-2.0` - -TARGET := librefront +COMMON_CFLAGS := -std=$(STD) -Werror -Wextra -Wall -MMD -MP -I$(SRC_DIR) `pkg-config --cflags glib-2.0` +COMMON_LDFLAGS := -std=$(STD) -lm `pkg-config --libs glib-2.0` ifeq ($(DEBUG),1) - CFLAGS += -g -DDEBUG - LDFLAGS += -g + COMMON_CFLAGS += -g -DDEBUG + COMMON_LDFLAGS += -g else - CFLAGS += -O2 -DNDEBUG + COMMON_CFLAGS += -O2 -DNDEBUG endif + +CLIENT_CFLAGS := $(COMMON_CFLAGS) `pkg-config --cflags sdl3 sdl3-image` +CLIENT_LDFLAGS := $(COMMON_LDFLAGS) `pkg-config --libs sdl3 sdl3-image` + +SERVER_CFLAGS := $(COMMON_CFLAGS) +SERVER_LDFLAGS := $(COMMON_LDFLAGS) + +CLIENT := librefront +SERVER := librefront-headless + .PHONY: all clean -all: $(TARGET) +all: $(CLIENT) $(SERVER) -$(TARGET): $(OBJ) - $(LD) $^ -o $@ $(LDFLAGS) +$(CLIENT): $(COMMON_OBJ) $(CLIENT_OBJ) + $(LD) $^ -o $@ $(CLIENT_LDFLAGS) -build/%.o: src/%.c +$(SERVER): $(COMMON_OBJ) $(SERVER_OBJ) + $(LD) $^ -o $@ $(SERVER_LDFLAGS) + +build/common/%.o: $(SRC_DIR)/common/%.c @mkdir -p $(dir $@) - $(CC) -c $< -o $@ $(CFLAGS) + $(CC) -c $< -o $@ $(COMMON_CFLAGS) + +build/client/%.o: $(SRC_DIR)/client/%.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ $(CLIENT_CFLAGS) + +build/server/%.o: $(SRC_DIR)/server/%.c + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ $(SERVER_CFLAGS) clean: - $(RM) -r build/ $(TARGET) $(OBJ) $(DEP) perf.data* massif.out* + $(RM) -r build/ $(CLIENT) $(SERVER) perf.data* massif.out* --include $(DEP) +-include $(COMMON_DEP) +-include $(CLIENT_DEP) +-include $(SERVER_DEP) diff --git a/doc/cd_GameState.odg b/doc/cd_GameState.odg index 26631c4..353c57a 100644 Binary files a/doc/cd_GameState.odg and b/doc/cd_GameState.odg differ diff --git a/src/main.c b/src/client/client.c similarity index 98% rename from src/main.c rename to src/client/client.c index e710d1b..bd1b65f 100644 --- a/src/main.c +++ b/src/client/client.c @@ -4,7 +4,8 @@ #include #include -#include "util.h" +#include + #include "gfx_context.h" static GfxContext *gfx_ctx; diff --git a/src/gfx_context.c b/src/client/gfx_context.c similarity index 100% rename from src/gfx_context.c rename to src/client/gfx_context.c diff --git a/src/gfx_context.h b/src/client/gfx_context.h similarity index 73% rename from src/gfx_context.h rename to src/client/gfx_context.h index da41892..246a84a 100644 --- a/src/gfx_context.h +++ b/src/client/gfx_context.h @@ -3,7 +3,8 @@ #include #include -#include "util.h" +#include +#include typedef struct GfxContext { @@ -15,3 +16,5 @@ GfxContext *GfxContext_new (); void GfxContext_prerender (GfxContext *self); void GfxContext_postrender (GfxContext *self); void GfxContext_free (GfxContext *self); + +void GfxContext_renderWorld (GfxContext *self, World *world); diff --git a/src/game_state.c b/src/common/game_state.c similarity index 100% rename from src/game_state.c rename to src/common/game_state.c diff --git a/src/game_state.h b/src/common/game_state.h similarity index 100% rename from src/game_state.h rename to src/common/game_state.h diff --git a/src/util.h b/src/common/util.h similarity index 100% rename from src/util.h rename to src/common/util.h diff --git a/src/world.c b/src/common/world.c similarity index 100% rename from src/world.c rename to src/common/world.c diff --git a/src/world.h b/src/common/world.h similarity index 85% rename from src/world.h rename to src/common/world.h index 80ee669..5f11062 100644 --- a/src/world.h +++ b/src/common/world.h @@ -19,14 +19,6 @@ typedef struct MapTile gboolean is_defended : 1, is_radiated : 1; } MapTile; -typedef struct Building -{ - MapTile *parent_tile; - unsigned int level; - - unsigned int (*at_what_cost) (Building *self, World *world); -} Building; - typedef struct World { unsigned int width, height; @@ -34,6 +26,15 @@ typedef struct World GArray *buildings; } World; + +typedef struct Building Building; // Typedef is needed to avoid circular dependency +struct Building +{ + MapTile *parent_tile; + unsigned int level; + + unsigned int (*at_what_cost) (Building *self, World *world); +}; + World *World_new (unsigned int width, unsigned int height); void World_tick (World *self); -void World_render (World *self, GfxContext *gfx_context); diff --git a/src/server/server.c b/src/server/server.c new file mode 100644 index 0000000..604ee00 --- /dev/null +++ b/src/server/server.c @@ -0,0 +1,7 @@ +#include + +int main () +{ + fprintf(stderr, "Server not implemented!\n"); + return -1; +}