fix play crash
This commit is contained in:
parent
2880badc98
commit
1b4a36f398
|
@ -407,9 +407,7 @@ Object.isAccessor = function(obj, prop)
|
|||
Object.mergekey = function(o1,o2,k)
|
||||
{
|
||||
if (!o2) return;
|
||||
if (Object.isAccessor(o2,k))
|
||||
Object.defineProperty(o1, k, Object.getOwnPropertyDescriptor(o2,k));
|
||||
else if (typeof o2[k] === 'object') {
|
||||
if (typeof o2[k] === 'object') {
|
||||
if (Array.isArray(o2[k]))
|
||||
o1[k] = deep_copy(o2[k]);
|
||||
else {
|
||||
|
@ -420,7 +418,8 @@ Object.mergekey = function(o1,o2,k)
|
|||
o1[k] = o2[k];
|
||||
}
|
||||
} else
|
||||
o1[k] = o2[k];
|
||||
Object.defineProperty(o1, k, Object.getOwnPropertyDescriptor(o2,k));
|
||||
// o1[k] = o2[k];
|
||||
}
|
||||
|
||||
/* Same as merge from Ruby */
|
||||
|
@ -438,6 +437,8 @@ Object.totalmerge = function(target, ...objs)
|
|||
for (var obj of objs)
|
||||
for (var key in obj)
|
||||
Object.mergekey(target,obj,key);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
/* Returns a new object with undefined, null, and empty values removed. */
|
||||
|
|
|
@ -20,8 +20,6 @@ function assign_impl(obj, impl)
|
|||
|
||||
Object.mixin(obj, impl);
|
||||
|
||||
if (obj.sync) obj.sync();
|
||||
|
||||
for (var key in tmp)
|
||||
obj[key] = tmp[key];
|
||||
}
|
||||
|
@ -53,7 +51,6 @@ var component = {
|
|||
var nc = Object.create(this);
|
||||
nc.gameobject = go;
|
||||
Object.assign(nc, this._enghook(go.body));
|
||||
nc.sync();
|
||||
assign_impl(nc,this.impl);
|
||||
Object.hide(nc, ...this.hides);
|
||||
nc.post();
|
||||
|
@ -497,14 +494,14 @@ component.polygon2d = Object.copy(collider2d, {
|
|||
});
|
||||
|
||||
component.polygon2d.impl = Object.mix(collider2d.impl, {
|
||||
sync() { cmd_poly2d(0, this.id, this.spoints()); },
|
||||
sync() { cmd_poly2d(0, this.id, this.spoints());},
|
||||
query() { return cmd(80, this.shape); },
|
||||
});
|
||||
|
||||
var polygon2d = component.polygon2d;
|
||||
|
||||
polygon2d.inputs = {};
|
||||
polygon2d.inputs.post = function() { this.sync(); };
|
||||
//polygon2d.inputs.post = function() { this.sync(); };
|
||||
polygon2d.inputs.f10 = function() {
|
||||
this.points = sortpointsccw(this.points);
|
||||
};
|
||||
|
@ -587,7 +584,7 @@ component.edge2d = Object.copy(collider2d, {
|
|||
|
||||
setpoints(points) {
|
||||
this.cpoints = points;
|
||||
this.sync();
|
||||
// this.sync();
|
||||
},
|
||||
|
||||
post() {
|
||||
|
@ -747,7 +744,7 @@ component.edge2d.impl = Object.mix({
|
|||
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.inputs = {};
|
||||
bucket.inputs.post = function() { this.sync(); };
|
||||
//bucket.inputs.post = function() { this.sync(); };
|
||||
bucket.inputs.h = function() { this.hollow = !this.hollow; };
|
||||
bucket.inputs.h.doc = "Toggle hollow.";
|
||||
|
||||
|
|
|
@ -193,6 +193,7 @@ var editor = {
|
|||
Player.players[0].control(limited_editor);
|
||||
Register.unregister_obj(this);
|
||||
load("predbg.js");
|
||||
console.warn(`starting game with ${this.dbg_ur}`);
|
||||
editor.dbg_play = Primum.spawn(this.dbg_ur);
|
||||
editor.dbg_play.pos = [0,0];
|
||||
load("debug.js");
|
||||
|
@ -605,9 +606,6 @@ editor.inputs.f9 = function() {
|
|||
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.snapshot();
|
||||
editor.edit_level.check_dirty();
|
||||
|
@ -839,7 +837,6 @@ editor.inputs['C-s'] = function() {
|
|||
|
||||
Object.values(saveobj.objects).forEach(function(x) { x.check_dirty(); });
|
||||
|
||||
|
||||
Game.all_objects(function(x) {
|
||||
if (typeof x !== 'object') 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() {
|
||||
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.openpanel(openlevelpanel);
|
||||
|
@ -1098,8 +1085,7 @@ editor.inputs.mouse.move = function(pos, dpos)
|
|||
editor.grabselect?.forEach(function(x) {
|
||||
if (!x) return;
|
||||
x.move(Game.camera.dir_view2world(dpos));
|
||||
if ('sync' in x)
|
||||
x.sync();
|
||||
x.sync();
|
||||
});
|
||||
|
||||
var relpos = Mouse.worldpos.sub(editor.cursor);
|
||||
|
@ -1767,7 +1753,6 @@ var objectexplorer = Object.copy(inputpanel, {
|
|||
// this.obj[key] = this.obj[key];
|
||||
});
|
||||
|
||||
// Game.all_objects(function(x) { x.sync(); });
|
||||
return items;
|
||||
},
|
||||
|
||||
|
|
|
@ -304,12 +304,15 @@ void phys2d_applypoly(struct phys2d_poly *poly) {
|
|||
if (arrlen(poly->points) <= 0) return;
|
||||
assert(sizeof(poly->points[0]) == sizeof(cpVect));
|
||||
struct gameobject *go = poly->shape.go;
|
||||
// cpTransform T = m3_to_cpt(transform2d2mat(poly->t));
|
||||
cpTransform T = m3_to_cpt(transform2d2mat(poly->shape.go->t));
|
||||
transform2d t = go2t(shape2go(poly->shape.shape));
|
||||
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);
|
||||
cpPolyShapeSetRadius(poly->shape.shape, poly->radius);
|
||||
cpSpaceReindexShapesForBody(space, cpShapeGetBody(poly->shape.shape));
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
|
||||
struct rgba color = shape_color(poly->shape.shape);
|
||||
struct rgba line_color = color;
|
||||
|
@ -318,9 +321,11 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
|
|||
if (arrlen(poly->points) >= 3) {
|
||||
int n = cpPolyShapeGetCount(poly->shape.shape);
|
||||
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++)
|
||||
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];
|
||||
|
||||
|
@ -520,7 +525,7 @@ static struct postphys_cb *begins = NULL;
|
|||
void flush_collide_cbs() {
|
||||
for (int i = 0; i < arrlen(begins); i++) {
|
||||
script_callee(begins[i].c, 1, &begins[i].send);
|
||||
JS_FreeValue(js, begins[i].send);
|
||||
// JS_FreeValue(js, begins[i].send);
|
||||
}
|
||||
|
||||
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;
|
||||
cb.c = c;
|
||||
cb.send = obj;
|
||||
arrput(begins, cb);
|
||||
script_callee(c, 1, &obj);
|
||||
// arrput(begins, cb);
|
||||
}
|
||||
|
||||
#define CTYPE_BEGIN 0
|
||||
|
|
|
@ -18,7 +18,7 @@ extern struct rgba static_color;
|
|||
extern struct rgba sleep_color;
|
||||
|
||||
struct phys2d_shape {
|
||||
cpShape *shape;
|
||||
cpShape *shape; /* user data is this phys2d_shape */
|
||||
transform2d t;
|
||||
gameobject *go;
|
||||
void *data; /* The specific subtype; phys2d_circle, etc */
|
||||
|
|
|
@ -67,8 +67,8 @@ transform2d go2t(gameobject *go)
|
|||
t.pos.cp = cpBodyGetPosition(go->body);
|
||||
t.angle = cpBodyGetAngle(go->body);
|
||||
t.scale = go->scale.XY;
|
||||
if (isnan(t.scale.X)) t.scale.X = 1;
|
||||
if (isnan(t.scale.Y)) t.scale.Y = 1;
|
||||
if (!isfinite(t.scale.X)) t.scale.X = 1;
|
||||
if (!isfinite(t.scale.Y)) t.scale.Y = 1;
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,6 @@ struct gameobject {
|
|||
struct shape_cb *shape_cbs;
|
||||
JSValue ref;
|
||||
HMM_Mat4 world;
|
||||
transform2d t; /* The local transformation of this object */
|
||||
float drawlayer;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue