From 0b254255e21ee2a7b86e981b31a3b963a8290e21 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 22 Nov 2021 20:18:14 +0100 Subject: [PATCH] - sector ambience --- source/build/include/buildtypes.h | 2 +- source/core/maploader.cpp | 1 - source/core/savegamehelp.cpp | 2 +- source/games/exhumed/src/init.cpp | 12 ----- source/games/exhumed/src/object.cpp | 70 +++++++++++------------------ source/games/exhumed/src/sound.cpp | 10 ++--- 6 files changed, 32 insertions(+), 65 deletions(-) diff --git a/source/build/include/buildtypes.h b/source/build/include/buildtypes.h index 8bdf6cf5f..2756dd101 100644 --- a/source/build/include/buildtypes.h +++ b/source/build/include/buildtypes.h @@ -104,7 +104,7 @@ struct sectortype }; struct // Exhumed { - int SoundSect; + sectortype* pSoundSect; int Depth; int Above; int Below; diff --git a/source/core/maploader.cpp b/source/core/maploader.cpp index bbf07e28d..de1458eb3 100644 --- a/source/core/maploader.cpp +++ b/source/core/maploader.cpp @@ -474,7 +474,6 @@ void engineLoadBoard(const char* filename, int flags, vec3_t* pos, int16_t* ang, // This way they just get copied to the sector backup array. These 4 are the only values in all games needing such treatment. if (isExhumed()) { - sector[i].SoundSect = -1; sector[i].Sound = -1; sector[i].Above = -1; sector[i].Below = -1; diff --git a/source/core/savegamehelp.cpp b/source/core/savegamehelp.cpp index c238a8f72..023a93d4c 100644 --- a/source/core/savegamehelp.cpp +++ b/source/core/savegamehelp.cpp @@ -573,7 +573,7 @@ FSerializer &Serialize(FSerializer &arc, const char *key, sectortype &c, sectort } else if (isExhumed()) { - arc("SoundSect", c.SoundSect, def->SoundSect) + arc("SoundSect", c.pSoundSect, def->pSoundSect) ("Depth", c.Depth, def->Depth) ("Above", c.Above, def->Above) ("Below", c.Below, def->Below) diff --git a/source/games/exhumed/src/init.cpp b/source/games/exhumed/src/init.cpp index a321de8de..598cfa3e9 100644 --- a/source/games/exhumed/src/init.cpp +++ b/source/games/exhumed/src/init.cpp @@ -243,17 +243,6 @@ void SnapSectors(int nSectorA, int nSectorB, int b) } } -void InitSectFlag() -{ - for(auto& Sect : sectors()) - { - Sect.SoundSect = -1; - Sect.Sound = -1; - Sect.Above = -1; - Sect.Below = -1; - } -} - void ProcessSpriteTag(DExhumedActor* pActor, int nLotag, int nHitag) { auto pSprite = &pActor->s(); @@ -778,7 +767,6 @@ void LoadObjects() InitSwitch(); InitElev(); InitWallFace(); - InitSectFlag(); for (auto& sect : sectors()) { diff --git a/source/games/exhumed/src/object.cpp b/source/games/exhumed/src/object.cpp index 7ff7f2e09..46fee2ebf 100644 --- a/source/games/exhumed/src/object.cpp +++ b/source/games/exhumed/src/object.cpp @@ -1482,21 +1482,18 @@ void DimLights() if (word_96786 == 0) return; - for (int i = 0; i < numsectors; i++) + for (auto§ : sectors()) { - if (sector[i].ceilingshade < 100) - sector[i].ceilingshade++; + if (sect.ceilingshade < 100) + sect.ceilingshade++; - if (sector[i].floorshade < 100) - sector[i].floorshade++; + if (sect.floorshade < 100) + sect.floorshade++; - int startwall = sector[i].wallptr; - int endwall = startwall + sector[i].wallnum; - - for (int nWall = startwall; nWall < endwall; nWall++) + for (auto& wal : wallsofsector(§)) { - if (wall[nWall].shade < 100) - wall[nWall].shade++; + if (wal.shade < 100) + wal.shade++; } } } @@ -2478,8 +2475,6 @@ void DoMovingSects() void PostProcess() { - int i, j; - for (unsigned i = 0; i < sMoveSect.Size(); i++) { int nTrail = sMoveSect[i].nTrail; @@ -2529,35 +2524,31 @@ void PostProcess() if (!(currentLevel->gameflags & LEVEL_EX_COUNTDOWN)) { - // esi is i - for (i = 0; i < numsectors; i++) + for (auto& sect : sectors()) { - auto secti = §or[i]; int var_20 = 30000; - if (secti->Speed && secti->Depth && !(secti->Flag & kSectLava)) + if (sect.Speed && sect.Depth && !(sect.Flag & kSectLava)) { - secti->SoundSect = i; - secti->Sound = StaticSound[kSound43]; + sect.pSoundSect = § + sect.Sound = StaticSound[kSound43]; } else { - // ebp and ecx are j - for (j = 0; j < numsectors; j++) + for (auto& sectj : sectors()) { - auto sectj = §or[j]; // loc_23CA6: - if (i != j && sectj->Speed && !(secti->Flag & kSectLava)) + if (§ != §j && sectj.Speed && !(sect.Flag & kSectLava)) { - int xVal = abs(secti->firstWall()->x - sectj->firstWall()->x); - int yVal = abs(secti->firstWall()->y - sectj->firstWall()->y); + int xVal = abs(sect.firstWall()->x - sectj.firstWall()->x); + int yVal = abs(sect.firstWall()->y - sectj.firstWall()->y); if (xVal < 15000 && yVal < 15000 && (xVal + yVal < var_20)) { var_20 = xVal + yVal; - secti->SoundSect = j; - secti->Sound = StaticSound[kSound43]; + sect.pSoundSect = §j; + sect.Sound = StaticSound[kSound43]; } } } @@ -2566,30 +2557,19 @@ void PostProcess() } else // nMap == kMap20) { - // int var_24 = 0; - int ebp = 0; - - for (i = 0; i < numsectors; i++) + for(auto& sect : sectors()) { - auto secti = §or[i]; - secti->SoundSect = i; - secti->Sound = StaticSound[kSound62]; + sect.pSoundSect = § + sect.Sound = StaticSound[kSound62]; - int startwall = sector[ebp].wallptr; - int endwall = sector[ebp].wallptr + sector[ebp].wallnum; - - int nWall = startwall; - - while (nWall < endwall) + for(auto& wal : wallsofsector(§)) { - if (wall[nWall].picnum == kTile3603) + if (wal.picnum == kTile3603) { - wall[nWall].pal = 1; - auto pActor = insertActor(i, 407); + wal.pal = 1; + auto pActor = insertActor(§, 407); pActor->s().cstat = 0x8000; } - - nWall++; } } diff --git a/source/games/exhumed/src/sound.cpp b/source/games/exhumed/src/sound.cpp index 89280436a..8640356db 100644 --- a/source/games/exhumed/src/sound.cpp +++ b/source/games/exhumed/src/sound.cpp @@ -676,11 +676,11 @@ void CheckAmbience(int nSector) auto sect = §or[nSector]; if (sect->Sound != -1) { - int nSector2 = sect->SoundSect; - walltype* pWall = sector[nSector2].firstWall(); + auto pSector2 = sect->pSoundSect; + walltype* pWall = pSector2->firstWall(); if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, &amb, 0)) { - vec3_t v = { pWall->x, pWall->y, sector[nSector2].floorz }; + vec3_t v = { pWall->x, pWall->y, pSector2->floorz }; amb = GetSoundPos(&v); soundEngine->StartSound(SOURCE_Ambient, &amb, nullptr, CHAN_BODY, CHANF_TRANSIENT, sect->Sound + 1, 1.f, ATTN_NORM); return; @@ -689,14 +689,14 @@ void CheckAmbience(int nSector) { if (chan->SourceType == SOURCE_Ambient) { - if (nSector == nSector2) + if (sect == pSector2) { spritetype* pSprite = &PlayerList[0].Actor()->s(); amb = GetSoundPos(&pSprite->pos); } else { - vec3_t v = { pWall->x, pWall->y, sector[nSector2].floorz }; + vec3_t v = { pWall->x, pWall->y, pSector2->floorz }; amb = GetSoundPos(&v); } return 1;