From 24a85dbadcc133f7cb1cc88ea615f93caeaf58e3 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 16 Dec 2022 18:12:38 +0900 Subject: [PATCH] [ui] Add a component set for passage hierarchy refs While "set" is a tad strong (there's just the one component for now), I had missed the changes when adding ECS systems. Fixes the segfault at the end of demo1 (ie, when any center text is printed). --- include/QF/ui/passage.h | 14 ++++++++++++-- include/QF/ui/text.h | 2 -- include/client/hud.h | 1 + libs/client/hud.c | 8 +++++++- libs/client/sbar.c | 3 ++- libs/ruamoko/rua_gui.c | 6 +++++- libs/ui/passage.c | 20 ++++++++++++++------ libs/ui/test/test-passage.c | 25 ++++++++----------------- libs/ui/text.c | 4 ---- 9 files changed, 49 insertions(+), 34 deletions(-) diff --git a/include/QF/ui/passage.h b/include/QF/ui/passage.h index 13ff097ed..ef23dd2f4 100644 --- a/include/QF/ui/passage.h +++ b/include/QF/ui/passage.h @@ -30,11 +30,21 @@ #include +#include "QF/ecs.h" + /** \defgroup passage Text passages \ingroup utils */ ///@{ +enum { + passage_href, + + passage_comp_count +}; + +extern const component_t passage_components[passage_comp_count]; + enum { passage_type_text_obj, @@ -52,12 +62,12 @@ typedef struct passage_s { const char *text; ///< Not owned by passage struct ecs_registry_s *reg; ///< Owning ECS registry - uint32_t href_comp; ///< Component for passage hierarcy reference + uint32_t comp_base; ///< Passage base component struct hierarchy_s *hierarchy; ///< hierarchy of text objects } passage_t; void Passage_ParseText (passage_t *passage, const char *text); -passage_t *Passage_New (struct ecs_registry_s *reg, uint32_t href_comp); +passage_t *Passage_New (ecs_system_t passage_sys); void Passage_Delete (passage_t *passage); int Passage_IsSpace (const char *text) __attribute__((pure)); diff --git a/include/QF/ui/text.h b/include/QF/ui/text.h index c3817eb9b..33ea226e1 100644 --- a/include/QF/ui/text.h +++ b/include/QF/ui/text.h @@ -73,8 +73,6 @@ typedef struct glyphset_s { } glyphset_t; enum { - // passage text object hierarcies - text_href, // all the glyphs in a passage. Always on only the root view of the passage. text_passage_glyphs, // glyphs for a single text object diff --git a/include/client/hud.h b/include/client/hud.h index e67d1180b..c3b7c7388 100644 --- a/include/client/hud.h +++ b/include/client/hud.h @@ -56,6 +56,7 @@ typedef struct hud_subpic_s { extern struct ecs_system_s hud_system; extern struct ecs_system_s hud_viewsys; +extern struct ecs_system_s hud_psgsys; extern int hud_sb_lines; diff --git a/libs/client/hud.c b/libs/client/hud.c index 68ef57864..580ffe45a 100644 --- a/libs/client/hud.c +++ b/libs/client/hud.c @@ -35,6 +35,7 @@ #include "QF/screen.h" #include "QF/render.h" #include "QF/plugin/vid_render.h" +#include "QF/ui/passage.h" #include "QF/ui/view.h" #include "compat.h" @@ -52,7 +53,7 @@ static const component_t hud_components[hud_comp_count] = { }, [hud_tile] = { .size = sizeof (byte), - .name = "pic", + .name = "tile", }, [hud_pic] = { .size = sizeof (qpic_t *), @@ -86,6 +87,7 @@ static const component_t hud_components[hud_comp_count] = { ecs_system_t hud_system; ecs_system_t hud_viewsys; +ecs_system_t hud_psgsys; int hud_sb_lines; int hud_sbar; @@ -263,10 +265,14 @@ HUD_Init (void) { hud_system.reg = ECS_NewRegistry (); hud_viewsys.reg = hud_system.reg; + hud_psgsys.reg = hud_system.reg; hud_system.base = ECS_RegisterComponents (hud_system.reg, hud_components, hud_comp_count); hud_viewsys.base = ECS_RegisterComponents (hud_system.reg, view_components, view_comp_count); + hud_psgsys.base = ECS_RegisterComponents (hud_system.reg, + passage_components, + passage_comp_count); ECS_CreateComponentPools (hud_system.reg); } diff --git a/libs/client/sbar.c b/libs/client/sbar.c index 9d6220d3f..7711e9437 100644 --- a/libs/client/sbar.c +++ b/libs/client/sbar.c @@ -2554,7 +2554,8 @@ Sbar_Init (int *stats, float *item_gettime) sbar_stats = stats; sbar_item_gettime = item_gettime; - center_passage.reg = hud_viewsys.reg; + center_passage.reg = hud_psgsys.reg; + center_passage.comp_base = hud_psgsys.base; HUD_Init_Cvars (); Cvar_AddListener (Cvar_FindVar ("hud_sbar"), sbar_hud_sbar_f, 0); Cvar_AddListener (Cvar_FindVar ("hud_swap"), sbar_hud_swap_f, 0); diff --git a/libs/ruamoko/rua_gui.c b/libs/ruamoko/rua_gui.c index a0f027bd5..d9994d058 100644 --- a/libs/ruamoko/rua_gui.c +++ b/libs/ruamoko/rua_gui.c @@ -72,6 +72,7 @@ typedef struct { ecs_registry_t *reg; uint32_t text_base; uint32_t view_base; + uint32_t passage_base; } gui_resources_t; static rua_passage_t * @@ -230,7 +231,8 @@ bi (Font_Load) bi (Passage_New) { gui_resources_t *res = _res; - passage_t *passage = Passage_New (res->reg, res->text_base + text_href); + ecs_system_t passage_sys = { .reg = res->reg, .base = res->passage_base }; + passage_t *passage = Passage_New (passage_sys); R_INT (pr) = alloc_passage (res, passage); } @@ -457,5 +459,7 @@ RUA_GUI_Init (progs_t *pr, int secure) text_comp_count); res->view_base = ECS_RegisterComponents (res->reg, view_components, view_comp_count); + res->passage_base = ECS_RegisterComponents (res->reg, passage_components, + passage_comp_count); ECS_CreateComponentPools (res->reg); } diff --git a/libs/ui/passage.c b/libs/ui/passage.c index 163f7de2b..089823267 100644 --- a/libs/ui/passage.c +++ b/libs/ui/passage.c @@ -44,7 +44,14 @@ #include "QF/ui/passage.h" #include "QF/ui/view.h" -static const component_t passage_components[passage_type_count] = { +const component_t passage_components[passage_comp_count] = { + [passage_href] = { + .size = sizeof (hierref_t), + .name = "passage href", + }, +}; + +static const component_t passage_type_components[passage_type_count] = { [passage_type_text_obj] = { .size = sizeof (psg_text_t), .name = "Text", @@ -53,7 +60,7 @@ static const component_t passage_components[passage_type_count] = { static const hierarchy_type_t passage_type = { .num_components = passage_type_count, - .components = passage_components, + .components = passage_type_components, }; VISIBLE int @@ -129,7 +136,8 @@ Passage_ParseText (passage_t *passage, const char *text) } root_text.size = c - text; } - passage->hierarchy = Hierarchy_New (passage->reg, passage->href_comp, + passage->hierarchy = Hierarchy_New (passage->reg, + passage->comp_base + passage_href, &passage_type, 0); Hierarchy_Reserve (passage->hierarchy, 1 + num_paragraphs + num_text_objects); @@ -198,12 +206,12 @@ Passage_ParseText (passage_t *passage, const char *text) } VISIBLE passage_t * -Passage_New (ecs_registry_t *reg, uint32_t href_comp) +Passage_New (ecs_system_t passage_sys) { passage_t *passage = malloc (sizeof (passage_t)); passage->text = 0; - passage->reg = reg; - passage->href_comp = href_comp; + passage->reg = passage_sys.reg; + passage->comp_base = passage_sys.base; passage->hierarchy = 0; return passage; } diff --git a/libs/ui/test/test-passage.c b/libs/ui/test/test-passage.c index 1998cedeb..74c917160 100644 --- a/libs/ui/test/test-passage.c +++ b/libs/ui/test/test-passage.c @@ -7,18 +7,6 @@ #include "QF/ui/passage.h" #include "QF/ecs/component.h" -enum { - test_href, -}; - -static const component_t test_components[] = { - [test_href] = { - .size = sizeof (hierref_t), - .create = 0,//create_href, - .name = "href", - }, -}; - static const char test_text[] = { "Guarding the entrance to the Grendal " "Gorge is the Shadow Gate, a small keep " @@ -62,11 +50,14 @@ int main (void) { int ret = 0; - ecs_registry_t *registry = ECS_NewRegistry (); - ECS_RegisterComponents (registry, test_components, 1); - ECS_CreateComponentPools (registry); + ecs_system_t psg_sys = { + .reg = ECS_NewRegistry (), + .base = ECS_RegisterComponents (psg_sys.reg, passage_components, + passage_comp_count), + }; + ECS_CreateComponentPools (psg_sys.reg); - passage_t *passage = Passage_New (registry, test_href); + passage_t *passage = Passage_New (psg_sys); Passage_ParseText (passage, test_text); if (passage->hierarchy->childCount[0] != 3) { ret = 1; @@ -136,6 +127,6 @@ main (void) } Passage_Delete (passage); - ECS_DelRegistry (registry); + ECS_DelRegistry (psg_sys.reg); return ret; } diff --git a/libs/ui/text.c b/libs/ui/text.c index ee3c226b0..3970b45a2 100644 --- a/libs/ui/text.c +++ b/libs/ui/text.c @@ -58,10 +58,6 @@ text_features_destroy (void *_features) } const component_t text_components[text_comp_count] = { - [text_href] = { - .size = sizeof (hierref_t), - .name = "href", - }, [text_passage_glyphs] = { .size = sizeof (glyphset_t), .name = "passage glyphs",