some bug fixes.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@936 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2005-04-02 18:00:45 +00:00
parent 94233a33c0
commit 4c9337fd35
8 changed files with 95 additions and 66 deletions

View File

@ -146,7 +146,11 @@ void PR_Configure (progfuncs_t *progfuncs, int addressable_size, int max_progs)
struct globalvars_s *PR_globals (progfuncs_t *progfuncs, progsnum_t pnum)
{
if (pnum < 0)
{
if (!current_progstate)
return NULL; //err.. you've not loaded one yet.
return (struct globalvars_s *)current_progstate->globals;
}
return (struct globalvars_s *)pr_progstate[pnum].globals;
}
@ -162,9 +166,20 @@ func_t PR_FindFunc(progfuncs_t *progfuncs, char *funcname, progsnum_t pnum)
{
dfunction_t *f=NULL;
if (pnum == -2)
if (pnum == PR_ANY)
{
for (pnum = 0; pnum < maxprogs; pnum ++)
for (pnum = 0; pnum < maxprogs; pnum++)
{
if (!pr_progstate[pnum].progs)
continue;
f = ED_FindFunction(progfuncs, funcname, &pnum, pnum);
if (f)
break;
}
}
else if (pnum == PR_ANYBACK) //run backwards
{
for (pnum = maxprogs-1; pnum >= 0; pnum--)
{
if (!pr_progstate[pnum].progs)
continue;
@ -192,7 +207,7 @@ func_t PR_FindFunc(progfuncs_t *progfuncs, char *funcname, progsnum_t pnum)
case 32:
var32 = ED_FindTypeGlobalFromProgs32(progfuncs, funcname, pnum, ev_function); //we must make sure we actually have a function def - 'light' is defined as a field before it is defined as a function.
if (!var32)
return (f - pr_progstate[pnum].functions) | (pnum << 24);;
return (f - pr_progstate[pnum].functions) | (pnum << 24);
return *(int *)&pr_progstate[pnum].globals[var32->ofs];
}
Sys_Error("Error with def size (PR_FindFunc)");

View File

@ -25,8 +25,19 @@ vec3_t vec3_origin;
//int pr_max_edict_size;
//unsigned short pr_crc;
int type_size[9] = {1,sizeof(string_t)/4,1,3,1,1,sizeof(func_t)/4,sizeof(void *)/4, 1};
const int type_size[12] = {1, //void
sizeof(string_t)/4, //string
1, //float
3, //vector
1, //entity
1, //field
sizeof(func_t)/4,//function
sizeof(void *)/4,//pointer
1, //integer
1, //fixme: how big should a variant be?
0, //ev_struct. variable sized.
0 //ev_union. variable sized.
};
fdef_t *ED_FieldAtOfs (progfuncs_t *progfuncs, unsigned int ofs);
pbool ED_ParseEpair (progfuncs_t *progfuncs, void *base, ddefXX_t *key, char *s, int bits);
@ -2011,7 +2022,7 @@ int LoadEnts(progfuncs_t *progfuncs, char *file, float killonspawnflags)
selfvar = (eval_t *)((int *)pr_globals + ED_FindGlobalOfs(progfuncs, "self"));
selfvar->edict = EDICT_TO_PROG(progfuncs, ed);
f = PR_FindFunc(progfuncs, var->string+progfuncs->stringtable, -2);
f = PR_FindFunc(progfuncs, var->string+progfuncs->stringtable, PR_ANYBACK);
if (f)
{
if (CheckSpawn)
@ -2781,13 +2792,18 @@ retry:
for (i = 0; i < pr_progs->numbodylessfuncs; i++)
{
d16 = ED_FindGlobal16(progfuncs, s);
if (!d16)
Sys_Error("Progs requires \"%s\" the external function \"%s\", but the definition was stripped", filename, s);
((int *)glob)[d16->ofs] = PR_FindFunc(progfuncs, s, PR_ANY);
if (!((int *)glob)[d16->ofs])
Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename);
/*
d2 = ED_FindGlobalOfsFromProgs(progfuncs, s, 0, ev_function);
if (!d2)
Sys_Error("Runtime-linked function %s was not found in existing progs", s);
if (!d16)
Sys_Error("Couldn't find def for \"%s\"", s);
Sys_Error("Runtime-linked function %s was not found in primary progs (loading %s)", s, filename);
((int *)glob)[d16->ofs] = (*(func_t *)&pr_progstate[0].globals[*d2]);
*/
s+=strlen(s)+1;
}
}

View File

@ -273,7 +273,7 @@ int NUM_FOR_EDICT(progfuncs_t *progfuncs, struct edict_s *e);
#define E_VECTOR(e,o) (&((float*)&e->v)[o])
#define E_STRING(e,o) (*(string_t *)&((float*)(e+1))[o])
extern int type_size[9];
const extern int type_size[];
extern unsigned short pr_crc;

View File

@ -191,6 +191,7 @@ typedef union eval_s
#define PR_CURRENT -1
#define PR_ANY -2 //not always valid. Use for finding funcs
#define PR_ANYBACK -3
#define PROGSTRUCT_VERSION 2

View File

@ -371,7 +371,7 @@ typedef union QCC_eval_s
union QCC_eval_s *ptr;
} QCC_eval_t;
const extern int type_size[12];
const extern int type_size[];
//extern QCC_def_t *def_for_type[9];
extern QCC_type_t *type_void, *type_string, *type_float, *type_vector, *type_entity, *type_field, *type_function, *type_pointer, *type_integer, *type_variant, *type_floatfield;

View File

@ -3251,7 +3251,7 @@ QCC_def_t *QCC_PR_ParseValue (QCC_type_t *assumeclass)
QCC_PR_ParseError (ERR_UNKNOWNVALUE, "Unknown value \"%s\"", name);
else
{
QCC_PR_ParseWarning (ERR_UNKNOWNVALUE, "Unknown value \"%s\", assuming float.", name);
QCC_PR_ParseWarning (ERR_UNKNOWNVALUE, "Unknown value \"%s\".", name);
}
}
}
@ -6653,7 +6653,7 @@ QCC_def_t *QCC_PR_DummyDef(QCC_type_t *type, char *name, QCC_def_t *scope, int a
{
char array[64];
char newname[256];
int a, i;
int a;
QCC_def_t *def, *first=NULL;
#define KEYWORD(x) if (!STRCMP(name, #x) && keyword_##x) {if (keyword_##x)QCC_PR_ParseWarning(WARN_KEYWORDDISABLED, "\""#x"\" keyword used as variable name%s", keywords_coexist?" - coexisting":" - disabling");keyword_##x=keywords_coexist;}
@ -6761,8 +6761,6 @@ QCC_def_t *QCC_PR_DummyDef(QCC_type_t *type, char *name, QCC_def_t *scope, int a
case ev_function:
sprintf(newname, "%s%s.%s", name, array, parttype->name);
QCC_PR_DummyDef(parttype, newname, scope, 1, ofs + type->size*a +parttype->ofs, false)->initialized = true;
for (i = parttype->num_parms; i>0; i--)
parttype=parttype->next;
break;
case ev_void:
break;
@ -7675,13 +7673,11 @@ void QCC_PR_ParseDefs (char *classname)
def->initialized = 2;
// check for an initialization
if (type->type == ev_function && (pr_scope || !constant))
if (type->type == ev_function && (pr_scope))
{
if ( QCC_PR_CheckToken ("=") )
{
if (def->arraysize>1)
goto lazyfunctiondeclaration;
QCC_PR_ParseError (ERR_INITIALISEDLOCALFUNCTION, "local functions may only be used as pointers");
QCC_PR_ParseError (ERR_INITIALISEDLOCALFUNCTION, "local functions may not be initialised");
}
arraysize = def->arraysize;
@ -7774,7 +7770,6 @@ void QCC_PR_ParseDefs (char *classname)
else if (type->type == ev_function)
{
lazyfunctiondeclaration:
def->constant = constant;
if (QCC_PR_CheckToken("0"))
{
@ -7784,9 +7779,22 @@ lazyfunctiondeclaration:
continue;
}
if (!def->constant && arraysize==1)
{
def->constant = 0;
def->initialized = 1; //fake function
name = QCC_PR_ParseName ();
d = QCC_PR_GetDef (NULL, name, pr_scope, false, 0);
if (!d)
QCC_PR_ParseError(ERR_NOTDEFINED, "%s was not previously defined", name);
G_FUNCTION(def->ofs+i) = G_FUNCTION(d->ofs);
continue;
}
if (arraysize>1)
{
int i;
int i;
def->initialized = 1; //fake function
QCC_PR_Expect ("{");
i = 0;
@ -7825,6 +7833,8 @@ lazyfunctiondeclaration:
QCC_PR_ParseError(ERR_TOOMANYINITIALISERS, "Too many initializers");
continue;
}
if (!def->constant)
QCC_PR_ParseError(0, "Functions must be constant");
def->references++;
pr_scope = def;

View File

@ -4,6 +4,7 @@
#ifdef QCC
#define print printf
#endif
#include "time.h"
#define MEMBERFIELDNAME "__m%s"
@ -65,7 +66,19 @@ QCC_type_t *type_variant;// = {ev_integer/*, &def_integer*/};
QCC_type_t *type_floatfield;// = {ev_field/*, &def_field*/, NULL, &type_float};
#ifdef QCCONLY
const int type_size[12] = {1,1,1,3,1,1,1,1,1, 1, 0,0};
const int type_size[12] = {1, //void
sizeof(string_t)/4, //string
1, //float
3, //vector
1, //entity
1, //field
sizeof(func_t)/4,//function
sizeof(void *)/4,//pointer
1, //integer
1, //fixme: how big should a variant be?
0, //ev_struct. variable sized.
0 //ev_union. variable sized.
};
#endif
/*QCC_def_t def_void = {type_void, "temp"};
@ -1809,31 +1822,6 @@ void QCC_PR_ConditionCompilation(void)
QCC_PR_ParseError(ERR_CONSTANTTOOLONG, "Macro %s too long (%i not %i)", cnst->name, strlen(cnst->value), sizeof(cnst->value));
}
char *daynames[] =
{
"Mon",
"Tue",
"Wed",
"Thu",
"Fri",
"Sat",
"Sun"
};
char *monthnames[] =
{
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
};
int QCC_PR_CheakCompConst(void)
{
char *oldpr_file_p = pr_file_p;
@ -2013,14 +2001,13 @@ int QCC_PR_CheakCompConst(void)
if (!strncmp(pr_file_p, "__TIME__", 8))
{
static char retbuf[256];
#ifdef WIN32
SYSTEMTIME Systime;
GetSystemTime(&Systime);
sprintf(retbuf, "\"%i:%i\"", Systime.wHour, Systime.wMinute);
#else //linux
sprintf(retbuf, "\"unknown time\"");
#endif
static char retbuf[128];
time_t long_time;
time( &long_time );
strftime( retbuf, sizeof(retbuf),
"%R", localtime( &long_time ));
pr_file_p = retbuf;
QCC_PR_Lex(); //translate the macro's value
pr_file_p = oldpr_file_p+8;
@ -2029,15 +2016,15 @@ int QCC_PR_CheakCompConst(void)
}
if (!strncmp(pr_file_p, "__DATE__", 8))
{
static char retbuf[256];
#ifdef WIN32
SYSTEMTIME Systime;
GetSystemTime(&Systime);
//dayname, day, month, year
sprintf(retbuf, "\"%s %i %s %i\"", daynames[Systime.wDayOfWeek], Systime.wDay, monthnames[Systime.wMonth], Systime.wYear);
#else //linux
sprintf(retbuf, "\"unknown date\"");
#endif
static char retbuf[128];
time_t long_time;
time( &long_time );
strftime( retbuf, sizeof(retbuf),
"%a %d %b %Y", localtime( &long_time ));
pr_file_p = retbuf;
QCC_PR_Lex(); //translate the macro's value
pr_file_p = oldpr_file_p+8;

View File

@ -485,7 +485,7 @@ int WriteBodylessFuncs (int handle)
{
if (d->type->type == ev_function && !d->scope)// function parms are ok
{
if (d->initialized != 1)
if (d->initialized != 1 && d->references>0)
{
SafeWrite(handle, d->name, strlen(d->name)+1);
ret++;