mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-04-23 10:01:13 +00:00
[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).
This commit is contained in:
parent
61f61baf48
commit
24a85dbadc
9 changed files with 49 additions and 34 deletions
|
@ -30,11 +30,21 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#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));
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue