pr_comp.h, pr_edict.c, progs.h, pr_cmds.c, pr_exec.c: made some of the

variables and functions private and did some whitespace tidy-ups.

git-svn-id: http://svn.code.sf.net/p/quakespasm/code/trunk/quakespasm@504 af15c1b1-3010-417e-b628-4374ebc0bcbd
This commit is contained in:
sezero 2011-12-12 08:56:25 +00:00
parent 18ad2c4554
commit d7c0fb946a
5 changed files with 598 additions and 579 deletions

View file

@ -26,14 +26,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static char pr_string_temp[STRINGTEMP_BUFFERS][STRINGTEMP_LENGTH];
static byte pr_string_tempindex = 0;
static char *
PR_GetTempString(void)
static char *PR_GetTempString (void)
{
return pr_string_temp[(STRINGTEMP_BUFFERS-1) & ++pr_string_tempindex];
}
#define RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
#define MSG_BROADCAST 0 // unreliable to all
#define MSG_ONE 1 // reliable to one (msg_entity)
#define MSG_ALL 2 // reliable to all
#define MSG_INIT 3 // write to the init string
/*
===============================================================================
@ -42,7 +46,7 @@ PR_GetTempString(void)
===============================================================================
*/
char *PF_VarString (int first)
static char *PF_VarString (int first)
{
int i;
static char out[256];
@ -58,7 +62,7 @@ char *PF_VarString (int first)
/*
=================
PF_errror
PF_error
This is a TERMINAL error, which will kill off the entire server.
Dumps self.
@ -66,7 +70,7 @@ Dumps self.
error(value)
=================
*/
void PF_error (void)
static void PF_error (void)
{
char *s;
edict_t *ed;
@ -90,7 +94,7 @@ removed, but the level can continue.
objerror(value)
=================
*/
void PF_objerror (void)
static void PF_objerror (void)
{
char *s;
edict_t *ed;
@ -115,7 +119,7 @@ Writes new values for v_forward, v_up, and v_right based on angles
makevectors(vector)
==============
*/
void PF_makevectors (void)
static void PF_makevectors (void)
{
AngleVectors (G_VECTOR(OFS_PARM0), pr_global_struct->v_forward, pr_global_struct->v_right, pr_global_struct->v_up);
}
@ -124,12 +128,17 @@ void PF_makevectors (void)
=================
PF_setorigin
This is the only valid way to move an object without using the physics of the world (setting velocity and waiting). Directly changing origin will not set internal links correctly, so clipping would be messed up. This should be called when an object is spawned, and then only if it is teleported.
This is the only valid way to move an object without using the physics
of the world (setting velocity and waiting). Directly changing origin
will not set internal links correctly, so clipping would be messed up.
This should be called when an object is spawned, and then only if it is
teleported.
setorigin (entity, origin)
=================
*/
void PF_setorigin (void)
static void PF_setorigin (void)
{
edict_t *e;
float *org;
@ -141,7 +150,7 @@ void PF_setorigin (void)
}
void SetMinMaxSize (edict_t *e, float *minvec, float *maxvec, qboolean rotate)
static void SetMinMaxSize (edict_t *e, float *minvec, float *maxvec, qboolean rotate)
{
float *angles;
vec3_t rmin, rmax;
@ -224,7 +233,7 @@ the size box is rotated by the current angle
setsize (entity, minvector, maxvector)
=================
*/
void PF_setsize (void)
static void PF_setsize (void)
{
edict_t *e;
float *minvec, *maxvec;
@ -243,24 +252,27 @@ PF_setmodel
setmodel(entity, model)
=================
*/
void PF_setmodel (void)
static void PF_setmodel (void)
{
edict_t *e;
int i;
const char *m, **check;
model_t *mod;
int i;
edict_t *e;
e = G_EDICT(OFS_PARM0);
m = G_STRING(OFS_PARM1);
// check to see if model was properly precached
for (i = 0, check = sv.model_precache; *check; i++, check++)
{
if (!strcmp(*check, m))
break;
}
if (!*check)
PR_RunError ("no precache: %s\n", m);
{
PR_RunError ("no precache: %s", m);
}
e->v.model = PR_SetEngineString(*check);
e->v.modelindex = i; //SV_ModelIndex (m);
@ -288,7 +300,7 @@ broadcast print to everyone on server
bprint(value)
=================
*/
void PF_bprint (void)
static void PF_bprint (void)
{
char *s;
@ -305,7 +317,7 @@ single print to a specific client
sprint(clientent, value)
=================
*/
void PF_sprint (void)
static void PF_sprint (void)
{
char *s;
client_t *client;
@ -336,7 +348,7 @@ single print to a specific client
centerprint(clientent, value)
=================
*/
void PF_centerprint (void)
static void PF_centerprint (void)
{
char *s;
client_t *client;
@ -365,7 +377,7 @@ PF_normalize
vector normalize(vector)
=================
*/
void PF_normalize (void)
static void PF_normalize (void)
{
float *value1;
vec3_t newvalue;
@ -396,7 +408,7 @@ PF_vlen
scalar vlen(vector)
=================
*/
void PF_vlen (void)
static void PF_vlen (void)
{
float *value1;
float new_temp;
@ -416,7 +428,7 @@ PF_vectoyaw
float vectoyaw(vector)
=================
*/
void PF_vectoyaw (void)
static void PF_vectoyaw (void)
{
float *value1;
float yaw;
@ -443,7 +455,7 @@ PF_vectoangles
vector vectoangles(vector)
=================
*/
void PF_vectoangles (void)
static void PF_vectoangles (void)
{
float *value1;
float forward;
@ -485,7 +497,7 @@ Returns a number from 0<= num < 1
random()
=================
*/
void PF_random (void)
static void PF_random (void)
{
float num;
@ -501,7 +513,7 @@ PF_particle
particle(origin, color, count)
=================
*/
void PF_particle (void)
static void PF_particle (void)
{
float *org, *dir;
float color;
@ -521,7 +533,7 @@ PF_ambientsound
=================
*/
void PF_ambientsound (void)
static void PF_ambientsound (void)
{
const char *samp, **check;
float *pos;
@ -536,8 +548,10 @@ void PF_ambientsound (void)
// check to see if samp was properly precached
for (soundnum = 0, check = sv.sound_precache; *check; check++, soundnum++)
{
if (!strcmp(*check, samp))
break;
}
if (!*check)
{
@ -587,14 +601,14 @@ Each entity can have eight independant sound sources, like voice,
weapon, feet, etc.
Channel 0 is an auto-allocate channel, the others override anything
allready running on that entity/channel pair.
already running on that entity/channel pair.
An attenuation of 0 will play full volume everywhere in the level.
Larger attenuations will drop off.
=================
*/
void PF_sound (void)
static void PF_sound (void)
{
const char *sample;
int channel;
@ -627,7 +641,7 @@ PF_break
break()
=================
*/
void PF_break (void)
static void PF_break (void)
{
Con_Printf ("break statement\n");
*(int *)-4 = 0; // dump to debugger
@ -645,7 +659,7 @@ if the tryents flag is set.
traceline (vector1, vector2, tryents)
=================
*/
void PF_traceline (void)
static void PF_traceline (void)
{
float *v1, *v2;
trace_t trace;
@ -696,15 +710,17 @@ FIXME: make work...
scalar checkpos (entity, vector)
=================
*/
void PF_checkpos (void)
#if 0
static void PF_checkpos (void)
{
}
#endif
//============================================================================
byte checkpvs[MAX_MAP_LEAFS/8];
static byte checkpvs[MAX_MAP_LEAFS/8];
int PF_newcheckclient (int check)
static int PF_newcheckclient (int check)
{
int i;
byte *pvs;
@ -770,8 +786,8 @@ name checkclient ()
=================
*/
#define MAX_CHECK 16
int c_invis, c_notvis;
void PF_checkclient (void)
static int c_invis, c_notvis;
static void PF_checkclient (void)
{
edict_t *ent, *self;
mleaf_t *leaf;
@ -822,7 +838,7 @@ Sends text over to the client's execution buffer
stuffcmd (clientent, value)
=================
*/
void PF_stuffcmd (void)
static void PF_stuffcmd (void)
{
int entnum;
const char *str;
@ -848,7 +864,7 @@ Sends text over to the client's execution buffer
localcmd (string)
=================
*/
void PF_localcmd (void)
static void PF_localcmd (void)
{
const char *str;
@ -863,7 +879,7 @@ PF_cvar
float cvar (string)
=================
*/
void PF_cvar (void)
static void PF_cvar (void)
{
const char *str;
@ -879,7 +895,7 @@ PF_cvar_set
float cvar (string)
=================
*/
void PF_cvar_set (void)
static void PF_cvar_set (void)
{
const char *var, *val;
@ -898,7 +914,7 @@ Returns a chain of entities that have origins within a spherical area
findradius (origin, radius)
=================
*/
void PF_findradius (void)
static void PF_findradius (void)
{
edict_t *ent, *chain;
float rad;
@ -930,24 +946,23 @@ void PF_findradius (void)
RETURN_EDICT(chain);
}
/*
=========
PF_dprint
=========
*/
void PF_dprint (void)
static void PF_dprint (void)
{
Con_DPrintf ("%s",PF_VarString(0));
}
void PF_ftos (void)
static void PF_ftos (void)
{
float v;
char *s;
v = G_FLOAT(OFS_PARM0);
s = PR_GetTempString();
if (v == (int)v)
sprintf (s, "%d",(int)v);
else
@ -955,14 +970,14 @@ void PF_ftos (void)
G_INT(OFS_RETURN) = PR_SetEngineString(s);
}
void PF_fabs (void)
static void PF_fabs (void)
{
float v;
v = G_FLOAT(OFS_PARM0);
G_FLOAT(OFS_RETURN) = fabs(v);
}
void PF_vtos (void)
static void PF_vtos (void)
{
char *s;
@ -971,14 +986,16 @@ void PF_vtos (void)
G_INT(OFS_RETURN) = PR_SetEngineString(s);
}
void PF_Spawn (void)
static void PF_Spawn (void)
{
edict_t *ed;
ed = ED_Alloc();
RETURN_EDICT(ed);
}
void PF_Remove (void)
static void PF_Remove (void)
{
edict_t *ed;
@ -988,7 +1005,7 @@ void PF_Remove (void)
// entity (entity start, .string field, string match) find = #5;
void PF_Find (void)
static void PF_Find (void)
{
int e;
int f;
@ -1019,18 +1036,18 @@ void PF_Find (void)
RETURN_EDICT(sv.edicts);
}
void PR_CheckEmptyString (const char *s)
static void PR_CheckEmptyString (const char *s)
{
if (s[0] <= ' ')
PR_RunError ("Bad string");
}
void PF_precache_file (void)
static void PF_precache_file (void)
{ // precache_file is only used to copy files with qcc, it does nothing
G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
}
void PF_precache_sound (void)
static void PF_precache_sound (void)
{
const char *s;
int i;
@ -1055,7 +1072,7 @@ void PF_precache_sound (void)
PR_RunError ("PF_precache_sound: overflow");
}
void PF_precache_model (void)
static void PF_precache_model (void)
{
const char *s;
int i;
@ -1082,22 +1099,22 @@ void PF_precache_model (void)
}
void PF_coredump (void)
static void PF_coredump (void)
{
ED_PrintEdicts ();
}
void PF_traceon (void)
static void PF_traceon (void)
{
pr_trace = true;
}
void PF_traceoff (void)
static void PF_traceoff (void)
{
pr_trace = false;
}
void PF_eprint (void)
static void PF_eprint (void)
{
ED_PrintNum (G_EDICTNUM(OFS_PARM0));
}
@ -1109,7 +1126,7 @@ PF_walkmove
float(float yaw, float dist) walkmove
===============
*/
void PF_walkmove (void)
static void PF_walkmove (void)
{
edict_t *ent;
float yaw, dist;
@ -1152,7 +1169,7 @@ PF_droptofloor
void() droptofloor
===============
*/
void PF_droptofloor (void)
static void PF_droptofloor (void)
{
edict_t *ent;
vec3_t end;
@ -1184,7 +1201,7 @@ PF_lightstyle
void(float style, string value) lightstyle
===============
*/
void PF_lightstyle (void)
static void PF_lightstyle (void)
{
int style;
const char *val;
@ -1202,6 +1219,7 @@ void PF_lightstyle (void)
return;
for (j = 0, client = svs.clients; j < svs.maxclients; j++, client++)
{
if (client->active || client->spawned)
{
MSG_WriteChar (&client->message, svc_lightstyle);
@ -1209,8 +1227,9 @@ void PF_lightstyle (void)
MSG_WriteString (&client->message, val);
}
}
}
void PF_rint (void)
static void PF_rint (void)
{
float f;
f = G_FLOAT(OFS_PARM0);
@ -1219,11 +1238,13 @@ void PF_rint (void)
else
G_FLOAT(OFS_RETURN) = (int)(f - 0.5);
}
void PF_floor (void)
static void PF_floor (void)
{
G_FLOAT(OFS_RETURN) = floor(G_FLOAT(OFS_PARM0));
}
void PF_ceil (void)
static void PF_ceil (void)
{
G_FLOAT(OFS_RETURN) = ceil(G_FLOAT(OFS_PARM0));
}
@ -1234,7 +1255,7 @@ void PF_ceil (void)
PF_checkbottom
=============
*/
void PF_checkbottom (void)
static void PF_checkbottom (void)
{
edict_t *ent;
@ -1248,7 +1269,7 @@ void PF_checkbottom (void)
PF_pointcontents
=============
*/
void PF_pointcontents (void)
static void PF_pointcontents (void)
{
float *v;
@ -1264,7 +1285,7 @@ PF_nextent
entity nextent(entity)
=============
*/
void PF_nextent (void)
static void PF_nextent (void)
{
int i;
edict_t *ent;
@ -1296,7 +1317,7 @@ vector aim(entity, missilespeed)
=============
*/
cvar_t sv_aim = {"sv_aim", "0.93"};
void PF_aim (void)
static void PF_aim (void)
{
edict_t *ent, *check, *bestent;
vec3_t start, dir, end, bestdir;
@ -1323,7 +1344,6 @@ void PF_aim (void)
return;
}
// try all possible entities
VectorCopy (dir, bestdir);
bestdist = sv_aim.value;
@ -1339,8 +1359,7 @@ void PF_aim (void)
if (teamplay.value && ent->v.team > 0 && ent->v.team == check->v.team)
continue; // don't aim at teammate
for (j = 0; j < 3; j++)
end[j] = check->v.origin[j]
+ 0.5*(check->v.mins[j] + check->v.maxs[j]);
end[j] = check->v.origin[j] + 0.5 * (check->v.mins[j] + check->v.maxs[j]);
VectorSubtract (end, start, dir);
VectorNormalize (dir);
dist = DotProduct (dir, pr_global_struct->v_forward);
@ -1421,12 +1440,7 @@ MESSAGE WRITING
===============================================================================
*/
#define MSG_BROADCAST 0 // unreliable to all
#define MSG_ONE 1 // reliable to one (msg_entity)
#define MSG_ALL 2 // reliable to all
#define MSG_INIT 3 // write to the init string
sizebuf_t *WriteDest (void)
static sizebuf_t *WriteDest (void)
{
int entnum;
int dest;
@ -1459,50 +1473,49 @@ sizebuf_t *WriteDest (void)
return NULL;
}
void PF_WriteByte (void)
static void PF_WriteByte (void)
{
MSG_WriteByte (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteChar (void)
static void PF_WriteChar (void)
{
MSG_WriteChar (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteShort (void)
static void PF_WriteShort (void)
{
MSG_WriteShort (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteLong (void)
static void PF_WriteLong (void)
{
MSG_WriteLong (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteAngle (void)
static void PF_WriteAngle (void)
{
MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteCoord (void)
static void PF_WriteCoord (void)
{
MSG_WriteCoord (WriteDest(), G_FLOAT(OFS_PARM1));
}
void PF_WriteString (void)
static void PF_WriteString (void)
{
MSG_WriteString (WriteDest(), G_STRING(OFS_PARM1));
}
void PF_WriteEntity (void)
static void PF_WriteEntity (void)
{
MSG_WriteShort (WriteDest(), G_EDICTNUM(OFS_PARM1));
}
//=============================================================================
void PF_makestatic (void)
static void PF_makestatic (void)
{
edict_t *ent;
int i;
@ -1579,7 +1592,7 @@ void PF_makestatic (void)
PF_setspawnparms
==============
*/
void PF_setspawnparms (void)
static void PF_setspawnparms (void)
{
edict_t *ent;
int i;
@ -1602,7 +1615,7 @@ void PF_setspawnparms (void)
PF_changelevel
==============
*/
void PF_changelevel (void)
static void PF_changelevel (void)
{
const char *s;
@ -1615,43 +1628,42 @@ void PF_changelevel (void)
Cbuf_AddText (va("changelevel %s\n",s));
}
void PF_Fixme (void)
static void PF_Fixme (void)
{
PR_RunError ("unimplemented bulitin");
PR_RunError ("unimplemented builtin");
}
static builtin_t pr_builtin[] =
{
PF_Fixme,
PF_makevectors, // void(entity e) makevectors = #1;
PF_setorigin, // void(entity e, vector o) setorigin = #2;
PF_setmodel, // void(entity e, string m) setmodel = #3;
PF_setsize, // void(entity e, vector min, vector max) setsize = #4;
PF_Fixme, // void(entity e, vector min, vector max) setabssize = #5;
PF_break, // void() break = #6;
PF_random, // float() random = #7;
PF_sound, // void(entity e, float chan, string samp) sound = #8;
PF_normalize, // vector(vector v) normalize = #9;
PF_error, // void(string e) error = #10;
PF_objerror, // void(string e) objerror = #11;
PF_vlen, // float(vector v) vlen = #12;
PF_vectoyaw, // float(vector v) vectoyaw = #13;
PF_Spawn, // entity() spawn = #14;
PF_Remove, // void(entity e) remove = #15;
PF_traceline, // float(vector v1, vector v2, float tryents) traceline = #16;
PF_checkclient, // entity() clientlist = #17;
PF_Find, // entity(entity start, .string fld, string match) find = #18;
PF_precache_sound, // void(string s) precache_sound = #19;
PF_precache_model, // void(string s) precache_model = #20;
PF_stuffcmd, // void(entity client, string s)stuffcmd = #21;
PF_findradius, // entity(vector org, float rad) findradius = #22;
PF_bprint, // void(string s) bprint = #23;
PF_sprint, // void(entity client, string s) sprint = #24;
PF_dprint, // void(string s) dprint = #25;
PF_ftos, // void(string s) ftos = #26;
PF_vtos, // void(string s) vtos = #27;
PF_makevectors, // void(entity e) makevectors = #1
PF_setorigin, // void(entity e, vector o) setorigin = #2
PF_setmodel, // void(entity e, string m) setmodel = #3
PF_setsize, // void(entity e, vector min, vector max) setsize = #4
PF_Fixme, // void(entity e, vector min, vector max) setabssize = #5
PF_break, // void() break = #6
PF_random, // float() random = #7
PF_sound, // void(entity e, float chan, string samp) sound = #8
PF_normalize, // vector(vector v) normalize = #9
PF_error, // void(string e) error = #10
PF_objerror, // void(string e) objerror = #11
PF_vlen, // float(vector v) vlen = #12
PF_vectoyaw, // float(vector v) vectoyaw = #13
PF_Spawn, // entity() spawn = #14
PF_Remove, // void(entity e) remove = #15
PF_traceline, // float(vector v1, vector v2, float tryents) traceline = #16
PF_checkclient, // entity() clientlist = #17
PF_Find, // entity(entity start, .string fld, string match) find = #18
PF_precache_sound, // void(string s) precache_sound = #19
PF_precache_model, // void(string s) precache_model = #20
PF_stuffcmd, // void(entity client, string s)stuffcmd = #21
PF_findradius, // entity(vector org, float rad) findradius = #22
PF_bprint, // void(string s) bprint = #23
PF_sprint, // void(entity client, string s) sprint = #24
PF_dprint, // void(string s) dprint = #25
PF_ftos, // void(string s) ftos = #26
PF_vtos, // void(string s) vtos = #27
PF_coredump,
PF_traceon,
PF_traceoff,

View file

@ -1,6 +1,5 @@
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -27,8 +26,18 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
typedef int func_t;
typedef int string_t;
typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_function, ev_pointer} etype_t;
typedef enum
{
ev_bad = -1,
ev_void = 0,
ev_string,
ev_float,
ev_vector,
ev_entity,
ev_field,
ev_function,
ev_pointer
} etype_t;
#define OFS_NULL 0
#define OFS_RETURN 1
@ -43,7 +52,8 @@ typedef enum {ev_void, ev_string, ev_float, ev_vector, ev_entity, ev_field, ev_f
#define RESERVED_OFS 28
enum {
enum
{
OP_DONE,
OP_MUL_F,
OP_MUL_V,
@ -121,7 +131,6 @@ enum {
OP_BITOR
};
typedef struct statement_s
{
unsigned short op;
@ -135,6 +144,7 @@ typedef struct
unsigned short ofs;
int s_name;
} ddef_t;
#define DEF_SAVEGLOBAL (1<<15)
#define MAX_PARMS 8

View file

@ -22,14 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
qboolean pr_alpha_supported; //johnfitz
dprograms_t *progs;
dfunction_t *pr_functions;
dstatement_t *pr_statements;
globalvars_t *pr_global_struct;
float *pr_globals; // same as pr_global_struct
int pr_edict_size; // in bytes
static char *pr_strings;
static int pr_stringssize;
@ -39,6 +33,13 @@ static int pr_numknownstrings;
static ddef_t *pr_fielddefs;
static ddef_t *pr_globaldefs;
qboolean pr_alpha_supported; //johnfitz
dstatement_t *pr_statements;
globalvars_t *pr_global_struct;
float *pr_globals; // same as pr_global_struct
int pr_edict_size; // in bytes
unsigned short pr_crc;
int type_size[8] = {
@ -52,8 +53,22 @@ int type_size[8] = {
1 // sizeof(void *) / 4 // ev_pointer
};
ddef_t *ED_FieldAtOfs (int ofs);
qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s);
static ddef_t *ED_FieldAtOfs (int ofs);
static qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s);
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 2
typedef struct {
ddef_t *pcache;
char field[MAX_FIELD_LEN];
} gefv_cache;
static gefv_cache gefvCache[GEFV_CACHESIZE] =
{
{ NULL, "" },
{ NULL, "" }
};
cvar_t nomonsters = {"nomonsters", "0"};
cvar_t gamecfg = {"gamecfg", "0"};
@ -67,16 +82,6 @@ cvar_t saved2 = {"saved2", "0", true};
cvar_t saved3 = {"saved3", "0", true};
cvar_t saved4 = {"saved4", "0", true};
#define MAX_FIELD_LEN 64
#define GEFV_CACHESIZE 2
typedef struct {
ddef_t *pcache;
char field[MAX_FIELD_LEN];
} gefv_cache;
static gefv_cache gefvCache[GEFV_CACHESIZE] = {{NULL, ""}, {NULL, ""}};
/*
=================
ED_ClearEdict
@ -163,7 +168,7 @@ void ED_Free (edict_t *ed)
ED_GlobalAtOfs
============
*/
ddef_t *ED_GlobalAtOfs (int ofs)
static ddef_t *ED_GlobalAtOfs (int ofs)
{
ddef_t *def;
int i;
@ -182,7 +187,7 @@ ddef_t *ED_GlobalAtOfs (int ofs)
ED_FieldAtOfs
============
*/
ddef_t *ED_FieldAtOfs (int ofs)
static ddef_t *ED_FieldAtOfs (int ofs)
{
ddef_t *def;
int i;
@ -201,7 +206,7 @@ ddef_t *ED_FieldAtOfs (int ofs)
ED_FindField
============
*/
ddef_t *ED_FindField (const char *name)
static ddef_t *ED_FindField (const char *name)
{
ddef_t *def;
int i;
@ -221,7 +226,7 @@ ddef_t *ED_FindField (const char *name)
ED_FindGlobal
============
*/
ddef_t *ED_FindGlobal (const char *name)
static ddef_t *ED_FindGlobal (const char *name)
{
ddef_t *def;
int i;
@ -241,7 +246,7 @@ ddef_t *ED_FindGlobal (const char *name)
ED_FindFunction
============
*/
dfunction_t *ED_FindFunction (const char *name)
static dfunction_t *ED_FindFunction (const char *fn_name)
{
dfunction_t *func;
int i;
@ -249,7 +254,7 @@ dfunction_t *ED_FindFunction (const char *name)
for (i = 0; i < progs->numfunctions; i++)
{
func = &pr_functions[i];
if (!strcmp(PR_GetString(func->s_name),name))
if ( !strcmp(PR_GetString(func->s_name), fn_name) )
return func;
}
return NULL;
@ -300,7 +305,7 @@ PR_ValueString
Returns a string describing *data in a type specific manner
=============
*/
const char *PR_ValueString (int type, eval_t *val)
static const char *PR_ValueString (int type, eval_t *val)
{
static char line[256];
ddef_t *def;
@ -353,7 +358,7 @@ Returns a string describing *data in a type specific manner
Easier to parse than PR_ValueString
=============
*/
const char *PR_UglyValueString (int type, eval_t *val)
static const char *PR_UglyValueString (int type, eval_t *val)
{
static char line[256];
ddef_t *def;
@ -413,7 +418,7 @@ const char *PR_GlobalString (int ofs)
val = (void *)&pr_globals[ofs];
def = ED_GlobalAtOfs(ofs);
if (!def)
sprintf (line,"%i(???)", ofs);
sprintf (line,"%i(?)", ofs);
else
{
s = PR_ValueString (def->type, (eval_t *)val);
@ -436,7 +441,7 @@ const char *PR_GlobalStringNoContents (int ofs)
def = ED_GlobalAtOfs(ofs);
if (!def)
sprintf (line,"%i(???)", ofs);
sprintf (line,"%i(?)", ofs);
else
sprintf (line,"%i(%s)", ofs, PR_GetString(def->s_name));
@ -485,8 +490,10 @@ void ED_Print (edict_t *ed)
type = d->type & ~DEF_SAVEGLOBAL;
for (j = 0; j < type_size[type]; j++)
{
if (v[j])
break;
}
if (j == type_size[type])
continue;
@ -534,8 +541,10 @@ void ED_Write (FILE *f, edict_t *ed)
// 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])
break;
}
if (j == type_size[type])
continue;
@ -579,7 +588,7 @@ ED_PrintEdict_f
For debugging, prints a single edicy
=============
*/
void ED_PrintEdict_f (void)
static void ED_PrintEdict_f (void)
{
int i;
@ -599,7 +608,7 @@ ED_Count
For debugging
=============
*/
void ED_Count (void)
static void ED_Count (void)
{
int i;
edict_t *ent;
@ -625,9 +634,9 @@ void ED_Count (void)
Con_Printf ("view :%3i\n", models);
Con_Printf ("touch :%3i\n", solid);
Con_Printf ("step :%3i\n", step);
}
/*
==============================================================================
@ -752,7 +761,7 @@ Can parse either fields or globals
returns false if error
=============
*/
qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s)
static qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s)
{
int i;
char string[128];
@ -940,9 +949,9 @@ to call ED_CallSpawnFunctions () to let the objects initialize themselves.
*/
void ED_LoadFromFile (const char *data)
{
dfunction_t *func;
edict_t *ent = NULL;
int inhibit = 0;
dfunction_t *func;
pr_global_struct->time = sv.time;
@ -1035,7 +1044,7 @@ void PR_LoadProgs (void)
CRC_ProcessByte (&pr_crc, ((byte *)progs)[i]);
// byte swap the header
for (i=0 ; i<sizeof(*progs)/4 ; i++)
for (i = 0; i < (int) sizeof(*progs) / 4; i++)
((int *)progs)[i] = LittleLong ( ((int *)progs)[i] );
if (progs->version != PROG_VERSION)
@ -1047,13 +1056,16 @@ void PR_LoadProgs (void)
pr_strings = (char *)progs + progs->ofs_strings;
if (progs->ofs_strings + progs->numstrings >= com_filesize)
Host_Error ("progs.dat strings go past end of file\n");
// initialize the strings
pr_numknownstrings = 0;
pr_maxknownstrings = 0;
pr_stringssize = progs->numstrings;
if (pr_knownstrings)
Z_Free ((void *)pr_knownstrings);
pr_knownstrings = NULL;
PR_SetEngineString(""); // initialize the strings
PR_SetEngineString("");
pr_globaldefs = (ddef_t *)((byte *)progs + progs->ofs_globaldefs);
pr_fielddefs = (ddef_t *)((byte *)progs + progs->ofs_fielddefs);
pr_statements = (dstatement_t *)((byte *)progs + progs->ofs_statements);
@ -1140,7 +1152,6 @@ void PR_Init (void)
}
edict_t *EDICT_NUM(int n)
{
if (n < 0 || n >= sv.max_edicts)
@ -1162,6 +1173,7 @@ int NUM_FOR_EDICT(edict_t *e)
//===========================================================================
#define PR_STRING_ALLOCSLOTS 256
static void PR_AllocStringSlots (void)

View file

@ -1,6 +1,5 @@
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2009 John Fitzgibbons and others
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
@ -21,11 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "quakedef.h"
/*
*/
typedef struct
{
int s;
@ -33,22 +27,19 @@ typedef struct
} prstack_t;
#define MAX_STACK_DEPTH 32
prstack_t pr_stack[MAX_STACK_DEPTH];
int pr_depth;
static prstack_t pr_stack[MAX_STACK_DEPTH];
static int pr_depth;
#define LOCALSTACK_SIZE 2048
int localstack[LOCALSTACK_SIZE];
int localstack_used;
static int localstack[LOCALSTACK_SIZE];
static int localstack_used;
qboolean pr_trace;
dfunction_t *pr_xfunction;
int pr_xstatement;
int pr_argc;
const char *pr_opnames[] =
static const char *pr_opnames[] =
{
"DONE",
@ -148,11 +139,11 @@ const char *PR_GlobalStringNoContents (int ofs);
PR_PrintStatement
=================
*/
void PR_PrintStatement (dstatement_t *s)
static void PR_PrintStatement (dstatement_t *s)
{
int i;
if ( (unsigned)s->op < sizeof(pr_opnames)/sizeof(pr_opnames[0]))
if ((unsigned int)s->op < sizeof(pr_opnames)/sizeof(pr_opnames[0]))
{
Con_Printf("%s ", pr_opnames[s->op]);
i = strlen(pr_opnames[s->op]);
@ -166,7 +157,7 @@ void PR_PrintStatement (dstatement_t *s)
{
Con_Printf("branch %i", s->a);
}
else if ( (unsigned)(s->op - OP_STORE_F) < 6)
else if ((unsigned int)(s->op-OP_STORE_F) < 6)
{
Con_Printf("%s", PR_GlobalString(s->a));
Con_Printf("%s", PR_GlobalStringNoContents(s->b));
@ -188,10 +179,10 @@ void PR_PrintStatement (dstatement_t *s)
PR_StackTrace
============
*/
void PR_StackTrace (void)
static void PR_StackTrace (void)
{
dfunction_t *f;
int i;
dfunction_t *f;
if (pr_depth == 0)
{
@ -203,15 +194,16 @@ void PR_StackTrace (void)
for (i = pr_depth; i >= 0; i--)
{
f = pr_stack[i].f;
if (!f)
{
Con_Printf("<NO FUNCTION>\n");
}
else
{
Con_Printf("%12s : %s\n", PR_GetString(f->s_file), PR_GetString(f->s_name));
}
}
}
/*
@ -222,10 +214,9 @@ PR_Profile_f
*/
void PR_Profile_f (void)
{
dfunction_t *f, *best;
int i, num;
int pmax;
int num;
int i;
dfunction_t *f, *best;
if (!sv.active)
return;
@ -273,6 +264,7 @@ void PR_RunError (const char *error, ...)
PR_PrintStatement(pr_statements + pr_xstatement);
PR_StackTrace();
Con_Printf("%s\n", string);
pr_depth = 0; // dump the stack so host_error can shutdown functions
@ -280,14 +272,6 @@ void PR_RunError (const char *error, ...)
Host_Error("Program error");
}
/*
============================================================================
PR_ExecuteProgram
The interpretation main loop
============================================================================
*/
/*
====================
PR_EnterFunction
@ -295,7 +279,7 @@ PR_EnterFunction
Returns the new program statement counter
====================
*/
int PR_EnterFunction (dfunction_t *f)
static int PR_EnterFunction (dfunction_t *f)
{
int i, j, c, o;
@ -334,18 +318,18 @@ int PR_EnterFunction (dfunction_t *f)
PR_LeaveFunction
====================
*/
int PR_LeaveFunction (void)
static int PR_LeaveFunction (void)
{
int i, c;
if (pr_depth <= 0)
Sys_Error("prog stack underflow");
// restore locals from the stack
// Restore locals from the stack
c = pr_xfunction->locals;
localstack_used -= c;
if (localstack_used < 0)
PR_RunError ("PR_ExecuteProgram: locals stack underflow\n");
PR_RunError("PR_ExecuteProgram: locals stack underflow");
for (i = 0; i < c; i++)
((int *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i];
@ -360,11 +344,14 @@ int PR_LeaveFunction (void)
/*
====================
PR_ExecuteProgram
The interpretation main loop
====================
*/
void PR_ExecuteProgram (func_t fnum)
{
eval_t *a, *b, *c;
eval_t *ptr;
int s;
dstatement_t *st;
dfunction_t *f, *newf;
@ -372,7 +359,6 @@ void PR_ExecuteProgram (func_t fnum)
int i;
edict_t *ed;
int exitdepth;
eval_t *ptr;
if (!fnum || fnum >= progs->numfunctions)
{
@ -433,9 +419,9 @@ while (1)
c->_float = a->_float * b->_float;
break;
case OP_MUL_V:
c->_float = a->vector[0]*b->vector[0]
+ a->vector[1]*b->vector[1]
+ a->vector[2]*b->vector[2];
c->_float = a->vector[0]*b->vector[0] +
a->vector[1]*b->vector[1] +
a->vector[2]*b->vector[2];
break;
case OP_MUL_FV:
c->vector[0] = a->_float * b->vector[0];
@ -460,7 +446,6 @@ while (1)
c->_float = (int)a->_float | (int)b->_float;
break;
case OP_GE:
c->_float = a->_float >= b->_float;
break;
@ -514,7 +499,6 @@ while (1)
c->_float = a->function == b->function;
break;
case OP_NE_F:
c->_float = a->_float != b->_float;
break;
@ -533,7 +517,6 @@ while (1)
c->_float = a->function != b->function;
break;
//==================
case OP_STORE_F:
case OP_STORE_ENT:
case OP_STORE_FLD: // integers
@ -565,7 +548,7 @@ while (1)
case OP_ADDRESS:
ed = PROG_TO_EDICT(a->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
NUM_FOR_EDICT(ed); // Make sure it's in range
#endif
if (ed == (edict_t *)sv.edicts && sv.state == ss_active)
PR_RunError("assignment to world entity");
@ -579,7 +562,7 @@ while (1)
case OP_LOAD_FNC:
ed = PROG_TO_EDICT(a->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
NUM_FOR_EDICT(ed); // Make sure it's in range
#endif
a = (eval_t *)((int *)&ed->v + b->_int);
c->_int = a->_int;
@ -588,7 +571,7 @@ while (1)
case OP_LOAD_V:
ed = PROG_TO_EDICT(a->edict);
#ifdef PARANOID
NUM_FOR_EDICT(ed); // make sure it's in range
NUM_FOR_EDICT(ed); // Make sure it's in range
#endif
a = (eval_t *)((int *)&ed->v + b->_int);
c->vector[0] = a->vector[0];
@ -624,18 +607,16 @@ while (1)
pr_argc = st->op - OP_CALL0;
if (!a->function)
PR_RunError("NULL function");
newf = &pr_functions[a->function];
if (newf->first_statement < 0)
{ // negative statements are built in functions
{ // Built-in function
i = -newf->first_statement;
if (i >= pr_numbuiltins)
PR_RunError ("Bad builtin call number");
PR_RunError("Bad builtin call number %d", i);
pr_builtins[i]();
break;
}
// Normal function
s = PR_EnterFunction(newf);
break;
@ -644,10 +625,11 @@ while (1)
pr_globals[OFS_RETURN] = pr_globals[st->a];
pr_globals[OFS_RETURN + 1] = pr_globals[st->a + 1];
pr_globals[OFS_RETURN + 2] = pr_globals[st->a + 2];
s = PR_LeaveFunction();
if (pr_depth == exitdepth)
return; // all done
{ // Done
return;
}
break;
case OP_STATE:
@ -663,6 +645,6 @@ while (1)
default:
PR_RunError("Bad opcode %i", st->op);
}
} /* end of while(1) loop */
}
}

View file

@ -22,8 +22,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef _QUAKE_PROGS_H
#define _QUAKE_PROGS_H
#include "pr_comp.h" // defs shared with qcc
#include "progdefs.h" // generated by program cdefs
#include "pr_comp.h" /* defs shared with qcc */
#include "progdefs.h" /* generated by program cdefs */
typedef union eval_s
{
@ -39,16 +39,21 @@ typedef union eval_s
typedef struct edict_s
{
qboolean free;
link_t area; // linked to a division node or leaf
link_t area; /* linked to a division node or leaf */
int num_leafs;
short leafnums[MAX_ENT_LEAFS];
entity_state_t baseline;
unsigned char alpha; // johnfitz -- hack to support alpha since it's not part of entvars_t
qboolean sendinterval; // johnfitz -- send time until nextthink to client for better lerp timing
float freetime; // sv.time when the object was freed
entvars_t v; // C exported fields from progs
// other fields from progs come immediately after
unsigned char alpha; /* johnfitz -- hack to support alpha since it's not part of entvars_t */
qboolean sendinterval; /* johnfitz -- send time until nextthink to client for better lerp timing */
float freetime; /* sv.time when the object was freed */
entvars_t v; /* C exported fields from progs */
/* other fields from progs come immediately after */
} edict_t;
#define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area)
//============================================================================
@ -57,23 +62,22 @@ extern dprograms_t *progs;
extern dfunction_t *pr_functions;
extern dstatement_t *pr_statements;
extern globalvars_t *pr_global_struct;
extern float *pr_globals; // same as pr_global_struct
extern float *pr_globals; /* same as pr_global_struct */
extern int pr_edict_size; // in bytes
extern int pr_edict_size; /* in bytes */
//============================================================================
void PR_Init (void);
void PR_ExecuteProgram (func_t fnum);
void PR_LoadProgs (void);
void PR_Profile_f (void);
const char *PR_GetString (int num);
int PR_SetEngineString (const char *s);
int PR_AllocString (int bufferlength, char **ptr);
void PR_Profile_f (void);
edict_t *ED_Alloc (void);
void ED_Free (edict_t *ed);
@ -86,9 +90,10 @@ void ED_ParseGlobals (const char *data);
void ED_LoadFromFile (const char *data);
//define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
//define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts)/pr_edict_size)
/*
#define EDICT_NUM(n) ((edict_t *)(sv.edicts+ (n)*pr_edict_size))
#define NUM_FOR_EDICT(e) (((byte *)(e) - sv.edicts) / pr_edict_size)
*/
edict_t *EDICT_NUM(int n);
int NUM_FOR_EDICT(edict_t *e);
@ -97,8 +102,6 @@ int NUM_FOR_EDICT(edict_t *e);
#define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts)
#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + e))
//============================================================================
#define G_FLOAT(o) (pr_globals[o])
#define G_INT(o) (*(int *)&pr_globals[o])
#define G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int *)&pr_globals[o]))