diff --git a/Makefile b/Makefile index dcc3ea6..ac5382c 100755 --- a/Makefile +++ b/Makefile @@ -6,19 +6,12 @@ MAKEDIR != pwd CXX:=$(CC) -ifeq ($(CXX), tcc) - CXX=clang -endif - -ifeq ($(CC),cc) - CC=clang -endif # Temp to strip long emcc paths to just emcc CC := $(notdir $(CC)) -DBG ?= 1 OPT ?= 0 -LEAK ?= 0 + +QJS := INFO := LD = $(CC) @@ -57,19 +50,24 @@ ifeq ($(CC), emcc) AR = emar endif -ifeq ($(DBG),1) - CPPFLAGS += -g - INFO += _dbg -else +ifdef NDEBUG CPPFLAGS += -DNDEBUG LDFLAGS += -s +else + CPPFLAGS += -g + INFO += _dbg endif -ifeq ($(LEAK),1) +ifdef LEAK CPPFLAGS += -fsanitize=address + CPPFLAGS += -fsanitize=undefined + CPPFLAGS += -fno-omit-frame-pointer + QJS += LEAK endif -CPPFLAGS += -DLEAK=$(LEAK) +ifdef DUMP + QJS += DUMP +endif ifeq ($(OPT),small) CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables @@ -259,7 +257,7 @@ input.md: $(INPUTMD) QUICKJS := source/engine/thirdparty/quickjs $(BIN)/libquickjs.a: make -C $(QUICKJS) clean - make -C $(QUICKJS) SYSRT=$(SYSRT) TTARGET=$(TTARGET) ARCH=$(ARCH) DBG=$(DBG) OPT=$(OPT) AR=$(AR) OS=$(OS) libquickjs.a HOST_CC=$(CC) LEAK=$(LEAK) + make -C $(QUICKJS) AR=$(AR) HOST_CC=$(CC) LEAK=$(LEAK) DUMP=$(DUMP) libquickjs.a @mkdir -p $(BIN) cp -rf $(QUICKJS)/libquickjs.* $(BIN) diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index 4652361..e451cb1 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -352,6 +352,10 @@ void phys2d_poly_free(struct phys2d_poly *poly) float phys2d_poly_moi(struct phys2d_poly *poly) { float m = poly->shape.go->mass; int len = cpPolyShapeGetCount(poly->shape.shape); + if (!len) { + YughWarn("Cannot evaluate the MOI of a polygon of length %d.", len); + return 0; + } cpVect points[len]; for (int i = 0; i < len; i++) points[i] = cpPolyShapeGetVert(poly->shape.shape, i); diff --git a/source/engine/debug/log.c b/source/engine/debug/log.c index dac15c6..d3f6078 100644 --- a/source/engine/debug/log.c +++ b/source/engine/debug/log.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "yugine.h" #include "resources.h" @@ -30,14 +32,19 @@ char *catstr[] = {"engine", "script", "render"}; static FILE *logout; /* where logs are written to */ static FILE *writeout; /* where console is written to */ +static FILE *dump; /* where data is dumped to */ -int stdout_lvl = LOG_PANIC; +int stdout_lvl = LOG_ERROR; void log_init() { #ifndef NDEBUG logout = fopen(".prosperon/log.txt", "w"); writeout = fopen(".prosperon/transcript.txt", "w"); +/* int og = dup(1); + close(1); + int fd = open("out.txt", O_WRONLY | O_CREAT, 0644); + dup2(fd, 1);*/ #endif } @@ -64,7 +71,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char va_end(args); fprintf(logout, "\n"); - if (priority == LOG_DEBUG || priority > stdout_lvl) { + if (priority == LOG_DEBUG || priority >= stdout_lvl) { printf(logfmt, file, line, timebuf, logcolor[priority], catstr[category]); va_list args; va_start(args,message); @@ -73,6 +80,9 @@ void mYughLog(int category, int priority, int line, const char *file, const char printf("\n"); fflush(stdout); } + + if (priority >= LOG_ERROR) + raise(SIGINT); #endif } diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 25e509b..0d484ae 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -438,8 +438,6 @@ HMM_Vec2 *jsfloat2vec(JSValue v) HMM_Vec2 *arr = NULL; int n = s/2; n /= sizeof(float); -// arrsetcap(arr,n); -// memcpy(arr,buf,s); return arr; } @@ -451,10 +449,6 @@ JSValue bitmask2js(cpBitmask mask) { return arr; } -void vec2float(HMM_Vec2 v, float *f) { - f[0] = v.x; - f[1] = v.y; -} JSValue vecarr2js(HMM_Vec2 *points, int n) { JSValue array = JS_NewArray(js); @@ -673,11 +667,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) case 4: debug_draw_phys(JS_ToBool(js, argv[1])); break; - case 15: - gameobject_draw_debug(js2gameobject(argv[1])); - break; + gameobject_draw_debug(js2gameobject(argv[1])); + break; case 16: str = js2str(argv[1]); @@ -723,7 +716,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) draw_grid(js2number(argv[1]), js2number(argv[2]), js2color(argv[3])); break; - case 51: draw_cppoint(js2vec2(argv[1]), js2number(argv[2]), js2color(argv[3])); break; @@ -912,7 +904,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) cpBodySetTorque(js2gameobject(argv[1])->body, js2number(argv[2])); break; - case 160: ret = vec22js(mat_t_dir(t_world2go(js2gameobject(argv[1])), js2vec2(argv[2]))); break; @@ -1391,7 +1382,6 @@ JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \ return n->ENTRY; \ } \ - GETSET_PAIR(warp_gravity, strength, number) GETSET_PAIR(warp_gravity, decay, number) GETSET_PAIR(warp_gravity, spherical, bool) @@ -2067,10 +2057,7 @@ void ffi_load() { DUK_FUNC(gui_img, 10) DUK_FUNC(inflate_cpv, 3) - DUK_FUNC(performance, 2) - - QJSCLASSPREP(ptr); QJSCLASSPREP_FUNCS(gameobject); diff --git a/source/engine/thirdparty/quickjs/Makefile b/source/engine/thirdparty/quickjs/Makefile index 0270a6a..848db82 100644 --- a/source/engine/thirdparty/quickjs/Makefile +++ b/source/engine/thirdparty/quickjs/Makefile @@ -179,6 +179,9 @@ LDEXPORT= else LDEXPORT=-rdynamic endif +ifdef DUMP +CFLAGS += -DDUMP +endif ifndef CONFIG_COSMO ifndef CONFIG_DARWIN diff --git a/source/engine/thirdparty/quickjs/quickjs.c b/source/engine/thirdparty/quickjs/quickjs.c index ebf45a9..e0fd4f7 100644 --- a/source/engine/thirdparty/quickjs/quickjs.c +++ b/source/engine/thirdparty/quickjs/quickjs.c @@ -105,6 +105,15 @@ //#define DUMP_PROMISE //#define DUMP_READ_OBJECT +#ifdef DUMP +//#define DUMP_FREE +#define DUMP_GC +#define DUMP_GC_FREE +#define DUMP_LEAKS 1 +//#define DUMP_OBJECTS +//#define DUMP_CLOSURE +#endif + /* test the GC by forcing it before each object allocation */ //#define FORCE_GC_AT_MALLOC diff --git a/source/engine/yugine.c b/source/engine/yugine.c index 39b03d1..35c8e91 100644 --- a/source/engine/yugine.c +++ b/source/engine/yugine.c @@ -11,8 +11,6 @@ #include #include "particle.h" #include "simplex.h" -#include "wchar.h" -#include "locale.h" #include "datastream.h" @@ -167,8 +165,6 @@ void c_clean() { void c_event(const sapp_event *e) { - char utf8str[6] = {0}; - wchar_t wcode; switch (e->type) { case SAPP_EVENTTYPE_MOUSE_MOVE: script_evalf("prosperon.mousemove([%g, %g], [%g, %g]);", e->mouse_x, mainwin.size.y -e->mouse_y, e->mouse_dx, -e->mouse_dy); @@ -195,9 +191,7 @@ void c_event(const sapp_event *e) break; case SAPP_EVENTTYPE_CHAR: - if (e->char_code > 127) break; /* only dealing with ascii now */ - wctomb(utf8str, wcode); - script_evalf("prosperon.textinput(`%ls`);", utf8str); + script_evalf("prosperon.textinput(`%lc`);", e->char_code); break; case SAPP_EVENTTYPE_RESIZED: @@ -288,7 +282,6 @@ static sapp_desc start_desc = { }; int main(int argc, char **argv) { - setlocale(LC_ALL, "en_US.utf8"); #ifndef NDEBUG log_init();