From 1bace1d508b2f6518b84231ee923e0cc22ac160c Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 31 Dec 2022 17:58:14 +0100 Subject: [PATCH] - use texture IDs in the spawn records. --- source/core/g_mapinfo.cpp | 12 ++++++------ source/core/g_mapinfo.h | 2 +- source/core/maptypes.h | 2 +- source/core/savegamehelp.cpp | 2 +- source/games/duke/src/actors_r.cpp | 2 +- source/games/duke/src/classnames.h | 1 + source/games/duke/src/funct.h | 2 +- source/games/duke/src/game.cpp | 6 +++--- source/games/duke/src/gameexec.cpp | 2 +- source/games/duke/src/player.cpp | 10 +++++----- source/games/duke/src/premap_r.cpp | 2 +- source/games/duke/src/sectors_d.cpp | 2 +- source/games/duke/src/sectors_r.cpp | 9 ++++----- source/games/duke/src/spawn.cpp | 8 ++++---- source/games/duke/src/vmexports.cpp | 8 ++++---- 15 files changed, 35 insertions(+), 35 deletions(-) diff --git a/source/core/g_mapinfo.cpp b/source/core/g_mapinfo.cpp index a2bf97c7d..117ef7ea1 100644 --- a/source/core/g_mapinfo.cpp +++ b/source/core/g_mapinfo.cpp @@ -266,8 +266,8 @@ void FMapInfoParser::ParseSpawnClasses() int clipdist = -1; int num = -1; int base = -1; - int basetex = -1; - int brokentex = -1; + FTextureID basetex = FNullTextureID(); + FTextureID brokentex = FNullTextureID(); int fullbright = 0; int flags = 0; FSoundID sound = NO_SOUND; @@ -305,8 +305,8 @@ void FMapInfoParser::ParseSpawnClasses() } const char* p = sc.String; if (*p == '*') { fullbright |= 1; p++; } - basetex = tileForName(p); - if (basetex < 0) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); + basetex = TexMan.CheckForTexture(p, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + if (!basetex.isValid()) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); if (sc.CheckString(",")) { sc.MustGetString(); @@ -314,8 +314,8 @@ void FMapInfoParser::ParseSpawnClasses() if (*p) { if (*p == '*') { fullbright |= 2; p++; } - brokentex = tileForName(p); - if (brokentex < 0) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); + brokentex = TexMan.CheckForTexture(p, ETextureType::Any, FTextureManager::TEXMAN_TryAny); + if (!brokentex.isValid()) sc.ScriptMessage("Unknown texture '%s' in definition for spawn ID # %d", sc.String, num); } if (sc.CheckString(",")) { diff --git a/source/core/g_mapinfo.h b/source/core/g_mapinfo.h index 551cf0210..3f48cdbee 100644 --- a/source/core/g_mapinfo.h +++ b/source/core/g_mapinfo.h @@ -42,7 +42,7 @@ struct SpawnRec { PClassActor* cls; - int basetex, brokentex; + FTextureID basetex, brokentex; FSoundID breaksound; int8_t fullbright, clipdist; int16_t flags; diff --git a/source/core/maptypes.h b/source/core/maptypes.h index 3399a07e5..7f59daad1 100644 --- a/source/core/maptypes.h +++ b/source/core/maptypes.h @@ -385,7 +385,7 @@ struct sectortype { struct // DukeRR { - uint8_t keyinfo; // This was originally the repurposed filler byte. + uint8_t lockinfo; // This was originally the repurposed filler byte. uint8_t shadedsector; TObjPtr hitagactor; // we need this because Duke stores an actor in the hitag field. Is really a DDukeActor, but cannot be declared here safely. }; diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index 1d1563acd..cd23ebeeb 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -479,7 +479,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectort // Save the extensions only when playing their respective games. if (isDukeEngine()) { - arc("keyinfo", c.keyinfo, def->keyinfo) + arc("keyinfo", c.lockinfo, def->lockinfo) ("shadedsector", c.shadedsector, def->shadedsector) ("hitagactor", c.hitagactor, def->hitagactor); diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index 7f212047c..f47cd4559 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -920,7 +920,7 @@ void destroyit(DDukeActor *actor) destsect->floorxpan_ = srcsect->floorxpan_; destsect->floorypan_ = srcsect->floorypan_; destsect->visibility = srcsect->visibility; - destsect->keyinfo = srcsect->keyinfo; + destsect->lockinfo = srcsect->lockinfo; destsect->lotag = srcsect->lotag; destsect->hitag = srcsect->hitag; destsect->extra = srcsect->extra; diff --git a/source/games/duke/src/classnames.h b/source/games/duke/src/classnames.h index e0189d1e5..761479f1e 100644 --- a/source/games/duke/src/classnames.h +++ b/source/games/duke/src/classnames.h @@ -129,3 +129,4 @@ xx(RedneckShotgun) xx(RedneckRipsaw) xx(RedneckBlaster) xx(RedneckPowderKeg) +xx(RedneckCow) diff --git a/source/games/duke/src/funct.h b/source/games/duke/src/funct.h index d98e7f0df..51672eb1a 100644 --- a/source/games/duke/src/funct.h +++ b/source/games/duke/src/funct.h @@ -119,7 +119,7 @@ int findotherplayer(int p, double* d); void quickkill(player_struct* p); int setpal(player_struct* p); int madenoise(int playerNum); -int haskey(sectortype* sect, int snum); +int haslock(sectortype* sect, int snum); void purplelavacheck(player_struct* p); void addphealth(player_struct* p, int amount, bool bigitem); int playereat(player_struct* p, int amount, bool bigitem); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 69e6f3955..8c11408d9 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -438,16 +438,16 @@ void GameInterface::FinalizeSetup() auto info = spawnMap.CheckKey(i); PClassActor* cls = nullptr; - if (info != nullptr && info->basetex <= 0) + if (info != nullptr && !info->basetex.isValid()) { cls = info->cls; } - else if (info == nullptr || info->basetex <= 0) + else if (info == nullptr || !info->basetex.isValid()) { // No unique actor exists here. Since we need one, create a new class here, directly derived from DDukeActor. auto newcls = (PClassActor*)RUNTIME_CLASS(DDukeActor)->CreateDerivedClass(FStringf("NewConActor%d", i), RUNTIME_CLASS(DDukeActor)->Size); newcls->InitializeDefaults(); - spawnMap.Insert(i, { newcls, -1, -1, NO_SOUND, int8_t(0), int8_t(0), int16_t(0x8000) }); + spawnMap.Insert(i, { newcls, FNullTextureID(), FNullTextureID(), NO_SOUND, int8_t(0), int8_t(0), int16_t(0x8000) }); cls = newcls; GetDefaultByType(newcls)->spr.picnum = i; // make it show the right pic. } diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 71084b34d..b1752d4b4 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1756,7 +1756,7 @@ int ParseState::parse(void) ps[g_p].tipincs = 26; break; case concmd_iftipcow: - case concmd_ifhittruck: // both have the same code. + case concmd_ifhittruck: // both have the same code. Note that 'iftipcpw' ONLY works when used on the cow! if (g_ac->spriteextra == 1) // { j = 1; diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index 46f46c8ce..5d59b367e 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -988,22 +988,22 @@ bool movementBlocked(player_struct *p) // //--------------------------------------------------------------------------- -int haskey(sectortype* sectp, int snum) +int haslock(sectortype* sectp, int snum) { auto p = &ps[snum]; if (!sectp) return 0; - if (!sectp->keyinfo) + if (!sectp->lockinfo) return 1; - if (sectp->keyinfo > 6) + if (sectp->lockinfo > 6) return 1; - int wk = sectp->keyinfo; + int wk = sectp->lockinfo; if (wk > 3) wk -= 3; if (p->keys[wk] == 1) { - sectp->keyinfo = 0; + sectp->lockinfo = 0; return 1; } diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp index 1706a0484..06394137e 100644 --- a/source/games/duke/src/premap_r.cpp +++ b/source/games/duke/src/premap_r.cpp @@ -556,7 +556,7 @@ void prelevel_r(int g, TArray& actors) actor->Destroy(); if (actor->GetClass() == RedneckKeyinfoSetterClass) { - actor->sector()->keyinfo = uint8_t(actor->spr.lotag); + actor->sector()->lockinfo = uint8_t(actor->spr.lotag); actor->Destroy(); } } diff --git a/source/games/duke/src/sectors_d.cpp b/source/games/duke/src/sectors_d.cpp index ae364e7b5..8a4407f2e 100644 --- a/source/games/duke/src/sectors_d.cpp +++ b/source/games/duke/src/sectors_d.cpp @@ -412,7 +412,7 @@ void checksectors_d(int snum) return; if (near.actor() == nullptr && near.hitWall == nullptr) - if (p->cursector->lotag == 2) + if (p->cursector->lotag == ST_2_UNDERWATER) { DDukeActor* hit; dist = hitasprite(p->GetActor(), &hit); diff --git a/source/games/duke/src/sectors_r.cpp b/source/games/duke/src/sectors_r.cpp index e3e9ad9b8..ba7b4b434 100644 --- a/source/games/duke/src/sectors_r.cpp +++ b/source/games/duke/src/sectors_r.cpp @@ -388,9 +388,8 @@ void checksectors_r(int snum) if (near.actor()->flags2 & SFLAG2_TRIGGERRESPAWN) return; - switch (near.actor()->spr.picnum) + if (near.actor()->IsKindOf(RedneckCowClass)) // This is for a VERY poorly implemented CON hack. See 'iftipcow'. { - case RTILE_COW: near.actor()->spriteextra = 1; return; } @@ -408,7 +407,7 @@ void checksectors_r(int snum) return; if (near.actor() == nullptr && near.hitWall == nullptr) - if (p->cursector->lotag == 2) + if (p->cursector->lotag == ST_2_UNDERWATER) { DDukeActor* hit; double dist = hitasprite(p->GetActor(), &hit); @@ -457,7 +456,7 @@ void checksectors_r(int snum) if (isactivator(act) || ismasterswitch(act)) return; } - if (haskey(near.hitSector, snum)) + if (haslock(near.hitSector, snum)) operatesectors(near.hitSector, p->GetActor()); else { @@ -478,7 +477,7 @@ void checksectors_r(int snum) if (isactivator(act) || ismasterswitch(act)) return; } - if (haskey(near.hitSector, snum)) + if (haslock(near.hitSector, snum)) operatesectors(p->GetActor()->sector(), p->GetActor()); else { diff --git a/source/games/duke/src/spawn.cpp b/source/games/duke/src/spawn.cpp index ad7db2119..61d23a852 100644 --- a/source/games/duke/src/spawn.cpp +++ b/source/games/duke/src/spawn.cpp @@ -50,11 +50,11 @@ void setFromSpawnRec(DDukeActor* act, SpawnRec* info) act->curAction = &actions[0]; if (info) { - if (info->basetex > 0 && act->IsKindOf(DukeGenericDestructibleClass)) + if (info->basetex.isValid() && act->IsKindOf(DukeGenericDestructibleClass)) { // allow defining simple destructibles without actual actor definitions. - act->IntVar(NAME_spawnstate) = info->basetex; - act->IntVar(NAME_brokenstate) = info->brokentex; + act->IntVar(NAME_spawnstate) = info->basetex.GetIndex(); + act->IntVar(NAME_brokenstate) = info->brokentex.GetIndex(); act->IntVar(NAME_breaksound) = info->breaksound.index(); act->IntVar(NAME_fullbright) = info->fullbright; act->spr.inittype = info->flags; @@ -63,7 +63,7 @@ void setFromSpawnRec(DDukeActor* act, SpawnRec* info) else { // same for simple sprite replacements with existing implementations. - if (info->basetex >= 0 && info->basetex < MAXTILES) act->spr.picnum = info->basetex; + if (info->basetex.isValid()) act->spr.setspritetexture(info->basetex); if (info->fullbright & 1) act->spr.cstat2 |= CSTAT2_SPRITE_FULLBRIGHT; } } diff --git a/source/games/duke/src/vmexports.cpp b/source/games/duke/src/vmexports.cpp index 098157883..530e23b09 100644 --- a/source/games/duke/src/vmexports.cpp +++ b/source/games/duke/src/vmexports.cpp @@ -1838,14 +1838,14 @@ DEFINE_ACTION_FUNCTION_NATIVE(_tspritetype, copyfloorpal, copyfloorpal) return 0; } -// this must still work around the lack of proper texture support on the script side. +// this must still work around the lack of proper texture support on the script side and should go away once sprites have proper texture support DEFINE_ACTION_FUNCTION(DDukeGenericDestructible, SetBroken) { PARAM_SELF_STRUCT_PROLOGUE(DDukeActor); PARAM_INT(bust); - int tilenum = self->IntVar(bust ? NAME_brokenstate : NAME_spawnstate); - if (tilenum >= 0) self->spr.picnum = tilenum; - ACTION_RETURN_BOOL(tilenum < 0); + FSetTextureID tilenum(self->IntVar(bust ? NAME_brokenstate : NAME_spawnstate)); + if (tilenum.isValid()) self->spr.setspritetexture(tilenum); + ACTION_RETURN_BOOL(!tilenum.isValid()); }