From 964c6c852d89a277094af82c05c1b8425a4db218 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Sun, 16 Jun 2024 08:56:06 -0400 Subject: [PATCH] Fixes to shape cache and atlas region math --- code/font/VEFontCache/VEFontCache.odin | 9 +++++---- code/font/VEFontCache/atlas.odin | 2 +- code/grime/hashmap_zpl.odin | 2 +- code/grime/memory_tracker.odin | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index 12164e3..ce1cbf7 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -156,8 +156,8 @@ eval_point_on_bezier4 :: proc( p0, p1, p2, p3 : Vec2, alpha : f32 ) -> Vec2 screenspace_x_form :: proc( position, scale : ^Vec2, width, height : f32 ) { scale.x = (scale.x / width ) * 2.0 scale.y = (scale.y / height) * 2.0 - position.x = position.x * (2.0 / width) - 1.0 - position.y = position.y * (2.0 / width) - 1.0 + position.x = position.x * (2.0 / width) - 1.0 + position.y = position.y * (2.0 / height) - 1.0 } textspace_x_form :: proc( position, scale : ^Vec2, width, height : f32 ) { @@ -310,7 +310,7 @@ init :: proc( ctx : ^Context, parser_kind : ParserKind, LRU_init( & shape_cache.state, shape_cache_params.capacity ) - shape_cache.storage, error = make( Array(ShapedText), u64(shape_cache_params.reserve_length) ) + shape_cache.storage, error = make( Array(ShapedText), u64(shape_cache_params.capacity) ) assert(error == .None, "VEFontCache.init : Failed to allocate shape_cache.storage") for idx : u32 = 0; idx < shape_cache_params.capacity; idx += 1 { @@ -716,6 +716,7 @@ shape_text_cached :: proc( ctx : ^Context, font : FontID, text_utf8 : string ) - if shape_cache.next_cache_id < i32(state.capacity) { shape_cache_idx = shape_cache.next_cache_id LRU_put( state, hash, shape_cache_idx ) + shape_cache.next_cache_id += 1 } else { @@ -798,6 +799,6 @@ shape_text_uncached :: proc( ctx : ^Context, font : FontID, output : ^ShapedText prev_codepoint = codepoint } - output.end_cursor_pos = position + // output.end_cursor_pos = position } } diff --git a/code/font/VEFontCache/atlas.odin b/code/font/VEFontCache/atlas.odin index ac2b0bb..e8341c8 100644 --- a/code/font/VEFontCache/atlas.odin +++ b/code/font/VEFontCache/atlas.odin @@ -140,7 +140,7 @@ decide_codepoint_region :: proc( ctx : ^Context, entry : ^Entry, glyph_index : G region_kind = .A region = & atlas.region_a } - else if bounds_width_scaled <= atlas.region_a.width && bounds_height_scaled <= atlas.region_a.height + else if bounds_width_scaled <= atlas.region_b.width && bounds_height_scaled <= atlas.region_b.height { // Region B for tall glyphs. These are good for things such as european alphabets. region_kind = .B diff --git a/code/grime/hashmap_zpl.odin b/code/grime/hashmap_zpl.odin index 302b3ed..1abb328 100644 --- a/code/grime/hashmap_zpl.odin +++ b/code/grime/hashmap_zpl.odin @@ -111,7 +111,7 @@ hmap_zpl_map_mut :: proc( using self : ^ HMapZPL( $ Type), map_proc : HMapZPL_Ma } hmap_zpl_grow :: proc( using self : ^ HMapZPL( $ Type ) ) -> AllocatorError { - new_num := array_grow_formula( entries.num ) + new_num : u64 = cast(u64) hmap_closest_prime( cast(uint) array_grow_formula( entries.num ) ) return hmap_zpl_rehash( self, new_num ) } diff --git a/code/grime/memory_tracker.odin b/code/grime/memory_tracker.odin index 04b46ea..a73674f 100644 --- a/code/grime/memory_tracker.odin +++ b/code/grime/memory_tracker.odin @@ -17,7 +17,7 @@ MemoryTracker :: struct { entries : Array(MemoryTrackerEntry), } -Track_Memory :: true +Track_Memory :: false memtracker_clear :: proc ( tracker : MemoryTracker ) { when ! Track_Memory {