Implemented expand method for Vec<T> of primitive T. FINALLY. On my way to make Lucy better
This commit is contained in:
parent
36396a0a7d
commit
306536c214
@ -18,7 +18,6 @@ void codegen_append_VecT_struct(VecU8* res, SpanU8 T, bool skip_declaration_gen)
|
||||
"};\n\n", T, T);
|
||||
}
|
||||
|
||||
// todo: add resize method
|
||||
/* if !primitive, requires methods T_drop, and, if also clonable, requires method T_clone */
|
||||
void codegen_append_VecT_base_methods(VecU8* res, SpanU8 T, bool primitive, bool clonable) {
|
||||
VecU8_append_fmt(res, "#define Vec%s_new() ((Vec%s){ 0 })\n\n", T, T);
|
||||
@ -73,6 +72,24 @@ void codegen_append_VecT_base_methods(VecU8* res, SpanU8 T, bool primitive, bool
|
||||
SPACE SPACE "%s_drop(self->buf[i]);\n", /* T */
|
||||
T));
|
||||
|
||||
if (primitive) {
|
||||
/* It is not a strict resize. If we are currently longer than new_length, we do nothing.
|
||||
* New space gets initialized with garbage */
|
||||
VecU8_append_fmt(res,
|
||||
"void Vec%s_expand(Vec%s* self, size_t new_length, %s filler) {\n" /* T, T, T */
|
||||
SPACE "if (self->len >= new_length)\n"
|
||||
SPACE SPACE "return;\n"
|
||||
SPACE "if (new_length > self->capacity) {\n"
|
||||
SPACE SPACE "size_t new_capacity = Vec_get_new_capacity(self->capacity, new_length);\n"
|
||||
SPACE SPACE "self->buf = (%s*)safe_realloc(self->buf, new_capacity * sizeof(%s));\n" /* T, T */
|
||||
SPACE SPACE "self->capacity = new_capacity;\n"
|
||||
SPACE "}\n"
|
||||
SPACE "for (size_t i = self->len; i < new_length; i++)\n"
|
||||
SPACE SPACE "self->buf[i] = filler;\n"
|
||||
SPACE "self->len = new_length;\n"
|
||||
"}\n\n", T, T, T, T, T);
|
||||
}
|
||||
|
||||
if (clonable) {
|
||||
VecU8_append_fmt(res,
|
||||
"NODISCARD Vec%s Vec%s_clone(const Vec%s* self) {\n" /* T, T, T */
|
||||
|
||||
@ -1635,7 +1635,7 @@ Alice* Alice_new(){
|
||||
return alice;
|
||||
}
|
||||
|
||||
/* Helper function. Automatically aquires the slot */
|
||||
/* Helper function. Automatically acquires the slot */
|
||||
U32 Alice__find_free_texture_slot(Alice* alice) {
|
||||
for (U32 i = 0; i < alice->texture_slots.len; i++) {
|
||||
if (!alice->texture_slots.buf[i].is_some) {
|
||||
|
||||
@ -306,12 +306,8 @@ void LucyGlyphCache_add_glyphs(LucyGlyphCache* cache, VecLucyGlyphCachingRequest
|
||||
starting_x = 0;
|
||||
goto one_more_chance;
|
||||
}
|
||||
// todo: replace with resize method
|
||||
// todo: Add expand method to vector
|
||||
for (U32 h = img_width; h < new_width_required; h++) {
|
||||
VecU32_append(&landscape, 0);
|
||||
}
|
||||
img_width = MAX_U64(img_width, new_width_required);
|
||||
VecU32_expand(&landscape, new_width_required, 0);
|
||||
img_width = landscape.len;
|
||||
U32 height_here = 0;
|
||||
for (size_t x = 0; x < p_glyph->bitmap.width; x++) {
|
||||
height_here = MAX_U32(height_here, *VecU32_at(&landscape, starting_x + x));
|
||||
|
||||
@ -341,6 +341,7 @@ void run_app(){
|
||||
});
|
||||
ranges_needed = VecU32Segment_new();
|
||||
VecU32Segment_append(&ranges_needed, (U32Segment){.start = 0x430, .len = 0x44f - 0x430 + 1});
|
||||
VecU32Segment_append(&ranges_needed, (U32Segment){.start = 0x410, .len = 0x42f - 0x410 + 1});
|
||||
VecLucyGlyphCachingRequest_append(&lucy_requests, (LucyGlyphCachingRequest){
|
||||
.sized_face = st.font_face_of_size_40, .codepoint_ranges = ranges_needed,
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user