fix play crash

This commit is contained in:
John Alanbrook 2023-12-27 13:04:18 +00:00
parent 2880badc98
commit 1b4a36f398
7 changed files with 27 additions and 39 deletions

View file

@ -407,9 +407,7 @@ Object.isAccessor = function(obj, prop)
Object.mergekey = function(o1,o2,k) Object.mergekey = function(o1,o2,k)
{ {
if (!o2) return; if (!o2) return;
if (Object.isAccessor(o2,k)) if (typeof o2[k] === 'object') {
Object.defineProperty(o1, k, Object.getOwnPropertyDescriptor(o2,k));
else if (typeof o2[k] === 'object') {
if (Array.isArray(o2[k])) if (Array.isArray(o2[k]))
o1[k] = deep_copy(o2[k]); o1[k] = deep_copy(o2[k]);
else { else {
@ -420,7 +418,8 @@ Object.mergekey = function(o1,o2,k)
o1[k] = o2[k]; o1[k] = o2[k];
} }
} else } else
o1[k] = o2[k]; Object.defineProperty(o1, k, Object.getOwnPropertyDescriptor(o2,k));
// o1[k] = o2[k];
} }
/* Same as merge from Ruby */ /* Same as merge from Ruby */
@ -438,6 +437,8 @@ Object.totalmerge = function(target, ...objs)
for (var obj of objs) for (var obj of objs)
for (var key in obj) for (var key in obj)
Object.mergekey(target,obj,key); Object.mergekey(target,obj,key);
return target;
} }
/* Returns a new object with undefined, null, and empty values removed. */ /* Returns a new object with undefined, null, and empty values removed. */

View file

@ -20,8 +20,6 @@ function assign_impl(obj, impl)
Object.mixin(obj, impl); Object.mixin(obj, impl);
if (obj.sync) obj.sync();
for (var key in tmp) for (var key in tmp)
obj[key] = tmp[key]; obj[key] = tmp[key];
} }
@ -53,7 +51,6 @@ var component = {
var nc = Object.create(this); var nc = Object.create(this);
nc.gameobject = go; nc.gameobject = go;
Object.assign(nc, this._enghook(go.body)); Object.assign(nc, this._enghook(go.body));
nc.sync();
assign_impl(nc,this.impl); assign_impl(nc,this.impl);
Object.hide(nc, ...this.hides); Object.hide(nc, ...this.hides);
nc.post(); nc.post();
@ -504,7 +501,7 @@ component.polygon2d.impl = Object.mix(collider2d.impl, {
var polygon2d = component.polygon2d; var polygon2d = component.polygon2d;
polygon2d.inputs = {}; polygon2d.inputs = {};
polygon2d.inputs.post = function() { this.sync(); }; //polygon2d.inputs.post = function() { this.sync(); };
polygon2d.inputs.f10 = function() { polygon2d.inputs.f10 = function() {
this.points = sortpointsccw(this.points); this.points = sortpointsccw(this.points);
}; };
@ -587,7 +584,7 @@ component.edge2d = Object.copy(collider2d, {
setpoints(points) { setpoints(points) {
this.cpoints = points; this.cpoints = points;
this.sync(); // this.sync();
}, },
post() { post() {
@ -747,7 +744,7 @@ component.edge2d.impl = Object.mix({
var bucket = component.edge2d; var bucket = component.edge2d;
bucket.spoints.doc = "Returns the controls points after modifiers are applied, such as it being hollow or mirrored on its axises."; bucket.spoints.doc = "Returns the controls points after modifiers are applied, such as it being hollow or mirrored on its axises.";
bucket.inputs = {}; bucket.inputs = {};
bucket.inputs.post = function() { this.sync(); }; //bucket.inputs.post = function() { this.sync(); };
bucket.inputs.h = function() { this.hollow = !this.hollow; }; bucket.inputs.h = function() { this.hollow = !this.hollow; };
bucket.inputs.h.doc = "Toggle hollow."; bucket.inputs.h.doc = "Toggle hollow.";

View file

@ -193,6 +193,7 @@ var editor = {
Player.players[0].control(limited_editor); Player.players[0].control(limited_editor);
Register.unregister_obj(this); Register.unregister_obj(this);
load("predbg.js"); load("predbg.js");
console.warn(`starting game with ${this.dbg_ur}`);
editor.dbg_play = Primum.spawn(this.dbg_ur); editor.dbg_play = Primum.spawn(this.dbg_ur);
editor.dbg_play.pos = [0,0]; editor.dbg_play.pos = [0,0];
load("debug.js"); load("debug.js");
@ -605,9 +606,6 @@ editor.inputs.f9 = function() {
cmd(173, "capture.bmp", 0, 0, 500, 500); cmd(173, "capture.bmp", 0, 0, 500, 500);
} }
editor.inputs.post = function() {
if (editor.sel_comp && 'sync' in editor.sel_comp) editor.sel_comp.sync();
};
editor.inputs.release_post = function() { editor.inputs.release_post = function() {
editor.snapshot(); editor.snapshot();
editor.edit_level.check_dirty(); editor.edit_level.check_dirty();
@ -839,7 +837,6 @@ editor.inputs['C-s'] = function() {
Object.values(saveobj.objects).forEach(function(x) { x.check_dirty(); }); Object.values(saveobj.objects).forEach(function(x) { x.check_dirty(); });
Game.all_objects(function(x) { Game.all_objects(function(x) {
if (typeof x !== 'object') return; if (typeof x !== 'object') return;
if (!('_ed' in x)) return; if (!('_ed' in x)) return;
@ -871,18 +868,8 @@ editor.inputs['M-t'].doc = "Unlock all objects in current level.";
editor.inputs['C-n'] = function() { editor.inputs['C-n'] = function() {
return; return;
gameobject.make(editor.edit_level);
console.warn("MADE A NEW OBJECT");
/* if (editor.edit_level._ed.dirty) {
Log.info("Level has changed; save before starting a new one.");
editor.openpanel(gen_notify("Level is changed. Are you sure you want to close it?", _ => editor.clear_level()));
return;
}
editor.clear_level();
*/
}; };
editor.inputs['C-n'].doc = "Open a new level."; editor.inputs['C-n'].doc = "Create an empty object.";
editor.inputs['C-o'] = function() { editor.inputs['C-o'] = function() {
editor.openpanel(openlevelpanel); editor.openpanel(openlevelpanel);
@ -1098,7 +1085,6 @@ editor.inputs.mouse.move = function(pos, dpos)
editor.grabselect?.forEach(function(x) { editor.grabselect?.forEach(function(x) {
if (!x) return; if (!x) return;
x.move(Game.camera.dir_view2world(dpos)); x.move(Game.camera.dir_view2world(dpos));
if ('sync' in x)
x.sync(); x.sync();
}); });
@ -1767,7 +1753,6 @@ var objectexplorer = Object.copy(inputpanel, {
// this.obj[key] = this.obj[key]; // this.obj[key] = this.obj[key];
}); });
// Game.all_objects(function(x) { x.sync(); });
return items; return items;
}, },

View file

@ -304,12 +304,15 @@ void phys2d_applypoly(struct phys2d_poly *poly) {
if (arrlen(poly->points) <= 0) return; if (arrlen(poly->points) <= 0) return;
assert(sizeof(poly->points[0]) == sizeof(cpVect)); assert(sizeof(poly->points[0]) == sizeof(cpVect));
struct gameobject *go = poly->shape.go; struct gameobject *go = poly->shape.go;
// cpTransform T = m3_to_cpt(transform2d2mat(poly->t)); transform2d t = go2t(shape2go(poly->shape.shape));
cpTransform T = m3_to_cpt(transform2d2mat(poly->shape.go->t)); t.pos.cp = cpvzero;
t.angle = 0;
cpTransform T = m3_to_cpt(transform2d2mat(t));
cpPolyShapeSetVerts(poly->shape.shape, arrlen(poly->points), (cpVect*)poly->points, T); cpPolyShapeSetVerts(poly->shape.shape, arrlen(poly->points), (cpVect*)poly->points, T);
cpPolyShapeSetRadius(poly->shape.shape, poly->radius); cpPolyShapeSetRadius(poly->shape.shape, poly->radius);
cpSpaceReindexShapesForBody(space, cpShapeGetBody(poly->shape.shape)); cpSpaceReindexShapesForBody(space, cpShapeGetBody(poly->shape.shape));
} }
void phys2d_dbgdrawpoly(struct phys2d_poly *poly) { void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
struct rgba color = shape_color(poly->shape.shape); struct rgba color = shape_color(poly->shape.shape);
struct rgba line_color = color; struct rgba line_color = color;
@ -318,9 +321,11 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
if (arrlen(poly->points) >= 3) { if (arrlen(poly->points) >= 3) {
int n = cpPolyShapeGetCount(poly->shape.shape); int n = cpPolyShapeGetCount(poly->shape.shape);
HMM_Vec2 points[n+1]; HMM_Vec2 points[n+1];
HMM_Mat3 rt = t_go2world(shape2go(poly->shape.shape)); transform2d t = go2t(shape2go(poly->shape.shape));
t.scale = (HMM_Vec2){1,1};
HMM_Mat3 rt = transform2d2mat(t);
for (int i = 0; i < n; i++) for (int i = 0; i < n; i++)
points[i] = (HMM_Vec2)cpPolyShapeGetVert(poly->shape.shape, i); points[i] = mat_t_pos(rt, (HMM_Vec2)cpPolyShapeGetVert(poly->shape.shape, i));
points[n] = points[0]; points[n] = points[0];
@ -520,7 +525,7 @@ static struct postphys_cb *begins = NULL;
void flush_collide_cbs() { void flush_collide_cbs() {
for (int i = 0; i < arrlen(begins); i++) { for (int i = 0; i < arrlen(begins); i++) {
script_callee(begins[i].c, 1, &begins[i].send); script_callee(begins[i].c, 1, &begins[i].send);
JS_FreeValue(js, begins[i].send); // JS_FreeValue(js, begins[i].send);
} }
arrsetlen(begins,0); arrsetlen(begins,0);
@ -545,7 +550,8 @@ void duk_call_phys_cb(HMM_Vec2 norm, struct callee c, gameobject *hit, cpArbiter
struct postphys_cb cb; struct postphys_cb cb;
cb.c = c; cb.c = c;
cb.send = obj; cb.send = obj;
arrput(begins, cb); script_callee(c, 1, &obj);
// arrput(begins, cb);
} }
#define CTYPE_BEGIN 0 #define CTYPE_BEGIN 0

View file

@ -18,7 +18,7 @@ extern struct rgba static_color;
extern struct rgba sleep_color; extern struct rgba sleep_color;
struct phys2d_shape { struct phys2d_shape {
cpShape *shape; cpShape *shape; /* user data is this phys2d_shape */
transform2d t; transform2d t;
gameobject *go; gameobject *go;
void *data; /* The specific subtype; phys2d_circle, etc */ void *data; /* The specific subtype; phys2d_circle, etc */

View file

@ -67,8 +67,8 @@ transform2d go2t(gameobject *go)
t.pos.cp = cpBodyGetPosition(go->body); t.pos.cp = cpBodyGetPosition(go->body);
t.angle = cpBodyGetAngle(go->body); t.angle = cpBodyGetAngle(go->body);
t.scale = go->scale.XY; t.scale = go->scale.XY;
if (isnan(t.scale.X)) t.scale.X = 1; if (!isfinite(t.scale.X)) t.scale.X = 1;
if (isnan(t.scale.Y)) t.scale.Y = 1; if (!isfinite(t.scale.Y)) t.scale.Y = 1;
return t; return t;
} }

View file

@ -44,7 +44,6 @@ struct gameobject {
struct shape_cb *shape_cbs; struct shape_cb *shape_cbs;
JSValue ref; JSValue ref;
HMM_Mat4 world; HMM_Mat4 world;
transform2d t; /* The local transformation of this object */
float drawlayer; float drawlayer;
}; };