From 343d558a94c0d1fd846f2b9f07b837dcc2a986b4 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 26 Jun 2024 13:28:54 -0400 Subject: [PATCH] Clean up of last remaining vestitudes of using my containers in VEFontCache --- code/font/VEFontCache/VEFontCache.odin | 1 + code/font/VEFontCache/mappings.odin | 107 +------------------------ code/font/VEFontCache/parser.odin | 22 ++--- 3 files changed, 18 insertions(+), 112 deletions(-) diff --git a/code/font/VEFontCache/VEFontCache.odin b/code/font/VEFontCache/VEFontCache.odin index 5b1f7a8..3f22c67 100644 --- a/code/font/VEFontCache/VEFontCache.odin +++ b/code/font/VEFontCache/VEFontCache.odin @@ -518,6 +518,7 @@ draw_text :: proc( ctx : ^Context, font : FontID, text_utf8 : string, position : last_byte_offset = byte_offset } + return true } diff --git a/code/font/VEFontCache/mappings.odin b/code/font/VEFontCache/mappings.odin index 9bfc49a..3369a43 100644 --- a/code/font/VEFontCache/mappings.odin +++ b/code/font/VEFontCache/mappings.odin @@ -21,57 +21,7 @@ AllocatorError :: mem.Allocator_Error import "codebase:grime" -// asserts -ensure :: grime.ensure -verify :: grime.verify - -// container - -Array :: grime.Array - -array_init :: grime.array_init -array_append :: grime.array_append -array_append_at :: grime.array_append_at -array_back :: grime.array_back -array_clear :: grime.array_clear -array_free :: grime.array_free -array_remove_at :: grime.array_remove_at -array_pop :: grime.array_pop -array_resize :: grime.array_resize -array_to_slice :: grime.array_to_slice -array_to_slice_cpacity :: grime.array_to_slice_capacity -array_underlying_slice :: grime.array_underlying_slice - -HMapChained :: grime.HMapChained - -hmap_chained_clear :: grime.hmap_chained_clear -hmap_chained_destroy :: grime.hmap_chained_destroy -hmap_chained_init :: grime.hmap_chained_init -hmap_chained_get :: grime.hmap_chained_get -hmap_chained_remove :: grime.hmap_chained_remove -hmap_chained_reload :: grime.hmap_chained_reload -hmap_chained_set :: grime.hmap_chained_set -hmap_closest_prime :: grime.hmap_closest_prime - -HMapZPL :: grime.HMapZPL - -hmap_zpl_clear :: grime.hmap_zpl_clear -hmap_zpl_init :: grime.hmap_zpl_init -hmap_zpl_get :: grime.hmap_zpl_get -hmap_zpl_reload :: grime.hmap_zpl_reload -hmap_zpl_remove :: grime.hmap_zpl_remove -hmap_zpl_set :: grime.hmap_zpl_set - -// Pool :: grime.Pool - -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 +hmap_closest_prime :: grime.hmap_closest_prime // logging log :: grime.log @@ -85,76 +35,27 @@ reload_map :: grime.reload_map //#region("Proc overload mappings") append :: proc { - grime.array_append_array, - grime.array_append_slice, - grime.array_append_value, - append_elem, - // append_elems, - // append_elem_string, -} - -append_at :: proc { - grime.array_append_at_slice, - grime.array_append_at_value, + append_elems, + append_elem_string, } clear :: proc { - array_clear, - hmap_chained_clear, - hmap_zpl_clear, - clear_dynamic_array, } -delete :: proc { - array_free, - hmap_chained_destroy, -} - -get :: proc { - hmap_chained_get, - hmap_zpl_get, -} - make :: proc { - array_init, - hmap_chained_init, - hmap_zpl_init, - make_map, - make_dynamic_array, make_dynamic_array_len, make_dynamic_array_len_cap, + make_map, } -// reload :: proc { - -// } - -remove_at :: proc { - array_remove_at, -} resize :: proc { - array_resize, - resize_dynamic_array, } -set :: proc { - hmap_chained_set, - hmap_zpl_set, -} - -to_slice :: proc { - array_to_slice, -} - -underlying_slice :: proc { - array_underlying_slice, -} - vec2 :: proc { vec2_from_scalar, } diff --git a/code/font/VEFontCache/parser.odin b/code/font/VEFontCache/parser.odin index fb97400..52796ec 100644 --- a/code/font/VEFontCache/parser.odin +++ b/code/font/VEFontCache/parser.odin @@ -9,6 +9,7 @@ That interface is not exposed from this parser but could be added to parser_init STB_Truetype has macros for its allocation unfortuantely */ +import "base:runtime" import "core:c" import "core:math" import stbtt "vendor:stb/truetype" @@ -45,7 +46,8 @@ ParserGlyphVertex :: struct { type : GlyphVertType, padding : u8, } -ParserGlyphShape :: []ParserGlyphVertex +// A shape can be a dynamic array free_type or an opaque set of data handled by stb_truetype +ParserGlyphShape :: [dynamic]ParserGlyphVertex ParserContext :: struct { kind : ParserKind, @@ -133,7 +135,7 @@ parser_free_shape :: proc( font : ^ParserFontInfo, shape : ParserGlyphShape ) switch font.kind { case .Freetype: - delete( array_underlying_slice(shape) ) + delete(shape) case .STB_TrueType: stbtt.FreeShape( & font.stbtt_info, transmute( [^]stbtt.vertex) raw_data(shape) ) @@ -252,7 +254,7 @@ parser_get_glyph_shape :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> FT_CURVE_TAG_ON :: 0x01 FT_CURVE_TAG_CUBIC :: 0x02 - vertices, error := make( Array(ParserGlyphVertex), 1024 ) + vertices, error := make( [dynamic]ParserGlyphVertex, 1024 ) assert( error == .None ) // TODO(Ed): This makes freetype second class I guess but VEFontCache doesn't have native support for freetype originally so.... @@ -275,7 +277,7 @@ parser_get_glyph_shape :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> if (tag & FT_CURVE_TAG_ON) != 0 { - if vertices.num > 0 && !(array_back(vertices).type == .Move ) + if len(vertices) > 0 && !(vertices[len(vertices) - 1].type == .Move ) { // Close the previous contour if needed append(& vertices, ParserGlyphVertex { type = .Line, @@ -353,16 +355,18 @@ parser_get_glyph_shape :: proc( font : ^ParserFontInfo, glyph_index : Glyph ) -> }) } - shape = array_to_slice(vertices) + shape = vertices } case .STB_TrueType: stb_shape : [^]stbtt.vertex nverts := stbtt.GetGlyphShape( & font.stbtt_info, cast(i32) glyph_index, & stb_shape ) - if nverts == 0 || shape == nil { - shape = transmute(ParserGlyphShape) stb_shape[0:0] - } - shape = transmute(ParserGlyphShape) stb_shape[:nverts] + + shape_raw := transmute( ^runtime.Raw_Dynamic_Array) & shape + shape_raw.data = stb_shape + shape_raw.len = int(nverts) + shape_raw.cap = int(nverts) + shape_raw.allocator = runtime.nil_allocator() error = AllocatorError.None return }