From fee0d3ffbdd95ba18d779ea5c79ef5f9b36b0460 Mon Sep 17 00:00:00 2001 From: hgn Date: Sun, 19 Oct 2025 23:06:18 +0100 Subject: [PATCH] SWITCH TO SDL3 BECAUSE IT ACTUALLY WORKS --- .gitmodules | 6 + async.kv | 7 - bootstrap.sh | 4 +- build.kv | 2 - foundation.kv | 368 ----- glfw3.kv | 37 - graphics.kv | 4 - include/engine_backend.h | 7 - include/glfw.h | 2 - include/opengl.h | 8 - shaders/blit_blur.fs | 32 - shaders/blit_colour.fs | 9 - shaders/debug_lines.vs | 12 - shaders/loader.fs | 34 - shaders/motion_vectors_common.glsl | 1 - shaders/motion_vectors_fs.glsl | 16 - shaders/motion_vectors_vs.glsl | 14 - shaders/rigidbody_view.fs | 48 - shaders/rigidbody_view.vs | 20 - shaders/ui.fs | 48 - shaders/ui.vs | 17 - shaders/ui_image.fs | 13 - shaders/ui_image.vs | 17 - shaders/ui_image_grad.fs | 22 - shaders/ui_image_hsv.fs | 15 - source/async/async.kv | 13 + source/async/sdl_async.c | 295 ++++ .../{foundation/async.c => async/vg_async.c} | 4 +- .../async/vg_async.h | 9 +- .../console_system.c} | 8 +- .../console_system.h} | 2 +- source/console/console_system.kv | 8 + source/{vg_model => engine}/array_file.c | 12 +- source/{vg_model => engine}/array_file.h | 8 +- source/engine/audio_mixer.c | 26 +- source/engine/console.c | 12 +- source/engine/engine.kv | 399 +++++ source/engine/input.c | 450 ------ source/engine/main.c | 189 --- source/{vg_model => engine}/metascene.c | 8 +- source/{vg_model => engine}/metascene.h | 1 + source/{vg_model => engine}/model.c | 14 +- source/{vg_model => engine}/model.h | 4 +- .../compiler.c => engine/model_compiler.c} | 0 .../compiler.h => engine/model_compiler.h} | 0 .../entity.h => engine/model_entity.h} | 0 source/engine/profiler.c | 2 +- source/{vg_model => engine}/shader_props.h | 0 {shaders => source/engine/shaders}/blit.vs | 0 .../engine/shaders}/blit_tex.fs | 0 .../engine/shaders}/debug_lines.fs | 0 .../shaders}/debug_lines.vs | 0 .../{steamworks.c => steamworks.c_UNUSED} | 8 +- source/engine/texture.c | 430 ------ source/engine/{ui.c => ui.c_UNUSED} | 38 +- source/engine/vg_audio.c | 1358 +++++++++++++++++ source/engine/vg_audio.h | 108 ++ source/engine/vg_audio_dsp.c | 278 ++++ source/engine/vg_audio_dsp.h | 5 + source/engine/vg_audio_vorbis.c | 74 + source/engine/vg_audio_vorbis.h | 11 + source/{vg_camera => engine}/vg_camera.c | 4 +- source/{vg_camera => engine}/vg_camera.h | 0 source/engine/vg_engine.c | 301 ++++ .../engine/vg_engine.h | 4 +- source/engine/vg_engine_core.kv | 379 +++++ source/engine/vg_framebuffer.c | 10 +- source/engine/vg_framebuffer.h | 5 +- source/engine/vg_input.c | 723 +++++++++ .../input_api.h => source/engine/vg_input.h | 8 +- source/{vg_lines => engine}/vg_lines.c | 9 +- source/{vg_lines => engine}/vg_lines.h | 0 source/engine/vg_opengl.h | 3 + source/engine/vg_render.c | 33 + source/engine/vg_render.h | 2 + source/engine/{shader.c => vg_shader.c} | 9 +- source/engine/vg_shader.h | 6 + source/{vg_tex => engine}/vg_tex.c | 14 +- source/{vg_tex => engine}/vg_tex.h | 12 +- source/engine/vg_ui.c | 71 + source/engine/vg_ui.h | 4 + source/foundation/allocator_heap.c | 2 +- source/foundation/allocator_pool.c | 6 +- source/foundation/allocator_queue.c | 6 +- source/foundation/allocator_stack.c | 2 +- source/foundation/allocator_stretchy.c | 3 +- source/foundation/buffer_operations.c | 6 +- source/foundation/exit.c | 27 +- source/foundation/exit_windows.c | 120 ++ .../foundation/foundation.h | 48 +- source/foundation/foundation.kv | 52 + source/foundation/io.c | 7 +- source/foundation/io_windows.c | 25 +- source/foundation/keyvalues.c | 24 +- source/foundation/logging.c | 19 +- source/foundation/options.c | 9 +- source/foundation/stream.c | 18 +- source/foundation/string.c | 8 +- source/foundation/temporary.c | 8 +- source/foundation/threads_c11.c | 25 + source/foundation/threads_sdl.c | 34 + source/graphics/font.c | 6 +- source/graphics/graphics.kv | 5 + source/graphics/graphics_software.c | 6 +- source/graphics/ui.c | 42 +- source/graphics/{graphics.c => vg_graphics.c} | 4 +- .../graphics/vg_graphics.h | 8 +- source/maths/common_maths.c | 135 +- {include => source}/maths/common_maths.h | 28 +- source/maths/maths.kv | 2 + source/maths/random.c | 112 ++ source/maths/random.h | 37 + {include => source}/maths/rigidbody.h | 0 source/thread/primative_sdl2.c | 13 - source/tools/metacompiler.c | 42 +- {include => source}/types.h | 2 +- source/vg_camera/vg_camera.kv | 2 - source/vg_lines/debug_lines.fs | 8 - source/vg_lines/vg_lines.kv | 40 - source/vg_model/model.kv | 4 - source/vg_tex/vg_tex.kv | 8 - source/vg_water/vg_water.c | 261 ---- source/vg_water/vg_water.h | 8 - source/vg_water/vg_water.kv | 12 - source/vg_water/water.fs | 151 -- submodules/SDL | 1 + 126 files changed, 4784 insertions(+), 2736 deletions(-) delete mode 100644 async.kv delete mode 100644 build.kv delete mode 100644 foundation.kv delete mode 100644 glfw3.kv delete mode 100644 graphics.kv delete mode 100644 include/engine_backend.h delete mode 100644 include/glfw.h delete mode 100644 include/opengl.h delete mode 100644 shaders/blit_blur.fs delete mode 100644 shaders/blit_colour.fs delete mode 100644 shaders/debug_lines.vs delete mode 100644 shaders/loader.fs delete mode 100644 shaders/motion_vectors_common.glsl delete mode 100644 shaders/motion_vectors_fs.glsl delete mode 100644 shaders/motion_vectors_vs.glsl delete mode 100644 shaders/rigidbody_view.fs delete mode 100644 shaders/rigidbody_view.vs delete mode 100644 shaders/ui.fs delete mode 100644 shaders/ui.vs delete mode 100644 shaders/ui_image.fs delete mode 100644 shaders/ui_image.vs delete mode 100644 shaders/ui_image_grad.fs delete mode 100644 shaders/ui_image_hsv.fs create mode 100644 source/async/async.kv create mode 100644 source/async/sdl_async.c rename source/{foundation/async.c => async/vg_async.c} (99%) rename include/common_thread_api.h => source/async/vg_async.h (81%) rename source/{console_core.c => console/console_system.c} (95%) rename source/{console_core.h => console/console_system.h} (73%) create mode 100644 source/console/console_system.kv rename source/{vg_model => engine}/array_file.c (95%) rename source/{vg_model => engine}/array_file.h (86%) create mode 100644 source/engine/engine.kv delete mode 100644 source/engine/input.c delete mode 100644 source/engine/main.c rename source/{vg_model => engine}/metascene.c (99%) rename source/{vg_model => engine}/metascene.h (99%) rename source/{vg_model => engine}/model.c (98%) rename source/{vg_model => engine}/model.h (96%) rename source/{vg_model/compiler.c => engine/model_compiler.c} (100%) rename source/{vg_model/compiler.h => engine/model_compiler.h} (100%) rename source/{vg_model/entity.h => engine/model_entity.h} (100%) rename source/{vg_model => engine}/shader_props.h (100%) rename {shaders => source/engine/shaders}/blit.vs (100%) rename {shaders => source/engine/shaders}/blit_tex.fs (100%) rename {shaders => source/engine/shaders}/debug_lines.fs (100%) rename source/{vg_lines => engine/shaders}/debug_lines.vs (100%) rename source/engine/{steamworks.c => steamworks.c_UNUSED} (98%) delete mode 100644 source/engine/texture.c rename source/engine/{ui.c => ui.c_UNUSED} (70%) create mode 100644 source/engine/vg_audio.c create mode 100644 source/engine/vg_audio.h create mode 100644 source/engine/vg_audio_dsp.c create mode 100644 source/engine/vg_audio_dsp.h create mode 100644 source/engine/vg_audio_vorbis.c create mode 100644 source/engine/vg_audio_vorbis.h rename source/{vg_camera => engine}/vg_camera.c (97%) rename source/{vg_camera => engine}/vg_camera.h (100%) create mode 100644 source/engine/vg_engine.c rename include/engine_interface.h => source/engine/vg_engine.h (87%) create mode 100644 source/engine/vg_engine_core.kv create mode 100644 source/engine/vg_input.c rename include/input_api.h => source/engine/vg_input.h (76%) rename source/{vg_lines => engine}/vg_lines.c (98%) rename source/{vg_lines => engine}/vg_lines.h (100%) create mode 100644 source/engine/vg_opengl.h create mode 100644 source/engine/vg_render.c create mode 100644 source/engine/vg_render.h rename source/engine/{shader.c => vg_shader.c} (95%) create mode 100644 source/engine/vg_shader.h rename source/{vg_tex => engine}/vg_tex.c (98%) rename source/{vg_tex => engine}/vg_tex.h (82%) create mode 100644 source/engine/vg_ui.c create mode 100644 source/engine/vg_ui.h create mode 100644 source/foundation/exit_windows.c rename include/common_api.h => source/foundation/foundation.h (88%) create mode 100644 source/foundation/foundation.kv create mode 100644 source/foundation/threads_c11.c create mode 100644 source/foundation/threads_sdl.c create mode 100644 source/graphics/graphics.kv rename source/graphics/{graphics.c => vg_graphics.c} (97%) rename include/graphics_api.h => source/graphics/vg_graphics.h (97%) rename {include => source}/maths/common_maths.h (97%) create mode 100644 source/maths/maths.kv create mode 100644 source/maths/random.c create mode 100644 source/maths/random.h rename {include => source}/maths/rigidbody.h (100%) delete mode 100644 source/thread/primative_sdl2.c rename {include => source}/types.h (91%) delete mode 100644 source/vg_camera/vg_camera.kv delete mode 100644 source/vg_lines/debug_lines.fs delete mode 100644 source/vg_lines/vg_lines.kv delete mode 100644 source/vg_model/model.kv delete mode 100644 source/vg_tex/vg_tex.kv delete mode 100644 source/vg_water/vg_water.c delete mode 100644 source/vg_water/vg_water.h delete mode 100644 source/vg_water/vg_water.kv delete mode 100644 source/vg_water/water.fs create mode 160000 submodules/SDL diff --git a/.gitmodules b/.gitmodules index 8fbe57b..693ee81 100644 --- a/.gitmodules +++ b/.gitmodules @@ -19,3 +19,9 @@ [submodule "submodules/miniaudio"] path = submodules/miniaudio url = https://github.com/mackron/miniaudio.git +[submodule "SDL"] + path = SDL + url = https://github.com/libsdl-org/SDL.git +[submodule "submodules/SDL"] + path = submodules/SDL + url = https://github.com/libsdl-org/SDL.git diff --git a/async.kv b/async.kv deleted file mode 100644 index 51f5f87..0000000 --- a/async.kv +++ /dev/null @@ -1,7 +0,0 @@ -add source/foundation/async.c - -hook -{ - event START - function _async_init -} diff --git a/bootstrap.sh b/bootstrap.sh index b5cadbc..38805e5 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -1,7 +1,8 @@ mkdir -p bin/vg.metacompiler-linux-x86_64-zig-cc/ && taskset -c 0-1 zig cc -I. -I./include/ -fsanitize=address -lasan -Wall -Wno-unused-function -O0 -ggdb \ -std=c11 -D_DEFAULT_SOURCE \ - -include "types.h" \ + -include "source/types.h" \ + -I./source/foundation/ \ source/foundation/options.c \ source/foundation/logging.c \ source/foundation/allocator_heap.c \ @@ -16,6 +17,7 @@ taskset -c 0-1 zig cc -I. -I./include/ -fsanitize=address -lasan -Wall -Wno-unus source/foundation/io.c \ source/foundation/buffer_operations.c \ source/foundation/temporary.c \ + source/foundation/threads_c11.c \ \ source/tools/metacompiler.c \ -o bin/vg.metacompiler-linux-x86_64-zig-cc/vg.metacompiler diff --git a/build.kv b/build.kv deleted file mode 100644 index bfc604d..0000000 --- a/build.kv +++ /dev/null @@ -1,2 +0,0 @@ -include include/ -include source/ diff --git a/foundation.kv b/foundation.kv deleted file mode 100644 index cd18ebd..0000000 --- a/foundation.kv +++ /dev/null @@ -1,368 +0,0 @@ -event -{ - name OPTIONS - prototype "void" -} -event -{ - name START - prototype "void" -} - -add source/foundation/options.c -add source/foundation/logging.c -{ - hook OPTIONS - function _log_options -} - -add source/foundation/allocator_heap.c -add source/foundation/allocator_stack.c -add source/foundation/allocator_pool.c -add source/foundation/allocator_queue.c -add source/foundation/allocator_stretchy.c -add source/foundation/stream.c -add source/foundation/string.c -add source/foundation/keyvalues.c -add source/foundation/buffer_operations.c -add source/foundation/temporary.c - -{ - if linux - add source/foundation/io.c - add source/foundation/exit.c -} - -{ - if windows - add source/foundation/io_windows.c - add source/foundation/exit_windows.c -} - -{ - if terminal - add source/terminal_main.c -} - -{ - - if game_engine - include source/engine - - { - add source/engine/main.c - hook - { - event OPTIONS - function _engine_options - } - - event - { - name ENGINE_NEW_FRAME - prototype "void" - } - event - { - name ENGINE_FIXED_UPDATE - prototype "void" - } - event - { - name ENGINE_RENDER - prototype "void" - } - event - { - name ENGINE_UI - prototype "void" - } - event - { - name ENGINE_WINDOW_RESIZE - prototype "void" - } - } - - { - add source/engine/ui.c - hook - { - event START - function _engine_ui_init - } - } - - { - add source/engine/input.c - hook - { - event START - function _input_init - } - hook - { - event ENGINE_NEW_FRAME - function _input_update - } - ccmd - { - name bind - function _input_bind_ccmd - description "Bind device input to a button, action or axis" - - parameter - { - description "Device input alias" - } - - parameter - { - description "button,action,axis name" - } - } - ccmd - { - name unbind - description "Unbind all bindings that match" - function _input_unbind_ccmd - - parameter - { - description "binding" - } - } - } - - { - add source/console_core.c - hook - { - event START - function _console_init - } - } - - { - add source/engine/console.c - hook - { - event START - function _engine_console_init - } - hook - { - event ENGINE_NEW_FRAME - function _engine_console_update - } - hook - { - event ENGINE_UI - function _engine_console_ui - affinity 9999 - } - } - - { - add source/engine/vg_framebuffer.c - hook - { - event ENGINE_WINDOW_RESIZE - function _framebuffer_resize - } - } - - add source/engine/shader.c - input_layer - { - name console - } - input_layer - { - name ui - } - input - { - name console - type action - layer_mask console - } - - append async.kv - thread - { - name main - queue_size_m 40 - flag MAIN - flag OPENGL - } - thread - { - name async - queue_size_m 40 - flag ASYNC - } - thread - { - name audio - } - thread - { - name exitor - queue_size_m 1 - } - - append graphics.kv - append glfw3.kv - - ccmd - { - name exec - function _console_exec_ccmd - description "Execute a configuration file" - - parameter - { - description "The path to the config" - } - } - config "bind ALT+GRAVE_ACCENT console" - - config "bind BACKSPACE ui_backspace" - config "bind DELETE ui_delete" - config "bind ENTER ui_enter" - config "bind TAB ui_indent" - config "bind HOME ui_home" - config "bind END ui_end" - config "bind LEFT ui_left" - config "bind RIGHT ui_right" - config "bind UP ui_up" - config "bind DOWN ui_down" - config "bind MOUSE_LEFT ui_click" - - config "bind LEFT_SHIFT ui_select" - config "bind RIGHT_SHIFT ui_select" - - input - { - name ui_delete - type action - layer_mask ui - } - input - { - name ui_backspace - type action - layer_mask ui - } - input - { - name ui_enter - type action - layer_mask ui - } - input - { - name ui_indent - type action - layer_mask ui - } - - input - { - name ui_select - type button - layer_mask ui - } - input - { - name ui_home - type button - layer_mask ui - } - input - { - name ui_end - type button - layer_mask ui - } - input - { - name ui_left - type button - layer_mask ui - } - input - { - name ui_right - type button - layer_mask ui - } - input - { - name ui_up - type button - layer_mask ui - } - input - { - name ui_down - type button - layer_mask ui - } - input - { - name ui_click - type action - layer_mask ui - } - - shader - { - name blit - - subshader - { - type vertex - add shaders/blit.vs - - uniform - { - type vec2 - alias uInverseRatio - } - uniform - { - type int - alias uFlip - } - } - - subshader - { - type fragment - add shaders/blit_tex.fs - - uniform - { - type sampler2D - alias uTexMain - } - } - } - - cvar - { - name test - type u32 - default 5 - cheat 1 - description "This is just a test variable!" - } - - hook - { - event START - function "_shaders_compile" - } -} diff --git a/glfw3.kv b/glfw3.kv deleted file mode 100644 index 37acf90..0000000 --- a/glfw3.kv +++ /dev/null @@ -1,37 +0,0 @@ -include dep/glfw-3.4/src -add dep/glfw-3.4/src/init.c -add dep/glfw-3.4/src/input.c -add dep/glfw-3.4/src/monitor.c -add dep/glfw-3.4/src/platform.c -add dep/glfw-3.4/src/context.c -add dep/glfw-3.4/src/window.c -add dep/glfw-3.4/src/vulkan.c - -add dep/glfw-3.4/src/null_init.c -add dep/glfw-3.4/src/null_joystick.c -add dep/glfw-3.4/src/null_monitor.c -add dep/glfw-3.4/src/null_window.c - -include dep/glad.4.3/ -add dep/glad.4.3/glad.c - -{ - if linux - define _GLFW_X11 - add dep/glfw-3.4/src/posix_thread.c - add dep/glfw-3.4/src/posix_poll.c - add dep/glfw-3.4/src/posix_time.c - add dep/glfw-3.4/src/posix_module.c - add dep/glfw-3.4/src/x11_init.c - add dep/glfw-3.4/src/x11_monitor.c - add dep/glfw-3.4/src/x11_window.c - add dep/glfw-3.4/src/linux_joystick.c - add dep/glfw-3.4/src/glx_context.c - add dep/glfw-3.4/src/egl_context.c - add dep/glfw-3.4/src/osmesa_context.c - add dep/glfw-3.4/src/xkb_unicode.c -} - -{ - if windows -} diff --git a/graphics.kv b/graphics.kv deleted file mode 100644 index f6e2877..0000000 --- a/graphics.kv +++ /dev/null @@ -1,4 +0,0 @@ -add source/graphics/font.c -add source/graphics/ui.c -add source/graphics/graphics.c -add source/graphics/graphics_software.c diff --git a/include/engine_backend.h b/include/engine_backend.h deleted file mode 100644 index 7f1621a..0000000 --- a/include/engine_backend.h +++ /dev/null @@ -1,7 +0,0 @@ -void _engine_console_ui(void); -void _engine_console_init(void); - -void _engine_ui_init(void); -void _engine_ui_pre_render(void); -void _engine_ui_post_render(void); -void _engine_ui_input_character( u32 codepoint ); diff --git a/include/glfw.h b/include/glfw.h deleted file mode 100644 index db755b5..0000000 --- a/include/glfw.h +++ /dev/null @@ -1,2 +0,0 @@ -#define GLFW_INCLUDE_NONE -#include "vg/dep/glfw-3.4/include/GLFW/glfw3.h" diff --git a/include/opengl.h b/include/opengl.h deleted file mode 100644 index c59e98d..0000000 --- a/include/opengl.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "vg/dep/glad.4.3/glad/glad.h" -#include "generated/shaders.h" - -GLuint compile_opengl_subshader( GLint type, const c8 *sources[], u32 source_count, bool critical, const c8 *debug_path ); -bool link_opengl_program( GLuint program, bool critical ); - -void _shader_bind( enum shader_id id ); diff --git a/shaders/blit_blur.fs b/shaders/blit_blur.fs deleted file mode 100644 index 592c83f..0000000 --- a/shaders/blit_blur.fs +++ /dev/null @@ -1,32 +0,0 @@ -out vec4 FragColor; -uniform sampler2D uTexMain; -uniform sampler2D uTexMotion; -uniform float uBlurStrength; -uniform vec2 uOverrideDir; -uniform vec2 uClampUv; - -in vec2 aUv; - -vec2 rand_hash22( vec2 p ) -{ - vec3 p3 = fract(vec3(p.xyx) * 213.8976123); - p3 += dot(p3, p3.yzx+19.19); - return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y)); -} - -void main() -{ - vec2 vuv = aUv; - - vec2 vrand = rand_hash22( vuv ) * 2.0 - vec2(1.0); - vec2 vrand1 = rand_hash22( vrand ) * 2.0 - vec2(1.0); - - vec2 vdir = texture( uTexMotion, vuv ).xy * uBlurStrength + uOverrideDir; - - vec4 vcolour0 = texture( uTexMain, min(vuv + vdir*vrand.x,uClampUv) ); - vec4 vcolour1 = texture( uTexMain, min(vuv + vdir*vrand.y,uClampUv) ); - vec4 vcolour2 = texture( uTexMain, min(vuv + vdir*vrand1.x,uClampUv) ); - vec4 vcolour3 = texture( uTexMain, min(vuv + vdir*vrand1.y,uClampUv) ); - - FragColor = ( vcolour0 + vcolour1 + vcolour2 + vcolour3 ) * 0.25; -} diff --git a/shaders/blit_colour.fs b/shaders/blit_colour.fs deleted file mode 100644 index 7eb290e..0000000 --- a/shaders/blit_colour.fs +++ /dev/null @@ -1,9 +0,0 @@ -out vec4 FragColor; -uniform vec4 uColour; - -in vec2 aUv; - -void main() -{ - FragColor = uColour; -} diff --git a/shaders/debug_lines.vs b/shaders/debug_lines.vs deleted file mode 100644 index 2fa61e0..0000000 --- a/shaders/debug_lines.vs +++ /dev/null @@ -1,12 +0,0 @@ -uniform mat4 uPv; -layout (location=0) in vec3 a_co; -layout (location=1) in vec4 a_colour; - -out vec4 s_colour; - -void main() -{ - vec4 vert_pos = uPv * vec4( a_co, 1.0 ); - s_colour = a_colour; - gl_Position = vert_pos; -} diff --git a/shaders/loader.fs b/shaders/loader.fs deleted file mode 100644 index dc265dc..0000000 --- a/shaders/loader.fs +++ /dev/null @@ -1,34 +0,0 @@ -out vec4 FragColor; -uniform float uTime; -uniform float uRatio; -uniform float uOpacity; -in vec2 aUv; - -float eval_zero( vec2 uv ) -{ - vec4 vsines = sin( (uTime+uv.y*80.0) * vec4(1.1,2.0234,3.73,2.444) ); - float gradient = min( uv.y, 0.0 ); - float offset = vsines.x*vsines.y*vsines.z*vsines.w*gradient; - - vec2 vpos = uv + vec2( offset, 0.0 ); - float dist = dot( vpos, vpos ); - - float fring = step(0.1*0.1,dist) * step(dist,0.15*0.15); - return max( 0.0, fring * 1.0+gradient*6.0 ); -} - -void main() -{ - vec3 col = 0.5+0.5*sin( uTime + aUv.xyx + vec3(0.0,2.0,4.0) ); - - vec2 uvx = aUv - vec2( 0.5 ); - uvx.x *= uRatio; - uvx.y *= 0.75; - - float zero = eval_zero( uvx ); - - float dither=fract(dot(vec2(171.0,231.0),gl_FragCoord.xy)/71.0)-0.5; - float fmt1 = step( 0.5, zero*zero + dither )*0.8+0.2; - - FragColor = vec4(vec3(fmt1),uOpacity); -} diff --git a/shaders/motion_vectors_common.glsl b/shaders/motion_vectors_common.glsl deleted file mode 100644 index 7e6c114..0000000 --- a/shaders/motion_vectors_common.glsl +++ /dev/null @@ -1 +0,0 @@ -const float k_motion_lerp_amount = 0.01; diff --git a/shaders/motion_vectors_fs.glsl b/shaders/motion_vectors_fs.glsl deleted file mode 100644 index b92ae2d..0000000 --- a/shaders/motion_vectors_fs.glsl +++ /dev/null @@ -1,16 +0,0 @@ -#include "../vg/shaders/motion_vectors_common.glsl" - -layout (location = 1) out vec4 oMotionVec; - -in vec3 aMotionVec0; -in vec3 aMotionVec1; - -void compute_motion_vectors() -{ - // Write motion vectors - vec2 vmotion0 = aMotionVec0.xy / aMotionVec0.z; - vec2 vmotion1 = aMotionVec1.xy / aMotionVec1.z; - vec2 vmotion = (vmotion1-vmotion0) * (1.0/k_motion_lerp_amount); - - oMotionVec = vec4( vmotion, 0.0, 1.0 ); -} diff --git a/shaders/motion_vectors_vs.glsl b/shaders/motion_vectors_vs.glsl deleted file mode 100644 index 4eee0a6..0000000 --- a/shaders/motion_vectors_vs.glsl +++ /dev/null @@ -1,14 +0,0 @@ -#include "../vg/shaders/motion_vectors_common.glsl" - -out vec3 aMotionVec0; -out vec3 aMotionVec1; - -void vs_motion_out( vec4 vproj0, vec4 vproj1 ) -{ - // This magically solves some artifacting errors! - // - vproj1 = vproj0*(1.0-k_motion_lerp_amount) + vproj1*k_motion_lerp_amount; - - aMotionVec0 = vec3( vproj0.xy, vproj0.w ); - aMotionVec1 = vec3( vproj1.xy, vproj1.w ); -} diff --git a/shaders/rigidbody_view.fs b/shaders/rigidbody_view.fs deleted file mode 100644 index a47829b..0000000 --- a/shaders/rigidbody_view.fs +++ /dev/null @@ -1,48 +0,0 @@ -out vec4 FragColor; -uniform vec4 uColour; - -in vec3 aNorm; -in vec3 aCo; -// The MIT License -// Copyright © 2017 Inigo Quilez -// Permission is hereby granted, free of charge, to any person obtaining a -// copy of this software and associated documentation files (the Software), -// to deal in the Software without restriction, including without limitation -// the rights to use, copy, modify, merge, publish, distribute, sublicense, -// and/or sell copies of the Software, and to permit persons to whom the -// Software is furnished to do so, subject to the following conditions: -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. THE SOFTWARE IS -// PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, -// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -// DEALINGS IN THE SOFTWARE. - -// Info: https://iquilezles.org/articles/filterableprocedurals -// -// More filtered patterns: https://www.shadertoy.com/playlist/l3KXR1 - -vec3 tri( in vec3 x ) -{ - return 1.0-abs(2.0*fract(x/2.0)-1.0); -} - -float checkersTextureGrad( in vec3 p, in vec3 ddx, in vec3 ddy ) -{ - vec3 w = max(abs(ddx), abs(ddy)) + 0.0001; // filter kernel - vec3 i = (tri(p+0.5*w)-tri(p-0.5*w))/w; // analytical integral (box filter) - return 0.5 - 0.5*i.x*i.y*i.z; // xor pattern -} - -void main() -{ - vec3 uvw = aCo; - vec3 ddx_uvw = dFdx( uvw ); - vec3 ddy_uvw = dFdy( uvw ); - float diffuse = checkersTextureGrad( uvw, ddx_uvw, ddy_uvw )*0.5+0.4; - float light = dot( vec3(0.8017,0.5345,-0.2672), aNorm )*0.5 + 0.5; - FragColor = light * diffuse * uColour; -} diff --git a/shaders/rigidbody_view.vs b/shaders/rigidbody_view.vs deleted file mode 100644 index 08fc744..0000000 --- a/shaders/rigidbody_view.vs +++ /dev/null @@ -1,20 +0,0 @@ -uniform mat4 uPv; -uniform mat4x3 uMdl; -uniform mat4x3 uMdl1; -layout (location=0) in vec4 a_co; -layout (location=1) in vec3 a_norm; -out vec3 aNorm; -out vec3 aCo; - -void main() -{ - vec3 world_pos0 = uMdl * vec4( a_co.xyz, 1.0 ); - vec3 world_pos1 = uMdl1 * vec4( a_co.xyz, 1.0 ); - vec3 co = mix( world_pos0, world_pos1, a_co.w ); - vec4 vert_pos = uPv * vec4( co, 1.0 ); - - gl_Position = vert_pos; - vec3 l = vec3(length(uMdl[0]),length(uMdl[1]),length(uMdl[2])); - aNorm = (mat3(uMdl) * a_norm)/l; - aCo = a_co.xyz*l; -} diff --git a/shaders/ui.fs b/shaders/ui.fs deleted file mode 100644 index bf8525d..0000000 --- a/shaders/ui.fs +++ /dev/null @@ -1,48 +0,0 @@ -uniform sampler2D uTexGlyphs; -uniform sampler2D uTexBG; -uniform vec4 uColour; -uniform float uSpread; -out vec4 FragColor; - -in vec4 aTexCoords; -in vec4 aColour; - -vec2 rand_hash22( vec2 p ) -{ - vec3 p3 = fract(vec3(p.xyx) * 213.8976123); - p3 += dot(p3, p3.yzx+19.19); - return fract(vec2((p3.x + p3.y)*p3.z, (p3.x+p3.z)*p3.y)); -} - -void main() -{ - vec4 diffuse = aColour; - - vec4 avg = vec4(0.0); - - if( aColour.a == 0.0 ) - { - avg = aColour; - avg.a = texture( uTexGlyphs, aTexCoords.xy ).r; - } - else - { - if( uSpread > 0.0001 ) - { - for( int i=0; i<4; i ++ ) - { - vec2 spread = rand_hash22(aTexCoords.zw+vec2(float(i))); - avg += texture( uTexBG, aTexCoords.zw + (spread-0.5)*uSpread ); - } - avg *= 0.25; - avg.a = 1.0; - avg.rgb = mix( avg.rgb, aColour.rgb, aColour.a ); - } - else - { - avg = aColour; - } - } - - FragColor = avg * uColour; -} diff --git a/shaders/ui.vs b/shaders/ui.vs deleted file mode 100644 index 37f8b3b..0000000 --- a/shaders/ui.vs +++ /dev/null @@ -1,17 +0,0 @@ -layout (location=0) in vec2 a_co; -layout (location=1) in vec2 a_uv; -layout (location=2) in vec4 a_colour; -uniform mat3 uPv; -uniform vec2 uBGInverseRatio; -uniform vec2 uInverseFontSheet; - -out vec4 aTexCoords; -out vec4 aColour; - -void main() -{ - vec4 proj_pos = vec4( uPv * vec3( a_co, 1.0 ), 1.0 ); - gl_Position = proj_pos; - aTexCoords = vec4( a_uv * uInverseFontSheet, (proj_pos.xy*0.5+0.5) * uBGInverseRatio ); - aColour = a_colour; -} diff --git a/shaders/ui_image.fs b/shaders/ui_image.fs deleted file mode 100644 index 5d45c1d..0000000 --- a/shaders/ui_image.fs +++ /dev/null @@ -1,13 +0,0 @@ -uniform sampler2D uTexImage; -uniform vec4 uColour; -out vec4 FragColor; - -in vec2 aTexCoords; -in vec4 aColour; -in vec2 aWsp; - -void main() -{ - vec4 colour = texture( uTexImage, aTexCoords ); - FragColor = colour * aColour * uColour; -} diff --git a/shaders/ui_image.vs b/shaders/ui_image.vs deleted file mode 100644 index 47f1704..0000000 --- a/shaders/ui_image.vs +++ /dev/null @@ -1,17 +0,0 @@ -layout (location=0) in vec2 a_co; -layout (location=1) in vec2 a_uv; -layout (location=2) in vec4 a_colour; -uniform mat3 uPv; - -out vec2 aTexCoords; -out vec4 aColour; -out vec2 aWsp; - -void main() -{ - gl_Position = vec4( uPv * vec3( a_co, 1.0 ), 1.0 ); - aTexCoords = a_uv * 0.00390625; - aColour = a_colour; - - aWsp = a_co; -} diff --git a/shaders/ui_image_grad.fs b/shaders/ui_image_grad.fs deleted file mode 100644 index 3201908..0000000 --- a/shaders/ui_image_grad.fs +++ /dev/null @@ -1,22 +0,0 @@ -uniform sampler2D uTexImage; -uniform vec4 uColour; -uniform int uLog; -uniform float uScale; - -out vec4 FragColor; - -in vec2 aTexCoords; -in vec4 aColour; -in vec2 aWsp; - -void main() -{ - vec4 colour = texture( uTexImage, aTexCoords ); - float v = colour.r; - if( uLog == 1 ) - { - v = log(v); - } - v *= uScale; - FragColor = vec4(vec3(v)*uColour.rgb,1.0); -} diff --git a/shaders/ui_image_hsv.fs b/shaders/ui_image_hsv.fs deleted file mode 100644 index e98838c..0000000 --- a/shaders/ui_image_hsv.fs +++ /dev/null @@ -1,15 +0,0 @@ -uniform float uHue; -out vec4 FragColor; - -in vec2 aTexCoords; -in vec4 aColour; -in vec2 aWsp; - -void main() -{ - vec3 c = vec3( uHue, aTexCoords ); - vec4 K = vec4(1.0,2.0/3.0,1.0/3.0,3.0); - vec3 p = abs(fract(c.xxx+K.xyz)*6.0 - K.www); - vec3 colour = c.z*mix(K.xxx,clamp(p-K.xxx,0.0,1.0),c.y); - FragColor = vec4( colour, 1.0 ); -} diff --git a/source/async/async.kv b/source/async/async.kv new file mode 100644 index 0000000..dfab494 --- /dev/null +++ b/source/async/async.kv @@ -0,0 +1,13 @@ +include "" + +{ + if SDL + add sdl_async.c +} + +hook +{ + affinity -20000 + event START + function _async_init +} diff --git a/source/async/sdl_async.c b/source/async/sdl_async.c new file mode 100644 index 0000000..c1aa445 --- /dev/null +++ b/source/async/sdl_async.c @@ -0,0 +1,295 @@ +#include "foundation.h" +#include "vg_async.h" +#include "generated/threads.c" +#include "SDL3/SDL.h" + +#define ASYNC_DEBUG_GROUP_COUNTS + +struct thread_context +{ + u16 async_groups[ 8 ]; + u32 async_group_depth; +} +_thread_contexts[ k_thread_count ]; + +struct thread_info *_get_thread_info( enum thread_id thread ) +{ + ASSERT_CRITICAL( thread < k_thread_count ); + return &_thread_infos[ thread ]; +} + +b8 _thread_has_flags( enum thread_id thread, u32 flags ) +{ + return (_get_thread_info( thread )->flags & flags) == flags; +} + +void _async_push_groups( u16 groups, b8 exclusive ) +{ + struct thread_context *context = &_thread_contexts[ _get_thread_id() ]; + + ASSERT_CRITICAL( context->async_group_depth < ARRAY_COUNT( context->async_groups ) ); + context->async_group_depth ++; + if( !exclusive ) + groups |= context->async_groups[ context->async_group_depth-1 ]; + context->async_groups[ context->async_group_depth ] = groups; +} + +void _async_pop_groups(void) +{ + struct thread_context *context = &_thread_contexts[ _get_thread_id() ]; + ASSERT_CRITICAL( context->async_group_depth ); + context->async_group_depth --; +} + +u16 _async_get_groups(void) +{ + struct thread_context *context = &_thread_contexts[ _get_thread_id() ]; + return context->async_groups[ context->async_group_depth ]; +} + +struct +{ + i16 group_counts[ 16 ]; + SDL_Mutex *count_lock; +} +_async; + +struct task_queue +{ + u32 count; + + SDL_Condition *blocking_signal, *work_signal; + SDL_Mutex *lock, *data_lock; + struct queue_allocator queue; + + struct task *allocating_task; +} +static _task_queues[ k_thread_count ]; + +struct task +{ + const c8 *alloc_debug_info; + + union + { + void (*fn)( struct task *task ); + enum thread_id target_thread; + }; + + u32 buffer_size; + u16 groups, unused0; + + union + { + u64 _force_8byte_align[]; + u8 buffer[]; + }; +}; + +_Thread_local enum thread_id _thread_id; + +void _set_thread_id( enum thread_id id ) +{ + _thread_id = id; +} + +enum thread_id _get_thread_id(void) +{ + return _thread_id; +} +void _async_init( void ) +{ + $log( $info, {"[INIT] _async_init"} ); + _async.count_lock = SDL_CreateMutex(); + ASSERT_CRITICAL( _async.count_lock ); + + for( u32 i=0; iqueue_size_m ) + { + struct task_queue *queue = &_task_queues[ i ]; + queue->lock = SDL_CreateMutex(); + queue->data_lock = SDL_CreateMutex(); + queue->blocking_signal = SDL_CreateCondition(); + queue->work_signal = SDL_CreateCondition(); + ASSERT_CRITICAL( queue->lock && queue->data_lock && queue->blocking_signal && queue->work_signal ); + + u32 bytes = BYTES_MB(thread_info->queue_size_m); + queue->queue.buffer = _heap_allocate( bytes ); + queue->queue.size = bytes; + } + } +} + +static void _async_group_increment( u16 groups, i16 dir, const c8 *who ) +{ + if( !groups ) + return; + + SDL_LockMutex( _async.count_lock ); + for( u16 i=0; i<16; i ++ ) + { + if( (groups >> i) & 0x1 ) + { + _async.group_counts[i] += dir; + ASSERT_CRITICAL( _async.group_counts[i] >= 0 ); + ASSERT_CRITICAL( _async.group_counts[i] <= 2048 ); + +#if defined( ASYNC_DEBUG_GROUP_COUNTS ) + $log( $warning, {"The task count for group "}, $unsigned(i), {" has "}, {dir>0? "increased": "decreased"}, + {" to "}, $unsigned(_async.group_counts[i]), {" ("}, {who}, {")"} ); +#endif + } + } + SDL_UnlockMutex( _async.count_lock ); +} + +i16 _async_group_count( u16 group ) +{ + ASSERT_CRITICAL( group ); + u32 index = __builtin_ctz( (u32)group ); + + SDL_LockMutex( _async.count_lock ); + i16 count = _async.group_counts[ index ]; + SDL_UnlockMutex ( _async.count_lock ); + return count; +} + +static struct task_queue *_get_thread_task_queue( enum thread_id thread ) +{ + ASSERT_CRITICAL( thread < k_thread_count ); + return &_task_queues[ thread ]; +} + +b8 _task_queue_can_fit( enum thread_id thread, u32 bytes ) +{ + struct task_queue *queue = _get_thread_task_queue( thread ); + u32 total_size = sizeof(struct task) + bytes; + return total_size <= queue->queue.size; +} + +struct task *_task_new( enum thread_id target_thread, u32 buffer_size, u32 async_flags, const c8 *debug_info ) +{ + ASSERT_CRITICAL( target_thread != _get_thread_id() ); + + struct task_queue *queue = _get_thread_task_queue( target_thread ); + struct queue_allocator *ring = &queue->queue; + u32 total_size = sizeof(struct task) + buffer_size; + ASSERT_CRITICAL( total_size <= queue->queue.size ); + + SDL_LockMutex( queue->data_lock ); + if( queue->allocating_task ) + { + $log( $fatal, {"Overlapping async allocations. \n" + " Previous allocation began at: "}, {queue->allocating_task->alloc_debug_info}, {"\n" + " Overlapping call at: "}, {debug_info} ); + _fatal_exit(); + } + SDL_LockMutex( queue->lock ); + + struct task *task = queue_alloc( ring, total_size ); + while( ((async_flags & ASYNC_CRITICAL) || !(async_flags & ASYNC_NONBLOCKING)) && !task ) + { + if( async_flags & ASYNC_CRITICAL ) + { + $log( $fatal, { "Too many tasks allocated on this queue, so we cant make this (critical allocation)"} ); + _fatal_exit(); + } + + SDL_WaitCondition( queue->blocking_signal, queue->lock ); + task = queue_alloc( ring, total_size ); + } + + if( task ) + { + queue->allocating_task = task; + task->target_thread = target_thread; + task->alloc_debug_info = debug_info; + task->buffer_size = buffer_size; + task->groups = _async_get_groups(); + _async_group_increment( task->groups, +1, task->alloc_debug_info ); + + SDL_UnlockMutex( queue->lock ); + return task; + } + else + { + SDL_UnlockMutex( queue->lock ); + return NULL; + } +} + +void *task_buffer( struct task *task ) +{ + return task->buffer; +} + +u32 task_buffer_size( struct task *task ) +{ + return task->buffer_size; +} + +void task_send( struct task *task, void (*fn)( struct task *task ) ) +{ + struct task_queue *queue = _get_thread_task_queue( task->target_thread ); + + ASSERT_CRITICAL( task ); + ASSERT_CRITICAL( queue->allocating_task == task ); + + if( fn ) task->fn = fn; + else _async_group_increment( task->groups, -1, task->alloc_debug_info ); + queue->allocating_task = NULL; + + SDL_LockMutex( queue->lock ); + queue->count ++; + SDL_UnlockMutex( queue->lock ); + SDL_UnlockMutex( queue->data_lock ); + SDL_SignalCondition( queue->work_signal ); +} + +b8 _task_queue_process( b8 blocking ) +{ + struct task_queue *queue = _get_thread_task_queue( _get_thread_id() ); + SDL_LockMutex( queue->lock ); + + if( blocking ) + { + while( queue->count == 0 ) + SDL_WaitCondition( queue->work_signal, queue->lock ); + } + else + { + if( queue->count == 0) + { + SDL_UnlockMutex( queue->lock ); + return 0; + } + } + + struct task *task = queue_tail_data( &queue->queue ); + SDL_UnlockMutex( queue->lock ); + + if( task ) + { + /* task fn can be NULL if it was cancelled (so this is a NOP). Makes code easier if we do this instead of + * reverting the queue to cancel. */ + if( task->fn ) + { + _async_push_groups( task->groups, 0 ); + task->fn( task ); + _async_pop_groups(); + _async_group_increment( task->groups, -1, task->alloc_debug_info ); + } + + SDL_LockMutex( queue->lock ); + queue_pop( &queue->queue ); + queue->count --; + SDL_UnlockMutex( queue->lock ); + SDL_SignalCondition( queue->blocking_signal ); + return 1; + } + else + return 0; +} diff --git a/source/foundation/async.c b/source/async/vg_async.c similarity index 99% rename from source/foundation/async.c rename to source/async/vg_async.c index 69a9379..c52183b 100644 --- a/source/foundation/async.c +++ b/source/async/vg_async.c @@ -1,5 +1,4 @@ -#include "common_api.h" -#include "common_thread_api.h" +#include "vg_async.h" #include "generated/threads.c" #include @@ -98,7 +97,6 @@ enum thread_id _get_thread_id(void) { return _thread_id; } - void _async_init( void ) { ASSERT_CRITICAL( mtx_init( &_async.count_lock, mtx_plain ) == thrd_success ); diff --git a/include/common_thread_api.h b/source/async/vg_async.h similarity index 81% rename from include/common_thread_api.h rename to source/async/vg_async.h index a149aa6..fd3a412 100644 --- a/include/common_thread_api.h +++ b/source/async/vg_async.h @@ -1,3 +1,4 @@ +#pragma once #include "generated/threads.h" struct thread_info @@ -22,7 +23,7 @@ struct thread_info *_get_thread_info( enum thread_id thread ); void _set_thread_id( enum thread_id id ); enum thread_id _get_thread_id(void); -bool _thread_has_flags( enum thread_id id, u32 flags ); +b8 _thread_has_flags( enum thread_id id, u32 flags ); struct task *_task_new( enum thread_id thread, u32 buffer_size, u32 async_flags, const c8 *debug_info ); void task_send( struct task *task, void (*fn)( struct task *task ) ); @@ -30,12 +31,12 @@ void task_send( struct task *task, void (*fn)( struct task *task ) ); void *task_buffer( struct task *task ); u32 task_buffer_size( struct task *task ); -bool _task_queue_process( bool blocking ); -bool _task_queue_can_fit( enum thread_id thread, u32 bytes ); +b8 _task_queue_process( b8 blocking ); +b8 _task_queue_can_fit( enum thread_id thread, u32 bytes ); void _async_init(void); -void _async_push_groups( u16 groups, bool exclusive ); +void _async_push_groups( u16 groups, b8 exclusive ); void _async_pop_groups(void); u16 _async_get_groups(void); i16 _async_group_count( u16 group ); diff --git a/source/console_core.c b/source/console/console_system.c similarity index 95% rename from source/console_core.c rename to source/console/console_system.c index 5ff9660..c30470f 100644 --- a/source/console_core.c +++ b/source/console/console_system.c @@ -1,5 +1,5 @@ -#include "common_api.h" -#include "console_core.h" +#include "foundation.h" +#include "console_system.h" struct console_command { @@ -22,7 +22,7 @@ i32 _console_exec_ccmd( struct console_arguments *args ) if( !stream_open_file( &file, path, k_stream_read ) ) return -1; - bool more_to_go = 1; + b8 more_to_go = 1; while( more_to_go ) { u32 temp_frame = _start_temporary_frame(); @@ -51,7 +51,7 @@ i32 _console_exec_ccmd( struct console_arguments *args ) return 0; } -void _console_execute( const c8 *command, bool silent, bool cheat_allowed ) +void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed ) { if( !silent ) $log( $shell, {command} ); diff --git a/source/console_core.h b/source/console/console_system.h similarity index 73% rename from source/console_core.h rename to source/console/console_system.h index 91928ac..f2b2329 100644 --- a/source/console_core.h +++ b/source/console/console_system.h @@ -1,7 +1,7 @@ #include "generated/console.h" void _console_init(void); -void _console_execute( const c8 *command, bool silent, bool cheat_allowed ); +void _console_execute( const c8 *command, b8 silent, b8 cheat_allowed ); struct console_arguments { diff --git a/source/console/console_system.kv b/source/console/console_system.kv new file mode 100644 index 0000000..8dd9a96 --- /dev/null +++ b/source/console/console_system.kv @@ -0,0 +1,8 @@ +include "" +add console_system.c + +hook +{ + event START + function _console_init +} diff --git a/source/vg_model/array_file.c b/source/engine/array_file.c similarity index 95% rename from source/vg_model/array_file.c rename to source/engine/array_file.c index 415b833..74df834 100644 --- a/source/vg_model/array_file.c +++ b/source/engine/array_file.c @@ -1,4 +1,4 @@ -#include "common_api.h" +#include "foundation.h" #include "array_file.h" u32 af_str_hash( const void *packed_strings, u32 pstr ) @@ -15,7 +15,7 @@ const c8 *af_str( const void *packed_strings, u32 pstr ) return packed_strings + pstr + 4; } -bool af_str_eq( const void *packed_strings, u32 pstr, const c8 *str, u32 str_hash ) +b8 af_str_eq( const void *packed_strings, u32 pstr, const c8 *str, u32 str_hash ) { if( af_str_hash( packed_strings, pstr ) == str_hash ) if( compare_buffers( str, 0, af_str( packed_strings, pstr ), 0 )) @@ -81,7 +81,7 @@ struct array_file_meta *af_find_array( struct array_file_context *ctx, const c8 return NULL; } -bool af_load_array( struct array_file_context *ctx, struct array_file_ptr *ptr, const c8 *name, +b8 af_load_array( struct array_file_context *ctx, struct array_file_ptr *ptr, const c8 *name, struct stack_allocator *stack, u32 stride ) { struct array_file_meta *arr = af_find_array( ctx, name ); @@ -100,7 +100,7 @@ bool af_load_array( struct array_file_context *ctx, struct array_file_ptr *ptr, } } -bool af_open_stream( struct array_file_context *afc, struct stream *stream, u32 min_version, u32 max_version, +b8 af_open_stream( struct array_file_context *afc, struct stream *stream, u32 min_version, u32 max_version, struct stack_allocator *stack ) { afc->stream = stream; @@ -140,7 +140,7 @@ static void af_init_iterator( struct af_compiler_iter *iter, struct af_compiler_ iter->data = NULL; } -static bool af_next( struct af_compiler_iter *iter ) +static b8 af_next( struct af_compiler_iter *iter ) { if( iter->i == 0 ) { @@ -264,7 +264,7 @@ struct af_compiler_index *af_get_or_make_index( struct af_compiler *compiler, co return af_compiler_create_index( compiler, alias, element_size ); } -bool af_write( struct af_compiler *compiler, const c8 *path, u32 version ) +b8 af_write( struct af_compiler *compiler, const c8 *path, u32 version ) { u32 indices_to_write = 0; diff --git a/source/vg_model/array_file.h b/source/engine/array_file.h similarity index 86% rename from source/vg_model/array_file.h rename to source/engine/array_file.h index 75b6113..68f9739 100644 --- a/source/vg_model/array_file.h +++ b/source/engine/array_file.h @@ -34,7 +34,7 @@ struct array_file_meta *af_find_array( struct array_file_context *ctx, const c8 void af_load_array_file( struct array_file_context *ctx, struct array_file_ptr *out_ptr, struct array_file_meta *arr, struct stack_allocator *stack, u32 stride ); -bool af_load_array( struct array_file_context *ctx, struct array_file_ptr *ptr, const c8 *name, +b8 af_load_array( struct array_file_context *ctx, struct array_file_ptr *ptr, const c8 *name, struct stack_allocator *stack, u32 stride ); void af_load_array_file_buffer( struct array_file_context *ctx, struct array_file_meta *arr, void *buffer, u32 stride ); @@ -45,7 +45,7 @@ u32 af_arrcount( struct array_file_ptr *arr ); /* packed string buffer access (with djb2 hash prefix) */ const c8 *af_str( const void *packed_strings, u32 pstr ); u32 af_str_hash( const void *packed_strings, u32 pstr ); -bool af_str_eq( const void *packed_strings, u32 pstr, const char *str, u32 str_hash ); +b8 af_str_eq( const void *packed_strings, u32 pstr, const char *str, u32 str_hash ); #define AF_STR_EQ( CTX, PSTR, CONSTR ) \ af_str_eq( CTX, PSTR, CONSTR, vg_strdjb2( CONSTR ) ) @@ -81,9 +81,9 @@ struct af_compiler void af_compiler_init( struct af_compiler *compiler, struct stack_allocator *stack ); struct af_compiler_item *af_compiler_allocate_items( struct af_compiler *compiler, struct af_compiler_index *index, u32 count ); struct af_compiler_index *af_compiler_create_index( struct af_compiler *compiler, const c8 *alias, u32 element_size ); -bool af_write( struct af_compiler *compiler, const c8 *path, u32 version ); +b8 af_write( struct af_compiler *compiler, const c8 *path, u32 version ); struct af_compiler_index *af_get_or_make_index( struct af_compiler *compiler, const c8 *alias, u32 element_size ); u32 af_compile_string( struct af_compiler *compiler, const c8 *string ); -bool af_open_stream( struct array_file_context *afc, struct stream *stream, u32 min_version, u32 max_version, +b8 af_open_stream( struct array_file_context *afc, struct stream *stream, u32 min_version, u32 max_version, struct stack_allocator *stack ); diff --git a/source/engine/audio_mixer.c b/source/engine/audio_mixer.c index 56aee24..0209e62 100644 --- a/source/engine/audio_mixer.c +++ b/source/engine/audio_mixer.c @@ -4,7 +4,7 @@ struct vg_audio _vg_audio = .dsp_enabled_ui = 1 }; -_Thread_local static bool _vg_audio_thread_has_lock = 0; +_Thread_local static b8 _vg_audio_thread_has_lock = 0; void vg_audio_lock(void) { @@ -30,7 +30,7 @@ static void vg_audio_assert_lock(void) /* clip loading from disk * ------------------------------------------------------------------------------- */ -VG_TIER_2 bool vg_audio_clip_load( audio_clip *clip, vg_stack_allocator *stack ) +VG_TIER_2 b8 vg_audio_clip_load( audio_clip *clip, vg_stack_allocator *stack ) { VG_ASSERT( _vg_thread_has_flags( VG_THREAD_BACKGROUND ) ); @@ -333,7 +333,7 @@ void vg_audio_sync_ui_master_controls(void) _vg_audio.controls.dsp_enabled = _vg_audio.dsp_enabled_ui; } -void vg_audio_set_channel_volume( audio_channel_id id, f64 volume, bool instant ) +void vg_audio_set_channel_volume( audio_channel_id id, f64 volume, b8 instant ) { vg_audio_assert_lock(); @@ -358,7 +358,7 @@ void vg_audio_set_channel_volume_slew_duration( audio_channel_id id, f64 length_ controls->volume_slew_rate_per_sample = (f64)AUDIO_VOLUME_100 / (length_seconds * 44100.0); } -void vg_audio_set_channel_pan( audio_channel_id id, f64 pan, bool instant ) +void vg_audio_set_channel_pan( audio_channel_id id, f64 pan, b8 instant ) { vg_audio_assert_lock(); @@ -431,7 +431,7 @@ audio_channel_id vg_audio_crossfade( audio_channel_id id, audio_clip *new_clip, return new_id; } -bool vg_audio_is_channel_using_clip( audio_channel_id id, audio_clip *clip ) +b8 vg_audio_is_channel_using_clip( audio_channel_id id, audio_clip *clip ) { vg_audio_assert_lock(); audio_channel *channel = get_audio_channel( id ); @@ -460,7 +460,7 @@ void vg_audio_fadeout_flagged_audio( u32 flag, f32 length ) } } -bool vg_audio_flagged_stopped( u32 flag ) +b8 vg_audio_flagged_stopped( u32 flag ) { vg_audio_lock(); for( u32 id=1; id<=AUDIO_CHANNELS; id ++ ) @@ -480,14 +480,14 @@ bool vg_audio_flagged_stopped( u32 flag ) return 1; } -void vg_audio_set_channel_pause( audio_channel_id id, bool pause ) +void vg_audio_set_channel_pause( audio_channel_id id, b8 pause ) { vg_audio_assert_lock(); struct audio_channel_controls *controls = get_audio_channel_controls( id ); controls->pause = pause; } -void vg_audio_set_flagged_pause( u32 flag, bool pause ) +void vg_audio_set_flagged_pause( u32 flag, b8 pause ) { vg_audio_assert_lock(); for( u32 id=1; id<=AUDIO_CHANNELS; id ++ ) @@ -747,8 +747,8 @@ static void audio_channel_mix( audio_channel_id id, { struct audio_channel_state *state = get_audio_channel_state( id ); - bool is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0; - bool use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1; + b8 is_3d = controls->flags & AUDIO_FLAG_SPACIAL_3D? 1: 0; + b8 use_doppler = controls->flags & AUDIO_FLAG_NO_DOPPLER? 0: 1; f32 frame_sample_rate = controls->sampling_rate_multiplier; @@ -1103,7 +1103,7 @@ static void _vg_audio_mixer( void *user, u8 *stream, int byte_count ) if( controls->flags & AUDIO_FLAG_RELINQUISHED ) { - bool die = 0; + b8 die = 0; if( state->activity == k_channel_activity_end ) die = 1; if( state->activity == k_channel_activity_error ) die = 1; if( state->volume == 0 ) die = 1; @@ -1153,7 +1153,7 @@ static void cb_vg_audio_view( ui_context *ctx, ui_rect rect, struct vg_magi_pane ui_rect row; ui_split( panel, k_ui_axis_h, 18, 1, row, panel ); - bool show_row = ui_clip( rect, row, row ); + b8 show_row = ui_clip( rect, row, row ); if( channel->stage == k_channel_stage_none ) { @@ -1445,7 +1445,7 @@ VG_API void _vg_audio_init(void) void vg_audio_preupdate(void) { - bool before_working = _vg_audio.working; + b8 before_working = _vg_audio.working; _vg_audio.working = 1; if( _vg_audio.sdl_output_device == 0 ) _vg_audio.working = 0; diff --git a/source/engine/console.c b/source/engine/console.c index f493c3a..735580f 100644 --- a/source/engine/console.c +++ b/source/engine/console.c @@ -1,13 +1,13 @@ -#include "common_api.h" -#include "console_core.h" -#include "graphics_api.h" -#include "engine_interface.h" -#include "input_api.h" +#include "foundation.h" +#include "console_system.h" +#include "vg_graphics.h" +#include "vg_engine.h" +#include "vg_input.h" struct { struct queue_allocator input_history, log_history; - bool open; + b8 open; } _console; diff --git a/source/engine/engine.kv b/source/engine/engine.kv new file mode 100644 index 0000000..0c66c16 --- /dev/null +++ b/source/engine/engine.kv @@ -0,0 +1,399 @@ +include "" +append ../maths/maths.kv + +include ../../submodules/SDL/include +include ../../dep/glad.4.3/ +add ../../dep/glad.4.3/glad.c + +enable SDL +append ../foundation/foundation.kv + +{ + add vg_engine.c + hook + { + event OPTIONS + function _engine_options + } + event + { + name ENGINE_NEW_FRAME + prototype "void" + } + event + { + name ENGINE_FIXED_UPDATE + prototype "void" + } + event + { + name ENGINE_RENDER + prototype "void" + } + event + { + name ENGINE_UI + prototype "void" + } + event + { + name ENGINE_WINDOW_RESIZE + prototype "void" + } +} + +{ + add vg_ui.c + hook + { + event START + function _engine_ui_init + } +} + +{ + add vg_input.c + hook + { + event START + function _input_init + } + hook + { + event ENGINE_NEW_FRAME + function _input_update + } + ccmd + { + name bind + function _input_bind_ccmd + description "Bind device input to a button, action or axis" + + parameter + { + description "Device input alias" + } + + parameter + { + description "button,action,axis name" + } + } + ccmd + { + name unbind + description "Unbind all bindings that match" + function _input_unbind_ccmd + + parameter + { + description "binding" + } + } +} + +append ../console/console_system.kv +{ + add console.c + hook + { + event START + function _engine_console_init + } + hook + { + event ENGINE_NEW_FRAME + function _engine_console_update + } + hook + { + event ENGINE_UI + function _engine_console_ui + affinity 9999 + } +} + +{ + add vg_framebuffer.c + hook + { + event ENGINE_WINDOW_RESIZE + function _framebuffer_resize + } +} + +{ + add vg_render.c + hook + { + event START + function _vg_render_init + } +} + +add vg_shader.c + +input_layer +{ + name console +} +input_layer +{ + name ui +} +input +{ + name console + type action + layer_mask console +} + +append ../async/async.kv +thread +{ + name main + queue_size_m 40 + flag MAIN + flag OPENGL +} +thread +{ + name async + queue_size_m 40 + flag ASYNC +} +thread +{ + name audio +} +thread +{ + name exitor + queue_size_m 1 +} + +append ../graphics/graphics.kv + +ccmd +{ + name exec + function _console_exec_ccmd + description "Execute a configuration file" + + parameter + { + description "The path to the config" + } +} +config "bind ALT+GRAVE_ACCENT console" + +config "bind BACKSPACE ui_backspace" +config "bind DELETE ui_delete" +config "bind ENTER ui_enter" +config "bind TAB ui_indent" +config "bind HOME ui_home" +config "bind END ui_end" +config "bind LEFT ui_left" +config "bind RIGHT ui_right" +config "bind UP ui_up" +config "bind DOWN ui_down" +config "bind MOUSE_LEFT ui_click" + +config "bind LEFT_SHIFT ui_select" +config "bind RIGHT_SHIFT ui_select" + +input +{ + name ui_delete + type action + layer_mask ui +} +input +{ + name ui_backspace + type action + layer_mask ui +} +input +{ + name ui_enter + type action + layer_mask ui +} +input +{ + name ui_indent + type action + layer_mask ui +} + +input +{ + name ui_select + type button + layer_mask ui +} +input +{ + name ui_home + type button + layer_mask ui +} +input +{ + name ui_end + type button + layer_mask ui +} +input +{ + name ui_left + type button + layer_mask ui +} +input +{ + name ui_right + type button + layer_mask ui +} +input +{ + name ui_up + type button + layer_mask ui +} +input +{ + name ui_down + type button + layer_mask ui +} +input +{ + name ui_click + type action + layer_mask ui +} + +shader +{ + name blit + + subshader + { + type vertex + add shaders/blit.vs + + uniform + { + type vec2 + alias uInverseRatio + } + uniform + { + type int + alias uFlip + } + } + + subshader + { + type fragment + add shaders/blit_tex.fs + + uniform + { + type sampler2D + alias uTexMain + } + } +} + +cvar +{ + name test + type u32 + default 5 + cheat 1 + description "This is just a test variable!" +} + +hook +{ + event START + function "_shaders_compile" +} +} + + + + + + +add vg_camera.c + + +add vg_tex.c +hook +{ + event START + function _vg_tex_init +} + + +add vg_lines.c +hook +{ + event START + function _vg_lines_init +} +cvar +{ + name debug_lines + type u32 + default 0 + cheat 1 + description "Show line debuggers" +} +shader +{ + name debug_lines + subshader + { + type vertex + add shaders/debug_lines.vs + uniform + { + type mat4 + alias uPv + } + } + subshader + { + type fragment + add shaders/debug_lines.fs + } +} + + +add vg_audio.c +add vg_audio_dsp.c +add vg_audio_vorbis.c +hook +{ + affinity -3008 + event START + function _audio_init +} +hook +{ + affinity -6004 + event START + function _dsp_init +} + + +add model.c +add metascene.c +add array_file.c diff --git a/source/engine/input.c b/source/engine/input.c deleted file mode 100644 index 533d1dc..0000000 --- a/source/engine/input.c +++ /dev/null @@ -1,450 +0,0 @@ -#include "common_api.h" -#include "glfw.h" -#include "engine_interface.h" -#include "input_api.h" -#include "console_core.h" -#include "generated/input.c" - -struct input_alias -{ - const c8 *alias; - u8 device_type; - u32 key; - u32 alias_hash; -} -_input_aliases[] = -{ - { "MOUSE_LEFT", k_input_device_mouse, .key = GLFW_MOUSE_BUTTON_1 }, - { "MOUSE_RIGHT", k_input_device_mouse, .key = GLFW_MOUSE_BUTTON_2 }, - { "MOUSE_MIDDLE", k_input_device_mouse, .key = GLFW_MOUSE_BUTTON_3 }, - { "SPACE", k_input_device_keyboard, .key = GLFW_KEY_SPACE }, - { "APOSTROPHE", k_input_device_keyboard, .key = GLFW_KEY_APOSTROPHE }, - { "COMMA", k_input_device_keyboard, .key = GLFW_KEY_COMMA }, - { "MINUS", k_input_device_keyboard, .key = GLFW_KEY_MINUS }, - { "PERIOD", k_input_device_keyboard, .key = GLFW_KEY_PERIOD }, - { "SLASH", k_input_device_keyboard, .key = GLFW_KEY_SLASH }, - { "0", k_input_device_keyboard, .key = GLFW_KEY_0 }, - { "1", k_input_device_keyboard, .key = GLFW_KEY_1 }, - { "2", k_input_device_keyboard, .key = GLFW_KEY_2 }, - { "3", k_input_device_keyboard, .key = GLFW_KEY_3 }, - { "4", k_input_device_keyboard, .key = GLFW_KEY_4 }, - { "5", k_input_device_keyboard, .key = GLFW_KEY_5 }, - { "6", k_input_device_keyboard, .key = GLFW_KEY_6 }, - { "7", k_input_device_keyboard, .key = GLFW_KEY_7 }, - { "8", k_input_device_keyboard, .key = GLFW_KEY_8 }, - { "9", k_input_device_keyboard, .key = GLFW_KEY_9 }, - { "SEMICOLON", k_input_device_keyboard, .key = GLFW_KEY_SEMICOLON }, - { "EQUAL", k_input_device_keyboard, .key = GLFW_KEY_EQUAL }, - { "A", k_input_device_keyboard, .key = GLFW_KEY_A }, - { "B", k_input_device_keyboard, .key = GLFW_KEY_B }, - { "C", k_input_device_keyboard, .key = GLFW_KEY_C }, - { "D", k_input_device_keyboard, .key = GLFW_KEY_D }, - { "E", k_input_device_keyboard, .key = GLFW_KEY_E }, - { "F", k_input_device_keyboard, .key = GLFW_KEY_F }, - { "G", k_input_device_keyboard, .key = GLFW_KEY_G }, - { "H", k_input_device_keyboard, .key = GLFW_KEY_H }, - { "I", k_input_device_keyboard, .key = GLFW_KEY_I }, - { "J", k_input_device_keyboard, .key = GLFW_KEY_J }, - { "K", k_input_device_keyboard, .key = GLFW_KEY_K }, - { "L", k_input_device_keyboard, .key = GLFW_KEY_L }, - { "M", k_input_device_keyboard, .key = GLFW_KEY_M }, - { "N", k_input_device_keyboard, .key = GLFW_KEY_N }, - { "O", k_input_device_keyboard, .key = GLFW_KEY_O }, - { "P", k_input_device_keyboard, .key = GLFW_KEY_P }, - { "Q", k_input_device_keyboard, .key = GLFW_KEY_Q }, - { "R", k_input_device_keyboard, .key = GLFW_KEY_R }, - { "S", k_input_device_keyboard, .key = GLFW_KEY_S }, - { "T", k_input_device_keyboard, .key = GLFW_KEY_T }, - { "U", k_input_device_keyboard, .key = GLFW_KEY_U }, - { "V", k_input_device_keyboard, .key = GLFW_KEY_V }, - { "W", k_input_device_keyboard, .key = GLFW_KEY_W }, - { "X", k_input_device_keyboard, .key = GLFW_KEY_X }, - { "Y", k_input_device_keyboard, .key = GLFW_KEY_Y }, - { "Z", k_input_device_keyboard, .key = GLFW_KEY_Z }, - { "LEFT_BRACKET", k_input_device_keyboard, .key = GLFW_KEY_LEFT_BRACKET }, - { "BACKSLASH", k_input_device_keyboard, .key = GLFW_KEY_BACKSLASH }, - { "RIGHT_BRACKET", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_BRACKET }, - { "GRAVE_ACCENT", k_input_device_keyboard, .key = GLFW_KEY_GRAVE_ACCENT }, - { "WORLD_1", k_input_device_keyboard, .key = GLFW_KEY_WORLD_1 }, - { "WORLD_2", k_input_device_keyboard, .key = GLFW_KEY_WORLD_2 }, - { "ESCAPE", k_input_device_keyboard, .key = GLFW_KEY_ESCAPE }, - { "ENTER", k_input_device_keyboard, .key = GLFW_KEY_ENTER }, - { "TAB", k_input_device_keyboard, .key = GLFW_KEY_TAB }, - { "BACKSPACE", k_input_device_keyboard, .key = GLFW_KEY_BACKSPACE }, - { "INSERT", k_input_device_keyboard, .key = GLFW_KEY_INSERT }, - { "DELETE", k_input_device_keyboard, .key = GLFW_KEY_DELETE }, - { "RIGHT", k_input_device_keyboard, .key = GLFW_KEY_RIGHT }, - { "LEFT", k_input_device_keyboard, .key = GLFW_KEY_LEFT }, - { "DOWN", k_input_device_keyboard, .key = GLFW_KEY_DOWN }, - { "UP", k_input_device_keyboard, .key = GLFW_KEY_UP }, - { "PAGE_UP", k_input_device_keyboard, .key = GLFW_KEY_PAGE_UP }, - { "PAGE_DOWN", k_input_device_keyboard, .key = GLFW_KEY_PAGE_DOWN }, - { "HOME", k_input_device_keyboard, .key = GLFW_KEY_HOME }, - { "END", k_input_device_keyboard, .key = GLFW_KEY_END }, - { "CAPS_LOCK", k_input_device_keyboard, .key = GLFW_KEY_CAPS_LOCK }, - { "SCROLL_LOCK", k_input_device_keyboard, .key = GLFW_KEY_SCROLL_LOCK }, - { "NUM_LOCK", k_input_device_keyboard, .key = GLFW_KEY_NUM_LOCK }, - { "PRINT_SCREEN", k_input_device_keyboard, .key = GLFW_KEY_PRINT_SCREEN }, - { "PAUSE", k_input_device_keyboard, .key = GLFW_KEY_PAUSE }, - { "F1", k_input_device_keyboard, .key = GLFW_KEY_F1 }, - { "F2", k_input_device_keyboard, .key = GLFW_KEY_F2 }, - { "F3", k_input_device_keyboard, .key = GLFW_KEY_F3 }, - { "F4", k_input_device_keyboard, .key = GLFW_KEY_F4 }, - { "F5", k_input_device_keyboard, .key = GLFW_KEY_F5 }, - { "F6", k_input_device_keyboard, .key = GLFW_KEY_F6 }, - { "F7", k_input_device_keyboard, .key = GLFW_KEY_F7 }, - { "F8", k_input_device_keyboard, .key = GLFW_KEY_F8 }, - { "F9", k_input_device_keyboard, .key = GLFW_KEY_F9 }, - { "F10", k_input_device_keyboard, .key = GLFW_KEY_F10 }, - { "F11", k_input_device_keyboard, .key = GLFW_KEY_F11 }, - { "F12", k_input_device_keyboard, .key = GLFW_KEY_F12 }, - { "F13", k_input_device_keyboard, .key = GLFW_KEY_F13 }, - { "F14", k_input_device_keyboard, .key = GLFW_KEY_F14 }, - { "F15", k_input_device_keyboard, .key = GLFW_KEY_F15 }, - { "F16", k_input_device_keyboard, .key = GLFW_KEY_F16 }, - { "F17", k_input_device_keyboard, .key = GLFW_KEY_F17 }, - { "F18", k_input_device_keyboard, .key = GLFW_KEY_F18 }, - { "F19", k_input_device_keyboard, .key = GLFW_KEY_F19 }, - { "F20", k_input_device_keyboard, .key = GLFW_KEY_F20 }, - { "F21", k_input_device_keyboard, .key = GLFW_KEY_F21 }, - { "F22", k_input_device_keyboard, .key = GLFW_KEY_F22 }, - { "F23", k_input_device_keyboard, .key = GLFW_KEY_F23 }, - { "F24", k_input_device_keyboard, .key = GLFW_KEY_F24 }, - { "F25", k_input_device_keyboard, .key = GLFW_KEY_F25 }, - { "KP_0", k_input_device_keyboard, .key = GLFW_KEY_KP_0 }, - { "KP_1", k_input_device_keyboard, .key = GLFW_KEY_KP_1 }, - { "KP_2", k_input_device_keyboard, .key = GLFW_KEY_KP_2 }, - { "KP_3", k_input_device_keyboard, .key = GLFW_KEY_KP_3 }, - { "KP_4", k_input_device_keyboard, .key = GLFW_KEY_KP_4 }, - { "KP_5", k_input_device_keyboard, .key = GLFW_KEY_KP_5 }, - { "KP_6", k_input_device_keyboard, .key = GLFW_KEY_KP_6 }, - { "KP_7", k_input_device_keyboard, .key = GLFW_KEY_KP_7 }, - { "KP_8", k_input_device_keyboard, .key = GLFW_KEY_KP_8 }, - { "KP_9", k_input_device_keyboard, .key = GLFW_KEY_KP_9 }, - { "KP_DECIMAL", k_input_device_keyboard, .key = GLFW_KEY_KP_DECIMAL }, - { "KP_DIVIDE", k_input_device_keyboard, .key = GLFW_KEY_KP_DIVIDE }, - { "KP_MULTIPLY", k_input_device_keyboard, .key = GLFW_KEY_KP_MULTIPLY }, - { "KP_SUBTRACT", k_input_device_keyboard, .key = GLFW_KEY_KP_SUBTRACT }, - { "KP_ADD", k_input_device_keyboard, .key = GLFW_KEY_KP_ADD }, - { "KP_ENTER", k_input_device_keyboard, .key = GLFW_KEY_KP_ENTER }, - { "KP_EQUAL", k_input_device_keyboard, .key = GLFW_KEY_KP_EQUAL }, - { "LEFT_SHIFT", k_input_device_keyboard, .key = GLFW_KEY_LEFT_SHIFT }, - { "LEFT_CONTROL", k_input_device_keyboard, .key = GLFW_KEY_LEFT_CONTROL }, - { "LEFT_ALT", k_input_device_keyboard, .key = GLFW_KEY_LEFT_ALT }, - { "LEFT_SUPER", k_input_device_keyboard, .key = GLFW_KEY_LEFT_SUPER }, - { "RIGHT_SHIFT", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_SHIFT }, - { "RIGHT_CONTROL", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_CONTROL }, - { "RIGHT_ALT", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_ALT }, - { "RIGHT_SUPER", k_input_device_keyboard, .key = GLFW_KEY_RIGHT_SUPER }, - { "MENU", k_input_device_keyboard, .key = GLFW_KEY_MENU }, - { "SHIFT", k_input_device_modifier, .key = GLFW_MOD_SHIFT }, - { "CONTROL", k_input_device_modifier, .key = GLFW_MOD_CONTROL }, - { "ALT", k_input_device_modifier, .key = GLFW_MOD_ALT }, - { "SUPER", k_input_device_modifier, .key = GLFW_MOD_SUPER }, -}; - -static struct input_alias *_input_alias_find( const c8 *alias, u32 alias_length ) -{ - u32 hash = buffer_djb2( alias, alias_length ); - for( u32 i=0; ialias_hash == hash ) - if( compare_buffers( alias_i->alias, 0, alias, alias_length ) ) - return alias_i; - } - return NULL; -} - -static i32 _input_page = 0; - -union input_state -{ - struct - { - u8 hold_count, activation_count, release_count, repeat_count; - } - button; - - struct - { - f32 value; - } - axis; -} -static _input_states[2][k_input_count]; - -struct bind -{ - u16 device, input_index; - u32 id; - u32 modifiers; -}; -struct stretchy_allocator _bind_allocator; - -i32 _input_bind_ccmd( struct console_arguments *args ) -{ - const c8 *buttons = console_get_argument( args, 0 ); - if( !buttons ) - { - $log( $error, {"Usage: bind