scale
This commit is contained in:
parent
885a2fd190
commit
2880badc98
7
Makefile
7
Makefile
|
@ -53,13 +53,18 @@ endif
|
||||||
CPPFLAGS += -ffast-math
|
CPPFLAGS += -ffast-math
|
||||||
|
|
||||||
ifeq ($(DBG),1)
|
ifeq ($(DBG),1)
|
||||||
CPPFLAGS += -g -fsanitize=address
|
CPPFLAGS += -g
|
||||||
INFO += _dbg
|
INFO += _dbg
|
||||||
else
|
else
|
||||||
CPPFLAGS += -DNDEBUG
|
CPPFLAGS += -DNDEBUG
|
||||||
LDFLAGS += -s
|
LDFLAGS += -s
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(LEAK),1)
|
||||||
|
CPPFLAGS += -fsanitize=address
|
||||||
|
INFO += _leak
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(OPT),small)
|
ifeq ($(OPT),small)
|
||||||
CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
|
CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
|
||||||
LDFLAGS += -flto
|
LDFLAGS += -flto
|
||||||
|
|
|
@ -1249,14 +1249,16 @@ Math.snap = function(val, grid) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Math.angledist = function (a1, a2) {
|
Math.angledist = function (a1, a2) {
|
||||||
|
a1 = Math.turn2deg(a1);
|
||||||
|
a2 = Math.turn2deg(a2);
|
||||||
var dist = a2 - a1;
|
var dist = a2 - a1;
|
||||||
var wrap = dist >= 0 ? dist+360 : dist-360;
|
var wrap = dist >= 0 ? dist+360 : dist-360;
|
||||||
wrap %= 360;
|
wrap %= 360;
|
||||||
|
|
||||||
if (Math.abs(dist) < Math.abs(wrap))
|
if (Math.abs(dist) < Math.abs(wrap))
|
||||||
return dist;
|
return Math.deg2turn(dist);
|
||||||
|
|
||||||
return wrap;
|
return Math.deg2turn(wrap);
|
||||||
};
|
};
|
||||||
Math.angledist.doc = "Find the shortest angle between two angles.";
|
Math.angledist.doc = "Find the shortest angle between two angles.";
|
||||||
Math.TAU = Math.PI*2;
|
Math.TAU = Math.PI*2;
|
||||||
|
@ -1266,6 +1268,8 @@ Math.deg2rad = function(x) { return x; };
|
||||||
Math.rad2deg = function(x) { return x; };
|
Math.rad2deg = function(x) { return x; };
|
||||||
Math.turn2rad = function(x) { return x*Math.TAU; };
|
Math.turn2rad = function(x) { return x*Math.TAU; };
|
||||||
Math.rad2turn = function(x) { return x/Math.TAU; };
|
Math.rad2turn = function(x) { return x/Math.TAU; };
|
||||||
|
Math.turn2deg = function(x) { return x*360; };
|
||||||
|
Math.deg2turn = function(x) { return x/360; };
|
||||||
Math.randomint = function(max) { return Math.clamp(Math.floor(Math.random() * max), 0, max-1); };
|
Math.randomint = function(max) { return Math.clamp(Math.floor(Math.random() * max), 0, max-1); };
|
||||||
|
|
||||||
/* BOUNDINGBOXES */
|
/* BOUNDINGBOXES */
|
||||||
|
|
|
@ -103,6 +103,10 @@ component.sprite.impl = {
|
||||||
get color() {return cmd(148,this.id);},
|
get color() {return cmd(148,this.id);},
|
||||||
get pos() { return cmd(111, this.id); },
|
get pos() { return cmd(111, this.id); },
|
||||||
set pos(x) { cmd(37,this.id,x); },
|
set pos(x) { cmd(37,this.id,x); },
|
||||||
|
get angle() { return cmd(217,this.id); },
|
||||||
|
set angle(x) { cmd(218,this.id,x); },
|
||||||
|
get scale() { return cmd(215, this.id); },
|
||||||
|
set scale(x) { cmd(216, this.id, x); },
|
||||||
set layer(x) { cmd(60, this.id, x); },
|
set layer(x) { cmd(60, this.id, x); },
|
||||||
get layer() { return undefined; },
|
get layer() { return undefined; },
|
||||||
emissive(x) { cmd(170, this.id, x); },
|
emissive(x) { cmd(170, this.id, x); },
|
||||||
|
|
|
@ -450,6 +450,7 @@ var editor = {
|
||||||
|
|
||||||
GUI.text(sname, x.screenpos().add([0, 32]), 1, Color.editor.ur);
|
GUI.text(sname, x.screenpos().add([0, 32]), 1, Color.editor.ur);
|
||||||
GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), x.screenpos(), 1, Color.white);
|
GUI.text(x.worldpos().map(function(x) { return Math.round(x); }), x.screenpos(), 1, Color.white);
|
||||||
|
Shape.cross(x.screenpos(), 10, Color.blue);
|
||||||
});
|
});
|
||||||
|
|
||||||
Object.entries(thiso.objects).forEach(function(x) {
|
Object.entries(thiso.objects).forEach(function(x) {
|
||||||
|
@ -1963,26 +1964,6 @@ var entitylistpanel = Object.copy(inputpanel, {
|
||||||
start() {
|
start() {
|
||||||
this.level = editor.edit_level;
|
this.level = editor.edit_level;
|
||||||
},
|
},
|
||||||
|
|
||||||
/* guibody() {
|
|
||||||
Nuke.newline(4);
|
|
||||||
Nuke.label("Object");
|
|
||||||
Nuke.label("Visible");
|
|
||||||
Nuke.label("Selectable");
|
|
||||||
Nuke.label("Selected?");
|
|
||||||
this.level.objects.forEach(function(x) {
|
|
||||||
if (Nuke.button(x.toString())) {
|
|
||||||
editor.selectlist = [];
|
|
||||||
editor.selectlist.push(x);
|
|
||||||
}
|
|
||||||
|
|
||||||
x.visible = Nuke.checkbox(x.visible);
|
|
||||||
x._ed.selectable = Nuke.checkbox(x._ed.selectable);
|
|
||||||
|
|
||||||
if (editor.selectlist.includes(x)) Nuke.label("T"); else Nuke.label("F");
|
|
||||||
});
|
|
||||||
},
|
|
||||||
*/
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var limited_editor = {};
|
var limited_editor = {};
|
||||||
|
|
|
@ -74,8 +74,10 @@ load("scripts/gui.js");
|
||||||
var timer = {
|
var timer = {
|
||||||
update(dt) {
|
update(dt) {
|
||||||
this.remain -= dt;
|
this.remain -= dt;
|
||||||
if (this.remain <= 0)
|
if (this.remain <= 0) {
|
||||||
this.fire();
|
this.fn();
|
||||||
|
this.kill();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
kill() {
|
kill() {
|
||||||
|
@ -86,7 +88,7 @@ var timer = {
|
||||||
var t = Object.create(this);
|
var t = Object.create(this);
|
||||||
t.time = secs;
|
t.time = secs;
|
||||||
t.remain = secs;
|
t.remain = secs;
|
||||||
t.fire = function() { fn(); t.kill(); };
|
t.fn = fn;
|
||||||
Register.update.register(t.update, t);
|
Register.update.register(t.update, t);
|
||||||
return function() { t.kill(); };
|
return function() { t.kill(); };
|
||||||
},
|
},
|
||||||
|
@ -522,7 +524,7 @@ function world_start() {
|
||||||
dirty:false,
|
dirty:false,
|
||||||
};
|
};
|
||||||
Primum.toString = function() { return "Primum"; };
|
Primum.toString = function() { return "Primum"; };
|
||||||
Primum.ur = undefined;
|
Primum.ur = "Primum";
|
||||||
Primum.kill = function() { this.clear(); };
|
Primum.kill = function() { this.clear(); };
|
||||||
gameobject.level = Primum;
|
gameobject.level = Primum;
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,13 @@ var gameobject_impl = {
|
||||||
|
|
||||||
get scale() {
|
get scale() {
|
||||||
Debug.assert(this.level, `No level set on ${this.toString()}`);
|
Debug.assert(this.level, `No level set on ${this.toString()}`);
|
||||||
return this.gscale().map((x,i) => x/this.level.gscale()[i]);
|
var pscale;
|
||||||
|
if (typeof this.__proto__.scale === 'object')
|
||||||
|
pscale = this.__proto__.scale;
|
||||||
|
else
|
||||||
|
pscale = [1,1,1];
|
||||||
|
|
||||||
|
return this.gscale().map((x,i) => x/(this.level.gscale()[i]*pscale[i]));
|
||||||
},
|
},
|
||||||
|
|
||||||
set scale(x) {
|
set scale(x) {
|
||||||
|
@ -109,7 +115,7 @@ var gameobject_impl = {
|
||||||
obj.pos = obj.pos.map((x,i)=>x*pct[i]);
|
obj.pos = obj.pos.map((x,i)=>x*pct[i]);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
get draw_layer() { return cmd(171, this.body); },
|
get draw_layer() { return cmd(171, this.body); },
|
||||||
set draw_layer(x) { cmd(172, this.body, x); },
|
set draw_layer(x) { cmd(172, this.body, x); },
|
||||||
set layer(x) { cmd(75,this.body,x); },
|
set layer(x) { cmd(75,this.body,x); },
|
||||||
|
@ -207,7 +213,7 @@ var gameobject = {
|
||||||
},
|
},
|
||||||
|
|
||||||
delay(fn, seconds) {
|
delay(fn, seconds) {
|
||||||
var t = timer.delay(fn.bind(this), seconds, false);
|
var t = timer.delay(fn.bind(this), seconds);
|
||||||
this.timers.push(t);
|
this.timers.push(t);
|
||||||
return t;
|
return t;
|
||||||
},
|
},
|
||||||
|
@ -275,8 +281,11 @@ var gameobject = {
|
||||||
/* Reparent 'this' to be 'parent's child */
|
/* Reparent 'this' to be 'parent's child */
|
||||||
reparent(parent) {
|
reparent(parent) {
|
||||||
Debug.assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
|
Debug.assert(parent, `Tried to reparent ${this.toString()} to nothing.`);
|
||||||
if (this.level === parent)
|
if (this.level === parent) {
|
||||||
|
console.warn("not reparenting ...");
|
||||||
|
console.warn(`${this.level} is the same as ${parent}`);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.level?.remove_obj(this);
|
this.level?.remove_obj(this);
|
||||||
|
|
||||||
|
@ -453,6 +462,7 @@ var gameobject = {
|
||||||
|
|
||||||
delete d.pos;
|
delete d.pos;
|
||||||
delete d.angle;
|
delete d.angle;
|
||||||
|
delete d.scale;
|
||||||
delete d.velocity;
|
delete d.velocity;
|
||||||
delete d.angularvelocity;
|
delete d.angularvelocity;
|
||||||
return d;
|
return d;
|
||||||
|
@ -547,6 +557,7 @@ var gameobject = {
|
||||||
};
|
};
|
||||||
|
|
||||||
obj.ur = this.toString();
|
obj.ur = this.toString();
|
||||||
|
obj.level = undefined;
|
||||||
|
|
||||||
obj.reparent(level);
|
obj.reparent(level);
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,6 @@ void set_cat_mask(int cat, unsigned int mask) { category_masks[cat] = mask; }
|
||||||
|
|
||||||
cpTransform m3_to_cpt(HMM_Mat3 m)
|
cpTransform m3_to_cpt(HMM_Mat3 m)
|
||||||
{
|
{
|
||||||
|
|
||||||
cpTransform t;
|
cpTransform t;
|
||||||
t.a = m.Columns[0].x;
|
t.a = m.Columns[0].x;
|
||||||
t.b = m.Columns[0].y;
|
t.b = m.Columns[0].y;
|
||||||
|
@ -306,7 +305,8 @@ void phys2d_applypoly(struct phys2d_poly *poly) {
|
||||||
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));
|
// cpTransform T = m3_to_cpt(transform2d2mat(poly->t));
|
||||||
cpPolyShapeSetVerts(poly->shape.shape, arrlen(poly->points), (cpVect*)poly->points, cpTransformIdentity);
|
cpTransform T = m3_to_cpt(transform2d2mat(poly->shape.go->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));
|
||||||
}
|
}
|
||||||
|
@ -320,7 +320,7 @@ void phys2d_dbgdrawpoly(struct phys2d_poly *poly) {
|
||||||
HMM_Vec2 points[n+1];
|
HMM_Vec2 points[n+1];
|
||||||
HMM_Mat3 rt = t_go2world(shape2go(poly->shape.shape));
|
HMM_Mat3 rt = t_go2world(shape2go(poly->shape.shape));
|
||||||
for (int i = 0; i < n; i++)
|
for (int i = 0; i < n; i++)
|
||||||
points[i] = mat_t_pos(rt, (HMM_Vec2)cpPolyShapeGetVert(poly->shape.shape, i));
|
points[i] = (HMM_Vec2)cpPolyShapeGetVert(poly->shape.shape, i);
|
||||||
|
|
||||||
points[n] = points[0];
|
points[n] = points[0];
|
||||||
|
|
||||||
|
|
|
@ -129,17 +129,17 @@ static void velocityFn(cpBody *body, cpVect gravity, cpFloat damping, cpFloat dt
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpFloat d = isnan(go->damping) ? damping : d;
|
cpFloat d = isfinite(go->damping) ? go->damping : damping;
|
||||||
cpVect g = gravity;
|
cpVect g = gravity;
|
||||||
if (isfinite(go->gravity.x) && isfinite(go->gravity.y))
|
if (isfinite(go->gravity.x) && isfinite(go->gravity.y))
|
||||||
g = go->gravity.cp;
|
g = go->gravity.cp;
|
||||||
|
|
||||||
cpBodyUpdateVelocity(body,g,d,dt*go->timescale);
|
cpBodyUpdateVelocity(body,g,d,dt*go->timescale);
|
||||||
|
|
||||||
if (!isinf(go->maxvelocity))
|
if (isfinite(go->maxvelocity))
|
||||||
cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity));
|
cpBodySetVelocity(body, cpvclamp(cpBodyGetVelocity(body), go->maxvelocity));
|
||||||
|
|
||||||
if (!isinf(go->maxangularvelocity)) {
|
if (isfinite(go->maxangularvelocity)) {
|
||||||
float av = cpBodyGetAngularVelocity(body);
|
float av = cpBodyGetAngularVelocity(body);
|
||||||
if (fabs(av) > go->maxangularvelocity)
|
if (fabs(av) > go->maxangularvelocity)
|
||||||
cpBodySetAngularVelocity(body, copysignf(go->maxangularvelocity, av));
|
cpBodySetAngularVelocity(body, copysignf(go->maxangularvelocity, av));
|
||||||
|
|
|
@ -1354,6 +1354,18 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
||||||
case 214:
|
case 214:
|
||||||
ret = int2js(go_count());
|
ret = int2js(go_count());
|
||||||
break;
|
break;
|
||||||
|
case 215:
|
||||||
|
ret = vec2js(js2sprite(argv[1])->t.scale);
|
||||||
|
break;
|
||||||
|
case 216:
|
||||||
|
js2sprite(argv[1])->t.scale = js2vec2(argv[2]);
|
||||||
|
break;
|
||||||
|
case 217:
|
||||||
|
ret = num2js(js2sprite(argv[1])->t.angle);
|
||||||
|
break;
|
||||||
|
case 218:
|
||||||
|
js2sprite(argv[1])->t.angle = js2number(argv[2]);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str)
|
if (str)
|
||||||
|
|
Loading…
Reference in a new issue