[gamecode] Support printing a single edict field

This commit is contained in:
Bill Currie 2021-07-25 09:54:08 +09:00
parent 342ba65f57
commit 81f73e4524
9 changed files with 69 additions and 35 deletions

View file

@ -292,9 +292,9 @@ void ED_Count (progs_t *pr);
qboolean PR_EdictValid (progs_t *pr, pr_int_t e) __attribute__((pure)); qboolean PR_EdictValid (progs_t *pr, pr_int_t e) __attribute__((pure));
// pr_debug.c // pr_debug.c
void ED_Print (progs_t *pr, edict_t *ed); void ED_Print (progs_t *pr, edict_t *ed, const char *fieldname);
void ED_PrintEdicts (progs_t *pr, const char *fieldval); void ED_PrintEdicts (progs_t *pr, const char *fieldval);
void ED_PrintNum (progs_t *pr, pr_int_t ent); void ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname);
// pr_parse.c // pr_parse.c
struct script_s; struct script_s;

View file

@ -1716,23 +1716,42 @@ PR_Profile (progs_t * pr)
} while (best); } while (best);
} }
static void
print_field (progs_t *pr, edict_t *ed, pr_def_t *d)
{
prdeb_resources_t *res = pr->pr_debug_resources;
int l;
pr_type_t *v;
qfot_type_t dummy_type = { };
qfot_type_t *type;
pr_debug_data_t data = {pr, res->dstr};
const char *name;
name = PR_GetString (pr, d->name);
type = get_def_type (pr, d, &dummy_type);
v = &E_fld (ed, d->ofs);
l = 15 - strlen (name);
if (l < 1)
l = 1;
dstring_clearstr (res->dstr);
value_string (&data, type, v);
Sys_Printf ("%s%*s%s\n", name, l, "", res->dstr->str);
}
/* /*
ED_Print ED_Print
For debugging For debugging
*/ */
VISIBLE void VISIBLE void
ED_Print (progs_t *pr, edict_t *ed) ED_Print (progs_t *pr, edict_t *ed, const char *fieldname)
{ {
prdeb_resources_t *res = pr->pr_debug_resources;
int l;
pr_uint_t i, j; pr_uint_t i, j;
const char *name; const char *name;
pr_def_t *d; pr_def_t *d;
pr_type_t *v; int l;
qfot_type_t dummy_type = { };
qfot_type_t *type;
pr_debug_data_t data = {pr, res->dstr};
if (ed->free) { if (ed->free) {
Sys_Printf ("FREE\n"); Sys_Printf ("FREE\n");
@ -1740,14 +1759,23 @@ ED_Print (progs_t *pr, edict_t *ed)
} }
Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed)); Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed));
if (fieldname) {
d = PR_FindField(pr, fieldname);
if (!d) {
Sys_Printf ("unknown field '%s'\n", fieldname);
} else {
print_field (pr, ed, d);
}
return;
}
for (i = 0; i < pr->progs->numfielddefs; i++) { for (i = 0; i < pr->progs->numfielddefs; i++) {
d = &pr->pr_fielddefs[i]; d = &pr->pr_fielddefs[i];
if (!d->name) // null field def (probably 1st) if (!d->name) // null field def (probably 1st)
continue; continue;
type = get_def_type (pr, d, &dummy_type);
name = PR_GetString (pr, d->name); name = PR_GetString (pr, d->name);
if (name[strlen (name) - 2] == '_' l = strlen (name);
&& strchr ("xyz", name[strlen (name) -1])) if (l >= 2 && name[l - 2] == '_' && strchr ("xyz", name[l - 1]))
continue; // skip _x, _y, _z vars continue; // skip _x, _y, _z vars
for (j = 0; j < d->size; j++) { for (j = 0; j < d->size; j++) {
@ -1759,15 +1787,7 @@ ED_Print (progs_t *pr, edict_t *ed)
continue; continue;
} }
v = &E_fld (ed, d->ofs); print_field (pr, ed, d);
l = 15 - strlen (name);
if (l < 1)
l = 1;
dstring_clearstr (res->dstr);
value_string (&data, type, v);
Sys_Printf ("%s%*s%s\n", name, l, "", res->dstr->str);
} }
} }

View file

@ -132,13 +132,13 @@ ED_Free (progs_t *pr, edict_t *ed)
VISIBLE void VISIBLE void
ED_PrintNum (progs_t *pr, pr_int_t ent) ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname)
{ {
if (!pr->num_edicts) { if (!pr->num_edicts) {
Sys_Printf ("Edicts not supported in this VM\n"); Sys_Printf ("Edicts not supported in this VM\n");
return; return;
} }
ED_Print (pr, EDICT_NUM (pr, ent)); ED_Print (pr, EDICT_NUM (pr, ent), fieldname);
} }
/* /*
@ -164,13 +164,13 @@ ED_PrintEdicts (progs_t *pr, const char *fieldval)
for (i = 0; i < *pr->num_edicts; i++) for (i = 0; i < *pr->num_edicts; i++)
if (strequal(fieldval, if (strequal(fieldval,
E_GSTRING (pr, EDICT_NUM(pr, i), def->ofs))) { E_GSTRING (pr, EDICT_NUM(pr, i), def->ofs))) {
ED_PrintNum (pr, i); ED_PrintNum (pr, i, 0);
count++; count++;
} }
Sys_Printf ("%i entities\n", count); Sys_Printf ("%i entities\n", count);
} else { } else {
for (i = 0; i < *pr->num_edicts; i++) for (i = 0; i < *pr->num_edicts; i++)
ED_PrintNum (pr, i); ED_PrintNum (pr, i, 0);
Sys_Printf ("%i entities\n", *pr->num_edicts); Sys_Printf ("%i entities\n", *pr->num_edicts);
} }
} }

View file

@ -475,7 +475,7 @@ ED_SpawnEntities (progs_t *pr, plitem_t *entity_list)
func = PR_FindFunction (pr, classname); func = PR_FindFunction (pr, classname);
if (!func) { if (!func) {
Sys_Printf ("No spawn function for :\n"); Sys_Printf ("No spawn function for :\n");
ED_Print (pr, ent); ED_Print (pr, ent, 0);
ED_Free (pr, ent); ED_Free (pr, ent);
continue; continue;
} }

View file

@ -343,7 +343,7 @@ PF_traceoff (progs_t *pr)
static void static void
PF_eprint (progs_t *pr) PF_eprint (progs_t *pr)
{ {
ED_PrintNum (pr, P_EDICTNUM (pr, 0)); ED_PrintNum (pr, P_EDICTNUM (pr, 0), 0);
} }
/* /*

View file

@ -74,7 +74,7 @@ PF_error (progs_t *pr)
Sys_Printf ("======SERVER ERROR in %s:\n%s\n", Sys_Printf ("======SERVER ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
ed = PROG_TO_EDICT (pr, *sv_globals.self); ed = PROG_TO_EDICT (pr, *sv_globals.self);
ED_Print (pr, ed); ED_Print (pr, ed, 0);
Host_Error ("Program error"); Host_Error ("Program error");
} }
@ -98,7 +98,7 @@ PF_objerror (progs_t *pr)
Sys_Printf ("======OBJECT ERROR in %s:\n%s\n", Sys_Printf ("======OBJECT ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
ed = PROG_TO_EDICT (pr, *sv_globals.self); ed = PROG_TO_EDICT (pr, *sv_globals.self);
ED_Print (pr, ed); ED_Print (pr, ed, 0);
ED_Free (pr, ed); ED_Free (pr, ed);
Host_Error ("Program error"); Host_Error ("Program error");

View file

@ -126,10 +126,17 @@ static void
ED_PrintEdict_f (void) ED_PrintEdict_f (void)
{ {
int i; int i;
const char *fieldname = 0;
if (Cmd_Argc () < 2) {
Sys_Printf ("edict num [fieldname]\n");
return;
}
if (Cmd_Argc () >= 3) {
fieldname = Cmd_Argv (2);
}
i = atoi (Cmd_Argv (1)); i = atoi (Cmd_Argv (1));
Sys_Printf ("\n EDICT %i:\n", i); ED_PrintNum (&sv_pr_state, i, fieldname);
ED_PrintNum (&sv_pr_state, i);
} }
static void static void

View file

@ -76,7 +76,7 @@ PF_error (progs_t *pr)
Sys_Printf ("======SERVER ERROR in %s:\n%s\n", Sys_Printf ("======SERVER ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
ed = PROG_TO_EDICT (pr, *sv_globals.self); ed = PROG_TO_EDICT (pr, *sv_globals.self);
ED_Print (pr, ed); ED_Print (pr, ed, 0);
Sys_Error ("Program error"); Sys_Error ("Program error");
} }
@ -100,7 +100,7 @@ PF_objerror (progs_t *pr)
Sys_Printf ("======OBJECT ERROR in %s:\n%s\n", Sys_Printf ("======OBJECT ERROR in %s:\n%s\n",
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s); PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
ed = PROG_TO_EDICT (pr, *sv_globals.self); ed = PROG_TO_EDICT (pr, *sv_globals.self);
ED_Print (pr, ed); ED_Print (pr, ed, 0);
ED_Free (pr, ed); ED_Free (pr, ed);
PR_RunError (pr, "object error"); PR_RunError (pr, "object error");

View file

@ -151,10 +151,17 @@ static void
ED_PrintEdict_f (void) ED_PrintEdict_f (void)
{ {
int i; int i;
const char *fieldname = 0;
if (Cmd_Argc () < 2) {
SV_Printf ("edict num [fieldname]\n");
return;
}
if (Cmd_Argc () >= 3) {
fieldname = Cmd_Argv (2);
}
i = atoi (Cmd_Argv (1)); i = atoi (Cmd_Argv (1));
SV_Printf ("\n EDICT %i:\n", i); ED_PrintNum (&sv_pr_state, i, fieldname);
ED_PrintNum (&sv_pr_state, i);
} }
static void static void