added meson build file, fixed sign-compare warnings
MCMakeLists.txt
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.0)
project(orcsmasher LANGUAGES C)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -Wno-sign-compare")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic")
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
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)
static inline struct game create_game(size_t y, size_t x)
{
size_t res = y * x;
if (y != 0 && res / y != x) {
assert(false);
}
struct game ret;
ret.map = xmalloc(x * y * sizeof(*ret.map));
ret.xs = x;
ret.ys = y;
for(size_t i = 0; i < x*y; i++)
{
ret.map[i].u = xmalloc(sizeof(*ret.map[i].u));
ret.map[i].has_monster = false;
}
ret.xs = x;
ret.ys = y;
return ret;
}
@@ -161,7 +166,7 @@ static inline struct point relative(struct point p, enum direction d)
static inline bool in_bounds(struct game *g, struct point p)
{
if(p.y >= 0 && p.y < g->ys && p.x >= 0 && p.x < g->xs)
if(p.y >= 0 && (size_t)p.y < g->ys && p.x >= 0 && (size_t)p.x < g->xs)
return true;
else
return false;
Minclude/tui.h
@@ -12,7 +12,7 @@ void charclear(); //clears the character screen
void charprint(const char *format, ...); //echoes printf string to the charwindow
void log_scroll(enum direction d); //scrolls the log up or down
void draw_map(const struct game *g, struct point p); //draws the map around the player
bool messagebox(const char *str, int y, int x); //shows a centered messagebox of at least the given size
bool messagebox(const char *str, size_t y, size_t x); //shows a centered messagebox of at least the given size
typedef bool(itemselectfn)(struct monster *m, size_t i); //returns true if cursor should be reset
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 @@
project('orcsmasher', 'c',
version : '0.1',
default_options : ['warning_level=3', 'c_std=c99'])
inc = include_directories('include')
cc = meson.get_compiler('c')
CFLAGS = []
LDFLAGS = []
if get_option('buildtype') == 'debug'
CFLAGS += ['-Og', '-g', '-fsanitize=address']
LDFLAGS += ['-lasan']
endif
if get_option('buildtype') == 'release'
CFLAGS += ['-O3', '-march=native', '-g']
endif
static_build = get_option('default_library') == 'static'
if static_build
LDFLAGS += ['-l:libgpm.a']
endif
srcprefix = 'src/'
srcraw = [
'algorithm.c',
'loop.c',
'main.c',
'tui.c',
]
src = []
foreach s : srcraw
src += srcprefix + s
endforeach
curses_dep = dependency('ncursesw', static: static_build)
panel_dep = dependency('panelw', static: static_build)
executable('orcsmasher', src, include_directories: inc, dependencies: [curses_dep, panel_dep], c_args: CFLAGS, link_args: LDFLAGS)
Msrc/algorithm.c
@@ -25,16 +25,15 @@ static char *maze_at(char *m, size_t xs, struct point p)
static bool maze_in_bounds(size_t ys, size_t xs, struct point p)
{
return p.y > 0 && p.y < ys-1 &&
p.x > 0 && p.x < xs-1;
return p.y > 0 && (size_t)p.y < ys-1 && p.x > 0 && (size_t)p.x < xs-1;
}
struct game make_maze(size_t y, size_t x)
{
assert(y >= 5);
assert(y >= 5);
y += (y%2 == 0); //it must be an uneven number to look fine
x += (x%2 == 0);
assert(y >= 5);
assert(x >= 5);
struct game g = create_game(y, x);
char *maze = xmalloc(y * x + 1);
Msrc/tui.c
@@ -184,7 +184,7 @@ void logstr(const char *format, ...)
vsprintf(logs[loglength-1]+10, format, ap2);
va_end(ap2);
if(loglength - logindex == getmaxy(logwin))
if(loglength - logindex == (size_t)getmaxy(logwin)) //cast is fine, getmaxy only returns ERR if WINDOW is NULL
logindex++;
printlog();
@@ -250,7 +250,7 @@ void draw_map(const struct game *g, struct point p)
wrefresh(mapwin);
}
bool messagebox(const char *str, int y, int x)
bool messagebox(const char *str, size_t y, size_t x)
{
int yorig = y, xorig = x;
struct winsize w;