Fix nametags color and rendering order#1150
Fix nametags color and rendering order#1150PeachyPeachSM64 wants to merge 2 commits intocoop-deluxe:devfrom
Conversation
|
Isaac0-dev
left a comment
There was a problem hiding this comment.
not a full review, just looked at the growing array stuff so far. I'll come back when I've got more time.
| if (!array->buffer || array->capacity != capacity) { | ||
| void **buffer = realloc(array->buffer, sizeof(void *) * capacity); | ||
|
|
||
| // if realloc fails, destroy the array and create a new one |
There was a problem hiding this comment.
If the new capacity is smaller, there should almost never be a situation where the realloc fails but the standard alloc succeeds. (doesn't require any change, just observing)
| memset(array->buffer, 0, sizeof(void *) * array->capacity); | ||
| } | ||
| } else { | ||
| array = calloc(1, sizeof(struct GrowingArray)); |
There was a problem hiding this comment.
since every field of the growing array structure is set in this function, for performance this can safely be changed to:
| array = calloc(1, sizeof(struct GrowingArray)); | |
| array = malloc(sizeof(struct GrowingArray)); |
| array->buffer = buffer; | ||
| array->capacity = capacity; | ||
| memset(array->buffer, 0, sizeof(void *) * array->capacity); |
There was a problem hiding this comment.
array->capacity is set below too, so
| array->buffer = buffer; | |
| array->capacity = capacity; | |
| memset(array->buffer, 0, sizeof(void *) * array->capacity); | |
| memset(buffer, 0, sizeof(void *) * capacity); | |
| array->buffer = buffer; |
| static void growing_array_free_elements(struct GrowingArray *array) { | ||
| if (array) { | ||
| for (u32 i = 0; i != array->capacity; ++i) { | ||
| if (array->buffer[i]) { | ||
| array->free(array->buffer[i]); | ||
| array->buffer[i] = NULL; | ||
| } | ||
| } | ||
| array->count = 0; | ||
| } | ||
| } |
There was a problem hiding this comment.
It's good practice that you've added this but, but both uses of this function (in growing_array_init and growing_array_free) the lines array->buffer[i] = NULL; and array->count = 0; go unused. Because growing_array_init clears the buffer, and growing_array_free frees it.
I guess at this point we're asking how fast we need the growing array to be.
Nametags now support color codes and are rendered based on their distance to the camera.
djui_hud_get/set/reset_text_color. Text color refers to the default color the text uses outside of color codes. Color codes are not affected by this color, but are still affected by the HUD color (djui_hud_get/set/reset_color).Line 1 is HUD color set to magenta. Notice that it also affects the word "color", which is normally yellow.
Line 2 is HUD alpha set to 50%. It affects all words, including the ones with color codes.
Line 3 is Text color set to magenta. None of the color codes are affected.
Line 4 is Text alpha set to 50%. None of the color codes are affected, they still are full opaque.