Compare commits
No commits in common. "51f3b5abeb3bf3f5a7c78febae91329171c98caa" and "7e6fc1ffbeb6a490031c94df5f685acbac1b6f95" have entirely different histories.
51f3b5abeb
...
7e6fc1ffbe
|
@ -8,4 +8,16 @@ this.right = function() { return this.pos.x + (window.rendersize.x/2); }
|
|||
|
||||
this.left = function() { return this.pos.x - (window.rendersize.x/2); }
|
||||
|
||||
this.zoom = 1;
|
||||
this.mixin({
|
||||
get zoom() {
|
||||
// var z = game.native.y / window.dimensions.y;
|
||||
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;
|
||||
render.add_zoom(x);
|
||||
},
|
||||
});
|
|
@ -22,7 +22,7 @@ var component = {
|
|||
make(go) {
|
||||
var nc = Object.create(this);
|
||||
nc.gameobject = go;
|
||||
Object.mixin(nc, this._enghook(go));
|
||||
Object.mixin(nc, this._enghook(go.body));
|
||||
assign_impl(nc,this.impl);
|
||||
Object.hide(nc, 'gameobject', 'id');
|
||||
nc.post();
|
||||
|
@ -152,7 +152,7 @@ Object.mixin(os.sprite(true), {
|
|||
os.sprite(true).make = function(go)
|
||||
{
|
||||
var sp = os.sprite();
|
||||
sp.go = go;
|
||||
sp.go = go.body;
|
||||
sp.gameobject = go;
|
||||
return sp;
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ component.edge2d = Object.copy(collider2d, {
|
|||
}
|
||||
|
||||
if (this.hollow) {
|
||||
var hpoints = vector.inflate(spoints, this.hollowt);
|
||||
var hpoints = inflate_cpv(spoints, spoints.length, this.hollowt);
|
||||
if (hpoints.length === spoints.length) return spoints;
|
||||
var arr1 = hpoints.filter(function(x,i) { return i % 2 === 0; });
|
||||
var arr2 = hpoints.filter(function(x,i) { return i % 2 !== 0; });
|
||||
|
|
|
@ -14,7 +14,7 @@ debug.draw_bb = false;
|
|||
debug.draw_gizmos = false;
|
||||
debug.draw_names = false;
|
||||
debug.draw = function() {
|
||||
if (this.draw_phys) game.all_objects(function(x) { debug.draw_gameobject(x); });
|
||||
if (this.draw_phys) game.all_objects(function(x) { debug.draw_gameobject(x.body); });
|
||||
|
||||
if (this.draw_bb)
|
||||
game.all_objects(function(x) { debug.boundingbox(x.boundingbox(), Color.debug.boundingbox.alpha(0.05)); });
|
||||
|
|
|
@ -31,6 +31,8 @@ var editor = {
|
|||
|
||||
get_this() { return this.edit_level; },
|
||||
|
||||
get_that() { return this.selectlist.length === 1 ? this.selectlist[0] : this.get_this(); },
|
||||
|
||||
try_select() { /* nullify true if it should set selected to null if it doesn't find an object */
|
||||
var go = physics.pos_query(Mouse.worldpos());
|
||||
return this.do_select(go);
|
||||
|
@ -235,7 +237,11 @@ var editor = {
|
|||
this.selectlist = [];
|
||||
editor.camera = world.spawn("scripts/camera2d.jso");
|
||||
editor.camera._ed.selectable = false;
|
||||
game.camera = editor.camera;
|
||||
game.view_camera(editor.camera);
|
||||
},
|
||||
|
||||
end_debug() {
|
||||
|
||||
},
|
||||
|
||||
openpanel(panel) {
|
||||
|
|
|
@ -58,6 +58,8 @@ console.doc = {
|
|||
clear: "Clear console."
|
||||
};
|
||||
|
||||
console.stdout_lvl = 1;
|
||||
|
||||
globalThis.global = globalThis;
|
||||
|
||||
function use(file)
|
||||
|
@ -68,7 +70,7 @@ function use(file)
|
|||
var c = io.slurp(file);
|
||||
|
||||
var script = `(function() { ${c} })();`;
|
||||
use.files[file] = os.eval_env(file,script,global);
|
||||
use.files[file] = os.eval_env(file,global,script);
|
||||
|
||||
return use.files[file];
|
||||
}
|
||||
|
@ -88,7 +90,7 @@ function eval_env(script, env, file)
|
|||
file ??= "SCRIPT";
|
||||
console.spam(`eval ${file}`);
|
||||
script = `(function() { ${script}; }).call(this);\n`;
|
||||
return os.eval_env(file,script,env);
|
||||
return os.eval_env(file,env,script);
|
||||
}
|
||||
|
||||
global.check_registers = function(obj)
|
||||
|
@ -100,10 +102,10 @@ global.check_registers = function(obj)
|
|||
obj.timers.push(Register.physupdate.register(obj.physupdate.bind(obj)));
|
||||
|
||||
if (typeof obj.collide === 'function')
|
||||
physics.collide_begin(obj.collide.bind(obj), obj);
|
||||
physics.collide_begin(obj.collide.bind(obj), obj.body);
|
||||
|
||||
if (typeof obj.separate === 'function')
|
||||
physics.collide_separate(obj.separate.bind(obj), obj);
|
||||
physics.collide_separate(obj.separate.bind(obj), obj.body);
|
||||
|
||||
if (typeof obj.draw === 'function')
|
||||
obj.timers.push(Register.draw.register(obj.draw.bind(obj), obj));
|
||||
|
@ -145,7 +147,8 @@ global.mixin("scripts/render.js");
|
|||
global.mixin("scripts/debug.js");
|
||||
|
||||
var frame_t = profile.secs(profile.now());
|
||||
var phys_step = 1/60;
|
||||
var updateMS = 1/60;
|
||||
var physMS = 1/60;
|
||||
|
||||
var sim = {
|
||||
mode: "play",
|
||||
|
@ -182,16 +185,13 @@ function process()
|
|||
|
||||
physlag += dt;
|
||||
|
||||
while (physlag > phys_step) {
|
||||
physlag -= phys_step;
|
||||
prosperon.phys2d_step(phys_step*timescale);
|
||||
prosperon.physupdate(phys_step*timescale);
|
||||
while (physlag > physMS) {
|
||||
physlag -= physMS;
|
||||
prosperon.phys2d_step(physMS*timescale);
|
||||
prosperon.physupdate(physMS*timescale);
|
||||
}
|
||||
|
||||
if (!game.camera)
|
||||
prosperon.window_render(world, 1);
|
||||
else
|
||||
prosperon.window_render(game.camera, game.camera.zoom);
|
||||
prosperon.window_render();
|
||||
render.sprites();
|
||||
render.models();
|
||||
render.emitters();
|
||||
|
@ -224,6 +224,7 @@ game.doc.stop = "Stop game simulation. This does the same thing as 'pause', and
|
|||
game.doc.play = "Resume or start game simulation.";
|
||||
game.doc.editor_mode = "Set to true for the game to only update on input; otherwise the game updates every frame.";
|
||||
game.doc.dt = "Current frame dt.";
|
||||
game.doc.view_camera = "Set the camera for the current view.";
|
||||
game.doc.camera = "Current camera.";
|
||||
|
||||
prosperon.semver = {};
|
||||
|
@ -428,18 +429,37 @@ global.mixin("scripts/actor.js");
|
|||
global.mixin("scripts/entity.js");
|
||||
|
||||
function world_start() {
|
||||
globalThis.world = os.make_gameobject();
|
||||
world.setref(world);
|
||||
gameobject.body = os.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(){};
|
||||
world._ed = {
|
||||
selectable:false,
|
||||
dirty:false,
|
||||
};
|
||||
world.toString = function() { return "world"; };
|
||||
world.master = gameobject;
|
||||
world.ur = "world";
|
||||
world.kill = function() { this.clear(); };
|
||||
world.phys = 2;
|
||||
world.zoom = 1;
|
||||
game.cam = world;
|
||||
|
||||
Object.hide(gameobject, 'timescale');
|
||||
var cam = world.spawn("scripts/camera2d.jso");
|
||||
game.view_camera(cam);
|
||||
}
|
||||
|
||||
global.mixin("scripts/physics.js");
|
||||
|
||||
game.view_camera = function(cam)
|
||||
{
|
||||
game.camera = cam;
|
||||
render.cam_body(game.camera.body);
|
||||
}
|
||||
|
||||
window.title = `Prosperon v${prosperon.version}`;
|
||||
window.size = [500,500];
|
||||
|
|
|
@ -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() {
|
||||
|
@ -56,6 +56,47 @@ var gameobject_impl = {
|
|||
obj.pos = obj.pos.map((x, i) => x * pct[i]);
|
||||
});
|
||||
},
|
||||
|
||||
get draw_layer() { return this.body.drawlayer; },
|
||||
set draw_layer(x) { this.body.drawlayer = x; },
|
||||
set layer(x) { this.body.layer = x; },
|
||||
get layer() { return this.body.layer; },
|
||||
set warp_layer(x) { this.body.warp_filter = x; },
|
||||
get warp_layer() { return this.body.warp_filter; },
|
||||
|
||||
set mass(x) { this.body.mass = x; },
|
||||
get mass() {
|
||||
if (!(this.phys === physics.dynamic))
|
||||
return undefined;
|
||||
|
||||
return this.body.mass;
|
||||
},
|
||||
get elasticity() { return this.body.e; },
|
||||
set elasticity(x) { this.body.e = x; },
|
||||
get friction() { return this.body.f; },
|
||||
set friction(x) { this.body.f = x; },
|
||||
set timescale(x) { this.body.timescale = x; },
|
||||
get timescale() { return this.body.timescale; },
|
||||
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(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 this.body.moi; },
|
||||
set_moi(x) {
|
||||
if (x <= 0) {
|
||||
console.error("Cannot set moment of inertia to 0 or less.");
|
||||
return;
|
||||
}
|
||||
this.body.moi = x;
|
||||
},
|
||||
};
|
||||
|
||||
var gameobject = {
|
||||
|
@ -67,7 +108,6 @@ var gameobject = {
|
|||
if (comps.length) return comps;
|
||||
return undefined;
|
||||
},
|
||||
|
||||
check_dirty() {
|
||||
this._ed.urdiff = this.json_obj();
|
||||
this._ed.dirty = !Object.empty(this._ed.urdiff);
|
||||
|
@ -81,7 +121,6 @@ var gameobject = {
|
|||
else
|
||||
this._ed.inst = false;
|
||||
},
|
||||
|
||||
_ed: {
|
||||
selectable: false,
|
||||
dirty: false
|
||||
|
@ -105,32 +144,32 @@ var gameobject = {
|
|||
},
|
||||
/* pin this object to the to object */
|
||||
pin(to) {
|
||||
var p = joint.pin(this,to);
|
||||
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 = joint.slide(this, to, 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 = joint.pivot(this, to, 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 = joint.groove(to, this, 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 = joint.damped_spring(this, to, [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;
|
||||
|
@ -140,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 = joint.damped_rotary(this, to, angle, stiffness, damping * dc);
|
||||
var p = joint.damped_rotary(this.body, to.body, angle, stiffness, damping * dc);
|
||||
},
|
||||
rotary_limit(to, min, max) {
|
||||
var p = joint.rotary(this, to, 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 = joint.ratchet(this, to, 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 = joint.gear(this, to, phase, ratio);
|
||||
var p = joint.gear(this.body, to.body, phase, ratio);
|
||||
},
|
||||
motor(to, rate) {
|
||||
var p = joint.motor(this, to, rate);
|
||||
var p = joint.motor(this.body, to.body, rate);
|
||||
},
|
||||
|
||||
path_from(o) {
|
||||
|
@ -215,12 +254,15 @@ var gameobject = {
|
|||
return killfn;
|
||||
},
|
||||
|
||||
gscale() { return this.scale; },
|
||||
set torque(x) { if (!(x >= 0 && x <= Infinity)) return;
|
||||
this.body.torque = x; },
|
||||
|
||||
gscale() { return this.body.scale; },
|
||||
sgscale(x) {
|
||||
if (typeof x === 'number')
|
||||
x = [x, x];
|
||||
|
||||
physics.sgscale(this, x)
|
||||
physics.sgscale(this.body, x)
|
||||
},
|
||||
|
||||
phys_material() {
|
||||
|
@ -230,18 +272,21 @@ var gameobject = {
|
|||
return mat;
|
||||
},
|
||||
|
||||
worldpos() { return this.pos; },
|
||||
worldpos() { return this.body.pos; },
|
||||
set_worldpos(x) {
|
||||
var poses = this.objects.map(x => x.pos);
|
||||
this.pos = 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(this.angle); },
|
||||
sworldangle(x) { this.angle = Math.turn2rad(x); },
|
||||
worldangle() { return Math.rad2turn(this.body.angle); },
|
||||
sworldangle(x) { this.body.angle = Math.turn2rad(x); },
|
||||
|
||||
get_ur() { return Object.access(ur, this.ur); },
|
||||
get_ur() {
|
||||
// if (this.ur === 'empty') return undefined;
|
||||
return Object.access(ur, this.ur);
|
||||
},
|
||||
|
||||
/* spawn an entity
|
||||
text can be:
|
||||
|
@ -250,7 +295,7 @@ var gameobject = {
|
|||
nothing
|
||||
*/
|
||||
spawn(text) {
|
||||
var ent = os.make_gameobject();
|
||||
var ent = Object.create(gameobject);
|
||||
|
||||
if (typeof text === 'object')
|
||||
text = text.name;
|
||||
|
@ -273,7 +318,10 @@ var gameobject = {
|
|||
|
||||
console.info(`Creating entity of type ${ent.ur}`);
|
||||
|
||||
Object.mixin(ent, gameobject_impl);
|
||||
ent.body = os.make_gameobject();
|
||||
ent.warp_layer = [true];
|
||||
ent.phys = 2;
|
||||
ent.components = {};
|
||||
ent.objects = {};
|
||||
ent.timers = [];
|
||||
|
@ -287,9 +335,9 @@ var gameobject = {
|
|||
urdiff: {},
|
||||
};
|
||||
|
||||
ent.setref(ent);
|
||||
ent.body.setref(ent); // set the internal obj reference to this obj
|
||||
|
||||
Object.hide(ent, 'ur', 'components', 'objects', '_ed', 'timers', 'master');
|
||||
Object.hide(ent, 'ur', 'body', 'components', 'objects', '_ed', 'timers', 'master');
|
||||
if (ent.ur === 'empty') {
|
||||
if (!ur.empty.proto) ur.empty.proto = json.decode(json.encode(ent));
|
||||
return ent;
|
||||
|
@ -313,9 +361,10 @@ var gameobject = {
|
|||
check_registers(ent);
|
||||
ent.components.forEach(function(x) {
|
||||
if (typeof x.collide === 'function')
|
||||
physics.collide_shape(x.collide.bind(x), ent, x.shape);
|
||||
physics.collide_shape(x.collide.bind(x), ent.body, x.shape);
|
||||
});
|
||||
|
||||
|
||||
if (typeof ent.load === 'function') ent.load();
|
||||
if (sim.playing())
|
||||
if (typeof ent.start === 'function') ent.start();
|
||||
|
@ -338,6 +387,8 @@ var gameobject = {
|
|||
}
|
||||
}
|
||||
|
||||
this.body.phys = this.body.phys; // simple way to sync
|
||||
|
||||
return ent;
|
||||
},
|
||||
|
||||
|
@ -385,14 +436,17 @@ var gameobject = {
|
|||
objects: {},
|
||||
master: undefined,
|
||||
|
||||
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)); },
|
||||
|
||||
in_air() { return this.in_air(); },
|
||||
alive() { return this.body >= 0; },
|
||||
in_air() { return this.body.in_air(); },
|
||||
|
||||
hide() { this.components.forEach(x => x.hide?.());
|
||||
this.objects.forEach(x => x.hide?.()); },
|
||||
|
||||
show() { this.components.forEach(function(x) { x.show?.(); });
|
||||
this.objects.forEach(function(x) { x.show?.(); }); },
|
||||
|
||||
|
@ -430,10 +484,20 @@ var gameobject = {
|
|||
flipx() { return this.scale.x < 0; },
|
||||
flipy() { return this.scale.y < 0; },
|
||||
|
||||
mirror(plane) { this.scale = Vector.reflect(this.scale, plane); },
|
||||
mirror(plane) {
|
||||
this.scale = Vector.reflect(this.scale, plane);
|
||||
},
|
||||
|
||||
save: true,
|
||||
selectable: true,
|
||||
ed_locked: false,
|
||||
|
||||
disable() { this.components.forEach(function(x) { x.disable(); }); },
|
||||
enable() { this.components.forEach(function(x) { x.enable(); }); },
|
||||
sync() {
|
||||
this.components.forEach(function(x) { x.sync?.(); });
|
||||
this.objects.forEach(function(x) { x.sync?.(); });
|
||||
},
|
||||
|
||||
/* Bounding box of the object in world dimensions */
|
||||
boundingbox() {
|
||||
|
@ -539,7 +603,7 @@ var gameobject = {
|
|||
this.timers = [];
|
||||
Event.rm_obj(this);
|
||||
Player.do_uncontrol(this);
|
||||
physics.collide_rm(this);
|
||||
physics.collide_rm(this.body);
|
||||
|
||||
if (this.master) {
|
||||
this.master.remove_obj(this);
|
||||
|
@ -615,16 +679,7 @@ var gameobject = {
|
|||
this.objects[o].obj_descend(fn);
|
||||
},
|
||||
}
|
||||
|
||||
var gop = os.make_gameobject().__proto__;
|
||||
Object.mixin(gop, gameobject);
|
||||
var gsync = gop.sync;
|
||||
gop.sync = function() {
|
||||
gsync.call(this);
|
||||
this.components.forEach(function(x) { x.sync?.(); });
|
||||
this.objects.forEach(function(x) { x.sync(); });
|
||||
}
|
||||
|
||||
Object.mixin(gameobject, gameobject_impl);
|
||||
|
||||
gameobject.spawn.doc = `Spawn an entity of type 'ur' on this entity. Returns the spawned entity.`;
|
||||
|
||||
|
@ -780,3 +835,7 @@ game.loadurs = function() {
|
|||
name: "empty"
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
gameobject
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* On collisions, entities are sent a 'hit' object, which looks like this:
|
||||
var HIT = {
|
||||
normal: "The normal of the collision point.",
|
||||
obj: "The gameobject of the object that collided.",
|
||||
hit: "The gameobject of the object that collided.",
|
||||
sensor: "Boolean for if the colliding object was a sensor.",
|
||||
velocity: "Velocity of the contact.",
|
||||
pos: "Position in world space of the contact.",
|
||||
|
|
|
@ -287,8 +287,9 @@ float phys2d_circle_moi(struct phys2d_circle *c) {
|
|||
return cpMomentForCircle(m, 0, cpCircleShapeGetRadius(c->shape.shape), cpCircleShapeGetOffset(c->shape.shape));
|
||||
}
|
||||
|
||||
void phys2d_circledel(struct phys2d_circle *c) { phys2d_shape_del(&c->shape); }
|
||||
void circle2d_free(circle2d *c) { phys2d_circledel(c); }
|
||||
void phys2d_circledel(struct phys2d_circle *c) {
|
||||
phys2d_shape_del(&c->shape);
|
||||
}
|
||||
|
||||
void phys2d_dbgdrawcpcirc(cpShape *c) {
|
||||
HMM_Vec2 pos = mat_t_pos(t_go2world(shape2go(c)), (HMM_Vec2)cpCircleShapeGetOffset(c));
|
||||
|
@ -309,7 +310,6 @@ void phys2d_shape_apply(struct phys2d_shape *s)
|
|||
float newmoi = s->moi(s->data);
|
||||
moment-=moi;
|
||||
moment += newmoi;
|
||||
if (moment < 0) moment = 0;
|
||||
cpBodySetMoment(s->go->body, moment);
|
||||
}
|
||||
|
||||
|
|
|
@ -47,8 +47,6 @@ struct phys2d_circle {
|
|||
struct phys2d_shape shape;
|
||||
};
|
||||
|
||||
typedef struct phys2d_circle circle2d;
|
||||
|
||||
/* A convex polygon; defined as the convex hull around the given set of points */
|
||||
struct phys2d_poly {
|
||||
HMM_Vec2 *points;
|
||||
|
@ -68,7 +66,6 @@ struct phys2d_edge {
|
|||
|
||||
struct phys2d_circle *Make2DCircle(gameobject *go);
|
||||
void phys2d_circledel(struct phys2d_circle *c);
|
||||
void circle2d_free(circle2d *c);
|
||||
void phys2d_applycircle(struct phys2d_circle *circle);
|
||||
void phys2d_dbgdrawcircle(struct phys2d_circle *circle);
|
||||
float phys2d_circle_moi(struct phys2d_circle *c);
|
||||
|
|
|
@ -546,8 +546,8 @@ void draw_box(HMM_Vec2 c, HMM_Vec2 wh, struct rgba color)
|
|||
|
||||
void draw_grid(float width, float span, struct rgba color)
|
||||
{
|
||||
HMM_Vec2 offset = campos;
|
||||
offset = HMM_MulV2F(offset, 1/camzoom);
|
||||
HMM_Vec2 offset = (HMM_Vec2)cam_pos();
|
||||
offset = HMM_MulV2F(offset, 1/cam_zoom());
|
||||
|
||||
float ubo[4];
|
||||
ubo[0] = offset.x;
|
||||
|
@ -562,7 +562,7 @@ void draw_grid(float width, float span, struct rgba color)
|
|||
|
||||
fs_params_t pt;
|
||||
pt.thickness = (float)width;
|
||||
pt.span = span/camzoom;
|
||||
pt.span = span/cam_zoom();
|
||||
memcpy(&pt.color, col, sizeof(float)*4);
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(ubo));
|
||||
sg_apply_uniforms(SG_SHADERSTAGE_FS, 0, SG_RANGE_REF(pt));
|
||||
|
|
|
@ -75,8 +75,8 @@ transform2d go2t(gameobject *go)
|
|||
unsigned int editor_cat = 1<<31;
|
||||
|
||||
void go_shape_apply(cpBody *body, cpShape *shape, gameobject *go) {
|
||||
cpShapeSetFriction(shape, go->friction);
|
||||
cpShapeSetElasticity(shape, go->elasticity);
|
||||
cpShapeSetFriction(shape, go->f);
|
||||
cpShapeSetElasticity(shape, go->e);
|
||||
cpShapeSetCollisionType(shape, (cpCollisionType)go);
|
||||
|
||||
cpShapeFilter filter;
|
||||
|
@ -105,7 +105,6 @@ void go_shape_moi(cpBody *body, cpShape *shape, gameobject *go) {
|
|||
}
|
||||
|
||||
void gameobject_apply(gameobject *go) {
|
||||
YughInfo("Applying gameobject %p", go);
|
||||
cpBodySetType(go->body, go->phys);
|
||||
cpBodyEachShape(go->body, go_shape_apply, go);
|
||||
|
||||
|
@ -116,6 +115,8 @@ void gameobject_apply(gameobject *go) {
|
|||
|
||||
if (cpBodyGetMoment(go->body) <= 0.f)
|
||||
cpBodySetMoment(go->body, 1.f);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ struct gameobject {
|
|||
HMM_Vec3 scale; /* local */
|
||||
int next;
|
||||
float mass;
|
||||
float friction;
|
||||
float elasticity;
|
||||
float f; /* friction */
|
||||
float e; /* elasticity */
|
||||
float damping;
|
||||
float timescale;
|
||||
float maxvelocity;
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -6,6 +6,7 @@
|
|||
#include "dsp.h"
|
||||
|
||||
void ffi_load();
|
||||
void ffi_stop();
|
||||
|
||||
JSValue vec22js(HMM_Vec2 v);
|
||||
HMM_Vec2 js2vec2(JSValue v);
|
||||
|
|
|
@ -26,9 +26,6 @@
|
|||
|
||||
#include "msf_gif.h"
|
||||
|
||||
HMM_Vec2 campos = {0,0};
|
||||
float camzoom = 1;
|
||||
|
||||
static struct {
|
||||
sg_swapchain swap;
|
||||
sg_pipeline pipe;
|
||||
|
@ -359,10 +356,18 @@ void render_init() {
|
|||
|
||||
}
|
||||
|
||||
static cpBody *camera = NULL;
|
||||
void set_cam_body(cpBody *body) { camera = body; }
|
||||
cpVect cam_pos() { return camera ? cpBodyGetPosition(camera) : cpvzero; }
|
||||
|
||||
static float zoom = 1.f;
|
||||
float cam_zoom() { return zoom; }
|
||||
void add_zoom(float val) { zoom = val; }
|
||||
|
||||
HMM_Vec2 world2screen(HMM_Vec2 pos)
|
||||
{
|
||||
pos = HMM_SubV2(pos, campos);
|
||||
pos = HMM_ScaleV2(pos, 1.0/camzoom);
|
||||
pos = HMM_SubV2(pos, HMM_V2(cam_pos().x, cam_pos().y));
|
||||
pos = HMM_ScaleV2(pos, 1.0/zoom);
|
||||
pos = HMM_AddV2(pos, HMM_ScaleV2(mainwin.size,0.5));
|
||||
return pos;
|
||||
}
|
||||
|
@ -371,8 +376,8 @@ HMM_Vec2 screen2world(HMM_Vec2 pos)
|
|||
{
|
||||
pos = HMM_ScaleV2(pos, 1/mainwin.dpi);
|
||||
pos = HMM_SubV2(pos, HMM_ScaleV2(mainwin.size, 0.5));
|
||||
pos = HMM_ScaleV2(pos, camzoom);
|
||||
pos = HMM_AddV2(pos, campos);
|
||||
pos = HMM_ScaleV2(pos, zoom);
|
||||
pos = HMM_AddV2(pos, HMM_V2(cam_pos().x, cam_pos().y));
|
||||
return pos;
|
||||
}
|
||||
|
||||
|
@ -410,7 +415,7 @@ void full_3d_pass(struct window *window)
|
|||
sg_apply_uniforms(SG_SHADERSTAGE_VS, 0, SG_RANGE_REF(subo));
|
||||
}
|
||||
|
||||
void openglRender(struct window *window, gameobject *cam, float zoom) {
|
||||
void openglRender(struct window *window) {
|
||||
sg_swapchain sch = sglue_swapchain();
|
||||
sg_begin_pass(&(sg_pass){
|
||||
.action = pass_action,
|
||||
|
@ -445,14 +450,13 @@ void openglRender(struct window *window, gameobject *cam, float zoom) {
|
|||
}
|
||||
|
||||
// 2D projection
|
||||
campos = go_pos(cam);
|
||||
camzoom = zoom;
|
||||
cpVect pos = cam_pos();
|
||||
|
||||
projection = HMM_Orthographic_LH_NO(
|
||||
campos.x - camzoom * usesize.x / 2,
|
||||
campos.x + camzoom * usesize.x / 2,
|
||||
campos.y - camzoom * usesize.y / 2,
|
||||
campos.y + camzoom * usesize.y / 2, -10000.f, 10000.f);
|
||||
pos.x - zoom * usesize.x / 2,
|
||||
pos.x + zoom * usesize.x / 2,
|
||||
pos.y - zoom * usesize.y / 2,
|
||||
pos.y + zoom * usesize.y / 2, -10000.f, 10000.f);
|
||||
|
||||
hudproj = HMM_Orthographic_LH_ZO(0, usesize.x, 0, usesize.y, -1.f, 1.f);
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
#include "sokol/sokol_gfx.h"
|
||||
#include "HandmadeMath.h"
|
||||
#include "gameobject.h"
|
||||
|
||||
#define RGBA_MAX 255
|
||||
|
||||
|
@ -53,16 +52,17 @@ enum RenderMode {
|
|||
};
|
||||
|
||||
void render_init();
|
||||
extern HMM_Vec2 campos;
|
||||
extern float camzoom;
|
||||
|
||||
void openglRender(struct window *window, gameobject *cam, float zoom);
|
||||
void openglRender(struct window *window);
|
||||
void opengl_rendermode(enum RenderMode r);
|
||||
|
||||
void openglInit3d(struct window *window);
|
||||
void openglRender3d(struct window *window, camera3d *camera);
|
||||
void capture_screen(int x, int y, int w, int h, const char *path);
|
||||
|
||||
void set_cam_body(cpBody *body);
|
||||
cpVect cam_pos();
|
||||
float cam_zoom();
|
||||
void add_zoom(float val);
|
||||
HMM_Vec2 world2screen(HMM_Vec2 pos);
|
||||
HMM_Vec2 screen2world(HMM_Vec2 pos);
|
||||
|
||||
|
|
|
@ -29,7 +29,9 @@ void script_startup() {
|
|||
|
||||
void script_stop()
|
||||
{
|
||||
script_evalf("Event.notify('quit');");
|
||||
script_evalf("prosperon.quit();");
|
||||
ffi_stop();
|
||||
|
||||
#if LEAK
|
||||
JS_FreeContext(js);
|
||||
|
|
|
@ -207,8 +207,8 @@ void sprite_draw(struct sprite *sprite) {
|
|||
if (!sprite->go) t = t2d_unit;
|
||||
else t = go2t(sprite->go);
|
||||
|
||||
t.pos.x += (campos.x - (campos.x/sprite->parallax));
|
||||
t.pos.y += (campos.y - (campos.y/sprite->parallax));
|
||||
t.pos.x += (cam_pos().x - (cam_pos().x/sprite->parallax));
|
||||
t.pos.y += (cam_pos().y - (cam_pos().y/sprite->parallax));
|
||||
HMM_Mat3 m = transform2d2mat(t);
|
||||
HMM_Mat3 sm = transform2d2mat(sprite2t(sprite));
|
||||
tex_draw(sprite->tex, HMM_MulM3(m,sm), sprite->frame, sprite->color, sprite->drawmode, (HMM_Vec2){0,0}, sprite->scale, sprite->emissive, sprite->parallax);
|
||||
|
|
|
@ -201,7 +201,6 @@ int main(int argc, char **argv) {
|
|||
signal(SIGABRT, seghandle);
|
||||
signal(SIGFPE, seghandle);
|
||||
#endif
|
||||
phys2d_init();
|
||||
|
||||
resources_init();
|
||||
stm_setup(); /* time */
|
||||
|
@ -238,6 +237,7 @@ void engine_start(JSValue start, JSValue procfn)
|
|||
c_process_fn = procfn;
|
||||
|
||||
sound_init();
|
||||
phys2d_init();
|
||||
|
||||
start_desc.width = mainwin.size.x;
|
||||
start_desc.height = mainwin.size.y;
|
||||
|
|
Loading…
Reference in a new issue