From 0bf7d419e0c1433263517dfbf63f9b823ff3cd1a Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Sat, 29 Apr 2023 01:55:24 +0000 Subject: [PATCH] fix compiler warnings --- Makefile | 4 ++-- source/engine/2dphysics.c | 5 ++--- source/engine/debug/log.c | 6 ++++-- source/engine/font.c | 2 -- source/engine/gameobject.c | 6 +++--- source/engine/input.c | 10 +++++++--- source/engine/openglrender.c | 1 - source/engine/resources.c | 2 +- source/engine/script.c | 5 +++++ source/engine/script.h | 1 + source/engine/sprite.c | 2 -- source/engine/texture.c | 3 +-- source/engine/transform.c | 3 +-- source/engine/window.c | 3 ++- 14 files changed, 29 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 848fe30..7d4b5a5 100755 --- a/Makefile +++ b/Makefile @@ -66,13 +66,13 @@ includeflag != find source -type d -name include includeflag += $(engincs) source/engine/thirdparty/Nuklear includeflag := $(addprefix -I, $(includeflag)) -WARNING_FLAGS = -Wall# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function +WARNING_FLAGS = -Wall -Wno-unused-function# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function SEM = 0.0.1 COM != git rev-parse --short HEAD VER = $(SEM)-$(COM) -COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -march=native -std=c99 -c $< -o $@ +COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -I. -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -march=native -std=c99 -c $< -o $@ LIBPATH = -L$(BIN) diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 1d59ba9..329c477 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -7,12 +7,13 @@ #include "debug.h" #include "debugdraw.h" -#include "gameobject.h" #include #include #include "stb_ds.h" #include +#include "2dphysics.h" + #include "tinyspline.h" #include "script.h" @@ -459,7 +460,6 @@ void phys2d_applypoly(struct phys2d_poly *poly) void phys2d_dbgdrawpoly(struct phys2d_poly *poly) { float *color = shape_color(poly->shape.shape); - int n = arrlen(poly->points); if (arrlen(poly->points) >= 3) { int n = cpPolyShapeGetCount(poly->shape.shape); @@ -686,7 +686,6 @@ static cpBool handle_collision(cpArbiter *arb, int type) struct phys2d_shape *pshape2 = cpShapeGetUserData(shape2); cpVect norm1 = cpArbiterGetNormal(arb); - cpVect vel1 = cpArbiterGetSurfaceVelocity(arb); switch (type) { case CTYPE_BEGIN: diff --git a/source/engine/debug/log.c b/source/engine/debug/log.c index 4a2dd68..40b153d 100644 --- a/source/engine/debug/log.c +++ b/source/engine/debug/log.c @@ -8,6 +8,8 @@ #include #include +#include "script.h" + int logLevel = 1; /* Four levels of log: @@ -25,8 +27,8 @@ FILE *logfile = NULL; #define CONSOLE_BUF 1024*1024*5/* 5MB */ -char lastlog[ERROR_BUFFER] = {'\0'}; -char consolelog[CONSOLE_BUF] = {'\0'}; +char lastlog[ERROR_BUFFER+1] = {'\0'}; +char consolelog[CONSOLE_BUF+1] = {'\0'}; void mYughLog(int category, int priority, int line, const char *file, const char *message, ...) { diff --git a/source/engine/font.c b/source/engine/font.c index 2d67bff..3e11290 100644 --- a/source/engine/font.c +++ b/source/engine/font.c @@ -162,7 +162,6 @@ struct sFont *MakeFont(const char *fontfile, int height) } static int curchar = 0; -static float *buffdraw; void draw_char_box(struct Character c, float cursor[2], float scale, float color[3]) { @@ -281,7 +280,6 @@ int renderText(const char *text, mfloat_t pos[2], float scale, mfloat_t color[3] curchar = 0; float *usecolor = color; - float caretcolor[3] = {0.4,0.98,0.75}; while (*line != '\0') { diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 12ee8de..681abd5 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -40,9 +40,9 @@ int body2id(cpBody *body) cpBody *id2body(int id) { - struct gameobject *go; + struct gameobject *go = id2go(id); - if (go = id2go(id)) + if (go) return go->body; return NULL; @@ -88,7 +88,7 @@ void gameobject_set_sensor(int id, int sensor) int go2id(struct gameobject *go) { - id_from_gameobject(go); + return id_from_gameobject(go); } void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go) diff --git a/source/engine/input.c b/source/engine/input.c index f120101..b916c4a 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -47,6 +47,8 @@ const char *gamepad2str(int btn) case GLFW_GAMEPAD_BUTTON_LEFT_THUMB: return "lthumb"; case GLFW_GAMEPAD_BUTTON_RIGHT_THUMB: return "rthumb"; } + + return "NOBTN"; } void register_pawn(struct callee c) @@ -196,7 +198,7 @@ void input_init() glfwSetJoystickCallback(joystick_cb); nukechar = glfwSetCharCallback(mainwin->window, char_cb); - const char *paddb = slurp_text("data/gamecontrollerdb.txt"); + char *paddb = slurp_text("data/gamecontrollerdb.txt"); glfwUpdateGamepadMappings(paddb); free(paddb); @@ -229,8 +231,9 @@ void call_input_signal(char *signal) { JS_FreeValue(js, s); } +char keybuf[50]; + const char *keyname_extd(int key, int scancode) { - char keybuf[50]; const char *kkey = NULL; if (key > 289 && key < 302) { @@ -372,6 +375,8 @@ const char *axis2str(int axis) case GLFW_GAMEPAD_AXIS_LEFT_TRIGGER: return "ltrigger"; case GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER: return "rtrigger"; } + + return "NOAXIS"; } /* This is called once every frame - or more if we want it more! */ @@ -394,7 +399,6 @@ void input_poll(double wait) JSValue argv[3]; argv[0] = num_cache[joysticks[i].id]; - char inputstr[50]; for (int b = 0; b < 15; b++) { argv[1] = jsgamepadstr[b]; diff --git a/source/engine/openglrender.c b/source/engine/openglrender.c index bebaaa8..93ea0c4 100644 --- a/source/engine/openglrender.c +++ b/source/engine/openglrender.c @@ -60,7 +60,6 @@ struct sprite *tsprite = NULL; static unsigned int projUBO; -static unsigned int resUBO; void debug_draw_phys(int draw) { debugDrawPhysics = draw; diff --git a/source/engine/resources.c b/source/engine/resources.c index 44ff165..29d3ec9 100644 --- a/source/engine/resources.c +++ b/source/engine/resources.c @@ -31,7 +31,7 @@ static const char *cur_ext = NULL; struct dirent *c_dirent = NULL; struct vec *c_vec = NULL; -char pathbuf[MAXPATH]; +char pathbuf[MAXPATH+1]; void resources_init() { diff --git a/source/engine/script.c b/source/engine/script.c index 07bcac4..069bf98 100644 --- a/source/engine/script.c +++ b/source/engine/script.c @@ -99,7 +99,11 @@ int js_print_exception(JSValue v) JS_FreeCString(js, msg); JS_FreeCString(js, stack); } + + return 1; } + + return 0; } int script_dofile(const char *file) { @@ -139,6 +143,7 @@ JSValue js_callee_exec(struct callee *c, int argc, JSValue *argv) JSValue ret = JS_Call(js, c->fn, c->obj, argc, argv); js_print_exception(ret); JS_FreeValue(js, ret); + return JS_NULL; } void call_callee(struct callee *c) { diff --git a/source/engine/script.h b/source/engine/script.h index 49997e3..00ff344 100644 --- a/source/engine/script.h +++ b/source/engine/script.h @@ -15,6 +15,7 @@ struct callee { extern struct callee stacktrace_callee; extern JSValue num_cache[100]; +void js_stacktrace(); void script_startup(); void script_init(); void script_run(const char *script); diff --git a/source/engine/sprite.c b/source/engine/sprite.c index d5bf502..01cec10 100644 --- a/source/engine/sprite.c +++ b/source/engine/sprite.c @@ -30,8 +30,6 @@ int make_sprite(int go) .layer = 0, .enabled = 1 }; - int ret; - if (first<0) { arrput(sprites, sprite); arrlast(sprites).id = arrlen(sprites)-1; diff --git a/source/engine/texture.c b/source/engine/texture.c index f76980f..f42fb95 100644 --- a/source/engine/texture.c +++ b/source/engine/texture.c @@ -63,7 +63,6 @@ struct Texture *texture_pullfromfile(const char *path) glGenTextures(1, &tex->id); glBindTexture(GL_TEXTURE_2D, tex->id); - GLenum fmt; switch (n) { @@ -84,7 +83,7 @@ struct Texture *texture_pullfromfile(const char *path) break; } - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->width, tex->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex->width, tex->height, 0, fmt, GL_UNSIGNED_BYTE, data); if (tex->opts.mips) glGenerateMipmap(GL_TEXTURE_2D); diff --git a/source/engine/transform.c b/source/engine/transform.c index 6902f69..722a124 100644 --- a/source/engine/transform.c +++ b/source/engine/transform.c @@ -1,8 +1,7 @@ #include "transform.h" #include -struct mTransform MakeTransform(mfloat_t pos[3], mfloat_t rotation[4], - float scale) +struct mTransform MakeTransform(mfloat_t pos[3], mfloat_t rotation[4], float scale) { struct mTransform newT; memcpy(newT.position, pos, sizeof(*pos)); diff --git a/source/engine/window.c b/source/engine/window.c index fc38b61..eb2d337 100644 --- a/source/engine/window.c +++ b/source/engine/window.c @@ -47,7 +47,8 @@ void window_iconify_callback(GLFWwindow *w, int iconified) void window_focus_callback(GLFWwindow *w, int focused) { struct window *win = winfind(w); - } + win->mouseFocus = focused; +} void window_maximize_callback(GLFWwindow *w, int maximized) {