From 0fc2498f90a9e29090260ce9e1022d97c5acf1a4 Mon Sep 17 00:00:00 2001 From: John Alanbrook Date: Wed, 17 Apr 2024 08:57:45 -0500 Subject: [PATCH] Add scripting for rendering colors --- scripts/editor.js | 3 ++- scripts/engine.js | 1 - source/engine/jsffi.c | 19 ++++++++++++++++++- source/engine/render.c | 6 +----- source/engine/render.h | 1 + 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/scripts/editor.js b/scripts/editor.js index 82e94f2..839ff3c 100644 --- a/scripts/editor.js +++ b/scripts/editor.js @@ -8,6 +8,7 @@ game.loadurs(); console.info(`window size: ${window.size}, render size: ${window.rendersize}`); player[0].control(debug); +render.clear_color([35,60,92,255].map(x => x/255)); var show_frame = true; @@ -486,7 +487,7 @@ var editor = { render.text("lock", obj,screenpos()); }); - render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3)); + render.grid(1, editor.grid_size, editor.grid_color); var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); }); var endgrid = game.camera.view2world([window.width, window.height]); diff --git a/scripts/engine.js b/scripts/engine.js index 5760a17..45cdf9c 100644 --- a/scripts/engine.js +++ b/scripts/engine.js @@ -144,7 +144,6 @@ console.transcript = ""; console.say = function(msg) { msg += "\n"; console.print(msg); - return; console.transcript += msg; }; console.log = console.say; diff --git a/source/engine/jsffi.c b/source/engine/jsffi.c index 636affe..3b8e9a3 100644 --- a/source/engine/jsffi.c +++ b/source/engine/jsffi.c @@ -610,6 +610,11 @@ JSC_CCALL(render_end_pass, JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1))) JSC_CCALL(render_set_camera, useproj = projection) JSC_CCALL(render_set_window, useproj = hudproj) +JSC_CCALL(render_clear_color, + sg_color c; + rgba2floats(&c, js2color(argv[0])); + pass_action.colors[0].clear_value = c; +) static const JSCFunctionListEntry js_render_funcs[] = { MIST_FUNC_DEF(render, grid, 3), @@ -625,6 +630,7 @@ static const JSCFunctionListEntry js_render_funcs[] = { MIST_FUNC_DEF(render, text_size, 3), MIST_FUNC_DEF(render, set_camera, 0), MIST_FUNC_DEF(render, set_window, 0), + MIST_FUNC_DEF(render, clear_color, 1), }; JSC_CCALL(gui_flush, text_flush(&useproj)); @@ -897,8 +903,19 @@ static const JSCFunctionListEntry js_io_funcs[] = { JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));) +JSC_GETSET_GLOBAL(disabled_color, color) +JSC_GETSET_GLOBAL(sleep_color, color) +JSC_GETSET_GLOBAL(dynamic_color, color) +JSC_GETSET_GLOBAL(kinematic_color, color) +JSC_GETSET_GLOBAL(static_color, color) + static const JSCFunctionListEntry js_debug_funcs[] = { - MIST_FUNC_DEF(debug, draw_gameobject, 1) + MIST_FUNC_DEF(debug, draw_gameobject, 1), + CGETSET_ADD(global, disabled_color), + CGETSET_ADD(global, sleep_color), + CGETSET_ADD(global, dynamic_color), + CGETSET_ADD(global, kinematic_color), + CGETSET_ADD(global, static_color), }; JSC_CCALL(physics_sgscale, diff --git a/source/engine/render.c b/source/engine/render.c index 2e1782a..4bd3092 100644 --- a/source/engine/render.c +++ b/source/engine/render.c @@ -121,9 +121,6 @@ void capture_screen(int x, int y, int w, int h, const char *path) #include "HandmadeMath.h" -//struct rgba editorClearColor = {35,60,92,255}; -struct rgba editorClearColor = {0,0,0,255}; - sg_pass_action pass_action = {0}; static struct { @@ -236,9 +233,8 @@ void render_init() { sprite_initialize(); model_init(); - sg_color c; - rgba2floats((float*)&c, editorClearColor); + sg_color c = (sg_color){0,0,0,1}; pass_action = (sg_pass_action){ .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c}, }; diff --git a/source/engine/render.h b/source/engine/render.h index 69f8ef9..6241472 100644 --- a/source/engine/render.h +++ b/source/engine/render.h @@ -30,6 +30,7 @@ extern HMM_Vec3 dirl_pos; extern HMM_Mat4 projection; extern HMM_Mat4 hudproj; extern HMM_Mat4 useproj; +extern sg_pass_action pass_action; struct draw_p { float x;