mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-31 04:20:42 +00:00
CON stuff
git-svn-id: https://svn.eduke32.com/eduke32@1436 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
cc58eafd29
commit
64f4c975c2
5 changed files with 3710 additions and 3654 deletions
|
@ -29,10 +29,6 @@ DEALINGS IN THE SOFTWARE.
|
|||
#ifndef NEDMALLOC_H
|
||||
#define NEDMALLOC_H
|
||||
|
||||
#ifndef UNREFERENCED_PARAMETER
|
||||
#define UNREFERENCED_PARAMETER(x) x=x
|
||||
#endif
|
||||
|
||||
/* See malloc.c.h for what each function does.
|
||||
|
||||
REPLACE_SYSTEM_ALLOCATOR causes nedalloc's functions to be called malloc,
|
||||
|
|
|
@ -34,7 +34,7 @@ DEALINGS IN THE SOFTWARE.
|
|||
/*#define FULLSANITYCHECKS*/
|
||||
|
||||
#include "nedmalloc.h"
|
||||
#ifdef WIN32
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#include <stddef.h>
|
||||
#endif
|
||||
|
|
|
@ -489,6 +489,7 @@ const char *keyw[] =
|
|||
"getarraysize", // 343
|
||||
"savenn", // 344
|
||||
"copy", // 345
|
||||
"<null>", // 346 internal inversion function
|
||||
"<null>"
|
||||
};
|
||||
|
||||
|
@ -1896,6 +1897,24 @@ static int32_t C_GetNextValue(int32_t type)
|
|||
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)
|
||||
{
|
||||
switch (C_GetKeyword())
|
||||
|
@ -1904,6 +1923,7 @@ static int32_t C_CheckMalformedBranch(intptr_t lastScriptPtr)
|
|||
case CON_ENDA:
|
||||
case CON_ENDEVENT:
|
||||
case CON_ENDS:
|
||||
case CON_ELSE:
|
||||
g_scriptPtr = lastScriptPtr + &script[0];
|
||||
g_ifElseAborted = 1;
|
||||
C_ReportError(-1);
|
||||
|
@ -3884,6 +3904,9 @@ static int32_t C_ParseCommand(void)
|
|||
case CON_SHIFTVARL:
|
||||
case CON_SHIFTVARR:
|
||||
|
||||
{
|
||||
intptr_t *inst = g_scriptPtr-1;
|
||||
char *tptr = textptr;
|
||||
// syntax: [rand|add|set]var <var1> <const1>
|
||||
// sets var1 to const1
|
||||
// adds const1 to var1 (const1 can be negative...)
|
||||
|
@ -3895,6 +3918,30 @@ static int32_t C_ParseCommand(void)
|
|||
else C_GetNextVar();
|
||||
|
||||
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;
|
||||
case CON_WRITEARRAYTOFILE:
|
||||
case CON_READARRAYFROMFILE:
|
||||
|
|
|
@ -903,6 +903,7 @@ enum ScriptKeywords_t
|
|||
CON_GETARRAYSIZE, // 343
|
||||
CON_SAVENN, // 344
|
||||
CON_COPY, // 345
|
||||
CON_INV, // 346
|
||||
CON_END
|
||||
};
|
||||
#endif
|
||||
|
|
|
@ -39,7 +39,7 @@ vmstate_t vm;
|
|||
int32_t g_errorLineNum;
|
||||
int32_t g_tw;
|
||||
|
||||
static int32_t X_DoExecute(void);
|
||||
static int32_t X_DoExecute(int32_t once);
|
||||
|
||||
#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;
|
||||
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
|
||||
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)
|
||||
{
|
||||
// skip 'else' pointer.. and...
|
||||
insptr+=2;
|
||||
X_DoExecute();
|
||||
X_DoExecute(1);
|
||||
return;
|
||||
}
|
||||
insptr = (intptr_t *) *(insptr+1);
|
||||
|
@ -660,13 +660,17 @@ static inline void X_DoConditional(int32_t condition)
|
|||
// else...
|
||||
// skip 'else' and...
|
||||
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;
|
||||
|
||||
|
@ -1328,14 +1332,14 @@ static int32_t X_DoExecute(void)
|
|||
intptr_t *tempscrptr=insptr+2;
|
||||
|
||||
insptr = (intptr_t *) *(insptr+1);
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
insptr = tempscrptr;
|
||||
}
|
||||
break;
|
||||
|
||||
case CON_LEFTBRACE:
|
||||
insptr++;
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
break;
|
||||
|
||||
case CON_MOVE:
|
||||
|
@ -1842,7 +1846,7 @@ static int32_t X_DoExecute(void)
|
|||
insptr=(intptr_t*)(lpCases[lCheckCase*2+1] + &script[0]);
|
||||
//Bsprintf(g_szBuf,"insptr=%d. ", (int32_t)insptr);
|
||||
//AddLog(g_szBuf);
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
//AddLog("Done Executing Case");
|
||||
bMatched=1;
|
||||
}
|
||||
|
@ -1855,7 +1859,7 @@ static int32_t X_DoExecute(void)
|
|||
{
|
||||
//AddLog("No Matching Case: Using Default");
|
||||
insptr=(intptr_t*)(*lpDefault + &script[0]);
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -2933,27 +2937,27 @@ static int32_t X_DoExecute(void)
|
|||
case CON_WACKPLAYER:
|
||||
insptr++;
|
||||
P_ForceAngle(g_player[vm.g_p].ps);
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_FLASH:
|
||||
insptr++;
|
||||
sprite[vm.g_i].shade = -127;
|
||||
g_player[vm.g_p].ps->visibility = -127;
|
||||
lastvisinc = totalclock+32;
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_SAVEMAPSTATE:
|
||||
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));
|
||||
G_SaveMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
|
||||
insptr++;
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_LOADMAPSTATE:
|
||||
if (MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate)
|
||||
G_RestoreMapState(MapInfo[ud.volume_number*MAXLEVELS+ud.level_number].savedstate);
|
||||
insptr++;
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_CLEARMAPSTATE:
|
||||
insptr++;
|
||||
|
@ -2962,18 +2966,18 @@ static int32_t X_DoExecute(void)
|
|||
if ((j < 0 || j >= MAXVOLUMES*MAXLEVELS) && g_scriptSanityChecks)
|
||||
{
|
||||
OSD_Printf(CON_ERROR "Invalid map number: %d\n",g_errorLineNum,keyw[g_tw],j);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
if (MapInfo[j].savedstate)
|
||||
G_FreeMapState(j);
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_STOPALLSOUNDS:
|
||||
insptr++;
|
||||
if (screenpeek == vm.g_p)
|
||||
FX_StopAllSounds();
|
||||
return 0;
|
||||
break;
|
||||
|
||||
case CON_IFGAPZL:
|
||||
insptr++;
|
||||
|
@ -3506,22 +3510,22 @@ static int32_t X_DoExecute(void)
|
|||
// gets the value of the per-actor variable varx into VAR
|
||||
// <var> <varx> <VAR>
|
||||
int32_t lSprite=Gv_GetVarX(*insptr++), lVar1=*insptr++;
|
||||
int32_t j=*insptr++;
|
||||
int32_t lVar2=*insptr++;
|
||||
|
||||
if ((lSprite < 0 || lSprite >= MAXSPRITES) && g_scriptSanityChecks)
|
||||
{
|
||||
OSD_Printf(CON_ERROR "invalid sprite ID %d\n",g_errorLineNum,keyw[g_tw],lSprite);
|
||||
if (lVar1 == MAXGAMEVARS) insptr++;
|
||||
if (j == MAXGAMEVARS) insptr++;
|
||||
if (lVar1 == MAXGAMEVARS || lVar1 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
|
||||
if (lVar2 == MAXGAMEVARS || lVar2 & ((MAXGAMEVARS<<2)|(MAXGAMEVARS<<3))) insptr++;
|
||||
break;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Gv_SetVarX(j, Gv_GetVar(lVar1, lSprite, vm.g_p));
|
||||
Gv_SetVarX(lVar2, Gv_GetVar(lVar1, lSprite, vm.g_p));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3529,11 +3533,10 @@ static int32_t X_DoExecute(void)
|
|||
case CON_GETPLAYERVAR:
|
||||
insptr++;
|
||||
{
|
||||
int32_t iPlayer;
|
||||
int32_t iPlayer = vm.g_p;
|
||||
|
||||
if (*insptr != g_iThisActorID)
|
||||
iPlayer=Gv_GetVarX(*insptr);
|
||||
else iPlayer = vm.g_p;
|
||||
|
||||
insptr++;
|
||||
{
|
||||
|
@ -3542,6 +3545,8 @@ static int32_t X_DoExecute(void)
|
|||
if ((iPlayer < 0 || iPlayer >= ud.multimode) && g_scriptSanityChecks)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -3665,7 +3670,7 @@ static int32_t X_DoExecute(void)
|
|||
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);
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
aGameArrays[j].plValues[index]=value;
|
||||
break;
|
||||
|
@ -3770,6 +3775,11 @@ static int32_t X_DoExecute(void)
|
|||
insptr += 2;
|
||||
break;
|
||||
|
||||
case CON_INV:
|
||||
Gv_SetVarX(*(insptr+1), -Gv_GetVarX(*(insptr+1)));
|
||||
insptr += 2;
|
||||
break;
|
||||
|
||||
case CON_MULVAR:
|
||||
insptr++;
|
||||
Gv_SetVarX(*insptr, Gv_GetVarX(*insptr) * *(insptr+1));
|
||||
|
@ -4466,6 +4476,8 @@ static int32_t X_DoExecute(void)
|
|||
"Thank you!");
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(!once);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -4492,7 +4504,7 @@ void A_LoadActor(int32_t iActor)
|
|||
return;
|
||||
}
|
||||
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
|
||||
if (vm.g_killitFlag == 1)
|
||||
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;
|
||||
}
|
||||
|
||||
while (!X_DoExecute());
|
||||
X_DoExecute(0);
|
||||
|
||||
if (vm.g_killitFlag == 1)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue