add dump option for qjs, clean up makefile

This commit is contained in:
John Alanbrook 2024-03-14 16:48:05 -05:00
parent 188fe7526c
commit bad225b965
7 changed files with 45 additions and 41 deletions

View file

@ -6,19 +6,12 @@ MAKEDIR != pwd
CXX:=$(CC) CXX:=$(CC)
ifeq ($(CXX), tcc)
CXX=clang
endif
ifeq ($(CC),cc)
CC=clang
endif
# Temp to strip long emcc paths to just emcc # Temp to strip long emcc paths to just emcc
CC := $(notdir $(CC)) CC := $(notdir $(CC))
DBG ?= 1
OPT ?= 0 OPT ?= 0
LEAK ?= 0
QJS :=
INFO := INFO :=
LD = $(CC) LD = $(CC)
@ -57,19 +50,24 @@ ifeq ($(CC), emcc)
AR = emar AR = emar
endif endif
ifeq ($(DBG),1) ifdef NDEBUG
CPPFLAGS += -g
INFO += _dbg
else
CPPFLAGS += -DNDEBUG CPPFLAGS += -DNDEBUG
LDFLAGS += -s LDFLAGS += -s
else
CPPFLAGS += -g
INFO += _dbg
endif endif
ifeq ($(LEAK),1) ifdef LEAK
CPPFLAGS += -fsanitize=address CPPFLAGS += -fsanitize=address
CPPFLAGS += -fsanitize=undefined
CPPFLAGS += -fno-omit-frame-pointer
QJS += LEAK
endif endif
CPPFLAGS += -DLEAK=$(LEAK) ifdef DUMP
QJS += DUMP
endif
ifeq ($(OPT),small) ifeq ($(OPT),small)
CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
@ -259,7 +257,7 @@ input.md: $(INPUTMD)
QUICKJS := source/engine/thirdparty/quickjs QUICKJS := source/engine/thirdparty/quickjs
$(BIN)/libquickjs.a: $(BIN)/libquickjs.a:
make -C $(QUICKJS) clean 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) @mkdir -p $(BIN)
cp -rf $(QUICKJS)/libquickjs.* $(BIN) cp -rf $(QUICKJS)/libquickjs.* $(BIN)

View file

@ -352,6 +352,10 @@ void phys2d_poly_free(struct phys2d_poly *poly)
float phys2d_poly_moi(struct phys2d_poly *poly) { float phys2d_poly_moi(struct phys2d_poly *poly) {
float m = poly->shape.go->mass; float m = poly->shape.go->mass;
int len = cpPolyShapeGetCount(poly->shape.shape); 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]; cpVect points[len];
for (int i = 0; i < len; i++) for (int i = 0; i < len; i++)
points[i] = cpPolyShapeGetVert(poly->shape.shape, i); points[i] = cpPolyShapeGetVert(poly->shape.shape, i);

View file

@ -7,6 +7,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include "yugine.h" #include "yugine.h"
#include "resources.h" #include "resources.h"
@ -30,14 +32,19 @@ char *catstr[] = {"engine", "script", "render"};
static FILE *logout; /* where logs are written to */ static FILE *logout; /* where logs are written to */
static FILE *writeout; /* where console is 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() void log_init()
{ {
#ifndef NDEBUG #ifndef NDEBUG
logout = fopen(".prosperon/log.txt", "w"); logout = fopen(".prosperon/log.txt", "w");
writeout = fopen(".prosperon/transcript.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 #endif
} }
@ -64,7 +71,7 @@ void mYughLog(int category, int priority, int line, const char *file, const char
va_end(args); va_end(args);
fprintf(logout, "\n"); 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]); printf(logfmt, file, line, timebuf, logcolor[priority], catstr[category]);
va_list args; va_list args;
va_start(args,message); va_start(args,message);
@ -73,6 +80,9 @@ void mYughLog(int category, int priority, int line, const char *file, const char
printf("\n"); printf("\n");
fflush(stdout); fflush(stdout);
} }
if (priority >= LOG_ERROR)
raise(SIGINT);
#endif #endif
} }

View file

@ -438,8 +438,6 @@ HMM_Vec2 *jsfloat2vec(JSValue v)
HMM_Vec2 *arr = NULL; HMM_Vec2 *arr = NULL;
int n = s/2; int n = s/2;
n /= sizeof(float); n /= sizeof(float);
// arrsetcap(arr,n);
// memcpy(arr,buf,s);
return arr; return arr;
} }
@ -451,10 +449,6 @@ JSValue bitmask2js(cpBitmask mask) {
return arr; 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 vecarr2js(HMM_Vec2 *points, int n) {
JSValue array = JS_NewArray(js); JSValue array = JS_NewArray(js);
@ -673,11 +667,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 4: case 4:
debug_draw_phys(JS_ToBool(js, argv[1])); debug_draw_phys(JS_ToBool(js, argv[1]));
break; break;
case 15: case 15:
gameobject_draw_debug(js2gameobject(argv[1])); gameobject_draw_debug(js2gameobject(argv[1]));
break; break;
case 16: case 16:
str = js2str(argv[1]); 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])); draw_grid(js2number(argv[1]), js2number(argv[2]), js2color(argv[3]));
break; break;
case 51: case 51:
draw_cppoint(js2vec2(argv[1]), js2number(argv[2]), js2color(argv[3])); draw_cppoint(js2vec2(argv[1]), js2number(argv[2]), js2color(argv[3]));
break; break;
@ -912,7 +904,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
cpBodySetTorque(js2gameobject(argv[1])->body, js2number(argv[2])); cpBodySetTorque(js2gameobject(argv[1])->body, js2number(argv[2]));
break; break;
case 160: case 160:
ret = vec22js(mat_t_dir(t_world2go(js2gameobject(argv[1])), js2vec2(argv[2]))); ret = vec22js(mat_t_dir(t_world2go(js2gameobject(argv[1])), js2vec2(argv[2])));
break; break;
@ -1391,7 +1382,6 @@ JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \
return n->ENTRY; \ return n->ENTRY; \
} \ } \
GETSET_PAIR(warp_gravity, strength, number) GETSET_PAIR(warp_gravity, strength, number)
GETSET_PAIR(warp_gravity, decay, number) GETSET_PAIR(warp_gravity, decay, number)
GETSET_PAIR(warp_gravity, spherical, bool) GETSET_PAIR(warp_gravity, spherical, bool)
@ -2067,10 +2057,7 @@ void ffi_load() {
DUK_FUNC(gui_img, 10) DUK_FUNC(gui_img, 10)
DUK_FUNC(inflate_cpv, 3) DUK_FUNC(inflate_cpv, 3)
DUK_FUNC(performance, 2) DUK_FUNC(performance, 2)
QJSCLASSPREP(ptr); QJSCLASSPREP(ptr);
QJSCLASSPREP_FUNCS(gameobject); QJSCLASSPREP_FUNCS(gameobject);

View file

@ -179,6 +179,9 @@ LDEXPORT=
else else
LDEXPORT=-rdynamic LDEXPORT=-rdynamic
endif endif
ifdef DUMP
CFLAGS += -DDUMP
endif
ifndef CONFIG_COSMO ifndef CONFIG_COSMO
ifndef CONFIG_DARWIN ifndef CONFIG_DARWIN

View file

@ -105,6 +105,15 @@
//#define DUMP_PROMISE //#define DUMP_PROMISE
//#define DUMP_READ_OBJECT //#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 */ /* test the GC by forcing it before each object allocation */
//#define FORCE_GC_AT_MALLOC //#define FORCE_GC_AT_MALLOC

View file

@ -11,8 +11,6 @@
#include <stdio.h> #include <stdio.h>
#include "particle.h" #include "particle.h"
#include "simplex.h" #include "simplex.h"
#include "wchar.h"
#include "locale.h"
#include "datastream.h" #include "datastream.h"
@ -167,8 +165,6 @@ void c_clean() {
void c_event(const sapp_event *e) void c_event(const sapp_event *e)
{ {
char utf8str[6] = {0};
wchar_t wcode;
switch (e->type) { switch (e->type) {
case SAPP_EVENTTYPE_MOUSE_MOVE: 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); 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; break;
case SAPP_EVENTTYPE_CHAR: case SAPP_EVENTTYPE_CHAR:
if (e->char_code > 127) break; /* only dealing with ascii now */ script_evalf("prosperon.textinput(`%lc`);", e->char_code);
wctomb(utf8str, wcode);
script_evalf("prosperon.textinput(`%ls`);", utf8str);
break; break;
case SAPP_EVENTTYPE_RESIZED: case SAPP_EVENTTYPE_RESIZED:
@ -288,7 +282,6 @@ static sapp_desc start_desc = {
}; };
int main(int argc, char **argv) { int main(int argc, char **argv) {
setlocale(LC_ALL, "en_US.utf8");
#ifndef NDEBUG #ifndef NDEBUG
log_init(); log_init();