make progs not a pointer
parent
c47de412bd
commit
0870dfba2e
|
@ -569,6 +569,64 @@ static float FloatNoSwap(float f)
|
|||
return f;
|
||||
}
|
||||
|
||||
int16_t ReadBigShort(byte *bytes)
|
||||
{
|
||||
int16_t v;
|
||||
v = bytes[1];
|
||||
v |= bytes[0] << 8;
|
||||
return v;
|
||||
}
|
||||
|
||||
int32_t ReadBigLong(byte *bytes)
|
||||
{
|
||||
int32_t v;
|
||||
v = bytes[3];
|
||||
v |= bytes[2] << 8;
|
||||
v |= bytes[1] << 16;
|
||||
v |= bytes[0] << 24;
|
||||
return v;
|
||||
}
|
||||
|
||||
float ReadBigFloat(byte *bytes)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
} data;
|
||||
data.i = ReadBigLong(bytes);
|
||||
return data.f;
|
||||
}
|
||||
|
||||
int16_t ReadLittleShort(byte *bytes)
|
||||
{
|
||||
int16_t v;
|
||||
v = bytes[0];
|
||||
v |= bytes[1] << 8;
|
||||
return v;
|
||||
}
|
||||
|
||||
int32_t ReadLittleLong(byte *bytes)
|
||||
{
|
||||
int32_t v;
|
||||
v = bytes[0];
|
||||
v |= bytes[1] << 8;
|
||||
v |= bytes[2] << 16;
|
||||
v |= bytes[3] << 24;
|
||||
return v;
|
||||
}
|
||||
|
||||
float ReadLittleFloat(byte *bytes)
|
||||
{
|
||||
union
|
||||
{
|
||||
float f;
|
||||
uint32_t i;
|
||||
} data;
|
||||
data.i = ReadLittleLong(bytes);
|
||||
return data.f;
|
||||
}
|
||||
|
||||
/*
|
||||
==============================================================================
|
||||
|
||||
|
|
|
@ -74,6 +74,14 @@ extern int16_t (*LittleShort)(int16_t l);
|
|||
extern int32_t (*LittleLong)(int32_t l);
|
||||
extern float (*LittleFloat)(float l);
|
||||
|
||||
int16_t ReadBigShort(byte *bytes);
|
||||
int32_t ReadBigLong(byte *bytes);
|
||||
float ReadBigFloat(byte *bytes);
|
||||
|
||||
int16_t ReadLittleShort(byte *bytes);
|
||||
int32_t ReadLittleLong(byte *bytes);
|
||||
float ReadLittleFloat(byte *bytes);
|
||||
|
||||
//============================================================================
|
||||
|
||||
void MSG_WriteChar(sizebuf_t *sb, int32_t c);
|
||||
|
|
|
@ -1241,7 +1241,7 @@ void Host_Loadgame_f(void)
|
|||
if(entnum < sv.num_edicts)
|
||||
{
|
||||
ent->free = false;
|
||||
memset(&ent->v, 0, progs->entityfields * 4);
|
||||
memset(&ent->v, 0, progs.entityfields * 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1655,7 +1655,7 @@ void Host_Spawn_f(void)
|
|||
// set up the edict
|
||||
ent = host_client->edict;
|
||||
|
||||
memset(&ent->v, 0, progs->entityfields * 4);
|
||||
memset(&ent->v, 0, progs.entityfields * 4);
|
||||
ent->v.colormap = NUM_FOR_EDICT(ent);
|
||||
ent->v.team = (host_client->colors & 15) + 1;
|
||||
ent->v.netname = PR_SetEngineString(host_client->name);
|
||||
|
|
|
@ -687,7 +687,7 @@ static void PF_traceline(void)
|
|||
nomonsters = G_FLOAT(OFS_PARM2);
|
||||
ent = G_EDICT(OFS_PARM3);
|
||||
|
||||
/* FIXME FIXME FIXME: Why do we hit this with certain progs.dat ?? */
|
||||
/* FIXME FIXME FIXME: Why do we hit this?? */
|
||||
if(developer.value)
|
||||
{
|
||||
if(isnan(v1[0]) || isnan(v1[1]) || isnan(v1[2]) ||
|
||||
|
@ -1181,7 +1181,7 @@ static void PF_walkmove(void)
|
|||
move[1] = sin(yaw) * dist;
|
||||
move[2] = 0;
|
||||
|
||||
// save program state, because SV_movestep may call other progs
|
||||
// save program state, because SV_movestep may call other functions
|
||||
oldf = pr_xfunction;
|
||||
oldself = pr_global_struct->self;
|
||||
|
||||
|
@ -1431,7 +1431,7 @@ static void PF_aim(void)
|
|||
==============
|
||||
PF_changeyaw
|
||||
|
||||
This was a major timewaster in progs, so it was converted to C
|
||||
This was a major timewaster so it was converted to C
|
||||
==============
|
||||
*/
|
||||
void PF_changeyaw(void)
|
||||
|
|
|
@ -23,7 +23,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
#include "q_defs.h"
|
||||
|
||||
dprograms_t *progs;
|
||||
dprograms_t progs;
|
||||
dfunction_t *pr_functions;
|
||||
|
||||
static char *pr_strings;
|
||||
|
@ -94,7 +94,7 @@ Sets everything to NULL
|
|||
*/
|
||||
void ED_ClearEdict(edict_t *e)
|
||||
{
|
||||
memset(&e->v, 0, progs->entityfields * 4);
|
||||
memset(&e->v, 0, progs.entityfields * 4);
|
||||
e->free = false;
|
||||
}
|
||||
|
||||
|
@ -176,7 +176,7 @@ static ddef_t *ED_GlobalAtOfs(int32_t ofs)
|
|||
ddef_t *def;
|
||||
int32_t i;
|
||||
|
||||
for(i = 0; i < progs->numglobaldefs; i++)
|
||||
for(i = 0; i < progs.numglobaldefs; i++)
|
||||
{
|
||||
def = &pr_globaldefs[i];
|
||||
if(def->ofs == ofs)
|
||||
|
@ -195,7 +195,7 @@ static ddef_t *ED_FieldAtOfs(int32_t ofs)
|
|||
ddef_t *def;
|
||||
int32_t i;
|
||||
|
||||
for(i = 0; i < progs->numfielddefs; i++)
|
||||
for(i = 0; i < progs.numfielddefs; i++)
|
||||
{
|
||||
def = &pr_fielddefs[i];
|
||||
if(def->ofs == ofs)
|
||||
|
@ -214,7 +214,7 @@ static ddef_t *ED_FindField(const char *name)
|
|||
ddef_t *def;
|
||||
int32_t i;
|
||||
|
||||
for(i = 0; i < progs->numfielddefs; i++)
|
||||
for(i = 0; i < progs.numfielddefs; i++)
|
||||
{
|
||||
def = &pr_fielddefs[i];
|
||||
if(!strcmp(PR_GetString(def->s_name), name))
|
||||
|
@ -234,7 +234,7 @@ static ddef_t *ED_FindGlobal(const char *name)
|
|||
ddef_t *def;
|
||||
int32_t i;
|
||||
|
||||
for(i = 0; i < progs->numglobaldefs; i++)
|
||||
for(i = 0; i < progs.numglobaldefs; i++)
|
||||
{
|
||||
def = &pr_globaldefs[i];
|
||||
if(!strcmp(PR_GetString(def->s_name), name))
|
||||
|
@ -254,7 +254,7 @@ static dfunction_t *ED_FindFunction(const char *fn_name)
|
|||
dfunction_t *func;
|
||||
int32_t i;
|
||||
|
||||
for(i = 0; i < progs->numfunctions; i++)
|
||||
for(i = 0; i < progs.numfunctions; i++)
|
||||
{
|
||||
func = &pr_functions[i];
|
||||
if(!strcmp(PR_GetString(func->s_name), fn_name))
|
||||
|
@ -479,7 +479,7 @@ void ED_Print(edict_t *ed)
|
|||
}
|
||||
|
||||
Con_SafePrintf("\nEDICT %" PRIi32 ":\n", NUM_FOR_EDICT(ed)); //johnfitz -- was Con_Printf
|
||||
for(i = 1; i < progs->numfielddefs; i++)
|
||||
for(i = 1; i < progs.numfielddefs; i++)
|
||||
{
|
||||
d = &pr_fielddefs[i];
|
||||
name = PR_GetString(d->s_name);
|
||||
|
@ -531,7 +531,7 @@ void ED_Write(FILE *f, edict_t *ed)
|
|||
return;
|
||||
}
|
||||
|
||||
for(i = 1; i < progs->numfielddefs; i++)
|
||||
for(i = 1; i < progs.numfielddefs; i++)
|
||||
{
|
||||
d = &pr_fielddefs[i];
|
||||
name = PR_GetString(d->s_name);
|
||||
|
@ -555,7 +555,7 @@ void ED_Write(FILE *f, edict_t *ed)
|
|||
fprintf(f, "\"%s\"\n", PR_UglyValueString(d->type, (eval_t *)v));
|
||||
}
|
||||
|
||||
//johnfitz -- save entity alpha manually when progs.dat doesn't know about alpha
|
||||
//johnfitz -- save entity alpha manually when program doesn't know about alpha
|
||||
if(!pr_alpha_supported && ed->alpha != ENTALPHA_DEFAULT)
|
||||
fprintf(f, "\"alpha\" \"%f\"\n", ENTALPHA_TOSAVE(ed->alpha));
|
||||
//johnfitz
|
||||
|
@ -670,7 +670,7 @@ void ED_WriteGlobals(FILE *f)
|
|||
int32_t type;
|
||||
|
||||
fprintf(f, "{\n");
|
||||
for(i = 0; i < progs->numglobaldefs; i++)
|
||||
for(i = 0; i < progs.numglobaldefs; i++)
|
||||
{
|
||||
def = &pr_globaldefs[i];
|
||||
type = def->type;
|
||||
|
@ -872,7 +872,7 @@ const char *ED_ParseEdict(const char *data, edict_t *ent)
|
|||
|
||||
// clear it
|
||||
if(ent != sv.edicts) // hack
|
||||
memset(&ent->v, 0, progs->entityfields * 4);
|
||||
memset(&ent->v, 0, progs.entityfields * 4);
|
||||
|
||||
// go through all the dictionary pairs
|
||||
while(1)
|
||||
|
@ -923,7 +923,7 @@ const char *ED_ParseEdict(const char *data, edict_t *ent)
|
|||
if(keyname[0] == '_')
|
||||
continue;
|
||||
|
||||
//johnfitz -- hack to support .alpha even when progs.dat doesn't know about it
|
||||
//johnfitz -- hack to support .alpha even when program doesn't know about it
|
||||
if(!strcmp(keyname, "alpha"))
|
||||
ent->alpha = ENTALPHA_ENCODE(atof(com_token));
|
||||
//johnfitz
|
||||
|
@ -1050,6 +1050,7 @@ PR_LoadProgs
|
|||
*/
|
||||
void PR_LoadProgs(void)
|
||||
{
|
||||
byte *prog_data;
|
||||
int32_t i;
|
||||
|
||||
// flush the non-C variable lookup cache
|
||||
|
@ -1058,46 +1059,66 @@ void PR_LoadProgs(void)
|
|||
|
||||
CRC_Init(&pr_crc);
|
||||
|
||||
progs = (dprograms_t *)COM_LoadHunkFile("progs.dat", NULL);
|
||||
if(!progs)
|
||||
prog_data = COM_LoadHunkFile("progs.dat", NULL);
|
||||
if(!prog_data)
|
||||
Host_Error("PR_LoadProgs: couldn't load progs.dat");
|
||||
Con_DPrintf("Programs occupy %" PRIi32 "K.\n", com_filesize / 1024);
|
||||
|
||||
for(i = 0; i < com_filesize; i++)
|
||||
CRC_ProcessByte(&pr_crc, ((byte *)progs)[i]);
|
||||
CRC_ProcessByte(&pr_crc, prog_data[i]);
|
||||
|
||||
// byte swap the header
|
||||
for(i = 0; i < (int32_t) sizeof(*progs) / 4; i++)
|
||||
((int32_t *)progs)[i] = LittleLong(((int32_t *)progs)[i]);
|
||||
progs.version = ReadLittleLong(&prog_data[4 * 0]);
|
||||
progs.crc = ReadLittleLong(&prog_data[4 * 1]);
|
||||
|
||||
if(progs->version != PROG_VERSION)
|
||||
Host_Error("progs.dat has wrong version number (%" PRIi32 " should be %" PRIi32 ")", progs->version, PROG_VERSION);
|
||||
if(progs->crc != PROGHEADER_CRC)
|
||||
progs.ofs_statements = ReadLittleLong(&prog_data[4 * 2]);
|
||||
progs.numstatements = ReadLittleLong(&prog_data[4 * 3]);
|
||||
|
||||
progs.ofs_globaldefs = ReadLittleLong(&prog_data[4 * 4]);
|
||||
progs.numglobaldefs = ReadLittleLong(&prog_data[4 * 5]);
|
||||
|
||||
progs.ofs_fielddefs = ReadLittleLong(&prog_data[4 * 6]);
|
||||
progs.numfielddefs = ReadLittleLong(&prog_data[4 * 7]);
|
||||
|
||||
progs.ofs_functions = ReadLittleLong(&prog_data[4 * 8]);
|
||||
progs.numfunctions = ReadLittleLong(&prog_data[4 * 9]);
|
||||
|
||||
progs.ofs_strings = ReadLittleLong(&prog_data[4 * 10]);
|
||||
progs.numstrings = ReadLittleLong(&prog_data[4 * 11]);
|
||||
|
||||
progs.ofs_globals = ReadLittleLong(&prog_data[4 * 12]);
|
||||
progs.numglobals = ReadLittleLong(&prog_data[4 * 13]);
|
||||
|
||||
progs.entityfields = ReadLittleLong(&prog_data[4 * 14]);
|
||||
|
||||
if(progs.version != PROG_VERSION)
|
||||
Host_Error("progs.dat has wrong version number (%" PRIi32 " should be %" PRIi32 ")", progs.version, PROG_VERSION);
|
||||
if(progs.crc != PROGHEADER_CRC)
|
||||
Host_Error("progs.dat system vars have been modified, progdefs.h is out of date");
|
||||
|
||||
pr_functions = (dfunction_t *)((byte *)progs + progs->ofs_functions);
|
||||
pr_strings = (char *)progs + progs->ofs_strings;
|
||||
if(progs->ofs_strings + progs->numstrings >= com_filesize)
|
||||
pr_functions = (dfunction_t *)(prog_data + progs.ofs_functions);
|
||||
pr_strings = (char *)prog_data + 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;
|
||||
pr_stringssize = progs.numstrings;
|
||||
if(pr_knownstrings)
|
||||
Z_Free((void *)pr_knownstrings);
|
||||
pr_knownstrings = NULL;
|
||||
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);
|
||||
pr_globaldefs = (ddef_t *)(prog_data + progs.ofs_globaldefs);
|
||||
pr_fielddefs = (ddef_t *)(prog_data + progs.ofs_fielddefs);
|
||||
pr_statements = (dstatement_t *)(prog_data + progs.ofs_statements);
|
||||
|
||||
pr_global_struct = (globalvars_t *)((byte *)progs + progs->ofs_globals);
|
||||
pr_global_struct = (globalvars_t *)(prog_data + progs.ofs_globals);
|
||||
pr_globals = (float *)pr_global_struct;
|
||||
|
||||
// byte swap the lumps
|
||||
for(i = 0; i < progs->numstatements; i++)
|
||||
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);
|
||||
|
@ -1105,7 +1126,7 @@ void PR_LoadProgs(void)
|
|||
pr_statements[i].c = LittleShort(pr_statements[i].c);
|
||||
}
|
||||
|
||||
for(i = 0; i < progs->numfunctions; 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);
|
||||
|
@ -1115,7 +1136,7 @@ void PR_LoadProgs(void)
|
|||
pr_functions[i].locals = LittleLong(pr_functions[i].locals);
|
||||
}
|
||||
|
||||
for(i = 0; i < progs->numglobaldefs; 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);
|
||||
|
@ -1124,7 +1145,7 @@ void PR_LoadProgs(void)
|
|||
|
||||
pr_alpha_supported = false; //johnfitz
|
||||
|
||||
for(i = 0; i < progs->numfielddefs; i++)
|
||||
for(i = 0; i < progs.numfielddefs; i++)
|
||||
{
|
||||
pr_fielddefs[i].type = LittleShort(pr_fielddefs[i].type);
|
||||
if(pr_fielddefs[i].type & DEF_SAVEGLOBAL)
|
||||
|
@ -1132,16 +1153,16 @@ void PR_LoadProgs(void)
|
|||
pr_fielddefs[i].ofs = LittleShort(pr_fielddefs[i].ofs);
|
||||
pr_fielddefs[i].s_name = LittleLong(pr_fielddefs[i].s_name);
|
||||
|
||||
//johnfitz -- detect alpha support in progs.dat
|
||||
//johnfitz -- detect alpha support
|
||||
if(!strcmp(pr_strings + pr_fielddefs[i].s_name, "alpha"))
|
||||
pr_alpha_supported = true;
|
||||
//johnfitz
|
||||
}
|
||||
|
||||
for(i = 0; i < progs->numglobals; i++)
|
||||
for(i = 0; i < progs.numglobals; i++)
|
||||
((int32_t *)pr_globals)[i] = LittleLong(((int32_t *)pr_globals)[i]);
|
||||
|
||||
pr_edict_size = progs->entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t);
|
||||
pr_edict_size = progs.entityfields * 4 + sizeof(edict_t) - sizeof(entvars_t);
|
||||
// round off to next highest whole word address (esp for Alpha)
|
||||
// this ensures that pointers in the engine data area are always
|
||||
// properly aligned
|
||||
|
|
|
@ -227,7 +227,7 @@ void PR_Profile_f(void)
|
|||
{
|
||||
pmax = 0;
|
||||
best = NULL;
|
||||
for(i = 0; i < progs->numfunctions; i++)
|
||||
for(i = 0; i < progs.numfunctions; i++)
|
||||
{
|
||||
f = &pr_functions[i];
|
||||
if(f->profile > pmax)
|
||||
|
@ -363,7 +363,7 @@ void PR_ExecuteProgram(func_t fnum)
|
|||
edict_t *ed;
|
||||
int32_t exitdepth;
|
||||
|
||||
if(!fnum || fnum >= progs->numfunctions)
|
||||
if(!fnum || fnum >= progs.numfunctions)
|
||||
{
|
||||
if(pr_global_struct->self)
|
||||
ED_Print(PROG_TO_EDICT(pr_global_struct->self));
|
||||
|
|
|
@ -59,7 +59,7 @@ typedef struct edict_s
|
|||
|
||||
//============================================================================
|
||||
|
||||
extern dprograms_t *progs;
|
||||
extern dprograms_t progs;
|
||||
extern dfunction_t *pr_functions;
|
||||
extern dstatement_t *pr_statements;
|
||||
extern globalvars_t *pr_global_struct;
|
||||
|
|
|
@ -1438,7 +1438,7 @@ void SV_SpawnServer(const char *server)
|
|||
// load the rest of the entities
|
||||
//
|
||||
ent = EDICT_NUM(0);
|
||||
memset(&ent->v, 0, progs->entityfields * 4);
|
||||
memset(&ent->v, 0, progs.entityfields * 4);
|
||||
ent->free = false;
|
||||
ent->v.model = PR_SetEngineString(sv.worldmodel->name);
|
||||
ent->v.modelindex = 1; // world model
|
||||
|
|
Loading…
Reference in New Issue