- cleaned up the checkhitswitch interface to receive sprites as pointers.

This commit is contained in:
Christoph Oelckers 2020-10-26 07:30:34 +01:00
parent 3e7c8adc1e
commit bc6ae872ae
12 changed files with 78 additions and 85 deletions

View file

@ -288,12 +288,6 @@ enum amoveflags_t
antifaceplayerslow = 32768
};
enum
{
SWITCH_WALL,
SWITCH_SPRITE
};
enum sflags_t
{
SFLAG_SHADOW = 0x00000001,

View file

@ -43,8 +43,8 @@ void operaterespawns_d(int low);
void operaterespawns_r(int low);
void operateforcefields_r(int s, int low);
void operateforcefields_d(int s, int low);
bool checkhitswitch_d(int snum, int w, int switchtype);
bool checkhitswitch_r(int snum, int w, int switchtype);
bool checkhitswitch_d(int snum, int w, DDukeActor *act);
bool checkhitswitch_r(int snum, int w, DDukeActor* act);
void activatebysector_d(int sect, int j);
void activatebysector_r(int sect, int j);
void checkhitwall_d(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith);

View file

@ -76,7 +76,7 @@ struct Dispatcher
void (*animatewalls)();
void (*operaterespawns)(int low);
void (*operateforcefields)(int s, int low);
bool (*checkhitswitch)(int snum, int w, int switchtype);
bool (*checkhitswitch)(int snum, int w, DDukeActor* act);
void (*activatebysector)(int sect, int j);
void (*checkhitwall)(DDukeActor* spr, int dawallnum, int x, int y, int z, int atwith);
bool (*checkhitceiling)(int sn);

View file

@ -135,7 +135,8 @@ unsigned ambientfx;
int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS];
int WindTime, WindDir;
short fakebubba_spawn, mamaspawn_count, banjosound;
short BellTime, BellSprite /* word_119BE0*/;
short BellTime;
DDukeActor* BellSprite /* word_119BE0*/;
uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive;
uint32_t everyothertime;
player_orig po[MAXPLAYERS];

View file

@ -127,7 +127,8 @@ extern unsigned ambientfx;
extern int msx[MAXANIMPOINTS], msy[MAXANIMPOINTS];
extern int WindTime, WindDir;
extern short fakebubba_spawn, mamaspawn_count, banjosound;
extern short BellTime, BellSprite /* word_119BE0*/;
extern short BellTime;
extern DDukeActor* BellSprite /* word_119BE0*/;
extern uint8_t enemysizecheat /*raat607*/, ufospawnsminion, pistonsound, chickenphase /* raat605*/, RRRA_ExitedLevel, fogactive;
extern uint32_t everyothertime;
extern player_orig po[MAXPLAYERS];

View file

@ -277,7 +277,7 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa)
if (hitsprt && hitsprt->s.picnum != ACCESSSWITCH && hitsprt->s.picnum != ACCESSSWITCH2)
{
fi.checkhitsprite(hitsprt, knee);
if (p >= 0) fi.checkhitswitch(p, hitsprt->GetIndex(), 1);
if (p >= 0) fi.checkhitswitch(p, -1, hitsprt);
}
else if (hitwall >= 0)
@ -290,7 +290,7 @@ static void shootknee(DDukeActor* actor, int p, int sx, int sy, int sz, int sa)
if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2)
{
fi.checkhitwall(knee, hitwall, hitx, hity, hitz, KNEE);
if (p >= 0) fi.checkhitswitch(p, hitwall, 0);
if (p >= 0) fi.checkhitswitch(p, hitwall, nullptr);
}
}
}
@ -462,7 +462,7 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa
hitact->s.picnum == HANDSWITCH ||
hitact->s.picnum == HANDSWITCH + 1))
{
fi.checkhitswitch(p, hitact->GetIndex(), 1);
fi.checkhitswitch(p, -1, hitact);
return;
}
}
@ -482,7 +482,7 @@ static void shootweapon(DDukeActor *actor, int p, int sx, int sy, int sz, int sa
wall[hitwall].picnum == HANDSWITCH ||
wall[hitwall].picnum == HANDSWITCH + 1))
{
fi.checkhitswitch(p, hitwall, 0);
fi.checkhitswitch(p, hitwall, nullptr);
return;
}
@ -1517,7 +1517,7 @@ int doincrements_d(struct player_struct* p)
{
if (p->access_spritenum != nullptr)
{
fi.checkhitswitch(snum, p->access_spritenum->GetIndex(), 1);
fi.checkhitswitch(snum, -1, p->access_spritenum);
switch (p->access_spritenum->s.pal)
{
case 0:p->got_access &= (0xffff - 0x1); break;
@ -1528,7 +1528,7 @@ int doincrements_d(struct player_struct* p)
}
else
{
fi.checkhitswitch(snum, p->access_wallnum, 0);
fi.checkhitswitch(snum, p->access_wallnum, nullptr);
switch (wall[p->access_wallnum].pal)
{
case 0:p->got_access &= (0xffff - 0x1); break;

View file

@ -175,7 +175,7 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa,
if (hitsprt && hitsprt->s.picnum != ACCESSSWITCH && hitsprt->s.picnum != ACCESSSWITCH2)
{
fi.checkhitsprite(hitsprt, wpn);
if (p >= 0) fi.checkhitswitch(p, hitsprt->GetIndex(), 1);
if (p >= 0) fi.checkhitswitch(p, -1, hitsprt);
}
else if (hitwall >= 0)
{
@ -187,7 +187,7 @@ static void shootmelee(DDukeActor *actor, int p, int sx, int sy, int sz, int sa,
if (hitwall >= 0 && wall[hitwall].picnum != ACCESSSWITCH && wall[hitwall].picnum != ACCESSSWITCH2)
{
fi.checkhitwall(wpn, hitwall, hitx, hity, hitz, atwith);
if (p >= 0) fi.checkhitswitch(p, hitwall, 0);
if (p >= 0) fi.checkhitswitch(p, hitwall, nullptr);
}
}
}
@ -364,7 +364,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa
hitsprt->s.picnum == HANDSWITCH ||
hitsprt->s.picnum == HANDSWITCH + 1))
{
fi.checkhitswitch(p, hitsprt->GetIndex(), 1);
fi.checkhitswitch(p, -1, hitsprt);
return;
}
}
@ -387,7 +387,7 @@ static void shootweapon(DDukeActor* actor, int p, int sx, int sy, int sz, int sa
wall[hitwall].picnum == HANDSWITCH ||
wall[hitwall].picnum == HANDSWITCH + 1))
{
fi.checkhitswitch(p, hitwall, 0);
fi.checkhitswitch(p, hitwall, nullptr);
return;
}
@ -1220,8 +1220,8 @@ int doincrements_r(struct player_struct* p)
if (BellTime > 0)
{
BellTime--;
if (BellTime == 0)
sprite[BellSprite].picnum++;
if (BellTime == 0 && BellSprite)
BellSprite->s.picnum++;
}
if (chickenphase > 0)
chickenphase--;
@ -1369,7 +1369,7 @@ int doincrements_r(struct player_struct* p)
{
if (p->access_spritenum != nullptr)
{
fi.checkhitswitch(snum, p->access_spritenum->GetIndex(), 1);
fi.checkhitswitch(snum, -1, p->access_spritenum);
switch (p->access_spritenum->s.pal)
{
case 0:p->keys[1] = 1; break;
@ -1380,7 +1380,7 @@ int doincrements_r(struct player_struct* p)
}
else
{
fi.checkhitswitch(snum, p->access_wallnum, 0);
fi.checkhitswitch(snum, p->access_wallnum, nullptr);
switch (wall[p->access_wallnum].pal)
{
case 0:p->keys[1] = 1; break;

View file

@ -426,7 +426,7 @@ void resetprestat(int snum,int g)
fakebubba_spawn = 0;
RRRA_ExitedLevel = 0;
BellTime = 0;
BellSprite = 0;
BellSprite = nullptr;
numinterpolations = 0;
//startofdynamicinterpolations = 0;
@ -677,7 +677,7 @@ void prelevel_common(int g)
RRRA_ExitedLevel = 0;
mamaspawn_count = 15;
BellTime = 0;
BellSprite = 0;
BellSprite = nullptr;
// RRRA E2L1 fog handling.
fogactive = 0;

View file

@ -223,20 +223,18 @@ void operateforcefields_d(int s, int low)
//
//---------------------------------------------------------------------------
bool checkhitswitch_d(int snum, int w, int switchtype)
bool checkhitswitch_d(int snum, int ww, DDukeActor *act)
{
uint8_t switchpal;
int i, x, lotag, hitag, picnum, correctdips, numdips;
int sx, sy;
if (w < 0) return 0;
if (ww < 0 && act == nullptr) return 0;
correctdips = 1;
numdips = 0;
DDukeActor* act = nullptr;
if (switchtype == SWITCH_SPRITE) // A wall sprite
if (act)
{
act = &hittype[w];
lotag = act->s.lotag;
if (lotag == 0) return 0;
hitag = act->s.hitag;
@ -247,7 +245,7 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
}
else
{
auto wal = &wall[w];
auto wal = &wall[ww];
lotag = wal->lotag;
if (lotag == 0) return 0;
hitag = wal->hitag;
@ -267,7 +265,7 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
case ALIENSWITCH + 1:
break;
case DEVELOPERCOMMENTARY + 1: //Twentieth Anniversary World Tour
if (switchtype == 1)
if (act)
{
StopCommentary();
act->s.picnum = DEVELOPERCOMMENTARY;
@ -275,9 +273,9 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
}
return false;
case DEVELOPERCOMMENTARY: //Twentieth Anniversary World Tour
if (switchtype == 1)
if (act)
{
if (StartCommentary(lotag, w))
if (StartCommentary(lotag, act))
act->s.picnum = DEVELOPERCOMMENTARY+1;
return true;
}
@ -309,8 +307,8 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
if (ps[snum].access_incs == 1)
{
if (switchtype == SWITCH_WALL)
ps[snum].access_wallnum = w;
if (!act)
ps[snum].access_wallnum = ww;
else
ps[snum].access_spritenum = act;
}
@ -363,14 +361,14 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
case DIPSWITCH:
case TECHSWITCH:
case ALIENSWITCH:
if (switchtype == SWITCH_SPRITE && act == other) si->picnum++;
if (act && act == other) si->picnum++;
else if (si->hitag == 0) correctdips++;
numdips++;
break;
case TECHSWITCH + 1:
case DIPSWITCH + 1:
case ALIENSWITCH + 1:
if (switchtype == SWITCH_SPRITE && act == other) si->picnum--;
if (act && act == other) si->picnum--;
else if (si->hitag == 1) correctdips++;
numdips++;
break;
@ -426,14 +424,14 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
case DIPSWITCH:
case TECHSWITCH:
case ALIENSWITCH:
if (switchtype == SWITCH_WALL && i == w) wall[x].picnum++;
if (!act && i == ww) wall[x].picnum++;
else if (wall[x].hitag == 0) correctdips++;
numdips++;
break;
case DIPSWITCH + 1:
case TECHSWITCH + 1:
case ALIENSWITCH + 1:
if (switchtype == SWITCH_WALL && i == w) wall[x].picnum--;
if (!act && i == ww) wall[x].picnum--;
else if (wall[x].hitag == 1) correctdips++;
numdips++;
break;
@ -501,13 +499,13 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
{
if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1)
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(ALIEN_SWITCH1, act, &v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v);
}
else
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
}
@ -590,7 +588,7 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
if (hitag == 0 && fi.isadoorwall(picnum) == 0)
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
}
@ -598,7 +596,7 @@ bool checkhitswitch_d(int snum, int w, int switchtype)
{
auto flags = S_GetUserFlags(hitag);
if (switchtype == SWITCH_SPRITE && (flags & SF_TALK) == 0)
if (act && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, act, &v);
else
S_PlayActorSound(hitag, ps[snum].i);
@ -1641,7 +1639,7 @@ void checksectors_d(int snum)
if (neartagsprite >= 0)
{
if (fi.checkhitswitch(snum, neartagsprite, 1)) return;
if (fi.checkhitswitch(snum, -1, &hittype[neartagsprite])) return;
switch (sprite[neartagsprite].picnum)
{
@ -1772,7 +1770,7 @@ void checksectors_d(int snum)
if (wall[neartagwall].lotag > 0 && fi.isadoorwall(wall[neartagwall].picnum))
{
if (hitscanwall == neartagwall || hitscanwall == -1)
fi.checkhitswitch(snum, neartagwall, 0);
fi.checkhitswitch(snum, neartagwall, nullptr);
return;
}
else if (p->newowner >= 0)
@ -1803,7 +1801,7 @@ void checksectors_d(int snum)
}
operatesectors(p->GetActor()->s.sectnum, p->GetActor());
}
else fi.checkhitswitch(snum, neartagwall, 0);
else fi.checkhitswitch(snum, neartagwall, nullptr);
}
}
}

View file

@ -343,20 +343,18 @@ void operateforcefields_r(int s, int low)
//
//---------------------------------------------------------------------------
bool checkhitswitch_r(int snum, int w, int switchtype)
bool checkhitswitch_r(int snum, int ww, DDukeActor* act)
{
uint8_t switchpal;
int i, x, lotag, hitag, picnum, correctdips, numdips;
int sx, sy;
if (w < 0) return 0;
if (ww < 0 && act == nullptr) return 0;
correctdips = 1;
numdips = 0;
DDukeActor* act = nullptr;
if (switchtype == SWITCH_SPRITE) // A wall sprite
if (act)
{
act = &hittype[w];
lotag = act->s.lotag;
if (lotag == 0) return 0;
hitag = act->s.hitag;
@ -367,7 +365,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
}
else
{
auto wal = &wall[w];
auto wal = &wall[ww];
lotag = wal->lotag;
if (lotag == 0) return 0;
hitag = wal->hitag;
@ -397,7 +395,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
else
{
FTA(70, &ps[snum]);
if (isRRRA()) S_PlayActorSound(99, w);
if (isRRRA()) S_PlayActorSound(99, act? act : ps[snum].GetActor());
}
}
@ -408,7 +406,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
else
{
FTA(71, &ps[snum]);
if (isRRRA()) S_PlayActorSound(99, w);
if (isRRRA()) S_PlayActorSound(99, act ? act : ps[snum].GetActor());
}
}
@ -419,14 +417,14 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
else
{
FTA(72, &ps[snum]);
if (isRRRA()) S_PlayActorSound(99, w);
if (isRRRA()) S_PlayActorSound(99, act ? act : ps[snum].GetActor());
}
}
if (ps[snum].access_incs == 1)
{
if (switchtype == 0)
ps[snum].access_wallnum = w;
if (!act)
ps[snum].access_wallnum = ww;
else
ps[snum].access_spritenum = act;
}
@ -496,14 +494,14 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
case DIPSWITCH:
case TECHSWITCH:
case ALIENSWITCH:
if (switchtype == SWITCH_SPRITE && act == other) si->picnum++;
if (act && act == other) si->picnum++;
else if (si->hitag == 0) correctdips++;
numdips++;
break;
case TECHSWITCH + 1:
case DIPSWITCH + 1:
case ALIENSWITCH + 1:
if (switchtype == SWITCH_SPRITE && act == other) si->picnum--;
if (act && act == other) si->picnum--;
else if (si->hitag == 1) correctdips++;
numdips++;
break;
@ -610,14 +608,14 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
case DIPSWITCH:
case TECHSWITCH:
case ALIENSWITCH:
if (switchtype == SWITCH_WALL && i == w) wall[x].picnum++;
if (!act && i == ww) wall[x].picnum++;
else if (wall[x].hitag == 0) correctdips++;
numdips++;
break;
case DIPSWITCH + 1:
case TECHSWITCH + 1:
case ALIENSWITCH + 1:
if (switchtype == SWITCH_WALL && i == w) wall[x].picnum--;
if (!act && i == ww) wall[x].picnum--;
else if (wall[x].hitag == 1) correctdips++;
numdips++;
break;
@ -699,13 +697,13 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
{
if (picnum == ALIENSWITCH || picnum == ALIENSWITCH + 1)
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(ALIEN_SWITCH1, act, &v);
else S_PlaySound3D(ALIEN_SWITCH1, ps[snum].GetActor(), &v);
}
else
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
}
@ -759,10 +757,10 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
goOn2:
if (isRRRA())
{
if (picnum == RRTILE8660)
if (picnum == RRTILE8660 && act)
{
BellTime = 132;
BellSprite = w;
BellSprite = act;
act->s.picnum++;
}
else if (picnum == RRTILE8464)
@ -785,7 +783,8 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
picnum == MULTISWITCH2 || picnum == (MULTISWITCH2 + 1) ||
picnum == (MULTISWITCH2 + 2) || picnum == (MULTISWITCH2 + 3))
{
int switches[3], switchcount = 0, j;
DDukeActor* switches[3];
int switchcount = 0, j;
S_PlaySound3D(SWITCH_ON, act, &v);
DukeSpriteIterator it;
while (auto actt = it.Next())
@ -796,7 +795,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
{
if (switchcount < 3)
{
switches[switchcount] = actt->GetIndex();
switches[switchcount] = actt;
switchcount++;
}
}
@ -806,12 +805,12 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
S_PlaySound3D(78, act, &v);
for (j = 0; j < switchcount; j++)
{
sprite[switches[j]].hitag = 0;
switches[j]->s.hitag = 0;
if (picnum >= MULTISWITCH2)
sprite[switches[j]].picnum = MULTISWITCH2 + 3;
switches[j]->s.picnum = MULTISWITCH2 + 3;
else
sprite[switches[j]].picnum = MULTISWITCH + 3;
checkhitswitch_r(snum, switches[j], 1);
switches[j]->s.picnum = MULTISWITCH + 3;
checkhitswitch_r(snum, -1, switches[j]);
}
}
return 1;
@ -871,7 +870,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
if (hitag == 0 && fi.isadoorwall(picnum) == 0)
{
if (switchtype == SWITCH_SPRITE)
if (act)
S_PlaySound3D(SWITCH_ON, act, &v);
else S_PlaySound3D(SWITCH_ON, ps[snum].GetActor(), &v);
}
@ -879,7 +878,7 @@ bool checkhitswitch_r(int snum, int w, int switchtype)
{
auto flags = S_GetUserFlags(hitag);
if (switchtype == SWITCH_SPRITE && (flags & SF_TALK) == 0)
if (act && (flags & SF_TALK) == 0)
S_PlaySound3D(hitag, act, &v);
else
S_PlayActorSound(hitag, ps[snum].GetActor());
@ -2604,7 +2603,7 @@ void checksectors_r(int snum)
if (neartagsprite >= 0)
{
if (fi.checkhitswitch(snum, neartagsprite, 1)) return;
if (fi.checkhitswitch(snum, -1, &hittype[neartagsprite])) return;
switch (sprite[neartagsprite].picnum)
{
@ -2721,7 +2720,7 @@ void checksectors_r(int snum)
if (wall[neartagwall].lotag > 0 && fi.isadoorwall(wall[neartagwall].picnum))
{
if (hitscanwall == neartagwall || hitscanwall == -1)
fi.checkhitswitch(snum, neartagwall, 0);
fi.checkhitswitch(snum, neartagwall, nullptr);
return;
}
}
@ -2766,7 +2765,7 @@ void checksectors_r(int snum)
FTA(41, p);
}
}
else fi.checkhitswitch(snum, neartagwall, 0);
else fi.checkhitswitch(snum, neartagwall, nullptr);
}
}
}

View file

@ -54,7 +54,7 @@ BEGIN_DUKE_NS
TArray<FString> specialmusic;
static FSoundID currentCommentarySound;
static int currentCommentarySprite;
static DDukeActor* currentCommentarySprite; // todo: GC this once actors become objects
class DukeSoundEngine : public SoundEngine
@ -90,7 +90,7 @@ public:
{
UnloadSound(schan->SoundID);
currentCommentarySound = 0;
sprite[currentCommentarySprite].picnum = DEVELOPERCOMMENTARY;
currentCommentarySprite->s.picnum = DEVELOPERCOMMENTARY;
I_SetRelativeVolume(1.0f);
}
SoundEngine::SoundDone(schan);
@ -815,7 +815,7 @@ void StopCommentary()
}
}
bool StartCommentary(int tag, int sprnum)
bool StartCommentary(int tag, DDukeActor* actor)
{
if (wt_commentary && Commentaries.Size() > tag && Commentaries[tag].IsNotEmpty())
{
@ -833,7 +833,7 @@ bool StartCommentary(int tag, int sprnum)
StopCommentary();
soundEngine->StartSound(SOURCE_None, nullptr, nullptr, CHAN_VOICE, CHANF_UI | CHANF_TRANSIENT | CHANF_OVERLAP, id, 1.f, 0.f);
currentCommentarySound = id;
currentCommentarySprite = sprnum;
currentCommentarySprite = actor;
I_SetRelativeVolume(0.25f);
return true;
}

View file

@ -72,7 +72,7 @@ void S_ContinueLevelMusic(void);
void S_ParseDeveloperCommentary();
void StopCommentary();
bool StartCommentary(int tag, int sprnum);
bool StartCommentary(int tag, DDukeActor* sprnum);
extern TArray<FString> specialmusic;