From c9b57312fb005920b265e513ac3e51bfd61d86bc Mon Sep 17 00:00:00 2001 From: Alison Watson Date: Thu, 5 Dec 2019 22:09:23 -0500 Subject: [PATCH] rewrite globals to use a safer interface that can be sanity checked --- source/host.c | 10 +- source/host_cmd.c | 38 +++---- source/net_dgrm.c | 2 +- source/pr_cmds.c | 248 ++++++++++++++++++++++----------------------- source/pr_comp.h | 78 ++++++++++++-- source/pr_edict.c | 22 ++-- source/pr_exec.c | 26 ++--- source/pr_load.c | 15 +-- source/pr_string.c | 2 +- source/progdefs.h | 59 ----------- source/progs.h | 17 ++-- source/sv_main.c | 22 ++-- source/sv_move.c | 10 +- source/sv_phys.c | 60 +++++------ source/world.c | 14 +-- 15 files changed, 308 insertions(+), 315 deletions(-) diff --git a/source/host.c b/source/host.c index 7e4281c..4faf74e 100644 --- a/source/host.c +++ b/source/host.c @@ -420,10 +420,10 @@ void SV_DropClient(bool crash) { // call the prog function for removing a client // this will set the body to a dead frame, among other things - saveSelf = pr_global_struct->self; - pr_global_struct->self = EDICT_TO_PROG(host_client->edict); - PR_ExecuteProgram(pr_global_struct->ClientDisconnect); - pr_global_struct->self = saveSelf; + saveSelf = G_INT(GBL_self); + G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict); + PR_ExecuteProgram(G_FUNC(GBL_ClientDisconnect)); + G_INT(GBL_self) = saveSelf; } Sys_Printf("Client %s removed\n", host_client->name); @@ -623,7 +623,7 @@ void Host_ServerFrame(void) edict_t *ent; //johnfitz // run the world state - pr_global_struct->frametime = host_frametime; + G_FLOAT(GBL_frametime) = host_frametime; // set the time and clear the general datagram SV_ClearDatagram(); diff --git a/source/host_cmd.c b/source/host_cmd.c index 5a2f41d..4cee473 100644 --- a/source/host_cmd.c +++ b/source/host_cmd.c @@ -490,7 +490,7 @@ void Host_God_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; //johnfitz -- allow user to explicitly set god mode to on or off @@ -535,7 +535,7 @@ void Host_Notarget_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; //johnfitz -- allow user to explicitly set notarget to on or off @@ -582,7 +582,7 @@ void Host_Noclip_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; //johnfitz -- allow user to explicitly set noclip to on or off @@ -638,7 +638,7 @@ void Host_SetPos_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; if(Cmd_Argc() != 7 && Cmd_Argc() != 4) @@ -699,7 +699,7 @@ void Host_Fly_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; //johnfitz -- allow user to explicitly set noclip to on or off @@ -1545,9 +1545,9 @@ void Host_Kill_f(void) return; } - pr_global_struct->time = sv.time; - pr_global_struct->self = EDICT_TO_PROG(sv_player); - PR_ExecuteProgram(pr_global_struct->ClientKill); + G_FLOAT(GBL_time) = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(sv_player); + PR_ExecuteProgram(G_FUNC(GBL_ClientKill)); } @@ -1662,16 +1662,16 @@ void Host_Spawn_f(void) // copy spawn parms out of the client_t for(i = 0 ; i < NUM_SPAWN_PARMS ; i++) - (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i]; + (&G_FLOAT(GBL_parm1))[i] = host_client->spawn_parms[i]; // call the spawn function - pr_global_struct->time = sv.time; - pr_global_struct->self = EDICT_TO_PROG(sv_player); - PR_ExecuteProgram(pr_global_struct->ClientConnect); + G_FLOAT(GBL_time) = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(sv_player); + PR_ExecuteProgram(G_FUNC(GBL_ClientConnect)); if((Sys_DoubleTime() - NET_QSocketGetTime(host_client->netconnection)) <= sv.time) Sys_Printf("%s entered the game\n", host_client->name); - PR_ExecuteProgram(pr_global_struct->PutClientInServer); + PR_ExecuteProgram(G_FUNC(GBL_PutClientInServer)); } @@ -1708,19 +1708,19 @@ void Host_Spawn_f(void) // MSG_WriteByte(&host_client->message, svc_updatestat); MSG_WriteByte(&host_client->message, STAT_TOTALSECRETS); - MSG_WriteLong(&host_client->message, pr_global_struct->total_secrets); + MSG_WriteLong(&host_client->message, G_FLOAT(GBL_total_secrets)); MSG_WriteByte(&host_client->message, svc_updatestat); MSG_WriteByte(&host_client->message, STAT_TOTALMONSTERS); - MSG_WriteLong(&host_client->message, pr_global_struct->total_monsters); + MSG_WriteLong(&host_client->message, G_FLOAT(GBL_total_monsters)); MSG_WriteByte(&host_client->message, svc_updatestat); MSG_WriteByte(&host_client->message, STAT_SECRETS); - MSG_WriteLong(&host_client->message, pr_global_struct->found_secrets); + MSG_WriteLong(&host_client->message, G_FLOAT(GBL_found_secrets)); MSG_WriteByte(&host_client->message, svc_updatestat); MSG_WriteByte(&host_client->message, STAT_MONSTERS); - MSG_WriteLong(&host_client->message, pr_global_struct->killed_monsters); + MSG_WriteLong(&host_client->message, G_FLOAT(GBL_killed_monsters)); // // send a fixangle @@ -1783,7 +1783,7 @@ void Host_Kick_f(void) return; } } - else if(pr_global_struct->deathmatch) + else if(G_FLOAT(GBL_deathmatch)) return; save = host_client; @@ -1871,7 +1871,7 @@ void Host_Give_f(void) return; } - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; t = Cmd_Argv(1); diff --git a/source/net_dgrm.c b/source/net_dgrm.c index c5c5bdb..4042527 100644 --- a/source/net_dgrm.c +++ b/source/net_dgrm.c @@ -89,7 +89,7 @@ static void NET_Ban_f(void) } else { - if(pr_global_struct->deathmatch) + if(G_FLOAT(GBL_deathmatch)) return; print_fn = SV_ClientPrintf; } diff --git a/source/pr_cmds.c b/source/pr_cmds.c index 2a25cc8..8d9ece5 100644 --- a/source/pr_cmds.c +++ b/source/pr_cmds.c @@ -32,7 +32,7 @@ static char *PR_GetTempString(void) return pr_string_temp[(STRINGTEMP_BUFFERS - 1) & ++pr_string_tempindex]; } -#define RETURN_EDICT(e) (((int32_t *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e)) +#define RETURN_EDICT(e) (G_INT(GBL_RETURN) = EDICT_TO_PROG(e)) #define MSG_BROADCAST 0 // unreliable to all #define MSG_ONE 1 // reliable to one (msg_entity) @@ -57,7 +57,7 @@ static char *PF_VarString(int32_t first) s = 0; for(i = first; i < pr_argc; i++) { - s = q_strlcat(out, G_STRING((OFS_PARM0 + i * 3)), sizeof(out)); + s = q_strlcat(out, G_STRING((GBL_PARM0 + i * 3)), sizeof(out)); if(s >= sizeof(out)) { Con_Warning("PF_VarString: overflow (string truncated)\n"); @@ -94,7 +94,7 @@ static void PF_error(void) s = PF_VarString(0); Con_Printf("======SERVER ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s); - ed = PROG_TO_EDICT(pr_global_struct->self); + ed = PROG_TO_EDICT(G_INT(GBL_self)); ED_Print(ed); Host_Error("Program error"); @@ -118,7 +118,7 @@ static void PF_objerror(void) s = PF_VarString(0); Con_Printf("======OBJECT ERROR in %s:\n%s\n", PR_GetString(pr_xfunction->s_name), s); - ed = PROG_TO_EDICT(pr_global_struct->self); + ed = PROG_TO_EDICT(G_INT(GBL_self)); ED_Print(ed); ED_Free(ed); @@ -137,7 +137,7 @@ makevectors(vector) */ 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); + AngleVectors(G_VECTOR(GBL_PARM0), G_VECTOR(GBL_v_forward), G_VECTOR(GBL_v_right), G_VECTOR(GBL_v_up)); } /* @@ -159,8 +159,8 @@ static void PF_setorigin(void) edict_t *e; float *org; - e = G_EDICT(OFS_PARM0); - org = G_VECTOR(OFS_PARM1); + e = G_EDICT(GBL_PARM0); + org = G_VECTOR(GBL_PARM1); VectorCopy(org, e->v.origin); SV_LinkEdict(e, false); } @@ -254,9 +254,9 @@ static void PF_setsize(void) edict_t *e; float *minvec, *maxvec; - e = G_EDICT(OFS_PARM0); - minvec = G_VECTOR(OFS_PARM1); - maxvec = G_VECTOR(OFS_PARM2); + e = G_EDICT(GBL_PARM0); + minvec = G_VECTOR(GBL_PARM1); + maxvec = G_VECTOR(GBL_PARM2); SetMinMaxSize(e, minvec, maxvec, false); } @@ -275,8 +275,8 @@ static void PF_setmodel(void) qmodel_t *mod; edict_t *e; - e = G_EDICT(OFS_PARM0); - m = G_STRING(OFS_PARM1); + e = G_EDICT(GBL_PARM0); + m = G_STRING(GBL_PARM1); // check to see if model was properly precached for(i = 0, check = sv.model_precache; *check; i++, check++) @@ -339,7 +339,7 @@ static void PF_sprint(void) client_t *client; int32_t entnum; - entnum = G_EDICTNUM(OFS_PARM0); + entnum = G_EDICTNUM(GBL_PARM0); s = PF_VarString(1); if(entnum < 1 || entnum > svs.maxclients) @@ -370,7 +370,7 @@ static void PF_centerprint(void) client_t *client; int32_t entnum; - entnum = G_EDICTNUM(OFS_PARM0); + entnum = G_EDICTNUM(GBL_PARM0); s = PF_VarString(1); if(entnum < 1 || entnum > svs.maxclients) @@ -399,7 +399,7 @@ static void PF_normalize(void) vec3_t newvalue; double new_temp; - value1 = G_VECTOR(OFS_PARM0); + value1 = G_VECTOR(GBL_PARM0); new_temp = (double)value1[0] * value1[0] + (double)value1[1] * value1[1] + (double)value1[2] * value1[2]; new_temp = sqrt(new_temp); @@ -414,7 +414,7 @@ static void PF_normalize(void) newvalue[2] = value1[2] * new_temp; } - VectorCopy(newvalue, G_VECTOR(OFS_RETURN)); + VectorCopy(newvalue, G_VECTOR(GBL_RETURN)); } /* @@ -429,12 +429,12 @@ static void PF_vlen(void) float *value1; double new_temp; - value1 = G_VECTOR(OFS_PARM0); + value1 = G_VECTOR(GBL_PARM0); new_temp = (double)value1[0] * value1[0] + (double)value1[1] * value1[1] + (double)value1[2] * value1[2]; new_temp = sqrt(new_temp); - G_FLOAT(OFS_RETURN) = new_temp; + G_FLOAT(GBL_RETURN) = new_temp; } /* @@ -449,7 +449,7 @@ static void PF_vectoyaw(void) float *value1; float yaw; - value1 = G_VECTOR(OFS_PARM0); + value1 = G_VECTOR(GBL_PARM0); if(value1[1] == 0 && value1[0] == 0) yaw = 0; @@ -460,7 +460,7 @@ static void PF_vectoyaw(void) yaw += 360; } - G_FLOAT(OFS_RETURN) = yaw; + G_FLOAT(GBL_RETURN) = yaw; } @@ -477,7 +477,7 @@ static void PF_vectoangles(void) float forward; float yaw, pitch; - value1 = G_VECTOR(OFS_PARM0); + value1 = G_VECTOR(GBL_PARM0); if(value1[1] == 0 && value1[0] == 0) { @@ -499,9 +499,9 @@ static void PF_vectoangles(void) pitch += 360; } - G_FLOAT(OFS_RETURN + 0) = pitch; - G_FLOAT(OFS_RETURN + 1) = yaw; - G_FLOAT(OFS_RETURN + 2) = 0; + G_FLOAT(GBL_RETURN + 0) = pitch; + G_FLOAT(GBL_RETURN + 1) = yaw; + G_FLOAT(GBL_RETURN + 2) = 0; } /* @@ -519,7 +519,7 @@ static void PF_random(void) num = (rand() & 0x7fff) / ((float)0x7fff); - G_FLOAT(OFS_RETURN) = num; + G_FLOAT(GBL_RETURN) = num; } /* @@ -535,10 +535,10 @@ static void PF_particle(void) float color; float count; - org = G_VECTOR(OFS_PARM0); - dir = G_VECTOR(OFS_PARM1); - color = G_FLOAT(OFS_PARM2); - count = G_FLOAT(OFS_PARM3); + org = G_VECTOR(GBL_PARM0); + dir = G_VECTOR(GBL_PARM1); + color = G_FLOAT(GBL_PARM2); + count = G_FLOAT(GBL_PARM3); SV_StartParticle(org, dir, color, count); } @@ -557,10 +557,10 @@ static void PF_ambientsound(void) int32_t i, soundnum; int32_t large = false; //johnfitz -- PROTOCOL_FITZQUAKE - pos = G_VECTOR(OFS_PARM0); - samp = G_STRING(OFS_PARM1); - vol = G_FLOAT(OFS_PARM2); - attenuation = G_FLOAT(OFS_PARM3); + pos = G_VECTOR(GBL_PARM0); + samp = G_STRING(GBL_PARM1); + vol = G_FLOAT(GBL_PARM2); + attenuation = G_FLOAT(GBL_PARM3); // check to see if samp was properly precached for(soundnum = 0, check = sv.sound_precache; *check; check++, soundnum++) @@ -632,11 +632,11 @@ static void PF_sound(void) int32_t volume; float attenuation; - entity = G_EDICT(OFS_PARM0); - channel = G_FLOAT(OFS_PARM1); - sample = G_STRING(OFS_PARM2); - volume = G_FLOAT(OFS_PARM3) * 255; - attenuation = G_FLOAT(OFS_PARM4); + entity = G_EDICT(GBL_PARM0); + channel = G_FLOAT(GBL_PARM1); + sample = G_STRING(GBL_PARM2); + volume = G_FLOAT(GBL_PARM3) * 255; + attenuation = G_FLOAT(GBL_PARM4); if(volume < 0 || volume > 255) Host_Error("SV_StartSound: volume = %" PRIi32 "", volume); @@ -682,10 +682,10 @@ static void PF_traceline(void) int32_t nomonsters; edict_t *ent; - v1 = G_VECTOR(OFS_PARM0); - v2 = G_VECTOR(OFS_PARM1); - nomonsters = G_FLOAT(OFS_PARM2); - ent = G_EDICT(OFS_PARM3); + v1 = G_VECTOR(GBL_PARM0); + v2 = G_VECTOR(GBL_PARM1); + nomonsters = G_FLOAT(GBL_PARM2); + ent = G_EDICT(GBL_PARM3); /* FIXME FIXME FIXME: Why do we hit this?? */ if(developer.value) @@ -705,18 +705,18 @@ static void PF_traceline(void) trace = SV_Move(v1, vec3_origin, vec3_origin, v2, nomonsters, ent); - pr_global_struct->trace_allsolid = trace.allsolid; - pr_global_struct->trace_startsolid = trace.startsolid; - pr_global_struct->trace_fraction = trace.fraction; - pr_global_struct->trace_inwater = trace.inwater; - pr_global_struct->trace_inopen = trace.inopen; - VectorCopy(trace.endpos, pr_global_struct->trace_endpos); - VectorCopy(trace.plane.normal, pr_global_struct->trace_plane_normal); - pr_global_struct->trace_plane_dist = trace.plane.dist; + G_FLOAT(GBL_trace_allsolid) = trace.allsolid; + G_FLOAT(GBL_trace_startsolid) = trace.startsolid; + G_FLOAT(GBL_trace_fraction) = trace.fraction; + G_FLOAT(GBL_trace_inwater) = trace.inwater; + G_FLOAT(GBL_trace_inopen) = trace.inopen; + VectorCopy(trace.endpos, G_VECTOR(GBL_trace_endpos)); + VectorCopy(trace.plane.normal, G_VECTOR(GBL_trace_plane_normal)); + G_FLOAT(GBL_trace_plane_dist) = trace.plane.dist; if(trace.ent) - pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent); + G_INT(GBL_trace_ent) = EDICT_TO_PROG(trace.ent); else - pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts); + G_INT(GBL_trace_ent) = EDICT_TO_PROG(sv.edicts); } //============================================================================ @@ -824,7 +824,7 @@ static void PF_checkclient(void) } // if current entity can't possibly see the check entity, return 0 - self = PROG_TO_EDICT(pr_global_struct->self); + self = PROG_TO_EDICT(G_INT(GBL_self)); VectorAdd(self->v.origin, self->v.view_ofs, view); leaf = Mod_PointInLeaf(view, sv.worldmodel); l = (leaf - sv.worldmodel->leafs) - 1; @@ -858,10 +858,10 @@ static void PF_stuffcmd(void) const char *str; client_t *old; - entnum = G_EDICTNUM(OFS_PARM0); + entnum = G_EDICTNUM(GBL_PARM0); if(entnum < 1 || entnum > svs.maxclients) PR_RunError("Parm 0 not a client"); - str = G_STRING(OFS_PARM1); + str = G_STRING(GBL_PARM1); old = host_client; host_client = &svs.clients[entnum - 1]; @@ -882,7 +882,7 @@ static void PF_localcmd(void) { const char *str; - str = G_STRING(OFS_PARM0); + str = G_STRING(GBL_PARM0); Cbuf_AddText(str); } @@ -897,9 +897,9 @@ static void PF_cvar(void) { const char *str; - str = G_STRING(OFS_PARM0); + str = G_STRING(GBL_PARM0); - G_FLOAT(OFS_RETURN) = Cvar_VariableValue(str); + G_FLOAT(GBL_RETURN) = Cvar_VariableValue(str); } /* @@ -913,8 +913,8 @@ static void PF_cvar_set(void) { const char *var, *val; - var = G_STRING(OFS_PARM0); - val = G_STRING(OFS_PARM1); + var = G_STRING(GBL_PARM0); + val = G_STRING(GBL_PARM1); Cvar_Set(var, val); } @@ -938,8 +938,8 @@ static void PF_findradius(void) chain = (edict_t *)sv.edicts; - org = G_VECTOR(OFS_PARM0); - rad = G_FLOAT(OFS_PARM1); + org = G_VECTOR(GBL_PARM0); + rad = G_FLOAT(GBL_PARM1); ent = NEXT_EDICT(sv.edicts); for(i = 1; i < sv.num_edicts; i++, ent = NEXT_EDICT(ent)) @@ -975,20 +975,20 @@ static void PF_ftos(void) float v; char *s; - v = G_FLOAT(OFS_PARM0); + v = G_FLOAT(GBL_PARM0); s = PR_GetTempString(); if(v == (int32_t)v) sprintf(s, "%" PRIi32 "", (int32_t)v); else sprintf(s, "%5.1f", v); - G_INT(OFS_RETURN) = PR_SetEngineString(s); + G_INT(GBL_RETURN) = PR_SetEngineString(s); } static void PF_fabs(void) { float v; - v = G_FLOAT(OFS_PARM0); - G_FLOAT(OFS_RETURN) = fabs(v); + v = G_FLOAT(GBL_PARM0); + G_FLOAT(GBL_RETURN) = fabs(v); } static void PF_vtos(void) @@ -996,8 +996,8 @@ static void PF_vtos(void) char *s; s = PR_GetTempString(); - sprintf(s, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]); - G_INT(OFS_RETURN) = PR_SetEngineString(s); + sprintf(s, "'%5.1f %5.1f %5.1f'", G_VECTOR(GBL_PARM0)[0], G_VECTOR(GBL_PARM0)[1], G_VECTOR(GBL_PARM0)[2]); + G_INT(GBL_RETURN) = PR_SetEngineString(s); } static void PF_spawn(void) @@ -1013,7 +1013,7 @@ static void PF_remove(void) { edict_t *ed; - ed = G_EDICT(OFS_PARM0); + ed = G_EDICT(GBL_PARM0); ED_Free(ed); } @@ -1026,9 +1026,9 @@ static void PF_find(void) const char *s, *t; edict_t *ed; - e = G_EDICTNUM(OFS_PARM0); - f = G_INT(OFS_PARM1); - s = G_STRING(OFS_PARM2); + e = G_EDICTNUM(GBL_PARM0); + f = G_INT(GBL_PARM1); + s = G_STRING(GBL_PARM2); if(!s) PR_RunError("PF_find: bad search string"); @@ -1059,7 +1059,7 @@ static void PR_CheckEmptyString(const char *s) 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); + G_INT(GBL_RETURN) = G_INT(GBL_PARM0); } static void PF_precache_sound(void) @@ -1070,8 +1070,8 @@ static void PF_precache_sound(void) if(sv.state != ss_loading) PR_RunError("PF_Precache_*: Precache can only be done in spawn functions"); - s = G_STRING(OFS_PARM0); - G_INT(OFS_RETURN) = G_INT(OFS_PARM0); + s = G_STRING(GBL_PARM0); + G_INT(GBL_RETURN) = G_INT(GBL_PARM0); PR_CheckEmptyString(s); for(i = 0; i < MAX_SOUNDS; i++) @@ -1095,8 +1095,8 @@ static void PF_precache_model(void) if(sv.state != ss_loading) PR_RunError("PF_Precache_*: Precache can only be done in spawn functions"); - s = G_STRING(OFS_PARM0); - G_INT(OFS_RETURN) = G_INT(OFS_PARM0); + s = G_STRING(GBL_PARM0); + G_INT(GBL_RETURN) = G_INT(GBL_PARM0); PR_CheckEmptyString(s); for(i = 0; i < MAX_MODELS; i++) @@ -1131,7 +1131,7 @@ static void PF_traceoff(void) static void PF_eprint(void) { - ED_PrintNum(G_EDICTNUM(OFS_PARM0)); + ED_PrintNum(G_EDICTNUM(GBL_PARM0)); } /* @@ -1149,13 +1149,13 @@ static void PF_walkmove(void) dfunction_t *oldf; int32_t oldself; - ent = PROG_TO_EDICT(pr_global_struct->self); - yaw = G_FLOAT(OFS_PARM0); - dist = G_FLOAT(OFS_PARM1); + ent = PROG_TO_EDICT(G_INT(GBL_self)); + yaw = G_FLOAT(GBL_PARM0); + dist = G_FLOAT(GBL_PARM1); if(!((int32_t)ent->v.flags & (FL_ONGROUND | FL_FLY | FL_SWIM))) { - G_FLOAT(OFS_RETURN) = 0; + G_FLOAT(GBL_RETURN) = 0; return; } @@ -1167,14 +1167,14 @@ static void PF_walkmove(void) // save program state, because SV_movestep may call other functions oldf = pr_xfunction; - oldself = pr_global_struct->self; + oldself = G_INT(GBL_self); - G_FLOAT(OFS_RETURN) = SV_movestep(ent, move, true); + G_FLOAT(GBL_RETURN) = SV_movestep(ent, move, true); // restore program state pr_xfunction = oldf; - pr_global_struct->self = oldself; + G_INT(GBL_self) = oldself; } /* @@ -1190,7 +1190,7 @@ static void PF_droptofloor(void) vec3_t end; trace_t trace; - ent = PROG_TO_EDICT(pr_global_struct->self); + ent = PROG_TO_EDICT(G_INT(GBL_self)); VectorCopy(ent->v.origin, end); end[2] -= 256; @@ -1198,14 +1198,14 @@ static void PF_droptofloor(void) trace = SV_Move(ent->v.origin, ent->v.mins, ent->v.maxs, end, false, ent); if(trace.fraction == 1 || trace.allsolid) - G_FLOAT(OFS_RETURN) = 0; + G_FLOAT(GBL_RETURN) = 0; else { VectorCopy(trace.endpos, ent->v.origin); SV_LinkEdict(ent, false); ent->v.flags = (int32_t)ent->v.flags | FL_ONGROUND; ent->v.groundentity = EDICT_TO_PROG(trace.ent); - G_FLOAT(OFS_RETURN) = 1; + G_FLOAT(GBL_RETURN) = 1; } } @@ -1223,8 +1223,8 @@ static void PF_lightstyle(void) client_t *client; int32_t j; - style = G_FLOAT(OFS_PARM0); - val = G_STRING(OFS_PARM1); + style = G_FLOAT(GBL_PARM0); + val = G_STRING(GBL_PARM1); // bounds check to avoid clobbering sv struct if(style < 0 || style >= MAX_LIGHTSTYLES) @@ -1254,21 +1254,21 @@ static void PF_lightstyle(void) static void PF_rint(void) { float f; - f = G_FLOAT(OFS_PARM0); + f = G_FLOAT(GBL_PARM0); if(f > 0) - G_FLOAT(OFS_RETURN) = (int32_t)(f + 0.5); + G_FLOAT(GBL_RETURN) = (int32_t)(f + 0.5); else - G_FLOAT(OFS_RETURN) = (int32_t)(f - 0.5); + G_FLOAT(GBL_RETURN) = (int32_t)(f - 0.5); } static void PF_floor(void) { - G_FLOAT(OFS_RETURN) = floor(G_FLOAT(OFS_PARM0)); + G_FLOAT(GBL_RETURN) = floor(G_FLOAT(GBL_PARM0)); } static void PF_ceil(void) { - G_FLOAT(OFS_RETURN) = ceil(G_FLOAT(OFS_PARM0)); + G_FLOAT(GBL_RETURN) = ceil(G_FLOAT(GBL_PARM0)); } @@ -1281,9 +1281,9 @@ static void PF_checkbottom(void) { edict_t *ent; - ent = G_EDICT(OFS_PARM0); + ent = G_EDICT(GBL_PARM0); - G_FLOAT(OFS_RETURN) = SV_CheckBottom(ent); + G_FLOAT(GBL_RETURN) = SV_CheckBottom(ent); } /* @@ -1295,9 +1295,9 @@ static void PF_pointcontents(void) { float *v; - v = G_VECTOR(OFS_PARM0); + v = G_VECTOR(GBL_PARM0); - G_FLOAT(OFS_RETURN) = SV_PointContents(v); + G_FLOAT(GBL_RETURN) = SV_PointContents(v); } /* @@ -1312,7 +1312,7 @@ static void PF_nextent(void) int32_t i; edict_t *ent; - i = G_EDICTNUM(OFS_PARM0); + i = G_EDICTNUM(GBL_PARM0); while(1) { i++; @@ -1348,21 +1348,21 @@ static void PF_aim(void) float dist, bestdist; float speed; - ent = G_EDICT(OFS_PARM0); - speed = G_FLOAT(OFS_PARM1); + ent = G_EDICT(GBL_PARM0); + speed = G_FLOAT(GBL_PARM1); (void) speed; /* variable set but not used */ VectorCopy(ent->v.origin, start); start[2] += 20; // try sending a trace straight - VectorCopy(pr_global_struct->v_forward, dir); + VectorCopy(G_VECTOR(GBL_v_forward), dir); 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)) { - VectorCopy(pr_global_struct->v_forward, G_VECTOR(OFS_RETURN)); + VectorCopy(G_VECTOR(GBL_v_forward), G_VECTOR(GBL_RETURN)); return; } @@ -1384,7 +1384,7 @@ static void PF_aim(void) 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); + dist = DotProduct(dir, G_VECTOR(GBL_v_forward)); if(dist < bestdist) continue; // to far to turn tr = SV_Move(start, vec3_origin, vec3_origin, end, false, ent); @@ -1399,15 +1399,15 @@ static void PF_aim(void) if(bestent) { VectorSubtract(bestent->v.origin, ent->v.origin, dir); - dist = DotProduct(dir, pr_global_struct->v_forward); - VectorScale(pr_global_struct->v_forward, dist, end); + dist = DotProduct(dir, G_VECTOR(GBL_v_forward)); + VectorScale(G_VECTOR(GBL_v_forward), dist, end); end[2] = dir[2]; VectorNormalize(end); - VectorCopy(end, G_VECTOR(OFS_RETURN)); + VectorCopy(end, G_VECTOR(GBL_RETURN)); } else { - VectorCopy(bestdir, G_VECTOR(OFS_RETURN)); + VectorCopy(bestdir, G_VECTOR(GBL_RETURN)); } } @@ -1423,7 +1423,7 @@ void PF_changeyaw(void) edict_t *ent; float ideal, current, move, speed; - ent = PROG_TO_EDICT(pr_global_struct->self); + ent = PROG_TO_EDICT(G_INT(GBL_self)); current = anglemod(ent->v.angles[1]); ideal = ent->v.ideal_yaw; speed = ent->v.yaw_speed; @@ -1469,14 +1469,14 @@ static sizebuf_t *WriteDest(void) int32_t dest; edict_t *ent; - dest = G_FLOAT(OFS_PARM0); + dest = G_FLOAT(GBL_PARM0); switch(dest) { case MSG_BROADCAST: return &sv.datagram; case MSG_ONE: - ent = PROG_TO_EDICT(pr_global_struct->msg_entity); + ent = PROG_TO_EDICT(G_INT(GBL_msg_entity)); entnum = NUM_FOR_EDICT(ent); if(entnum < 1 || entnum > svs.maxclients) PR_RunError("WriteDest: not a client"); @@ -1498,42 +1498,42 @@ static sizebuf_t *WriteDest(void) static void PF_WriteByte(void) { - MSG_WriteByte(WriteDest(), G_FLOAT(OFS_PARM1)); + MSG_WriteByte(WriteDest(), G_FLOAT(GBL_PARM1)); } static void PF_WriteChar(void) { - MSG_WriteChar(WriteDest(), G_FLOAT(OFS_PARM1)); + MSG_WriteChar(WriteDest(), G_FLOAT(GBL_PARM1)); } static void PF_WriteShort(void) { - MSG_WriteShort(WriteDest(), G_FLOAT(OFS_PARM1)); + MSG_WriteShort(WriteDest(), G_FLOAT(GBL_PARM1)); } static void PF_WriteLong(void) { - MSG_WriteLong(WriteDest(), G_FLOAT(OFS_PARM1)); + MSG_WriteLong(WriteDest(), G_FLOAT(GBL_PARM1)); } static void PF_WriteAngle(void) { - MSG_WriteAngle(WriteDest(), G_FLOAT(OFS_PARM1), sv.protocolflags); + MSG_WriteAngle(WriteDest(), G_FLOAT(GBL_PARM1), sv.protocolflags); } static void PF_WriteCoord(void) { - MSG_WriteCoord(WriteDest(), G_FLOAT(OFS_PARM1), sv.protocolflags); + MSG_WriteCoord(WriteDest(), G_FLOAT(GBL_PARM1), sv.protocolflags); } static void PF_WriteString(void) { - MSG_WriteString(WriteDest(), G_STRING(OFS_PARM1)); + MSG_WriteString(WriteDest(), G_STRING(GBL_PARM1)); } static void PF_WriteEntity(void) { - MSG_WriteShort(WriteDest(), G_EDICTNUM(OFS_PARM1)); + MSG_WriteShort(WriteDest(), G_EDICTNUM(GBL_PARM1)); } //============================================================================= @@ -1544,7 +1544,7 @@ static void PF_makestatic(void) int32_t i; int32_t bits = 0; //johnfitz -- PROTOCOL_FITZQUAKE - ent = G_EDICT(OFS_PARM0); + ent = G_EDICT(GBL_PARM0); //johnfitz -- don't send invisible static entities if(ent->alpha == ENTALPHA_ZERO) @@ -1622,7 +1622,7 @@ static void PF_setspawnparms(void) int32_t i; client_t *client; - ent = G_EDICT(OFS_PARM0); + ent = G_EDICT(GBL_PARM0); i = NUM_FOR_EDICT(ent); if(i < 1 || i > svs.maxclients) PR_RunError("Entity is not a client"); @@ -1631,7 +1631,7 @@ static void PF_setspawnparms(void) client = svs.clients + (i - 1); for(i = 0; i < NUM_SPAWN_PARMS; i++) - (&pr_global_struct->parm1)[i] = client->spawn_parms[i]; + (&G_FLOAT(GBL_parm1))[i] = client->spawn_parms[i]; } /* @@ -1648,7 +1648,7 @@ static void PF_changelevel(void) return; svs.changelevel_issued = true; - s = G_STRING(OFS_PARM0); + s = G_STRING(GBL_PARM0); Cbuf_AddText(va("changelevel %s\n", s)); } diff --git a/source/pr_comp.h b/source/pr_comp.h index e22651d..a3e07d3 100644 --- a/source/pr_comp.h +++ b/source/pr_comp.h @@ -22,16 +22,74 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef spingle__pr_comp_h #define spingle__pr_comp_h -#define OFS_NULL 0 -#define OFS_RETURN 1 -#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 -#define OFS_PARM4 16 -#define OFS_PARM5 19 -#define OFS_PARM6 22 -#define OFS_PARM7 25 +enum +{ + GBL_NULL, + GBL_RETURN, + GBL_PARM0 = GBL_RETURN + 3, + GBL_PARM1 = GBL_PARM0 + 3, + GBL_PARM2 = GBL_PARM1 + 3, + GBL_PARM3 = GBL_PARM2 + 3, + GBL_PARM4 = GBL_PARM3 + 3, + GBL_PARM5 = GBL_PARM4 + 3, + GBL_PARM6 = GBL_PARM5 + 3, + GBL_PARM7 = GBL_PARM6 + 3, + GBL_self = 28, + GBL_other, + GBL_world, + GBL_time, + GBL_frametime, + GBL_force_retouch, + GBL_mapname, + GBL_deathmatch, + GBL_coop, + GBL_teamplay, + GBL_serverflags, + GBL_total_secrets, + GBL_total_monsters, + GBL_found_secrets, + GBL_killed_monsters, + GBL_parm1, + GBL_parm2, + GBL_parm3, + GBL_parm4, + GBL_parm5, + GBL_parm6, + GBL_parm7, + GBL_parm8, + GBL_parm9, + GBL_parm10, + GBL_parm11, + GBL_parm12, + GBL_parm13, + GBL_parm14, + GBL_parm15, + GBL_parm16, + GBL_v_forward, + GBL_v_up = GBL_v_forward + 3, + GBL_v_right = GBL_v_up + 3, + GBL_trace_allsolid = GBL_v_right + 3, + GBL_trace_startsolid, + GBL_trace_fraction, + GBL_trace_endpos, + GBL_trace_plane_normal = GBL_trace_endpos + 3, + GBL_trace_plane_dist = GBL_trace_plane_normal + 3, + GBL_trace_ent, + GBL_trace_inopen, + GBL_trace_inwater, + GBL_msg_entity, + GBL_main, + GBL_StartFrame, + GBL_PlayerPreThink, + GBL_PlayerPostThink, + GBL_ClientKill, + GBL_ClientConnect, + GBL_PutClientInServer, + GBL_ClientDisconnect, + GBL_SetNewParms, + GBL_SetChangeParms, + GBL_SYSTEM_END, +}; #define DEF_SAVEGLOBAL (1 << 15) diff --git a/source/pr_edict.c b/source/pr_edict.c index 0e57379..69ac4db 100644 --- a/source/pr_edict.c +++ b/source/pr_edict.c @@ -23,18 +23,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "q_defs.h" -dprograms_t progs; -dfunction_t *pr_functions; +dprograms_t progs; +dfunction_t *pr_functions; +dstatement_t *pr_statements; +byte *pr_global_data; -ddef_t *pr_fielddefs; +ddef_t *pr_fielddefs; +int32_t pr_edict_size; // in bytes bool pr_alpha_supported; //johnfitz -dstatement_t *pr_statements; -globalvars_t *pr_global_struct; -float *pr_globals; // same as pr_global_struct -int32_t pr_edict_size; // in bytes - uint16_t pr_crc; static int32_t type_size[] = @@ -505,7 +503,7 @@ void ED_WriteGlobals(FILE *f) 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\"\n", PR_UglyValueString(type, G_EVAL(def->ofs))); } fprintf(f, "}\n"); } @@ -546,7 +544,7 @@ const char *ED_ParseGlobals(const char *data) continue; } - if(!ED_ParseEpair(pr_globals, key, com_token)) + if(!ED_ParseEpair(pr_global_data, key, com_token)) Host_Error("ED_ParseGlobals: parse error"); } return data; @@ -798,7 +796,7 @@ void ED_LoadFromFile(const char *data) edict_t *ent = NULL; int32_t inhibit = 0; - pr_global_struct->time = sv.time; + G_FLOAT(GBL_time) = sv.time; // parse ents while(1) @@ -857,7 +855,7 @@ void ED_LoadFromFile(const char *data) continue; } - pr_global_struct->self = EDICT_TO_PROG(ent); + G_INT(GBL_self) = EDICT_TO_PROG(ent); PR_ExecuteProgram(func - pr_functions); } diff --git a/source/pr_exec.c b/source/pr_exec.c index ed241a6..c590cf2 100644 --- a/source/pr_exec.c +++ b/source/pr_exec.c @@ -297,7 +297,7 @@ static int32_t PR_EnterFunction(dfunction_t *f) PR_RunError("PR_ExecuteProgram: locals stack overflow\n"); for(i = 0; i < c ; i++) - localstack[localstack_used + i] = ((int32_t *)pr_globals)[f->parm_start + i]; + localstack[localstack_used + i] = G_INT(f->parm_start + i); localstack_used += c; // copy parameters @@ -306,7 +306,7 @@ static int32_t PR_EnterFunction(dfunction_t *f) { for(j = 0; j < f->parm_size[i]; j++) { - ((int32_t *)pr_globals)[o] = ((int32_t *)pr_globals)[OFS_PARM0 + i * 3 + j]; + G_INT(o) = G_INT(GBL_PARM0 + i * 3 + j); o++; } } @@ -334,7 +334,7 @@ static int32_t PR_LeaveFunction(void) PR_RunError("PR_ExecuteProgram: locals stack underflow"); for(i = 0; i < c; i++) - ((int32_t *)pr_globals)[pr_xfunction->parm_start + i] = localstack[localstack_used + i]; + G_INT(pr_xfunction->parm_start + i) = localstack[localstack_used + i]; // up stack pr_depth--; @@ -350,9 +350,9 @@ PR_ExecuteProgram The interpretation main loop ==================== */ -#define OPA ((eval_t *)&pr_globals[(uint16_t)st->a]) -#define OPB ((eval_t *)&pr_globals[(uint16_t)st->b]) -#define OPC ((eval_t *)&pr_globals[(uint16_t)st->c]) +#define OPA G_EVAL((uint16_t)st->a) +#define OPB G_EVAL((uint16_t)st->b) +#define OPC G_EVAL((uint16_t)st->c) void PR_ExecuteProgram(func_t fnum) { @@ -365,8 +365,8 @@ void PR_ExecuteProgram(func_t fnum) if(!fnum || fnum >= progs.numfunctions) { - if(pr_global_struct->self) - ED_Print(PROG_TO_EDICT(pr_global_struct->self)); + if(G_INT(GBL_self)) + ED_Print(PROG_TO_EDICT(G_INT(GBL_self))); Host_Error("PR_ExecuteProgram: NULL function"); } @@ -606,9 +606,9 @@ void PR_ExecuteProgram(func_t fnum) pr_xfunction->profile += profile - startprofile; startprofile = profile; pr_xstatement = st - pr_statements; - pr_globals[OFS_RETURN] = pr_globals[(uint16_t)st->a]; - pr_globals[OFS_RETURN + 1] = pr_globals[(uint16_t)st->a + 1]; - pr_globals[OFS_RETURN + 2] = pr_globals[(uint16_t)st->a + 2]; + G_FLOAT(GBL_RETURN + 0) = G_FLOAT((uint16_t)st->a + 0); + G_FLOAT(GBL_RETURN + 1) = G_FLOAT((uint16_t)st->a + 1); + G_FLOAT(GBL_RETURN + 2) = G_FLOAT((uint16_t)st->a + 2); st = &pr_statements[PR_LeaveFunction()]; if(pr_depth == exitdepth) { @@ -618,8 +618,8 @@ void PR_ExecuteProgram(func_t fnum) break; case OP_STATE: - ed = PROG_TO_EDICT(pr_global_struct->self); - ed->v.nextthink = pr_global_struct->time + 0.1; + ed = PROG_TO_EDICT(G_INT(GBL_self)); + ed->v.nextthink = G_FLOAT(GBL_time) + 0.1; ed->v.frame = OPA->_float; ed->v.think = OPB->function; break; diff --git a/source/pr_load.c b/source/pr_load.c index e2022fc..8a97b86 100644 --- a/source/pr_load.c +++ b/source/pr_load.c @@ -77,6 +77,9 @@ static void PR_LoadProgHeader(byte const *data) if(progs.ofs_strings + progs.numstrings >= com_filesize) Host_Error("PR_LoadProgHeader: strings go past end of file\n"); + + if(progs.numglobals < GBL_SYSTEM_END) + Host_Error("PR_LoadProgHeader: not enough globals\n"); } static void PR_LoadFunctions(byte const *data) @@ -175,18 +178,10 @@ static void PR_LoadGlobals(byte const *data) { int32_t i; - // HACK - pr_global_struct = Hunk_Memdup(data, progs.numglobals * 4, "pr_global_struct"); - - /* - pr_global_struct = Hunk_AllocName(sizeof(*pr_global_struct), - "pr_global_struct"); - */ - - pr_globals = (float *)pr_global_struct; + pr_global_data = Hunk_Memdup(data, progs.numglobals * 4, "pr_global_data"); for(i = 0; i < progs.numglobals; i++) - pr_globals[i] = LittleFloat(pr_globals[i]); + G_INT(i) = LittleLong(G_INT(i)); } /* diff --git a/source/pr_string.c b/source/pr_string.c index 12178d5..168e6b5 100644 --- a/source/pr_string.c +++ b/source/pr_string.c @@ -147,7 +147,7 @@ const char *PR_GlobalString(int32_t ofs) ddef_t *def; void *val; - val = &pr_globals[ofs]; + val = G_VOID(ofs); def = ED_GlobalAtOfs(ofs); if(!def) sprintf(line, "%" PRIi32 "(?)", ofs); diff --git a/source/progdefs.h b/source/progdefs.h index 6357160..07eb03f 100644 --- a/source/progdefs.h +++ b/source/progdefs.h @@ -22,65 +22,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef spingle__progdefs_h #define spingle__progdefs_h -typedef struct -{ - int32_t pad[28]; - int32_t self; - int32_t other; - int32_t world; - float time; - float frametime; - float force_retouch; - string_t mapname; - float deathmatch; - float coop; - float teamplay; - float serverflags; - float total_secrets; - float total_monsters; - float found_secrets; - float killed_monsters; - float parm1; - float parm2; - float parm3; - float parm4; - float parm5; - float parm6; - float parm7; - float parm8; - float parm9; - float parm10; - float parm11; - float parm12; - float parm13; - float parm14; - float parm15; - float parm16; - vec3_t v_forward; - vec3_t v_up; - vec3_t v_right; - float trace_allsolid; - float trace_startsolid; - float trace_fraction; - vec3_t trace_endpos; - vec3_t trace_plane_normal; - float trace_plane_dist; - int32_t trace_ent; - float trace_inopen; - float trace_inwater; - int32_t msg_entity; - func_t main; - func_t StartFrame; - func_t PlayerPreThink; - func_t PlayerPostThink; - func_t ClientKill; - func_t ClientConnect; - func_t PutClientInServer; - func_t ClientDisconnect; - func_t SetNewParms; - func_t SetChangeParms; -} globalvars_t; - typedef struct { float modelindex; diff --git a/source/progs.h b/source/progs.h index 8274087..274ca9e 100644 --- a/source/progs.h +++ b/source/progs.h @@ -62,8 +62,7 @@ typedef struct edict_s extern dprograms_t progs; extern dfunction_t *pr_functions; extern dstatement_t *pr_statements; -extern globalvars_t *pr_global_struct; -extern float *pr_globals; +extern byte *pr_global_data; extern ddef_t *pr_fielddefs; extern int32_t pr_edict_size; @@ -116,13 +115,15 @@ int32_t 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) (*(int32_t *)&pr_globals[o]) -#define G_EDICT(o) ((edict_t *)((byte *)sv.edicts+ *(int32_t *)&pr_globals[o])) +#define G_FLOAT(o) (((float *)pr_global_data)[o]) +#define G_INT(o) (((int32_t *)pr_global_data)[o]) +#define G_EDICT(o) ((edict_t *)(&((byte *)sv.edicts)[G_INT(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_VECTOR(o) (&G_FLOAT(o)) +#define G_STRING(o) (PR_GetString((string_t)G_INT(o))) +#define G_FUNC(o) ((func_t)G_INT(o)) +#define G_EVAL(o) ((eval_t *)&G_FLOAT(o)) +#define G_VOID(o) ((void *)&G_FLOAT(o)) typedef void (*builtin_t)(void); diff --git a/source/sv_main.c b/source/sv_main.c index 4c27de8..ba9c31d 100644 --- a/source/sv_main.c +++ b/source/sv_main.c @@ -382,9 +382,9 @@ void SV_ConnectClient(int32_t clientnum) else { // call the progs to get default spawn parms for the new client - PR_ExecuteProgram(pr_global_struct->SetNewParms); + PR_ExecuteProgram(G_FUNC(GBL_SetNewParms)); for(i = 0 ; i < NUM_SPAWN_PARMS ; i++) - client->spawn_parms[i] = (&pr_global_struct->parm1)[i]; + client->spawn_parms[i] = (&G_FLOAT(GBL_parm1))[i]; } SV_SendServerinfo(client); @@ -822,7 +822,7 @@ void SV_WriteClientdataToMessage(edict_t *ent, sizebuf_t *msg) if(val) items = (int32_t)ent->v.items | ((int32_t)val->_float << 23); else - items = (int32_t)ent->v.items | ((int32_t)pr_global_struct->serverflags << 28); + items = (int32_t)ent->v.items | ((int32_t)G_FLOAT(GBL_serverflags) << 28); bits |= SU_ITEMS; @@ -1296,7 +1296,7 @@ void SV_SaveSpawnparms(void) { int32_t i, j; - svs.serverflags = pr_global_struct->serverflags; + svs.serverflags = G_FLOAT(GBL_serverflags); for(i = 0, host_client = svs.clients ; i < svs.maxclients ; i++, host_client++) { @@ -1304,10 +1304,10 @@ void SV_SaveSpawnparms(void) continue; // call the progs to get default spawn parms for the new client - pr_global_struct->self = EDICT_TO_PROG(host_client->edict); - PR_ExecuteProgram(pr_global_struct->SetChangeParms); + G_INT(GBL_self) = EDICT_TO_PROG(host_client->edict); + PR_ExecuteProgram(G_FUNC(GBL_SetChangeParms)); for(j = 0 ; j < NUM_SPAWN_PARMS ; j++) - host_client->spawn_parms[j] = (&pr_global_struct->parm1)[j]; + host_client->spawn_parms[j] = (&G_FLOAT(GBL_parm1))[j]; } } @@ -1444,14 +1444,14 @@ void SV_SpawnServer(const char *server) ent->v.movetype = MOVETYPE_PUSH; if(coop.value) - pr_global_struct->coop = coop.value; + G_FLOAT(GBL_coop) = coop.value; else - pr_global_struct->deathmatch = deathmatch.value; + G_FLOAT(GBL_deathmatch) = deathmatch.value; - pr_global_struct->mapname = PR_SetEngineString(sv.name); + G_INT(GBL_mapname) = PR_SetEngineString(sv.name); // serverflags are for cross level information (sigils) - pr_global_struct->serverflags = svs.serverflags; + G_FLOAT(GBL_serverflags) = svs.serverflags; ED_LoadFromFile(sv.worldmodel->entities); diff --git a/source/sv_move.c b/source/sv_move.c index 6726622..7cec0f7 100644 --- a/source/sv_move.c +++ b/source/sv_move.c @@ -105,8 +105,8 @@ SV_movestep Called by monster program code. The move will be adjusted for slopes and stairs, but if the move isn't -possible, no move is done, false is returned, and -pr_global_struct->trace_normal is set to the normal of the blocking wall +possible, no move is done, false is returned, and trace_normal is set to the +normal of the blocking wall ============= */ bool SV_movestep(edict_t *ent, vec3_t move, bool relink) @@ -399,13 +399,13 @@ void SV_MoveToGoal(void) edict_t *ent, *goal; float dist; - ent = PROG_TO_EDICT(pr_global_struct->self); + ent = PROG_TO_EDICT(G_INT(GBL_self)); goal = PROG_TO_EDICT(ent->v.goalentity); - dist = G_FLOAT(OFS_PARM0); + dist = G_FLOAT(GBL_PARM0); if(!((int32_t)ent->v.flags & (FL_ONGROUND | FL_FLY | FL_SWIM))) { - G_FLOAT(OFS_RETURN) = 0; + G_FLOAT(GBL_RETURN) = 0; return; } diff --git a/source/sv_phys.c b/source/sv_phys.c index 96d1236..aede82d 100644 --- a/source/sv_phys.c +++ b/source/sv_phys.c @@ -138,9 +138,9 @@ bool SV_RunThink(edict_t *ent) oldframe = ent->v.frame; //johnfitz ent->v.nextthink = 0; - pr_global_struct->time = thinktime; - pr_global_struct->self = EDICT_TO_PROG(ent); - pr_global_struct->other = EDICT_TO_PROG(sv.edicts); + G_FLOAT(GBL_time) = thinktime; + G_INT(GBL_self) = EDICT_TO_PROG(ent); + G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); PR_ExecuteProgram(ent->v.think); //johnfitz -- PROTOCOL_FITZQUAKE @@ -169,26 +169,26 @@ void SV_Impact(edict_t *e1, edict_t *e2) { int32_t old_self, old_other; - old_self = pr_global_struct->self; - old_other = pr_global_struct->other; + old_self = G_INT(GBL_self); + old_other = G_INT(GBL_other); - pr_global_struct->time = sv.time; + G_FLOAT(GBL_time) = sv.time; if(e1->v.touch && e1->v.solid != SOLID_NOT) { - pr_global_struct->self = EDICT_TO_PROG(e1); - pr_global_struct->other = EDICT_TO_PROG(e2); + G_INT(GBL_self) = EDICT_TO_PROG(e1); + G_INT(GBL_other) = EDICT_TO_PROG(e2); PR_ExecuteProgram(e1->v.touch); } if(e2->v.touch && e2->v.solid != SOLID_NOT) { - pr_global_struct->self = EDICT_TO_PROG(e2); - pr_global_struct->other = EDICT_TO_PROG(e1); + G_INT(GBL_self) = EDICT_TO_PROG(e2); + G_INT(GBL_other) = EDICT_TO_PROG(e1); PR_ExecuteProgram(e2->v.touch); } - pr_global_struct->self = old_self; - pr_global_struct->other = old_other; + G_INT(GBL_self) = old_self; + G_INT(GBL_other) = old_other; } @@ -555,8 +555,8 @@ void SV_PushMove(edict_t *pusher, float movetime) // otherwise, just stay in place until the obstacle is gone if(pusher->v.blocked) { - pr_global_struct->self = EDICT_TO_PROG(pusher); - pr_global_struct->other = EDICT_TO_PROG(check); + G_INT(GBL_self) = EDICT_TO_PROG(pusher); + G_INT(GBL_other) = EDICT_TO_PROG(check); PR_ExecuteProgram(pusher->v.blocked); } @@ -607,9 +607,9 @@ void SV_Physics_Pusher(edict_t *ent) if(thinktime > oldltime && thinktime <= ent->v.ltime) { ent->v.nextthink = 0; - pr_global_struct->time = sv.time; - pr_global_struct->self = EDICT_TO_PROG(ent); - pr_global_struct->other = EDICT_TO_PROG(sv.edicts); + G_FLOAT(GBL_time) = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(ent); + G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); PR_ExecuteProgram(ent->v.think); if(ent->free) return; @@ -942,9 +942,9 @@ void SV_Physics_Client(edict_t *ent, int32_t num) // // call standard client pre-think // - pr_global_struct->time = sv.time; - pr_global_struct->self = EDICT_TO_PROG(ent); - PR_ExecuteProgram(pr_global_struct->PlayerPreThink); + G_FLOAT(GBL_time) = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(ent); + PR_ExecuteProgram(G_FUNC(GBL_PlayerPreThink)); // // do a move @@ -996,9 +996,9 @@ void SV_Physics_Client(edict_t *ent, int32_t num) // SV_LinkEdict(ent, true); - pr_global_struct->time = sv.time; - pr_global_struct->self = EDICT_TO_PROG(ent); - PR_ExecuteProgram(pr_global_struct->PlayerPostThink); + G_FLOAT(GBL_time) = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(ent); + PR_ExecuteProgram(G_FUNC(GBL_PlayerPostThink)); } //============================================================================ @@ -1212,10 +1212,10 @@ void SV_Physics(void) edict_t *ent; // let the progs know that a new frame has started - pr_global_struct->self = EDICT_TO_PROG(sv.edicts); - pr_global_struct->other = EDICT_TO_PROG(sv.edicts); - pr_global_struct->time = sv.time; - PR_ExecuteProgram(pr_global_struct->StartFrame); + G_INT(GBL_self) = EDICT_TO_PROG(sv.edicts); + G_INT(GBL_other) = EDICT_TO_PROG(sv.edicts); + G_FLOAT(GBL_time) = sv.time; + PR_ExecuteProgram(G_FUNC(GBL_StartFrame)); //SV_CheckAllEnts (); @@ -1235,7 +1235,7 @@ void SV_Physics(void) if(ent->free) continue; - if(pr_global_struct->force_retouch) + if(G_FLOAT(GBL_force_retouch)) { SV_LinkEdict(ent, true); // force retouch even for stationary } @@ -1259,8 +1259,8 @@ void SV_Physics(void) Sys_Error("SV_Physics: bad movetype %" PRIi32 "", (int32_t)ent->v.movetype); } - if(pr_global_struct->force_retouch) - pr_global_struct->force_retouch--; + if(G_FLOAT(GBL_force_retouch)) + G_FLOAT(GBL_force_retouch)--; if(!sv_freezenonclients.value) sv.time += host_frametime; diff --git a/source/world.c b/source/world.c index 2b74fee..e949ba9 100644 --- a/source/world.c +++ b/source/world.c @@ -364,16 +364,16 @@ void SV_TouchLinks(edict_t *ent) || ent->v.absmax[1] < touch->v.absmin[1] || ent->v.absmax[2] < touch->v.absmin[2]) continue; - old_self = pr_global_struct->self; - old_other = pr_global_struct->other; + old_self = G_INT(GBL_self); + old_other = G_INT(GBL_other); - pr_global_struct->self = EDICT_TO_PROG(touch); - pr_global_struct->other = EDICT_TO_PROG(ent); - pr_global_struct->time = sv.time; + G_INT(GBL_self) = EDICT_TO_PROG(touch); + G_INT(GBL_other) = EDICT_TO_PROG(ent); + G_FLOAT(GBL_time) = sv.time; PR_ExecuteProgram(touch->v.touch); - pr_global_struct->self = old_self; - pr_global_struct->other = old_other; + G_INT(GBL_self) = old_self; + G_INT(GBL_other) = old_other; } // free hunk-allocated edicts array