Tidy up progs dump output, and do some whitespace.

This commit is contained in:
Jeff Teunissen 2002-10-08 19:46:42 +00:00
parent bca275944c
commit 575689296a

View file

@ -99,8 +99,8 @@ const char *pr_type_name[ev_type_count] = {
"array", "array",
}; };
ddef_t *ED_FieldAtOfs (progs_t * pr, int ofs); ddef_t *ED_FieldAtOfs (progs_t *pr, int ofs);
qboolean ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const char *s); qboolean ED_ParseEpair (progs_t *pr, pr_type_t *base, ddef_t *key, const char *s);
/* /*
ED_ClearEdict ED_ClearEdict
@ -108,7 +108,7 @@ qboolean ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const cha
Sets everything to NULL Sets everything to NULL
*/ */
void void
ED_ClearEdict (progs_t * pr, edict_t *e, int val) ED_ClearEdict (progs_t *pr, edict_t *e, int val)
{ {
int i; int i;
@ -129,7 +129,7 @@ ED_ClearEdict (progs_t * pr, edict_t *e, int val)
angles and bad trails. angles and bad trails.
*/ */
edict_t * edict_t *
ED_Alloc (progs_t * pr) ED_Alloc (progs_t *pr)
{ {
int i; int i;
edict_t *e; edict_t *e;
@ -166,7 +166,7 @@ ED_Alloc (progs_t * pr)
NULLs all references to entity NULLs all references to entity
*/ */
void void
ED_FreeRefs (progs_t * pr, edict_t *ed) ED_FreeRefs (progs_t *pr, edict_t *ed)
{ {
int i, j, k; int i, j, k;
ddef_t *def; ddef_t *def;
@ -197,7 +197,7 @@ ED_FreeRefs (progs_t * pr, edict_t *ed)
FIXME: walk all entities and NULL out references to this entity FIXME: walk all entities and NULL out references to this entity
*/ */
void void
ED_Free (progs_t * pr, edict_t *ed) ED_Free (progs_t *pr, edict_t *ed)
{ {
if (pr->unlink) if (pr->unlink)
pr->unlink (ed); // unlink from world bsp pr->unlink (ed); // unlink from world bsp
@ -219,10 +219,10 @@ ED_Free (progs_t * pr, edict_t *ed)
/* /*
PR_ValueString PR_ValueString
Returns a string describing *data in a type specific manner Returns a string describing *data in a type-specific manner
*/ */
char * char *
PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val) PR_ValueString (progs_t *pr, etype_t type, pr_type_t *val)
{ {
static char line[256]; static char line[256];
ddef_t *def; ddef_t *def;
@ -259,18 +259,18 @@ PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
strcpy (line, "void"); strcpy (line, "void");
break; break;
case ev_float: case ev_float:
snprintf (line, sizeof (line), "%5.1f", val->float_var); snprintf (line, sizeof (line), "%g", val->float_var);
break; break;
case ev_vector: case ev_vector:
snprintf (line, sizeof (line), "'%5.1f %5.1f %5.1f'", snprintf (line, sizeof (line), "'%g %g %g'",
val->vector_var[0], val->vector_var[1], val->vector_var[0], val->vector_var[1],
val->vector_var[2]); val->vector_var[2]);
break; break;
case ev_pointer: case ev_pointer:
snprintf (line, sizeof (line), "[%d]", val->integer_var); snprintf (line, sizeof (line), "[$%x]", val->integer_var);
break; break;
case ev_quaternion: case ev_quaternion:
snprintf (line, sizeof (line), "'%5.1f %5.1f %5.1f %5.1f'", snprintf (line, sizeof (line), "'%g %g %g %g'",
val->vector_var[0], val->vector_var[1], val->vector_var[0], val->vector_var[1],
val->vector_var[2], val->vector_var[3]); val->vector_var[2], val->vector_var[3]);
break; break;
@ -278,7 +278,7 @@ PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
snprintf (line, sizeof (line), "%d", val->integer_var); snprintf (line, sizeof (line), "%d", val->integer_var);
break; break;
case ev_uinteger: case ev_uinteger:
snprintf (line, sizeof (line), "%u", val->uinteger_var); snprintf (line, sizeof (line), "$%08x", val->uinteger_var);
break; break;
default: default:
snprintf (line, sizeof (line), "bad type %i", type); snprintf (line, sizeof (line), "bad type %i", type);
@ -295,7 +295,7 @@ PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
Easier to parse than PR_ValueString Easier to parse than PR_ValueString
*/ */
char * char *
PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val) PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val)
{ {
static char line[256]; static char line[256];
ddef_t *def; ddef_t *def;
@ -345,7 +345,7 @@ PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val)
Returns a string with a description and the contents of a global Returns a string with a description and the contents of a global
*/ */
dstring_t * dstring_t *
PR_GlobalString (progs_t * pr, int ofs, etype_t type) PR_GlobalString (progs_t *pr, int ofs, etype_t type)
{ {
ddef_t *def = NULL; ddef_t *def = NULL;
static dstring_t *line = NULL; static dstring_t *line = NULL;
@ -364,7 +364,7 @@ PR_GlobalString (progs_t * pr, int ofs, etype_t type)
if (!def) if (!def)
def = ED_GlobalAtOfs (pr, ofs); def = ED_GlobalAtOfs (pr, ofs);
if (!def && type == ev_void) if (!def && type == ev_void)
dsprintf (line, "[%04x]", ofs); dsprintf (line, "[$%x]", ofs);
else { else {
char *name = "?"; char *name = "?";
char *oi = ""; char *oi = "";
@ -387,7 +387,7 @@ PR_GlobalString (progs_t * pr, int ofs, etype_t type)
else else
dsprintf (line, "%s", s); dsprintf (line, "%s", s);
} else if (strequal(name, "?")) } else if (strequal(name, "?"))
dsprintf (line, "[%04x]", ofs); dsprintf (line, "[$%x]", ofs);
else { else {
if (type == ev_func) if (type == ev_func)
dsprintf (line, "%s%s", name, oi); dsprintf (line, "%s%s", name, oi);
@ -399,7 +399,7 @@ PR_GlobalString (progs_t * pr, int ofs, etype_t type)
} }
dstring_t * dstring_t *
PR_GlobalStringNoContents (progs_t * pr, int ofs, etype_t type) PR_GlobalStringNoContents (progs_t *pr, int ofs, etype_t type)
{ {
static dstring_t *line = NULL; static dstring_t *line = NULL;
ddef_t *def = NULL; ddef_t *def = NULL;
@ -417,7 +417,7 @@ PR_GlobalStringNoContents (progs_t * pr, int ofs, etype_t type)
if (!def) if (!def)
def = ED_GlobalAtOfs (pr, ofs); def = ED_GlobalAtOfs (pr, ofs);
if (!def) if (!def)
dsprintf (line, "[%x]", ofs); dsprintf (line, "[$%x]", ofs);
else else
dsprintf (line, "%s", PR_GetString (pr, def->s_name)); dsprintf (line, "%s", PR_GetString (pr, def->s_name));
@ -431,14 +431,14 @@ PR_GlobalStringNoContents (progs_t * pr, int ofs, etype_t type)
For debugging For debugging
*/ */
void void
ED_Print (progs_t * pr, edict_t *ed) ED_Print (progs_t *pr, edict_t *ed)
{ {
int l; int l;
ddef_t *d;
pr_type_t *v;
int i; int i;
char *name; char *name;
int type; int type;
ddef_t *d;
pr_type_t *v;
if (ed->free) { if (ed->free) {
Sys_Printf ("FREE\n"); Sys_Printf ("FREE\n");
@ -496,13 +496,13 @@ ED_Print (progs_t * pr, edict_t *ed)
For savegames For savegames
*/ */
void void
ED_Write (progs_t * pr, QFile *f, edict_t *ed) ED_Write (progs_t *pr, QFile *f, edict_t *ed)
{ {
int i, j;
int type;
char *name;
ddef_t *d; ddef_t *d;
pr_type_t *v; pr_type_t *v;
int i, j;
char *name;
int type;
Qprintf (f, "{\n"); Qprintf (f, "{\n");
@ -535,7 +535,7 @@ ED_Write (progs_t * pr, QFile *f, edict_t *ed)
} }
void void
ED_PrintNum (progs_t * pr, int ent) ED_PrintNum (progs_t *pr, int ent)
{ {
ED_Print (pr, EDICT_NUM (pr, ent)); ED_Print (pr, EDICT_NUM (pr, ent));
} }
@ -575,13 +575,13 @@ ED_PrintEdicts (progs_t *pr, const char *fieldval)
For debugging For debugging
*/ */
void void
ED_Count (progs_t * pr) ED_Count (progs_t *pr)
{ {
int i; int i;
edict_t *ent;
int active, models, solid, step, zombie; int active, models, solid, step, zombie;
ddef_t *solid_def; ddef_t *solid_def;
ddef_t *model_def; ddef_t *model_def;
edict_t *ent;
solid_def = ED_FindField (pr, "solid"); solid_def = ED_FindField (pr, "solid");
model_def = ED_FindField (pr, "model"); model_def = ED_FindField (pr, "model");
@ -617,7 +617,7 @@ ED_Count (progs_t * pr)
ED_WriteGlobals ED_WriteGlobals
*/ */
void void
ED_WriteGlobals (progs_t * pr, QFile *f) ED_WriteGlobals (progs_t *pr, QFile *f)
{ {
ddef_t *def; ddef_t *def;
int i; int i;
@ -647,7 +647,7 @@ ED_WriteGlobals (progs_t * pr, QFile *f)
ED_ParseGlobals ED_ParseGlobals
*/ */
void void
ED_ParseGlobals (progs_t * pr, const char *data) ED_ParseGlobals (progs_t *pr, const char *data)
{ {
char keyname[64]; char keyname[64];
ddef_t *key; ddef_t *key;
@ -688,7 +688,7 @@ ED_ParseGlobals (progs_t * pr, const char *data)
ED_NewString ED_NewString
*/ */
char * char *
ED_NewString (progs_t * pr, const char *string) ED_NewString (progs_t *pr, const char *string)
{ {
char *new, *new_p; char *new, *new_p;
int i, l; int i, l;
@ -719,7 +719,7 @@ ED_NewString (progs_t * pr, const char *string)
returns false if error returns false if error
*/ */
qboolean qboolean
ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const char *s) ED_ParseEpair (progs_t *pr, pr_type_t *base, ddef_t *key, const char *s)
{ {
int i; int i;
char string[128]; char string[128];
@ -788,23 +788,20 @@ ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, const char *s)
Used for initial level load and for savegames. Used for initial level load and for savegames.
*/ */
const char * const char *
ED_ParseEdict (progs_t * pr, const char *data, edict_t *ent) ED_ParseEdict (progs_t *pr, const char *data, edict_t *ent)
{ {
ddef_t *key; ddef_t *key;
qboolean anglehack; qboolean anglehack;
qboolean init; qboolean init = false;
char keyname[256]; char keyname[256];
const char *token; const char *token;
int n; int n;
init = false; // clear it
// clear it
if (ent != *(pr)->edicts) // hack if (ent != *(pr)->edicts) // hack
memset (&ent->v, 0, pr->progs->entityfields * 4); memset (&ent->v, 0, pr->progs->entityfields * 4);
// go through all the dictionary pairs while (1) { // go through all the dictionary pairs
while (1) {
// parse key // parse key
data = COM_Parse (data); data = COM_Parse (data);
if (com_token[0] == '}') if (com_token[0] == '}')
@ -888,21 +885,17 @@ ED_ParseEdict (progs_t * pr, const char *data, edict_t *ent)
to call ED_CallSpawnFunctions () to let the objects initialize themselves. to call ED_CallSpawnFunctions () to let the objects initialize themselves.
*/ */
void void
ED_LoadFromFile (progs_t * pr, const char *data) ED_LoadFromFile (progs_t *pr, const char *data)
{ {
edict_t *ent; edict_t *ent = NULL;
int inhibit; int inhibit = 0;
dfunction_t *func; dfunction_t *func;
pr_type_t *classname; pr_type_t *classname;
ddef_t *def; ddef_t *def;
ent = NULL;
inhibit = 0;
*pr->globals.time = *(pr)->time; *pr->globals.time = *(pr)->time;
// parse ents while (1) { // parse ents
while (1) {
// parse the opening brace // parse the opening brace
data = COM_Parse (data); data = COM_Parse (data);
if (!data) if (!data)
@ -922,6 +915,7 @@ ED_LoadFromFile (progs_t * pr, const char *data)
inhibit++; inhibit++;
continue; continue;
} }
// //
// immediately call spawn function // immediately call spawn function
// //
@ -933,9 +927,9 @@ ED_LoadFromFile (progs_t * pr, const char *data)
continue; continue;
} }
classname = &ent->v[def->ofs]; classname = &ent->v[def->ofs];
// look for the spawn function // look for the spawn function
func = ED_FindFunction (pr, PR_GetString (pr, classname->string_var)); func = ED_FindFunction (pr, PR_GetString (pr, classname->string_var));
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);
@ -958,14 +952,16 @@ PR_InitEdicts (progs_t *pr, int num_edicts)
edict_t *edicts; edict_t *edicts;
edict_t *e; edict_t *e;
int i, j; int i, j;
pr->pr_edictareasize = pr->pr_edict_size * num_edicts; pr->pr_edictareasize = pr->pr_edict_size * num_edicts;
edicts = Hunk_AllocName (pr->pr_edictareasize, "edicts"); edicts = Hunk_AllocName (pr->pr_edictareasize, "edicts");
(*pr->edicts) = edicts; (*pr->edicts) = edicts;
if (pr_deadbeef_ents->int_val) { if (pr_deadbeef_ents->int_val) {
memset (edicts, 0, *pr->reserved_edicts * pr->pr_edict_size); memset (edicts, 0, *pr->reserved_edicts * pr->pr_edict_size);
for (j = *pr->reserved_edicts; j < num_edicts; j++) { for (j = *pr->reserved_edicts; j < num_edicts; j++) {
e = EDICT_NUM (pr, j); e = EDICT_NUM (pr, j);
for (i=0; i < pr->progs->entityfields; i++) for (i = 0; i < pr->progs->entityfields; i++)
e->v[i].integer_var = 0xdeadbeef; e->v[i].integer_var = 0xdeadbeef;
} }
} else { } else {
@ -975,7 +971,7 @@ PR_InitEdicts (progs_t *pr, int num_edicts)
} }
edict_t * edict_t *
EDICT_NUM (progs_t * pr, int n) EDICT_NUM (progs_t *pr, int n)
{ {
int offs = n * pr->pr_edict_size; int offs = n * pr->pr_edict_size;
if (offs < 0 || n >= pr->pr_edictareasize) if (offs < 0 || n >= pr->pr_edictareasize)