unsure
This commit is contained in:
parent
99bd0091f9
commit
5ddf3558ef
|
@ -556,9 +556,8 @@ Object.defineProperty(Object.prototype, 'obscure', {
|
|||
|
||||
Object.defineProperty(Object.prototype, 'mixin', {
|
||||
value: function(obj) {
|
||||
if (typeof obj === 'string') {
|
||||
if (typeof obj === 'string')
|
||||
obj = use(obj);
|
||||
}
|
||||
|
||||
if (obj)
|
||||
Object.mixin(this, obj);
|
||||
|
|
|
@ -4,6 +4,8 @@ debug.urnames = false;
|
|||
debug.termout = true;
|
||||
debug.console = false;
|
||||
debug.cheat = false;
|
||||
debug.meta = false;
|
||||
|
||||
debug.fn_break = function(fn,obj = globalThis) {
|
||||
if (typeof fn !== 'function') return;
|
||||
|
||||
|
|
|
@ -205,6 +205,7 @@ game.tex_hotreload = function()
|
|||
}
|
||||
|
||||
game.texture = function (path) {
|
||||
if (!path) return game.texture("icons/no_text.gif");
|
||||
path = Resources.find_image(path);
|
||||
|
||||
if (!io.exists(path)) {
|
||||
|
|
|
@ -975,6 +975,76 @@ prosperon.make_camera = function()
|
|||
|
||||
var screencolor;
|
||||
|
||||
globalThis.imtoggle = function(name, obj, field) { obj[field] = imgui.checkbox(name, obj[field]); }
|
||||
var replstr = "";
|
||||
|
||||
var imdebug = function()
|
||||
{
|
||||
imtoggle("Physics", debug, 'draw_phys');
|
||||
imtoggle("Bouning boxes", debug, 'draw_bb');
|
||||
imtoggle("Gizmos", debug, 'draw_gizmos');
|
||||
imtoggle("Names", debug, 'draw_names');
|
||||
imtoggle("Sprite nums", debug, 'sprite_nums');
|
||||
imtoggle("Debug overlay", debug, 'show');
|
||||
imtoggle("Show ur names", debug, 'urnames');
|
||||
}
|
||||
|
||||
var imgui_fn = function()
|
||||
{
|
||||
render.imgui_new(window.size.x, window.size.y, 0.01);
|
||||
if (debug.console) debug.console = imgui.window("console", _ => { imgui.text(console.transcript); replstr = imgui.textinput(undefined, replstr); imgui.button("submit", _ => { eval(replstr); replstr = ""; }); });
|
||||
|
||||
imgui.mainmenubar(_=>{
|
||||
imgui.menu("File", _ => {
|
||||
imgui.menu("Game settings", _ => {
|
||||
window.title = imgui.textinput("Title", window.title);
|
||||
window.icon = imgui.textinput("Icon", window.icon);
|
||||
imgui.button("Refresh window", _ => {
|
||||
window.set_icon(game.texture(window.icon));
|
||||
});
|
||||
});
|
||||
imgui.button("quit", os.quit);
|
||||
});
|
||||
imgui.menu("Debug", imdebug);
|
||||
imgui.menu("View", _ => {
|
||||
imtoggle("Profiler", gamestate, 'showprofiler');
|
||||
imtoggle("Terminal out", debug, 'termout');
|
||||
imtoggle("Meta [f7]", debug, 'meta');
|
||||
imtoggle("Cheats [f8]", debug, 'cheat');
|
||||
imtoggle("Console [f9]", debug, 'console');
|
||||
});
|
||||
|
||||
imgui.sokol_gfx();
|
||||
|
||||
imgui.menu("Graphics", _ => {
|
||||
imtoggle("Draw sprites", render, 'draw_sprites');
|
||||
imtoggle("Draw particles", render, 'draw_particles');
|
||||
imtoggle("Draw HUD", render, 'draw_hud');
|
||||
imtoggle("Draw GUI", render, 'draw_gui');
|
||||
imtoggle("Draw gizmos", render, 'draw_gizmos');
|
||||
|
||||
imgui.menu("Window", _ => {
|
||||
window.fullscreen = imgui.checkbox("fullscreen", window.fullscreen);
|
||||
// window.vsync = imgui.checkbox("vsync", window.vsync);
|
||||
imgui.menu("MSAA", _ => {
|
||||
for (var msaa of gamestate.msaa)
|
||||
imgui.button(msaa + "x", _ => window.sample_count = msaa);
|
||||
});
|
||||
imgui.menu("Resolution", _ => {
|
||||
for (var res of gamestate.resolutions)
|
||||
imgui.button(res, _ => window.resolution = res);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
prosperon.menu_hook?.();
|
||||
});
|
||||
|
||||
prosperon.imgui();
|
||||
render.imgui_end();
|
||||
}
|
||||
|
||||
prosperon.render = function()
|
||||
{
|
||||
profile.frame("world");
|
||||
|
@ -1039,9 +1109,8 @@ prosperon.render = function()
|
|||
|
||||
profile.frame("imgui");
|
||||
|
||||
render.imgui_new(window.size.x, window.size.y, 0.01);
|
||||
prosperon.imgui();
|
||||
render.imgui_end();
|
||||
if (debug.show)
|
||||
imgui_fn();
|
||||
|
||||
profile.endframe();
|
||||
|
||||
|
|
|
@ -12,16 +12,6 @@ if (os.sys() === 'macos') {
|
|||
appy.inputs['S-q'] = os.quit;
|
||||
}
|
||||
|
||||
game.op_search = function()
|
||||
{
|
||||
if (!game.ooop) return;
|
||||
game.ooop = imgui.window("operator search", _ => {
|
||||
imgui.text("test");
|
||||
});
|
||||
}
|
||||
|
||||
game.ooop = false;
|
||||
|
||||
//appy.inputs.f12 = function() { mum.debug = !mum.debug; }
|
||||
appy.inputs['C-space'] = function() {
|
||||
game.ooop = !game.ooop;
|
||||
|
@ -258,7 +248,11 @@ Cmdline.register_order("play", function(argv) {
|
|||
game.title = project.title;
|
||||
game.size = [1280,720];
|
||||
window.size = game.size;
|
||||
if (io.exists("config.js"))
|
||||
global.mixin("config.js");
|
||||
else
|
||||
console.warn('No config.js file found. Starting with default parameters.');
|
||||
|
||||
if (project.title) window.title = project.title;
|
||||
|
||||
game.engine_start(function() {
|
||||
|
|
|
@ -13,6 +13,9 @@ static sgimgui_t sgimgui;
|
|||
|
||||
#include "jsffi.h"
|
||||
|
||||
static int wantkeys = 0;
|
||||
static int wantmouse = 0;
|
||||
|
||||
JSC_SCALL(imgui_window,
|
||||
bool active = true;
|
||||
ImGui::Begin(str, &active);
|
||||
|
@ -187,11 +190,12 @@ JSValue gui_init(JSContext *js)
|
|||
return imgui;
|
||||
}
|
||||
|
||||
int gui_input(sapp_event *e)
|
||||
void gui_input(sapp_event *e)
|
||||
{
|
||||
if (started)
|
||||
return simgui_handle_event(e);
|
||||
return 0;
|
||||
simgui_handle_event(e);
|
||||
ImGuiIO io = ImGui::GetIO();
|
||||
wantkeys = io.WantCaptureKeyboard;
|
||||
wantmouse = io.WantCaptureMouse;
|
||||
}
|
||||
|
||||
void gui_newframe(int x, int y, float dt)
|
||||
|
@ -213,3 +217,6 @@ void gui_exit()
|
|||
{
|
||||
sgimgui_discard(&sgimgui);
|
||||
}
|
||||
|
||||
int gui_wantmouse() { return wantmouse; }
|
||||
int gui_wantkeys() { return wantkeys; }
|
||||
|
|
|
@ -11,10 +11,13 @@ extern "C" {
|
|||
JSValue gui_init(JSContext *js);
|
||||
void gui_newframe(int x, int y, float dt);
|
||||
void gfx_gui();
|
||||
int gui_input(sapp_event *e);
|
||||
void gui_input(sapp_event *e);
|
||||
void gui_endframe();
|
||||
void gui_exit();
|
||||
|
||||
int gui_wantmouse();
|
||||
int gui_wantkeys();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -2472,6 +2472,8 @@ JSC_GET(texture, width, number)
|
|||
JSC_GET(texture, height, number)
|
||||
JSC_GET(texture, frames, number)
|
||||
JSC_GET(texture, delays, ints)
|
||||
JSC_GET(texture, size, number)
|
||||
JSC_GET(texture, gpusize, number)
|
||||
|
||||
JSC_SCALL(texture_save, texture_save(js2texture(self), str));
|
||||
|
||||
|
@ -2489,6 +2491,8 @@ static const JSCFunctionListEntry js_texture_funcs[] = {
|
|||
MIST_GET(texture, height),
|
||||
MIST_GET(texture, frames),
|
||||
MIST_GET(texture, delays),
|
||||
MIST_GET(texture, gpusize),
|
||||
MIST_GET(texture, size),
|
||||
MIST_FUNC_DEF(texture, save, 1),
|
||||
MIST_FUNC_DEF(texture, blit, 5),
|
||||
MIST_FUNC_DEF(texture, getid, 0),
|
||||
|
@ -2973,8 +2977,6 @@ JSC_SCALL(os_gltf_skin,
|
|||
cgltf_parse_file(&options,str,&data);
|
||||
cgltf_load_buffers(&options,data,str);
|
||||
|
||||
printf("file %s has %d skins\n", str, data->skins_count);
|
||||
|
||||
if (data->skins_count <= 0) {
|
||||
ret = (JS_UNDEFINED);
|
||||
goto CLEANUP;
|
||||
|
|
|
@ -117,6 +117,8 @@ struct texture *texture_from_file(const char *path) {
|
|||
return NULL;
|
||||
|
||||
tex->data = data;
|
||||
tex->size = tex->width*tex->height*4;
|
||||
tex->gpusize = tex->size;
|
||||
|
||||
unsigned int nw = next_pow2(tex->width);
|
||||
unsigned int nh = next_pow2(tex->height);
|
||||
|
@ -142,6 +144,7 @@ struct texture *texture_from_file(const char *path) {
|
|||
mipdata[i] = malloc(w * h * 4);
|
||||
stbir_resize_uint8_linear(mipdata[i-1], mipw, miph, 0, mipdata[i], w, h, 0, 4);
|
||||
sg_img_data.subimage[0][i] = (sg_range){ .ptr = mipdata[i], .size = w*h*4 };
|
||||
tex->gpusize += w*h*4;
|
||||
|
||||
mipw = w;
|
||||
miph = h;
|
||||
|
@ -159,6 +162,8 @@ struct texture *texture_from_file(const char *path) {
|
|||
for (int i = 1; i < mips; i++)
|
||||
free(mipdata[i]);
|
||||
|
||||
|
||||
|
||||
return tex;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@ struct texture {
|
|||
int width;
|
||||
int height;
|
||||
unsigned char *data;
|
||||
int size;
|
||||
int gpusize;
|
||||
int frames;
|
||||
int *delays;
|
||||
};
|
||||
|
|
|
@ -13,7 +13,6 @@ timer *timer_make()
|
|||
|
||||
void timer_free(timer *t)
|
||||
{
|
||||
printf("before free arrlen if timers is now %d\n", arrlen(timers));
|
||||
for (int i = 0; i < arrlen(timers); i++) {
|
||||
if (timers[i] == t) {
|
||||
arrdelswap(timers,i);
|
||||
|
@ -22,7 +21,6 @@ void timer_free(timer *t)
|
|||
}
|
||||
|
||||
free(t);
|
||||
printf("arrlen if timers is now %d\n", arrlen(timers));
|
||||
}
|
||||
|
||||
void timer_update(double dt)
|
||||
|
|
|
@ -110,34 +110,41 @@ void c_clean() {
|
|||
|
||||
void c_event(const sapp_event *e)
|
||||
{
|
||||
if (gui_input(e) && e->type != SAPP_EVENTTYPE_KEY_UP) return;
|
||||
gui_input(e);
|
||||
char lcfmt[5];
|
||||
switch (e->type) {
|
||||
case SAPP_EVENTTYPE_MOUSE_MOVE:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mousemove([%g, %g], [%g, %g]);", e->mouse_x, e->mouse_y, e->mouse_dx, -e->mouse_dy);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_MOUSE_SCROLL:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mousescroll([%g, %g]);", e->scroll_x, e->scroll_y);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_KEY_DOWN:
|
||||
if (gui_wantkeys()) return;
|
||||
script_evalf("prosperon.keydown(%d, %d);", e->key_code, e->key_repeat);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_KEY_UP:
|
||||
if (gui_wantkeys()) return;
|
||||
script_evalf("prosperon.keyup(%d);", e->key_code);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_MOUSE_UP:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mouseup(%d);", e->mouse_button);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_MOUSE_DOWN:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mousedown(%d);", e->mouse_button);
|
||||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_CHAR:
|
||||
if (gui_wantkeys()) return;
|
||||
if (iswcntrl(e->char_code)) break;
|
||||
snprintf(lcfmt, 5, "%lc", e->char_code);
|
||||
script_evalf("prosperon.textinput(`%s`);", lcfmt);
|
||||
|
@ -176,9 +183,11 @@ void c_event(const sapp_event *e)
|
|||
break;
|
||||
|
||||
case SAPP_EVENTTYPE_MOUSE_ENTER:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mouseenter();");
|
||||
break;
|
||||
case SAPP_EVENTTYPE_MOUSE_LEAVE:
|
||||
if (gui_wantmouse()) return;
|
||||
script_evalf("prosperon.mouseleave();");
|
||||
break;
|
||||
case SAPP_EVENTTYPE_TOUCHES_BEGAN:
|
||||
|
|
Loading…
Reference in a new issue