- got rid of the old interpreter code.

This commit is contained in:
Christoph Oelckers 2020-05-15 08:04:30 +02:00
parent b9deaba834
commit ed6262e0bf
8 changed files with 50 additions and 372 deletions

View file

@ -40,9 +40,7 @@ BEGIN_DUKE_NS
#define VM_INSTMASK 0xfff
#define VM_DECODE_LINE_NUMBER(xxx) ((int)((xxx) >> 12))
extern intptr_t const * insptr;
extern intptr_t apScriptGameEvent[EVENT_NUMEVENTS];
extern intptr_t apScriptGameEvent[];
extern char g_scriptFileName[BMAX_PATH];
@ -64,24 +62,6 @@ void C_InitQuotes(void);
extern int32_t g_numProjectiles;
typedef struct {
int spriteNum;
int playerNum;
int playerDist;
int flags;
union {
spritetype *pSprite;
uspritetype *pUSprite;
};
int32_t * pData;
DukePlayer_t *pPlayer;
actor_t * pActor;
} vmstate_t;
extern vmstate_t vm;
void G_DoGameStartup(const int32_t *params);
void C_DefineMusic(int volumeNum, int levelNum, const char *fileName);

View file

@ -41,11 +41,12 @@ source as it is released.
BEGIN_DUKE_NS
// curse these global variables for parameter passing...
int g_i, g_p;
int g_x;
int* g_t;
uint8_t killit_flag;
spritetype* g_sp;
static int g_i, g_p;
static int g_x;
static int* g_t;
static uint8_t killit_flag;
static spritetype* g_sp;
static intptr_t* insptr;
int parse(void);
int furthestcanseepoint(int i, spritetype* ts, int* dax, int* day);
@ -56,11 +57,10 @@ void destroyit(int g_i);
void mamaspawn(int g_i);
void forceplayerangle(DukePlayer_t* p);
TArray<int> spritesToDelete; // List of sprites to delete.
static bool killthesprite = false;
void addspritetodelete(int spnum)
{
if (spritesToDelete.Find(spnum) == spritesToDelete.Size()) spritesToDelete.Push(spnum);
killthesprite = true;
}
//---------------------------------------------------------------------------
@ -76,11 +76,7 @@ void parseifelse(int condition)
{
// skip 'else' pointer.. and...
insptr+=2;
#if 0
parse();
#else
VM_Execute(0);
#endif
}
else
{
@ -91,12 +87,7 @@ void parseifelse(int condition)
// skip 'else' and...
insptr+=2;
#if 0
parse();
#else
VM_Execute(0);
#endif
}
}
}
@ -842,11 +833,7 @@ int parse(void)
break;
case concmd_leftbrace:
insptr++;
#if 0
while (1) if (parse()) break;
#else
VM_Execute(1);
#endif
break;
case concmd_move:
g_t[0]=0;
@ -1521,7 +1508,7 @@ int parse(void)
break;
case concmd_ifnosounds:
parseifelse(!A_CheckAnySoundPlaying(vm.spriteNum) );
parseifelse(!A_CheckAnySoundPlaying(g_i) );
break;
case concmd_ifplaybackon: //Twentieth Anniversary World Tour
@ -1537,8 +1524,10 @@ int parse(void)
return 0;
}
void execute(short i,short p,int x)
void execute(int i,int p,int x)
{
if (!G_HaveActor(sprite[i].picnum)) return;
int done;
g_i = i; // Sprite ID
@ -1548,8 +1537,8 @@ void execute(short i,short p,int x)
g_t = &hittype[g_i].temp_data[0]; // Sprite's 'extra' data
#if 1
if (!g_tile[vm.pSprite->picnum].execPtr) return;
insptr = 4 + (g_tile[vm.pSprite->picnum].execPtr);
if (!g_tile[g_sp->picnum].execPtr) return;
insptr = 4 + (g_tile[g_sp->picnum].execPtr);
#else
if( actorscrptr[g_sp->picnum] == 0 ) return;
insptr = 4 + (actorscrptr[g_sp->picnum]);
@ -1580,7 +1569,7 @@ void execute(short i,short p,int x)
g_sp->lotag = 0;
g_t[3] += increment;
}
if (abs(g_t[3]) >= abs(numframes * delay))
if (abs(g_t[3]) >= abs(numframes * increment))
g_t[3] = 0;
}
@ -1593,31 +1582,33 @@ void execute(short i,short p,int x)
// if player was set to squish, first stop that...
if(ps[g_p].actorsqu == g_i)
ps[g_p].actorsqu = -1;
addspritetodelete(g_i);
killthesprite = true;
}
else
{
fi.move(g_i, g_p, g_x);
if (g_sp->statnum == 1)
if (g_sp->statnum == STAT_ACTOR)
{
if (badguy(g_sp))
{
if (g_sp->xrepeat > 60) return;
if (ud.respawn_monsters == 1 && g_sp->extra <= 0) return;
if (g_sp->xrepeat > 60) goto quit;
if (ud.respawn_monsters == 1 && g_sp->extra <= 0) goto quit;
}
else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) return;
else if (ud.respawn_items == 1 && (g_sp->cstat & 32768)) goto quit;
if (hittype[g_i].timetosleep > 1)
hittype[g_i].timetosleep--;
else if (hittype[g_i].timetosleep == 1)
changespritestat(g_i, 2);
changespritestat(g_i, STAT_ZOMBIEACTOR);
}
else if (g_sp->statnum == STAT_STANDABLE)
fi.checktimetosleep(g_i);
}
for (auto i : spritesToDelete) deletesprite(i);
quit:
if (killthesprite) deletesprite(i);
killthesprite = false;
}

View file

@ -66,19 +66,11 @@ static FORCE_INLINE int32_t VM_OnEventWithReturn(int nEventID, int spriteNum, in
extern int32_t ticrandomseed;
extern vmstate_t vm;
extern int32_t g_tw;
extern int32_t g_currentEvent;
extern int32_t g_errorLineNum;
extern uint32_t g_actorCalls[MAXTILES];
extern double g_actorTotalMs[MAXTILES], g_actorMinMs[MAXTILES], g_actorMaxMs[MAXTILES];
void A_Execute(int spriteNum, int playerNum, int playerDist);
inline void execute(int s, int p, int d)
{
A_Execute(s, p, d);
}
void execute(int s, int p, int d);
void makeitfall(int s);
int furthestangle(int spriteNum, int angDiv);
void getglobalz(int s);

View file

@ -52,11 +52,8 @@ int iGameVarCount;
extern int errorcount, warningcount, line_count;
#if 0
intptr_t *actorLoadEventScrptr[MAXTILES];
intptr_t *apScriptGameEvent[MAXGAMEEVENTS];
#endif
//intptr_t *actorLoadEventScrptr[MAXTILES];
intptr_t apScriptGameEvent[MAXGAMEEVENTS];
//---------------------------------------------------------------------------
//

View file

@ -62,12 +62,9 @@ void loadcons(const char* filenam);
void C_Compile(const char *fileName)
{
Bmemset(apScriptGameEvent, 0, sizeof(apScriptGameEvent));
for (int i=0; i<MAXTILES; i++)
{
Bmemset(&g_tile[i], 0, sizeof(tiledata_t));
g_actorMinMs[i] = 1e308;
}
apScript = (intptr_t *)Xcalloc(1, g_scriptSize * sizeof(intptr_t));

View file

@ -39,81 +39,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_DUKE_NS
#if KRANDDEBUG
# define GAMEEXEC_INLINE
# define GAMEEXEC_STATIC
#else
# define GAMEEXEC_INLINE inline
# define GAMEEXEC_STATIC static
#endif
vmstate_t vm;
enum vmflags_t
{
VM_RETURN = 0x00000001,
VM_KILL = 0x00000002,
VM_NOEXECUTE = 0x00000004,
VM_SAFEDELETE = 0x00000008
};
int32_t g_tw;
int32_t g_currentEvent = -1;
int32_t g_errorLineNum;
intptr_t const *insptr;
int32_t g_returnVarID = -1; // var ID of "RETURN"
int32_t g_weaponVarID = -1; // var ID of "WEAPON"
int32_t g_worksLikeVarID = -1; // var ID of "WORKSLIKE"
int32_t g_zRangeVarID = -1; // var ID of "ZRANGE"
int32_t g_angRangeVarID = -1; // var ID of "ANGRANGE"
int32_t g_aimAngleVarID = -1; // var ID of "AUTOAIMANGLE"
// for timing events and actors
uint32_t g_actorCalls[MAXTILES];
double g_actorTotalMs[MAXTILES], g_actorMinMs[MAXTILES], g_actorMaxMs[MAXTILES];
void VM_Execute(native_t loop);
int parse();
#define VM_CONDITIONAL(xxx) \
{ \
if ((xxx) || ((insptr = apScript + *(insptr + 1)) && (((*insptr) & VM_INSTMASK) == concmd_else))) \
{ \
insptr += 2; \
VM_Execute(0); \
} \
}
static void VM_DeleteSprite(int const spriteNum, int const playerNum)
{
if (EDUKE32_PREDICT_FALSE((unsigned) spriteNum >= MAXSPRITES))
return;
// if player was set to squish, first stop that...
if (EDUKE32_PREDICT_FALSE(playerNum >= 0 && g_player[playerNum].ps->actorsqu == spriteNum))
g_player[playerNum].ps->actorsqu = -1;
A_DeleteSprite(spriteNum);
}
intptr_t apScriptGameEvent[EVENT_NUMEVENTS];
static uspritetype dummy_sprite;
static actor_t dummy_actor;
static inline void VM_DummySprite(void)
{
vm.pUSprite = &dummy_sprite;
vm.pActor = &dummy_actor;
vm.pData = &dummy_actor.t_data[0];
}
// verification that the event actually exists happens elsewhere
static FORCE_INLINE int32_t VM_EventInlineInternal__(int const eventNum, int const spriteNum, int const playerNum,
int const playerDist = -1, int32_t returnValue = 0)
{
#if 0
vmstate_t const newVMstate = { spriteNum, playerNum, playerDist, 0,
&sprite[spriteNum&(MAXSPRITES-1)],
&actor[spriteNum&(MAXSPRITES-1)].t_data[0],
@ -143,10 +74,15 @@ static FORCE_INLINE int32_t VM_EventInlineInternal__(int const eventNum, int con
if ((unsigned)playerNum >= (unsigned)g_mostConcurrentPlayers)
vm.pPlayer = g_player[0].ps;
VM_Execute(true);
while (1) if (parse()) break;
if (vm.flags & VM_KILL)
VM_DeleteSprite(vm.spriteNum, vm.playerNum);
if (killit_flag == 1)
{
// if player was set to squish, first stop that...
if (ps[g_p].actorsqu == g_i)
ps[g_p].actorsqu = -1;
deletesprite(g_i);
}
// restoring these needs to happen after VM_DeleteSprite() due to event recursion
returnValue = globalReturn;
@ -157,6 +93,8 @@ static FORCE_INLINE int32_t VM_EventInlineInternal__(int const eventNum, int con
insptr = saved.insptr;
return returnValue;
#endif
return 0;
}
// the idea here is that the compiler inlines the call to VM_EventInlineInternal__() and gives us a set of
@ -182,188 +120,4 @@ int32_t VM_ExecuteEventWithValue(int const nEventID, int const spriteNum, int co
return VM_EventInlineInternal__(nEventID, spriteNum, playerNum, -1, nReturn);
}
bool ifsquished(int i, int p);
void forceplayerangle(DukePlayer_t *pPlayer)
{
int const nAngle = 128-(krand2()&255);
pPlayer->q16horiz += F16(64);
pPlayer->return_to_center = 9;
pPlayer->rotscrnang = nAngle >> 1;
pPlayer->look_ang = pPlayer->rotscrnang;
}
GAMEEXEC_STATIC void VM_Move(void)
{
fi.move(vm.spriteNum, vm.playerNum, vm.playerDist);
}
extern uint8_t killit_flag;
void VM_Execute(native_t loop)
{
native_t tw = *insptr;
DukePlayer_t *const pPlayer = vm.pPlayer;
// jump directly into the loop, skipping branches during the first iteration
goto skip_check;
while (loop)
{
if (vm.flags & (VM_RETURN | VM_KILL | VM_NOEXECUTE))
break;
tw = *insptr;
skip_check:
if (parse()) goto out;
if (killit_flag & 1) vm.flags |= VM_KILL;
if (killit_flag & 2) vm.flags |= VM_NOEXECUTE;
killit_flag = 0;
continue;
}
out:
if (killit_flag & 1) vm.flags |= VM_KILL;
if (killit_flag & 2) vm.flags |= VM_NOEXECUTE;
killit_flag = 0;
}
void VM_UpdateAnim(int spriteNum, int32_t *pData)
{
size_t const actionofs = AC_ACTION_ID(pData);
intptr_t const *actionptr = (actionofs != 0 && actionofs + (ACTION_PARAM_COUNT-1) < (unsigned) g_scriptSize) ? &apScript[actionofs] : NULL;
if (actionptr != NULL)
{
int const action_frames = actionptr[ACTION_NUMFRAMES];
int const action_incval = actionptr[ACTION_INCVAL];
int const action_delay = actionptr[ACTION_DELAY];
auto actionticsptr = &AC_ACTIONTICS(&sprite[spriteNum], &actor[spriteNum]);
*actionticsptr += TICSPERFRAME;
if (*actionticsptr > action_delay)
{
*actionticsptr = 0;
AC_ACTION_COUNT(pData)++;
AC_CURFRAME(pData) += action_incval;
}
if (klabs(AC_CURFRAME(pData)) >= klabs(action_frames * action_incval))
AC_CURFRAME(pData) = 0;
}
}
extern int g_i, g_p;
extern int g_x;
extern int* g_t;
extern uint8_t killit_flag;
extern spritetype* g_sp;
// NORECURSE
void A_Execute(int spriteNum, int playerNum, int playerDist)
{
if (!G_HaveActor(sprite[spriteNum].picnum)) return;
vmstate_t tempvm
= { spriteNum, playerNum, playerDist, 0, &sprite[spriteNum], &actor[spriteNum].t_data[0], g_player[playerNum].ps, &actor[spriteNum] };
vm = tempvm;
g_i = spriteNum;
g_p = playerNum;
g_x = playerDist;
g_sp = &sprite[spriteNum];
g_t = &actor[spriteNum].t_data[0];
killit_flag = 0;
/*
if (g_netClient && A_CheckSpriteFlags(spriteNum, SFLAG_NULL))
{
A_DeleteSprite(spriteNum);
return;
}
*/
//if (g_netClient) // [75] The server should not overwrite its own randomseed
// randomseed = ticrandomseed;
if (EDUKE32_PREDICT_FALSE((unsigned)vm.pSprite->sectnum >= MAXSECTORS))
{
if (A_CheckEnemySprite(vm.pSprite))
P_AddKills(vm.pPlayer, 1);
A_DeleteSprite(vm.spriteNum);
return;
}
VM_UpdateAnim(vm.spriteNum, vm.pData);
double t = timerGetHiTicks();
int const picnum = vm.pSprite->picnum;
insptr = 4 + (g_tile[vm.pSprite->picnum].execPtr);
VM_Execute(1);
insptr = NULL;
t = timerGetHiTicks()-t;
g_actorTotalMs[picnum] += t;
g_actorMinMs[picnum] = min(g_actorMinMs[picnum], t);
g_actorMaxMs[picnum] = max(g_actorMaxMs[picnum], t);
g_actorCalls[picnum]++;
if (vm.flags & VM_KILL)
{
VM_DeleteSprite(spriteNum, playerNum);
return;
}
VM_Move();
if (DEER || vm.pSprite->statnum != STAT_ACTOR)
{
if (vm.pSprite->statnum == STAT_STANDABLE)
{
switch (DYNAMICTILEMAP(vm.pSprite->picnum))
{
case RUBBERCAN__STATIC:
case EXPLODINGBARREL__STATIC:
case WOODENHORSE__STATIC:
case HORSEONSIDE__STATIC:
case CANWITHSOMETHING__STATIC:
case FIREBARREL__STATIC:
case NUKEBARREL__STATIC:
case NUKEBARRELDENTED__STATIC:
case NUKEBARRELLEAKED__STATIC:
case TRIPBOMB__STATIC:
case EGG__STATIC:
if (vm.pActor->timetosleep > 1)
vm.pActor->timetosleep--;
else if (vm.pActor->timetosleep == 1)
changespritestat(vm.spriteNum, STAT_ZOMBIEACTOR);
default: break;
}
}
goto safe_delete;
}
if (A_CheckEnemySprite(vm.pSprite))
{
if (vm.pSprite->xrepeat > 60 || (ud.respawn_monsters == 1 && vm.pSprite->extra <= 0))
goto safe_delete;
}
else if (EDUKE32_PREDICT_FALSE(ud.respawn_items == 1 && (vm.pSprite->cstat & 32768)))
goto safe_delete;
if (A_CheckSpriteFlags(vm.spriteNum, SFLAG_USEACTIVATOR) && sector[vm.pSprite->sectnum].lotag & 16384)
changespritestat(vm.spriteNum, STAT_ZOMBIEACTOR);
else if (vm.pActor->timetosleep > 1)
vm.pActor->timetosleep--;
else if (vm.pActor->timetosleep == 1)
changespritestat(vm.spriteNum, STAT_ZOMBIEACTOR);
safe_delete:
if (vm.flags & VM_SAFEDELETE)
A_DeleteSprite(spriteNum);
}
END_DUKE_NS

View file

@ -406,48 +406,6 @@ static int osdcmd_password(CCmdFuncPtr parm)
int osdcmd_listplayers(CCmdFuncPtr parm);
#endif
static int osdcmd_printtimes(CCmdFuncPtr UNUSED(parm))
{
UNREFERENCED_CONST_PARAMETER(parm);
char buf[32];
int32_t maxlen = 0;
int32_t haveac=0;
for (int i=0; i<MAXTILES; i++)
if (g_actorCalls[i])
{
if (!haveac)
{
haveac = 1;
Printf("\nactor times: tile, total calls, total time [ms], {min,mean,max} time/call [us]\n");
}
buf[0] = 0;
/*
for (int ii=0; ii<labelcnt; ii++)
{
if (labelcode[ii] == i && labeltype[ii] & LABEL_ACTOR)
{
Bstrcpy(buf, label+(ii<<6));
break;
}
}
*/
if (!buf[0]) Bsprintf(buf, "%d", i);
Printf("%17s, %8d, %9.3f, %9.3f, %9.3f, %9.3f,\n",
buf, g_actorCalls[i], g_actorTotalMs[i],
1000*g_actorMinMs[i],
1000*g_actorTotalMs[i]/g_actorCalls[i],
1000*g_actorMaxMs[i]);
}
return OSDCMD_OK;
}
int32_t registerosdcommands(void)
{
@ -485,8 +443,6 @@ int32_t registerosdcommands(void)
C_RegisterFunction("password","password: sets multiplayer game password", osdcmd_password);
#endif
C_RegisterFunction("printtimes", "printtimes: prints VM timing statistics", osdcmd_printtimes);
C_RegisterFunction("restartmap", "restartmap: restarts the current map", osdcmd_restartmap);
C_RegisterFunction("spawn","spawn <picnum> [palnum] [cstat] [ang] [x y z]: spawns a sprite with the given properties",osdcmd_spawn);

View file

@ -9220,4 +9220,15 @@ int P_HasKey(int sectNum, int playerNum)
int16_t max_ammo_amount[MAX_WEAPONS];
void forceplayerangle(DukePlayer_t* pPlayer)
{
int const nAngle = 128 - (krand2() & 255);
pPlayer->q16horiz += F16(64);
pPlayer->return_to_center = 9;
pPlayer->rotscrnang = nAngle >> 1;
pPlayer->look_ang = pPlayer->rotscrnang;
}
END_DUKE_NS