fix particle render bug
This commit is contained in:
parent
76497fb600
commit
94d4d86944
|
@ -9,17 +9,12 @@ emitter.color = Color.white;
|
|||
|
||||
emitter.draw = function()
|
||||
{
|
||||
var amt = Object.values(this.particles).length;
|
||||
if (amt === 0) return;
|
||||
var pars = Object.values(this.particles);
|
||||
if (pars.length === 0) return;
|
||||
render.use_shader(this.shader);
|
||||
render.use_mat(this);
|
||||
render.make_particle_ssbo(Object.values(this.particles), this.ssbo);
|
||||
render.draw(this.shape, this.ssbo, amt);
|
||||
}
|
||||
|
||||
var std_spawn = function(par)
|
||||
{
|
||||
|
||||
render.make_particle_ssbo(pars, this.ssbo);
|
||||
render.draw(this.shape, this.ssbo, pars.length);
|
||||
}
|
||||
|
||||
var std_step = function(p)
|
||||
|
@ -35,13 +30,7 @@ var std_step = function(p)
|
|||
p.transform.scale = [this.scale,this.scale,this.scale];
|
||||
}
|
||||
|
||||
var std_die = function(par)
|
||||
{
|
||||
}
|
||||
|
||||
emitter.spawn_hook = std_spawn;
|
||||
emitter.step_hook = std_step;
|
||||
emitter.die_hook = std_die;
|
||||
|
||||
emitter.spawn = function(t)
|
||||
{
|
||||
|
@ -53,7 +42,7 @@ emitter.spawn = function(t)
|
|||
par.transform.scale = [this.scale,this.scale,this.scale];
|
||||
this.particles[par.id] = par;
|
||||
par.time = 0;
|
||||
this.spawn_hook(par);
|
||||
this.spawn_hook?.(par);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,7 +81,7 @@ emitter.step = function(dt)
|
|||
this.step_hook?.(p);
|
||||
|
||||
if (p.time >= p.life) {
|
||||
this.die_hook(p);
|
||||
this.die_hook?.(p);
|
||||
this.dead.push(this.particles[p.id]);
|
||||
delete this.particles[p.id];
|
||||
}
|
||||
|
@ -103,6 +92,8 @@ emitter.burst = function(count, t) {
|
|||
for (var i = 0; i < count; i++) this.spawn(t);
|
||||
}
|
||||
|
||||
var emitters = [];
|
||||
|
||||
var make_emitter = function()
|
||||
{
|
||||
var e = Object.create(emitter);
|
||||
|
@ -110,7 +101,19 @@ var make_emitter = function()
|
|||
e.shape = shape.centered_quad;
|
||||
e.shader = "shaders/baseparticle.cg";
|
||||
e.dead = [];
|
||||
emitters.push(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
return {make_emitter};
|
||||
function update_emitters(dt)
|
||||
{
|
||||
for (var e of emitters)
|
||||
e.step(dt);
|
||||
}
|
||||
|
||||
function draw_emitters()
|
||||
{
|
||||
for (var e of emitters) e.draw();
|
||||
}
|
||||
|
||||
return {make_emitter, update_emitters, draw_emitters};
|
||||
|
|
|
@ -295,6 +295,7 @@ window.__proto__.toJSON = function()
|
|||
return {
|
||||
size: this.size,
|
||||
fullscreen: this.fullscreen,
|
||||
title: this.title
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -390,13 +390,6 @@ function shader_apply_material(shader, material = {}, old = {})
|
|||
|
||||
function sg_bind(mesh, ssbo)
|
||||
{
|
||||
if (cur.mesh === mesh && cur.bind) {
|
||||
cur.bind.inst = 1;
|
||||
cur.bind.images = cur.images;
|
||||
render.setbind(cur.bind);
|
||||
return cur.bind;
|
||||
}
|
||||
|
||||
cur.mesh = mesh;
|
||||
|
||||
var bind = {};
|
||||
|
@ -525,6 +518,11 @@ render.init = function() {
|
|||
}
|
||||
}
|
||||
|
||||
render.draw_sprites = true;
|
||||
render.draw_particles = true;
|
||||
render.draw_hud = true;
|
||||
render.draw_gui = true;
|
||||
|
||||
render.sprites = function render_sprites(gridsize = 1)
|
||||
{
|
||||
// When y sorting, draw layer is firstly important followed by the gameobject position
|
||||
|
@ -827,18 +825,6 @@ render.slice9 = function(tex, pos, bb, scale = [tex.width,tex.height], color = C
|
|||
render.draw(shape.quad);
|
||||
}
|
||||
|
||||
render.emitter = function(emit)
|
||||
{
|
||||
var amt = Object.values(emit.particles).length;
|
||||
if (amt === 0) return;
|
||||
render.use_shader(parshader);
|
||||
render.use_mat(emit);
|
||||
var ts = [];
|
||||
for (var p of Object.values(emit.particles)) ts.push([p.transform,p.color]);
|
||||
render.make_particle_ssbo(ts, emit.ssbo);
|
||||
render.draw(shape.quad, emit.ssbo, amt);
|
||||
}
|
||||
|
||||
var textssbo;
|
||||
|
||||
render.flush_text = function()
|
||||
|
@ -984,7 +970,8 @@ prosperon.render = function()
|
|||
profile.frame("world");
|
||||
render.set_camera(prosperon.camera);
|
||||
profile.frame("sprites");
|
||||
render.sprites();
|
||||
if (render.draw_sprites) render.sprites();
|
||||
if (render.draw_particles) draw_emitters();
|
||||
profile.endframe();
|
||||
profile.frame("draws");
|
||||
prosperon.draw();
|
||||
|
@ -996,7 +983,7 @@ prosperon.render = function()
|
|||
profile.endframe();
|
||||
profile.frame("hud");
|
||||
|
||||
prosperon.hud();
|
||||
if (render.draw_hud) prosperon.hud();
|
||||
render.flush_text();
|
||||
|
||||
render.end_pass();
|
||||
|
@ -1029,7 +1016,7 @@ prosperon.render = function()
|
|||
|
||||
// Call gui functions
|
||||
mum.style = mum.dbg_style;
|
||||
prosperon.gui();
|
||||
if (render.draw_gui) prosperon.gui();
|
||||
if (mum.drawinput) mum.drawinput();
|
||||
prosperon.gui_dbg();
|
||||
render.flush_text();
|
||||
|
@ -1078,6 +1065,7 @@ prosperon.process = function process() {
|
|||
if (sim.mode === "play" || sim.mode === "step") {
|
||||
profile.frame("update");
|
||||
prosperon.update(dt * game.timescale);
|
||||
update_emitters(dt * game.timescale);
|
||||
profile.endframe();
|
||||
if (sim.mode === "step") sim.pause();
|
||||
|
||||
|
|
|
@ -22,14 +22,15 @@ audio.bus.master = dspsound.master();
|
|||
audio.dsp = {};
|
||||
audio.dsp = dspsound;
|
||||
|
||||
|
||||
audio.bus.master.__proto__.imgui = function()
|
||||
audio.dsp.mix().__proto__.imgui = function()
|
||||
{
|
||||
imgui.pushid(this.memid());
|
||||
this.volume = imgui.slider("Volume", this.volume);
|
||||
this.off = imgui.checkbox("Mute", this.off);
|
||||
imgui.popid();
|
||||
}
|
||||
|
||||
audio.cry = function(file, bus = audio.bus.master)
|
||||
audio.cry = function(file, bus = audio.bus.sfx)
|
||||
{
|
||||
file = Resources.find_sound(file);
|
||||
var player = audio.play(file, bus);
|
||||
|
@ -83,6 +84,9 @@ audio.music = function(file, fade = 0.5) {
|
|||
audio.bus.music = audio.dsp.mix();
|
||||
audio.bus.music.plugin(audio.bus.master);
|
||||
|
||||
audio.bus.sfx = audio.dsp.mix();
|
||||
audio.bus.sfx.plugin(audio.bus.master);
|
||||
|
||||
audio.dsp.allpass = function(secs, decay) {
|
||||
var composite = {};
|
||||
var fwd = audio.dsp.fwd_delay(secs,-decay);
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#define SOKOL_IMPL
|
||||
#include "sokol/util/sokol_imgui.h"
|
||||
#include "sokol/util/sokol_gfx_imgui.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
static sgimgui_t sgimgui;
|
||||
|
||||
|
@ -82,7 +83,7 @@ JSC_SCALL(imgui_text,
|
|||
|
||||
JSC_SCALL(imgui_button,
|
||||
if (ImGui::Button(str))
|
||||
script_call_sym(argv[1], 0, NULL);
|
||||
script_call_sym(argv[1], 1, argv);
|
||||
)
|
||||
|
||||
JSC_CCALL(imgui_sokol_gfx,
|
||||
|
@ -115,9 +116,17 @@ JSC_SCALL(imgui_checkbox,
|
|||
ret = boolean2js(val);
|
||||
)
|
||||
|
||||
JSC_CCALL(imgui_pushid,
|
||||
ImGui::PushID(js2number(argv[0]));
|
||||
)
|
||||
|
||||
JSC_CCALL(imgui_popid, ImGui::PopID(); )
|
||||
|
||||
static const JSCFunctionListEntry js_imgui_funcs[] = {
|
||||
MIST_FUNC_DEF(imgui, window, 2),
|
||||
MIST_FUNC_DEF(imgui, menu, 2),
|
||||
MIST_FUNC_DEF(imgui, pushid, 1),
|
||||
MIST_FUNC_DEF(imgui, popid, 0),
|
||||
MIST_FUNC_DEF(imgui, slider, 4),
|
||||
MIST_FUNC_DEF(imgui, menubar, 1),
|
||||
MIST_FUNC_DEF(imgui, mainmenubar, 1),
|
||||
|
|
|
@ -1024,7 +1024,6 @@ JSC_CCALL(render_make_particle_ssbo,
|
|||
size_t size = js_arrlen(array)*(sizeof(particle_ss));
|
||||
sg_buffer *b = js2sg_buffer(argv[1]);
|
||||
if (!b) return JS_UNDEFINED;
|
||||
|
||||
particle_ss ms[js_arrlen(array)];
|
||||
|
||||
if (sg_query_buffer_will_overflow(*b, size)) {
|
||||
|
|
Loading…
Reference in a new issue