Using TCC again; add clang-format

This commit is contained in:
2023-04-21 21:57:30 +00:00
parent 1f3a0091bb
commit 653e80cae8
6 changed files with 266 additions and 41 deletions

View File

@@ -83,7 +83,7 @@ void querylist(cpShape *shape, cpContactPointSet *points, void *data)
void querylistbodies(cpBody *body, void *data)
{
cpBB *bbox = data;
cpBB *bbox = data;
if (cpBBContainsVect(*bbox, cpBodyGetPosition(body))) {
int go = body2id(body);
if (go < 0) return;
@@ -137,7 +137,6 @@ int *phys2d_query_box(cpVect pos, cpVect wh)
if (qhits) arrfree(qhits);
cpSpaceShapeQuery(space, box, querylist, NULL);
cpSpaceEachBody(space, querylistbodies, &bbox);
cpShapeFree(box);
@@ -207,6 +206,7 @@ void phys2d_init()
}
void phys2d_set_gravity(cpVect v) {
YughInfo("Set gravity to %g %g", v.x, v.y);
cpSpaceSetGravity(space, v);
}
@@ -668,7 +668,7 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
JS_SetPropertyStr(js, obj, "hit", JS_NewInt32(js, hit));
JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2)));
JS_SetPropertyStr(js, obj, "velocity", vec2js(cpArbiterGetSurfaceVelocity(arb)));
JS_Call(js, c.fn, c.obj, 1, &obj);
script_callee(c, 1, &obj);
}
#define CTYPE_BEGIN 0
@@ -692,26 +692,26 @@ static cpBool handle_collision(cpArbiter *arb, int type)
cpVect norm1 = cpArbiterGetNormal(arb);
cpVect vel1 = cpArbiterGetSurfaceVelocity(arb);
/*
switch (type) {
case CTYPE_BEGIN:
for (int i = 0; i < arrlen(go->shape_cbs); i++)
if (go->shape_cbs[i].shape == pshape1)
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2, arb);
if (go->cbs.begin.obj)
if (!JS_IsNull(go->cbs.begin.obj))
duk_call_phys_cb(norm1, go->cbs.begin, g2, arb);
break;
case CTYPE_SEP:
if (go->cbs.separate.obj)
if (!JS_IsNull(go->cbs.separate.obj))
duk_call_phys_cb(norm1, go->cbs.separate, g2, arb);
break;
}
*/
return 1;
}

View File

@@ -10,17 +10,5 @@
#define PI 3.14159265358979323846264338327950288f
#define DEG2RADS 0.0174532925199432957692369076848861271344287188854172545609719144f
#define RAD2DEGS 57.2958f
#define MSAA_SAMPLES 2
/* S7 Scheme defines */
#define INITIAL_HEAP_SIZE 4096
#define INITIAL_STACK_SIZE 4096
#define DEFAULT_BIGNUM_PRECISION 128
#define WITH_PURE_S7 0
#define WITH_SYSTEM_EXTRAS 0
#define WITH_C_LOADER 0
#define WITH_NUMBER_SEPARATOR 1
#endif

View File

@@ -26,6 +26,7 @@
#include "debugdraw.h"
#include "stb_ds.h"
#include <ftw.h>
#include <assert.h>
#include "miniaudio.h"
@@ -276,6 +277,11 @@ JSValue duk_nuke(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
if (JS_IsString(argv[1]))
str = JS_ToCString(js,argv[1]);
else {
JSValue tostr = JS_ToString(js,argv[1]);
str = JS_ToCString(js,argv[1]);
JS_FreeValue(js,tostr);
}
struct nk_rect rect = nk_rect(0,0,0,0);
JSValue ret = JS_NULL;
@@ -375,34 +381,46 @@ JSValue duk_win_make(JSContext *js, JSValueConst this, int argc, JSValueConst *a
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
{
static_assert(sizeof(tsReal)*2 == sizeof(cpVect));
tsBSpline spline;
int n = js_arrlen(argv[4]);
int d = js2int(argv[2]);
cpVect points[n*d];
int d = js2int(argv[2]); /* dimensions */
int degrees = js2int(argv[1]);
int type = js2int(argv[3]);
JSValue ctrl_pts = argv[4];
int n = js_arrlen(ctrl_pts);
size_t nsamples = js2int(argv[5]);
cpVect points[n];
tsStatus status;
ts_bspline_new(n, d, js2int(argv[1]), js2int(argv[3]), &spline, &status);
ts_bspline_new(n, d, degrees, type, &spline, &status);
if (status.code)
YughCritical("Spline creation error %d: %s", status.code, status.message);
for (int i = 0; i < n; i++)
points[i] = js2vec2(JS_GetPropertyUint32(js, argv[4], i));
points[i] = js2vec2(JS_GetPropertyUint32(js, ctrl_pts, i));
ts_bspline_set_control_points(&spline, points, NULL);
ts_bspline_set_control_points(&spline, (tsReal*)points, &status);
size_t nsamples = js2int(argv[5]);
if (status.code)
YughCritical("Spline creation error %d: %s", status.code, status.message);
cpVect samples[nsamples];
static_assert(sizeof(tsReal)*2 == sizeof(cpVect));
size_t rsamples;
ts_bspline_sample(&spline, nsamples, &samples, &rsamples, NULL);
/* TODO: This does not work with Clang/GCC due to UB */
ts_bspline_sample(&spline, nsamples, (tsReal**)&samples, &rsamples, &status);
if (status.code)
YughCritical("Spline creation error %d: %s", status.code, status.message);
JSValue arr = JS_NewArray(js);
for (int i = 0; i < nsamples; i++) {
JSValue psample;
JSValue psample = JS_NewArray(js);
JS_SetPropertyUint32(js, psample, 0, float2js(samples[i].x));
JS_SetPropertyUint32(js, psample, 1, float2js(samples[i].y));
JS_SetPropertyUint32(js, arr, i, psample);
@@ -943,7 +961,9 @@ JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValue
{
int cmd = js2int(argv[0]);
int go = js2int(argv[3]);
struct callee c = {argv[1], argv[2]};
struct callee c;
c.fn = argv[1];
c.obj = argv[2];
switch(cmd) {
case 0:
@@ -1237,14 +1257,14 @@ JSValue duk_cmd_box2d(JSContext *js, JSValueConst this, int argc, JSValueConst *
JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
{
int go = js2int(argv[0]);
int go = js2int(argv[0]);
double radius = js2number(argv[1]);
struct phys2d_circle *circle = Make2DCircle(go);
circle->radius = radius;
circle->offset = js2vec2(argv[2]);
struct phys2d_circle *circle = Make2DCircle(go);
circle->radius = radius;
circle->offset = js2vec2(argv[2]);
phys2d_applycircle(circle);
phys2d_applycircle(circle);
JSValue circleval = JS_NewObject(js);
JS_SetPropertyStr(js, circleval, "id", ptr2js(circle));
@@ -1306,8 +1326,6 @@ JSValue duk_make_edge2d(JSContext *js, JSValueConst this, int argc, JSValueConst
int go = js2int(argv[0]);
struct phys2d_edge *edge = Make2DEdge(go);
int arridx = 1;
int n = js_arrlen(argv[1]);
cpVect points[n];

View File

@@ -96,12 +96,14 @@ void go_shape_apply(cpBody *body, cpShape *shape, struct gameobject *go)
cpShapeSetFriction(shape, go->f);
cpShapeSetElasticity(shape, go->e);
cpShapeSetCollisionType(shape, go2id(go));
cpShapeFilter filter;
/* cpShapeFilter filter;
filter.group = go2id(go);
filter.categories = 1<<go->layer;
filter.mask = category_masks[go->layer];
cpShapeSetFilter(shape, filter);
*/
}
void go_shape_moi(cpBody *body, cpShape *shape, struct gameobject *go)