From f415eada0d197162ca3c93db9a8406fe4714fc61 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 31 May 2024 17:58:18 -0400 Subject: [PATCH] Doing some heavy refactors on the container interfaces Trying to set up their use to be more ideomatic to the core containers --- code/grime/array.odin | 10 ++---- code/grime/mappings.odin | 14 ++++++++ code/grime/memory_tracker.odin | 2 +- code/grime/stack_fixed.odin | 46 ++++++++++++++++++++++++++ code/grime/unicode.odin | 2 +- code/grime/virtual_memory.odin | 4 +-- code/grime/virtual_memory_windows.odin | 2 +- code/sectr/app/screen.odin | 2 +- code/sectr/engine/client_api.odin | 6 ++-- code/sectr/font/provider.odin | 4 +-- code/sectr/grime/hashmap_chained.odin | 33 +++++++++--------- code/sectr/grime/hashmap_zpl.odin | 10 +++--- code/sectr/grime/mappings.odin | 25 +++++++++++++- code/sectr/grime/slab_allocator.odin | 2 +- code/sectr/grime/stack.odin | 45 ------------------------- code/sectr/grime/string_interning.odin | 4 +-- code/sectr/parser/whitespace.odin | 6 ++-- code/sectr/ui/core/base.odin | 4 +-- code/sectr/ui/floating.odin | 8 ++--- code/sectr/ui/tests.odin | 2 +- 20 files changed, 133 insertions(+), 98 deletions(-) create mode 100644 code/grime/stack_fixed.odin diff --git a/code/grime/array.odin b/code/grime/array.odin index 51d6949..4e5d1ae 100644 --- a/code/grime/array.odin +++ b/code/grime/array.odin @@ -50,12 +50,9 @@ array_grow_formula :: proc( value : u64 ) -> u64 { return result } -array_init :: proc( $ Type : typeid, allocator : Allocator ) -> ( Array(Type), AllocatorError ) { - return array_init_reserve( Type, allocator, array_grow_formula(0) ) -} - -array_init_reserve :: proc -( $ Type : typeid, allocator : Allocator, capacity : u64, fixed_cap : b32 = false, dbg_name : string = "" ) -> ( result : Array(Type), alloc_error : AllocatorError ) +array_init :: proc( $Array_Type : typeid/Array($Type), capacity : u64, + allocator := context.allocator, fixed_cap : b32 = false, dbg_name : string = "" +) -> ( result : Array(Type), alloc_error : AllocatorError ) { header_size := size_of(ArrayHeader(Type)) array_size := header_size + int(capacity) * size_of(Type) @@ -229,7 +226,6 @@ array_free :: proc( using self : Array( $ Type ) ) { array_grow :: proc( using self : ^Array( $ Type ), min_capacity : u64 ) -> AllocatorError { - // profile(#procedure) new_capacity := array_grow_formula( capacity ) if new_capacity < min_capacity { diff --git a/code/grime/mappings.odin b/code/grime/mappings.odin index bb04361..413882f 100644 --- a/code/grime/mappings.odin +++ b/code/grime/mappings.odin @@ -138,6 +138,20 @@ is_power_of_two :: proc { is_power_of_two_uintptr, } +make :: proc { + array_init, + // hmap_chained_init, + // hmap_zpl_init, + + // Usual + make_slice, + make_dynamic_array, + make_dynamic_array_len, + make_dynamic_array_len_cap, + make_map, + make_multi_pointer, +} + to_string :: proc { runes_to_string, str_builder_to_string, diff --git a/code/grime/memory_tracker.odin b/code/grime/memory_tracker.odin index 80a4c2d..df096ff 100644 --- a/code/grime/memory_tracker.odin +++ b/code/grime/memory_tracker.odin @@ -38,7 +38,7 @@ memtracker_init :: proc ( tracker : ^MemoryTracker, allocator : Allocator, num_e tracker.name = name error : AllocatorError - tracker.entries, error = array_init_reserve( MemoryTrackerEntry, allocator, num_entries, dbg_name = name ) + tracker.entries, error = make( Array(MemoryTrackerEntry), num_entries, dbg_name = name, allocator = allocator ) if error != AllocatorError.None { fatal("Failed to allocate memory tracker's hashmap"); } diff --git a/code/grime/stack_fixed.odin b/code/grime/stack_fixed.odin new file mode 100644 index 0000000..f829233 --- /dev/null +++ b/code/grime/stack_fixed.odin @@ -0,0 +1,46 @@ +package grime + +//#region("Fixed Stack") + +StackFixed :: struct ( $ Type : typeid, $ Size : u32 ) { + idx : u32, + items : [ Size ] Type, +} + +stack_clear :: #force_inline proc ( using stack : ^StackFixed( $Type, $Size)) { + idx = 0 +} + +stack_push :: #force_inline proc( using stack : ^ StackFixed( $ Type, $ Size ), value : Type ) { + assert( idx < len( items ), "Attempted to push on a full stack" ) + + items[ idx ] = value + idx += 1 +} + +stack_pop :: #force_inline proc( using stack : ^StackFixed( $ Type, $ Size ) ) { + assert( idx > 0, "Attempted to pop an empty stack" ) + + idx -= 1 + if idx == 0 { + items[idx] = {} + } +} + +stack_peek_ref :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> ( ^Type) { + last_idx := max( 0, idx - 1 ) if idx > 0 else 0 + last := & items[last_idx] + return last +} + +stack_peek :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> Type { + last := max( 0, idx - 1 ) if idx > 0 else 0 + return items[last] +} + +stack_push_contextless :: #force_inline proc "contextless" ( stack : ^StackFixed( $Type, $Size), value : Type ) { + items[idx] = value + idx += 1 +} + +//#endregion("Fixed Stack") diff --git a/code/grime/unicode.odin b/code/grime/unicode.odin index 2ee7365..9f6d8f2 100644 --- a/code/grime/unicode.odin +++ b/code/grime/unicode.odin @@ -24,7 +24,7 @@ string_to_runes_array :: proc( content : string, allocator := context.allocator { num := cast(u64) str_rune_count(content) - runes_array, alloc_error := array_init_reserve( rune, allocator, num ) + runes_array, alloc_error := make( Array(rune), num, allocator ) if alloc_error != AllocatorError.None { return nil, alloc_error } diff --git a/code/grime/virtual_memory.odin b/code/grime/virtual_memory.odin index a2227a7..36e3131 100644 --- a/code/grime/virtual_memory.odin +++ b/code/grime/virtual_memory.odin @@ -68,7 +68,7 @@ virtual_protect :: proc "contextless" ( vmem : VirtualMemoryRegion, region : []b virtual_reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( VirtualMemoryRegion, AllocatorError ) { page_size := uint(virtual_get_page_size()) to_reserve := memory_align_formula( size, page_size ) - return virtual__reserve( base_address, to_reserve ) + return virtual_resreve__platform_impl( base_address, to_reserve ) } @(require_results) @@ -97,7 +97,7 @@ virtual_release :: proc "contextless" ( vmem : VirtualMemoryRegion ) { // If the OS is not windows, we just use the library's interface which does not support base_address. when ODIN_OS != OS_Type.Windows { -virtual__reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError ) +virtual_resreve__platform_impl :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError ) { header_size := memory_align_formula(size_of(VirtualMemoryRegionHeader), mem.DEFAULT_ALIGNMENT) diff --git a/code/grime/virtual_memory_windows.odin b/code/grime/virtual_memory_windows.odin index 4628454..95d095f 100644 --- a/code/grime/virtual_memory_windows.odin +++ b/code/grime/virtual_memory_windows.odin @@ -4,7 +4,7 @@ import "core:mem" import win32 "core:sys/windows" @(require_results) -virtual__reserve :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError ) +virtual_resreve__platform_impl :: proc "contextless" ( base_address : uintptr, size : uint ) -> ( vmem : VirtualMemoryRegion, alloc_error : AllocatorError ) { header_size := cast(uint) memory_align_formula(size_of(VirtualMemoryRegionHeader), mem.DEFAULT_ALIGNMENT) diff --git a/code/sectr/app/screen.odin b/code/sectr/app/screen.odin index 4dc2224..3d0c02d 100644 --- a/code/sectr/app/screen.odin +++ b/code/sectr/app/screen.odin @@ -243,7 +243,7 @@ ui_screen_settings_menu :: proc( captures : rawptr = nil ) -> ( should_raise : b @static value_str : Array(rune) if value_str.header == nil { error : AllocatorError - value_str, error = array_init_reserve(rune, persistent_slab_allocator(), Kilo) + value_str, error = make( Array(rune), Kilo, persistent_slab_allocator()) ensure(error == AllocatorError.None, "Failed to allocate array for value_str of input_box") } diff --git a/code/sectr/engine/client_api.odin b/code/sectr/engine/client_api.odin index fec44a8..72b2bd3 100644 --- a/code/sectr/engine/client_api.odin +++ b/code/sectr/engine/client_api.odin @@ -109,9 +109,9 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem for & input in input_data { using input error : AllocatorError - keyboard_events.keys_pressed, error = array_init_reserve(KeyCode, persistent_slab_allocator(), Kilo) + keyboard_events.keys_pressed, error = make( Array(KeyCode), Kilo, persistent_slab_allocator() ) ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.keys_pressed array") - keyboard_events.chars_pressed, error = array_init_reserve(rune, persistent_slab_allocator(), Kilo) + keyboard_events.chars_pressed, error = make( Array(rune), Kilo, persistent_slab_allocator() ) ensure(error == AllocatorError.None, "Failed to allocate input.keyboard_events.chars_pressed array") } } @@ -290,7 +290,7 @@ startup :: proc( prof : ^SpallProfiler, persistent_mem, frame_mem, transient_mem if false { ui_startup( & screen_ui.base, cache_allocator = persistent_slab_allocator() ) - ui_floating_startup( & screen_ui.floating, persistent_slab_allocator(), 1 * Kilobyte, 1 * Kilobyte, "screen ui floating manager" ) + ui_floating_startup( & screen_ui.floating, 1 * Kilobyte, 1 * Kilobyte, persistent_slab_allocator(), "screen ui floating manager" ) using screen_ui menu_bar.pos = { -60, 0 } diff --git a/code/sectr/font/provider.odin b/code/sectr/font/provider.odin index 106a914..aaae7fc 100644 --- a/code/sectr/font/provider.odin +++ b/code/sectr/font/provider.odin @@ -59,7 +59,7 @@ FontDef :: struct { } FontProviderData :: struct { - font_cache : HMapChainedPtr(FontDef), + font_cache : HMapChained(FontDef), parser : FontParserData, glyph_shader : sokol_gfx.Shader, gfx_bindings : sokol_gfx.Bindings, @@ -79,7 +79,7 @@ font_provider_startup :: proc() font_provider_data := & get_state().font_provider_data; using font_provider_data font_cache_alloc_error : AllocatorError - font_cache, font_cache_alloc_error = hmap_chained_init(FontDef, hmap_closest_prime(1 * Kilo), persistent_allocator(), dbg_name = "font_cache" ) + font_cache, font_cache_alloc_error = make( HMapChained(FontDef), hmap_closest_prime(1 * Kilo), persistent_allocator(), dbg_name = "font_cache" ) verify( font_cache_alloc_error == AllocatorError.None, "Failed to allocate font_cache" ) log("font_cache created") diff --git a/code/sectr/grime/hashmap_chained.odin b/code/sectr/grime/hashmap_chained.odin index 4ca2329..f2dace6 100644 --- a/code/sectr/grime/hashmap_chained.odin +++ b/code/sectr/grime/hashmap_chained.odin @@ -24,13 +24,13 @@ HMapChainedSlot :: struct( $Type : typeid ) { occupied : b32, } -HMapChained :: struct( $ Type : typeid ) { +HMapChainedHeader :: struct( $ Type : typeid ) { pool : Pool, lookup : [] ^HMapChainedSlot(Type), } -HMapChainedPtr :: struct( $ Type : typeid) { - using header : ^HMapChained(Type), +HMapChained :: struct( $ Type : typeid) { + using header : ^HMapChainedHeader(Type), } // Provides the nearest prime number value for the given capacity @@ -50,21 +50,22 @@ hmap_closest_prime :: proc( capacity : uint ) -> uint return prime_table[len(prime_table) - 1] } -hmap_chained_init :: proc( $Type : typeid, lookup_capacity : uint, allocator : Allocator, +hmap_chained_init :: proc( $HMapChainedType : typeid/HMapChained($Type), lookup_capacity : uint, + allocator := context.allocator, pool_bucket_cap : uint = 1 * Kilo, pool_bucket_reserve_num : uint = 0, pool_alignment : uint = mem.DEFAULT_ALIGNMENT, dbg_name : string = "" -) -> (table : HMapChainedPtr(Type), error : AllocatorError) +) -> (table : HMapChained(Type), error : AllocatorError) { - header_size := size_of(HMapChained(Type)) + header_size := size_of(HMapChainedHeader(Type)) size := header_size + int(lookup_capacity) * size_of( ^HMapChainedSlot(Type)) + size_of(int) raw_mem : rawptr raw_mem, error = alloc( size, allocator = allocator ) if error != AllocatorError.None do return - table.header = cast( ^HMapChained(Type)) raw_mem + table.header = cast( ^HMapChainedHeader(Type)) raw_mem table.pool, error = pool_init( should_zero_buckets = false, block_size = size_of(HMapChainedSlot(Type)), @@ -74,12 +75,12 @@ hmap_chained_init :: proc( $Type : typeid, lookup_capacity : uint, allocator : A allocator = allocator, dbg_name = str_intern(str_fmt("%v: pool", dbg_name)).str ) - data := transmute([^] ^HMapChainedSlot(Type)) (transmute( [^]HMapChained(Type)) table.header)[1:] + data := transmute([^] ^HMapChainedSlot(Type)) (transmute( [^]HMapChainedHeader(Type)) table.header)[1:] table.lookup = slice_ptr( data, int(lookup_capacity) ) return } -hmap_chained_clear :: proc( using self : HMapChainedPtr($Type)) +hmap_chained_clear :: proc( using self : HMapChained($Type)) { for slot in lookup { @@ -93,19 +94,19 @@ hmap_chained_clear :: proc( using self : HMapChainedPtr($Type)) } } -hmap_chained_destroy :: proc( using self : ^HMapChainedPtr($Type)) { +hmap_chained_destroy :: proc( using self : ^HMapChained($Type)) { pool_destroy( pool ) free( self.header, backing) self = nil } -hmap_chained_lookup_id :: #force_inline proc( using self : HMapChainedPtr($Type), key : u64 ) -> u64 +hmap_chained_lookup_id :: #force_inline proc( using self : HMapChained($Type), key : u64 ) -> u64 { hash_index := key % u64( len(lookup) ) return hash_index } -hmap_chained_get :: proc( using self : HMapChainedPtr($Type), key : u64) -> ^Type +hmap_chained_get :: proc( using self : HMapChained($Type), key : u64) -> ^Type { // profile(#procedure) surface_slot := lookup[hmap_chained_lookup_id(self, key)] @@ -127,14 +128,14 @@ hmap_chained_get :: proc( using self : HMapChainedPtr($Type), key : u64) -> ^Typ return nil } -hmap_chained_reload :: proc( self : HMapChainedPtr($Type), allocator : Allocator ) +hmap_chained_reload :: proc( self : HMapChained($Type), allocator : Allocator ) { pool_reload(self.pool, allocator) } // Returns true if an slot was actually found and marked as vacant // Entries already found to be vacant will not return true -hmap_chained_remove :: proc( self : HMapChainedPtr($Type), key : u64 ) -> b32 +hmap_chained_remove :: proc( self : HMapChained($Type), key : u64 ) -> b32 { surface_slot := lookup[hmap_chained_lookup_id(self, key)] @@ -160,12 +161,12 @@ hmap_chained_remove :: proc( self : HMapChainedPtr($Type), key : u64 ) -> b32 // Sets the value to a vacant slot // Will preemptively allocate the next slot in the hashtable if its null for the slot. -hmap_chained_set :: proc( using self : HMapChainedPtr($Type), key : u64, value : Type ) -> (^ Type, AllocatorError) +hmap_chained_set :: proc( using self : HMapChained($Type), key : u64, value : Type ) -> (^ Type, AllocatorError) { // profile(#procedure) hash_index := hmap_chained_lookup_id(self, key) surface_slot := lookup[hash_index] - set_slot :: #force_inline proc( using self : HMapChainedPtr(Type), + set_slot :: #force_inline proc( using self : HMapChained(Type), slot : ^HMapChainedSlot(Type), key : u64, value : Type diff --git a/code/sectr/grime/hashmap_zpl.odin b/code/sectr/grime/hashmap_zpl.odin index f399257..37a6804 100644 --- a/code/sectr/grime/hashmap_zpl.odin +++ b/code/sectr/grime/hashmap_zpl.odin @@ -47,13 +47,13 @@ HMapZPL :: struct ( $ Type : typeid ) { entries : Array( HMapZPL_Entry(Type) ), } -hamp_zpl_init :: proc -( $ Type : typeid, allocator : Allocator, num : u64, dbg_name : string = "" ) -> ( HMapZPL( Type), AllocatorError ) +hmap_zpl_init :: proc +( $HMapZPL_Type : typeid / HMapZPL($Type), num : u64, allocator := context.allocator, dbg_name : string = "" ) -> ( HMapZPL( Type), AllocatorError ) { result : HMapZPL(Type) table_result, entries_result : AllocatorError - result.table, table_result = array_init_reserve( i64, allocator, num, dbg_name = dbg_name ) + result.table, table_result = make( Array(i64), num, dbg_name = dbg_name, allocator = allocator ) if table_result != AllocatorError.None { ensure( false, "Failed to allocate table array" ) return result, table_result @@ -61,7 +61,7 @@ hamp_zpl_init :: proc array_resize( & result.table, num ) slice.fill( slice_ptr( result.table.data, cast(int) result.table.num), -1 ) - result.entries, entries_result = array_init_reserve( HMapZPL_Entry(Type), allocator, num, dbg_name = dbg_name ) + result.entries, entries_result = make( Array( HMapZPL_Entry(Type) ), num, dbg_name = dbg_name, allocator = allocator ) if entries_result != AllocatorError.None { ensure( false, "Failed to allocate entries array" ) return result, entries_result @@ -122,7 +122,7 @@ hamp_zpl_rehash :: proc( ht : ^ HMapZPL( $ Type ), new_num : u64 ) -> AllocatorE ensure( false, "ZPL HMAP IS REHASHING" ) last_added_index : i64 - new_ht, init_result := hamp_zpl_init( Type, ht.table.backing, new_num, ht.table.dbg_name ) + new_ht, init_result := hmap_zpl_init( HMapZPL(Type), new_num, ht.table.backing, ht.table.dbg_name ) if init_result != AllocatorError.None { ensure( false, "New hamp_zpl failed to allocate" ) return init_result diff --git a/code/sectr/grime/mappings.odin b/code/sectr/grime/mappings.odin index bbf10e8..280fd53 100644 --- a/code/sectr/grime/mappings.odin +++ b/code/sectr/grime/mappings.odin @@ -156,7 +156,7 @@ import "codebase:grime" Array :: grime.Array array_to_slice :: grime.array_to_slice - array_init_reserve :: grime.array_init_reserve + array_init :: grime.array_init array_append :: grime.array_append array_append_at :: grime.array_append_at array_clear :: grime.array_clear @@ -165,6 +165,15 @@ import "codebase:grime" array_remove_at :: grime.array_remove_at array_resize :: grime.array_resize + StackFixed :: grime.StackFixed + + stack_clear :: grime.stack_clear + stack_push :: grime.stack_push + stack_pop :: grime.stack_pop + stack_peek_ref :: grime.stack_peek_ref + stack_peek :: grime.stack_peek + stack_push_contextless :: grime.stack_push_contextless + // filesystem file_exists :: grime.file_exists file_rewind :: grime.file_rewind @@ -296,6 +305,20 @@ is_power_of_two :: proc { is_power_of_two_uintptr, } +make :: proc { + array_init, + hmap_chained_init, + hmap_zpl_init, + + // Usual + make_slice, + make_dynamic_array, + make_dynamic_array_len, + make_dynamic_array_len_cap, + make_map, + make_multi_pointer, +} + // measure_text_size :: proc { // measure_text_size_raylib, // } diff --git a/code/sectr/grime/slab_allocator.odin b/code/sectr/grime/slab_allocator.odin index 8a7a9ba..bded63b 100644 --- a/code/sectr/grime/slab_allocator.odin +++ b/code/sectr/grime/slab_allocator.odin @@ -59,7 +59,7 @@ slab_allocator :: proc( slab : Slab ) -> ( allocator : Allocator ) { return } -slab_init :: proc( policy : ^SlabPolicy, bucket_reserve_num : uint = 0, allocator : Allocator, dbg_name : string = "", should_zero_buckets : b32 = false ) -> ( slab : Slab, alloc_error : AllocatorError ) +slab_init :: proc( policy : ^SlabPolicy, bucket_reserve_num : uint = 0, allocator : Allocator = context.allocator, dbg_name : string = "", should_zero_buckets : b32 = false ) -> ( slab : Slab, alloc_error : AllocatorError ) { header_size :: size_of( SlabHeader ) diff --git a/code/sectr/grime/stack.odin b/code/sectr/grime/stack.odin index c19c291..f5b8a72 100644 --- a/code/sectr/grime/stack.odin +++ b/code/sectr/grime/stack.odin @@ -3,51 +3,6 @@ package sectr import "core:mem" import "core:slice" -//region Fixed Stack - -StackFixed :: struct ( $ Type : typeid, $ Size : u32 ) { - idx : u32, - items : [ Size ] Type, -} - -stack_clear :: #force_inline proc ( using stack : ^StackFixed( $Type, $Size)) { - idx = 0 -} - -stack_push :: #force_inline proc( using stack : ^ StackFixed( $ Type, $ Size ), value : Type ) { - verify( idx < len( items ), "Attempted to push on a full stack" ) - - items[ idx ] = value - idx += 1 -} - -stack_pop :: #force_inline proc( using stack : ^StackFixed( $ Type, $ Size ) ) { - verify( idx > 0, "Attempted to pop an empty stack" ) - - idx -= 1 - if idx == 0 { - items[idx] = {} - } -} - -stack_peek_ref :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> ( ^Type) { - last_idx := max( 0, idx - 1 ) if idx > 0 else 0 - last := & items[last_idx] - return last -} - -stack_peek :: #force_inline proc "contextless" ( using stack : ^StackFixed( $ Type, $ Size ) ) -> Type { - last := max( 0, idx - 1 ) if idx > 0 else 0 - return items[last] -} - -stack_push_contextless :: #force_inline proc "contextless" ( stack : ^StackFixed( $Type, $Size), value : Type ) { - items[idx] = value - idx += 1 -} - -//endregion Fixed Stack - //region Stack Allocator // TODO(Ed) : This is untested and problably filled with bugs. diff --git a/code/sectr/grime/string_interning.odin b/code/sectr/grime/string_interning.odin index aa3b955..abe5ecd 100644 --- a/code/sectr/grime/string_interning.odin +++ b/code/sectr/grime/string_interning.odin @@ -63,10 +63,10 @@ str_cache_init :: proc( /*allocator : Allocator*/ ) -> ( cache : StringCache ) { state := get_state() alloc_error : AllocatorError - cache.slab, alloc_error = slab_init( & policy, allocator = persistent_allocator(), dbg_name = dbg_name ) + cache.slab, alloc_error = slab_init( & policy, dbg_name = dbg_name, allocator = persistent_allocator() ) verify(alloc_error == .None, "Failed to initialize the string cache" ) - cache.table, alloc_error = hamp_zpl_init( StrRunesPair, persistent_allocator(), 4 * Megabyte, dbg_name ) + cache.table, alloc_error = make( HMapZPL(StrRunesPair), 4 * Megabyte, persistent_allocator(), dbg_name ) return } diff --git a/code/sectr/parser/whitespace.odin b/code/sectr/parser/whitespace.odin index 83671e0..390ebbb 100644 --- a/code/sectr/parser/whitespace.odin +++ b/code/sectr/parser/whitespace.odin @@ -166,7 +166,7 @@ pws_parser_lex :: proc ( text : string, allocator : Allocator ) -> ( PWS_LexResu alloc_error : AllocatorError // tokens, alloc_error = array_init_reserve( PWS_Token, allocator, Kilobyte * 4 ) - tokens, alloc_error = array_init_reserve( PWS_Token, allocator, PWS_TokenArray_ReserveSize ) + tokens, alloc_error = make( Array(PWS_Token), PWS_TokenArray_ReserveSize, allocator ) if alloc_error != AllocatorError.None { ensure(false, "Failed to allocate token's array") return result, alloc_error @@ -259,10 +259,10 @@ pws_parser_parse :: proc( text : string, allocator : Allocator ) -> ( PWS_ParseR log( str_fmt( "parsing: %v ...", (len(text) > 30 ? transmute(string) bytes[ :30] : text) )) // TODO(Ed): Change this to use a node pool - nodes, alloc_error = array_init_reserve( PWS_AST, allocator, PWS_NodeArray_ReserveSize ) + nodes, alloc_error = make( Array(PWS_AST), PWS_NodeArray_ReserveSize, allocator ) verify( alloc_error == nil, "Allocation failure creating nodes array") - parser.lines, alloc_error = array_init_reserve( ^PWS_AST, allocator, PWS_LineArray_ReserveSize ) + parser.lines, alloc_error = make( Array( ^PWS_AST), PWS_LineArray_ReserveSize, allocator ) verify( alloc_error == nil, "Allocation failure creating line array") //region Helper procs diff --git a/code/sectr/ui/core/base.odin b/code/sectr/ui/core/base.odin index e54846c..7abced0 100644 --- a/code/sectr/ui/core/base.odin +++ b/code/sectr/ui/core/base.odin @@ -133,7 +133,7 @@ ui_startup :: proc( ui : ^ UI_State, cache_allocator : Allocator /* , cache_rese ui^ = {} for & cache in ui.caches { - box_cache, allocation_error := hamp_zpl_init( UI_Box, cache_allocator, UI_Built_Boxes_Array_Size ) + box_cache, allocation_error := make( HMapZPL(UI_Box), UI_Built_Boxes_Array_Size, cache_allocator ) verify( allocation_error == AllocatorError.None, "Failed to allocate box cache" ) cache = box_cache } @@ -141,7 +141,7 @@ ui_startup :: proc( ui : ^ UI_State, cache_allocator : Allocator /* , cache_rese ui.prev_cache = (& ui.caches[0]) allocation_error : AllocatorError - ui.render_queue, allocation_error = array_init_reserve( UI_RenderBoxInfo, cache_allocator, UI_Built_Boxes_Array_Size, fixed_cap = true ) + ui.render_queue, allocation_error = make( Array(UI_RenderBoxInfo), UI_Built_Boxes_Array_Size, cache_allocator, fixed_cap = true ) verify( allocation_error == AllocatorError.None, "Failed to allocate render queue" ) log("ui_startup completed") diff --git a/code/sectr/ui/floating.odin b/code/sectr/ui/floating.odin index 0126ae6..c5ab163 100644 --- a/code/sectr/ui/floating.odin +++ b/code/sectr/ui/floating.odin @@ -14,15 +14,15 @@ UI_FloatingBuilder :: #type proc( captures : rawptr ) -> (became_active : b32) UI_FloatingManager :: struct { using links : DLL_NodeFL(UI_Floating), build_queue : Array(UI_Floating), - tracked : HMapChainedPtr(UI_Floating), + tracked : HMapChained(UI_Floating), } -ui_floating_startup :: proc( self : ^UI_FloatingManager, allocator : Allocator, build_queue_cap, tracked_cap : u64, dbg_name : string = "" ) -> AllocatorError +ui_floating_startup :: proc( self : ^UI_FloatingManager, build_queue_cap, tracked_cap : u64, allocator := context.allocator, dbg_name : string = "" ) -> AllocatorError { error : AllocatorError queue_dbg_name := str_intern(str_fmt("%s: build_queue", dbg_name)) - self.build_queue, error = array_init_reserve( UI_Floating, allocator, build_queue_cap, dbg_name = queue_dbg_name.str ) + self.build_queue, error = make( Array(UI_Floating), build_queue_cap, dbg_name = queue_dbg_name.str, allocator = allocator ) if error != AllocatorError.None { ensure(false, "Failed to allocate the build_queue") @@ -30,7 +30,7 @@ ui_floating_startup :: proc( self : ^UI_FloatingManager, allocator : Allocator, } tracked_dbg_name := str_intern(str_fmt("%s: tracked", dbg_name)) - self.tracked, error = hmap_chained_init(UI_Floating, uint(tracked_cap), allocator, dbg_name = tracked_dbg_name.str ) + self.tracked, error = make( HMapChained(UI_Floating), uint(tracked_cap), allocator, dbg_name = tracked_dbg_name.str ) if error != AllocatorError.None { ensure(false, "Failed to allocate tracking table") diff --git a/code/sectr/ui/tests.odin b/code/sectr/ui/tests.odin index f9bdc9a..f39762b 100644 --- a/code/sectr/ui/tests.odin +++ b/code/sectr/ui/tests.odin @@ -189,7 +189,7 @@ test_whitespace_ast :: proc( default_layout : ^UI_Layout, frame_style_default : // index := 0 widgets : Array(UI_Widget) // widgets, alloc_error = array_init_reserve( UI_Widget, frame_slab_allocator(), 8 ) - widgets, alloc_error = array_init_reserve( UI_Widget, frame_slab_allocator(), 4 * Kilobyte ) + widgets, alloc_error = make( Array(UI_Widget), 4 * Kilobyte ) widgets_ptr := & widgets label_id := 0