added meson build file, fixed sign-compare warnings
MCMakeLists.txt
| @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0) | |||
|---|---|---|---|
| 2 | 2 | ||
| 3 | 3 | project(orcsmasher LANGUAGES C) | |
| 4 | 4 | ||
| 5 | - | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Wno-sign-compare") | |
| 5 | + | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic") | |
| 6 | 6 | ||
| 7 | 7 | if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") | |
| 8 | 8 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Og -g -fsanitize=address") | |
Minclude/game.h
| @@ -102,15 +102,20 @@ static inline struct field *game_at(const struct game *g, struct point p) | |||
|---|---|---|---|
| 102 | 102 | ||
| 103 | 103 | static inline struct game create_game(size_t y, size_t x) | |
| 104 | 104 | { | |
| 105 | + | size_t res = y * x; | |
| 106 | + | if (y != 0 && res / y != x) { | |
| 107 | + | assert(false); | |
| 108 | + | } | |
| 105 | 109 | struct game ret; | |
| 106 | 110 | ret.map = xmalloc(x * y * sizeof(*ret.map)); | |
| 111 | + | ret.xs = x; | |
| 112 | + | ret.ys = y; | |
| 113 | + | ||
| 107 | 114 | for(size_t i = 0; i < x*y; i++) | |
| 108 | 115 | { | |
| 109 | 116 | ret.map[i].u = xmalloc(sizeof(*ret.map[i].u)); | |
| 110 | 117 | ret.map[i].has_monster = false; | |
| 111 | 118 | } | |
| 112 | - | ret.xs = x; | |
| 113 | - | ret.ys = y; | |
| 114 | 119 | ||
| 115 | 120 | return ret; | |
| 116 | 121 | } | |
| @@ -161,7 +166,7 @@ static inline struct point relative(struct point p, enum direction d) | |||
|---|---|---|---|
| 161 | 166 | ||
| 162 | 167 | static inline bool in_bounds(struct game *g, struct point p) | |
| 163 | 168 | { | |
| 164 | - | if(p.y >= 0 && p.y < g->ys && p.x >= 0 && p.x < g->xs) | |
| 169 | + | if(p.y >= 0 && (size_t)p.y < g->ys && p.x >= 0 && (size_t)p.x < g->xs) | |
| 165 | 170 | return true; | |
| 166 | 171 | else | |
| 167 | 172 | return false; | |
Minclude/tui.h
| @@ -12,7 +12,7 @@ void charclear(); //clears the character screen | |||
|---|---|---|---|
| 12 | 12 | void charprint(const char *format, ...); //echoes printf string to the charwindow | |
| 13 | 13 | void log_scroll(enum direction d); //scrolls the log up or down | |
| 14 | 14 | void draw_map(const struct game *g, struct point p); //draws the map around the player | |
| 15 | - | bool messagebox(const char *str, int y, int x); //shows a centered messagebox of at least the given size | |
| 15 | + | bool messagebox(const char *str, size_t y, size_t x); //shows a centered messagebox of at least the given size | |
| 16 | 16 | ||
| 17 | 17 | typedef bool(itemselectfn)(struct monster *m, size_t i); //returns true if cursor should be reset | |
| 18 | 18 | void itemselect(struct monster *m, itemselectfn f); //provides an inventory screen, calls f when the space is pressed on an item | |
Ameson.build
| @@ -0,0 +1,42 @@ | |||
|---|---|---|---|
| 1 | + | project('orcsmasher', 'c', | |
| 2 | + | version : '0.1', | |
| 3 | + | default_options : ['warning_level=3', 'c_std=c99']) | |
| 4 | + | ||
| 5 | + | inc = include_directories('include') | |
| 6 | + | ||
| 7 | + | cc = meson.get_compiler('c') | |
| 8 | + | ||
| 9 | + | CFLAGS = [] | |
| 10 | + | LDFLAGS = [] | |
| 11 | + | ||
| 12 | + | if get_option('buildtype') == 'debug' | |
| 13 | + | CFLAGS += ['-Og', '-g', '-fsanitize=address'] | |
| 14 | + | LDFLAGS += ['-lasan'] | |
| 15 | + | endif | |
| 16 | + | ||
| 17 | + | if get_option('buildtype') == 'release' | |
| 18 | + | CFLAGS += ['-O3', '-march=native', '-g'] | |
| 19 | + | endif | |
| 20 | + | ||
| 21 | + | static_build = get_option('default_library') == 'static' | |
| 22 | + | ||
| 23 | + | if static_build | |
| 24 | + | LDFLAGS += ['-l:libgpm.a'] | |
| 25 | + | endif | |
| 26 | + | ||
| 27 | + | srcprefix = 'src/' | |
| 28 | + | srcraw = [ | |
| 29 | + | 'algorithm.c', | |
| 30 | + | 'loop.c', | |
| 31 | + | 'main.c', | |
| 32 | + | 'tui.c', | |
| 33 | + | ] | |
| 34 | + | src = [] | |
| 35 | + | foreach s : srcraw | |
| 36 | + | src += srcprefix + s | |
| 37 | + | endforeach | |
| 38 | + | ||
| 39 | + | curses_dep = dependency('ncursesw', static: static_build) | |
| 40 | + | panel_dep = dependency('panelw', static: static_build) | |
| 41 | + | executable('orcsmasher', src, include_directories: inc, dependencies: [curses_dep, panel_dep], c_args: CFLAGS, link_args: LDFLAGS) | |
| 42 | + | ||
Msrc/algorithm.c
| @@ -25,16 +25,15 @@ static char *maze_at(char *m, size_t xs, struct point p) | |||
|---|---|---|---|
| 25 | 25 | ||
| 26 | 26 | static bool maze_in_bounds(size_t ys, size_t xs, struct point p) | |
| 27 | 27 | { | |
| 28 | - | return p.y > 0 && p.y < ys-1 && | |
| 29 | - | p.x > 0 && p.x < xs-1; | |
| 28 | + | return p.y > 0 && (size_t)p.y < ys-1 && p.x > 0 && (size_t)p.x < xs-1; | |
| 30 | 29 | } | |
| 31 | 30 | ||
| 32 | 31 | struct game make_maze(size_t y, size_t x) | |
| 33 | 32 | { | |
| 34 | - | assert(y >= 5); | |
| 35 | - | assert(y >= 5); | |
| 36 | 33 | y += (y%2 == 0); //it must be an uneven number to look fine | |
| 37 | 34 | x += (x%2 == 0); | |
| 35 | + | assert(y >= 5); | |
| 36 | + | assert(x >= 5); | |
| 38 | 37 | struct game g = create_game(y, x); | |
| 39 | 38 | ||
| 40 | 39 | char *maze = xmalloc(y * x + 1); | |
Msrc/tui.c
| @@ -184,7 +184,7 @@ void logstr(const char *format, ...) | |||
|---|---|---|---|
| 184 | 184 | vsprintf(logs[loglength-1]+10, format, ap2); | |
| 185 | 185 | va_end(ap2); | |
| 186 | 186 | ||
| 187 | - | if(loglength - logindex == getmaxy(logwin)) | |
| 187 | + | if(loglength - logindex == (size_t)getmaxy(logwin)) //cast is fine, getmaxy only returns ERR if WINDOW is NULL | |
| 188 | 188 | logindex++; | |
| 189 | 189 | ||
| 190 | 190 | printlog(); | |
| @@ -250,7 +250,7 @@ void draw_map(const struct game *g, struct point p) | |||
|---|---|---|---|
| 250 | 250 | wrefresh(mapwin); | |
| 251 | 251 | } | |
| 252 | 252 | ||
| 253 | - | bool messagebox(const char *str, int y, int x) | |
| 253 | + | bool messagebox(const char *str, size_t y, size_t x) | |
| 254 | 254 | { | |
| 255 | 255 | int yorig = y, xorig = x; | |
| 256 | 256 | struct winsize w; | |