From: hgn Date: Tue, 7 Oct 2025 20:49:06 +0000 (+0000) Subject: misc and also stretchy delete implementation X-Git-Url: https://skaterift.com/git/?a=commitdiff_plain;h=12d425397cec045d754a6d169d47c0e335fe85da;p=vg.git misc and also stretchy delete implementation --- diff --git a/foundation.kv b/foundation.kv index 259175b..96319db 100644 --- a/foundation.kv +++ b/foundation.kv @@ -201,7 +201,6 @@ add source/foundation/temporary.c append graphics.kv append glfw3.kv - ccmd { name exec @@ -213,8 +212,8 @@ add source/foundation/temporary.c 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" diff --git a/include/common_api.h b/include/common_api.h index da6de5e..5996500 100644 --- a/include/common_api.h +++ b/include/common_api.h @@ -47,7 +47,11 @@ static inline f32 f32_min( f32 a, f32 b ){ return a < b? a: b; } static inline f32 f32_max( f32 a, f32 b ){ return a > b? a: b; } static inline i32 i32_min( i32 a, i32 b ){ return a < b? a: b; } static inline i32 i32_max( i32 a, i32 b ){ return a > b? a: b; } +static inline i16 i16_min( i16 a, i16 b ){ return a < b? a: b; } +static inline i16 i16_max( i16 a, i16 b ){ return a > b? a: b; } static inline f32 f32_clamp( f32 a, f32 min, f32 max ) { return f32_min( max, f32_max( a, min ) ); } +static inline i16 i16_clamp( i16 a, i16 min, i16 max ){ return i16_min( max, i16_max( a, min ) ); } +static inline i16 i32_clamp( i32 a, i32 min, i32 max ){ return i32_min( max, i32_max( a, min ) ); } static inline f32 f32_sign( f32 a ) { return a < 0.0f? -1.0f: 1.0f; } void _exit_init(void); @@ -89,7 +93,7 @@ struct stretchy_allocator void stretchy_init( struct stretchy_allocator *stretchy, u32 element_size ); void *stretchy_append( struct stretchy_allocator *stretchy ); void *stretchy_get( struct stretchy_allocator *stretchy, u32 index ); -void *stretchy_delete( struct stretchy_allocator *stretchy, u32 index ); // TODO +void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ); u32 stretchy_count( struct stretchy_allocator *stretchy ); void stretchy_free( struct stretchy_allocator *stretchy ); diff --git a/include/graphics_api.h b/include/graphics_api.h index 701e492..57f5265 100644 --- a/include/graphics_api.h +++ b/include/graphics_api.h @@ -55,6 +55,7 @@ void rect_copy( i16 a[4], i16 b[4] ); void rect_pad( i16 rect[4], i16 padding[2] ); void rect_split( i16 rect[4], u32 vertical, i16 width, i16 gap, i16 out_left[4], i16 out_right[4] ); void rect_split_ratio( i16 rect[4], u32 vertical, f32 ratio, i16 gap, i16 out_left[4], i16 out_right[4] ); +bool ui_inside_rect( i16 rect[4], i16 co[2] ); /* Font * ------------------------------------------------------------------------------------------------------------------ */ @@ -89,6 +90,7 @@ bool _font_decode_bitmap( i16 uv[2] ); /* Immediate mode UI * ------------------------------------------------------------------------------------------------------------------ */ void _ui_set_mouse( i16 x, i16 y ); +void _ui_get_mouse_co( i16 out_co[2] ); void _ui_input_text( const c8 *text ); #define UI_PADDING_PX 8 diff --git a/source/engine/input.c b/source/engine/input.c index d5e5c23..4cb6c0b 100644 --- a/source/engine/input.c +++ b/source/engine/input.c @@ -364,6 +364,7 @@ static void _input_key_callback( GLFWwindow *window, i32 key, i32 scancode, i32 void _input_init(void) { glfwSetKeyCallback( _engine.window_handle, _input_key_callback ); + glfwSetMouseButtonCallback( _engine.window_handle, _input_mouse_callback ); for( u32 i=0; icount = 0; @@ -23,7 +23,10 @@ void *stretchy_append( struct stretchy_allocator *stretchy ) i32 i, offset; stretchy_core( stretchy, stretchy->count ++, &i, &offset ); if( offset == 0 ) + { + $log( $ok, {"Allocated new stretchy segment: "}, $unsigned( i ), {", size: "}, $unsigned(1<<(i+SMALL_SEGMENTS)) ); stretchy->segments[ i ] = _heap_allocate( (1<<(i+SMALL_SEGMENTS)) * stretchy->element_size ); + } return stretchy->segments[ i ] + stretchy->element_size*offset; } @@ -42,3 +45,22 @@ void stretchy_free( struct stretchy_allocator *stretchy ) stretchy->segments[i] = NULL; } } + +void stretchy_delete( struct stretchy_allocator *stretchy, u32 index ) +{ + if( (stretchy->count > 1) && (index != stretchy->count-1) ) + { + buffer_copy( stretchy_get( stretchy, stretchy->count-1 ), stretchy->element_size, + stretchy_get( stretchy, index ), stretchy->element_size ); + } + stretchy->count --; + + i32 i, offset; + stretchy_core( stretchy, stretchy->count, &i, &offset ); + if( offset == 0 ) + { + $log( $ok, {"Deleted stretchy segment: "}, $unsigned(i) ); + _heap_free( stretchy->segments[i] ); + stretchy->segments[i] = NULL; + } +} diff --git a/source/graphics/graphics.c b/source/graphics/graphics.c index 7a3f4dd..0a0a11f 100644 --- a/source/graphics/graphics.c +++ b/source/graphics/graphics.c @@ -7,9 +7,6 @@ void _graphics_set_target( struct graphics_target *target ) _graphics_target = target; } -static i16 i16_min( i16 a, i16 b ){ return ab?a:b; } -static i16 i16_clamp( i16 a, i16 min, i16 max ){ return i16_min( max, i16_max( a, min ) ); } void rect_clip( i16 child[4], i16 parent[4], i16 clipped[4] ) { i16 px = parent[0], py = parent[1], pw = parent[2], ph = parent[3]; diff --git a/source/graphics/ui.c b/source/graphics/ui.c index 51de2f6..e33a72c 100644 --- a/source/graphics/ui.c +++ b/source/graphics/ui.c @@ -55,12 +55,18 @@ struct } _ui; +void _ui_get_mouse_co( i16 out_co[2] ) +{ + out_co[0] = _ui.mouse_co[0]; + out_co[1] = _ui.mouse_co[1]; +} + void _ui_set_encoding( enum ui_text_encoding encoding ) { _ui.text_encoding = encoding; } -static bool ui_inside_rect( i16 rect[4], i16 co[2] ) +bool ui_inside_rect( i16 rect[4], i16 co[2] ) { return (co[0] >= rect[0]) && (co[1] >= rect[1]) && (co[0] < rect[0]+rect[2]) && (co[1] < rect[1]+rect[3]); } diff --git a/source/tools/metacompiler.c b/source/tools/metacompiler.c index c8c46e9..2412850 100644 --- a/source/tools/metacompiler.c +++ b/source/tools/metacompiler.c @@ -511,6 +511,8 @@ bool use_asan = 0; bool shared = 0; bool no_pdb = 0; +u32 optimise = 0; + enum libc_version { k_libc_version_native = 0, @@ -591,6 +593,9 @@ void _metacompiler_options(void) stream_open_buffer_read( &arg_stream, (void*)arg, buffer_last_index(arg,0,0)+1, 0 ); ASSERT_CRITICAL( string_parse_u64( &arg_stream, &processors ) == k_string_parse_ok ); } + + if( _option_flag( 'O', "Run optimisers" ) ) + optimise = 3; target_file_path = _option(); ASSERT_CRITICAL( target_file_path ); @@ -847,6 +852,7 @@ i32 main( i32 argc, const c8 *argv[] ) if( use_tsan ) $v_string( &command_string, {" -fsanitize=thread -lasan \\\n"} ); if( use_asan ) $v_string( &command_string, {" -fsanitize=address -lasan \\\n"} ); + $v_string( &command_string, { " -O" }, $unsigned( optimise ), {" \\\n"} ); $v_string( &command_string, {" -target "}, {string_get(&tripple_string)}, {" "} ); if( platform == k_platform_windows )