From d5de8bf53f4b91b9fe2056664f89c7f75a6c38ca Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sun, 6 Nov 2022 03:08:50 +0900 Subject: [PATCH] [nq] Get hud_sbar working for the most part Setting the parent to another object in the same hierarchy still causes a segfault (worked around for now), but the mangled views were caused by View_UpdateHierarchy not being called prior to the first call to set_hud_sbar (why, though? I suspect something to do with oldlen). And ECS_SortComponentPool finally gets used to ensure the sbar panels are behind the info pics. --- nq/source/sbar.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nq/source/sbar.c b/nq/source/sbar.c index b92eb067e..a44a0fb0f 100644 --- a/nq/source/sbar.c +++ b/nq/source/sbar.c @@ -1603,6 +1603,20 @@ sbar_hud_swap_f (void *data, const cvar_t *cvar) View_UpdateHierarchy (hud_view); } +static int +href_cmp (const void *_a, const void *_b, void *arg) +{ + uint32_t enta = *(const uint32_t *)_a; + uint32_t entb = *(const uint32_t *)_b; + hierref_t *ref_a = Ent_GetComponent (enta, hud_href, hud_registry); + hierref_t *ref_b = Ent_GetComponent (entb, hud_href, hud_registry); + if (ref_a->hierarchy == ref_b->hierarchy) { + return ref_a->index - ref_b->index; + } + ptrdiff_t diff = ref_a->hierarchy - ref_b->hierarchy; + return diff > 0 ? 1 : diff < 0 ? -1 : 0; +} + static void set_hud_sbar (void) { @@ -1690,6 +1704,7 @@ set_hud_sbar (void) sbar_remcomponent (sbar_inventory, hud_pic); sbar_remcomponent (sbar_statusbar, hud_pic); } + ECS_SortComponentPool (hud_registry, hud_pic, href_cmp, 0); } static void @@ -2240,6 +2255,7 @@ Sbar_Init (void) load_pics (); init_views (); + View_UpdateHierarchy (sbar_main); set_hud_sbar (); View_UpdateHierarchy (sbar_main);