eval_t is no more: too many evil casts involved in using it (which can result

it bad code being generated by gcc).
This commit is contained in:
Bill Currie 2001-06-08 00:13:06 +00:00
parent 05cf89dd5d
commit 62c783f47a
6 changed files with 43 additions and 54 deletions

View file

@ -33,16 +33,6 @@
#include "QF/vfile.h"
#include "QF/pr_comp.h"
typedef union eval_s
{
string_t string;
float _float;
float vector[3];
func_t function;
int _int;
int edict;
} eval_t;
typedef union pr_type_u {
float float_var;
int int_var;
@ -145,7 +135,7 @@ typedef void (*builtin_t) (progs_t *pr);
ddef_t *PR_FindGlobal (progs_t *pr, const char *name);
eval_t *PR_GetGlobalPointer (progs_t *pr, const char *name);
pr_type_t *PR_GetGlobalPointer (progs_t *pr, const char *name);
func_t PR_GetFunctionIndex (progs_t *pr, const char *name);
int PR_GetFieldOffset (progs_t *pr, const char *name);
@ -160,7 +150,7 @@ void PR_Profile (progs_t *pr);
char *PR_GlobalString (progs_t *pr, int ofs);
char *PR_GlobalStringNoContents (progs_t *pr, int ofs);
eval_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, char *field);
pr_type_t *GetEdictFieldValue(progs_t *pr, edict_t *ed, char *field);
//
// PR STrings stuff

View file

@ -265,14 +265,14 @@ PR_FindGlobal (progs_t * pr, const char *name)
return Hash_Find (pr->global_hash, name);
}
eval_t *
pr_type_t *
PR_GetGlobalPointer (progs_t *pr, const char *name)
{
ddef_t *def;
def = PR_FindGlobal (pr, name);
if (def)
return (eval_t*)&pr->pr_globals[def->ofs];
return &pr->pr_globals[def->ofs];
PR_Error (pr, "undefined global %s", name);
return 0;
}
@ -306,7 +306,7 @@ ED_FindFunction (progs_t * pr, const char *name)
return Hash_Find (pr->function_hash, name);
}
eval_t *
pr_type_t *
GetEdictFieldValue (progs_t * pr, edict_t *ed, char *field)
{
ddef_t *def = NULL;
@ -332,7 +332,7 @@ GetEdictFieldValue (progs_t * pr, edict_t *ed, char *field)
if (!def)
return NULL;
return (eval_t *) ((char *) &ed->v + def->ofs * 4);
return &ed->v[def->ofs];
}
/*
@ -396,7 +396,7 @@ PR_ValueString (progs_t * pr, etype_t type, pr_type_t *val)
Easier to parse than PR_ValueString
*/
char *
PR_UglyValueString (progs_t * pr, etype_t type, eval_t *val)
PR_UglyValueString (progs_t * pr, etype_t type, pr_type_t *val)
{
static char line[256];
ddef_t *def;
@ -407,18 +407,18 @@ PR_UglyValueString (progs_t * pr, etype_t type, eval_t *val)
switch (type) {
case ev_string:
snprintf (line, sizeof (line), "%s",
PR_GetString (pr, val->string));
PR_GetString (pr, val->string_var));
break;
case ev_entity:
snprintf (line, sizeof (line), "%i",
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->edict)));
NUM_FOR_EDICT (pr, PROG_TO_EDICT (pr, val->entity_var)));
break;
case ev_func:
f = pr->pr_functions + val->function;
f = pr->pr_functions + val->func_var;
snprintf (line, sizeof (line), "%s", PR_GetString (pr, f->s_name));
break;
case ev_field:
def = ED_FieldAtOfs (pr, val->_int);
def = ED_FieldAtOfs (pr, val->int_var);
snprintf (line, sizeof (line), "%s",
PR_GetString (pr, def->s_name));
break;
@ -426,11 +426,11 @@ PR_UglyValueString (progs_t * pr, etype_t type, eval_t *val)
strcpy (line, "void");
break;
case ev_float:
snprintf (line, sizeof (line), "%f", val->_float);
snprintf (line, sizeof (line), "%f", val->float_var);
break;
case ev_vector:
snprintf (line, sizeof (line), "%f %f %f", val->vector[0],
val->vector[1], val->vector[2]);
snprintf (line, sizeof (line), "%f %f %f", val->vector_var[0],
val->vector_var[1], val->vector_var[2]);
break;
default:
snprintf (line, sizeof (line), "bad type %i", type);
@ -552,7 +552,7 @@ void
ED_Write (progs_t * pr, VFile *f, edict_t *ed)
{
ddef_t *d;
int *v;
pr_type_t *v;
int i, j;
char *name;
int type;
@ -570,18 +570,18 @@ ED_Write (progs_t * pr, VFile *f, edict_t *ed)
if (name[strlen (name) - 2] == '_')
continue; // skip _x, _y, _z vars
v = (int *) ((char *) &ed->v + d->ofs * 4);
v = &ed->v[d->ofs];
// if the value is still all 0, skip the field
type = d->type & ~DEF_SAVEGLOBAL;
for (j = 0; j < type_size[type]; j++)
if (v[j])
if (v[j].int_var)
break;
if (j == type_size[type])
continue;
Qprintf (f, "\"%s\" ", name);
Qprintf (f, "\"%s\"\n", PR_UglyValueString (pr, d->type, (eval_t *) v));
Qprintf (f, "\"%s\"\n", PR_UglyValueString (pr, d->type, v));
}
Qprintf (f, "}\n");
@ -676,8 +676,7 @@ ED_WriteGlobals (progs_t * pr, VFile *f)
name = PR_GetString (pr, def->s_name);
Qprintf (f, "\"%s\" ", name);
Qprintf (f, "\"%s\"\n",
PR_UglyValueString (pr, type,
(eval_t *) &pr->pr_globals[def->ofs]));
PR_UglyValueString (pr, type, &pr->pr_globals[def->ofs]));
}
Qprintf (f, "}\n");
}
@ -764,18 +763,18 @@ ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, char *s)
char string[128];
ddef_t *def;
char *v, *w;
eval_t *d;
pr_type_t *d;
dfunction_t *func;
d = (eval_t*)&base[key->ofs];
d = &base[key->ofs];
switch (key->type & ~DEF_SAVEGLOBAL) {
case ev_string:
d->string = PR_SetString (pr, ED_NewString (pr, s));
d->string_var = PR_SetString (pr, ED_NewString (pr, s));
break;
case ev_float:
d->_float = atof (s);
d->float_var = atof (s);
break;
case ev_vector:
@ -786,13 +785,13 @@ ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, char *s)
while (*v && *v != ' ')
v++;
*v = 0;
d->vector[i] = atof (w);
d->vector_var[i] = atof (w);
w = v = v + 1;
}
break;
case ev_entity:
d->edict = EDICT_TO_PROG (pr, EDICT_NUM (pr, atoi (s)));
d->entity_var = EDICT_TO_PROG (pr, EDICT_NUM (pr, atoi (s)));
break;
case ev_field:
@ -801,7 +800,7 @@ ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, char *s)
Con_Printf ("Can't find field %s\n", s);
return false;
}
d->_int = G_INT (pr, def->ofs);
d->int_var = G_INT (pr, def->ofs);
break;
case ev_func:
@ -810,7 +809,7 @@ ED_ParseEpair (progs_t * pr, pr_type_t *base, ddef_t *key, char *s)
Con_Printf ("Can't find function %s\n", s);
return false;
}
d->function = func - pr->pr_functions;
d->func_var = func - pr->pr_functions;
break;
default:
@ -931,7 +930,7 @@ ED_LoadFromFile (progs_t * pr, char *data)
edict_t *ent;
int inhibit;
dfunction_t *func;
eval_t *classname;
pr_type_t *classname;
ddef_t *def;
ent = NULL;
@ -970,9 +969,9 @@ ED_LoadFromFile (progs_t * pr, char *data)
ED_Free (pr, ent);
continue;
}
classname = (eval_t*)&ent->v[def->ofs];
classname = &ent->v[def->ofs];
// look for the spawn function
func = ED_FindFunction (pr, PR_GetString (pr, classname->string));
func = ED_FindFunction (pr, PR_GetString (pr, classname->string_var));
if (!func) {
Con_Printf ("No spawn function for:\n");

View file

@ -599,7 +599,7 @@ SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
int items;
#ifndef QUAKE2
eval_t *val;
pr_type_t *val;
#endif
//
@ -647,7 +647,7 @@ SV_WriteClientdataToMessage (edict_t *ent, sizebuf_t *msg)
val = GetEdictFieldValue (&sv_pr_state, ent, "items2");
if (val)
items = (int) SVFIELD (ent, items, float) | ((int) val->_float << 23);
items = (int) SVFIELD (ent, items, float) | ((int) val->float_var << 23);
else
items =
(int) SVFIELD (ent, items, float) | ((int) sv_globals.serverflags << 28);

View file

@ -388,11 +388,11 @@ SV_AddGravity (edict_t *ent)
else
ent_gravity = 1.0;
#else
eval_t *val;
pr_type_t *val;
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
if (val && val->_float)
ent_gravity = val->_float;
if (val && val->float_var)
ent_gravity = val->float_var;
else
ent_gravity = 1.0;
#endif

View file

@ -644,7 +644,7 @@ SV_UpdateToReliableMessages (void)
{
int i, j;
client_t *client;
eval_t *val;
pr_type_t *val;
edict_t *ent;
// check for changes to be sent over the reliable streams to all clients
@ -670,14 +670,14 @@ SV_UpdateToReliableMessages (void)
ent = host_client->edict;
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
if (val && host_client->entgravity != val->_float) {
host_client->entgravity = val->_float;
if (val && host_client->entgravity != val->float_var) {
host_client->entgravity = val->float_var;
ClientReliableWrite_Begin (host_client, svc_entgravity, 5);
ClientReliableWrite_Float (host_client, host_client->entgravity);
}
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed");
if (val && host_client->maxspeed != val->_float) {
host_client->maxspeed = val->_float;
if (val && host_client->maxspeed != val->float_var) {
host_client->maxspeed = val->float_var;
ClientReliableWrite_Begin (host_client, svc_maxspeed, 5);
ClientReliableWrite_Float (host_client, host_client->maxspeed);
}

View file

@ -332,7 +332,7 @@ SV_Spawn_f (void)
int i;
client_t *client;
edict_t *ent;
eval_t *val;
pr_type_t *val;
int n;
if (host_client->state != cs_connected) {
@ -387,11 +387,11 @@ SV_Spawn_f (void)
host_client->entgravity = 1.0;
val = GetEdictFieldValue (&sv_pr_state, ent, "gravity");
if (val)
val->_float = 1.0;
val->float_var = 1.0;
host_client->maxspeed = sv_maxspeed->value;
val = GetEdictFieldValue (&sv_pr_state, ent, "maxspeed");
if (val)
val->_float = sv_maxspeed->value;
val->float_var = sv_maxspeed->value;
//
// force stats to be updated