diff --git a/Quake/pr_cmds.c b/Quake/pr_cmds.c index 1e426ff2..b83d607c 100644 --- a/Quake/pr_cmds.c +++ b/Quake/pr_cmds.c @@ -26,29 +26,33 @@ 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 + /* =============================================================================== - BUILT-IN FUNCTIONS + BUILT-IN FUNCTIONS =============================================================================== */ -char *PF_VarString (int first) +static char *PF_VarString (int first) { int i; static char out[256]; out[0] = 0; - for (i=first ; iv_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; @@ -151,7 +160,7 @@ void SetMinMaxSize (edict_t *e, float *minvec, float *maxvec, qboolean rotate) vec3_t base, transformed; int i, j, k, l; - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) if (minvec[i] > maxvec[i]) PR_RunError ("backwards mins/maxs"); @@ -180,13 +189,13 @@ void SetMinMaxSize (edict_t *e, float *minvec, float *maxvec, qboolean rotate) rmin[0] = rmin[1] = rmin[2] = 9999; rmax[0] = rmax[1] = rmax[2] = -9999; - for (i=0 ; i<= 1 ; i++) + for (i = 0; i <= 1; i++) { base[0] = bounds[i][0]; - for (j=0 ; j<= 1 ; j++) + for (j = 0; j <= 1; j++) { base[1] = bounds[j][1]; - for (k=0 ; k<= 1 ; k++) + for (k = 0; k <= 1; k++) { base[2] = bounds[k][2]; @@ -195,7 +204,7 @@ void SetMinMaxSize (edict_t *e, float *minvec, float *maxvec, qboolean rotate) transformed[1] = xvector[1]*base[0] + yvector[1]*base[1]; transformed[2] = base[2]; - for (l=0 ; l<3 ; l++) + for (l = 0; l < 3; l++) { if (transformed[l] < rmin[l]) rmin[l] = transformed[l]; @@ -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++) + 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,11 +317,11 @@ single print to a specific client sprint(clientent, value) ================= */ -void PF_sprint (void) +static void PF_sprint (void) { char *s; client_t *client; - int entnum; + int entnum; entnum = G_EDICTNUM(OFS_PARM0); s = PF_VarString(1); @@ -336,11 +348,11 @@ single print to a specific client centerprint(clientent, value) ================= */ -void PF_centerprint (void) +static void PF_centerprint (void) { char *s; client_t *client; - int entnum; + int entnum; entnum = G_EDICTNUM(OFS_PARM0); s = PF_VarString(1); @@ -354,7 +366,7 @@ void PF_centerprint (void) client = &svs.clients[entnum-1]; MSG_WriteChar (&client->message,svc_centerprint); - MSG_WriteString (&client->message, s ); + MSG_WriteString (&client->message, s); } @@ -365,7 +377,7 @@ PF_normalize vector normalize(vector) ================= */ -void PF_normalize (void) +static void PF_normalize (void) { float *value1; vec3_t newvalue; @@ -374,13 +386,13 @@ void PF_normalize (void) value1 = G_VECTOR(OFS_PARM0); new_temp = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2]; - new_temp = sqrt(new_temp); + new_temp = sqrt (new_temp); if (new_temp == 0) newvalue[0] = newvalue[1] = newvalue[2] = 0; else { - new_temp = 1/new_temp; + new_temp = 1 / new_temp; newvalue[0] = value1[0] * new_temp; newvalue[1] = value1[1] * new_temp; newvalue[2] = value1[2] * new_temp; @@ -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; @@ -480,16 +492,16 @@ void PF_vectoangles (void) ================= PF_Random -Returns a number from 0<= num < 1 +Returns a number from 0 <= num < 1 random() ================= */ -void PF_random (void) +static void PF_random (void) { float num; - num = (rand ()&0x7fff) / ((float)0x7fff); + num = (rand() & 0x7fff) / ((float)0x7fff); G_FLOAT(OFS_RETURN) = 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,13 +533,13 @@ PF_ambientsound ================= */ -void PF_ambientsound (void) +static void PF_ambientsound (void) { const char *samp, **check; float *pos; - float vol, attenuation; - int i, soundnum; - int large=false; //johnfitz -- PROTOCOL_FITZQUAKE + float vol, attenuation; + int i, soundnum; + int large = false; //johnfitz -- PROTOCOL_FITZQUAKE pos = G_VECTOR (OFS_PARM0); samp = G_STRING(OFS_PARM1); @@ -535,9 +547,11 @@ void PF_ambientsound (void) attenuation = G_FLOAT(OFS_PARM3); // check to see if samp was properly precached - for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++) - if (!strcmp(*check,samp)) + for (soundnum = 0, check = sv.sound_precache; *check; check++, soundnum++) + { + if (!strcmp(*check, samp)) break; + } if (!*check) { @@ -564,12 +578,12 @@ void PF_ambientsound (void) MSG_WriteByte (&sv.signon,svc_spawnstaticsound); //johnfitz - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) MSG_WriteCoord(&sv.signon, pos[i]); //johnfitz -- PROTOCOL_FITZQUAKE if (large) - MSG_WriteShort (&sv.signon, soundnum); + MSG_WriteShort(&sv.signon, soundnum); else MSG_WriteByte (&sv.signon, soundnum); //johnfitz @@ -587,20 +601,20 @@ 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; + int channel; edict_t *entity; - int volume; - float attenuation; + int volume; + float attenuation; entity = G_EDICT(OFS_PARM0); channel = G_FLOAT(OFS_PARM1); @@ -627,10 +641,10 @@ PF_break break() ================= */ -void PF_break (void) +static void PF_break (void) { -Con_Printf ("break statement\n"); -*(int *)-4 = 0; // dump to debugger + Con_Printf ("break statement\n"); + *(int *)-4 = 0; // dump to debugger // PR_RunError ("break statement"); } @@ -645,11 +659,11 @@ 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; - int nomonsters; + int nomonsters; edict_t *ent; v1 = G_VECTOR(OFS_PARM0); @@ -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; @@ -798,15 +814,15 @@ void PF_checkclient (void) VectorAdd (self->v.origin, self->v.view_ofs, view); leaf = Mod_PointInLeaf (view, sv.worldmodel); l = (leaf - sv.worldmodel->leafs) - 1; - if ( (l<0) || !(checkpvs[l>>3] & (1<<(l&7)) ) ) + if ( (l < 0) || !(checkpvs[l>>3] & (1 << (l & 7))) ) { -c_notvis++; + c_notvis++; RETURN_EDICT(sv.edicts); return; } // might be able to see it -c_invis++; + c_invis++; RETURN_EDICT(ent); } @@ -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,13 +914,13 @@ 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; float *org; vec3_t eorg; - int i, j; + int i, j; chain = (edict_t *)sv.edicts; @@ -912,14 +928,14 @@ void PF_findradius (void) rad = G_FLOAT(OFS_PARM1); ent = NEXT_EDICT(sv.edicts); - for (i=1 ; ifree) continue; if (ent->v.solid == SOLID_NOT) continue; - for (j=0 ; j<3 ; j++) - eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j])*0.5); + for (j = 0; j < 3; j++) + eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j]) * 0.5); if (VectorLength(eorg) > rad) continue; @@ -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; @@ -1042,7 +1059,7 @@ void PF_precache_sound (void) G_INT(OFS_RETURN) = G_INT(OFS_PARM0); PR_CheckEmptyString (s); - for (i=0 ; iself); yaw = G_FLOAT(OFS_PARM0); @@ -1127,10 +1144,10 @@ void PF_walkmove (void) return; } - yaw = yaw*M_PI*2 / 360; + yaw = yaw * M_PI * 2 / 360; - move[0] = cos(yaw)*dist; - move[1] = sin(yaw)*dist; + move[0] = cos(yaw) * dist; + move[1] = sin(yaw) * dist; move[2] = 0; // save program state, because SV_movestep may call other progs @@ -1152,7 +1169,7 @@ PF_droptofloor void() droptofloor =============== */ -void PF_droptofloor (void) +static void PF_droptofloor (void) { edict_t *ent; vec3_t end; @@ -1184,12 +1201,12 @@ PF_lightstyle void(float style, string value) lightstyle =============== */ -void PF_lightstyle (void) +static void PF_lightstyle (void) { int style; const char *val; client_t *client; - int j; + int j; style = G_FLOAT(OFS_PARM0); val = G_STRING(OFS_PARM1); @@ -1201,16 +1218,18 @@ void PF_lightstyle (void) if (sv.state != ss_active) return; - for (j=0, client = svs.clients ; jactive || client->spawned) { MSG_WriteChar (&client->message, svc_lightstyle); - MSG_WriteChar (&client->message,style); + MSG_WriteChar (&client->message, style); 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; @@ -1317,20 +1338,19 @@ void PF_aim (void) VectorMA (start, 2048, dir, end); tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent); if (tr.ent && tr.ent->v.takedamage == DAMAGE_AIM - && (!teamplay.value || ent->v.team <=0 || ent->v.team != tr.ent->v.team) ) + && (!teamplay.value || ent->v.team <= 0 || ent->v.team != tr.ent->v.team) ) { VectorCopy (pr_global_struct->v_forward, G_VECTOR(OFS_RETURN)); return; } - // try all possible entities VectorCopy (dir, bestdir); bestdist = sv_aim.value; bestent = NULL; check = NEXT_EDICT(sv.edicts); - for (i=1 ; iv.takedamage != DAMAGE_AIM) continue; @@ -1338,9 +1358,8 @@ void PF_aim (void) continue; 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]); + for (j = 0; j < 3; 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,54 +1473,53 @@ 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; - int bits=0; //johnfitz -- PROTOCOL_FITZQUAKE + edict_t *ent; + int i; + int bits = 0; //johnfitz -- PROTOCOL_FITZQUAKE ent = G_EDICT(OFS_PARM0); @@ -1557,7 +1570,7 @@ void PF_makestatic (void) MSG_WriteByte (&sv.signon, ent->v.colormap); MSG_WriteByte (&sv.signon, ent->v.skin); - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) { MSG_WriteCoord(&sv.signon, ent->v.origin[i]); MSG_WriteAngle(&sv.signon, ent->v.angles[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; @@ -1593,7 +1606,7 @@ void PF_setspawnparms (void) // copy spawn parms out of the client_t client = svs.clients + (i-1); - for (i=0 ; i< NUM_SPAWN_PARMS ; i++) + for (i = 0; i < NUM_SPAWN_PARMS; i++) (&pr_global_struct->parm1)[i] = client->spawn_parms[i]; } @@ -1602,7 +1615,7 @@ void PF_setspawnparms (void) PF_changelevel ============== */ -void PF_changelevel (void) +static void PF_changelevel (void) { const char *s; @@ -1615,102 +1628,101 @@ 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_coredump, -PF_traceon, -PF_traceoff, -PF_eprint, // void(entity e) debug print an entire entity -PF_walkmove, // float(float yaw, float dist) walkmove -PF_Fixme, // float(float yaw, float dist) walkmove -PF_droptofloor, -PF_lightstyle, -PF_rint, -PF_floor, -PF_ceil, -PF_Fixme, -PF_checkbottom, -PF_pointcontents, -PF_Fixme, -PF_fabs, -PF_aim, -PF_cvar, -PF_localcmd, -PF_nextent, -PF_particle, -PF_changeyaw, -PF_Fixme, -PF_vectoangles, + 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_coredump, + PF_traceon, + PF_traceoff, + PF_eprint, // void(entity e) debug print an entire entity + PF_walkmove, // float(float yaw, float dist) walkmove + PF_Fixme, // float(float yaw, float dist) walkmove + PF_droptofloor, + PF_lightstyle, + PF_rint, + PF_floor, + PF_ceil, + PF_Fixme, + PF_checkbottom, + PF_pointcontents, + PF_Fixme, + PF_fabs, + PF_aim, + PF_cvar, + PF_localcmd, + PF_nextent, + PF_particle, + PF_changeyaw, + PF_Fixme, + PF_vectoangles, -PF_WriteByte, -PF_WriteChar, -PF_WriteShort, -PF_WriteLong, -PF_WriteCoord, -PF_WriteAngle, -PF_WriteString, -PF_WriteEntity, + PF_WriteByte, + PF_WriteChar, + PF_WriteShort, + PF_WriteLong, + PF_WriteCoord, + PF_WriteAngle, + PF_WriteString, + PF_WriteEntity, -PF_Fixme, -PF_Fixme, -PF_Fixme, -PF_Fixme, -PF_Fixme, -PF_Fixme, -PF_Fixme, + PF_Fixme, + PF_Fixme, + PF_Fixme, + PF_Fixme, + PF_Fixme, + PF_Fixme, + PF_Fixme, -SV_MoveToGoal, -PF_precache_file, -PF_makestatic, + SV_MoveToGoal, + PF_precache_file, + PF_makestatic, -PF_changelevel, -PF_Fixme, + PF_changelevel, + PF_Fixme, -PF_cvar_set, -PF_centerprint, + PF_cvar_set, + PF_centerprint, -PF_ambientsound, + PF_ambientsound, -PF_precache_model, -PF_precache_sound, // precache_sound2 is different only for qcc -PF_precache_file, + PF_precache_model, + PF_precache_sound, // precache_sound2 is different only for qcc + PF_precache_file, -PF_setspawnparms + PF_setspawnparms }; builtin_t *pr_builtins = pr_builtin; diff --git a/Quake/pr_comp.h b/Quake/pr_comp.h index 3f6f64f9..ff04e61c 100644 --- a/Quake/pr_comp.h +++ b/Quake/pr_comp.h @@ -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,12 +26,22 @@ 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 -#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors +#define OFS_PARM0 4 // leave 3 ofs for each parm to hold vectors #define OFS_PARM1 7 #define OFS_PARM2 10 #define OFS_PARM3 13 @@ -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,20 +131,20 @@ enum { OP_BITOR }; - typedef struct statement_s { unsigned short op; - short a,b,c; + short a, b, c; } dstatement_t; typedef struct { - unsigned short type; // if DEF_SAVEGLOBAL bit is set - // the variable needs to be saved in savegames + unsigned short type; // if DEF_SAVEGLOBAL bit is set + // the variable needs to be saved in savegames unsigned short ofs; - int s_name; + int s_name; } ddef_t; + #define DEF_SAVEGLOBAL (1<<15) #define MAX_PARMS 8 @@ -143,7 +153,7 @@ typedef struct { int first_statement; // negative numbers are builtins int parm_start; - int locals; // total ints of parms + locals + int locals; // total ints of parms + locals int profile; // runtime @@ -159,7 +169,7 @@ typedef struct typedef struct { int version; - int crc; // check of header file + int crc; // check of header file int ofs_statements; int numstatements; // statement 0 is an error @@ -174,7 +184,7 @@ typedef struct int numfunctions; // function 0 is an empty int ofs_strings; - int numstrings; // first string is a null string + int numstrings; // first string is a null string int ofs_globals; int numglobals; diff --git a/Quake/pr_edict.c b/Quake/pr_edict.c index 03017e09..012d65b7 100644 --- a/Quake/pr_edict.c +++ b/Quake/pr_edict.c @@ -22,24 +22,25 @@ 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; + +static char *pr_strings; +static int pr_stringssize; +static const char **pr_knownstrings; +static int pr_maxknownstrings; +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 +float *pr_globals; // same as pr_global_struct +int pr_edict_size; // in bytes -static char *pr_strings; -static int pr_stringssize; -static const char **pr_knownstrings; -static int pr_maxknownstrings; -static int pr_numknownstrings; -static ddef_t *pr_fielddefs; -static ddef_t *pr_globaldefs; - -unsigned short pr_crc; +unsigned short pr_crc; int type_size[8] = { 1, // ev_void @@ -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 @@ -106,7 +111,7 @@ edict_t *ED_Alloc (void) int i; edict_t *e; - for ( i=svs.maxclients+1 ; inumglobaldefs ; i++) + for (i = 0; i < progs->numglobaldefs; i++) { def = &pr_globaldefs[i]; if (def->ofs == ofs) @@ -182,12 +187,12 @@ 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; - for (i=0 ; inumfielddefs ; i++) + for (i = 0; i < progs->numfielddefs; i++) { def = &pr_fielddefs[i]; if (def->ofs == ofs) @@ -201,15 +206,15 @@ 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; - for (i=0 ; inumfielddefs ; i++) + for (i = 0; i < progs->numfielddefs; i++) { def = &pr_fielddefs[i]; - if (!strcmp(PR_GetString(def->s_name),name)) + if ( !strcmp(PR_GetString(def->s_name), name) ) return def; } return NULL; @@ -221,15 +226,15 @@ 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; - for (i=0 ; inumglobaldefs ; i++) + for (i = 0; i < progs->numglobaldefs; i++) { def = &pr_globaldefs[i]; - if (!strcmp(PR_GetString(def->s_name),name)) + if ( !strcmp(PR_GetString(def->s_name), name) ) return def; } return NULL; @@ -241,15 +246,15 @@ 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; - for (i=0 ; inumfunctions ; i++) + 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; @@ -266,7 +271,7 @@ eval_t *GetEdictFieldValue(edict_t *ed, const char *field) int i; static int rep = 0; - for (i=0 ; itype, (eval_t *)val); @@ -421,9 +426,9 @@ const char *PR_GlobalString (int ofs) } i = strlen(line); - for ( ; i<20 ; i++) - strcat (line," "); - strcat (line," "); + for ( ; i < 20; i++) + strcat (line, " "); + strcat (line, " "); return line; } @@ -431,19 +436,19 @@ const char *PR_GlobalString (int ofs) const char *PR_GlobalStringNoContents (int ofs) { int i; - ddef_t *def; + ddef_t *def; static char line[128]; 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)); i = strlen(line); - for ( ; i<20 ; i++) - strcat (line," "); - strcat (line," "); + for ( ; i < 20; i++) + strcat (line, " "); + strcat (line, " "); return line; } @@ -471,11 +476,11 @@ void ED_Print (edict_t *ed) } Con_SafePrintf("\nEDICT %i:\n", NUM_FOR_EDICT(ed)); //johnfitz -- was Con_Printf - for (i=1 ; inumfielddefs ; i++) + for (i = 1; i < progs->numfielddefs; i++) { d = &pr_fielddefs[i]; name = PR_GetString(d->s_name); - l = strlen(name); + l = strlen (name); if (l > 1 && name[l - 2] == '_') continue; // skip _x, _y, _z vars @@ -484,13 +489,15 @@ void ED_Print (edict_t *ed) // if the value is still all 0, skip the field type = d->type & ~DEF_SAVEGLOBAL; - for (j=0 ; jnumfielddefs ; i++) + for (i = 1; i < progs->numfielddefs; i++) { d = &pr_fielddefs[i]; name = PR_GetString(d->s_name); - j = strlen(name); + j = strlen (name); if (j > 1 && name[j - 2] == '_') continue; // skip _x, _y, _z vars @@ -533,19 +540,21 @@ 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 ; jtype, (eval_t *)v)); + fprintf (f, "\"%s\" ", name); + fprintf (f, "\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v)); } //johnfitz -- save entity alpha manually when progs.dat doesn't know about alpha if (!pr_alpha_supported && ed->alpha != ENTALPHA_DEFAULT) - fprintf (f,"\"alpha\" \"%f\"\n", ENTALPHA_TOSAVE(ed->alpha)); + fprintf (f, "\"alpha\" \"%f\"\n", ENTALPHA_TOSAVE(ed->alpha)); //johnfitz fprintf (f, "}\n"); @@ -568,7 +577,7 @@ void ED_PrintEdicts (void) int i; Con_Printf ("%i entities\n", sv.num_edicts); - for (i=0 ; ifree) @@ -625,13 +634,13 @@ void ED_Count (void) Con_Printf ("view :%3i\n", models); Con_Printf ("touch :%3i\n", solid); Con_Printf ("step :%3i\n", step); - } + /* ============================================================================== - ARCHIVING GLOBALS +ARCHIVING GLOBALS FIXME: need to tag constants, doesn't really work ============================================================================== @@ -649,8 +658,8 @@ void ED_WriteGlobals (FILE *f) const char *name; int type; - fprintf (f,"{\n"); - for (i=0 ; inumglobaldefs ; i++) + fprintf (f, "{\n"); + for (i = 0; i < progs->numglobaldefs; i++) { def = &pr_globaldefs[i]; type = def->type; @@ -662,10 +671,10 @@ void ED_WriteGlobals (FILE *f) continue; name = PR_GetString(def->s_name); - fprintf (f,"\"%s\" ", name); - fprintf (f,"\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); + fprintf (f, "\"%s\" ", name); + fprintf (f, "\"%s\"\n", PR_UglyValueString(type, (eval_t *)&pr_globals[def->ofs])); } - fprintf (f,"}\n"); + fprintf (f, "}\n"); } /* @@ -726,7 +735,7 @@ static string_t ED_NewString (const char *string) l = strlen(string) + 1; num = PR_AllocString (l, &new_p); - for (i=0 ; i< l ; i++) + for (i = 0; i < l; i++) { if (string[i] == '\\' && i < l-1) { @@ -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]; @@ -766,7 +775,7 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s) switch (key->type & ~DEF_SAVEGLOBAL) { case ev_string: - *(string_t *)d = ED_NewString (s); + *(string_t *)d = ED_NewString(s); break; case ev_float: @@ -777,7 +786,7 @@ qboolean ED_ParseEpair (void *base, ddef_t *key, const char *s) strcpy (string, s); v = string; w = string; - for (i=0 ; i<3 ; i++) + for (i = 0; i < 3; i++) { while (*v && *v != ' ') v++; @@ -838,14 +847,14 @@ const char *ED_ParseEdict (const char *data, edict_t *ent) init = false; -// clear it + // clear it if (ent != sv.edicts) // hack memset (&ent->v, 0, progs->entityfields * 4); -// go through all the dictionary pairs + // go through all the dictionary pairs while (1) { - // parse key + // parse key data = COM_Parse (data); if (com_token[0] == '}') break; @@ -940,16 +949,16 @@ 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; -// parse ents + // parse ents while (1) { -// parse the opening brace + // parse the opening brace data = COM_Parse (data); if (!data) break; @@ -962,7 +971,7 @@ void ED_LoadFromFile (const char *data) ent = ED_Alloc (); data = ED_ParseEdict (data, ent); -// remove things from different skill levels or deathmatch + // remove things from different skill levels or deathmatch if (deathmatch.value) { if (((int)ent->v.spawnflags & SPAWNFLAG_NOT_DEATHMATCH)) @@ -993,7 +1002,7 @@ void ED_LoadFromFile (const char *data) } // look for the spawn function - func = ED_FindFunction (PR_GetString(ent->v.classname)); + func = ED_FindFunction ( PR_GetString(ent->v.classname) ); if (!func) { @@ -1018,10 +1027,10 @@ PR_LoadProgs */ void PR_LoadProgs (void) { - int i; + int i; -// flush the non-C variable lookup cache - for (i=0 ; iversion != 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); @@ -1061,8 +1073,8 @@ void PR_LoadProgs (void) pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals); pr_globals = (float *)pr_global_struct; -// byte swap the lumps - for (i=0 ; inumstatements ; i++) + // byte swap the lumps + for (i = 0; i < progs->numstatements; i++) { pr_statements[i].op = LittleShort(pr_statements[i].op); pr_statements[i].a = LittleShort(pr_statements[i].a); @@ -1070,17 +1082,17 @@ void PR_LoadProgs (void) pr_statements[i].c = LittleShort(pr_statements[i].c); } - for (i=0 ; inumfunctions; i++) + for (i = 0; i < progs->numfunctions; i++) { - pr_functions[i].first_statement = LittleLong (pr_functions[i].first_statement); - pr_functions[i].parm_start = LittleLong (pr_functions[i].parm_start); - pr_functions[i].s_name = LittleLong (pr_functions[i].s_name); - pr_functions[i].s_file = LittleLong (pr_functions[i].s_file); - pr_functions[i].numparms = LittleLong (pr_functions[i].numparms); - pr_functions[i].locals = LittleLong (pr_functions[i].locals); + pr_functions[i].first_statement = LittleLong (pr_functions[i].first_statement); + pr_functions[i].parm_start = LittleLong (pr_functions[i].parm_start); + pr_functions[i].s_name = LittleLong (pr_functions[i].s_name); + pr_functions[i].s_file = LittleLong (pr_functions[i].s_file); + pr_functions[i].numparms = LittleLong (pr_functions[i].numparms); + pr_functions[i].locals = LittleLong (pr_functions[i].locals); } - for (i=0 ; inumglobaldefs ; i++) + for (i = 0; i < progs->numglobaldefs; i++) { pr_globaldefs[i].type = LittleShort (pr_globaldefs[i].type); pr_globaldefs[i].ofs = LittleShort (pr_globaldefs[i].ofs); @@ -1089,7 +1101,7 @@ void PR_LoadProgs (void) pr_alpha_supported = false; //johnfitz - for (i=0 ; inumfielddefs ; i++) + for (i = 0; i < progs->numfielddefs; i++) { pr_fielddefs[i].type = LittleShort (pr_fielddefs[i].type); if (pr_fielddefs[i].type & DEF_SAVEGLOBAL) @@ -1103,7 +1115,7 @@ void PR_LoadProgs (void) //johnfitz } - for (i=0 ; inumglobals ; i++) + for (i = 0; i < progs->numglobals; i++) ((int *)pr_globals)[i] = LittleLong (((int *)pr_globals)[i]); pr_edict_size = progs->entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t); @@ -1140,12 +1152,11 @@ void PR_Init (void) } - edict_t *EDICT_NUM(int n) { if (n < 0 || n >= sv.max_edicts) Sys_Error ("EDICT_NUM: bad number %i", n); - return (edict_t *)((byte *)sv.edicts+ (n)*pr_edict_size); + return (edict_t *)((byte *)sv.edicts + (n)*pr_edict_size); } int NUM_FOR_EDICT(edict_t *e) @@ -1162,6 +1173,7 @@ int NUM_FOR_EDICT(edict_t *e) //=========================================================================== + #define PR_STRING_ALLOCSLOTS 256 static void PR_AllocStringSlots (void) diff --git a/Quake/pr_exec.c b/Quake/pr_exec.c index 7d7feaa6..59a1485c 100644 --- a/Quake/pr_exec.c +++ b/Quake/pr_exec.c @@ -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,120 +20,112 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" - -/* - -*/ - typedef struct { - int s; - dfunction_t *f; + int s; + dfunction_t *f; } 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_xstatement; int pr_argc; -const char *pr_opnames[] = +static const char *pr_opnames[] = { -"DONE", + "DONE", -"MUL_F", -"MUL_V", -"MUL_FV", -"MUL_VF", + "MUL_F", + "MUL_V", + "MUL_FV", + "MUL_VF", -"DIV", + "DIV", -"ADD_F", -"ADD_V", + "ADD_F", + "ADD_V", -"SUB_F", -"SUB_V", + "SUB_F", + "SUB_V", -"EQ_F", -"EQ_V", -"EQ_S", -"EQ_E", -"EQ_FNC", + "EQ_F", + "EQ_V", + "EQ_S", + "EQ_E", + "EQ_FNC", -"NE_F", -"NE_V", -"NE_S", -"NE_E", -"NE_FNC", + "NE_F", + "NE_V", + "NE_S", + "NE_E", + "NE_FNC", -"LE", -"GE", -"LT", -"GT", + "LE", + "GE", + "LT", + "GT", -"INDIRECT", -"INDIRECT", -"INDIRECT", -"INDIRECT", -"INDIRECT", -"INDIRECT", + "INDIRECT", + "INDIRECT", + "INDIRECT", + "INDIRECT", + "INDIRECT", + "INDIRECT", -"ADDRESS", + "ADDRESS", -"STORE_F", -"STORE_V", -"STORE_S", -"STORE_ENT", -"STORE_FLD", -"STORE_FNC", + "STORE_F", + "STORE_V", + "STORE_S", + "STORE_ENT", + "STORE_FLD", + "STORE_FNC", -"STOREP_F", -"STOREP_V", -"STOREP_S", -"STOREP_ENT", -"STOREP_FLD", -"STOREP_FNC", + "STOREP_F", + "STOREP_V", + "STOREP_S", + "STOREP_ENT", + "STOREP_FLD", + "STOREP_FNC", -"RETURN", + "RETURN", -"NOT_F", -"NOT_V", -"NOT_S", -"NOT_ENT", -"NOT_FNC", + "NOT_F", + "NOT_V", + "NOT_S", + "NOT_ENT", + "NOT_FNC", -"IF", -"IFNOT", + "IF", + "IFNOT", -"CALL0", -"CALL1", -"CALL2", -"CALL3", -"CALL4", -"CALL5", -"CALL6", -"CALL7", -"CALL8", + "CALL0", + "CALL1", + "CALL2", + "CALL3", + "CALL4", + "CALL5", + "CALL6", + "CALL7", + "CALL8", -"STATE", + "STATE", -"GOTO", + "GOTO", -"AND", -"OR", + "AND", + "OR", -"BITAND", -"BITOR" + "BITAND", + "BITOR" }; const char *PR_GlobalString (int ofs); @@ -148,39 +139,39 @@ const char *PR_GlobalStringNoContents (int ofs); PR_PrintStatement ================= */ -void PR_PrintStatement (dstatement_t *s) +static void PR_PrintStatement (dstatement_t *s) { - int i; + 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]); + Con_Printf("%s ", pr_opnames[s->op]); i = strlen(pr_opnames[s->op]); - for ( ; i<10 ; i++) - Con_Printf (" "); + for ( ; i < 10; i++) + Con_Printf(" "); } if (s->op == OP_IF || s->op == OP_IFNOT) - Con_Printf ("%sbranch %i",PR_GlobalString(s->a),s->b); + Con_Printf("%sbranch %i", PR_GlobalString(s->a), s->b); else if (s->op == OP_GOTO) { - Con_Printf ("branch %i",s->a); + 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)); + Con_Printf("%s", PR_GlobalString(s->a)); + Con_Printf("%s", PR_GlobalStringNoContents(s->b)); } else { if (s->a) - Con_Printf ("%s",PR_GlobalString(s->a)); + Con_Printf("%s", PR_GlobalString(s->a)); if (s->b) - Con_Printf ("%s",PR_GlobalString(s->b)); + Con_Printf("%s", PR_GlobalString(s->b)); if (s->c) - Con_Printf ("%s", PR_GlobalStringNoContents(s->c)); + Con_Printf("%s", PR_GlobalStringNoContents(s->c)); } - Con_Printf ("\n"); + Con_Printf("\n"); } /* @@ -188,28 +179,29 @@ void PR_PrintStatement (dstatement_t *s) PR_StackTrace ============ */ -void PR_StackTrace (void) +static void PR_StackTrace (void) { + int i; dfunction_t *f; - int i; if (pr_depth == 0) { - Con_Printf ("\n"); + Con_Printf("\n"); return; } pr_stack[pr_depth].f = pr_xfunction; - for (i=pr_depth ; i>=0 ; i--) + for (i = pr_depth; i >= 0; i--) { f = pr_stack[i].f; - if (!f) { - Con_Printf ("\n"); + Con_Printf("\n"); } else - Con_Printf ("%12s : %s\n", PR_GetString(f->s_file), PR_GetString(f->s_name)); + { + 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) { + int i, num; + int pmax; dfunction_t *f, *best; - int pmax; - int num; - int i; if (!sv.active) return; @@ -235,7 +226,7 @@ void PR_Profile_f (void) { pmax = 0; best = NULL; - for (i=0 ; inumfunctions ; i++) + for (i = 0; i < progs->numfunctions; i++) { f = &pr_functions[i]; if (f->profile > pmax) @@ -247,7 +238,7 @@ void PR_Profile_f (void) if (best) { if (num < 10) - Con_Printf ("%7i %s\n", best->profile, PR_GetString(best->s_name)); + Con_Printf("%7i %s\n", best->profile, PR_GetString(best->s_name)); num++; best->profile = 0; } @@ -264,30 +255,23 @@ Aborts the currently executing function */ void PR_RunError (const char *error, ...) { - va_list argptr; - char string[1024]; + va_list argptr; + char string[1024]; - va_start (argptr,error); + va_start (argptr, error); q_vsnprintf (string, sizeof(string), error, argptr); va_end (argptr); - PR_PrintStatement (pr_statements + pr_xstatement); - PR_StackTrace (); - Con_Printf ("%s\n", string); + PR_PrintStatement(pr_statements + pr_xstatement); + PR_StackTrace(); - pr_depth = 0; // dump the stack so host_error can shutdown functions + Con_Printf("%s\n", string); - Host_Error ("Program error"); + pr_depth = 0; // dump the stack so host_error can shutdown functions + + Host_Error("Program error"); } -/* -============================================================================ -PR_ExecuteProgram - -The interpretation main loop -============================================================================ -*/ - /* ==================== PR_EnterFunction @@ -295,32 +279,32 @@ 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; + int i, j, c, o; pr_stack[pr_depth].s = pr_xstatement; pr_stack[pr_depth].f = pr_xfunction; pr_depth++; if (pr_depth >= MAX_STACK_DEPTH) - PR_RunError ("stack overflow"); + PR_RunError("stack overflow"); -// save off any locals that the new function steps on + // save off any locals that the new function steps on c = f->locals; if (localstack_used + c > LOCALSTACK_SIZE) - PR_RunError ("PR_ExecuteProgram: locals stack overflow\n"); + PR_RunError("PR_ExecuteProgram: locals stack overflow\n"); - for (i=0 ; i < c ; i++) - localstack[localstack_used+i] = ((int *)pr_globals)[f->parm_start + i]; + for (i = 0; i < c ; i++) + localstack[localstack_used + i] = ((int *)pr_globals)[f->parm_start + i]; localstack_used += c; -// copy parameters + // copy parameters o = f->parm_start; - for (i=0 ; inumparms ; i++) + for (i = 0; i < f->numparms; i++) { - for (j=0 ; jparm_size[i] ; j++) + for (j = 0; j < f->parm_size[i]; j++) { - ((int *)pr_globals)[o] = ((int *)pr_globals)[OFS_PARM0+i*3+j]; + ((int *)pr_globals)[o] = ((int *)pr_globals)[OFS_PARM0 + i*3 + j]; o++; } } @@ -334,23 +318,23 @@ int PR_EnterFunction (dfunction_t *f) PR_LeaveFunction ==================== */ -int PR_LeaveFunction (void) +static int PR_LeaveFunction (void) { - int i, c; + int i, c; if (pr_depth <= 0) - Sys_Error ("prog stack underflow"); + 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]; + for (i = 0; i < c; i++) + ((int *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i]; -// up stack + // up stack pr_depth--; pr_xfunction = pr_stack[pr_depth].f; return pr_stack[pr_depth].s; @@ -360,19 +344,21 @@ int PR_LeaveFunction (void) /* ==================== PR_ExecuteProgram + +The interpretation main loop ==================== */ void PR_ExecuteProgram (func_t fnum) { eval_t *a, *b, *c; - int s; + eval_t *ptr; + int s; dstatement_t *st; dfunction_t *f, *newf; int runaway; int i; - edict_t *ed; + edict_t *ed; int exitdepth; - eval_t *ptr; if (!fnum || fnum >= progs->numfunctions) { @@ -389,10 +375,10 @@ void PR_ExecuteProgram (func_t fnum) // make a stack frame exitdepth = pr_depth; - s = PR_EnterFunction (f); + s = PR_EnterFunction(f); -while (1) -{ + while (1) + { s++; // next statement st = &pr_statements[s]; @@ -401,13 +387,13 @@ while (1) c = (eval_t *)&pr_globals[st->c]; if (!--runaway) - PR_RunError ("runaway loop error"); + PR_RunError("runaway loop error"); pr_xfunction->profile++; pr_xstatement = s; if (pr_trace) - PR_PrintStatement (st); + PR_PrintStatement(st); switch (st->op) { @@ -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; @@ -501,11 +486,11 @@ while (1) break; case OP_EQ_V: c->_float = (a->vector[0] == b->vector[0]) && - (a->vector[1] == b->vector[1]) && - (a->vector[2] == b->vector[2]); + (a->vector[1] == b->vector[1]) && + (a->vector[2] == b->vector[2]); break; case OP_EQ_S: - c->_float = !strcmp(PR_GetString(a->string),PR_GetString(b->string)); + c->_float = !strcmp(PR_GetString(a->string), PR_GetString(b->string)); break; case OP_EQ_E: c->_float = a->_int == b->_int; @@ -514,14 +499,13 @@ while (1) c->_float = a->function == b->function; break; - case OP_NE_F: c->_float = a->_float != b->_float; break; case OP_NE_V: c->_float = (a->vector[0] != b->vector[0]) || - (a->vector[1] != b->vector[1]) || - (a->vector[2] != b->vector[2]); + (a->vector[1] != b->vector[1]) || + (a->vector[2] != b->vector[2]); break; case OP_NE_S: c->_float = strcmp(PR_GetString(a->string),PR_GetString(b->string)); @@ -533,12 +517,11 @@ while (1) c->_float = a->function != b->function; break; -//================== case OP_STORE_F: case OP_STORE_ENT: - case OP_STORE_FLD: // integers + case OP_STORE_FLD: // integers case OP_STORE_S: - case OP_STORE_FNC: // pointers + case OP_STORE_FNC: // pointers b->_int = a->_int; break; case OP_STORE_V: @@ -549,9 +532,9 @@ while (1) case OP_STOREP_F: case OP_STOREP_ENT: - case OP_STOREP_FLD: // integers + case OP_STOREP_FLD: // integers case OP_STOREP_S: - case OP_STOREP_FNC: // pointers + case OP_STOREP_FNC: // pointers ptr = (eval_t *)((byte *)sv.edicts + b->_int); ptr->_int = a->_int; break; @@ -565,10 +548,10 @@ 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"); + PR_RunError("assignment to world entity"); c->_int = (byte *)((int *)&ed->v + b->_int) - (byte *)sv.edicts; break; @@ -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]; @@ -609,7 +592,7 @@ while (1) break; case OP_GOTO: - s += st->a - 1; // offset the s++ + s += st->a - 1; // offset the s++ break; case OP_CALL0: @@ -623,31 +606,30 @@ while (1) case OP_CALL8: pr_argc = st->op - OP_CALL0; if (!a->function) - PR_RunError ("NULL 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_builtins[i] (); + PR_RunError("Bad builtin call number %d", i); + pr_builtins[i](); break; } - - s = PR_EnterFunction (newf); + // Normal function + s = PR_EnterFunction(newf); break; case OP_DONE: case OP_RETURN: 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 (); + 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: @@ -661,8 +643,8 @@ while (1) break; default: - PR_RunError ("Bad opcode %i", st->op); + PR_RunError("Bad opcode %i", st->op); } + } /* end of while(1) loop */ } -} diff --git a/Quake/progs.h b/Quake/progs.h index 2b430f2a..0f6cd7ac 100644 --- a/Quake/progs.h +++ b/Quake/progs.h @@ -22,58 +22,62 @@ 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 { - string_t string; - float _float; - float vector[3]; - func_t function; - int _int; - int edict; + string_t string; + float _float; + float vector[3]; + func_t function; + int _int; + int edict; } eval_t; #define MAX_ENT_LEAFS 16 typedef struct edict_s { - qboolean free; - link_t area; // linked to a division node or leaf - int num_leafs; - short leafnums[MAX_ENT_LEAFS]; + qboolean free; + 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) + +#define EDICT_FROM_AREA(l) STRUCT_FROM_LINK(l,edict_t,area) //============================================================================ -extern dprograms_t *progs; -extern dfunction_t *pr_functions; +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,45 +90,44 @@ 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); -#define NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size)) +#define NEXT_EDICT(e) ((edict_t *)( (byte *)e + pr_edict_size)) -#define EDICT_TO_PROG(e) ((byte *)e - (byte *)sv.edicts) -#define PROG_TO_EDICT(e) ((edict_t *)((byte *)sv.edicts + 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])) +#define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) +#define G_VECTOR(o) (&pr_globals[o]) +#define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o])) +#define G_FUNCTION(o) (*(func_t *)&pr_globals[o]) -#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])) -#define G_EDICTNUM(o) NUM_FOR_EDICT(G_EDICT(o)) -#define G_VECTOR(o) (&pr_globals[o]) -#define G_STRING(o) (PR_GetString(*(string_t *)&pr_globals[o])) -#define G_FUNCTION(o) (*(func_t *)&pr_globals[o]) - -#define E_FLOAT(e,o) (((float*)&e->v)[o]) -#define E_INT(e,o) (*(int *)&((float*)&e->v)[o]) -#define E_VECTOR(e,o) (&((float*)&e->v)[o]) -#define E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)&e->v)[o])) +#define E_FLOAT(e,o) (((float*)&e->v)[o]) +#define E_INT(e,o) (*(int *)&((float*)&e->v)[o]) +#define E_VECTOR(e,o) (&((float*)&e->v)[o]) +#define E_STRING(e,o) (PR_GetString(*(string_t *)&((float*)&e->v)[o])) extern int type_size[8]; typedef void (*builtin_t) (void); -extern builtin_t *pr_builtins; -extern int pr_numbuiltins; +extern builtin_t *pr_builtins; +extern int pr_numbuiltins; -extern int pr_argc; +extern int pr_argc; extern qboolean pr_trace; extern dfunction_t *pr_xfunction; -extern int pr_xstatement; +extern int pr_xstatement; -extern unsigned short pr_crc; +extern unsigned short pr_crc; void PR_RunError (const char *error, ...) __attribute__((__format__(__printf__,1,2), __noreturn__));