polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit 43af373d7d35df01900649f6a7d354c4be88827d
parent c0bfe45a842799b17b5ada2e7c437550d4706ec9
Author: William Casarin <jb55@jb55.com>
Date:   Mon, 29 Jul 2019 10:02:32 -0700

release build fixes

Diffstat:
MMakefile | 10++++++----
Mmain.c | 4++--
Msrc/debug.c | 5+++--
Msrc/debug.h | 6++++++
Msrc/mdl.c | 1+
Msrc/ply.c | 2+-
Msrc/poisson.c | 1+
Msrc/render.c | 13+++++++------
Msrc/skybox.c | 1+
Msrc/terrain.c | 5+++++
Msrc/terrain.h | 2+-
Msrc/terrain_collision.c | 2++
Msrc/ui.c | 2++
13 files changed, 38 insertions(+), 16 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,11 +1,13 @@ NAME ?= polyadvent BIN ?= $(NAME) PREFIX ?= /usr/local -DEFS= -DGLFW_INCLUDE_NONE -DDEBUG +DEFS= -DGLFW_INCLUDE_NONE # release build lol -#DEFS= -DGLFW_INCLUDE_NONE -DNDEBUG -# CFLAGS = $(DEFS) -ggdb -O0 -I src -Wall -Wextra -std=c99 -CFLAGS = $(DEFS) -ggdb -O2 -I src -Wall -Werror -Wextra -std=c99 \ +# DEFS= -DGLFW_INCLUDE_NONE -DNDEBUG + +# CFLAGS = $(DEFS) -ggdb -O0 -I src -Wall -Wextra -std=c99 \ + +CFLAGS = $(DEFS) -O2 -I src -Wall -Werror -Wextra -std=c99 \ -Wno-unused-function \ -Wno-unused-parameter \ -Wno-unused-variable \ diff --git a/main.c b/main.c @@ -30,8 +30,8 @@ int main(void) { int nsamples; - /* int seed = time(NULL); */ - int seed = 42; + int seed = time(NULL); + /* int seed = 42; */ debug("seed %d\n", seed); srand(seed); diff --git a/src/debug.c b/src/debug.c @@ -3,8 +3,7 @@ #include <stdlib.h> #include <stdio.h> -void -show_info_log(GLuint shader) { +void show_info_log(GLuint shader) { GLint msgLen = 0; glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &msgLen); @@ -16,3 +15,5 @@ show_info_log(GLuint shader) { free(buffer); } + + diff --git a/src/debug.h b/src/debug.h @@ -6,6 +6,12 @@ void show_info_log(GLuint shader); +// rtassert exists in release builds, use sparingly +#define rtassert(cond, msg) if (!cond) { \ + fprintf(stderr, "FATAL %s:%d %s\n", __FILE__, __LINE__, msg); \ + exit(1); \ + } + #define unusual(...) fprintf(stderr, "UNUSUAL: " __VA_ARGS__) #ifdef DEBUG diff --git a/src/mdl.c b/src/mdl.c @@ -173,6 +173,7 @@ void load_mdl_fd(FILE *in, struct model *model, struct mdl_geometry *lgeom) { struct make_geometry *mkgeom = &lgeom->mkgeom; int num; + (void)num; while (1) { enum mdl_tag tag = read_tag(in); diff --git a/src/ply.c b/src/ply.c @@ -132,7 +132,7 @@ int parse_ply_with_mkgeom(const char *filename, struct mdl_geometry *mdlgeom) const char *data = file_contents(filename, &len); const char *p = data; - float vert[3], norm[3], min[3], max[3]; + float vert[3], norm[3], min[3]={0}, max[3]={0}; int inds[3]; u8 color[3]; diff --git a/src/poisson.c b/src/poisson.c @@ -86,6 +86,7 @@ struct point * load_samples(int *seed, int *n_samples) { FILE *fp = fopen("data/samples-200x200.bin", "rb"); int res; + (void)res; int localseed; seed = seed ? seed : &localseed; res = fread(seed, sizeof(*seed), 1, fp); diff --git a/src/render.c b/src/render.c @@ -74,15 +74,15 @@ init_gl(struct resources *resources, int width, int height) { glCullFace(GL_BACK); glEnable(GL_MULTISAMPLE); -check_gl(); + check_gl(); // Shaders ok = make_shader(GL_VERTEX_SHADER, SHADER("vertex-color.glsl"), &vertex); - assert(ok && "vertex-color shader"); + rtassert(ok, "vertex-color shader"); ok = make_shader(GL_VERTEX_SHADER, SHADER("terrain.v.glsl"), &terrain_vertex); - assert(ok && "terrain vertex shader"); + rtassert(ok, "terrain vertex shader"); check_gl(); /* ok = make_shader(GL_GEOMETRY_SHADER, SHADER("terrain.g.glsl"), */ @@ -100,7 +100,7 @@ check_gl(); /* check_gl(); */ ok = make_shader(GL_FRAGMENT_SHADER, SHADER("test.f.glsl"), &fragment); - assert(ok && "default fragment shader"); + rtassert(ok, "default fragment shader"); check_gl(); // camera @@ -127,11 +127,12 @@ check_gl(); ok = make_program_from_shaders(terrain_shaders, ARRAY_SIZE(terrain_shaders), &resources->programs[TERRAIN_PROGRAM]); - assert(ok && "terrain program"); + // TODO: replace rtassert with error reporting/handling + rtassert(ok, "terrain program"); check_gl(); ok = make_program(&vertex, &fragment, &resources->programs[DEFAULT_PROGRAM]); - assert(ok && "vertex-color program"); + rtassert(ok, "vertex-color program"); check_gl(); GLuint programs[] = diff --git a/src/skybox.c b/src/skybox.c @@ -37,6 +37,7 @@ void create_skybox(struct skybox *skybox, struct gpu_program *program) { struct shader vertex, frag; struct shader *shaders[] = {&vertex, &frag}; int ok; + (void)ok; node_init(&skybox->node); init_id(&skybox->model_id); diff --git a/src/terrain.c b/src/terrain.c @@ -158,6 +158,7 @@ static void insert_grid_vertex(struct terrain_cell *cell, int ind) cell->verts_index[cell->vert_count++] = ind; } +#ifdef DEBUG static int terrain_cell_debug(struct terrain *terrain, struct terrain_cell *cell, int ind, vec3 *pos) { int ok = 0; @@ -179,7 +180,10 @@ static int terrain_cell_debug(struct terrain *terrain, struct terrain_cell *cell return ok; } +#endif /* DEBUG */ + +#ifdef DEBUG static int collide_terrain_debug(struct terrain *terrain, struct terrain_cell *cell, int ind, vec3 *pos) { int ok = 0; @@ -189,6 +193,7 @@ static int collide_terrain_debug(struct terrain *terrain, struct terrain_cell *c return ok; } +#endif /* DEBUG */ void create_terrain(struct terrain *terrain, float scale, int seed) { diff --git a/src/terrain.h b/src/terrain.h @@ -8,7 +8,7 @@ #include "debug.h" #define MAX_CELL_VERTS 4 -#define MAX_VERT_TRIS 24 +#define MAX_VERT_TRIS 20 struct point; diff --git a/src/terrain_collision.c b/src/terrain_collision.c @@ -117,6 +117,8 @@ static void terrain_tri_debug(float *verts, struct tri *tri) } } +#else +#define terrain_tri_debug(...) #endif diff --git a/src/ui.c b/src/ui.c @@ -93,6 +93,8 @@ void create_ui(struct ui *ui, int width, int height, struct gpu_program *shader) struct shader vertex; struct shader fragment; int ok = 0; + // TODO: handle runtime ui errors (there shouldn't be any...) + (void)ok; ui->shader = shader; create_quad(&ui->quad_geom_id);