From 7f6fcbf987995cc5a799c292fbe1eab51481e553 Mon Sep 17 00:00:00 2001 From: hgn Date: Thu, 1 Jan 2026 23:14:59 +0000 Subject: [PATCH] more entity data --- source/foundation/foundation.h | 15 ++++---- source/graphics/ui.c | 62 +++++++++++++++++++++++++--------- source/graphics/vg_graphics.h | 17 +++++++--- source/tools/metacompiler.c | 20 +++++++++++ source/types.h | 4 ++- 5 files changed, 90 insertions(+), 28 deletions(-) diff --git a/source/foundation/foundation.h b/source/foundation/foundation.h index 86194ca..bfb1481 100644 --- a/source/foundation/foundation.h +++ b/source/foundation/foundation.h @@ -18,17 +18,20 @@ #define PAD_TO_8( X ) (((u32)X+0x7) & ~(u32)0x7) #define PAD_TO_16( X ) (((u32)X+0xf) & ~(u32)0xf) -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 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 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 i32 u32_min( u32 a, u32 b ){ return a < b? a: b; } static inline i32 u32_max( u32 a, u32 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 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 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 i32 i32_clamp( i32 a, i32 min, i32 max ){ return i32_min( max, i32_max( a, min ) ); } +static inline u32 u32_clamp( u32 a, u32 min, u32 max ){ return u32_min( max, u32_max( a, min ) ); } +static inline f32 f32_clamp( f32 a, f32 min, f32 max ){ return f32_min( max, f32_max( a, min ) ); } + static inline f32 f32_sign( f32 a ) { return a < 0.0f? -1.0f: 1.0f; } void _exit_init(void); diff --git a/source/graphics/ui.c b/source/graphics/ui.c index 3e34a82..a161fab 100644 --- a/source/graphics/ui.c +++ b/source/graphics/ui.c @@ -1101,7 +1101,7 @@ enum textbox_action _ui_panel_textbox( struct ui_panel *panel, c8 *text_buffer, return action; } -void _ui_panel_number( struct ui_panel *panel, const c8 *label, +enum number_action _ui_panel_number( struct ui_panel *panel, const c8 *label, void *values, void *mins, void *maxs, @@ -1117,6 +1117,11 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, i32 *maxs_i32 = maxs; i32 *start_i32s = (void *)_ui.controls.number.start_values; + u32 *values_u32 = values; + u32 *mins_u32 = mins; + u32 *maxs_u32 = maxs; + u32 *start_u32s = (void *)_ui.controls.number.start_values; + i16 label_box[4]; union colour tc = (flag & UI_DULL)? _ui_scheme[ k_ui_bg+3 ]: _ui_scheme[ k_ui_fg+3 ]; @@ -1128,14 +1133,17 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, struct ui_panel cols[3]; _ui_panel_grid( panel, cols, 1, 3, 5, UI_PADDING_PX/2, NULL ); - _ui_panel_number( &cols[0], "CO", values_f32+0, mins_f32? mins_f32+0: NULL, - maxs_f32? maxs_f32+0: NULL, k_data_type_vec3, UI_LABEL_ABOVE ); - _ui_panel_number( &cols[1], "S", values_f32+3, mins_f32? mins_f32+3: NULL, - maxs_f32? maxs_f32+3: NULL, k_data_type_vec3, UI_LABEL_ABOVE ); - _ui_panel_number( &cols[2], "Q", values_f32+6, NULL, NULL, k_data_type_quat, UI_LABEL_ABOVE ); - return; + enum number_action action = + _ui_panel_number( &cols[0], "CO", values_f32+0, mins_f32? mins_f32+0: NULL, + maxs_f32? maxs_f32+0: NULL, k_data_type_vec3, UI_LABEL_ABOVE ) | + _ui_panel_number( &cols[1], "S", values_f32+3, mins_f32? mins_f32+3: NULL, + maxs_f32? maxs_f32+3: NULL, k_data_type_vec3, UI_LABEL_ABOVE ) | + _ui_panel_number( &cols[2], "Q", values_f32+6, NULL, NULL, k_data_type_quat, UI_LABEL_ABOVE ); + return action; } + enum number_action action = k_number_action_none; + struct ui_panel grid[3*16]; if( flag & UI_LABEL_ABOVE ) { @@ -1207,27 +1215,29 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, up_a = _ui_panel_button( &buttons[2], "+", flag ); enum button_action main_a = _ui_button( buttons[1].content_area ); - b8 modified = 0; enum data_type single_type = DATATYPE_GET_SINGLE( data_type ); /* inc/dec */ if( down_a == k_button_click ) { if( single_type == k_data_type_i32 ) values_i32[i] --; + else if( single_type == k_data_type_u32 ) values_u32[i] --; else if( single_type == k_data_type_f32 ) values_f32[i] -= 1.0f; - modified = 1; + action = k_number_action_changed; } if( up_a == k_button_click ) { if( single_type == k_data_type_i32 ) values_i32[i] ++; + else if( single_type == k_data_type_u32 ) values_u32[i] ++; else if( single_type == k_data_type_f32 ) values_f32[i] += 1.0f; - modified = 1; + action = k_number_action_changed; } /* slider action */ if( main_a == k_button_click ) { if( single_type == k_data_type_i32 ) start_i32s[i] = values_i32[i]; + else if( single_type == k_data_type_u32 ) start_u32s[i] = values_u32[i]; else if( single_type == k_data_type_f32 ) start_f32s[i] = values_f32[i]; } if( main_a == k_button_repeat ) @@ -1237,16 +1247,16 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, if( _ui.mouse_mods & UI_KEYBOARD_ALT ) div = 8; if( single_type == k_data_type_i32 ) values_i32[i] = start_i32s[i] + (delta/div); + else if( single_type == k_data_type_u32 ) values_u32[i] = start_u32s[i] + (delta/div); else if( single_type == k_data_type_f32 ) values_f32[i] = start_f32s[i] + ((f32)delta/(f32)div)/10.0f; - modified = 1; + action = k_number_action_changed; } - if( modified && (mins && maxs) ) + if( (action == k_number_action_changed) && (mins && maxs) ) { - if( single_type == k_data_type_i32 ) - values_i32[i] = i32_clamp( values_i32[i], mins_i32[i], maxs_i32[i] ); - else if( single_type == k_data_type_f32 ) - values_f32[i] = f32_clamp( values_f32[i], mins_f32[i], maxs_f32[i] ); + if( single_type == k_data_type_i32 ) values_i32[i] = i32_clamp( values_i32[i], mins_i32[i], maxs_i32[i] ); + else if( single_type == k_data_type_u32 ) values_u32[i] = u32_clamp( values_u32[i], mins_u32[i], maxs_u32[i] ); + else if( single_type == k_data_type_f32 ) values_f32[i] = f32_clamp( values_f32[i], mins_f32[i], maxs_f32[i] ); } c8 buf[32]; @@ -1257,6 +1267,10 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, { $v_string( &number_str, $signed( values_i32[i] ) ); } + else if( single_type == k_data_type_u32 ) + { + $v_string( &number_str, $unsigned( values_u32[i] ) ); + } else if( single_type == k_data_type_f32 ) { $v_string( &number_str, $float( values_f32[i] ) ); @@ -1288,6 +1302,7 @@ void _ui_panel_number( struct ui_panel *panel, const c8 *label, _ui.fiddle.co[1] = buttons[2].content_area[1]; } } + return action; } enum dropdown_action _ui_panel_enum( struct ui_panel *panel, const c8 *label, i32 *value, @@ -1308,6 +1323,21 @@ enum dropdown_action _ui_panel_enum( struct ui_panel *panel, const c8 *label, i3 return action; } +enum button_action _ui_panel_checkbox( struct ui_panel *panel, const c8 *label, b8 *value, u32 flag ) +{ + i16 rect[4]; + _ui_panel_widget( panel, rect ); + + enum button_action action = _ui_panel_button_internal( rect, label, 0 ); + if( action == k_button_click ) + *value = (*value) ^ 0x1; + + i16 end_box[4] = { rect[0] + rect[2] - rect[3], rect[1], rect[3], rect[3] }; + if( *value ) _ui_text( end_box, "\xB3", k_ui_align_center, _ui_scheme[ k_ui_green ] ); + else _ui_text( end_box, "\xB2", k_ui_align_center, _ui_scheme[ k_ui_red ] ); + return action; +} + void _ui_panel_heading( struct ui_panel *panel, const c8 *label, u32 flag ) { i16 kerning[3]; diff --git a/source/graphics/vg_graphics.h b/source/graphics/vg_graphics.h index 3064a1f..304063b 100644 --- a/source/graphics/vg_graphics.h +++ b/source/graphics/vg_graphics.h @@ -262,11 +262,18 @@ enum textbox_action _ui_panel_textbox( struct ui_panel *panel, c8 *text_buffer, u32 flag, const c8 *label ); void _ui_panel_heading( struct ui_panel *panel, const c8 *label, u32 flag ); -void _ui_panel_number( struct ui_panel *panel, const c8 *label, - void *values, - void *mins, - void *maxs, - enum data_type data_type, u32 flag ); +enum number_action +{ + k_number_action_none, + k_number_action_changed = 0x1 +}; +enum number_action _ui_panel_number( + struct ui_panel *panel, const c8 *label, + void *values, + void *mins, + void *maxs, + enum data_type data_type, u32 flag ); enum dropdown_action _ui_panel_enum( struct ui_panel *panel, const c8 *label, i32 *value, struct ui_dropdown_option *options, u32 option_count, u32 flag ); +enum button_action _ui_panel_checkbox( struct ui_panel *panel, const c8 *label, b8 *value, u32 flag ); diff --git a/source/tools/metacompiler.c b/source/tools/metacompiler.c index f7ed14d..55b65ef 100644 --- a/source/tools/metacompiler.c +++ b/source/tools/metacompiler.c @@ -824,6 +824,13 @@ void _codegen_entities(void) ent->parameter_count ++; parameter_count ++; + + u32 flag_it = 0; + while( keyvalues_foreach( &_assembly, &flag_it, parameter_it, "flag" ) ) + { + ent->parameter_count ++; + parameter_count ++; + } } $v_string( &H, {"};\n"} ); } @@ -875,6 +882,19 @@ void _codegen_entities(void) $v_string( &C, {", .type = k_data_type_"}, {type} ); $v_string( &C, {", .offset = __builtin_offsetof(struct "}, {ent->name}, {", "}, {name}, {")"} ); $v_string( &C, {" },\n"} ); + + u32 flag_it = 0; + while( keyvalues_foreach( &_assembly, &flag_it, parameter_it, "flag" ) ) + { + const c8 *flag_name = keyvalues_read_string( &_assembly, flag_it, "name", NULL ); + ASSERT_CRITICAL( flag_name ); + const c8 *flag_value = keyvalues_read_string( &_assembly, flag_it, "value", NULL ); + ASSERT_CRITICAL( flag_value ); + $v_string( &C, {" { .name = \""}, {name}, {":"},{flag_name},{"\""} ); + $v_string( &C, {", .type = k_data_format_bit"} ); + $v_string( &C, {", .offset = __builtin_ctz("}, {flag_value}, {")"} ); + $v_string( &C, {" },\n"} ); + } } } $v_string( &C, {"};\n"} ); diff --git a/source/types.h b/source/types.h index d908532..f0b54ab 100644 --- a/source/types.h +++ b/source/types.h @@ -36,11 +36,13 @@ enum data_type k_data_semantic_box = 0x0008, k_data_semantic_key = 0x0009, k_data_semantic_offset_string = 0x000A, + k_data_semantic_flags = 0x000B, k_data_format_unsigned = 0x1000, k_data_format_signed = 0x2000, k_data_format_float = 0x3000, k_data_format_void = 0x4000, + k_data_format_bit = 0x8000, k_data_type_none = 0, @@ -86,5 +88,5 @@ enum data_type k_data_type_2dbox = k_data_format_float | DATATYPE_SIZE( 4, 4 ) | k_data_semantic_box, k_data_type_3dbox = k_data_format_float | DATATYPE_SIZE( 6, 4 ) | k_data_semantic_box, - k_data_type_function = k_data_format_void + k_data_type_function = k_data_format_void, }; -- 2.25.1