Skip to content

Fix nametags color and rendering order#1150

Open
PeachyPeachSM64 wants to merge 2 commits intocoop-deluxe:devfrom
PeachyPeachSM64:fix-nametags
Open

Fix nametags color and rendering order#1150
PeachyPeachSM64 wants to merge 2 commits intocoop-deluxe:devfrom
PeachyPeachSM64:fix-nametags

Conversation

@PeachyPeachSM64
Copy link
Contributor

  • Fixed nametags color and rendering order:
image

Nametags now support color codes and are rendered based on their distance to the camera.

  • Added 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).
image

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.

  • Made HUD interpolations unlimited using a Growing Array.
  • Fixed a bug in regular text rendering not using the correct alpha value for color codes.

@PeachyPeachSM64
Copy link
Contributor Author

@Isaac0-dev

  • moved growing_array_init in djui_hud_clear_interp_data
  • growing_array_init can reuse array and buffer if already allocated

Copy link
Contributor

@Isaac0-dev Isaac0-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since every field of the growing array structure is set in this function, for performance this can safely be changed to:

Suggested change
array = calloc(1, sizeof(struct GrowingArray));
array = malloc(sizeof(struct GrowingArray));

Comment on lines +214 to +216
array->buffer = buffer;
array->capacity = capacity;
memset(array->buffer, 0, sizeof(void *) * array->capacity);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array->capacity is set below too, so

Suggested change
array->buffer = buffer;
array->capacity = capacity;
memset(array->buffer, 0, sizeof(void *) * array->capacity);
memset(buffer, 0, sizeof(void *) * capacity);
array->buffer = buffer;

Comment on lines +188 to +198
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;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants