stability

This commit is contained in:
2023-05-29 15:47:30 +00:00
parent 591f48c703
commit 9cb53b04af
16 changed files with 248 additions and 159 deletions

View File

@@ -164,6 +164,8 @@ void phys2d_init()
{
space = cpSpaceNew();
cpSpaceSetSleepTimeThreshold(space, 1);
cpSpaceSetCollisionSlop(space, 0.01);
cpSpaceSetCollisionBias(space, cpfpow(1.0-0.5, 165.f));
}
void phys2d_set_gravity(cpVect v) {
@@ -613,6 +615,7 @@ void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb) {
JS_SetPropertyStr(js, obj, "sensor", JS_NewBool(js, cpShapeGetSensor(shape2)));
JS_SetPropertyStr(js, obj, "velocity", vec2js(cpArbiterGetSurfaceVelocity(arb)));
JS_SetPropertyStr(js, obj, "pos", vec2js(cpArbiterGetPointA(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,id2go(hit)->ref));

View File

@@ -81,7 +81,6 @@ static struct circle_vertex circle_b[v_amt];
void debug_flush()
{
if (poly_c != 0) {
sg_apply_pipeline(poly_pipe);
sg_apply_bindings(&poly_bind);
@@ -136,7 +135,6 @@ void debug_flush()
sg_draw(0,4,circle_count);
circle_count = 0;
}
}
static sg_shader_uniform_block_desc projection_ubo = {
@@ -586,7 +584,7 @@ void draw_poly(cpVect *points, int n, struct rgba color)
/* Find polygon mesh */
int tric = n - 2;
if (n < 1) return;
if (tric < 1) return;
uint32_t tridxs[tric*3];

View File

@@ -899,7 +899,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
return JS_NULL;
case 83:
draw_edge(js2cpvec2arr(argv[1]), 2, js2color(argv[2]), 1, 0, 0, js2color(argv[2]), 10);
draw_edge(js2cpvec2arr(argv[1]), js_arrlen(argv[1]), js2color(argv[2]), js2number(argv[3]), 0, 0, js2color(argv[2]), 10);
return JS_NULL;
case 84:
@@ -1021,6 +1021,14 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 115:
draw_circle(js2vec2(argv[1]), js2number(argv[2]), js2number(argv[2]), js2color(argv[3]), -1);
break;
case 116:
return str2js(tex_get_path(js2sprite(argv[1])->tex));
case 117:
str = JS_ToCString(js, argv[1]);
ret = JS_NewInt64(js, script_runfile(str));
break;
}
if (str)

View File

@@ -20,7 +20,7 @@ JSRuntime *rt = NULL;
#ifdef DBG
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT
#else
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT | JS_EVAL_FLAG_STRIP
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT | JS_EVAL_FLAG_STRIP
#endif
static int load_prefab(const char *fpath, const struct stat *sb, int typeflag) {
@@ -53,8 +53,10 @@ void script_init() {
num_cache[i] = int2js(i);
}
void script_run(const char *script) {
JS_FreeValue(js, JS_Eval(js, script, strlen(script), "script", JS_EVAL_FLAGS));
void script_run(const char *script, const char *file) {
JSValue obj = JS_Eval(js, script, strlen(script), file, JS_EVAL_FLAGS);
js_print_exception(obj);
JS_FreeValue(js,obj);
}
void compile_script(const char *file) {
@@ -91,20 +93,22 @@ int js_print_exception(JSValue v) {
#ifdef DBG
if (JS_IsException(v)) {
JSValue exception = JS_GetException(js);
/* TODO: Does it need freed if null? */
if (JS_IsNull(exception))
return 0;
JSValue val = JS_GetPropertyStr(js, exception, "stack");
const char *name = JS_ToCString(js, JS_GetPropertyStr(js, exception, "name"));
const char *msg = JS_ToCString(js, JS_GetPropertyStr(js, exception, "message"));
const char *stack = JS_ToCString(js, val);
YughLog(LOG_SCRIPT, LOG_ERROR, "%s :: %s\n%s", name, msg,stack);
const char *name = JS_ToCString(js, JS_GetPropertyStr(js, exception, "name"));
const char *msg = JS_ToCString(js, JS_GetPropertyStr(js, exception, "message"));
const char *stack = JS_ToCString(js, val);
YughLog(LOG_SCRIPT, LOG_ERROR, "%s :: %s\n%s", name, msg,stack);
JS_FreeCString(js, name);
JS_FreeCString(js, msg);
JS_FreeCString(js, stack);
JS_FreeValue(js,val);
JS_FreeValue(js,exception);
JS_FreeCString(js, name);
JS_FreeCString(js, msg);
JS_FreeCString(js, stack);
JS_FreeValue(js,val);
JS_FreeValue(js,exception);
return 1;
}
@@ -112,17 +116,27 @@ int js_print_exception(JSValue v) {
return 0;
}
int script_dofile(const char *file) {
YughInfo("Doing script %s", file);
const char *script = slurp_text(file);
if (!script) {
YughError("Can't find file %s.", file);
return 0;
}
JSValue obj = JS_Eval(js, script, strlen(script), file, JS_EVAL_FLAGS);
js_print_exception(obj);
JS_FreeValue(js, obj);
script_run(script,file);
free(script);
return file_mod_secs(file);
}
int script_runfile(const char *file)
{
const char *script = slurp_text(file);
int bufsize = strlen(script)+50;
char scriptbuffer[bufsize];
snprintf(scriptbuffer,bufsize, "(function(){%s})()", script);
script_run(scriptbuffer,file);
free(script);
return file_mod_secs(file);
}

View File

@@ -18,8 +18,9 @@ extern JSValue num_cache[100];
void js_stacktrace();
void script_startup();
void script_init();
void script_run(const char *script);
void script_run(const char *script, const char *file);
int script_dofile(const char *file);
int script_runfile(const char *file);
void script_update(double dt);
void script_draw();

View File

@@ -19,7 +19,6 @@ static int first = -1;
static sg_pipeline pip_sprite;
static sg_bindings bind_sprite;
static int sprite_c = 0;
int make_sprite(int go) {
struct sprite sprite = {

View File

@@ -156,7 +156,7 @@ char *tex_get_path(struct Texture *tex) {
}
}
return NULL;
return "";
}
struct Texture *texture_loadfromfile(const char *path) {

View File

@@ -61,8 +61,8 @@ struct TextureOptions {
/* Represents an actual texture on the GPU */
struct Texture {
sg_image id; /* ID reference for the GPU memory location of the texture */
int width;
int height;
uint16_t width;
uint16_t height;
unsigned char *data;
struct TextureOptions opts;
struct TexAnim anim;

View File

@@ -73,6 +73,7 @@ void timer_remove(int id) {
struct timer *t = id2timer(id);
if (t->owndata) free(t->data);
t->next = first;
t->on = 0;
first = id;
}

View File

@@ -42,8 +42,8 @@ double physlag = 0;
double updatelag = 0;
double renderMS = 1 / 165.f;
double physMS = 1 / 240.f;
double updateMS = 1 / 60.f;
double physMS = 1 / 165.f;
double updateMS = 1 / 165.f;
static int ed = 1;
static int sim_play = 0;
@@ -234,14 +234,14 @@ int main(int argc, char **args) {
timer_update(elapsed * timescale);
physlag += elapsed;
call_updates(elapsed * timescale);
while (physlag >= physMS) {
// while (physlag >= physMS) {
phys_step = 1;
physlag -= physMS;
phys2d_update(physMS * timescale);
call_physics(physMS * timescale);
if (sim_play == SIM_STEP) sim_pause();
phys_step = 0;
}
// }
}
renderlag += elapsed;