From beee0c50f3cd9919eaf02f873674a44f51e1da62 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 27 Dec 2023 16:34:14 +0000 Subject: [PATCH] fixes --- scripts/base.js | 12 +++++++++--- scripts/components.js | 6 +++--- scripts/editor.js | 3 +++ scripts/entity.js | 9 ++++++++- source/engine/2dphysics.c | 3 +-- 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scripts/base.js b/scripts/base.js index 7d4758d..ca1fbe9 100644 --- a/scripts/base.js +++ b/scripts/base.js @@ -1209,6 +1209,12 @@ Math.nearest = function(n, incr) return Math.round(n/incr)*incr; } +Math.places = function(n,digits) +{ + var div = Math.pow(10,digits); + return Math.round(n*div)/div; +} + Number.hex = function(n) { var s = Math.floor(n).toString(16); @@ -1413,9 +1419,9 @@ var Vector = { rotate(v,angle) { var r = Vector.length(v); - var p = Vector.angle(v) + angle; - p = Math.turn2rad(angle); - return [r*Math.cos(p), r*Math.sin(p)]; + angle += Vector.angle(v); + angle = Math.turn2rad(angle); + return [r*Math.cos(angle), r*Math.sin(angle)]; }, equal(v1, v2, tol) { diff --git a/scripts/components.js b/scripts/components.js index cb57fa5..ddc3968 100644 --- a/scripts/components.js +++ b/scripts/components.js @@ -620,7 +620,7 @@ component.edge2d = Object.copy(collider2d, { /* EDITOR */ gizmo() { - if (this.type === Spline.type.catmull) { + if (this.type === Spline.type.catmull || this.type === -1) { this.spoints().forEach(x => Shape.point(this.gameobject.this2screen(x), 3, Color.teal)); this.cpoints.forEach((x,i) => Debug.numbered_point(this.gameobject.this2screen(x), i)); } else { @@ -643,7 +643,7 @@ component.edge2d = Object.copy(collider2d, { var p = this.cpoints[i]; if (!p) return undefined; - if (Spline.is_catmull(this.type)) + if (Spline.is_catmull(this.type) || this.type === -1) return make_point_obj(this,p); var that = this.gameobject; @@ -691,7 +691,7 @@ component.edge2d = Object.copy(collider2d, { add_node(pos) { pos = this.gameobject.world2this(pos); var idx = 0; - if (Spline.is_catmull(this.type)) { + if (Spline.is_catmull(this.type) || this.type === -1) { if (this.cpoints.length >= 2) idx = cmd(59, pos, this.cpoints, 400); diff --git a/scripts/editor.js b/scripts/editor.js index 2a0f05a..94a00a1 100644 --- a/scripts/editor.js +++ b/scripts/editor.js @@ -609,6 +609,9 @@ editor.inputs.f9 = function() { editor.inputs.release_post = function() { editor.snapshot(); editor.edit_level.check_dirty(); + + /* snap all objects to be pixel perfect */ + editor.edit_level.obj_descend(o => o.pos = o.pos.map(x => Math.round(x))); }; editor.inputs['C-a'] = function() { if (!editor.selectlist.empty) { editor.unselect(); return; } diff --git a/scripts/entity.js b/scripts/entity.js index 835250f..996c102 100644 --- a/scripts/entity.js +++ b/scripts/entity.js @@ -480,9 +480,10 @@ var gameobject = { transform() { var t = {}; t.pos = this.pos; - t.angle = this.angle; + t.angle = Math.places(this.angle,4); t.scale = this.scale; t.scale = t.scale.map((x,i) => x/this.__proto__.scale[i]); + t.scale = t.scale.map(x => Math.places(x,3)); return t; }, @@ -636,6 +637,12 @@ var gameobject = { obj ??= this; Signal.obj_separate(fn,obj,this); }, + + obj_descend(fn) { + fn(this); + for (var o in this.objects) + this.objects[o].obj_descend(fn); + }, } Object.mixin(gameobject,gameobject_impl); diff --git a/source/engine/2dphysics.c b/source/engine/2dphysics.c index a85859d..98cb6f8 100644 --- a/source/engine/2dphysics.c +++ b/source/engine/2dphysics.c @@ -550,8 +550,7 @@ void duk_call_phys_cb(HMM_Vec2 norm, struct callee c, gameobject *hit, cpArbiter struct postphys_cb cb; cb.c = c; cb.send = obj; - script_callee(c, 1, &obj); -// arrput(begins, cb); + arrput(begins, cb); } #define CTYPE_BEGIN 0