Remove generic cmd from jsffi
This commit is contained in:
parent
9730f8defb
commit
62a34c1e7c
4
Makefile
4
Makefile
|
@ -2,7 +2,7 @@ MAKEFLAGS = --jobs=4
|
|||
UNAME != uname
|
||||
MAKEDIR != pwd
|
||||
# Options
|
||||
# DBG --- build with debugging symbols and logging
|
||||
# NDEBUG --- build with debugging symbols and logging
|
||||
|
||||
CXX:=$(CC)
|
||||
|
||||
|
@ -46,7 +46,7 @@ ifeq ($(CC), emcc)
|
|||
LDFLAGS += #--closure 1
|
||||
CPPFLAGS += -O0
|
||||
OPT = 0
|
||||
DBG = 0
|
||||
NDEBUG = 1
|
||||
AR = emar
|
||||
endif
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
In addition to the removal of a bunch of stuff as seen here.
|
||||
Access prototypes through __proto__ instead of the long-winded Object.getProtoTypeOf.
|
||||
*/
|
||||
|
||||
/*
|
||||
Object.getPrototypeOf = undefined;
|
||||
Object.setPrototypeOf = undefined;
|
||||
|
|
|
@ -1,29 +1,23 @@
|
|||
this.phys = physics.kinematic;
|
||||
this.dir_view2world = function(dir) { return dir.scale(this.realzoom()); };
|
||||
this.view2world = function(pos) { return cmd(137,pos); };
|
||||
this.world2view = function(pos) { return cmd(136,pos); };
|
||||
this.realzoom = function() { return cmd(135); };
|
||||
this.view2world = function(pos) { return render.view2world(pos); };
|
||||
this.world2view = function(pos) { return render.world2view(pos); };
|
||||
this.realzoom = function() { return render.get_zoom(); };
|
||||
|
||||
this.right = function()
|
||||
{
|
||||
return this.pos.x + (window.rendersize.x/2);
|
||||
}
|
||||
this.right = function() { return this.pos.x + (window.rendersize.x/2); }
|
||||
|
||||
this.left = function()
|
||||
{
|
||||
return this.pos.x - (window.rendersize.x/2);
|
||||
}
|
||||
this.left = function() { return this.pos.x - (window.rendersize.x/2); }
|
||||
|
||||
this.mixin({
|
||||
get zoom() {
|
||||
// var z = game.native.y / window.dimensions.y;
|
||||
return cmd(135);///z;
|
||||
return render.get_zoom(); // /z
|
||||
},
|
||||
|
||||
set zoom(x) {
|
||||
x = Math.clamp(x,0.1,10);
|
||||
// var z = game.native.y / window.dimensions.y;
|
||||
// z *= x;
|
||||
cmd(62,x);
|
||||
render.add_zoom(x);
|
||||
},
|
||||
});
|
|
@ -75,7 +75,7 @@ function json_from_whitelist(whitelist)
|
|||
}
|
||||
}
|
||||
|
||||
Object.mixin(cmd(268,true), {
|
||||
Object.mixin(os.sprite(true), {
|
||||
toJSON:json_from_whitelist([
|
||||
"path",
|
||||
"pos",
|
||||
|
@ -149,29 +149,18 @@ Object.mixin(cmd(268,true), {
|
|||
height() { return this.dimensions().y; },
|
||||
});
|
||||
|
||||
cmd(268,true).make = function(go)
|
||||
os.sprite(true).make = function(go)
|
||||
{
|
||||
var sp = cmd(268);
|
||||
var sp = os.sprite();
|
||||
sp.go = go.body;
|
||||
sp.gameobject = go;
|
||||
return sp;
|
||||
}
|
||||
|
||||
component.sprite = cmd(268,true);
|
||||
component.sprite = os.sprite(true);
|
||||
|
||||
Object.freeze(sprite);
|
||||
|
||||
component.model = Object.copy(component, {
|
||||
path:"",
|
||||
_enghook: make_model,
|
||||
});
|
||||
|
||||
component.model.impl = {
|
||||
set path(x) { cmd(149, this.id, x); },
|
||||
draw() { cmd(150, this.id); },
|
||||
kill() { cmd(213, this.id); },
|
||||
};
|
||||
|
||||
var sprite = component.sprite;
|
||||
|
||||
sprite.doc = {
|
||||
|
@ -224,7 +213,7 @@ var SpriteAnim = {
|
|||
frame.time = 0.05;
|
||||
anim.frames.push(frame);
|
||||
}
|
||||
var times = cmd(224,path);
|
||||
var times = render.gif_times(path);
|
||||
for (var i = 0; i < frames; i++)
|
||||
anim.frames[i].time = times[i]/1000;
|
||||
anim.loop = true;
|
||||
|
@ -319,10 +308,10 @@ var collider2d = Object.copy(component, {
|
|||
kill() {}, /* No killing is necessary - it is done through the gameobject's kill */
|
||||
|
||||
impl: {
|
||||
set sensor(x) { cmd(18,this.shape,x); },
|
||||
get sensor() { return cmd(21,this.shape); },
|
||||
set enabled(x) { cmd(22,this.shape,x); },
|
||||
get enabled() { return cmd(23,this.shape); }
|
||||
set sensor(x) { physics.shape_set_sensor(this.shape,x); },
|
||||
get sensor() { return physics.shape_get_sensor(this.shape); },
|
||||
set enabled(x) { physics.shape_set_enabled(this.shape,x); },
|
||||
get enabled() { return physics.shape_get_enabled(this.shape); }
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -403,7 +392,7 @@ function pointscaler(x) {
|
|||
|
||||
component.polygon2d.impl = Object.mix(collider2d.impl, {
|
||||
sync() { cmd_poly2d(0, this.id, this.spoints());},
|
||||
query() { return cmd(80, this.shape); },
|
||||
query() { return physics.shape_query(this.shape); },
|
||||
grow: pointscaler,
|
||||
});
|
||||
|
||||
|
@ -611,7 +600,7 @@ component.edge2d = Object.copy(collider2d, {
|
|||
var idx = 0;
|
||||
if (Spline.is_catmull(this.type) || this.type === -1) {
|
||||
if (this.points.length >= 2)
|
||||
idx = cmd(59, pos, this.points, 400);
|
||||
idx = physics.closest_point(pos, this.points, 400);
|
||||
|
||||
if (idx === this.points.length)
|
||||
this.points.push(pos);
|
||||
|
@ -620,7 +609,7 @@ component.edge2d = Object.copy(collider2d, {
|
|||
}
|
||||
|
||||
if (Spline.is_bezier(this.type)) {
|
||||
idx = cmd(59, pos, Spline.bezier_nodes(this.points),400);
|
||||
idx = physics.closest_point(pos, Spline.bezier_nodes(this.points),400);
|
||||
|
||||
if (idx < 0) return;
|
||||
|
||||
|
@ -649,7 +638,7 @@ component.edge2d.impl = Object.mix(collider2d.impl, {
|
|||
set thickness(x) {
|
||||
cmd_edge2d(1,this.id,x);
|
||||
},
|
||||
get thickness() { return cmd(112,this.id); },
|
||||
get thickness() { return physics.edge_thickness(this.id); },
|
||||
grow: pointscaler,
|
||||
sync() {
|
||||
var sensor = this.sensor;
|
||||
|
|
|
@ -75,12 +75,6 @@ function assert(op, str)
|
|||
}
|
||||
}
|
||||
|
||||
Debug.Options = { };
|
||||
Debug.Options.Color = {
|
||||
//set trigger(x) { cmd(17,x); },
|
||||
//set debug(x) { cmd(16, x); },
|
||||
};
|
||||
|
||||
var Gizmos = {
|
||||
pick_gameobject_points(worldpos, gameobject, points) {
|
||||
var idx = Math.grab_from_points(worldpos, points.map(gameobject.this2world,gameobject), 25);
|
||||
|
@ -161,6 +155,8 @@ Debug.inputs.f4 = function() {
|
|||
};
|
||||
Debug.inputs.f4.doc = "Toggle drawing gizmos and names of objects.";
|
||||
|
||||
Debug.Options = {};
|
||||
|
||||
Debug.Options.gif = {
|
||||
w: 640, /* Max width */
|
||||
h: 480, /* Max height */
|
||||
|
@ -184,7 +180,7 @@ Debug.Options.gif = {
|
|||
w = h / win;
|
||||
}
|
||||
|
||||
cmd(131, w, h, this.cpf, this.depth);
|
||||
// cmd(131, w, h, this.cpf, this.depth);
|
||||
this.rec = true;
|
||||
this.fps = (1/this.cpf)*100;
|
||||
this.start_time = time.now();
|
||||
|
@ -194,7 +190,7 @@ Debug.Options.gif = {
|
|||
|
||||
stop() {
|
||||
if (!this.rec) return;
|
||||
cmd(132, this.file);
|
||||
// cmd(132, this.file);
|
||||
this.rec = false;
|
||||
},
|
||||
};
|
||||
|
|
|
@ -1551,7 +1551,7 @@ var replpanel = Object.copy(inputpanel, {
|
|||
|
||||
guibody() {
|
||||
this.win.selectable = true;
|
||||
//var log = cmd(84);
|
||||
var log = "";
|
||||
log = log.slice(-5000);
|
||||
return [
|
||||
Mum.text({str:log, anchor:[0,0], offset:[0,-300].sub(this.scrolloffset), selectable: true}),
|
||||
|
|
|
@ -70,7 +70,7 @@ function use(file)
|
|||
var c = io.slurp(file);
|
||||
|
||||
var script = `(function() { ${c} })();`;
|
||||
use.files[file] = cmd(123,file,global,script);
|
||||
use.files[file] = os.eval_env(file,global,script);
|
||||
|
||||
return use.files[file];
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ function eval_env(script, env, file)
|
|||
file ??= "SCRIPT";
|
||||
console.info(`eval ${file}`);
|
||||
script = `(function() { ${script}; }).call(this);\n`;
|
||||
return cmd(123,file,env,script);
|
||||
return os.eval_env(file,env,script);
|
||||
}
|
||||
|
||||
global.check_registers = function(obj)
|
||||
|
@ -437,8 +437,12 @@ global.mixin("scripts/actor.js");
|
|||
global.mixin("scripts/entity.js");
|
||||
|
||||
function world_start() {
|
||||
gameobject.body = make_gameobject();
|
||||
gameobject.body.setref(gameobject);
|
||||
|
||||
console.info("START WORLD");
|
||||
globalThis.world = Object.create(gameobject);
|
||||
gameobject.level = world;
|
||||
world.objects = {};
|
||||
world.check_dirty = function() {};
|
||||
world.namestr = function(){};
|
||||
|
@ -452,9 +456,6 @@ function world_start() {
|
|||
world.kill = function() { this.clear(); };
|
||||
world.phys = 2;
|
||||
|
||||
gameobject.level = world;
|
||||
gameobject.body = make_gameobject();
|
||||
cmd(113,gameobject.body, gameobject);
|
||||
Object.hide(gameobject, 'timescale');
|
||||
var cam = world.spawn("scripts/camera2d.jso");
|
||||
game.view_camera(cam);
|
||||
|
@ -465,7 +466,7 @@ global.mixin("scripts/physics.js");
|
|||
game.view_camera = function(cam)
|
||||
{
|
||||
game.camera = cam;
|
||||
cmd(61, game.camera.body);
|
||||
render.cam_body(game.camera.body);
|
||||
}
|
||||
|
||||
window.title = `Prosperon v${prosperon.version}`;
|
||||
|
|
|
@ -13,12 +13,12 @@ function obj_unique_name(name, obj) {
|
|||
var gameobject_impl = {
|
||||
get pos() {
|
||||
assert(this.master, `Entity ${this.toString()} has no master.`);
|
||||
return this.master.world2this(this.worldpos());
|
||||
return this.master.body.world2this(this.worldpos());
|
||||
},
|
||||
|
||||
set pos(x) {
|
||||
assert(this.master, `Entity ${this.toString()} has no master.`);
|
||||
this.set_worldpos(this.master.this2world(x));
|
||||
this.set_worldpos(this.master.body.this2world(x));
|
||||
},
|
||||
|
||||
get angle() {
|
||||
|
@ -64,12 +64,12 @@ var gameobject_impl = {
|
|||
set warp_layer(x) { this.body.warp_filter = x; },
|
||||
get warp_layer() { return this.body.warp_filter; },
|
||||
|
||||
set mass(x) { set_body(7, this.body, x); },
|
||||
set mass(x) { this.body.mass = x; },
|
||||
get mass() {
|
||||
if (!(this.phys === physics.dynamic))
|
||||
return undefined;
|
||||
|
||||
return q_body(5, this.body);
|
||||
return this.body.mass;
|
||||
},
|
||||
get elasticity() { return this.body.e; },
|
||||
set elasticity(x) { this.body.e = x; },
|
||||
|
@ -77,25 +77,25 @@ var gameobject_impl = {
|
|||
set friction(x) { this.body.f = x; },
|
||||
set timescale(x) { this.body.timescale = x; },
|
||||
get timescale() { return this.body.timescale; },
|
||||
set phys(x) { set_body(1, this.body, x); },
|
||||
get phys() { return q_body(0, this.body); },
|
||||
get velocity() { return q_body(3, this.body); },
|
||||
set velocity(x) { set_body(9, this.body, x); },
|
||||
set phys(x) { this.body.phys = x; },
|
||||
get phys() { return this.body.phys; },
|
||||
get velocity() { return this.body.velocity; },
|
||||
set velocity(x) { this.body.velocity = x; },
|
||||
get damping() { return this.body.damping; },
|
||||
set damping(x) { this.body.damping = x },
|
||||
get angularvelocity() { return Math.rad2turn(q_body(4, this.body)); },
|
||||
set angularvelocity(x) { set_body(8, this.body, Math.turn2rad(x)); },
|
||||
get angularvelocity() { return Math.rad2turn(this.body.angularvelocity); },
|
||||
set angularvelocity(x) { this.body.angularvelocity = Math.turn2rad(x); },
|
||||
get max_velocity() { return this.body.maxvelocity; },
|
||||
set max_velocity(x) { this.body.maxvelocity = x; },
|
||||
get max_angularvelocity() { return this.body.maxangularvelocity; },
|
||||
set max_angularvelocity(x) { this.body.maxangularvelocity = x; },
|
||||
get_moi() { return q_body(6, this.body); },
|
||||
get_moi() { return this.body.moi; },
|
||||
set_moi(x) {
|
||||
if (x <= 0) {
|
||||
console.error("Cannot set moment of inertia to 0 or less.");
|
||||
return;
|
||||
}
|
||||
set_body(13, this.body, x);
|
||||
this.body.moi = x;
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -144,32 +144,32 @@ var gameobject = {
|
|||
},
|
||||
/* pin this object to the to object */
|
||||
pin(to) {
|
||||
var p = cmd(222, this.body, to.body);
|
||||
var p = joint.pin(this.body,to.body);
|
||||
},
|
||||
slide(to, a, b, min, max) {
|
||||
a ??= [0, 0];
|
||||
b ??= [0, 0];
|
||||
min ??= 0;
|
||||
max ??= 50;
|
||||
var p = cmd(229, this.body, to.body, a, b, min, max);
|
||||
var p = joint.slide(this.body, to.body, a, b, min, max);
|
||||
p.max_force = 500;
|
||||
p.break();
|
||||
},
|
||||
pivot(to, piv) {
|
||||
piv ??= this.worldpos();
|
||||
var p = cmd(221, this.body, to.body, piv);
|
||||
var p = joint.pivot(this.body, to.body, piv);
|
||||
},
|
||||
/* groove is on to, from local points a and b, anchored to this at local anchor */
|
||||
groove(to, a, b, anchor) {
|
||||
anchor ??= [0, 0];
|
||||
var p = cmd(228, to.body, this.body, a, b, anchor);
|
||||
var p = joint.groove(to.body, this.body, a, b, anchor);
|
||||
},
|
||||
damped_spring(to, length, stiffness, damping) {
|
||||
length ??= Vector.length(this.worldpos(), to.worldpos());
|
||||
stiffness ??= 1;
|
||||
damping ??= 1;
|
||||
var dc = 2 * Math.sqrt(stiffness * this.mass);
|
||||
var p = cmd(227, this.body, to.body, [0, 0], [0, 0], stiffness, damping * dc);
|
||||
var p = joint.damped_spring(this.body, to.body, [0, 0], [0, 0], stiffness, damping * dc);
|
||||
},
|
||||
damped_rotary_spring(to, angle, stiffness, damping) {
|
||||
angle ??= 0;
|
||||
|
@ -179,23 +179,23 @@ var gameobject = {
|
|||
/* damping = 1 is critical */
|
||||
var dc = 2 * Math.sqrt(stiffness * this.get_moi()); /* critical damping number */
|
||||
/* zeta = actual/critical */
|
||||
var p = cmd(226, this.body, to.body, angle, stiffness, damping * dc);
|
||||
var p = joint.damped_rotary(this.body, to.body, angle, stiffness, damping * dc);
|
||||
},
|
||||
rotary_limit(to, min, max) {
|
||||
var p = cmd(225, this.body, to.body, Math.turn2rad(min), Math.turn2rad(max));
|
||||
var p = joint.rotary(this.body, to.body, Math.turn2rad(min), Math.turn2rad(max));
|
||||
},
|
||||
ratchet(to, ratch) {
|
||||
var phase = this.angle - to.angle;
|
||||
var p = cmd(230, this.body, to.body, phase, Math.turn2rad(ratch));
|
||||
var p = joint.ratchet(this.body, to.body, phase, Math.turn2rad(ratch));
|
||||
},
|
||||
gear(to, ratio) {
|
||||
phase ??= 1;
|
||||
ratio ??= 1;
|
||||
var phase = this.angle - to.angle;
|
||||
var p = cmd(223, this.body, to.body, phase, ratio);
|
||||
var p = joint.gear(this.body, to.body, phase, ratio);
|
||||
},
|
||||
motor(to, rate) {
|
||||
var p = cmd(231, this.body, to.body, rate);
|
||||
var p = joint.motor(this.body, to.body, rate);
|
||||
},
|
||||
|
||||
path_from(o) {
|
||||
|
@ -255,11 +255,13 @@ var gameobject = {
|
|||
},
|
||||
|
||||
set torque(x) { if (!(x >= 0 && x <= Infinity)) return;
|
||||
cmd(153, this.body, x); },
|
||||
gscale() { return cmd(103, this.body); },
|
||||
this.body.torque = x; },
|
||||
|
||||
gscale() { return this.body.scale; },
|
||||
sgscale(x) {
|
||||
if (typeof x === 'number')
|
||||
x = [x, x];
|
||||
|
||||
physics.sgscale(this.body, x)
|
||||
},
|
||||
|
||||
|
@ -270,16 +272,16 @@ var gameobject = {
|
|||
return mat;
|
||||
},
|
||||
|
||||
worldpos() { return q_body(1, this.body); },
|
||||
worldpos() { return this.body.pos; },
|
||||
set_worldpos(x) {
|
||||
var poses = this.objects.map(x => x.pos);
|
||||
set_body(2, this.body, x);
|
||||
this.body.pos = x;
|
||||
this.objects.forEach((o, i) => o.set_worldpos(this.this2world(poses[i])));
|
||||
},
|
||||
screenpos() { return window.world2screen(this.worldpos()); },
|
||||
|
||||
worldangle() { return Math.rad2turn(q_body(2, this.body)); },
|
||||
sworldangle(x) { set_body(0, this.body, Math.turn2rad(x)); },
|
||||
worldangle() { return Math.rad2turn(this.body.angle); },
|
||||
sworldangle(x) { this.body.angle = Math.turn2rad(x); },
|
||||
|
||||
get_ur() {
|
||||
// if (this.ur === 'empty') return undefined;
|
||||
|
@ -331,7 +333,7 @@ var gameobject = {
|
|||
urdiff: {},
|
||||
};
|
||||
|
||||
cmd(113, ent.body, ent); // set the internal obj reference to this obj
|
||||
ent.body.setref(ent); // set the internal obj reference to this obj
|
||||
|
||||
Object.hide(ent, 'ur', 'body', 'components', 'objects', '_ed', 'timers', 'master');
|
||||
if (ent.ur === 'empty') {
|
||||
|
@ -432,18 +434,14 @@ var gameobject = {
|
|||
objects: {},
|
||||
master: undefined,
|
||||
|
||||
pulse(vec) { set_body(4, this.body, vec); },
|
||||
shove(vec) { set_body(12, this.body, vec); },
|
||||
shove_at(vec, at) { set_body(14, this.body, vec, at); },
|
||||
world2this(pos) { return cmd(70, this.body, pos); },
|
||||
this2world(pos) { return cmd(71, this.body, pos); },
|
||||
pulse(vec) { this.body.impulse(vec); },
|
||||
shove(vec) { this.body.force(vec); },
|
||||
shove_at(vec, at) { this.body.force_local(vec,at); },
|
||||
this2screen(pos) { return window.world2screen(this.this2world(pos)); },
|
||||
screen2this(pos) { return this.world2this(window.screen2world(pos)); },
|
||||
dir_world2this(dir) { return cmd(160, this.body, dir); },
|
||||
dir_this2world(dir) { return cmd(161, this.body, dir); },
|
||||
|
||||
alive() { return this.body >= 0; },
|
||||
in_air() { return q_body(7, this.body); },
|
||||
in_air() { return this.body.in_air(); },
|
||||
|
||||
hide() { this.components.forEach(x => x.hide?.());
|
||||
this.objects.forEach(x => x.hide?.()); },
|
||||
|
|
|
@ -13,11 +13,11 @@ var GUI = {
|
|||
|
||||
cursor ??= -1;
|
||||
|
||||
var bb = cmd(118, str, size, wrap);
|
||||
var bb = render.text_size(str, size, wrap);
|
||||
var w = bb.r*2;
|
||||
var h = bb.t*2;
|
||||
|
||||
//ui_text draws with an anchor on top left corner
|
||||
//gui.text draws with an anchor on top left corner
|
||||
var p = pos.slice();
|
||||
p.x -= w * anchor.x;
|
||||
bb.r += (w*anchor.x);
|
||||
|
@ -25,7 +25,7 @@ var GUI = {
|
|||
p.y += h * (1 - anchor.y);
|
||||
bb.t += h*(1-anchor.y);
|
||||
bb.b += h*(1-anchor.y);
|
||||
ui_text(str, p, size, color, wrap, cursor);
|
||||
gui.text(str, p, size, color, wrap, cursor);
|
||||
|
||||
return bb;
|
||||
},
|
||||
|
@ -194,7 +194,7 @@ Mum.text = Mum.extend({
|
|||
var aa = [0,1].sub(params.anchor);
|
||||
var pos = cursor.add(params.wh.scale(aa)).add(params.offset);
|
||||
gui.font_set(params.font);
|
||||
ui_text(params.str, pos, params.font_size, params.color, this.width, params.caret);
|
||||
gui.text(params.str, pos, params.font_size, params.color, this.width, params.caret);
|
||||
},
|
||||
|
||||
update_bb(cursor) {
|
||||
|
@ -202,7 +202,7 @@ Mum.text = Mum.extend({
|
|||
},
|
||||
|
||||
calc_bb(cursor) {
|
||||
var bb = cmd(118,this.str, this.font_size, this.width);
|
||||
var bb = render.text_size(this.str, this.font_size, this.width);
|
||||
this.wh = bbox.towh(bb);
|
||||
var pos = cursor.add(this.wh.scale([0,1].sub(this.anchor))).add(this.offset);
|
||||
this.bb = bbox.move(bb,pos.add([this.wh.x/2,0]));
|
||||
|
|
|
@ -10,28 +10,23 @@ var HIT = {
|
|||
|
||||
*/
|
||||
|
||||
var pq = physics.pos_query;
|
||||
physics.pos_query = function(pos,give) {
|
||||
give ??= 25;
|
||||
pq(pos,give);
|
||||
}
|
||||
|
||||
var bpq = physics.box_point_query;
|
||||
physics.box_point_query = function(box,points) {
|
||||
if (!box || !points) return [];
|
||||
return bpq(box.pos,box.wh,points,points.length)
|
||||
}
|
||||
|
||||
Object.assign(physics, {
|
||||
dynamic: 0,
|
||||
kinematic: 1,
|
||||
static: 2,
|
||||
|
||||
pos_query(pos, give) {
|
||||
give ??= 25;
|
||||
return cmd(44, pos, give);
|
||||
},
|
||||
|
||||
/* Returns a list of body ids that a box collides with */
|
||||
box_query(box) { return cmd(52, box.pos, box.wh); },
|
||||
|
||||
box_point_query(box, points) {
|
||||
if (!box || !points)
|
||||
return [];
|
||||
|
||||
return cmd(86, box.pos, box.wh, points, points.length);
|
||||
},
|
||||
|
||||
shape_query(shape) { return cmd(80,shape); },
|
||||
|
||||
com(pos) {
|
||||
if (!Array.isArray(pos)) return [0,0];
|
||||
return pos.reduce((a,i) => a.add(i)).map(g => g/pos.length);
|
||||
|
@ -65,14 +60,10 @@ for (var i = 0; i < physics.collision.num; i++) {
|
|||
|
||||
physics.collision.sync();
|
||||
|
||||
physics.warp = {};
|
||||
physics.warp.gravity = function() { return cmd(253); }
|
||||
physics.warp.damp = function() { return cmd(254); }
|
||||
|
||||
physics.gravity = physics.warp.gravity();
|
||||
physics.gravity = physics.make_gravity();
|
||||
physics.gravity.mask = [true];
|
||||
physics.gravity.strength = 500;
|
||||
physics.damp = physics.warp.damp();
|
||||
physics.damp = physics.make_damp();
|
||||
physics.damp.mask = [true];
|
||||
|
||||
return {
|
||||
|
|
|
@ -88,15 +88,16 @@ render.arrow = function(start, end, color, wingspan, wingangle) {
|
|||
};
|
||||
|
||||
render.rectangle = function(lowerleft, upperright, color) {
|
||||
var pos = lowerleft.add(upperright).map(x=>x/2);
|
||||
var wh = [upperright.x-lowerleft.x,upperright.y-lowerleft.y];
|
||||
render.box(pos,wh,color);
|
||||
};
|
||||
var points = [lowerleft, lowerleft.add([upperright.x-lowerleft.x,0]), upperright, lowerleft.add([0,upperright.y-lowerleft.y])];
|
||||
render.poly(points, color);
|
||||
};
|
||||
|
||||
render.box = function(pos, wh, color) {
|
||||
color ??= Color.white;
|
||||
cmd(53, pos, wh, color);
|
||||
};
|
||||
var lower = pos.sub(wh.scale(0.5));
|
||||
var upper = pos.add(wh.scale(0.5));
|
||||
render.rectangle(lower,upper,color);
|
||||
};
|
||||
|
||||
render.doc = "Draw shapes in screen space.";
|
||||
render.circle.doc = "Draw a circle at pos, with a given radius and color.";
|
||||
|
|
|
@ -4,7 +4,8 @@ var sound_pref = ['wav', 'flac', 'mp3', 'qoa'];
|
|||
|
||||
audio.sound = {
|
||||
bus: {},
|
||||
samplerate() { return cmd(198); },
|
||||
samplerate: dspsound.samplerate,
|
||||
|
||||
sounds: [], /* array of loaded sound files */
|
||||
play(file, bus) {
|
||||
file = Resources.find_sound(file);
|
||||
|
@ -24,22 +25,16 @@ audio.sound = {
|
|||
},
|
||||
};
|
||||
|
||||
audio.dsp = {
|
||||
mix(to) {
|
||||
var n = cmd(181);
|
||||
audio.dsp = {};
|
||||
Object.assign(audio.dsp, dspsound);
|
||||
|
||||
audio.dsp.mix = function(to) {
|
||||
var n = audio.dsp.mix();
|
||||
if (to) n.plugin(to);
|
||||
return n;
|
||||
},
|
||||
source(path) {
|
||||
return cmd(182,path);
|
||||
},
|
||||
delay(secs,decay) {
|
||||
return cmd(185, secs, decay);
|
||||
},
|
||||
fwd_delay(secs, decay) {
|
||||
return cmd(207,secs,decay);
|
||||
},
|
||||
allpass(secs, decay) {
|
||||
};
|
||||
|
||||
audio.dsp.allpass = function(secs, decay) {
|
||||
var composite = {};
|
||||
var fwd = audio.dsp.fwd_delay(secs,-decay);
|
||||
var fbk = audio.dsp.delay(secs,decay);
|
||||
|
@ -48,44 +43,7 @@ audio.dsp = {
|
|||
composite.unplug = dsp_node.unplug.bind(fbk);
|
||||
fwd.plugin(fbk);
|
||||
return composite;
|
||||
},
|
||||
lpf(f) {
|
||||
return cmd(186,f);
|
||||
},
|
||||
hpf(f) {
|
||||
return cmd(187,f);
|
||||
},
|
||||
mod(path) {
|
||||
return cmd(188,path);
|
||||
},
|
||||
midi(midi,sf) {
|
||||
return cmd(206,midi,sf);
|
||||
},
|
||||
crush(rate, depth) {
|
||||
return cmd(189,rate,depth);
|
||||
},
|
||||
compressor() {
|
||||
return cmd(190);
|
||||
},
|
||||
limiter(ceil) {
|
||||
return cmd(191,ceil);
|
||||
},
|
||||
noise_gate(floor) {
|
||||
return cmd(192,floor);
|
||||
},
|
||||
pitchshift(octaves) {
|
||||
return cmd(200,octaves);
|
||||
},
|
||||
noise() {
|
||||
return cmd(203);
|
||||
},
|
||||
pink() {
|
||||
return cmd(204);
|
||||
},
|
||||
red() {
|
||||
return cmd(205);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
audio.dsp.doc = {
|
||||
delay: "Delays the input by secs, multiplied by decay",
|
||||
|
@ -103,17 +61,16 @@ audio.dsp.doc = {
|
|||
red: "Red noise"
|
||||
};
|
||||
|
||||
Object.mixin(cmd(180).__proto__, {
|
||||
Object.mixin(dspsound.master().__proto__, {
|
||||
get db() { return 20*Math.log10(Math.abs(this.volume)); },
|
||||
set db(x) { x = Math.clamp(x,-100,0); this.volume = Math.pow(10, x/20); },
|
||||
get volume() { return this.gain; },
|
||||
set volume(x) { this.gain = x; },
|
||||
});
|
||||
|
||||
audio.sound.bus.master = cmd(180);
|
||||
audio.sound.bus.master = dspsound.master();
|
||||
|
||||
/*Object.mixin(audio.dsp.source().__proto__, {
|
||||
frames() { return cmd(197,this); },
|
||||
length() { return this.frames()/sound.samplerate(); },
|
||||
time() { return this.frame/sound.samplerate(); },
|
||||
pct() { return this.time()/this.length(); },
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
var Spline = {};
|
||||
Spline.sample_angle = function(type, points, angle) {
|
||||
return spline_cmd(0, type, points[0].length, points, angle);
|
||||
if (type === 0) return spline.catmull(points, angle);
|
||||
else if (type === 1) return spline.bezier(points,angle);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Spline.bezier_loop = function(cp)
|
||||
|
|
|
@ -85,7 +85,7 @@ Resources.texture = {};
|
|||
Resources.texture.dimensions = function(path) { texture.dimensions(path); }
|
||||
|
||||
Resources.gif = {};
|
||||
Resources.gif.frames = function(path) { return cmd(139,path); }
|
||||
Resources.gif.frames = function(path) { return render.gif_frames(path); }
|
||||
|
||||
Resources.replpath = function(str, path)
|
||||
{
|
||||
|
|
|
@ -414,7 +414,7 @@ void draw_drawmodel(struct drawmodel *dm)
|
|||
draw_model(dm->model, rst);
|
||||
}
|
||||
|
||||
void free_drawmodel(struct drawmodel *dm) {
|
||||
void drawmodel_free(struct drawmodel *dm) {
|
||||
int rm;
|
||||
for (int i = 0; i < arrlen(models); i++)
|
||||
if (models[i] == dm) {
|
||||
|
|
|
@ -28,11 +28,11 @@ typedef struct model {
|
|||
} model;
|
||||
|
||||
/* A model with draw information */
|
||||
struct drawmodel {
|
||||
typedef struct drawmodel {
|
||||
struct model *model;
|
||||
HMM_Mat4 amodel;
|
||||
gameobject *go;
|
||||
};
|
||||
} drawmodel;
|
||||
|
||||
typedef struct bone {
|
||||
transform3d t;
|
||||
|
@ -53,7 +53,7 @@ void model_init();
|
|||
struct drawmodel *make_drawmodel(gameobject *go);
|
||||
void draw_drawmodel(struct drawmodel *dm);
|
||||
void model_draw_all();
|
||||
void free_drawmodel(struct drawmodel *dm);
|
||||
void drawmodel_free(struct drawmodel *dm);
|
||||
|
||||
material *material_make();
|
||||
void material_free(material *mat);
|
||||
|
|
|
@ -29,6 +29,7 @@ extern int stdout_lvl;
|
|||
#define YughCritical(msg, ...) mYughLog(0, LOG_PANIC, __LINE__, __FILE__, msg, ##__VA_ARGS__);
|
||||
#else
|
||||
#define YughLog(cat, pri, msg, ...)
|
||||
#define YughSpam(msg,...)
|
||||
#define YughInfo(msg, ...)
|
||||
#define YughWarn(msg, ...)
|
||||
#define YughError(msg, ...)
|
||||
|
|
|
@ -78,6 +78,7 @@ QJSCLASS(warp_damp)
|
|||
QJSCLASS(material)
|
||||
QJSCLASS(mesh)
|
||||
QJSCLASS(window)
|
||||
QJSCLASS(drawmodel)
|
||||
|
||||
/* qjs class colliders and constraints */
|
||||
/* constraint works for all constraints - 2d or 3d */
|
||||
|
@ -128,14 +129,9 @@ JS_SetClassProto(js, js_##TYPE##_id, TYPE##_proto); \
|
|||
(byte & 0x02 ? '1' : '0'), \
|
||||
(byte & 0x01 ? '1' : '0')
|
||||
|
||||
void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); }
|
||||
|
||||
int js2bool(JSValue v) { return JS_ToBool(js, v); }
|
||||
|
||||
JSValue bool2js(int b) { return JS_NewBool(js,b); }
|
||||
|
||||
void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); }
|
||||
|
||||
JSValue gos2ref(gameobject **go)
|
||||
{
|
||||
JSValue array = JS_NewArray(js);
|
||||
|
@ -144,6 +140,7 @@ JSValue gos2ref(gameobject **go)
|
|||
return array;
|
||||
}
|
||||
|
||||
void js_setprop_str(JSValue obj, const char *prop, JSValue v) { JS_SetPropertyStr(js, obj, prop, v); }
|
||||
JSValue js_getpropstr(JSValue v, const char *str)
|
||||
{
|
||||
JSValue p = JS_GetPropertyStr(js,v,str);
|
||||
|
@ -151,6 +148,7 @@ JSValue js_getpropstr(JSValue v, const char *str)
|
|||
return p;
|
||||
}
|
||||
|
||||
void js_setprop_num(JSValue obj, uint32_t i, JSValue v) { JS_SetPropertyUint32(js, obj, i, v); }
|
||||
JSValue js_getpropidx(JSValue v, uint32_t i)
|
||||
{
|
||||
JSValue p = JS_GetPropertyUint32(js, v, i);
|
||||
|
@ -161,7 +159,9 @@ JSValue js_getpropidx(JSValue v, uint32_t i)
|
|||
static inline cpBody *js2body(JSValue v) { return js2gameobject(v)->body; }
|
||||
|
||||
JSValue str2js(const char *c) { return JS_NewString(js, c); }
|
||||
const char *js2str(JSValue v) { return JS_ToCString(js, v); }
|
||||
const char *js2str(JSValue v) {
|
||||
return JS_ToCString(js, v);
|
||||
}
|
||||
|
||||
JSValue strarr2js(char **c)
|
||||
{
|
||||
|
@ -172,6 +172,7 @@ JSValue strarr2js(char **c)
|
|||
return arr;
|
||||
}
|
||||
|
||||
JSValue number2js(double g) { return JS_NewFloat64(js,g); }
|
||||
double js2number(JSValue v) {
|
||||
double g;
|
||||
JS_ToFloat64(js, &g, v);
|
||||
|
@ -180,8 +181,6 @@ double js2number(JSValue v) {
|
|||
|
||||
void *js2ptr(JSValue v) { return JS_GetOpaque(v,js_ptr_id); }
|
||||
|
||||
JSValue number2js(double g) { return JS_NewFloat64(js,g); }
|
||||
|
||||
JSValue ptr2js(void *ptr) {
|
||||
JSValue obj = JS_NewObjectClass(js, js_ptr_id);
|
||||
JS_SetOpaque(obj, ptr);
|
||||
|
@ -343,6 +342,8 @@ struct boundingbox js2bb(JSValue v)
|
|||
return bb;
|
||||
}
|
||||
|
||||
cpVect js2cvec2(JSValue v) { return js2vec2(v).cp; }
|
||||
JSValue cvec22js(cpVect v) { return vec22js((HMM_Vec2)v); }
|
||||
|
||||
HMM_Vec2 js2vec2(JSValue v)
|
||||
{
|
||||
|
@ -429,19 +430,6 @@ JSValue vecarr2js(HMM_Vec2 *points, int n) {
|
|||
return array;
|
||||
}
|
||||
|
||||
JSValue duk_ui_text(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
HMM_Vec2 pos = js2vec2(argv[1]);
|
||||
|
||||
float size = js2number(argv[2]);
|
||||
struct rgba c = js2color(argv[3]);
|
||||
int wrap = js2number(argv[4]);
|
||||
int cursor = js2number(argv[5]);
|
||||
JSValue ret = JS_NewInt64(js, renderText(s, pos, size, c, wrap, cursor, 1.0));
|
||||
JS_FreeCString(js, s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int js_print_exception(JSValue v)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
|
@ -465,17 +453,6 @@ int js_print_exception(JSValue v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
JSValue duk_gui_img(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
const char *img = JS_ToCString(js, argv[0]);
|
||||
transform2d t;
|
||||
t.pos = js2vec2(argv[1]);
|
||||
t.scale = js2vec2(argv[2]);
|
||||
t.angle = js2number(argv[3]);
|
||||
gui_draw_img(img, t, js2bool(argv[4]), js2vec2(argv[5]), 1.0, js2color(argv[6]));
|
||||
JS_FreeCString(js, img);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
struct rect js2rect(JSValue v) {
|
||||
struct rect rect;
|
||||
rect.x = js2number(js_getpropstr(v, "x"));
|
||||
|
@ -504,38 +481,6 @@ JSValue bb2js(struct boundingbox bb)
|
|||
return obj;
|
||||
}
|
||||
|
||||
JSValue duk_spline_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2number(argv[0]);
|
||||
/*
|
||||
0: catmull-rom
|
||||
1: bezier
|
||||
*/
|
||||
|
||||
int type = js2number(argv[1]);
|
||||
int d = js2number(argv[2]); /* dimensions: 1d, 2d, 3d ...*/
|
||||
HMM_Vec2 *points = js2cpvec2arr(argv[3]);
|
||||
float param = js2number(argv[4]);
|
||||
HMM_Vec2 *samples = NULL;
|
||||
switch(type) {
|
||||
case 0:
|
||||
samples = catmull_rom_ma_v2(points, param);
|
||||
break;
|
||||
case 1:
|
||||
samples = bezier_cb_ma_v2(points, param);
|
||||
break;
|
||||
}
|
||||
|
||||
arrfree(points);
|
||||
|
||||
if (!samples)
|
||||
return JS_UNDEFINED;
|
||||
|
||||
JSValue arr = vecarr2js(samples, arrlen(samples));
|
||||
arrfree(samples);
|
||||
|
||||
return arr;
|
||||
}
|
||||
|
||||
JSValue ints2js(int *ints) {
|
||||
JSValue arr = JS_NewArray(js);
|
||||
for (int i = 0; i < arrlen(ints); i++)
|
||||
|
@ -616,286 +561,6 @@ int point2segindex(HMM_Vec2 p, HMM_Vec2 *segs, double slop) {
|
|||
return best;
|
||||
}
|
||||
|
||||
JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2number(argv[0]);
|
||||
const char *str = NULL;
|
||||
const char *str2 = NULL;
|
||||
void *d1 = NULL;
|
||||
void *d2 = NULL;
|
||||
void *v1 = NULL;
|
||||
gameobject **ids = NULL;
|
||||
int *intids = NULL;
|
||||
gameobject *go = NULL;
|
||||
JSValue ret = JS_UNDEFINED;
|
||||
size_t plen = 0;
|
||||
|
||||
switch (cmd) {
|
||||
case 18:
|
||||
shape_set_sensor(js2ptr(argv[1]), JS_ToBool(js, argv[2]));
|
||||
break;
|
||||
|
||||
case 21:
|
||||
ret = JS_NewBool(js, shape_get_sensor(js2ptr(argv[1])));
|
||||
break;
|
||||
|
||||
case 22:
|
||||
shape_enabled(js2ptr(argv[1]), JS_ToBool(js, argv[2]));
|
||||
break;
|
||||
|
||||
case 23:
|
||||
ret = JS_NewBool(js, shape_is_enabled(js2ptr(argv[1])));
|
||||
break;
|
||||
|
||||
case 44:
|
||||
go = pos2gameobject(js2vec2(argv[1]), js2number(argv[2]));
|
||||
ret = go ? JS_DupValue(js,go->ref) : JS_UNDEFINED;
|
||||
break;
|
||||
|
||||
case 52:
|
||||
ids = phys2d_query_box(js2vec2(argv[1]), js2vec2(argv[2]));
|
||||
ret = gos2ref(ids);
|
||||
arrfree(ids);
|
||||
break;
|
||||
|
||||
case 53:
|
||||
draw_box(js2vec2(argv[1]), js2vec2(argv[2]), js2color(argv[3]));
|
||||
break;
|
||||
|
||||
case 59:
|
||||
v1 = js2cpvec2arr(argv[2]);
|
||||
ret = JS_NewInt64(js, point2segindex(js2vec2(argv[1]), v1, js2number(argv[3])));
|
||||
break;
|
||||
|
||||
case 61:
|
||||
set_cam_body(js2gameobject(argv[1])->body);
|
||||
break;
|
||||
|
||||
case 62:
|
||||
add_zoom(js2number(argv[1]));
|
||||
break;
|
||||
|
||||
case 70:
|
||||
ret = vec22js(world2go(js2gameobject(argv[1]), js2vec2(argv[2])));
|
||||
break;
|
||||
|
||||
case 71:
|
||||
ret = vec22js(go2world(js2gameobject(argv[1]), js2vec2(argv[2])));
|
||||
break;
|
||||
|
||||
case 80:
|
||||
ids = phys2d_query_shape(js2ptr(argv[1]));
|
||||
ret = gos2ref(ids);
|
||||
arrfree(ids);
|
||||
break;
|
||||
|
||||
case 83:
|
||||
v1 = js2cpvec2arr(argv[1]);
|
||||
draw_edge(v1, js_arrlen(argv[1]), js2color(argv[2]), js2number(argv[3]), 0, js2color(argv[2]), 10);
|
||||
break;
|
||||
|
||||
case 86:
|
||||
v1 = js2cpvec2arr(argv[3]);
|
||||
intids = phys2d_query_box_points(js2vec2(argv[1]), js2vec2(argv[2]), v1, js2number(argv[4]));
|
||||
ret = ints2js(intids);
|
||||
arrfree(intids);
|
||||
break;
|
||||
|
||||
case 103:
|
||||
ret = vec22js(js2gameobject(argv[1])->scale.XY);
|
||||
break;
|
||||
|
||||
case 112:
|
||||
ret = number2js(((struct phys2d_edge*)js2ptr(argv[1]))->thickness);
|
||||
break;
|
||||
|
||||
case 113:
|
||||
js2gameobject(argv[1])->ref = argv[2];
|
||||
break;
|
||||
|
||||
case 118:
|
||||
str = JS_ToCString(js,argv[1]);
|
||||
ret = bb2js(text_bb(str, js2number(argv[2]), js2number(argv[3]), 1.0));
|
||||
break;
|
||||
|
||||
case 123:
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
str2 = JS_ToCString(js, argv[3]);
|
||||
ret = eval_script_env(str, argv[2], str2);
|
||||
break;
|
||||
|
||||
case 131:
|
||||
gif_rec_start(js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), js2number(argv[4]));
|
||||
break;
|
||||
case 132:
|
||||
str = JS_ToCString(js, argv[1]);
|
||||
gif_rec_end(str);
|
||||
break;
|
||||
|
||||
case 135:
|
||||
ret = number2js(cam_zoom());
|
||||
break;
|
||||
|
||||
case 136:
|
||||
ret = vec22js(world2screen(js2vec2(argv[1])));
|
||||
break;
|
||||
|
||||
case 137:
|
||||
ret = vec22js(screen2world(js2vec2(argv[1])));
|
||||
break;
|
||||
|
||||
case 139:
|
||||
str = JS_ToCString(js,argv[1]);
|
||||
ret = JS_NewInt64(js, gif_nframes(str));
|
||||
break;
|
||||
|
||||
case 149:
|
||||
((struct drawmodel *)js2ptr(argv[1]))->model = GetExistingModel(js2str(argv[2]));
|
||||
break;
|
||||
|
||||
case 150:
|
||||
draw_drawmodel(js2ptr(argv[1]));
|
||||
break;
|
||||
|
||||
case 153:
|
||||
cpBodySetTorque(js2gameobject(argv[1])->body, js2number(argv[2]));
|
||||
break;
|
||||
|
||||
case 160:
|
||||
ret = vec22js(mat_t_dir(t_world2go(js2gameobject(argv[1])), js2vec2(argv[2])));
|
||||
break;
|
||||
case 161:
|
||||
ret = vec22js(mat_t_dir(t_go2world(js2gameobject(argv[1])), js2vec2(argv[2])));
|
||||
break;
|
||||
|
||||
case 177:
|
||||
plugin_node(js2dsp_node(argv[1]), js2dsp_node(argv[2]));
|
||||
break;
|
||||
case 180:
|
||||
ret = dsp_node2js(masterbus);
|
||||
break;
|
||||
case 181:
|
||||
ret = dsp_node2js(make_node(NULL,NULL,NULL));
|
||||
break;
|
||||
case 182:
|
||||
str = js2str(argv[1]);
|
||||
ret = dsp_node2js(dsp_source(str));
|
||||
JS_SetPrototype(js, ret, sound_proto);
|
||||
break;
|
||||
case 185:
|
||||
ret = dsp_node2js(dsp_delay(js2number(argv[1]), js2number(argv[2])));
|
||||
break;
|
||||
case 186:
|
||||
ret = dsp_node2js(dsp_lpf(js2number(argv[1])));
|
||||
break;
|
||||
case 187:
|
||||
ret = dsp_node2js(dsp_hpf(js2number(argv[1])));
|
||||
break;
|
||||
case 188:
|
||||
str = js2str(argv[1]);
|
||||
ret = dsp_node2js(dsp_mod(str));
|
||||
break;
|
||||
case 189:
|
||||
ret = dsp_node2js(dsp_bitcrush(js2number(argv[1]), js2number(argv[2])));
|
||||
break;
|
||||
case 190:
|
||||
ret = dsp_node2js(dsp_compressor());
|
||||
break;
|
||||
case 191:
|
||||
ret = dsp_node2js(dsp_limiter(js2number(argv[1])));
|
||||
break;
|
||||
case 192:
|
||||
ret = dsp_node2js(dsp_noise_gate(js2number(argv[1])));
|
||||
break;
|
||||
case 197:
|
||||
ret = number2js(js2sound(argv[1])->data->frames);
|
||||
break;
|
||||
case 198:
|
||||
ret = number2js(SAMPLERATE);
|
||||
break;
|
||||
case 200:
|
||||
ret = dsp_node2js(dsp_pitchshift(js2number(argv[1])));
|
||||
break;
|
||||
case 203:
|
||||
ret = dsp_node2js(dsp_whitenoise());
|
||||
break;
|
||||
case 204:
|
||||
ret = dsp_node2js(dsp_pinknoise());
|
||||
break;
|
||||
case 205:
|
||||
ret = dsp_node2js(dsp_rednoise());
|
||||
break;
|
||||
case 206:
|
||||
str = js2str(argv[1]);
|
||||
str2 = js2str(argv[2]);
|
||||
ret = dsp_node2js(dsp_midi(str, make_soundfont(str2)));
|
||||
break;
|
||||
case 207:
|
||||
ret = dsp_node2js(dsp_fwd_delay(js2number(argv[1]), js2number(argv[2])));
|
||||
break;
|
||||
case 213:
|
||||
free_drawmodel(js2ptr(argv[1]));
|
||||
break;
|
||||
|
||||
case 221:
|
||||
ret = constraint2js(constraint_make(cpPivotJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body,js2vec2(argv[3]).cp)));
|
||||
break;
|
||||
case 222:
|
||||
ret = constraint2js(constraint_make(cpPinJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, cpvzero,cpvzero)));
|
||||
break;
|
||||
case 223:
|
||||
ret = constraint2js(constraint_make(cpGearJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2number(argv[3]), js2number(argv[4]))));
|
||||
break;
|
||||
case 224:
|
||||
str = js2str(argv[1]);
|
||||
ret = ints2js(gif_delays(str));
|
||||
break;
|
||||
case 225:
|
||||
ret = constraint2js(constraint_make(cpRotaryLimitJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2number(argv[3]), js2number(argv[4]))));
|
||||
break;
|
||||
case 226:
|
||||
ret = constraint2js(constraint_make(cpDampedRotarySpringNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2number(argv[3]), js2number(argv[4]), js2number(argv[5]))));
|
||||
break;
|
||||
case 227:
|
||||
ret = constraint2js(constraint_make(cpDampedSpringNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2vec2(argv[3]).cp, js2vec2(argv[4]).cp, js2number(argv[5]), js2number(argv[6]), js2number(argv[7]))));
|
||||
break;
|
||||
case 228:
|
||||
ret = constraint2js(constraint_make(cpGrooveJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2vec2(argv[3]).cp, js2vec2(argv[4]).cp, js2vec2(argv[5]).cp)));
|
||||
break;
|
||||
case 229:
|
||||
ret = constraint2js(constraint_make(cpSlideJointNew(js2gameobject(argv[1])->body, js2gameobject(argv[2])->body, js2vec2(argv[3]).cp, js2vec2(argv[4]).cp, js2number(argv[5]), js2number(argv[6]))));
|
||||
break;
|
||||
case 230:
|
||||
ret = constraint2js(constraint_make(cpRatchetJointNew(js2body(argv[1]), js2body(argv[2]), js2number(argv[3]), js2number(argv[4]))));
|
||||
break;
|
||||
case 231:
|
||||
ret = constraint2js(constraint_make(cpSimpleMotorNew(js2body(argv[1]), js2body(argv[2]), js2number(argv[3]))));
|
||||
break;
|
||||
|
||||
case 253:
|
||||
ret = warp_gravity2js(warp_gravity_make());
|
||||
break;
|
||||
case 254:
|
||||
ret = warp_damp2js(warp_damp_make());
|
||||
break;
|
||||
|
||||
case 268:
|
||||
if (js2bool(argv[1]))
|
||||
ret = JS_GetClassProto(js, js_sprite_id);
|
||||
else
|
||||
ret = sprite2js(sprite_make());
|
||||
break;
|
||||
}
|
||||
|
||||
if (str) JS_FreeCString(js, str);
|
||||
if (str2) JS_FreeCString(js, str2);
|
||||
if (d1) free(d1);
|
||||
if (d2) free(d2);
|
||||
if (v1) arrfree(v1);
|
||||
|
||||
if (!JS_IsNull(ret)) return ret;
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
void gameobject_add_shape_collider(gameobject *go, JSValue fn, struct phys2d_shape *shape) {
|
||||
struct shape_cb shapecb;
|
||||
shapecb.shape = shape;
|
||||
|
@ -929,102 +594,6 @@ JSValue duk_register_collide(JSContext *js, JSValueConst this, int argc, JSValue
|
|||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
JSValue duk_make_gameobject(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
return gameobject2js(MakeGameobject());
|
||||
}
|
||||
|
||||
JSValue duk_set_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int cmd = js2number(argv[0]);
|
||||
gameobject *go = js2gameobject(argv[1]);
|
||||
|
||||
if (!go) return JS_UNDEFINED;
|
||||
|
||||
/* TODO: Possible that reindexing shapes only needs done for static shapes? */
|
||||
switch (cmd) {
|
||||
case 0:
|
||||
gameobject_setangle(go, js2number(argv[2]));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
go->bodytype = js2number(argv[2]);
|
||||
cpBodySetType(go->body, go->bodytype);
|
||||
gameobject_apply(go);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
cpBodySetPosition(go->body, js2vec2(argv[2]).cp);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
cpBodyApplyImpulseAtWorldPoint(go->body, js2vec2(argv[2]).cp, cpBodyGetPosition(go->body));
|
||||
return JS_UNDEFINED;
|
||||
|
||||
case 7:
|
||||
go->mass = js2number(argv[2]);
|
||||
if (go->bodytype == CP_BODY_TYPE_DYNAMIC)
|
||||
cpBodySetMass(go->body, go->mass);
|
||||
break;
|
||||
|
||||
case 8:
|
||||
cpBodySetAngularVelocity(go->body, js2number(argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
|
||||
case 9:
|
||||
cpBodySetVelocity(go->body, js2vec2(argv[2]).cp);
|
||||
return JS_UNDEFINED;
|
||||
|
||||
case 12:
|
||||
cpBodyApplyForceAtWorldPoint(go->body, js2vec2(argv[2]).cp, cpBodyGetPosition(go->body));
|
||||
return JS_UNDEFINED;
|
||||
|
||||
case 13:
|
||||
cpBodySetMoment(go->body, js2number(argv[2]));
|
||||
return JS_UNDEFINED;
|
||||
case 14:
|
||||
cpBodyApplyForceAtLocalPoint(go->body, js2vec2(argv[2]).cp, js2vec2(argv[3]).cp);
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
cpSpaceReindexShapesForBody(space, go->body);
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
JSValue duk_q_body(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
int q = js2number(argv[0]);
|
||||
gameobject *go = js2gameobject(argv[1]);
|
||||
|
||||
if (!go) return JS_UNDEFINED;
|
||||
|
||||
switch (q) {
|
||||
case 0:
|
||||
return JS_NewInt64(js, cpBodyGetType(go->body));
|
||||
|
||||
case 1:
|
||||
return vec22js((HMM_Vec2)cpBodyGetPosition(go->body));
|
||||
|
||||
case 2:
|
||||
return number2js(cpBodyGetAngle(go->body));
|
||||
|
||||
case 3:
|
||||
return vec22js((HMM_Vec2)cpBodyGetVelocity(go->body));
|
||||
|
||||
case 4:
|
||||
return number2js(cpBodyGetAngularVelocity(go->body));
|
||||
|
||||
case 5:
|
||||
return number2js(cpBodyGetMass(go->body));
|
||||
|
||||
case 6:
|
||||
return number2js(cpBodyGetMoment(go->body));
|
||||
|
||||
case 7:
|
||||
return JS_NewBool(js, phys2d_in_air(go->body));
|
||||
}
|
||||
|
||||
return JS_UNDEFINED;
|
||||
}
|
||||
|
||||
JSValue duk_make_circle2d(JSContext *js, JSValueConst this, int argc, JSValueConst *argv) {
|
||||
gameobject *go = js2gameobject(argv[0]);
|
||||
|
||||
|
@ -1194,6 +763,18 @@ static const JSCFunctionListEntry js_warp_damp_funcs [] = {
|
|||
CGETSET_ADD(warp_damp, damp)
|
||||
};
|
||||
|
||||
JSC_CCALL(drawmodel_draw, draw_drawmodel(js2drawmodel(this)))
|
||||
JSC_CCALL(drawmodel_path,
|
||||
char *s = js2str(argv[0]);
|
||||
js2drawmodel(this)->model = GetExistingModel(s);
|
||||
JS_FreeCString(js,s);
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_drawmodel_funcs[] = {
|
||||
MIST_FUNC_DEF(drawmodel, draw, 0),
|
||||
MIST_FUNC_DEF(drawmodel, path, 1)
|
||||
};
|
||||
|
||||
GETSET_PAIR(emitter, life, number)
|
||||
GETSET_PAIR(emitter, life_var, number)
|
||||
GETSET_PAIR(emitter, speed, number)
|
||||
|
@ -1271,6 +852,14 @@ JSValue js_os_sys(JSContext *js, JSValueConst this, int argc, JSValue *argv)
|
|||
JSC_CCALL(os_quit, quit();)
|
||||
JSC_CCALL(os_reindex_static, cpSpaceReindexStatic(space));
|
||||
JSC_CCALL(os_gc, script_gc());
|
||||
JSC_CCALL(os_eval_env,
|
||||
char *s1 = js2str(argv[0]);
|
||||
char *s2 = js2str(argv[2]);
|
||||
JSValue ret = eval_script_env(s1, argv[1], s2);
|
||||
JS_FreeCString(js,s1);
|
||||
JS_FreeCString(js,s2);
|
||||
return ret;
|
||||
)
|
||||
|
||||
#define RETUN return JS_UNDEFINED
|
||||
|
||||
|
@ -1281,7 +870,13 @@ JSValue js_os_capture(JSContext *js, JSValueConst this, int argc, JSValue *argv)
|
|||
RETUN;
|
||||
}
|
||||
|
||||
JSC_CCALL(os_sprite,
|
||||
if (js2bool(argv[0])) return JS_GetClassProto(js,js_sprite_id);
|
||||
return sprite2js(sprite_make());
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_os_funcs[] = {
|
||||
MIST_FUNC_DEF(os,sprite,1),
|
||||
MIST_FUNC_DEF(os, cwd, 0),
|
||||
MIST_FUNC_DEF(os, env, 1),
|
||||
MIST_FUNC_DEF(os, sys, 0),
|
||||
|
@ -1289,6 +884,7 @@ static const JSCFunctionListEntry js_os_funcs[] = {
|
|||
MIST_FUNC_DEF(os, reindex_static, 0),
|
||||
MIST_FUNC_DEF(os, gc, 0),
|
||||
MIST_FUNC_DEF(os, capture, 5),
|
||||
MIST_FUNC_DEF(os, eval_env, 3),
|
||||
};
|
||||
|
||||
JSC_CCALL(render_normal, opengl_rendermode(LIT))
|
||||
|
@ -1317,8 +913,40 @@ JSC_CCALL(render_flush_hud, debug_flush(&hudproj); debug_flush(&hudproj); sprite
|
|||
JSC_CCALL(render_pass, debug_nextpass())
|
||||
JSC_CCALL(render_end_pass, sg_end_pass())
|
||||
JSC_CCALL(render_commit, sg_commit(); debug_newframe();)
|
||||
JSC_CCALL(render_text_size,
|
||||
char *s = js2str(argv[0]);
|
||||
JSValue ret = bb2js(text_bb(s, js2number(argv[1]), js2number(argv[2]), 1));
|
||||
JS_FreeCString(js,s);
|
||||
return ret;
|
||||
)
|
||||
JSC_CCALL(render_gif_times,
|
||||
char *s = js2str(argv[0]);
|
||||
JSValue ret = ints2js(gif_delays(s));
|
||||
JS_FreeCString(js,s);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(render_gif_frames,
|
||||
char *s = js2str(argv[0]);
|
||||
JSValue ret = number2js(gif_nframes(s));
|
||||
JS_FreeCString(js,s);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(render_cam_body, set_cam_body(js2gameobject(argv[0])->body))
|
||||
JSC_CCALL(render_add_zoom, add_zoom(js2number(argv[0])))
|
||||
JSC_CCALL(render_get_zoom, return number2js(cam_zoom()))
|
||||
JSC_CCALL(render_world2screen, return vec22js(world2screen(js2vec2(argv[0]))))
|
||||
JSC_CCALL(render_screen2world, return vec22js(screen2world(js2vec2(argv[0]))))
|
||||
|
||||
static const JSCFunctionListEntry js_render_funcs[] = {
|
||||
MIST_FUNC_DEF(render,cam_body, 1),
|
||||
MIST_FUNC_DEF(render,add_zoom,1),
|
||||
MIST_FUNC_DEF(render,get_zoom,0),
|
||||
MIST_FUNC_DEF(render,world2screen,1),
|
||||
MIST_FUNC_DEF(render,screen2world,1),
|
||||
MIST_FUNC_DEF(render,gif_frames,1),
|
||||
MIST_FUNC_DEF(render, gif_times, 1),
|
||||
MIST_FUNC_DEF(render, normal, 0),
|
||||
MIST_FUNC_DEF(render, wireframe, 0),
|
||||
MIST_FUNC_DEF(render, grid, 3),
|
||||
|
@ -1333,20 +961,73 @@ static const JSCFunctionListEntry js_render_funcs[] = {
|
|||
MIST_FUNC_DEF(render, flush_hud, 0),
|
||||
MIST_FUNC_DEF(render, pass, 0),
|
||||
MIST_FUNC_DEF(render, end_pass, 0),
|
||||
MIST_FUNC_DEF(render, commit, 0)
|
||||
MIST_FUNC_DEF(render, commit, 0),
|
||||
MIST_FUNC_DEF(render, text_size, 3)
|
||||
};
|
||||
|
||||
JSC_CCALL(gui_flush, text_flush(&hudproj));
|
||||
JSC_CCALL(gui_scissor, sg_apply_scissor_rectf(js2number(argv[0]), js2number(argv[1]), js2number(argv[2]), js2number(argv[3]), 0))
|
||||
JSC_CCALL(gui_text,
|
||||
const char *s = JS_ToCString(js, argv[0]);
|
||||
HMM_Vec2 pos = js2vec2(argv[1]);
|
||||
|
||||
float size = js2number(argv[2]);
|
||||
struct rgba c = js2color(argv[3]);
|
||||
int wrap = js2number(argv[4]);
|
||||
int cursor = js2number(argv[5]);
|
||||
JSValue ret = JS_NewInt64(js, renderText(s, pos, size, c, wrap, cursor, 1.0));
|
||||
JS_FreeCString(js, s);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(gui_img,
|
||||
const char *img = JS_ToCString(js, argv[0]);
|
||||
transform2d t;
|
||||
t.pos = js2vec2(argv[1]);
|
||||
t.scale = js2vec2(argv[2]);
|
||||
t.angle = js2number(argv[3]);
|
||||
gui_draw_img(img, t, js2bool(argv[4]), js2vec2(argv[5]), 1.0, js2color(argv[6]));
|
||||
JS_FreeCString(js, img);
|
||||
)
|
||||
|
||||
|
||||
DEF_FN_STR(font_set)
|
||||
|
||||
static const JSCFunctionListEntry js_gui_funcs[] = {
|
||||
MIST_FUNC_DEF(gui, flush, 0),
|
||||
MIST_FUNC_DEF(gui, scissor, 4),
|
||||
MIST_FUNC_DEF(gui, text, 6),
|
||||
MIST_FUNC_DEF(gui, img, 7),
|
||||
MIST_FN_STR(font_set),
|
||||
};
|
||||
|
||||
JSC_CCALL(spline_catmull,
|
||||
HMM_Vec2 *points = js2cpvec2arr(argv[0]);
|
||||
float param = js2number(argv[1]);
|
||||
HMM_Vec2 *samples = catmull_rom_ma_v2(points,param);
|
||||
arrfree(points);
|
||||
if (!samples) return JS_UNDEFINED;
|
||||
JSValue arr = vecarr2js(samples, arrlen(samples));
|
||||
arrfree(samples);
|
||||
return arr;
|
||||
)
|
||||
|
||||
JSC_CCALL(spline_bezier,
|
||||
HMM_Vec2 *points = js2cpvec2arr(argv[0]);
|
||||
float param = js2number(argv[1]);
|
||||
HMM_Vec2 *samples = catmull_rom_ma_v2(points,param);
|
||||
arrfree(points);
|
||||
if (!samples) return JS_UNDEFINED;
|
||||
JSValue arr = vecarr2js(samples, arrlen(samples));
|
||||
arrfree(samples);
|
||||
return arr;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_spline_funcs[] = {
|
||||
MIST_FUNC_DEF(spline, catmull, 2),
|
||||
MIST_FUNC_DEF(spline, bezier, 2)
|
||||
};
|
||||
|
||||
JSValue js_vector_dot(JSContext *js, JSValueConst this, int argc, JSValue *argv) { return number2js(HMM_DotV2(js2vec2(argv[0]), js2vec2(argv[1]))) ; };
|
||||
|
||||
JSC_RET(vector_project, return vec22js(HMM_ProjV2(js2vec2(argv[0]), js2vec2(argv[1])));)
|
||||
|
@ -1629,9 +1310,56 @@ JSValue js_physics_sgscale(JSContext *js, JSValueConst this, int argc, JSValue *
|
|||
|
||||
JSValue js_physics_set_cat_mask(JSContext *js, JSValueConst this, int argc, JSValue *argv) { set_cat_mask(js2number(argv[0]), js2bitmask(argv[1])); RETUN; }
|
||||
|
||||
JSC_CCALL(physics_box_query,
|
||||
int *ids = phys2d_query_box(js2vec2(argv[0]), js2vec2(argv[1]));
|
||||
JSValue ret = gos2ref(ids);
|
||||
arrfree(ids);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(physics_pos_query,
|
||||
gameobject *go = pos2gameobject(js2vec2(argv[0]), js2number(argv[1]));
|
||||
JSValue ret = go ? JS_DupValue(js,go->ref) : JS_UNDEFINED;
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(physics_box_point_query,
|
||||
void *v = js2cpvec2arr(argv[2]);
|
||||
int *intids = phys2d_query_box_points(js2vec2(argv[0]), js2vec2(argv[1]), v, js_arrlen(argv[2]));
|
||||
JSValue ret = ints2js(intids);
|
||||
arrfree(intids);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(physics_query_shape,
|
||||
int *ids = phys2d_query_shape(js2ptr(argv[0]));
|
||||
JSValue ret = gos2ref(ids);
|
||||
arrfree(ids);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(physics_closest_point,
|
||||
void *v1 = js2cpvec2arr(argv[1]);
|
||||
JSValue ret = number2js(point2segindex(js2vec2(argv[0]), v1, js2number(argv[2])));
|
||||
arrfree(v1);
|
||||
return ret;
|
||||
)
|
||||
|
||||
JSC_CCALL(physics_make_gravity, return warp_gravity2js(warp_gravity_make()))
|
||||
JSC_CCALL(physics_make_damp, return warp_damp2js(warp_damp_make()))
|
||||
JSC_CCALL(physics_edge_thickness, return number2js(((struct phys2d_edge*)js2ptr(argv[0]))->thickness))
|
||||
|
||||
static const JSCFunctionListEntry js_physics_funcs[] = {
|
||||
MIST_FUNC_DEF(physics,edge_thickness,1),
|
||||
MIST_FUNC_DEF(physics, sgscale, 2),
|
||||
MIST_FUNC_DEF(physics, set_cat_mask, 2)
|
||||
MIST_FUNC_DEF(physics, set_cat_mask, 2),
|
||||
MIST_FUNC_DEF(physics, box_query, 2),
|
||||
MIST_FUNC_DEF(physics, pos_query, 2),
|
||||
MIST_FUNC_DEF(physics, box_point_query, 3),
|
||||
MIST_FUNC_DEF(physics, query_shape, 1),
|
||||
MIST_FUNC_DEF(physics, closest_point, 3),
|
||||
MIST_FUNC_DEF(physics, make_damp, 0),
|
||||
MIST_FUNC_DEF(physics, make_gravity, 0)
|
||||
};
|
||||
|
||||
static const JSCFunctionListEntry js_emitter_funcs[] = {
|
||||
|
@ -1689,12 +1417,14 @@ GETSET_PAIR(sound, loop, bool)
|
|||
GETSET_PAIR(sound, timescale, number)
|
||||
GETSET_PAIR(sound, frame, number)
|
||||
GETSET_PAIR_HOOK(sound, hook)
|
||||
JSC_CCALL(sound_frames, return number2js(js2sound(this)->data->frames))
|
||||
|
||||
static const JSCFunctionListEntry js_sound_funcs[] = {
|
||||
CGETSET_ADD(sound, loop),
|
||||
CGETSET_ADD(sound, timescale),
|
||||
CGETSET_ADD(sound, frame),
|
||||
CGETSET_ADD(sound, hook)
|
||||
CGETSET_ADD(sound, hook),
|
||||
MIST_FUNC_DEF(sound, frames, 0),
|
||||
};
|
||||
|
||||
static JSValue window_get_size(JSContext *js, JSValueConst this) { return vec22js(js2window(this)->size); }
|
||||
|
@ -1765,6 +1495,34 @@ JSValue ID##_get_##ENTRY (JSContext *js, JSValue this) { \
|
|||
return TYPE##2js(js2##ID (this)->ENTRY); \
|
||||
} \
|
||||
|
||||
#define BODY_GETSET(ENTRY, CPENTRY, TYPE) \
|
||||
JSValue gameobject_set_##ENTRY (JSContext *js, JSValue this, JSValue val) { \
|
||||
cpBody *b = js2gameobject(this)->body; \
|
||||
cpBodySet##CPENTRY (b, js2##TYPE (val)); \
|
||||
return JS_UNDEFINED; \
|
||||
} \
|
||||
\
|
||||
JSValue gameobject_get_##ENTRY (JSContext *js, JSValue this) { \
|
||||
cpBody *b = js2gameobject(this)->body; \
|
||||
return TYPE##2js (cpBodyGet##CPENTRY (b)); \
|
||||
} \
|
||||
|
||||
BODY_GETSET(pos, Position, cvec2)
|
||||
BODY_GETSET(angle, Angle, number)
|
||||
GETSET_PAIR(gameobject, scale, vec3)
|
||||
BODY_GETSET(velocity, Velocity, cvec2)
|
||||
BODY_GETSET(angularvelocity, AngularVelocity, number)
|
||||
BODY_GETSET(moi, Moment, number)
|
||||
BODY_GETSET(phys, Type, number)
|
||||
BODY_GETSET(torque, Torque, number)
|
||||
JSC_CCALL(gameobject_impulse, cpBodyApplyImpulseAtWorldPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, cpBodyGetPosition(js2gameobject(this)->body)))
|
||||
JSC_CCALL(gameobject_force, cpBodyApplyForceAtWorldPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, cpBodyGetPosition(js2gameobject(this)->body)))
|
||||
JSC_CCALL(gameobject_force_local, cpBodyApplyForceAtLocalPoint(js2gameobject(this)->body, js2vec2(argv[0]).cp, js2vec2(argv[1]).cp))
|
||||
JSC_CCALL(gameobject_in_air, return bool2js(phys2d_in_air(js2gameobject(this)->body)))
|
||||
JSC_CCALL(gameobject_world2this, return vec22js(world2go(js2gameobject(this), js2vec2(argv[0]))))
|
||||
JSC_CCALL(gameobject_this2world, return vec22js(go2world(js2gameobject(this), js2vec2(argv[0]))))
|
||||
JSC_CCALL(gameobject_dir_world2this, return vec22js(mat_t_dir(t_world2go(js2gameobject(this)), js2vec2(argv[0]))))
|
||||
JSC_CCALL(gameobject_dir_this2world, return vec22js(mat_t_dir(t_go2world(js2gameobject(this)), js2vec2(argv[0]))))
|
||||
GETSET_PAIR_BODY(gameobject, f, number)
|
||||
GETSET_PAIR_BODY(gameobject, e, number)
|
||||
GETSET_PAIR_BODY(gameobject, mass, number)
|
||||
|
@ -1774,21 +1532,138 @@ GETSET_PAIR(gameobject, maxvelocity, number)
|
|||
GETSET_PAIR(gameobject, maxangularvelocity, number)
|
||||
GETSET_PAIR_BODY(gameobject, layer, number)
|
||||
GETSET_PAIR(gameobject, warp_filter, bitmask)
|
||||
GETSET_PAIR(gameobject, scale, vec3)
|
||||
GETSET_PAIR(gameobject, drawlayer, number)
|
||||
JSC_CCALL(gameobject_setref, js2gameobject(this)->ref = argv[0]);
|
||||
|
||||
JSValue duk_make_gameobject(JSContext *js, JSValue this) { return gameobject2js(MakeGameobject()); }
|
||||
|
||||
static const JSCFunctionListEntry js_gameobject_funcs[] = {
|
||||
CGETSET_ADD(gameobject, f),
|
||||
CGETSET_ADD(gameobject, e),
|
||||
CGETSET_ADD(gameobject,mass),
|
||||
CGETSET_ADD(gameobject,damping),
|
||||
CGETSET_ADD(gameobject, scale),
|
||||
CGETSET_ADD(gameobject,timescale),
|
||||
CGETSET_ADD(gameobject,maxvelocity),
|
||||
CGETSET_ADD(gameobject,maxangularvelocity),
|
||||
CGETSET_ADD(gameobject,layer),
|
||||
CGETSET_ADD(gameobject,warp_filter),
|
||||
CGETSET_ADD(gameobject,scale),
|
||||
CGETSET_ADD(gameobject,drawlayer)
|
||||
CGETSET_ADD(gameobject,drawlayer),
|
||||
CGETSET_ADD(gameobject, pos),
|
||||
CGETSET_ADD(gameobject, angle),
|
||||
CGETSET_ADD(gameobject, velocity),
|
||||
CGETSET_ADD(gameobject, angularvelocity),
|
||||
CGETSET_ADD(gameobject, moi),
|
||||
CGETSET_ADD(gameobject, phys),
|
||||
CGETSET_ADD(gameobject, torque),
|
||||
MIST_FUNC_DEF(gameobject, impulse, 1),
|
||||
MIST_FUNC_DEF(gameobject, force, 1),
|
||||
MIST_FUNC_DEF(gameobject, force_local, 2),
|
||||
MIST_FUNC_DEF(gameobject, in_air, 0),
|
||||
MIST_FUNC_DEF(gameobject, world2this, 1),
|
||||
MIST_FUNC_DEF(gameobject, this2world, 1),
|
||||
MIST_FUNC_DEF(gameobject, dir_world2this, 1),
|
||||
MIST_FUNC_DEF(gameobject, dir_this2world, 1),
|
||||
MIST_FUNC_DEF(gameobject,setref,1),
|
||||
};
|
||||
|
||||
JSC_CCALL(joint_pin, return constraint2js(constraint_make(cpPinJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, cpvzero,cpvzero))))
|
||||
JSC_CCALL(joint_pivot, return constraint2js(constraint_make(cpPivotJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body,js2vec2(argv[2]).cp))))
|
||||
JSC_CCALL(joint_gear, return constraint2js(constraint_make(cpGearJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2number(argv[2]), js2number(argv[3])))))
|
||||
JSC_CCALL(joint_rotary, return constraint2js(constraint_make(cpRotaryLimitJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2number(argv[2]), js2number(argv[3])))))
|
||||
JSC_CCALL(joint_damped_rotary, return constraint2js(constraint_make(cpDampedRotarySpringNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2number(argv[2]), js2number(argv[3]), js2number(argv[4])))))
|
||||
JSC_CCALL(joint_damped_spring, return constraint2js(constraint_make(cpDampedSpringNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2vec2(argv[2]).cp, js2vec2(argv[3]).cp, js2number(argv[4]), js2number(argv[5]), js2number(argv[6])))))
|
||||
JSC_CCALL(joint_groove, return constraint2js(constraint_make(cpGrooveJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2vec2(argv[2]).cp, js2vec2(argv[3]).cp, js2vec2(argv[4]).cp))))
|
||||
JSC_CCALL(joint_slide, return constraint2js(constraint_make(cpSlideJointNew(js2gameobject(argv[0])->body, js2gameobject(argv[1])->body, js2vec2(argv[2]).cp, js2vec2(argv[3]).cp, js2number(argv[4]), js2number(argv[5])))))
|
||||
JSC_CCALL(joint_ratchet, return constraint2js(constraint_make(cpRatchetJointNew(js2body(argv[0]), js2body(argv[1]), js2number(argv[2]), js2number(argv[3])))))
|
||||
JSC_CCALL(joint_motor, return constraint2js(constraint_make(cpSimpleMotorNew(js2body(argv[0]), js2body(argv[1]), js2number(argv[2])))))
|
||||
|
||||
static const JSCFunctionListEntry js_joint_funcs[] = {
|
||||
MIST_FUNC_DEF(joint, pin, 2),
|
||||
MIST_FUNC_DEF(joint, pivot, 3),
|
||||
MIST_FUNC_DEF(joint, gear, 4),
|
||||
MIST_FUNC_DEF(joint, rotary, 4),
|
||||
MIST_FUNC_DEF(joint, damped_rotary, 5),
|
||||
MIST_FUNC_DEF(joint, damped_spring, 7),
|
||||
MIST_FUNC_DEF(joint, groove, 5),
|
||||
MIST_FUNC_DEF(joint, slide, 6),
|
||||
MIST_FUNC_DEF(joint, ratchet, 4),
|
||||
MIST_FUNC_DEF(joint, motor, 3)
|
||||
};
|
||||
|
||||
JSC_CCALL(dspsound_noise, return dsp_node2js(dsp_whitenoise()))
|
||||
JSC_CCALL(dspsound_pink, return dsp_node2js(dsp_pinknoise()))
|
||||
JSC_CCALL(dspsound_red, return dsp_node2js(dsp_rednoise()))
|
||||
JSC_CCALL(dspsound_pitchshift, return dsp_node2js(dsp_pitchshift(js2number(argv[0]))))
|
||||
JSC_CCALL(dspsound_noise_gate, return dsp_node2js(dsp_noise_gate(js2number(argv[0]))))
|
||||
JSC_CCALL(dspsound_limiter, return dsp_node2js(dsp_limiter(js2number(argv[0]))))
|
||||
JSC_CCALL(dspsound_compressor, return dsp_node2js(dsp_compressor()))
|
||||
JSC_CCALL(dspsound_crush, return dsp_node2js(dsp_bitcrush(js2number(argv[0]), js2number(argv[1]))))
|
||||
JSC_CCALL(dspsound_lpf, return dsp_node2js(dsp_lpf(js2number(argv[0]))))
|
||||
JSC_CCALL(dspsound_hpf, return dsp_node2js(dsp_hpf(js2number(argv[0]))))
|
||||
JSC_CCALL(dspsound_delay, return dsp_node2js(dsp_delay(js2number(argv[0]), js2number(argv[1]))))
|
||||
JSC_CCALL(dspsound_fwd_delay, return dsp_node2js(dsp_fwd_delay(js2number(argv[0]), js2number(argv[1]))))
|
||||
JSC_CCALL(dspsound_source,
|
||||
char *s = js2str(argv[0]);
|
||||
JSValue ret = dsp_node2js(dsp_source(s));
|
||||
JS_FreeCString(js,s);
|
||||
JS_SetPrototype(js, ret, sound_proto);
|
||||
return ret;
|
||||
)
|
||||
JSC_CCALL(dspsound_mix, return dsp_node2js(make_node(NULL,NULL,NULL)))
|
||||
JSC_CCALL(dspsound_master, return dsp_node2js(masterbus))
|
||||
JSC_CCALL(dspsound_plugin_node, plugin_node(js2dsp_node(argv[0]), js2dsp_node(argv[1])))
|
||||
JSC_CCALL(dspsound_samplerate, return number2js(SAMPLERATE))
|
||||
JSC_CCALL(dspsound_mod,
|
||||
char *s = js2str(argv[0]);
|
||||
JSValue ret = dsp_node2js(dsp_mod(s));
|
||||
JS_FreeCString(js,s);
|
||||
return ret;
|
||||
)
|
||||
JSC_CCALL(dspsound_midi,
|
||||
char *s1;
|
||||
char *s2;
|
||||
s1 = js2str(argv[0]);
|
||||
s2 = js2str(argv[1]);
|
||||
JSValue ret = dsp_node2js(dsp_midi(s1, make_soundfont(s2)));
|
||||
JS_FreeCString(js,s1);
|
||||
JS_FreeCString(js,s2);
|
||||
return ret;
|
||||
)
|
||||
|
||||
static const JSCFunctionListEntry js_dspsound_funcs[] = {
|
||||
MIST_FUNC_DEF(dspsound, noise, 0),
|
||||
MIST_FUNC_DEF(dspsound, pink, 0),
|
||||
MIST_FUNC_DEF(dspsound, red, 0),
|
||||
MIST_FUNC_DEF(dspsound, pitchshift, 1),
|
||||
MIST_FUNC_DEF(dspsound, noise_gate, 1),
|
||||
MIST_FUNC_DEF(dspsound, limiter, 1),
|
||||
MIST_FUNC_DEF(dspsound, compressor, 0),
|
||||
MIST_FUNC_DEF(dspsound, crush, 2),
|
||||
MIST_FUNC_DEF(dspsound, lpf, 1),
|
||||
MIST_FUNC_DEF(dspsound, hpf, 1),
|
||||
MIST_FUNC_DEF(dspsound, delay, 2),
|
||||
MIST_FUNC_DEF(dspsound, fwd_delay, 2),
|
||||
MIST_FUNC_DEF(dspsound, source, 1),
|
||||
MIST_FUNC_DEF(dspsound, mix, 0),
|
||||
MIST_FUNC_DEF(dspsound, master, 0),
|
||||
MIST_FUNC_DEF(dspsound, plugin_node, 2),
|
||||
MIST_FUNC_DEF(dspsound, samplerate, 0),
|
||||
MIST_FUNC_DEF(dspsound, midi, 2),
|
||||
MIST_FUNC_DEF(dspsound, mod, 1)
|
||||
};
|
||||
|
||||
JSC_CCALL(shape_set_sensor, shape_set_sensor(js2ptr(argv[0]), js2bool(argv[1])))
|
||||
JSC_CCALL(shape_get_sensor, shape_get_sensor(js2ptr(argv[0])))
|
||||
JSC_CCALL(shape_set_enabled, shape_enabled(js2ptr(argv[0]), js2bool(argv[1])))
|
||||
JSC_CCALL(shape_get_enabled, shape_is_enabled(js2ptr(argv[0])))
|
||||
|
||||
static const JSCFunctionListEntry js_shape_funcs[] = {
|
||||
MIST_FUNC_DEF(shape, set_sensor, 2),
|
||||
MIST_FUNC_DEF(shape, get_sensor, 1),
|
||||
MIST_FUNC_DEF(shape, set_enabled, 2),
|
||||
MIST_FUNC_DEF(shape, get_enabled, 1)
|
||||
};
|
||||
|
||||
GETSET_PAIR(sprite, color, color)
|
||||
|
@ -1838,7 +1713,7 @@ static const JSCFunctionListEntry js_texture_funcs[] = {
|
|||
MIST_FUNC_DEF(texture, height, 0),
|
||||
MIST_FUNC_DEF(texture, path, 0),
|
||||
MIST_FUNC_DEF(texture, find, 1),
|
||||
//MIST_FUNC_DEF(texture, dimensions, 1),
|
||||
// MIST_FUNC_DEF(texture, dimensions, 1),
|
||||
};
|
||||
|
||||
JSValue constraint_set_max_force (JSContext *js, JSValue this, JSValue val) {
|
||||
|
@ -1966,9 +1841,6 @@ void ffi_load() {
|
|||
globalThis = JS_GetGlobalObject(js);
|
||||
|
||||
DUK_FUNC(make_gameobject, 0)
|
||||
DUK_FUNC(set_body, 3)
|
||||
DUK_FUNC(q_body, 2)
|
||||
DUK_FUNC(spline_cmd, 6)
|
||||
DUK_FUNC(make_circle2d, 1)
|
||||
DUK_FUNC(cmd_circle2d, 6)
|
||||
DUK_FUNC(make_poly2d, 1)
|
||||
|
@ -1976,12 +1848,8 @@ void ffi_load() {
|
|||
DUK_FUNC(make_edge2d, 3)
|
||||
DUK_FUNC(cmd_edge2d, 6)
|
||||
DUK_FUNC(make_model,2);
|
||||
DUK_FUNC(cmd, 6)
|
||||
DUK_FUNC(register_collide, 6)
|
||||
|
||||
DUK_FUNC(ui_text, 8)
|
||||
DUK_FUNC(gui_img, 10)
|
||||
|
||||
DUK_FUNC(inflate_cpv, 3)
|
||||
DUK_FUNC(performance, 2)
|
||||
|
||||
|
@ -2000,6 +1868,7 @@ void ffi_load() {
|
|||
QJSCLASSPREP_FUNCS(texture);
|
||||
QJSCLASSPREP_FUNCS(constraint);
|
||||
QJSCLASSPREP_FUNCS(window);
|
||||
QJSCLASSPREP_FUNCS(drawmodel);
|
||||
|
||||
QJSGLOBALCLASS(os);
|
||||
QJSGLOBALCLASS(nota);
|
||||
|
@ -2015,6 +1884,10 @@ void ffi_load() {
|
|||
QJSGLOBALCLASS(render);
|
||||
QJSGLOBALCLASS(physics);
|
||||
QJSGLOBALCLASS(vector);
|
||||
QJSGLOBALCLASS(spline);
|
||||
QJSGLOBALCLASS(joint);
|
||||
QJSGLOBALCLASS(dspsound);
|
||||
QJSGLOBALCLASS(shape);
|
||||
|
||||
JS_SetPropertyStr(js, prosperon, "version", str2js(VER));
|
||||
JS_SetPropertyStr(js, prosperon, "revision", str2js(COM));
|
||||
|
|
Loading…
Reference in a new issue