actors have delay now; fix sprite rendering for painters algo
This commit is contained in:
parent
6b3cea4ca5
commit
7b8be5b4f8
|
@ -14,6 +14,7 @@ actor.spawn = function(script, config){
|
||||||
padawan.timers = [];
|
padawan.timers = [];
|
||||||
padawan.master = this;
|
padawan.master = this;
|
||||||
Object.hide(padawan, "master","timers", "padawans");
|
Object.hide(padawan, "master","timers", "padawans");
|
||||||
|
check_registers(padawan);
|
||||||
this.padawans.push(padawan);
|
this.padawans.push(padawan);
|
||||||
return padawan;
|
return padawan;
|
||||||
};
|
};
|
||||||
|
@ -28,7 +29,9 @@ actor.rm_pawn = function(pawn)
|
||||||
actor.timers = [];
|
actor.timers = [];
|
||||||
actor.kill = function(){
|
actor.kill = function(){
|
||||||
if (this.__dead__) return;
|
if (this.__dead__) return;
|
||||||
this.timers.forEach(t => t.kill());
|
this.timers.forEach(t => t());
|
||||||
|
Player.do_uncontrol(this);
|
||||||
|
Event.rm_obj(this);
|
||||||
if (this.master) this.master.rm_pawn(this);
|
if (this.master) this.master.rm_pawn(this);
|
||||||
this.padawans.forEach(p => p.kill());
|
this.padawans.forEach(p => p.kill());
|
||||||
this.padawans = [];
|
this.padawans = [];
|
||||||
|
@ -40,20 +43,9 @@ actor.kill = function(){
|
||||||
actor.kill.doc = `Remove this actor and all its padawans from existence.`;
|
actor.kill.doc = `Remove this actor and all its padawans from existence.`;
|
||||||
|
|
||||||
actor.delay = function(fn, seconds) {
|
actor.delay = function(fn, seconds) {
|
||||||
var t = Object.create(timer);
|
var t = timer.delay(fn.bind(this), seconds);
|
||||||
t.remain = seconds;
|
|
||||||
t.kill = () => {
|
|
||||||
timer.kill.call(t);
|
|
||||||
delete this.timers[t.toString()];
|
|
||||||
}
|
|
||||||
t.fire = () => {
|
|
||||||
if (this.__dead__) return;
|
|
||||||
fn();
|
|
||||||
t.kill();
|
|
||||||
};
|
|
||||||
Register.appupdate.register(t.update, t);
|
|
||||||
this.timers.push(t);
|
this.timers.push(t);
|
||||||
return function() { t.kill(); };
|
return t;
|
||||||
};
|
};
|
||||||
|
|
||||||
actor.delay.doc = `Call 'fn' after 'seconds' with 'this' set to the actor.`;
|
actor.delay.doc = `Call 'fn' after 'seconds' with 'this' set to the actor.`;
|
||||||
|
|
|
@ -29,6 +29,38 @@ function eval_env(script, env, file)
|
||||||
return cmd(123,script,env,file);
|
return cmd(123,script,env,file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
global.check_registers = function(obj)
|
||||||
|
{
|
||||||
|
if (typeof obj.update === 'function')
|
||||||
|
obj.timers.push(Register.update.register(obj.update.bind(obj)));
|
||||||
|
|
||||||
|
if (typeof obj.physupdate === 'function')
|
||||||
|
obj.timers.push(Register.physupdate.register(obj.physupdate.bind(obj)));
|
||||||
|
|
||||||
|
if (typeof obj.collide === 'function')
|
||||||
|
register_collide(0, obj.collide.bind(obj), obj.body);
|
||||||
|
|
||||||
|
if (typeof obj.separate === 'function')
|
||||||
|
register_collide(3,obj.separate.bind(obj), obj.body);
|
||||||
|
|
||||||
|
if (typeof obj.draw === 'function')
|
||||||
|
obj.timers.push(Register.draw.register(obj.draw.bind(obj), obj));
|
||||||
|
|
||||||
|
if (typeof obj.debug === 'function')
|
||||||
|
obj.timers.push(Register.debug.register(obj.debug.bind(obj)));
|
||||||
|
|
||||||
|
if (typeof obj.gui === 'function')
|
||||||
|
obj.timers.push(Register.gui.register(obj.gui.bind(obj)));
|
||||||
|
|
||||||
|
for (var k in obj) {
|
||||||
|
if (!k.startswith("on_")) continue;
|
||||||
|
var signal = k.fromfirst("on_");
|
||||||
|
Event.observe(signal, obj, obj[k]);
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
eval_env.dov = `Counterpart to /load_env/, but with a string.`;
|
eval_env.dov = `Counterpart to /load_env/, but with a string.`;
|
||||||
|
|
||||||
function feval_env(file, env)
|
function feval_env(file, env)
|
||||||
|
|
|
@ -11,40 +11,6 @@ function obj_unique_name(name, obj)
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
function check_registers(obj)
|
|
||||||
{
|
|
||||||
if (typeof obj.update === 'function')
|
|
||||||
obj.timers.push(Register.update.register(obj.update.bind(obj)));
|
|
||||||
|
|
||||||
if (typeof obj.physupdate === 'function')
|
|
||||||
obj.timers.push(Register.physupdate.register(obj.physupdate.bind(obj)));
|
|
||||||
|
|
||||||
if (typeof obj.collide === 'function')
|
|
||||||
register_collide(0, obj.collide.bind(obj), obj.body);
|
|
||||||
|
|
||||||
if (typeof obj.separate === 'function')
|
|
||||||
register_collide(3,obj.separate.bind(obj), obj.body);
|
|
||||||
|
|
||||||
if (typeof obj.draw === 'function')
|
|
||||||
obj.timers.push(Register.draw.register(obj.draw.bind(obj), obj));
|
|
||||||
|
|
||||||
if (typeof obj.debug === 'function')
|
|
||||||
obj.timers.push(Register.debug.register(obj.debug.bind(obj)));
|
|
||||||
|
|
||||||
if (typeof obj.gui === 'function')
|
|
||||||
obj.timers.push(Register.gui.register(obj.gui.bind(obj)));
|
|
||||||
|
|
||||||
for (var k in obj) {
|
|
||||||
if (!k.startswith("on_")) continue;
|
|
||||||
var signal = k.fromfirst("on_");
|
|
||||||
Event.observe(signal, obj, obj[k]);
|
|
||||||
};
|
|
||||||
|
|
||||||
obj.components.forEach(function(x) {
|
|
||||||
if (typeof x.collide === 'function')
|
|
||||||
register_collide(1, x.collide.bind(x), obj.body, x.shape);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
var gameobject_impl = {
|
var gameobject_impl = {
|
||||||
get pos() {
|
get pos() {
|
||||||
|
@ -378,6 +344,11 @@ var gameobject = {
|
||||||
};
|
};
|
||||||
|
|
||||||
check_registers(ent);
|
check_registers(ent);
|
||||||
|
ent.components.forEach(function(x) {
|
||||||
|
if (typeof x.collide === 'function')
|
||||||
|
register_collide(1, x.collide.bind(x), ent.body, x.shape);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
if (typeof ent.load === 'function') ent.load();
|
if (typeof ent.load === 'function') ent.load();
|
||||||
if (Game.playing())
|
if (Game.playing())
|
||||||
|
@ -749,37 +720,6 @@ gameobject.doc = {
|
||||||
warp_layer: 'Bitmask for selecting what warps should affect this entity.',
|
warp_layer: 'Bitmask for selecting what warps should affect this entity.',
|
||||||
};
|
};
|
||||||
|
|
||||||
var resavi = function(ur, path)
|
|
||||||
{
|
|
||||||
if (!ur) return path;
|
|
||||||
if (path[0] === '/') return path;
|
|
||||||
|
|
||||||
var res = ur.replaceAll('.', '/');
|
|
||||||
var dir = path.dir();
|
|
||||||
if (res.startsWith(dir))
|
|
||||||
return path.base();
|
|
||||||
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
var resani = function(ur, path)
|
|
||||||
{
|
|
||||||
if (!path) return "";
|
|
||||||
if (!ur) return path;
|
|
||||||
if (path[0] === '/') return path.slice(1);
|
|
||||||
|
|
||||||
var res = ur.replaceAll('.', '/');
|
|
||||||
var restry = res + "/" + path;
|
|
||||||
while (!io.exists(restry)) {
|
|
||||||
res = res.updir() + "/";
|
|
||||||
if (res === "/")
|
|
||||||
return path;
|
|
||||||
|
|
||||||
restry = res + path;
|
|
||||||
}
|
|
||||||
return restry;
|
|
||||||
}
|
|
||||||
|
|
||||||
global.ur = {};
|
global.ur = {};
|
||||||
|
|
||||||
if (io.exists(".prosperon/ur.json"))
|
if (io.exists(".prosperon/ur.json"))
|
||||||
|
|
|
@ -366,7 +366,8 @@ Cmdline.register_order("play", function(argv) {
|
||||||
|
|
||||||
Game.engine_start(function() {
|
Game.engine_start(function() {
|
||||||
global.mixin("scripts/sound.js");
|
global.mixin("scripts/sound.js");
|
||||||
global.mixin("game.js");
|
global.game = actor.spawn("game.js");
|
||||||
|
say(`spawned game with ${game.score} points`);
|
||||||
if (project.icon) Window.icon(project.icon);
|
if (project.icon) Window.icon(project.icon);
|
||||||
});
|
});
|
||||||
}, "Play the game present in this folder.");
|
}, "Play the game present in this folder.");
|
||||||
|
@ -423,6 +424,7 @@ Cmdline.register_order("about", function(argv) {
|
||||||
}, "Get information about this game.");
|
}, "Get information about this game.");
|
||||||
|
|
||||||
Cmdline.register_order("ur", function(argv) {
|
Cmdline.register_order("ur", function(argv) {
|
||||||
|
Game.loadurs();
|
||||||
for (var i of ur._list.sort()) say(i);
|
for (var i of ur._list.sort()) say(i);
|
||||||
}, "Get information about the ur types in your game.");
|
}, "Get information about the ur types in your game.");
|
||||||
|
|
||||||
|
|
|
@ -75,7 +75,6 @@ void gif_rec_start(int w, int h, int cpf, int bitdepth)
|
||||||
.render_target = true,
|
.render_target = true,
|
||||||
.width = gif.w,
|
.width = gif.w,
|
||||||
.height = gif.h,
|
.height = gif.h,
|
||||||
// .pixel_format = SG_PIXELFORMAT_DEPTH,
|
|
||||||
.label = "gif depth",
|
.label = "gif depth",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -255,7 +254,6 @@ void render_init() {
|
||||||
mainwin.height = sapp_height();
|
mainwin.height = sapp_height();
|
||||||
sg_setup(&(sg_desc){
|
sg_setup(&(sg_desc){
|
||||||
.environment = sglue_environment(),
|
.environment = sglue_environment(),
|
||||||
// .mtl_force_managed_storage_mode = 1,
|
|
||||||
.logger = { .func = sg_logging },
|
.logger = { .func = sg_logging },
|
||||||
.buffer_pool_size = 1024
|
.buffer_pool_size = 1024
|
||||||
});
|
});
|
||||||
|
@ -320,7 +318,6 @@ void render_init() {
|
||||||
.size = sizeof(gif_quad),
|
.size = sizeof(gif_quad),
|
||||||
.data = gif_quad,
|
.data = gif_quad,
|
||||||
});
|
});
|
||||||
// sg_gif.bind.fs.images[0] = crt_post.img;
|
|
||||||
sg_gif.bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
|
sg_gif.bind.fs.samplers[0] = sg_make_sampler(&(sg_sampler_desc){});
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -367,7 +364,6 @@ void render_init() {
|
||||||
|
|
||||||
void render_winsize()
|
void render_winsize()
|
||||||
{
|
{
|
||||||
// sg_gif.bind.fs.images[0] = crt_post.img;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static cpBody *camera = NULL;
|
static cpBody *camera = NULL;
|
||||||
|
@ -402,7 +398,7 @@ HMM_Vec3 dirl_pos = {4, 100, 20};
|
||||||
|
|
||||||
void full_2d_pass(struct window *window)
|
void full_2d_pass(struct window *window)
|
||||||
{
|
{
|
||||||
//////////// 2D projection
|
// 2D projection
|
||||||
cpVect pos = cam_pos();
|
cpVect pos = cam_pos();
|
||||||
|
|
||||||
projection = HMM_Orthographic_LH_NO(
|
projection = HMM_Orthographic_LH_NO(
|
||||||
|
|
|
@ -50,9 +50,7 @@ static void response_cb(const sfetch_response_t *r)
|
||||||
if (r->finished) {
|
if (r->finished) {
|
||||||
LOADED_GAME = -1;
|
LOADED_GAME = -1;
|
||||||
if (r->failed) {
|
if (r->failed) {
|
||||||
printf("NO GAME\n");
|
|
||||||
LOADED_GAME = -1;
|
LOADED_GAME = -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,14 +144,9 @@ void sprite_initialize() {
|
||||||
[1].format = SG_VERTEXFORMAT_FLOAT2,
|
[1].format = SG_VERTEXFORMAT_FLOAT2,
|
||||||
[2].format = SG_VERTEXFORMAT_UBYTE4N,
|
[2].format = SG_VERTEXFORMAT_UBYTE4N,
|
||||||
[3].format = SG_VERTEXFORMAT_UBYTE4N}},
|
[3].format = SG_VERTEXFORMAT_UBYTE4N}},
|
||||||
// [4].format = SG_VERTEXFORMAT_FLOAT}},
|
|
||||||
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
.primitive_type = SG_PRIMITIVETYPE_TRIANGLE_STRIP,
|
||||||
.label = "sprite pipeline",
|
.label = "sprite pipeline",
|
||||||
.colors[0].blend = blend_trans,
|
.colors[0].blend = blend_trans,
|
||||||
.depth = {
|
|
||||||
.write_enabled = true,
|
|
||||||
.compare = SG_COMPAREFUNC_LESS_EQUAL,
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
bind_sprite.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
bind_sprite.vertex_buffers[0] = sg_make_buffer(&(sg_buffer_desc){
|
||||||
|
|
Loading…
Reference in a new issue