This commit is contained in:
John Alanbrook 2023-11-22 09:51:43 +00:00
parent 811d8bb708
commit d047ceb07b
9 changed files with 63 additions and 13 deletions

View file

@ -465,7 +465,7 @@ Object.defineProperty(String.prototype, 'fromfirst', {
value: function(val) { value: function(val) {
var idx = this.indexOf(val); var idx = this.indexOf(val);
if (idx === -1) return this; if (idx === -1) return this;
return this.slice(idx+1); return this.slice(idx+val.length);
} }
}); });

View file

@ -676,6 +676,11 @@ var editor = {
} }
editor.inputs = {}; editor.inputs = {};
editor.inputs.f9 = function() {
Log.warn("CAPTURING");
cmd(173, "capture.bmp", 0, 0, 500, 500);
}
editor.inputs.post = function() { editor.inputs.post = function() {
if (editor.sel_comp && 'sync' in editor.sel_comp) editor.sel_comp.sync(); if (editor.sel_comp && 'sync' in editor.sel_comp) editor.sel_comp.sync();
}; };

View file

@ -639,6 +639,26 @@ var game_quit = function()
Signal.register("quit", game_quit); 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 = { var Window = {
fullscreen(f) { cmd(145, f); }, fullscreen(f) { cmd(145, f); },
set width(w) { cmd(125, w); }, set width(w) { cmd(125, w); },

View file

@ -255,7 +255,6 @@ var gameobject = {
get layer() { cmd(77,this.body); }, get layer() { cmd(77,this.body); },
alive() { return this.body >= 0; }, alive() { return this.body >= 0; },
in_air() { return q_body(7, this.body);}, 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(); }); }, 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(); }); }, 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') if (typeof obj.gui === 'function')
Register.gui.register(obj.gui,obj); 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) { obj.components.forEach(function(x) {
if (typeof x.collide === 'function') if (typeof x.collide === 'function')
register_collide(1, x.collide, x, obj.body, x.shape); register_collide(1, x.collide, x, obj.body, x.shape);

View file

@ -114,8 +114,8 @@ transform3d go2t3(gameobject *go)
t.scale = go->scale; t.scale = go->scale;
t.scale.Z = go->scale.X; t.scale.Z = go->scale.X;
t.rotation = HMM_QFromAxisAngle_RH(vFWD, go2angle(go)); 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(vRIGHT, -t.pos.Y/100), t.rotation);
t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vUP, t.pos.X/70), t.rotation); t.rotation = HMM_MulQ(HMM_QFromAxisAngle_RH(vUP, t.pos.X/100), t.rotation);
return t; return t;
} }

View file

@ -1190,6 +1190,10 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 172: case 172:
js2go(argv[1])->drawlayer = js2number(argv[2]); js2go(argv[1])->drawlayer = js2number(argv[2]);
break; 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) if (str)

View file

@ -15,6 +15,7 @@
#include "resources.h" #include "resources.h"
#include "yugine.h" #include "yugine.h"
#include "sokol/sokol_app.h" #include "sokol/sokol_app.h"
#include "stb_image_write.h"
#include "crt.sglsl.h" #include "crt.sglsl.h"
#include "box.sglsl.h" #include "box.sglsl.h"
@ -46,6 +47,16 @@ static struct {
char *buffer; char *buffer;
} gif; } 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 = {}; MsfGifState gif_state = {};
void gif_rec_start(int w, int h, int cpf, int bitdepth) 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; 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 "sokol/sokol_app.h"
#include "HandmadeMath.h" #include "HandmadeMath.h"
@ -170,14 +192,6 @@ static struct {
sg_shader shader; sg_shader shader;
} sg_shadow; } 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) void trace_make_image(const sg_image_desc *d, sg_image result, void *data)
{ {

View file

@ -70,6 +70,7 @@ void opengl_rendermode(enum RenderMode r);
void openglInit3d(struct window *window); void openglInit3d(struct window *window);
void openglRender3d(struct window *window, struct mCamera *camera); void openglRender3d(struct window *window, struct mCamera *camera);
void capture_screen(int x, int y, int w, int h, char *path);
void render_winsize(); void render_winsize();

View file

@ -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); void *data = stbi_load_from_memory(raw, size, &tex->width, &tex->height, &n, 4);
if (data == NULL) { if (data == NULL) {
YughError("Given raw data no valid. Loading default instead."); YughError("Given raw data not valid. Loading default instead.");
return texture_notex(); return texture_notex();
} }