Patch from hunter_rus to use hash tables for CON compiling

This was sent to me broken, but after some investigation it looks like the only problem was in CON_STATE.  This should speed up CON compilation speed about 500%or so.


git-svn-id: https://svn.eduke32.com/eduke32@1024 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2008-08-25 00:49:12 +00:00
parent 07b71b1139
commit 25adc68899
6 changed files with 574 additions and 414 deletions

View file

@ -1060,6 +1060,30 @@ extern char *mousenames[];
extern char *duke3dgrp, *duke3dgrpstring;
extern char mod_dir[BMAX_PATH];
// Hash functions
struct HASH_item // size is 12/24 bits.
{
const char *string;
int key;
struct HASH_item *next;
};
struct HASH_table
{
int size;
struct HASH_item **items;
};
void HASH_init(struct HASH_table *t);
void HASH_free(struct HASH_table *t);
int HASH_findcase(struct HASH_table *t, const char *s);
int HASH_find(struct HASH_table *t, const char *s);
void HASH_replace(struct HASH_table *t, const char *s, int key);
void HASH_add(struct HASH_table *t, const char *s, int key);
struct HASH_table gamevarH;
struct HASH_table arrayH;
struct HASH_table keywH;
#ifdef __cplusplus
}
#endif

View file

@ -9941,6 +9941,7 @@ static void loadtmb(void)
kclose(fil);
}
void freehash();
static void freeconmem(void)
{
int i;
@ -10008,6 +10009,8 @@ static void freeconmem(void)
Bfree(script);
if (bitptr != NULL)
Bfree(bitptr);
freehash();
}
/*

View file

@ -923,6 +923,248 @@ char *bitptr;
#define BITPTR_DONTFUCKWITHIT 0
#define BITPTR_POINTER 1
/*struct HASH_item // size is 12/24 bits.
{
const char *string;
int key;
struct HASH_item *next;
};
struct HASH_table
{
int size;
struct HASH_item **items;
};
void HASH_init(struct HASH_table *t,int size);
void HASH_free(struct HASH_table *t);
int HASH_findcase(struct HASH_table *t, const char *s);
int HASH_find(struct HASH_table *t, const char *s);
void HASH_replace(struct HASH_table *t, const char *s, int key);
void HASH_add(struct HASH_table *t, const char *s, int key);
*/
void HASH_init(struct HASH_table *t)
{
HASH_free(t);
t->items=Bcalloc(1,t->size * sizeof(struct HASH_item));
Bmemset(t->items,0,t->size * sizeof(struct HASH_item));
}
void HASH_free(struct HASH_table *t)
{
struct HASH_item *cur, *tmp;
int i;
int num;
if (t->items==NULL)return;
initprintf("*free\n");
i=t->size-1;
do
{
cur=t->items[i];
num=0;
while (cur)
{
tmp=cur;
cur=cur->next;
// initprintf("Free %4d '%s'\n",tmp->key,(tmp->string)?tmp->string:".");
Bfree(tmp);
num++;
}
// initprintf("Bucket #%4d: %3d\n",i,num);
}
while (--i>=0);
Bfree(t->items);
t->items=0;
}
inline int HASH_getcode(const char *s)
{
int i=0, fact=1;
while (*s)
{
i+=*s;
i+=1<<fact;
s++;
}
return i;
}
void HASH_add(struct HASH_table *t, const char *s, int key)
{
struct HASH_item *cur, *prev=NULL;
int code;
if (!s)return;
if (t->items==NULL) {initprintf("HASH_add: not initalized\n");return;}
code=HASH_getcode(s)%t->size;
cur=t->items[code];
if (!cur)
{
cur=Bcalloc(1,sizeof(struct HASH_item));
cur->string=s;
cur->key=key;
cur->next=NULL;
t->items[code]=cur;
return;
}
do
{
if (Bstrcmp(s,cur->string)==0)return;
prev=cur;
cur=cur->next;
}
while (cur);
cur=Bcalloc(1,sizeof(struct HASH_item));
cur->string=s;
cur->key=key;
cur->next=NULL;
prev->next=cur;
}
void HASH_replace(struct HASH_table *t, const char *s, int key)
{
struct HASH_item *cur, *prev=NULL;
int code;
if (t->items==NULL) {initprintf("HASH_add: not initalized\n");return;}
code=HASH_getcode(s)%t->size;
cur=t->items[code];
if (!cur)
{
cur=Bcalloc(1,sizeof(struct HASH_item));
cur->string=s;
cur->key=key;
cur->next=NULL;
t->items[code]=cur;
return;
}
do
{
if (Bstrcmp(s,cur->string)==0)
{
cur->key=key;
return;
}
prev=cur;
cur=cur->next;
}
while (cur);
cur=Bcalloc(1,sizeof(struct HASH_item));
cur->string=s;
cur->key=key;
cur->next=NULL;
prev->next=cur;
}
int HASH_find(struct HASH_table *t, const char *s)
{
struct HASH_item *cur;
// initprintf("{");
if (t->items==NULL) {initprintf("HASH_findyy: not initalized\n");return -1;}
cur=t->items[HASH_getcode(s)%t->size];
while (cur)
{
if (Bstrcmp(s,cur->string)==0)return cur->key;
cur=cur->next;
}
// initprintf("}");
return -1;
}
int HASH_findcase(struct HASH_table *t, const char *s)
{
struct HASH_item *cur;
// initprintf("{");
if (t->items==NULL) {initprintf("HASH_findcase: not initalized\n");return -1;}
cur=t->items[HASH_getcode(s)%t->size];
while (cur)
{
if (Bstrcasecmp(s,cur->string)==0)return cur->key;
cur=cur->next;
}
// initprintf("}");
return -1;
}
struct HASH_table gamevarH ={8096,NULL};
struct HASH_table arrayH ={2096,NULL};
struct HASH_table labelH ={8096,NULL};
struct HASH_table keywH ={ 800,NULL};
struct HASH_table sectorH ={ 200,NULL};
struct HASH_table wallH ={ 200,NULL};
struct HASH_table userdefH ={ 200,NULL};
struct HASH_table projectileH ={ 500,NULL};
struct HASH_table playerH ={ 500,NULL};
struct HASH_table inputH ={ 100,NULL};
struct HASH_table actorH ={ 500,NULL};
struct HASH_table tspriteH ={ 400,NULL};
void inithash()
{
int i;
HASH_init(&gamevarH);
HASH_init(&arrayH);
HASH_init(&labelH);
HASH_init(&keywH);
for (i=NUMKEYWORDS-1;i>=0;i--)
HASH_add(&keywH,keyw[i],i);
HASH_init(&sectorH);
for (i=0;sectorlabels[i].lId >=0 ; i++)
HASH_add(&sectorH,sectorlabels[i].name,i);
HASH_init(&wallH);
for (i=0;walllabels[i].lId >=0 ; i++)
HASH_add(&wallH,walllabels[i].name,i);
HASH_init(&userdefH);
for (i=0;userdefslabels[i].lId >=0 ; i++)
HASH_add(&userdefH,userdefslabels[i].name,i);
HASH_init(&projectileH);
for (i=0;projectilelabels[i].lId >=0 ; i++)
HASH_add(&projectileH,projectilelabels[i].name,i);
HASH_init(&playerH);
for (i=0;playerlabels[i].lId >=0 ; i++)
HASH_add(&playerH,playerlabels[i].name,i);
HASH_init(&inputH);
for (i=0;inputlabels[i].lId >=0 ; i++)
HASH_add(&inputH,inputlabels[i].name,i);
HASH_init(&actorH);
for (i=0;actorlabels[i].lId >=0 ; i++)
HASH_add(&actorH,actorlabels[i].name,i);
HASH_init(&tspriteH);
for (i=0;tsprlabels[i].lId >=0 ; i++)
HASH_add(&tspriteH,tsprlabels[i].name,i);
}
void freehash()
{
HASH_free(&gamevarH);
HASH_free(&arrayH);
HASH_free(&labelH);
HASH_free(&keywH);
HASH_free(&sectorH);
HASH_free(&wallH);
HASH_free(&userdefH);
HASH_free(&projectileH);
HASH_free(&playerH);
HASH_free(&inputH);
HASH_free(&actorH);
HASH_free(&tspriteH);
}
static int increasescriptsize(int size)
{
intptr_t oscriptptr = (unsigned)(scriptptr-script);
@ -1281,37 +1523,13 @@ void AddLog(const char *psz, ...)
}
#endif
static int GetDefID(const char *szGameLabel)
inline static int GetDefID(const char *szGameLabel)
{
int i;
for (i=0;i<iGameVarCount;i++)
{
if (aGameVars[i].szLabel != NULL)
{
if (Bstrcmp(szGameLabel, aGameVars[i].szLabel) == 0)
{
return i;
return HASH_find(&gamevarH,szGameLabel);
}
}
}
return -1;
}
static int GetADefID(const char *szGameLabel)
inline static int GetADefID(const char *szGameLabel)
{
int i;
// initprintf("iGameArrayCount is %i\n",iGameArrayCount);
for (i=0;i<iGameArrayCount;i++)
{
if (aGameArrays[i].szLabel != NULL)
{
if (Bstrcmp(szGameLabel, aGameArrays[i].szLabel) == 0)
{
return i;
}
}
}
// initprintf("game array %s not found\n",szGameLabel);
return -1;
return HASH_find(&arrayH,szGameLabel);
}
static int ispecial(char c)
{
@ -1332,40 +1550,25 @@ static inline int isaltok(char c)
return (isalnum(c) || c == '{' || c == '}' || c == '/' || c == '*' || c == '-' || c == '_' || c == '.');
}
static int getlabelid(const memberlabel_t *pLabel, const char *psz)
inline static int getlabelid(const memberlabel_t *pLabel, struct HASH_table *tH, const char *psz)
{
// find the label psz in the table pLabel.
// returns the ID for the label, or -1
int l=-1;
int i;
for (i=0;pLabel[i].lId >=0 ; i++)
{
if (!Bstrcasecmp(pLabel[i].name,psz))
{
l= pLabel[i].lId;
break; // stop for loop
}
}
l = HASH_findcase(tH,psz);
if (l>=0) l= pLabel[l].lId;
return l;
}
static int getlabeloffset(const memberlabel_t *pLabel, const char *psz)
inline static int getlabeloffset(struct HASH_table *tH, const char *psz)
{
// find the label psz in the table pLabel.
// returns the offset in the array for the label, or -1
int i;
for (i=0;pLabel[i].lId >=0 ; i++)
{
if (!Bstrcasecmp(pLabel[i].name,psz))
{
// printf("Label has flags of %02X\n",pLabel[i].flags);
return i;
}
}
return -1;
return HASH_findcase(tH,psz);
}
static void getlabel(void)
@ -1414,11 +1617,7 @@ static int keyword(void)
i++;
}
tempbuf[i] = 0;
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(tempbuf,keyw[i]) == 0)
return i;
return -1;
return HASH_find(&keywH,tempbuf);
}
static int transword(void) //Returns its code #
@ -1448,9 +1647,8 @@ static int transword(void) //Returns its code #
}
tempbuf[l] = 0;
for (i=0;i<NUMKEYWORDS;i++)
{
if (Bstrcmp(tempbuf,keyw[i]) == 0)
i = HASH_find(&keywH,tempbuf);
if (i>=0)
{
*scriptptr = i + (line_number<<12);
bitptr[(scriptptr-script)] = BITPTR_DONTFUCKWITHIT;
@ -1460,7 +1658,6 @@ static int transword(void) //Returns its code #
initprintf("%s:%d: debug: translating keyword `%s'.\n",compilefile,line_number,keyw[i]);
return i;
}
}
textptr += l;
@ -1517,9 +1714,7 @@ static void transvartype(int type)
}
getlabel();
if (!nokeywordcheck)
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (!nokeywordcheck && HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
@ -1568,9 +1763,10 @@ static void transvartype(int type)
{
//try looking for a define instead
Bstrcpy(tempbuf,label+(labelcnt<<6));
for (i=labelcnt-1;i>=0;i--)
i = HASH_find(&labelH,tempbuf);
if (i>=0)
{
if (Bstrcmp(tempbuf,label+(i<<6)) == 0 && (labeltype[i] & LABEL_DEFINE))
if (labeltype[i] & LABEL_DEFINE)
{
if (!(error || warning) && g_ScriptDebug)
initprintf("%s:%d: debug: accepted defined label `%s' instead of gamevar.\n",compilefile,line_number,label+(i<<6));
@ -1654,18 +1850,15 @@ static int transnum(int type)
}
tempbuf[l] = 0;
if (!nokeywordcheck)
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (!nokeywordcheck && HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
textptr+=l;
}
for (i=labelcnt-1;i>=0;i--)
{
if (!Bstrcmp(tempbuf,label+(i<<6)))
i = HASH_find(&labelH,tempbuf);
if (i>=0)
{
char *el,*gl;
@ -1695,7 +1888,6 @@ static int transnum(int type)
Bfree(gl);
return -1; // valid label name, but wrong type
}
}
if (isdigit(*textptr) == 0 && *textptr != '-')
{
@ -1804,34 +1996,29 @@ static int parsecommand(void)
parsing_state = 1;
Bsprintf(parsing_item_name,"%s",label+(labelcnt<<6));
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labelcnt++;
return 0;
}
getlabel();
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
for (j=0;j<labelcnt;j++)
{
if (Bstrcmp(label+(j<<6),label+(labelcnt<<6)) == 0)
j = HASH_find(&labelH,label+(labelcnt<<6));
if (j>=0)
{
if (labeltype[j] & LABEL_STATE)
{
@ -1841,7 +2028,8 @@ static int parsecommand(void)
if (labelcode[j] >= (intptr_t)&script[0] && labelcode[j] < (intptr_t)&script[g_ScriptSize])
bitptr[(scriptptr-script)] = BITPTR_POINTER;
else bitptr[(scriptptr-script)] = BITPTR_DONTFUCKWITHIT;
break;
scriptptr++;
return 0;
}
else
{
@ -1854,8 +2042,7 @@ static int parsecommand(void)
return 0; // valid label name, but wrong type
}
}
}
if (j==labelcnt)
else
{
ReportError(-1);
initprintf("%s:%d: error: state `%s' not found.\n",compilefile,line_number,label+(labelcnt<<6));
@ -1942,7 +2129,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabeloffset(projectilelabels,label+(labelcnt<<6));
lLabelID=getlabeloffset(&projectileH,label+(labelcnt<<6));
//printf("LabelID is %d\n",lLabelID);
if (lLabelID == -1)
{
@ -1994,8 +2181,7 @@ static int parsecommand(void)
//printf("Got Label '%.20s'\n",textptr);
// Check to see it's already defined
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
@ -2054,23 +2240,18 @@ static int parsecommand(void)
//printf("Got Label '%.20s'\n",textptr);
// Check to see it's already defined
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
transnum(LABEL_DEFINE);
@ -2087,36 +2268,28 @@ static int parsecommand(void)
//printf("Got label. '%.20s'\n",textptr);
// Check to see it's already defined
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
for (i=labelcnt-1;i>=0;i--)
{
if (Bstrcmp(label+(labelcnt<<6),label+(i<<6)) == 0 /* && (labeltype[i] & LABEL_DEFINE) */)
i = HASH_find(&labelH,label+(labelcnt<<6));
if (i>=0)
{
if (i >= defaultlabelcnt)
{
warning++;
ReportError(WARNING_DUPLICATEDEFINITION);
}
break;
}
}
//printf("Translating. '%.20s'\n",textptr);
@ -2125,6 +2298,7 @@ static int parsecommand(void)
if (i == -1)
{
// printf("Defining Definition '%s' to be '%d'\n",label+(labelcnt<<6),*(scriptptr-1));
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labeltype[labelcnt] = LABEL_DEFINE;
labelcode[labelcnt++] = *(scriptptr-1);
if (*(scriptptr-1) >= 0 && *(scriptptr-1) < MAXTILES && dynamicremap)
@ -2183,34 +2357,29 @@ static int parsecommand(void)
getlabel();
// Check to see it's already defined
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
for (i=labelcnt-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),label+(i<<6)) == 0 /* && (labeltype[i] & LABEL_MOVE) */)
i = HASH_find(&labelH,label+(labelcnt<<6));
if (i>=0)
{
warning++;
initprintf("%s:%d: warning: duplicate move `%s' ignored.\n",compilefile,line_number,label+(labelcnt<<6));
break;
}
if (i == -1)
{
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labeltype[labelcnt] = LABEL_MOVE;
labelcode[labelcnt++] = (intptr_t) scriptptr;
}
@ -2387,36 +2556,31 @@ static int parsecommand(void)
scriptptr--;
getlabel();
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
for (i=labelcnt-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),label+(i<<6)) == 0 /* && (labeltype[i] & LABEL_AI) */)
i = HASH_find(&labelH,label+(labelcnt<<6));
if (i>=0)
{
warning++;
initprintf("%s:%d: warning: duplicate ai `%s' ignored.\n",compilefile,line_number,label+(labelcnt<<6));
break;
}
if (i == -1)
{
labeltype[labelcnt] = LABEL_AI;
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labelcode[labelcnt++] = (intptr_t) scriptptr;
}
@ -2469,37 +2633,32 @@ static int parsecommand(void)
getlabel();
// Check to see it's already defined
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
return 0;
}
for (i=iGameVarCount-1;i>=0;i--)
{
if (aGameVars[i].szLabel)
if (Bstrcmp(label+(labelcnt<<6),aGameVars[i].szLabel) == 0)
i = HASH_find(&gamevarH,label+(labelcnt<<6));
if (i>=0)
{
// warning++;
ReportError(WARNING_NAMEMATCHESVAR);
break;
}
}
for (i=labelcnt-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),label+(i<<6)) == 0 /* && (labeltype[i] & LABEL_ACTION) */)
i = HASH_find(&labelH,label+(labelcnt<<6));
if (i>=0)
{
warning++;
initprintf("%s:%d: warning: duplicate action `%s' ignored.\n",compilefile,line_number,label+(labelcnt<<6));
break;
}
if (i == -1)
{
labeltype[labelcnt] = LABEL_ACTION;
labelcode[labelcnt] = (intptr_t) scriptptr;
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labelcnt++;
}
@ -2929,7 +3088,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabelid(sectorlabels,label+(labelcnt<<6));
lLabelID=getlabelid(sectorlabels,&sectorH,label+(labelcnt<<6));
if (lLabelID == -1)
{
@ -3061,7 +3220,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabelid(walllabels,label+(labelcnt<<6));
lLabelID=getlabelid(walllabels,&wallH,label+(labelcnt<<6));
if (lLabelID == -1)
{
@ -3125,7 +3284,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabeloffset(playerlabels,label+(labelcnt<<6));
lLabelID=getlabeloffset(&playerH,label+(labelcnt<<6));
//printf("LabelID is %d\n",lLabelID);
if (lLabelID == -1)
{
@ -3203,7 +3362,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabeloffset(inputlabels,label+(labelcnt<<6));
lLabelID=getlabeloffset(&inputH,label+(labelcnt<<6));
//printf("LabelID is %d\n",lLabelID);
if (lLabelID == -1)
{
@ -3254,7 +3413,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabelid(userdefslabels,label+(labelcnt<<6));
lLabelID=getlabelid(userdefslabels,&userdefH,label+(labelcnt<<6));
if (lLabelID == -1)
{
@ -3342,8 +3501,7 @@ static int parsecommand(void)
//printf("found label of '%s'\n", label+(labelcnt<<6));
// Check to see if it's a keyword
for (i=NUMKEYWORDS-1;i>=0;i--)
if (Bstrcmp(label+(labelcnt<<6),keyw[i]) == 0)
if (HASH_find(&keywH,label+(labelcnt<<6))>=0)
{
error++;
ReportError(ERROR_ISAKEYWORD);
@ -3454,7 +3612,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabeloffset(actorlabels,label+(labelcnt<<6));
lLabelID=getlabeloffset(&actorH,label+(labelcnt<<6));
//printf("LabelID is %d\n",lLabelID);
if (lLabelID == -1)
{
@ -3536,7 +3694,7 @@ static int parsecommand(void)
getlabel();
//printf("found xxx label of '%s'\n", label+(labelcnt<<6));
lLabelID=getlabeloffset(tsprlabels,label+(labelcnt<<6));
lLabelID=getlabeloffset(&tspriteH,label+(labelcnt<<6));
//printf("LabelID is %d\n",lLabelID);
if (lLabelID == -1)
{
@ -5295,6 +5453,7 @@ static void AddDefinition(const char *lLabel,int lValue,int lType)
{
Bstrcpy(label+(labelcnt<<6),lLabel);
labeltype[labelcnt] = lType;
HASH_add(&labelH,label+(labelcnt<<6),labelcnt);
labelcode[labelcnt++] = lValue;
defaultlabelcnt++;
}
@ -5468,6 +5627,7 @@ void loadefs(const char *filenam)
clearbuf(apScriptGameEvent,MAXGAMEEVENTS,0L);
inithash();
InitGameVars();
InitProjectiles();

View file

@ -50,6 +50,8 @@ static void FreeGameVars(void) /* called from ReadGameVars() and ResetGameVars()
aGameArrays[i].bReset=1;
}
iGameVarCount=iGameArrayCount=0;
HASH_init(&gamevarH);
HASH_init(&arrayH);
return;
}
@ -84,6 +86,8 @@ static void ClearGameVars(void)
aGameArrays[i].bReset=1;
}
iGameVarCount=iGameArrayCount=0;
HASH_init(&gamevarH);
HASH_init(&arrayH);
return;
}
@ -107,6 +111,7 @@ int ReadGameVars(int fil)
if (kdfread(&(aGameVars[i]),sizeof(gamevar_t),1,fil) != 1) goto corrupt;
aGameVars[i].szLabel=Bcalloc(MAXVARLABEL,sizeof(char));
if (kdfread(aGameVars[i].szLabel,sizeof(char) * MAXVARLABEL, 1, fil) != 1) goto corrupt;
HASH_add(&gamevarH,aGameVars[i].szLabel,i);
}
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
// AddLog(g_szBuf);
@ -152,6 +157,7 @@ int ReadGameVars(int fil)
if (kdfread(&(aGameArrays[i]),sizeof(gamearray_t),1,fil) != 1) goto corrupt;
aGameArrays[i].szLabel=Bcalloc(MAXARRAYLABEL,sizeof(char));
if (kdfread(aGameArrays[i].szLabel,sizeof(char) * MAXARRAYLABEL, 1, fil) != 1) goto corrupt;
HASH_add(&arrayH,aGameArrays[i].szLabel,i);
}
// Bsprintf(g_szBuf,"CP:%s %d",__FILE__,__LINE__);
// AddLog(g_szBuf);
@ -417,20 +423,14 @@ int AddGameArray(const char *pszLabel, int asize)
initprintf("%s:%d: error: array name `%s' exceeds limit of %d characters.\n",compilefile,line_number,pszLabel, MAXARRAYLABEL);
return 0;
}
for (i=0;i<iGameArrayCount;i++)
{
if (aGameVars[i].szLabel != NULL && !aGameArrays[i].bReset)
{
if (Bstrcmp(pszLabel,aGameArrays[i].szLabel) == 0)
if (HASH_find(&arrayH,pszLabel)>=0 && !aGameArrays[i].bReset)
{
// found it it's a duplicate in error
warning++;
ReportError(WARNING_DUPLICATEDEFINITION);
return 0;
}
}
}
i = iGameArrayCount;
if (i < MAXGAMEARRAYS)
{
if (aGameArrays[i].szLabel == NULL)
@ -441,6 +441,7 @@ int AddGameArray(const char *pszLabel, int asize)
aGameArrays[i].size=asize;
aGameVars[i].bReset=0;
iGameArrayCount++;
HASH_add(&arrayH,aGameArrays[i].szLabel,i);
return 1;
}
return 0;
@ -523,6 +524,7 @@ int AddGameVar(const char *pszLabel, int lValue, unsigned int dwFlags)
if (i==iGameVarCount)
{
// we're adding a new one.
HASH_replace(&gamevarH,aGameVars[i].szLabel,i);
iGameVarCount++;
}
if (aGameVars[i].plValues && !(aGameVars[i].dwFlags & GAMEVAR_FLAG_SYSTEM))
@ -566,21 +568,9 @@ void ResetActorGameVars(int iActor)
}
}
static int GetGameID(const char *szGameLabel)
inline static int GetGameID(const char *szGameLabel)
{
int i;
for (i=0;i<iGameVarCount;i++)
{
if (aGameVars[i].szLabel != NULL)
{
if (Bstrcmp(szGameLabel, aGameVars[i].szLabel) == 0)
{
return i;
}
}
}
return -1;
return HASH_find(&gamevarH,szGameLabel);
}
int GetGameVarID(int id, int iActor, int iPlayer)
@ -732,29 +722,18 @@ void SetGameVarID(int id, int lValue, int iActor, int iPlayer)
int GetGameVar(const char *szGameLabel, int lDefault, int iActor, int iPlayer)
{
int i=0;
for (;i<iGameVarCount;i++)
{
if (aGameVars[i].szLabel != NULL)
{
if (Bstrcmp(szGameLabel, aGameVars[i].szLabel) == 0)
{
i = HASH_find(&gamevarH,szGameLabel);
if (i<0)return lDefault;
return GetGameVarID(i, iActor, iPlayer);
}
}
}
return lDefault;
}
static intptr_t *GetGameValuePtr(const char *szGameLabel)
{
int i=0;
for (;i<iGameVarCount;i++)
{
if (aGameVars[i].szLabel != NULL)
{
if (Bstrcmp(szGameLabel, aGameVars[i].szLabel) == 0)
{
i = HASH_find(&gamevarH,szGameLabel);
if (i<0)return NULL;
if (aGameVars[i].dwFlags & (GAMEVAR_FLAG_PERACTOR | GAMEVAR_FLAG_PERPLAYER))
{
if (!aGameVars[i].plValues)
@ -765,12 +744,6 @@ static intptr_t *GetGameValuePtr(const char *szGameLabel)
}
return &(aGameVars[i].lValue);
}
}
}
//Bsprintf(g_szBuf,"Could not find value '%s'\n",szGameLabel);
//AddLog(g_szBuf);
return NULL;
}
void ResetSystemDefaults(void)
{

View file

@ -289,7 +289,7 @@ static int getsound(unsigned int num)
if (fp == -1)fp = kopen4loadfrommod(g_sounds[num].filename,loadfromgrouponly);
if (fp == -1)
{
// initprintf("Sound '%s' not found\n",g_sounds[num].filename);
initprintf("Sound '%s' not found\n",g_sounds[num].filename);
return 0;
}