events
This commit is contained in:
parent
811d8bb708
commit
d047ceb07b
|
@ -465,7 +465,7 @@ Object.defineProperty(String.prototype, 'fromfirst', {
|
|||
value: function(val) {
|
||||
var idx = this.indexOf(val);
|
||||
if (idx === -1) return this;
|
||||
return this.slice(idx+1);
|
||||
return this.slice(idx+val.length);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -676,6 +676,11 @@ var editor = {
|
|||
}
|
||||
|
||||
editor.inputs = {};
|
||||
editor.inputs.f9 = function() {
|
||||
Log.warn("CAPTURING");
|
||||
cmd(173, "capture.bmp", 0, 0, 500, 500);
|
||||
}
|
||||
|
||||
editor.inputs.post = function() {
|
||||
if (editor.sel_comp && 'sync' in editor.sel_comp) editor.sel_comp.sync();
|
||||
};
|
||||
|
|
|
@ -639,6 +639,26 @@ var game_quit = function()
|
|||
|
||||
Signal.register("quit", game_quit);
|
||||
|
||||
var Event = {
|
||||
events: {},
|
||||
|
||||
observe(name, obj, fn) {
|
||||
this.events[name] ??= [];
|
||||
this.events[name].push([obj, fn]);
|
||||
},
|
||||
|
||||
unobserve(name, obj) {
|
||||
this.events[name] = this.events[name].filter(x => x[0] !== obj);
|
||||
},
|
||||
|
||||
notify(name) {
|
||||
if (!this.events[name]) return;
|
||||
this.events[name].forEach(function(x) {
|
||||
x[1].call(x[0]);
|
||||
});
|
||||
},
|
||||
};
|
||||
|
||||
var Window = {
|
||||
fullscreen(f) { cmd(145, f); },
|
||||
set width(w) { cmd(125, w); },
|
||||
|
|
|
@ -255,7 +255,6 @@ var gameobject = {
|
|||
get layer() { cmd(77,this.body); },
|
||||
alive() { return this.body >= 0; },
|
||||
in_air() { return q_body(7, this.body);},
|
||||
on_ground() { return !this.in_air(); },
|
||||
|
||||
hide() { this.components.forEach(function(x) { x.hide(); }); this.objects.forEach(function(x) { x.hide(); }); },
|
||||
show() { this.components.forEach(function(x) { x.show(); }); this.objects.forEach(function(x) { x.show(); }); },
|
||||
|
@ -321,6 +320,13 @@ var gameobject = {
|
|||
if (typeof obj.gui === 'function')
|
||||
Register.gui.register(obj.gui,obj);
|
||||
|
||||
for (var k in obj) {
|
||||
if (!k.startswith("on_")) continue;
|
||||
var signal = k.fromfirst("on_");
|
||||
Event.observe(signal, obj, obj[k]);
|
||||
Log.warn("REGISTERED " + signal);
|
||||
};
|
||||
|
||||
obj.components.forEach(function(x) {
|
||||
if (typeof x.collide === 'function')
|
||||
register_collide(1, x.collide, x, obj.body, x.shape);
|
||||
|
|
|
@ -114,8 +114,8 @@ transform3d go2t3(gameobject *go)
|
|||
t.scale = go->scale;
|
||||
t.scale.Z = go->scale.X;
|
||||
t.rotation = HMM_QFromAxisAngle_RH(vFWD, go2angle(go));
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vRIGHT, -t.pos.Y/70), t.rotation);
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vUP, t.pos.X/70), t.rotation);
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vRIGHT, -t.pos.Y/100), t.rotation);
|
||||
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vUP, t.pos.X/100), t.rotation);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
|
|
@ -1190,6 +1190,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
|
|||
case 172:
|
||||
js2go(argv[1])->drawlayer = js2number(argv[2]);
|
||||
break;
|
||||
case 173:
|
||||
str = js2str(argv[1]);
|
||||
capture_screen(js2number(argv[2]), js2number(argv[3]), js2number(argv[4]), js2number(argv[5]), str);
|
||||
break;
|
||||
}
|
||||
|
||||
if (str)
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "resources.h"
|
||||
#include "yugine.h"
|
||||
#include "sokol/sokol_app.h"
|
||||
#include "stb_image_write.h"
|
||||
|
||||
#include "crt.sglsl.h"
|
||||
#include "box.sglsl.h"
|
||||
|
@ -46,6 +47,16 @@ static struct {
|
|||
char *buffer;
|
||||
} gif;
|
||||
|
||||
static struct {
|
||||
sg_shader shader;
|
||||
sg_pipeline pipe;
|
||||
sg_bindings bind;
|
||||
sg_pass pass;
|
||||
sg_image img;
|
||||
sg_image depth_img;
|
||||
} crt_post;
|
||||
|
||||
|
||||
MsfGifState gif_state = {};
|
||||
void gif_rec_start(int w, int h, int cpf, int bitdepth)
|
||||
{
|
||||
|
@ -100,6 +111,17 @@ void gif_rec_end(char *path)
|
|||
gif.rec = 0;
|
||||
}
|
||||
|
||||
void capture_screen(int x, int y, int w, int h, char *path)
|
||||
{
|
||||
int n = 4;
|
||||
void *data = malloc(w*h*n);
|
||||
sg_query_pixels(0,0,w,h,1,data,w*h*sizeof(char)*n);
|
||||
// sg_query_image_pixels(crt_post.img, crt_post.bind.fs.samplers[0], data, w*h*4);
|
||||
stbi_write_png("cap.png", w, h, n, data, n*w);
|
||||
// stbi_write_bmp("cap.bmp", w, h, n, data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
#include "sokol/sokol_app.h"
|
||||
|
||||
#include "HandmadeMath.h"
|
||||
|
@ -170,14 +192,6 @@ static struct {
|
|||
sg_shader shader;
|
||||
} sg_shadow;
|
||||
|
||||
static struct {
|
||||
sg_shader shader;
|
||||
sg_pipeline pipe;
|
||||
sg_bindings bind;
|
||||
sg_pass pass;
|
||||
sg_image img;
|
||||
sg_image depth_img;
|
||||
} crt_post;
|
||||
|
||||
void trace_make_image(const sg_image_desc *d, sg_image result, void *data)
|
||||
{
|
||||
|
|
|
@ -70,6 +70,7 @@ void opengl_rendermode(enum RenderMode r);
|
|||
|
||||
void openglInit3d(struct window *window);
|
||||
void openglRender3d(struct window *window, struct mCamera *camera);
|
||||
void capture_screen(int x, int y, int w, int h, char *path);
|
||||
|
||||
void render_winsize();
|
||||
|
||||
|
|
|
@ -229,7 +229,7 @@ struct Texture *texture_fromdata(void *raw, long size)
|
|||
void *data = stbi_load_from_memory(raw, size, &tex->width, &tex->height, &n, 4);
|
||||
|
||||
if (data == NULL) {
|
||||
YughError("Given raw data no valid. Loading default instead.");
|
||||
YughError("Given raw data not valid. Loading default instead.");
|
||||
return texture_notex();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue