From 0b64d0872b93157aada26992a68fc7ffcf5eca15 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 14 Dec 2022 19:01:42 +0000 Subject: [PATCH] Fixed many incompatible pointer warnings; add tcc specific debugging flags to makefile --- Makefile | 13 +++++++++---- source/engine/2dphysics.c | 2 +- source/engine/3d/static_actor.c | 16 ---------------- source/engine/debug/debugdraw.c | 4 ++-- source/engine/debug/log.c | 15 ++++++--------- source/engine/editor/ed_project.c | 8 +++++--- source/engine/editor/editor.c | 21 +++++++++++---------- source/engine/font.c | 2 +- source/engine/font.h | 2 +- source/engine/gameobject.c | 6 +++--- source/engine/input.c | 4 +++- source/engine/sound.c | 7 ------- source/engine/sound/dsp.h | 2 ++ source/engine/sound/mix.c | 2 ++ source/engine/window.c | 4 +++- source/engine/yugine.c | 8 ++++++++ 16 files changed, 57 insertions(+), 59 deletions(-) diff --git a/Makefile b/Makefile index ff54bfc..6c3d70a 100755 --- a/Makefile +++ b/Makefile @@ -14,6 +14,9 @@ PTYPE != uname -m ifeq ($(DBG), 1) QFLAGS = -O0 -g -DDBG=1 -DED=1 + ifeq ($(CC), tcc) + QFLAGS += -b -bt24 + endif INFO = dbg endif @@ -22,7 +25,7 @@ ifeq ($(ED), 0) INFO = ed endif -BIN = bin/ +BIN = bin/$(CC)/ objprefix = $(BIN)obj/$(INFO) define prefix @@ -46,7 +49,7 @@ eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player y includeflag != $(call prefix,$(edirs),-I) -WARNING_FLAGS = #-Wall -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function +WARNING_FLAGS = -Wall# -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 @@ -54,7 +57,7 @@ VER = $(SEM)-$(COM) COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@ -LIBPATH = -Lbin +LIBPATH = -L$(BIN) ifeq ($(OS), WIN32) LINKER_FLAGS = $(QFLAGS) @@ -89,6 +92,8 @@ DIST = yugine-$(MYTAG).tar.gz .PHONY: yugine +yugine: $(BIN)yugine + $(BIN)yugine: $(objprefix)/source/engine/yugine.o $(ENGINE) @echo Linking yugine $(CC) $< $(LINK) -o $(BIN)yugine @@ -127,5 +132,5 @@ $(objprefix)/%.o:%.c .PHONY: clean clean: @echo Cleaning project - @find $(BIN) -type f -delete + @rm -rf bin/* @rm -f *.gz diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index d157925..045a1ec 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -153,7 +153,7 @@ void box_gui(struct phys2d_box *box) { nk_property_float(ctx, "Width", 0.f, &box->w, 1000.f, 1.f, 1.f); nk_property_float(ctx, "Height", 0.f, &box->h, 1000.f, 1.f, 1.f); - nk_property_float2(ctx, "Offset", 0.f, &box->offset, 1.f, 0.01f, 0.01f); + nk_property_float2(ctx, "Offset", 0.f, box->offset, 1.f, 0.01f, 0.01f); phys2d_applybox(box); } diff --git a/source/engine/3d/static_actor.c b/source/engine/3d/static_actor.c index bf8c6a0..948e3b8 100644 --- a/source/engine/3d/static_actor.c +++ b/source/engine/3d/static_actor.c @@ -76,19 +76,3 @@ Serialize *make_staticactor() */ #include "nuke.h" - -void staticactor_gui(struct mStaticActor *sa) -{ - object_gui(&sa->obj); - if (nk_tree_push(ctx, NK_TREE_NODE, "Model", NK_MINIMIZED)) { - nk_checkbox_label(ctx, "Cast Shadows", &sa->castShadows); - nk_labelf(ctx, NK_TEXT_LEFT, "Model path: %s", sa->currentModelPath); - - //ImGui::SameLine(); - if (nk_button_label(ctx, "Load model")) { - //asset_command = set_new_model; - curActor = sa; - } - - } -} diff --git a/source/engine/debug/debugdraw.c b/source/engine/debug/debugdraw.c index 8b7bb43..0deb801 100644 --- a/source/engine/debug/debugdraw.c +++ b/source/engine/debug/debugdraw.c @@ -55,7 +55,7 @@ void draw_line(int x1, int y1, int x2, int y2) x2, y2 }; - draw_poly(&verts, 2); + draw_poly(verts, 2); } void draw_edge(float *points, int n) @@ -98,7 +98,7 @@ void draw_rect(int x, int y, int w, int h) x - hw, y + hh }; - draw_poly(&verts, 4); + draw_poly(verts, 4); } void draw_grid(int width, int span) diff --git a/source/engine/debug/log.c b/source/engine/debug/log.c index 8ad187d..9129ceb 100644 --- a/source/engine/debug/log.c +++ b/source/engine/debug/log.c @@ -5,6 +5,7 @@ #include #include #include +#include #define logLevel 0 @@ -12,7 +13,7 @@ char *logstr[] = { "INFO", "WARN", "ERROR", "CRITICAL" }; char *catstr[] = {"ENGINE"}; -FILE *fout = NULL; + void mYughLog(int category, int priority, int line, const char *file, const char *message, ...) { @@ -30,19 +31,15 @@ void mYughLog(int category, int priority, int line, const char *file, const char char buffer[ERROR_BUFFER] = { '\0' }; snprintf(buffer, ERROR_BUFFER, "%s | %s | %s [ %s:%d ] %s\n", logstr[priority], catstr[0], dt, file, line, msgbuffer); - printf("%s", buffer); - fflush(stdout); - - if (fout) { - fprintf(fout, "%s", buffer); - fflush(fout); - } + fprintf(stderr, "%s", buffer); + fprintf(stdout, "%s", buffer); + fflush(stdout); } } void log_setfile(char *file) { YughInfo("Opening output log %s.", file); - fout = fopen(file, "w"); + freopen(file, "w", stderr); } void log_cat(FILE *f) { diff --git a/source/engine/editor/ed_project.c b/source/engine/editor/ed_project.c index b1449e4..ca719fe 100644 --- a/source/engine/editor/ed_project.c +++ b/source/engine/editor/ed_project.c @@ -1,5 +1,8 @@ #include "ed_project.h" +#include +#include +#include #include "editor.h" void editor_init_project(struct gameproject *gp) @@ -17,8 +20,7 @@ void editor_init_project(struct gameproject *gp) void editor_make_project(char *path) { FILE *f = path_open("w", "%s%s", path, "/project.yugh"); - cur_project = - (struct gameproject *) malloc(sizeof(struct gameproject)); + cur_project = malloc(sizeof(struct gameproject)); strncpy(cur_project->name, "New Game", 127); strncpy(cur_project->path, path, 2048); vec_add(projects, cur_project); @@ -36,7 +38,7 @@ void editor_import_project(char *path) if (!f) return; - struct gameproject *gp = (struct gameproject *) malloc(sizeof(*gp)); + struct gameproject *gp = malloc(sizeof(*gp)); fread(gp, sizeof(*gp), 1, f); fclose(f); diff --git a/source/engine/editor/editor.c b/source/engine/editor/editor.c index 4dc79e5..eeef7b6 100644 --- a/source/engine/editor/editor.c +++ b/source/engine/editor/editor.c @@ -27,6 +27,7 @@ #include #include #include +#include "nuke.h" #include "log.h" @@ -48,9 +49,9 @@ static bool renderAO = true; static bool renderDynamicShadows = true; // Debug render modes -static bool renderGizmos = false; -static bool showGrid = true; -static bool debugDrawPhysics = false; +static int renderGizmos = false; +static int showGrid = true; +static int debugDrawPhysics = false; const char *allowed_extensions[] = {"jpg", "png", "rb", "wav", "mp3", }; @@ -81,8 +82,8 @@ static int grid1_width = 1; static int grid1_span = 100; static int grid2_width = 3; static int grid2_span = 1000; -static bool grid1_draw = true; -static bool grid2_draw = true; +static int grid1_draw = true; +static int grid2_draw = true; static float tex_scale = 1.f; static struct TexAnimation tex_gui_anim = {0}; @@ -495,7 +496,7 @@ void editor_project_gui() { */ NK_MENU_START(level) nuke_nel(1); - nuke_labelf(ctx, "Current level: %s", current_level[0] == '\0' ? "No level loaded." : current_level); + nuke_labelf("Current level: %s", current_level[0] == '\0' ? "No level loaded." : current_level); nuke_nel(3); if (nk_button_label(ctx, "New")) { @@ -585,9 +586,9 @@ void editor_project_gui() { NK_MENU_START(debug) if (nk_tree_push(ctx, NK_TREE_NODE, "Debug Draws", NK_MINIMIZED)) { - nk_checkbox_label(ctx, "Gizmos", &renderGizmos); - nk_checkbox_label(ctx, "Grid", &showGrid); - nk_checkbox_label(ctx, "Physics", &debugDrawPhysics); + nuke_checkbox("Gizmos", &renderGizmos); + nuke_checkbox("Grid", &showGrid); + nuke_checkbox("Physics", &debugDrawPhysics); nk_tree_pop(ctx); } @@ -596,7 +597,7 @@ void editor_project_gui() { NK_MENU_START(hierarchy) nk_layout_row_dynamic(ctx, 25, 1); - if (nk_button_label(ctx, "New Object")) { + if (nuke_btn("New Object")) { MakeGameobject(); } diff --git a/source/engine/font.c b/source/engine/font.c index 49bdb1a..a731998 100644 --- a/source/engine/font.c +++ b/source/engine/font.c @@ -79,7 +79,7 @@ struct sFont *MakeFont(const char *fontfile, int height) glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - for (unsigned char c = 32; c < 128; c++) { + for (unsigned char c = 32; c < 127; c++) { unsigned char *bitmap; int advance, lsb, w, h, x0, y0; stbtt_GetCodepointHMetrics(&fontinfo, c, &advance, &lsb); diff --git a/source/engine/font.h b/source/engine/font.h index 6eac02b..79826bb 100644 --- a/source/engine/font.h +++ b/source/engine/font.h @@ -17,7 +17,7 @@ struct Character { struct sFont { uint32_t fontTexture; uint32_t height; - struct Character Characters[127]; + struct Character Characters[126]; }; diff --git a/source/engine/gameobject.c b/source/engine/gameobject.c index 62cfd25..9a5b1ac 100644 --- a/source/engine/gameobject.c +++ b/source/engine/gameobject.c @@ -259,9 +259,9 @@ void object_gui(struct gameobject *go) nk_property_float(ctx, "Scale", 0.f, &go->scale, 1000.f, 0.01f, go->scale * 0.01f); nk_layout_row_dynamic(ctx, 25, 3); - nk_radio_button_label(ctx, "Static", &go->bodytype, CP_BODY_TYPE_STATIC); - nk_radio_button_label(ctx, "Dynamic", &go->bodytype, CP_BODY_TYPE_DYNAMIC); - nk_radio_button_label(ctx, "Kinematic", &go->bodytype, CP_BODY_TYPE_KINEMATIC); + nuke_radio_btn("Static", &go->bodytype, CP_BODY_TYPE_STATIC); + nuke_radio_btn("Dynamic", &go->bodytype, CP_BODY_TYPE_DYNAMIC); + nuke_radio_btn("Kinematic", &go->bodytype, CP_BODY_TYPE_KINEMATIC); cpBodySetType(go->body, go->bodytype); diff --git a/source/engine/input.c b/source/engine/input.c index bf55e77..665da49 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -1,5 +1,7 @@ #include "input.h" +#include +#include "script.h" #include "stb_ds.h" int32_t mouseWheelX = 0; @@ -57,7 +59,7 @@ void input_poll(double wait) //editor_input(&e); for (int i = 0; i < arrlen(downkeys); i++) - call_input_down(downkeys[i]); + call_input_down(&downkeys[i]); } void win_key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) diff --git a/source/engine/sound.c b/source/engine/sound.c index df63f3f..e63531f 100644 --- a/source/engine/sound.c +++ b/source/engine/sound.c @@ -104,13 +104,6 @@ void wav_norm_gain(struct wav *w, double lv) } } -struct osc sin600; -struct osc sin20; -struct dsp_ammod dspammod; -struct dsp_delay dspdel; -struct wav s600wav; -struct sound s600wavsound; - void sound_init() { PaError err = Pa_Initialize(); diff --git a/source/engine/sound/dsp.h b/source/engine/sound/dsp.h index 9eb00c8..f5c878c 100644 --- a/source/engine/sound/dsp.h +++ b/source/engine/sound/dsp.h @@ -153,4 +153,6 @@ void dsp_mono(void *p, short *out, int n); void dsp_bitcrush(void *p, short *out, int n); +void dsp_run(struct dsp_filter filter, short *out, int n); + #endif diff --git a/source/engine/sound/mix.c b/source/engine/sound/mix.c index e52d032..5ec531e 100644 --- a/source/engine/sound/mix.c +++ b/source/engine/sound/mix.c @@ -2,6 +2,8 @@ #include "stddef.h" #include "time.h" #include "sound.h" +#include "dsp.h" +#include static struct bus bus[256]; short mastermix[BUF_FRAMES*CHANNELS]; diff --git a/source/engine/window.c b/source/engine/window.c index 8dbf1e1..ea42ff4 100644 --- a/source/engine/window.c +++ b/source/engine/window.c @@ -8,6 +8,8 @@ #include "script.h" #include "nuke.h" +#include "openglrender.h" + #include "stb_ds.h" struct window *mainwin; @@ -21,7 +23,7 @@ int is_win(struct window *s, GLFWwindow *w) return s->window == w; } -void window_size_callback(GLFWwindow *w) +void window_size_callback(GLFWwindow *w, int width, int height) { } diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 231c15b..d1d9d9d 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -10,6 +10,7 @@ #include #include + #ifdef __linux__ #include #endif @@ -83,6 +84,13 @@ int main(int argc, char **args) { exit(1); break; + case 'h': + printf("-l Set log file\n"); + printf("-play Launch engine in play mode instead of editor mode\n"); + printf("-v Display engine info\n"); + exit(0); + break; + } } }