CON stuff

git-svn-id: https://svn.eduke32.com/eduke32@1436 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2009-06-19 01:10:10 +00:00
parent cc58eafd29
commit 64f4c975c2
5 changed files with 3710 additions and 3654 deletions

View file

@ -29,10 +29,6 @@ DEALINGS IN THE SOFTWARE.
#ifndef NEDMALLOC_H #ifndef NEDMALLOC_H
#define NEDMALLOC_H #define NEDMALLOC_H
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(x) x=x
#endif
/* See malloc.c.h for what each function does. /* See malloc.c.h for what each function does.
REPLACE_SYSTEM_ALLOCATOR causes nedalloc's functions to be called malloc, REPLACE_SYSTEM_ALLOCATOR causes nedalloc's functions to be called malloc,

View file

@ -34,7 +34,7 @@ DEALINGS IN THE SOFTWARE.
/*#define FULLSANITYCHECKS*/ /*#define FULLSANITYCHECKS*/
#include "nedmalloc.h" #include "nedmalloc.h"
#ifdef WIN32 #ifdef _WIN32
#include <malloc.h> #include <malloc.h>
#include <stddef.h> #include <stddef.h>
#endif #endif

View file

@ -489,6 +489,7 @@ const char *keyw[] =
"getarraysize", // 343 "getarraysize", // 343
"savenn", // 344 "savenn", // 344
"copy", // 345 "copy", // 345
"<null>", // 346 internal inversion function
"<null>" "<null>"
}; };
@ -1896,6 +1897,24 @@ static int32_t C_GetNextValue(int32_t type)
return 0; // literal value return 0; // literal value
} }
static inline int32_t C_IntPow2(int32_t v)
{
return ((v!=0) && (v&(v-1))==0);
}
static inline uint32_t C_Pow2IntLogBase2(int32_t v)
{
static const uint32_t b[] = {0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0,
0xFF00FF00, 0xFFFF0000};
register uint32_t r = (v & b[0]) != 0;
int32_t i = 4;
for (; i > 0; i--)
r |= ((v & b[i]) != 0) << i;
return r;
}
static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr) static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr)
{ {
switch (C_GetKeyword()) switch (C_GetKeyword())
@ -1904,6 +1923,7 @@ static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr)
case CON_ENDA: case CON_ENDA:
case CON_ENDEVENT: case CON_ENDEVENT:
case CON_ENDS: case CON_ENDS:
case CON_ELSE:
g_scriptPtr = lastScriptPtr + &script[0]; g_scriptPtr = lastScriptPtr + &script[0];
g_ifElseAborted = 1; g_ifElseAborted = 1;
C_ReportError(-1); C_ReportError(-1);
@ -3884,6 +3904,9 @@ static int32_t C_ParseCommand(void)
case CON_SHIFTVARL: case CON_SHIFTVARL:
case CON_SHIFTVARR: case CON_SHIFTVARR:
{
intptr_t *inst = g_scriptPtr-1;
char *tptr = textptr;
// syntax: [rand|add|set]var <var1> <const1> // syntax: [rand|add|set]var <var1> <const1>
// sets var1 to const1 // sets var1 to const1
// adds const1 to var1 (const1 can be negative...) // adds const1 to var1 (const1 can be negative...)
@ -3895,6 +3918,30 @@ static int32_t C_ParseCommand(void)
else C_GetNextVar(); else C_GetNextVar();
C_GetNextValue(LABEL_DEFINE); // the number to check against... C_GetNextValue(LABEL_DEFINE); // the number to check against...
if (tw == CON_DIVVAR || (tw == CON_MULVAR && *(g_scriptPtr-1) > 0))
{
int32_t i = *(g_scriptPtr-1);
j = klabs(*(g_scriptPtr-1));
if (C_IntPow2(j))
{
*inst = ((tw == CON_DIVVAR) ? CON_SHIFTVARR : CON_SHIFTVARL);
*(g_scriptPtr-1) = C_Pow2IntLogBase2(j);
// initprintf("%s:%d: replacing multiply/divide with shift\n",g_szScriptFileName,g_lineNumber);
if (i == j)
return 0;
*g_scriptPtr++ = CON_INV + (g_lineNumber<<12);
textptr = tptr;
C_GetNextVarType(GAMEVAR_READONLY);
C_GetNextValue(LABEL_DEFINE);
g_scriptPtr--;
// initprintf("%s:%d: adding inversion\n",g_szScriptFileName,g_lineNumber);
}
}
}
return 0; return 0;
case CON_WRITEARRAYTOFILE: case CON_WRITEARRAYTOFILE:
case CON_READARRAYFROMFILE: case CON_READARRAYFROMFILE:

View file

@ -903,6 +903,7 @@ enum ScriptKeywords_t
CON_GETARRAYSIZE, // 343 CON_GETARRAYSIZE, // 343
CON_SAVENN, // 344 CON_SAVENN, // 344
CON_COPY, // 345 CON_COPY, // 345
CON_INV, // 346
CON_END CON_END
}; };
#endif #endif

View file

@ -39,7 +39,7 @@ vmstate_t vm;
int32_t g_errorLineNum; int32_t g_errorLineNum;
int32_t g_tw; int32_t g_tw;
static int32_t X_DoExecute(void); static int32_t X_DoExecute(int32_t once);
#include "gamestructures.c" #include "gamestructures.c"
@ -94,7 +94,7 @@ void X_OnEvent(int32_t iEventID, int32_t iActor, int32_t iPlayer, int32_t lDist)
vm.g_killitFlag = 0; vm.g_killitFlag = 0;
while (!X_DoExecute()); X_DoExecute(0);
if (vm.g_killitFlag == 1) if (vm.g_killitFlag == 1)
{ {
@ -645,13 +645,13 @@ static void X_Move(void)
} }
} }
static inline void X_DoConditional(int32_t condition) static inline void __fastcall X_DoConditional(int32_t condition)
{ {
if (condition) if (condition)
{ {
// skip 'else' pointer.. and... // skip 'else' pointer.. and...
insptr+=2; insptr+=2;
X_DoExecute(); X_DoExecute(1);
return; return;
} }
insptr = (intptr_t *) *(insptr+1); insptr = (intptr_t *) *(insptr+1);
@ -660,13 +660,17 @@ static inline void X_DoConditional(int32_t condition)
// else... // else...
// skip 'else' and... // skip 'else' and...
insptr+=2; insptr+=2;
X_DoExecute(); X_DoExecute(1);
} }
} }
static int32_t X_DoExecute(void) static int32_t X_DoExecute(int32_t once)
{ {
int32_t tw = *insptr; int32_t tw;
do
{
tw = *insptr;
if (vm.g_killitFlag + vm.g_killitFlag) return 1; if (vm.g_killitFlag + vm.g_killitFlag) return 1;
@ -1328,14 +1332,14 @@ static int32_t X_DoExecute(void)
intptr_t *tempscrptr=insptr+2; intptr_t *tempscrptr=insptr+2;
insptr = (intptr_t *) *(insptr+1); insptr = (intptr_t *) *(insptr+1);
while (!X_DoExecute()); X_DoExecute(0);
insptr = tempscrptr; insptr = tempscrptr;
} }
break; break;
case CON_LEFTBRACE: case CON_LEFTBRACE:
insptr++; insptr++;
while (!X_DoExecute()); X_DoExecute(0);
break; break;
case CON_MOVE: case CON_MOVE:
@ -1842,7 +1846,7 @@ static int32_t X_DoExecute(void)
insptr=(intptr_t*)(lpCases[lCheckCase*2+1] + &script[0]); insptr=(intptr_t*)(lpCases[lCheckCase*2+1] + &script[0]);
//Bsprintf(g_szBuf,"insptr=%d. ", (int32_t)insptr); //Bsprintf(g_szBuf,"insptr=%d. ", (int32_t)insptr);
//AddLog(g_szBuf); //AddLog(g_szBuf);
while (!X_DoExecute()); X_DoExecute(0);
//AddLog("Done Executing Case"); //AddLog("Done Executing Case");
bMatched=1; bMatched=1;
} }
@ -1855,7 +1859,7 @@ static int32_t X_DoExecute(void)
{ {
//AddLog("No Matching Case: Using Default"); //AddLog("No Matching Case: Using Default");
insptr=(intptr_t*)(*lpDefault + &script[0]); insptr=(intptr_t*)(*lpDefault + &script[0]);
while (!X_DoExecute()); X_DoExecute(0);
} }
else else
{ {
@ -2933,27 +2937,27 @@ static int32_t X_DoExecute(void)
case CON_WACKPLAYER: case CON_WACKPLAYER:
insptr++; insptr++;
P_ForceAngle(g_player[vm.g_p].ps); P_ForceAngle(g_player[vm.g_p].ps);
return 0; break;
case CON_FLASH: case CON_FLASH:
insptr++; insptr++;
sprite[vm.g_i].shade = -127; sprite[vm.g_i].shade = -127;
g_player[vm.g_p].ps->visibility = -127; g_player[vm.g_p].ps->visibility = -127;
lastvisinc = totalclock+32; lastvisinc = totalclock+32;
return 0; break;
case CON_SAVEMAPSTATE: case CON_SAVEMAPSTATE:
if (MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate == NULL) if (MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate == NULL)
MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate = Bcalloc(1,sizeof(mapstate_t)); MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate = Bcalloc(1,sizeof(mapstate_t));
G_SaveMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate); G_SaveMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
insptr++; insptr++;
return 0; break;
case CON_LOADMAPSTATE: case CON_LOADMAPSTATE:
if (MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate) if (MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
G_RestoreMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate); G_RestoreMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
insptr++; insptr++;
return 0; break;
case CON_CLEARMAPSTATE: case CON_CLEARMAPSTATE:
insptr++; insptr++;
@ -2962,18 +2966,18 @@ static int32_t X_DoExecute(void)
if ((j < 0 || j >= MAXVOLUMES*MAXLEVELS) && g_scriptSanityChecks) if ((j < 0 || j >= MAXVOLUMES*MAXLEVELS) && g_scriptSanityChecks)
{ {
OSD_Printf(CON_ERROR "Invalid map number: %d\n",g_errorLineNum,keyw[g_tw],j); OSD_Printf(CON_ERROR "Invalid map number: %d\n",g_errorLineNum,keyw[g_tw],j);
return 0; break;
} }
if (MapInfo[j].savedstate) if (MapInfo[j].savedstate)
G_FreeMapState(j); G_FreeMapState(j);
} }
return 0; break;
case CON_STOPALLSOUNDS: case CON_STOPALLSOUNDS:
insptr++; insptr++;
if (screenpeek == vm.g_p) if (screenpeek == vm.g_p)
FX_StopAllSounds(); FX_StopAllSounds();
return 0; break;
case CON_IFGAPZL: case CON_IFGAPZL:
insptr++; insptr++;
@ -3506,22 +3510,22 @@ static int32_t X_DoExecute(void)
// gets the value of the per-actor variable varx into VAR // gets the value of the per-actor variable varx into VAR
// <var> <varx> <VAR> // <var> <varx> <VAR>
int32_t lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++; int32_t lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++;
int32_t j=*insptr++; int32_t lVar2=*insptr++;
if ((lSprite < 0 || lSprite >= MAXSPRITES) && g_scriptSanityChecks) if ((lSprite < 0 || lSprite >= MAXSPRITES) && g_scriptSanityChecks)
{ {
OSD_Printf(CON_ERROR "invalid sprite ID %d\n",g_errorLineNum,keyw[g_tw],lSprite); OSD_Printf(CON_ERROR "invalid sprite ID %d\n",g_errorLineNum,keyw[g_tw],lSprite);
if (lVar1 == MAXGAMEVARS) insptr++; if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
if (j == MAXGAMEVARS) insptr++; if (lVar2 == MAXGAMEVARS || lVar2 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
break; break;
} }
if (tw == CON_SETACTORVAR) if (tw == CON_SETACTORVAR)
{ {
Gv_SetVar(lVar1, Gv_GetVarX(j), lSprite, vm.g_p); Gv_SetVar(lVar1, Gv_GetVarX(lVar2), lSprite, vm.g_p);
break; break;
} }
Gv_SetVarX(j, Gv_GetVar(lVar1, lSprite, vm.g_p)); Gv_SetVarX(lVar2, Gv_GetVar(lVar1, lSprite, vm.g_p));
break; break;
} }
@ -3529,11 +3533,10 @@ static int32_t X_DoExecute(void)
case CON_GETPLAYERVAR: case CON_GETPLAYERVAR:
insptr++; insptr++;
{ {
int32_t iPlayer; int32_t iPlayer = vm.g_p;
if (*insptr != g_iThisActorID) if (*insptr != g_iThisActorID)
iPlayer=Gv_GetVarX(*insptr); iPlayer=Gv_GetVarX(*insptr);
else iPlayer = vm.g_p;
insptr++; insptr++;
{ {
@ -3542,6 +3545,8 @@ static int32_t X_DoExecute(void)
if ((iPlayer < 0 || iPlayer >= ud.multimode) && g_scriptSanityChecks) if ((iPlayer < 0 || iPlayer >= ud.multimode) && g_scriptSanityChecks)
{ {
OSD_Printf(CON_ERROR "invalid player ID %d\n",g_errorLineNum,keyw[g_tw],iPlayer); OSD_Printf(CON_ERROR "invalid player ID %d\n",g_errorLineNum,keyw[g_tw],iPlayer);
if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
if (lVar2 == MAXGAMEVARS || lVar2 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
break; break;
} }
@ -3665,7 +3670,7 @@ static int32_t X_DoExecute(void)
if (j<0 || j >= g_gameArrayCount || index >= aGameArrays[j].size || index < 0) if (j<0 || j >= g_gameArrayCount || index >= aGameArrays[j].size || index < 0)
{ {
OSD_Printf(OSD_ERROR "Gv_SetVar(): tried to set invalid array ID (%d) or index out of bounds from sprite %d (%d), player %d\n",j,vm.g_i,sprite[vm.g_i].picnum,vm.g_p); OSD_Printf(OSD_ERROR "Gv_SetVar(): tried to set invalid array ID (%d) or index out of bounds from sprite %d (%d), player %d\n",j,vm.g_i,sprite[vm.g_i].picnum,vm.g_p);
return 0; break;
} }
aGameArrays[j].plValues[index]=value; aGameArrays[j].plValues[index]=value;
break; break;
@ -3770,6 +3775,11 @@ static int32_t X_DoExecute(void)
insptr += 2; insptr += 2;
break; break;
case CON_INV:
Gv_SetVarX(*(insptr+1), -Gv_GetVarX(*(insptr+1)));
insptr += 2;
break;
case CON_MULVAR: case CON_MULVAR:
insptr++; insptr++;
Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) * *(insptr+1)); Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) * *(insptr+1));
@ -4466,6 +4476,8 @@ static int32_t X_DoExecute(void)
"Thank you!"); "Thank you!");
break; break;
} }
}
while(!once);
return 0; return 0;
} }
@ -4492,7 +4504,7 @@ void A_LoadActor(int32_t iActor)
return; return;
} }
while (!X_DoExecute()); X_DoExecute(0);
if (vm.g_killitFlag == 1) if (vm.g_killitFlag == 1)
deletesprite(vm.g_i); deletesprite(vm.g_i);
@ -4541,7 +4553,7 @@ void A_Execute(int32_t iActor,int32_t iPlayer,int32_t lDist)
vm.g_t[3] = 0; vm.g_t[3] = 0;
} }
while (!X_DoExecute()); X_DoExecute(0);
if (vm.g_killitFlag == 1) if (vm.g_killitFlag == 1)
{ {