fix compilation bugs; add bignum
This commit is contained in:
parent
9fb36f5df3
commit
d9f6dd5e56
|
@ -52,7 +52,7 @@ prefix=/usr/local
|
||||||
# use address sanitizer
|
# use address sanitizer
|
||||||
#CONFIG_ASAN=y
|
#CONFIG_ASAN=y
|
||||||
# include the code for BigInt/BigFloat/BigDecimal and math mode
|
# include the code for BigInt/BigFloat/BigDecimal and math mode
|
||||||
#CONFIG_BIGNUM=y
|
CONFIG_BIGNUM=y
|
||||||
|
|
||||||
OBJDIR=.obj
|
OBJDIR=.obj
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
"use math";
|
||||||
var files = {};
|
var files = {};
|
||||||
function load(file) {
|
function load(file) {
|
||||||
var modtime = cmd(0, file);
|
var modtime = cmd(0, file);
|
||||||
|
|
|
@ -57,18 +57,9 @@ cpShape *phys2d_query_pos(cpVect pos) {
|
||||||
return find;
|
return find;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sort_ids(int *a, int *b)
|
gameobject **clean_ids(gameobject **ids)
|
||||||
{
|
{
|
||||||
if (*a == *b) return 0;
|
gameobject *curid = NULL;
|
||||||
if (*a < *b) return -1;
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
gameobject *clean_ids(int *ids)
|
|
||||||
{
|
|
||||||
qsort(ids, sizeof(*ids), arrlen(ids), sort_ids);
|
|
||||||
|
|
||||||
int curid = -1;
|
|
||||||
for (int i = arrlen(ids)-1; i >= 0; i--)
|
for (int i = arrlen(ids)-1; i >= 0; i--)
|
||||||
if (ids[i] == curid)
|
if (ids[i] == curid)
|
||||||
arrdelswap(ids, i);
|
arrdelswap(ids, i);
|
||||||
|
@ -78,7 +69,7 @@ gameobject *clean_ids(int *ids)
|
||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
void querylist(cpShape *shape, cpContactPointSet *points, int *ids) { arrput(ids,shape2go(shape)); }
|
void querylist(cpShape *shape, cpContactPointSet *points, gameobject **ids) { arrput(ids,shape2go(shape)); }
|
||||||
|
|
||||||
typedef struct querybox {
|
typedef struct querybox {
|
||||||
cpBB bb;
|
cpBB bb;
|
||||||
|
@ -184,7 +175,7 @@ void init_phys2dshape(struct phys2d_shape *shape, gameobject *go, void *data) {
|
||||||
shape->go = go;
|
shape->go = go;
|
||||||
shape->data = data;
|
shape->data = data;
|
||||||
go_shape_apply(go->body, shape->shape, go);
|
go_shape_apply(go->body, shape->shape, go);
|
||||||
cpShapeSetCollisionType(shape->shape, go);
|
cpShapeSetCollisionType(shape->shape, (int)go);
|
||||||
cpShapeSetUserData(shape->shape, shape);
|
cpShapeSetUserData(shape->shape, shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +557,7 @@ void duk_call_phys_cb(HMM_Vec2 norm, struct callee c, gameobject *hit, cpArbiter
|
||||||
|
|
||||||
JSValue obj = JS_NewObject(js);
|
JSValue obj = JS_NewObject(js);
|
||||||
JS_SetPropertyStr(js, obj, "normal", vec2js(norm));
|
JS_SetPropertyStr(js, obj, "normal", vec2js(norm));
|
||||||
JS_SetPropertyStr(js, obj, "hit", JS_NewInt32(js, hit));
|
JS_SetPropertyStr(js, obj, "hit", hit->ref);
|
||||||
JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2)));
|
JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2)));
|
||||||
HMM_Vec2 srfv;
|
HMM_Vec2 srfv;
|
||||||
srfv.cp = cpArbiterGetSurfaceVelocity(arb);
|
srfv.cp = cpArbiterGetSurfaceVelocity(arb);
|
||||||
|
@ -574,7 +565,6 @@ void duk_call_phys_cb(HMM_Vec2 norm, struct callee c, gameobject *hit, cpArbiter
|
||||||
// srfv.cp = cpArbiterGetPointA(arb,0);
|
// srfv.cp = cpArbiterGetPointA(arb,0);
|
||||||
// JS_SetPropertyStr(js, obj, "pos", vec2js(srfv));
|
// JS_SetPropertyStr(js, obj, "pos", vec2js(srfv));
|
||||||
// JS_SetPropertyStr(js,obj,"depth", num2js(cpArbiterGetDepth(arb,0)));
|
// JS_SetPropertyStr(js,obj,"depth", num2js(cpArbiterGetDepth(arb,0)));
|
||||||
JS_SetPropertyStr(js, obj, "id", JS_NewInt32(js,hit));
|
|
||||||
JS_SetPropertyStr(js,obj,"obj", JS_DupValue(js,hit->ref));
|
JS_SetPropertyStr(js,obj,"obj", JS_DupValue(js,hit->ref));
|
||||||
|
|
||||||
struct postphys_cb cb;
|
struct postphys_cb cb;
|
||||||
|
@ -631,14 +621,14 @@ static cpBool script_phys_cb_separate(cpArbiter *arb, cpSpace *space, void *data
|
||||||
}
|
}
|
||||||
|
|
||||||
void phys2d_rm_go_handlers(gameobject *go) {
|
void phys2d_rm_go_handlers(gameobject *go) {
|
||||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, (int)go);
|
||||||
handler->userData = NULL;
|
handler->userData = NULL;
|
||||||
handler->beginFunc = NULL;
|
handler->beginFunc = NULL;
|
||||||
handler->separateFunc = NULL;
|
handler->separateFunc = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void phys2d_setup_handlers(gameobject *go) {
|
void phys2d_setup_handlers(gameobject *go) {
|
||||||
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, go);
|
cpCollisionHandler *handler = cpSpaceAddWildcardHandler(space, (int)go);
|
||||||
handler->userData = go;
|
handler->userData = go;
|
||||||
handler->beginFunc = script_phys_cb_begin;
|
handler->beginFunc = script_phys_cb_begin;
|
||||||
handler->separateFunc = script_phys_cb_separate;
|
handler->separateFunc = script_phys_cb_separate;
|
||||||
|
|
|
@ -378,7 +378,7 @@ void draw_model(struct model *model, HMM_Mat4 amodel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct drawmodel *make_drawmodel(int go)
|
struct drawmodel *make_drawmodel(gameobject *go)
|
||||||
{
|
{
|
||||||
struct drawmodel *dm = malloc(sizeof(struct drawmodel));
|
struct drawmodel *dm = malloc(sizeof(struct drawmodel));
|
||||||
dm->model = NULL;
|
dm->model = NULL;
|
||||||
|
|
|
@ -55,7 +55,7 @@ void model_init();
|
||||||
void draw_model(struct model *model, HMM_Mat4 amodel);
|
void draw_model(struct model *model, HMM_Mat4 amodel);
|
||||||
void draw_models(struct model *model, struct shader *shader);
|
void draw_models(struct model *model, struct shader *shader);
|
||||||
|
|
||||||
struct drawmodel *make_drawmodel(int go);
|
struct drawmodel *make_drawmodel(gameobject *go);
|
||||||
void draw_drawmodel(struct drawmodel *dm);
|
void draw_drawmodel(struct drawmodel *dm);
|
||||||
void free_drawmodel(struct drawmodel *dm);
|
void free_drawmodel(struct drawmodel *dm);
|
||||||
|
|
||||||
|
|
|
@ -88,10 +88,10 @@ unsigned int editor_cat = 1<<31;
|
||||||
void go_shape_apply(cpBody *body, cpShape *shape, gameobject *go) {
|
void go_shape_apply(cpBody *body, cpShape *shape, gameobject *go) {
|
||||||
cpShapeSetFriction(shape, go->f);
|
cpShapeSetFriction(shape, go->f);
|
||||||
cpShapeSetElasticity(shape, go->e);
|
cpShapeSetElasticity(shape, go->e);
|
||||||
cpShapeSetCollisionType(shape, go);
|
cpShapeSetCollisionType(shape, (int)go);
|
||||||
|
|
||||||
cpShapeFilter filter;
|
cpShapeFilter filter;
|
||||||
filter.group = go;
|
filter.group = (int)go;
|
||||||
filter.categories = 1<<go->layer | editor_cat;
|
filter.categories = 1<<go->layer | editor_cat;
|
||||||
// filter.mask = CP_ALL_CATEGORIES;
|
// filter.mask = CP_ALL_CATEGORIES;
|
||||||
filter.mask = category_masks[go->layer] | editor_cat;
|
filter.mask = category_masks[go->layer] | editor_cat;
|
||||||
|
|
|
@ -74,23 +74,6 @@ void js_setprop_str(JSValue obj, const char *prop, JSValue v)
|
||||||
JS_SetPropertyStr(js, obj, prop, v);
|
JS_SetPropertyStr(js, obj, prop, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
JSValue unix2time(time_t unix)
|
|
||||||
{
|
|
||||||
struct tm *t = localtime(&unix);
|
|
||||||
JSValue o = JS_NewObject(js);
|
|
||||||
js_setprop_str(o, "sec", JS_NewFloat64(js, t->tm_sec));
|
|
||||||
js_setprop_str(o, "min", JS_NewFloat64(js, t->tm_min));
|
|
||||||
js_setprop_str(o, "hour", JS_NewFloat64(js, t->tm_hour));
|
|
||||||
js_setprop_str(o, "day", JS_NewFloat64(js, t->tm_mday));
|
|
||||||
js_setprop_str(o, "mon", JS_NewFloat64(js, t->tm_mon));
|
|
||||||
js_setprop_str(o, "year", JS_NewFloat64(js, t->tm_year+1900));
|
|
||||||
js_setprop_str(o, "weekday", JS_NewFloat64(js, t->tm_wday));
|
|
||||||
js_setprop_str(o, "yday", JS_NewFloat64(js, t->tm_yday));
|
|
||||||
js_setprop_str(o, "dst", JS_NewBool(js, t->tm_isdst));
|
|
||||||
js_setprop_str(o, "unix", JS_NewFloat64(js, unix));
|
|
||||||
return o;
|
|
||||||
}
|
|
||||||
|
|
||||||
JSValue jstzone()
|
JSValue jstzone()
|
||||||
{
|
{
|
||||||
time_t t = time(NULL);
|
time_t t = time(NULL);
|
||||||
|
@ -524,7 +507,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
gameobject_free(js2int(argv[1]));
|
// gameobject_free(js2gameobject(argv[1]));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
|
@ -1344,7 +1327,6 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
dag_set(js2gameobject(argv[1]), js2gameobject(argv[2]));
|
dag_set(js2gameobject(argv[1]), js2gameobject(argv[2]));
|
||||||
break;
|
break;
|
||||||
case 209:
|
case 209:
|
||||||
ret = unix2time(js2number(argv[1]));
|
|
||||||
break;
|
break;
|
||||||
case 210:
|
case 210:
|
||||||
ret = jscurtime();
|
ret = jscurtime();
|
||||||
|
@ -1495,7 +1477,7 @@ JSValue duk_sys_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *ar
|
||||||
return JS_NewBool(js, sim_paused());
|
return JS_NewBool(js, sim_paused());
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
return JS_NewInt64(js, MakeGameobject());
|
return gameobject2js(MakeGameobject());
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
return JS_NewInt64(js, frame_fps());
|
return JS_NewInt64(js, frame_fps());
|
||||||
|
|
|
@ -270,7 +270,7 @@ void free_source(struct sound *s)
|
||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long *src_cb(struct sound *s, float **data)
|
static long src_cb(struct sound *s, float **data)
|
||||||
{
|
{
|
||||||
long needed = BUF_FRAMES/s->timescale;
|
long needed = BUF_FRAMES/s->timescale;
|
||||||
*data = s->data->data+s->frame;
|
*data = s->data->data+s->frame;
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct slice9_vert {
|
||||||
struct rgba color;
|
struct rgba color;
|
||||||
};
|
};
|
||||||
|
|
||||||
int make_sprite(int go) {
|
int make_sprite(gameobject *go) {
|
||||||
struct sprite sprite = {
|
struct sprite sprite = {
|
||||||
.t = t2d_unit,
|
.t = t2d_unit,
|
||||||
.color = color_white,
|
.color = color_white,
|
||||||
|
@ -70,7 +70,7 @@ int make_sprite(int go) {
|
||||||
|
|
||||||
void sprite_delete(int id) {
|
void sprite_delete(int id) {
|
||||||
struct sprite *sp = id2sprite(id);
|
struct sprite *sp = id2sprite(id);
|
||||||
sp->go = -1;
|
sp->go = NULL;
|
||||||
sp->enabled = 0;
|
sp->enabled = 0;
|
||||||
freelist_kill(sprites,id);
|
freelist_kill(sprites,id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ struct sprite {
|
||||||
int next;
|
int next;
|
||||||
};
|
};
|
||||||
|
|
||||||
int make_sprite(int go);
|
int make_sprite(gameobject *go);
|
||||||
struct sprite *id2sprite(int id);
|
struct sprite *id2sprite(int id);
|
||||||
void sprite_delete(int id);
|
void sprite_delete(int id);
|
||||||
void sprite_enabled(int id, int e);
|
void sprite_enabled(int id, int e);
|
||||||
|
|
|
@ -14,7 +14,7 @@ HMM_Vec3 trans_down(const transform3d *trans) { return HMM_QVRot(vDOWN, trans->r
|
||||||
HMM_Vec3 trans_right(const transform3d *trans) { return HMM_QVRot(vRIGHT, trans->rotation); }
|
HMM_Vec3 trans_right(const transform3d *trans) { return HMM_QVRot(vRIGHT, trans->rotation); }
|
||||||
HMM_Vec3 trans_left(const transform3d *trans) { return HMM_QVRot(vLEFT, trans->rotation); }
|
HMM_Vec3 trans_left(const transform3d *trans) { return HMM_QVRot(vLEFT, trans->rotation); }
|
||||||
|
|
||||||
HMM_Vec2 mat_t_pos(HMM_Mat3 m, HMM_Vec2 pos) { return HMM_MulM3V3(m, (HMM_Vec3){pos.x, pos.y, 0}).XY; }
|
HMM_Vec2 mat_t_pos(HMM_Mat3 m, HMM_Vec2 pos) { return HMM_MulM3V3(m, (HMM_Vec3){pos.x, pos.y, 0}).xy; }
|
||||||
|
|
||||||
HMM_Vec2 mat_t_dir(HMM_Mat3 m, HMM_Vec2 dir)
|
HMM_Vec2 mat_t_dir(HMM_Mat3 m, HMM_Vec2 dir)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue