From 1a98f9b478854a3384d5943e38183373e232b4c0 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 8 Dec 2022 23:09:46 +0100 Subject: [PATCH] - Duke: change all checks for mirrors to texture IDs --- source/games/duke/src/actors_d.cpp | 2 +- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/animatesprites_d.cpp | 2 +- source/games/duke/src/animatesprites_r.cpp | 2 +- source/games/duke/src/constants.h | 2 ++ source/games/duke/src/dispatch.cpp | 1 - source/games/duke/src/duke3d.h | 1 + source/games/duke/src/flags_d.cpp | 1 - source/games/duke/src/flags_r.cpp | 1 - source/games/duke/src/game.cpp | 19 ++++++++++-- source/games/duke/src/names.h | 1 - source/games/duke/src/player_d.cpp | 2 +- source/games/duke/src/player_r.cpp | 2 +- source/games/duke/src/premap.cpp | 4 +-- source/games/duke/src/premap_d.cpp | 12 ++++---- source/games/duke/src/premap_r.cpp | 35 ++++++++++------------ source/games/duke/src/sectors.cpp | 2 +- source/games/duke/src/sectors_d.cpp | 2 +- source/games/duke/src/sectors_r.cpp | 4 +-- source/games/duke/src/vmexports.cpp | 2 +- 20 files changed, 55 insertions(+), 44 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index d950c1ec2..389a9472c 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1704,7 +1704,7 @@ void move_d(DDukeActor *actor, int playernum, int xvel) actor->spr.shade += (actor->sector()->ceilingshade - actor->spr.shade) >> 1; else actor->spr.shade += (actor->sector()->floorshade - actor->spr.shade) >> 1; - if (actor->sector()->floorpicnum == DTILE_MIRROR) + if (actor->sector()->floortexture() == mirrortex) actor->Destroy(); } } diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 91529889e..87e1d80c9 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -1697,7 +1697,7 @@ void move_r(DDukeActor *actor, int pnum, int xvel) } else actor->spr.shade += (actor->sector()->floorshade - actor->spr.shade) >> 1; - if (actor->sector()->floorpicnum == RTILE_MIRROR) + if (actor->sector()->floortexture() == mirrortex) actor->Destroy(); } } diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index 258140ab2..ee39b3137 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -352,7 +352,7 @@ void animatesprites_d(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi } h->dispicnum = t->picnum; - if (t->sectp->floorpicnum == DTILE_MIRROR) + if (t->sectp->floortexture() == mirrortex) t->scale = DVector2(0, 0); } } diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index c73478b6b..b1ed4ead6 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -425,7 +425,7 @@ void animatesprites_r(tspriteArray& tsprites, const DVector2& viewVec, DAngle vi } h->dispicnum = t->picnum; - if (t->sectp->floorpicnum == RTILE_MIRROR) + if (t->sectp->floortexture() == mirrortex) t->scale = DVector2(0, 0); } } diff --git a/source/games/duke/src/constants.h b/source/games/duke/src/constants.h index a62682231..ea60b78a9 100644 --- a/source/games/duke/src/constants.h +++ b/source/games/duke/src/constants.h @@ -25,6 +25,8 @@ enum RESPAWN = 9, GPSPEED = 10, FOF = 13, + MIRROR_DUKE = 560, + MIRROR_RR = 1089, // hack alert! CYCLER is free for use here as all items of this type get destroyed right on map spawn and this value never gets checked anywhere else. // This avoids overallocation of empty tile slots as a high value slightly below the tile limit would do. diff --git a/source/games/duke/src/dispatch.cpp b/source/games/duke/src/dispatch.cpp index e43a6702c..7504148dd 100644 --- a/source/games/duke/src/dispatch.cpp +++ b/source/games/duke/src/dispatch.cpp @@ -188,7 +188,6 @@ int TILE_CLOUDYSKIES; int TILE_ACCESSSWITCH; int TILE_ACCESSSWITCH2; int TILE_HEN; -int TILE_MIRROR; int TILE_MIRRORBROKE; int TILE_LOADSCREEN; int TILE_CROSSHAIR; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 43f5b70dc..4d639f8e9 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -127,6 +127,7 @@ void CallPlayFTASound(DDukeActor* actor); void CallStandingOn(DDukeActor* actor, player_struct* p); void CallRunState(DDukeActor* actor); +extern FTextureID mirrortex, foftex; END_DUKE_NS diff --git a/source/games/duke/src/flags_d.cpp b/source/games/duke/src/flags_d.cpp index c646a3522..9aba9c482 100644 --- a/source/games/duke/src/flags_d.cpp +++ b/source/games/duke/src/flags_d.cpp @@ -293,7 +293,6 @@ void initactorflags_d() TILE_CLOUDYSKIES = DTILE_CLOUDYSKIES; TILE_ACCESSSWITCH = DTILE_ACCESSSWITCH; TILE_ACCESSSWITCH2 = DTILE_ACCESSSWITCH2; - TILE_MIRROR = DTILE_MIRROR; TILE_MIRRORBROKE = DTILE_MIRRORBROKE; TILE_LOADSCREEN = DTILE_LOADSCREEN; TILE_CROSSHAIR = DTILE_CROSSHAIR; diff --git a/source/games/duke/src/flags_r.cpp b/source/games/duke/src/flags_r.cpp index 9e6affc94..2729004e5 100644 --- a/source/games/duke/src/flags_r.cpp +++ b/source/games/duke/src/flags_r.cpp @@ -293,7 +293,6 @@ void initactorflags_r() TILE_CLOUDYSKIES = RTILE_CLOUDYSKIES; TILE_ACCESSSWITCH = RTILE_ACCESSSWITCH; TILE_ACCESSSWITCH2 = RTILE_ACCESSSWITCH2; - TILE_MIRROR = RTILE_MIRROR; TILE_MIRRORBROKE = RTILE_MIRRORBROKE; TILE_HEN = RTILE_HEN; TILE_LOADSCREEN = RTILE_LOADSCREEN; diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index d8e8564c0..de03781e2 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -51,6 +51,8 @@ void SetDispatcher(); void InitCheats(); int registerosdcommands(void); +FTextureID mirrortex, foftex; + //--------------------------------------------------------------------------- // // DObject stuff - everything GC related. @@ -309,12 +311,12 @@ void GameInterface::SetupSpecialTextures(TilesetBuildInfo& info) FImageSource* viewscreen; if (!isRR()) { - info.Delete(560); // the mirror tile. + info.Delete(MIRROR_DUKE); // the mirror tile. viewscreen = info.tile[502].tileimage; } else { - info.Delete(1089); // the mirror tile. + info.Delete(MIRROR_RR); // the mirror tile. info.Delete(0); // RR uses this as an empty texture info.MakeWritable(2025); // bowling lane pin displays info.MakeWritable(2026); @@ -338,6 +340,18 @@ int GameInterface::GetCurrentSkill() return ud.player_skill - 1; } +//--------------------------------------------------------------------------- +// +// IDs for non-textures that need direct checking +// +//--------------------------------------------------------------------------- + +void setTextureIDs() +{ + mirrortex = tileGetTextureID(isRR() ? MIRROR_RR : MIRROR_DUKE); + foftex = tileGetTextureID(FOF); +} + //--------------------------------------------------------------------------- // // set up the game module's state @@ -382,6 +396,7 @@ void GameInterface::app_init() loadcons(); fi.initactorflags(); + setTextureIDs(); // sets a few texture IDs needed for map checking. duke_menufont->Callback(); // depends on the .CON files so it must be after loadcons OnEvent(EVENT_INIT); diff --git a/source/games/duke/src/names.h b/source/games/duke/src/names.h index 789f5b571..3cb4a97e5 100644 --- a/source/games/duke/src/names.h +++ b/source/games/duke/src/names.h @@ -21,7 +21,6 @@ extern int TILE_CLOUDYSKIES; extern int TILE_ACCESSSWITCH; extern int TILE_ACCESSSWITCH2; extern int TILE_HEN; -extern int TILE_MIRROR; extern int TILE_MIRRORBROKE; extern int TILE_LOADSCREEN; extern int TILE_CROSSHAIR; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index 53a529a04..792742fce 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -2844,7 +2844,7 @@ void processinput_d(int snum) pact->vel.X = clamp((p->GetActor()->spr.pos.XY() - p->bobpos).Length(), 0., 32.); if (p->on_ground) p->bobcounter += int(p->GetActor()->vel.X * 8); - p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floorpicnum == DTILE_MIRROR) || !p->insector())); + p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floortexture() == mirrortex) || !p->insector())); // Shrinking code diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 8e7cf3d7e..874599677 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -3441,7 +3441,7 @@ void processinput_r(int snum) pact->vel.X = clamp((p->GetActor()->spr.pos.XY() - p->bobpos).Length(), 0., 32.); if (p->on_ground) p->bobcounter += int(p->GetActor()->vel.X * 8); - p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floorpicnum == RTILE_MIRROR) || !p->insector())); + p->backuppos(ud.clipping == 0 && ((p->insector() && p->cursector->floortexture() == mirrortex) || !p->insector())); // Shrinking code diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index 851de7a36..88721f979 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -805,7 +805,7 @@ static void SpawnPortals() { for (auto& wal : wall) { - if (wal.overpicnum == TILE_MIRROR && (wal.cstat & CSTAT_WALL_1WAY)) wal.portalflags |= PORTAL_WALL_MIRROR; + if (wal.overtexture() == mirrortex && (wal.cstat & CSTAT_WALL_1WAY)) wal.portalflags |= PORTAL_WALL_MIRROR; } portalClear(); @@ -887,7 +887,7 @@ static void SpawnPortals() } } } - else if (sectp->ceilingpicnum == FOF && sectp->portalflags != PORTAL_SECTOR_CEILING) + else if (sectp->ceilingtexture() == foftex && sectp->portalflags != PORTAL_SECTOR_CEILING) { for (auto& pt : allPortals) { diff --git a/source/games/duke/src/premap_d.cpp b/source/games/duke/src/premap_d.cpp index 34901f32a..97cefb68c 100644 --- a/source/games/duke/src/premap_d.cpp +++ b/source/games/duke/src/premap_d.cpp @@ -325,16 +325,16 @@ void prelevel_d(int g, TArray& actors) for (auto& wal : wall) { - if (wal.overpicnum == DTILE_MIRROR && (wal.cstat & CSTAT_WALL_1WAY) != 0) + if (wal.overtexture() == mirrortex && (wal.cstat & CSTAT_WALL_1WAY) != 0) { auto sectp = wal.nextSector(); if (mirrorcnt > 63) I_Error("Too many mirrors (64 max.)"); - if (sectp && sectp->ceilingpicnum != DTILE_MIRROR) + if (sectp && sectp->ceilingtexture() != mirrortex) { - sectp->ceilingpicnum = DTILE_MIRROR; - sectp->floorpicnum = DTILE_MIRROR; + sectp->setceilingtexture(mirrortex); + sectp->setfloortexture(mirrortex); mirrorwall[mirrorcnt] = &wal; mirrorsector[mirrorcnt] = sectp; mirrorcnt++; @@ -443,8 +443,8 @@ void prelevel_d(int g, TArray& actors) { for (auto& wal : mirrorsector[i]->walls) { - wal.wallpicnum = DTILE_MIRROR; - wal.overpicnum = DTILE_MIRROR; + wal.setwalltexture(mirrortex); + wal.setovertexture(mirrortex); } } } diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index c566db5d9..43ede2d23 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -634,22 +634,19 @@ void prelevel_r(int g, TArray& actors) mirrorcnt = 0; - for (auto& wl : wall) + for (auto& wal : wall) { - walltype* wal = &wl; - - - if (wal->overpicnum == RTILE_MIRROR && (wal->cstat & CSTAT_WALL_1WAY) != 0) + if (wal.overtexture() == mirrortex && (wal.cstat & CSTAT_WALL_1WAY) != 0) { - auto sectp = wal->nextSector(); + auto sectp = wal.nextSector(); if (mirrorcnt > 63) I_Error("Too many mirrors (64 max.)"); - if (sectp && sectp->ceilingpicnum != RTILE_MIRROR) + if (sectp && sectp->ceilingtexture() != mirrortex) { - sectp->ceilingpicnum = RTILE_MIRROR; - sectp->floorpicnum = RTILE_MIRROR; - mirrorwall[mirrorcnt] = wal; + sectp->setceilingtexture(mirrortex); + sectp->setfloortexture(mirrortex); + mirrorwall[mirrorcnt] = &wal; mirrorsector[mirrorcnt] = sectp; mirrorcnt++; continue; @@ -662,29 +659,29 @@ void prelevel_r(int g, TArray& actors) animwall[numanimwalls].tag = 0; animwall[numanimwalls].wall = nullptr; - switch (wal->overpicnum) + switch (wal.overpicnum) { case RTILE_FANSPRITE: //wal.cstat |= CSTAT_WALL_BLOCK | CSTAT_WALL_BLOCK_HITSCAN; Original code assigned this to 'wall', i.e. wall[0] - animwall[numanimwalls].wall = wal; + animwall[numanimwalls].wall = &wal; numanimwalls++; break; case RTILE_BIGFORCE: - animwall[numanimwalls].wall = wal; + animwall[numanimwalls].wall = &wal; numanimwalls++; continue; } - wal->extra = -1; + wal.extra = -1; - switch (wal->wallpicnum) + switch (wal.wallpicnum) { case RTILE_SCREENBREAK6: case RTILE_SCREENBREAK7: case RTILE_SCREENBREAK8: for (j = RTILE_SCREENBREAK6; j <= RTILE_SCREENBREAK8; j++) tloadtile(j); - animwall[numanimwalls].wall = wal; + animwall[numanimwalls].wall = &wal; animwall[numanimwalls].tag = -1; numanimwalls++; break; @@ -694,10 +691,10 @@ void prelevel_r(int g, TArray& actors) //Invalidate textures in sector behind mirror for (i = 0; i < mirrorcnt; i++) { - for (auto& mwal : mirrorsector[i]->walls) + for (auto& wal : mirrorsector[i]->walls) { - mwal.wallpicnum = RTILE_MIRROR; - mwal.overpicnum = RTILE_MIRROR; + wal.setwalltexture(mirrortex); + wal.setovertexture(mirrortex); } } thunder_brightness = 0; diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 37cd74cdf..7cf9bd33c 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -1273,7 +1273,7 @@ void operateforcefields_common(DDukeActor *effector, int low, const std::initial void checkhitwall(DDukeActor* spr, walltype* wal, const DVector3& pos) { - if (wal->overpicnum == TILE_MIRROR && actorflag(spr, SFLAG2_BREAKMIRRORS)) + if (wal->overtexture() == mirrortex && actorflag(spr, SFLAG2_BREAKMIRRORS)) { lotsofglass(spr, wal, 70); wal->cstat &= ~CSTAT_WALL_MASKED; diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index 1e4ab320f..953f283c2 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -832,7 +832,7 @@ void checksectors_d(int snum) if (hitscanwall != nullptr) { - if (dist < 80 && hitscanwall->overpicnum == DTILE_MIRROR) + if (dist < 80 && hitscanwall->overtexture() == mirrortex) if (hitscanwall->lotag > 0 && S_CheckSoundPlaying(hitscanwall->lotag) == 0 && snum == screenpeek) { S_PlayActorSound(hitscanwall->lotag, pact); diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index e8015a5e8..e31dd2720 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -901,7 +901,7 @@ void checksectors_r(int snum) { if (isRRRA()) { - if (hitscanwall->overpicnum == RTILE_MIRROR && snum == screenpeek) + if (hitscanwall->overtexture() == mirrortex && snum == screenpeek) if (numplayers == 1) { if (S_CheckActorSoundPlaying(pact, 27) == 0 && S_CheckActorSoundPlaying(pact, 28) == 0 && S_CheckActorSoundPlaying(pact, 29) == 0 @@ -924,7 +924,7 @@ void checksectors_r(int snum) } else { - if (hitscanwall->overpicnum == RTILE_MIRROR) + if (hitscanwall->overtexture() == mirrortex) if (hitscanwall->lotag > 0 && S_CheckActorSoundPlaying(pact, hitscanwall->lotag) == 0 && snum == screenpeek) { S_PlayActorSound(hitscanwall->lotag, pact); diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index e0909804a..b894457f1 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -1323,7 +1323,7 @@ DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, wallflags, duke_wallflags) int duke_ismirror(walltype* wal) { - return wal->wallpicnum == TILE_MIRROR || wal->overpicnum == TILE_MIRROR; + return wal->walltexture() == mirrortex || wal->overtexture() == mirrortex; } DEFINE_ACTION_FUNCTION_NATIVE(_DukeLevel, ismirror, duke_ismirror)