From: Brendan Hansen Date: Mon, 9 Aug 2021 10:39:36 +0000 (-0500) Subject: random cleanup; fixed ui layering bug X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=4251637742a8fb2660b8bdd0c26e0030106f0213;p=onyx.git random cleanup; fixed ui layering bug --- diff --git a/bin/onyx b/bin/onyx index 27fc96e3..1e5eadc5 100755 Binary files a/bin/onyx and b/bin/onyx differ diff --git a/modules/immediate_mode/immediate_renderer.onyx b/modules/immediate_mode/immediate_renderer.onyx index 4f7e3cca..4cb38fde 100644 --- a/modules/immediate_mode/immediate_renderer.onyx +++ b/modules/immediate_mode/immediate_renderer.onyx @@ -515,3 +515,10 @@ push_matrix :: () do global_renderer->push_matrix(); pop_matrix :: () do global_renderer->pop_matrix(); identity :: () do global_renderer->identity(); apply_transform :: (transform: Transform) do global_renderer->apply_transform(transform); + + + +save_matrix :: #code { + (package immediate_mode).push_matrix(); + defer (package immediate_mode).pop_matrix(); +} \ No newline at end of file diff --git a/modules/ui/components/scrollable_region.onyx b/modules/ui/components/scrollable_region.onyx index 41ff29ec..edd9082b 100644 --- a/modules/ui/components/scrollable_region.onyx +++ b/modules/ui/components/scrollable_region.onyx @@ -21,13 +21,11 @@ scrollable_region_start :: (use r: Rectangle, x_scroll: ^f32, y_scroll: ^f32, si state := map.get(^scrollable_region_states, hash); mx, my := get_mouse_position(); - contained := false; if Rectangle.contains(r, mx, my) { - // if hot_item == 0 do set_hot_item(hash); - contained = true; + set_hot_item(hash); } - if contained { // is_hot_item(hash) { + if is_hot_item(hash) { speed :: 30.0f; @ThemeConfiguration if is_key_down(38) do state.transform.translation.y += speed; diff --git a/modules/ui/components/workspace.onyx b/modules/ui/components/workspace.onyx index 64558d2f..900952d8 100644 --- a/modules/ui/components/workspace.onyx +++ b/modules/ui/components/workspace.onyx @@ -24,7 +24,7 @@ workspace_start :: (use r: Rectangle, site := #callsite) { mx, my := get_mouse_position(); if Rectangle.contains(r, mx, my) { - if hot_item == 0 do set_hot_item(hash); + set_hot_item(hash); } if is_hot_item(hash) { diff --git a/modules/ui/ui.onyx b/modules/ui/ui.onyx index 92e06f09..3a6c4084 100644 --- a/modules/ui/ui.onyx +++ b/modules/ui/ui.onyx @@ -29,6 +29,7 @@ init_ui :: () { // This function should be called at the end of drawing a frame, after all of the UI elements // had a chance to interact with the hardware events. + end_frame :: () { mouse_state.left_button_just_up = false; mouse_state.left_button_just_down = false; @@ -47,7 +48,9 @@ end_frame :: () { keyboard_state.keys_down_this_frame = 0; keyboard_state.keys_up_this_frame = 0; + hot_item_depth_needed = hot_item_depth; if !hot_item_was_set do set_hot_item(0); + hot_item_depth = 0; hot_item_was_set = false; for ^s: keyboard_state.state { @@ -61,13 +64,26 @@ set_active_item :: (id: UI_Id) -> bool { return true; } -set_hot_item :: (id: UI_Id) -> bool { +#private_file hot_item_depth := 0; +#private_file hot_item_depth_needed := 0; + +set_hot_item :: (id: UI_Id, force := false) -> bool { if active_item != 0 do return false; - hot_item_was_set = true; + if force { + hot_item_was_set = true; + hot_item = id; + return true; + } - hot_item = id; - return true; + hot_item_depth += 1; + if hot_item_depth >= hot_item_depth_needed { + hot_item_was_set = true; + hot_item = id; + return true; + } else { + return false; + } } is_active_item :: (id: UI_Id) -> bool { diff --git a/src/onyxastnodes.c b/src/onyxastnodes.c index 9944f63a..5aef4393 100644 --- a/src/onyxastnodes.c +++ b/src/onyxastnodes.c @@ -58,7 +58,7 @@ static const char* ast_node_names[] = { "ARRAY ACCESS", "SLICE", "FIELD ACCESS", - "UNARY FIELD ACCESS" + "UNARY FIELD ACCESS", "PIPE", "METHOD_CALL", "RANGE", @@ -257,8 +257,6 @@ AstTyped* ast_reduce_unaryop(bh_allocator a, AstUnaryOp* unop) { AstNumLit* operand = (AstNumLit *) ast_reduce(a, unop->expr); unop->expr = (AstTyped *) operand; - // while (operand->kind == Ast_Kind_Alias) operand = (AstNumLit *) ((AstAlias *) operand)->alias; - if (operand->kind != Ast_Kind_NumLit) { return (AstTyped *) unop; } @@ -278,6 +276,72 @@ AstTyped* ast_reduce_unaryop(bh_allocator a, AstUnaryOp* unop) { } case Unary_Op_Bitwise_Not: REDUCE_UNOP_INT(~); + case Unary_Op_Cast: { + #if 0 + Type* from = operand->type; + Type* to = unop->type; + + if (from->kind == Type_Kind_Enum) from = from->Enum.backing; + if (to->kind == Type_Kind_Enum) to = to->Enum.backing; + + if (from->kind != Type_Kind_Pointer && from->kind != Type_Kind_Basic) return (AstTyped *) unop; + if (to->kind != Type_Kind_Pointer && to->kind != Type_Kind_Basic) return (AstTyped *) unop; + + b32 from_is_int=0, to_is_int=0; + i32 from_size, to_size; + + from_size = type_size_of(from); + to_size = type_size_of(to); + + if (from->kind == Type_Kind_Basic) from_is_int = (from->flags & (Basic_Flag_Integer | Basic_Flag_Pointer)) != 0; + if (to->kind == Type_Kind_Basic) to_is_int = (to->flags & (Basic_Flag_Integer | Basic_Flag_Pointer)) != 0; + + if (from->kind == Type_Kind_Pointer) from_is_int = 1; + if (to->kind == Type_Kind_Pointer) to_is_int = 1; + + if (from_is_int == to_is_int && from_size == to_size) { + // If they are already equal, nothing to do + return (AstTyped *) res; + } + + if (from_is_int && !to_is_int) { + if (from_size == to_size) { + if (from_size == 4) { + res->value.f = (f32) operand->value.i; + } + else if (from_size == 8) { + res->value.d = (f64) operand->value.l; + } + } else { + if (from_size == 4) { + res->value.d = (f64) operand->value.i; + } + else if (from_size == 8) { + res->value.f = (f32) operand->value.l; + } + } + } else { + if (from_size == to_size) { + if (from_size == 4) { + res->value.i = (i32) operand->value.f; + } + else if (from_size == 8) { + res->value.l = (i64) operand->value.d; + } + } else { + if (from_size == 4) { + res->value.l = (i64) operand->value.f; + } + else if (from_size == 8) { + res->value.i = (i32) operand->value.d; + } + } + } + break; + + #endif + } + default: return (AstTyped *) unop; } diff --git a/src/onyxchecker.c b/src/onyxchecker.c index ca848767..3cac3da8 100644 --- a/src/onyxchecker.c +++ b/src/onyxchecker.c @@ -1733,6 +1733,7 @@ CheckStatus check_insert_directive(AstDirectiveInsert** pinsert) { assert(code_block->kind == Ast_Kind_Code_Block); AstNode* cloned_block = ast_clone(context.ast_alloc, code_block->code); + cloned_block->next = insert->next; if (cloned_block->kind == Ast_Kind_Block) { AstNode* next = insert->next; diff --git a/src/onyxwasm.c b/src/onyxwasm.c index e2e63bc9..0bc1cb45 100644 --- a/src/onyxwasm.c +++ b/src/onyxwasm.c @@ -3212,15 +3212,17 @@ static b32 emit_raw_data_(OnyxWasmModule* mod, ptr data, AstTyped* node) { Type* sl_type = sl->type; // ROBUSTNESS: Handle cases for slices and dynamic arrays - if (sl_type->kind != Type_Kind_Struct) { + if (sl_type->kind != Type_Kind_Struct && sl_type->kind != Type_Kind_Slice && sl_type->kind != Type_Kind_DynArray) { retval = 0; break; } - i32 i = 0; - bh_arr_each(AstTyped *, expr, sl->args.values) { - retval &= emit_raw_data_(mod, bh_pointer_add(data, sl_type->Struct.memarr[i]->offset), *expr); - i++; + i32 mem_count = type_structlike_mem_count(sl_type); + StructMember smem; + + fori (i, 0, mem_count) { + type_lookup_member_by_idx(sl_type, i, &smem); + retval &= emit_raw_data_(mod, bh_pointer_add(data, smem.offset), sl->args.values[i]); } break; diff --git a/tests/aoc-2020/day17.onyx b/tests/aoc-2020/day17.onyx index 6c6825f2..19c29ab9 100644 --- a/tests/aoc-2020/day17.onyx +++ b/tests/aoc-2020/day17.onyx @@ -41,7 +41,7 @@ main :: (args: [] cstr) { file := reader.make(contents); - cubes := map.make(CubePos, CubeState, .{}, 1021); + cubes := map.make(CubePos, CubeState, .{}, 2047); defer map.free(^cubes); z := 0; diff --git a/tests/aoc-2020/day25.onyx b/tests/aoc-2020/day25.onyx index 7806bede..443a1cb8 100644 --- a/tests/aoc-2020/day25.onyx +++ b/tests/aoc-2020/day25.onyx @@ -20,8 +20,7 @@ power_mod :: (base: u32, exp: u32, mod: u32) -> u32 { } dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 { - use package core.intrinsics.wasm { ceil_f64, sqrt_f64 } - m := cast(u32) ceil_f64(sqrt_f64(~~n)); + m := cast(u32) math.ceil(math.sqrt(cast(f64) n)); t := map.make(u32, u32, default=0, hash_count=m/2); defer map.free(^t); @@ -36,8 +35,8 @@ dlp_bsgs :: (n: u32, a: u32, b: u32) -> u32 { tmp = ~~b; for i: 0 .. m { - if map.has(^t, cast(u32) tmp) { - v := map.get(^t, cast(u32) tmp); + if map.has(^t, ~~tmp) { + v := map.get(^t, ~~tmp); return i * m + v; } diff --git a/tests/aoc-2020/day3.onyx b/tests/aoc-2020/day3.onyx index f494fe65..ad082a60 100644 --- a/tests/aoc-2020/day3.onyx +++ b/tests/aoc-2020/day3.onyx @@ -34,12 +34,13 @@ main :: (args: [] cstr) { for ch: line do array.push(^forest, ch); } - lis : [5] LineInterp; - lis[0] = .{ 0, 0, 1, 1 }; - lis[1] = .{ 0, 0, 3, 1 }; - lis[2] = .{ 0, 0, 5, 1 }; - lis[3] = .{ 0, 0, 7, 1 }; - lis[4] = .{ 0, 0, 1, 2 }; + lis := LineInterp.[ + .{ 0, 0, 1, 1 }, + .{ 0, 0, 3, 1 }, + .{ 0, 0, 5, 1 }, + .{ 0, 0, 7, 1 }, + .{ 0, 0, 1, 2 }, + ]; tree_prod: u64 = 1;