mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 23:11:38 +00:00
[gamecode] Support printing a single edict field
This commit is contained in:
parent
342ba65f57
commit
81f73e4524
9 changed files with 69 additions and 35 deletions
|
@ -292,9 +292,9 @@ void ED_Count (progs_t *pr);
|
|||
qboolean PR_EdictValid (progs_t *pr, pr_int_t e) __attribute__((pure));
|
||||
|
||||
// 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_PrintNum (progs_t *pr, pr_int_t ent);
|
||||
void ED_PrintNum (progs_t *pr, pr_int_t ent, const char *fieldname);
|
||||
|
||||
// pr_parse.c
|
||||
struct script_s;
|
||||
|
|
|
@ -1716,23 +1716,42 @@ PR_Profile (progs_t * pr)
|
|||
} 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
|
||||
|
||||
For debugging
|
||||
*/
|
||||
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;
|
||||
const char *name;
|
||||
pr_def_t *d;
|
||||
pr_type_t *v;
|
||||
qfot_type_t dummy_type = { };
|
||||
qfot_type_t *type;
|
||||
pr_debug_data_t data = {pr, res->dstr};
|
||||
int l;
|
||||
|
||||
if (ed->free) {
|
||||
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));
|
||||
|
||||
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++) {
|
||||
d = &pr->pr_fielddefs[i];
|
||||
if (!d->name) // null field def (probably 1st)
|
||||
continue;
|
||||
type = get_def_type (pr, d, &dummy_type);
|
||||
name = PR_GetString (pr, d->name);
|
||||
if (name[strlen (name) - 2] == '_'
|
||||
&& strchr ("xyz", name[strlen (name) -1]))
|
||||
l = strlen (name);
|
||||
if (l >= 2 && name[l - 2] == '_' && strchr ("xyz", name[l - 1]))
|
||||
continue; // skip _x, _y, _z vars
|
||||
|
||||
for (j = 0; j < d->size; j++) {
|
||||
|
@ -1759,15 +1787,7 @@ ED_Print (progs_t *pr, edict_t *ed)
|
|||
continue;
|
||||
}
|
||||
|
||||
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);
|
||||
print_field (pr, ed, d);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -132,13 +132,13 @@ ED_Free (progs_t *pr, edict_t *ed)
|
|||
|
||||
|
||||
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) {
|
||||
Sys_Printf ("Edicts not supported in this VM\n");
|
||||
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++)
|
||||
if (strequal(fieldval,
|
||||
E_GSTRING (pr, EDICT_NUM(pr, i), def->ofs))) {
|
||||
ED_PrintNum (pr, i);
|
||||
ED_PrintNum (pr, i, 0);
|
||||
count++;
|
||||
}
|
||||
Sys_Printf ("%i entities\n", count);
|
||||
} else {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -475,7 +475,7 @@ ED_SpawnEntities (progs_t *pr, plitem_t *entity_list)
|
|||
func = PR_FindFunction (pr, classname);
|
||||
if (!func) {
|
||||
Sys_Printf ("No spawn function for :\n");
|
||||
ED_Print (pr, ent);
|
||||
ED_Print (pr, ent, 0);
|
||||
ED_Free (pr, ent);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -343,7 +343,7 @@ PF_traceoff (progs_t *pr)
|
|||
static void
|
||||
PF_eprint (progs_t *pr)
|
||||
{
|
||||
ED_PrintNum (pr, P_EDICTNUM (pr, 0));
|
||||
ED_PrintNum (pr, P_EDICTNUM (pr, 0), 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -74,7 +74,7 @@ PF_error (progs_t *pr)
|
|||
Sys_Printf ("======SERVER ERROR in %s:\n%s\n",
|
||||
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
|
||||
ed = PROG_TO_EDICT (pr, *sv_globals.self);
|
||||
ED_Print (pr, ed);
|
||||
ED_Print (pr, ed, 0);
|
||||
|
||||
Host_Error ("Program error");
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ PF_objerror (progs_t *pr)
|
|||
Sys_Printf ("======OBJECT ERROR in %s:\n%s\n",
|
||||
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
|
||||
ed = PROG_TO_EDICT (pr, *sv_globals.self);
|
||||
ED_Print (pr, ed);
|
||||
ED_Print (pr, ed, 0);
|
||||
ED_Free (pr, ed);
|
||||
|
||||
Host_Error ("Program error");
|
||||
|
|
|
@ -126,10 +126,17 @@ static void
|
|||
ED_PrintEdict_f (void)
|
||||
{
|
||||
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));
|
||||
Sys_Printf ("\n EDICT %i:\n", i);
|
||||
ED_PrintNum (&sv_pr_state, i);
|
||||
ED_PrintNum (&sv_pr_state, i, fieldname);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -76,7 +76,7 @@ PF_error (progs_t *pr)
|
|||
Sys_Printf ("======SERVER ERROR in %s:\n%s\n",
|
||||
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
|
||||
ed = PROG_TO_EDICT (pr, *sv_globals.self);
|
||||
ED_Print (pr, ed);
|
||||
ED_Print (pr, ed, 0);
|
||||
|
||||
Sys_Error ("Program error");
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ PF_objerror (progs_t *pr)
|
|||
Sys_Printf ("======OBJECT ERROR in %s:\n%s\n",
|
||||
PR_GetString (pr, pr->pr_xfunction->descriptor->s_name), s);
|
||||
ed = PROG_TO_EDICT (pr, *sv_globals.self);
|
||||
ED_Print (pr, ed);
|
||||
ED_Print (pr, ed, 0);
|
||||
ED_Free (pr, ed);
|
||||
|
||||
PR_RunError (pr, "object error");
|
||||
|
|
|
@ -151,10 +151,17 @@ static void
|
|||
ED_PrintEdict_f (void)
|
||||
{
|
||||
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));
|
||||
SV_Printf ("\n EDICT %i:\n", i);
|
||||
ED_PrintNum (&sv_pr_state, i);
|
||||
ED_PrintNum (&sv_pr_state, i, fieldname);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Loading…
Reference in a new issue