Make conditional linking happen in makefile for merges

This commit is contained in:
Tiehuis 2015-02-25 10:47:41 +13:00
parent 3db0537685
commit 2d9f89f339
6 changed files with 18 additions and 15 deletions

View File

@ -5,18 +5,19 @@ DEFINES := -DINVERT_COLORS -DVT100 $(shell pkg-config --cflags sdl2)
PROGRAM := 2048
C_FILES := $(wildcard src/*.c)
O_FILES := $(addprefix obj/,$(notdir $(C_FILES:.c=.o)))
O_FILES := $(addprefix obj/, $(notdir $(C_FILES:.c=.o)))
FILTERED_O_FILES := $(filter-out obj/gfx%.o obj/merge%.o, $(O_FILES))
all: curses
curses: $(O_FILES)
$(CC) $(filter-out obj/gfx%.o, $(O_FILES)) obj/gfx_curses.o -o $(PROGRAM) -lcurses
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_curses.o -o $(PROGRAM) -lcurses
vt100: $(O_FILES)
$(CC) $(filter-out obj/gfx%.o, $(O_FILES)) obj/gfx_terminal.o -o $(PROGRAM)
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_terminal.o -o $(PROGRAM)
sdl: $(O_FILES)
$(CC) $(filter-out obj/gfx%.o, $(O_FILES)) obj/gfx_sdl.o -o $(PROGRAM) -lSDL2 -lSDL2_ttf
$(CC) $(FILTERED_O_FILES) obj/merge_std.o obj/gfx_sdl.o -o $(PROGRAM) -lSDL2 -lSDL2_ttf
obj/%.o: src/%.c
$(CC) $(DEFINES) $(CFLAGS) -c -o $@ $<

View File

@ -192,6 +192,8 @@ void gamestate_new_block(struct gamestate *g)
if (!g->grid[x][y]) p++;
}
if (y == g->opts->grid_height - 1) y = 0;
}
#endif
@ -211,12 +213,12 @@ static int digits_ceiling(unsigned int n)
return l + 1;
}
/* Return NULL if we couldn't allocate space for the gamestate. The opt
* argument can be passed directly via gameoptions_default i.e
* *o = gamestate_init(gameoptions_default) is valid, as the delete function
* will find the pointer to the gameoptions and delete the data accordingly. */
struct gamestate* gamestate_init(struct gameoptions *opt)
/* Return NULL if we couldn't allocate space for the gamestate. initializating the
* gamestate will parse the options internally, so any caller should pass argc and argv
* through this function */
struct gamestate* gamestate_init(int argc, char **argv)
{
struct gameoptions *opt = parse_options(gameoptions_default(), argc, argv);
if (!opt) return NULL;
srand(time(NULL));

View File

@ -38,6 +38,6 @@ int gamestate_end_condition(struct gamestate*);
void gamestate_new_block(struct gamestate*);
int gamestate_tick(struct gfx_state*, struct gamestate*, int, void (*callback)(struct gfx_state*, struct gamestate*));
void gamestate_clear(struct gamestate*);
struct gamestate* gamestate_init(struct gameoptions *);
struct gamestate* gamestate_init(int argc, char **argv);
#endif

View File

@ -11,8 +11,7 @@ void draw_then_sleep(struct gfx_state *s, struct gamestate *g)
int main(int argc, char **argv)
{
struct gameoptions *o = gameoptions_default();
struct gamestate *g = gamestate_init(parse_options(o, argc, argv));
struct gamestate *g = gamestate_init(argc, argv);
struct gfx_state *s = gfx_init(g);
int game_running = true;

View File

@ -1,6 +1,6 @@
#include "merge.h"
#define MERGE_GOAL (int)(sizeof(merge_values)/sizeof(merge_values[0]))
#define MERGE_GOAL (int)((sizeof(merge_values)/sizeof(merge_values[0]))-1)
const long merge_values[] = {
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,
@ -19,7 +19,8 @@ inline long merge_goal(void)
inline int merge_possible(const int v1, const int v2)
{
return v1 == v2 - 1 || v2 == v1 - 1;
return v1 == v2 - 1 || v2 == v1 - 1 ||
((v1 == 1 || v1 == 2) && (v2 == 1 || v2 == 2));
}
inline int merge_result(const int v1, const int v2)

View File

@ -1,6 +1,6 @@
#include "merge.h"
#define MERGE_GOAL (int)(sizeof(merge_values)/sizeof(merge_values[0]))
#define MERGE_GOAL (int)((sizeof(merge_values)/sizeof(merge_values[0]))-1)
const long merge_values[] = {
0, 2, 4, 8, 16, 32, 64, 128, 256, 512,