diff --git a/source/games/sw/src/_polymost.cpp b/source/games/sw/src/_polymost.cpp index ac1d6cd51..77cbb9153 100644 --- a/source/games/sw/src/_polymost.cpp +++ b/source/games/sw/src/_polymost.cpp @@ -53,9 +53,9 @@ void DrawOverlapRoom(int tx, int ty, int tz, fixed_t tq16ang, fixed_t tq16horiz, // reset Z's for (int i = 0; i < save.zcount; i++) { - save.sector[i]->floorz = save.zval[i]; - save.sector[i]->floorpicnum = save.pic[i]; - save.sector[i]->floorheinum = save.slope[i]; + save.sect[i]->floorz = save.zval[i]; + save.sect[i]->floorpicnum = save.pic[i]; + save.sect[i]->floorheinum = save.slope[i]; } analyzesprites(pm_tsprite, pm_spritesortcnt, tx, ty, tz, false); @@ -78,9 +78,9 @@ void DrawOverlapRoom(int tx, int ty, int tz, fixed_t tq16ang, fixed_t tq16horiz, // reset Z's for (int i = 0; i < save.zcount; i++) { - save.sector[i]->ceilingz = save.zval[i]; - save.sector[i]->ceilingpicnum = save.pic[i]; - save.sector[i]->ceilingheinum = save.slope[i]; + save.sect[i]->ceilingz = save.zval[i]; + save.sect[i]->ceilingpicnum = save.pic[i]; + save.sect[i]->ceilingheinum = save.slope[i]; } analyzesprites(pm_tsprite, pm_spritesortcnt, tx, ty, tz, false); diff --git a/source/games/sw/src/game.h b/source/games/sw/src/game.h index af60cfb9a..460bc6e27 100644 --- a/source/games/sw/src/game.h +++ b/source/games/sw/src/game.h @@ -1530,7 +1530,8 @@ typedef struct typedef struct SINE_WAVE_FLOOR { - int floor_origz, ceiling_origz, range, sector; + sectortype* sectp; + int floor_origz, ceiling_origz, range; int16_t sintable_ndx, speed_shift; uint8_t flags; } *SINE_WAVE_FLOORp; diff --git a/source/games/sw/src/jweapon.cpp b/source/games/sw/src/jweapon.cpp index 529aabc5b..e6fac4249 100644 --- a/source/games/sw/src/jweapon.cpp +++ b/source/games/sw/src/jweapon.cpp @@ -2117,7 +2117,7 @@ int DoCarryFlag(DSWActor* actor) u->WaitTics = SEC(1) / 2; } // if in score box, score. - if (sector[ap->sectnum].hitag == 9000 && sector[ap->sectnum].lotag == ap->pal + if (ap->sector()->hitag == 9000 && ap->sector()->lotag == ap->pal && ap->pal != sp->pal) { if (fown != nullptr) @@ -2256,7 +2256,7 @@ int DoCarryFlagNoDet(DSWActor* actor) } // if in score box, score. - if (sector[ap->sectnum].hitag == 9000 && sector[ap->sectnum].lotag == ap->pal + if (ap->sector()->hitag == 9000 && ap->sector()->lotag == ap->pal && ap->pal != sp->pal) { if (u->flagOwnerActor != nullptr) diff --git a/source/games/sw/src/rooms.cpp b/source/games/sw/src/rooms.cpp index 15bc36145..c4a97b919 100644 --- a/source/games/sw/src/rooms.cpp +++ b/source/games/sw/src/rooms.cpp @@ -43,7 +43,7 @@ BEGIN_SW_NS #define ZMAX 400 typedef struct { - sectortype* sector[ZMAX]; + sectortype* sect[ZMAX]; int32_t zval[ZMAX]; int16_t pic[ZMAX]; int16_t zcount; @@ -818,7 +818,7 @@ bool FindCeilingView(int match, int* x, int* y, int z, int* sectnum) if (sp->hitag == VIEW_LEVEL2) { // save it off - save.sector[save.zcount] = sp->sector(); + save.sect[save.zcount] = sp->sector(); save.zval[save.zcount] = sp->sector()->floorz; save.pic[save.zcount] = sp->sector()->floorpicnum; save.slope[save.zcount] = sp->sector()->floorheinum; @@ -914,7 +914,7 @@ bool FindFloorView(int match, int* x, int* y, int z, int* sectnum) if (sp->hitag == VIEW_LEVEL1) { // save it off - save.sector[save.zcount] = sp->sector(); + save.sect[save.zcount] = sp->sector(); save.zval[save.zcount] = sp->sector()->ceilingz; save.pic[save.zcount] = sp->sector()->ceilingpicnum; save.slope[save.zcount] = sp->sector()->ceilingheinum; diff --git a/source/games/sw/src/save.cpp b/source/games/sw/src/save.cpp index daa9e5c46..c33b3bc33 100644 --- a/source/games/sw/src/save.cpp +++ b/source/games/sw/src/save.cpp @@ -878,7 +878,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def FSerializer& Serialize(FSerializer& arc, const char* keyname, SINE_WAVE_FLOOR& w, SINE_WAVE_FLOOR* def) { - static SINE_WAVE_FLOOR nul = { -1,-1,-1,-1,-1,-1,255 }; + static SINE_WAVE_FLOOR nul = { nullptr,-1,-1,-1,-1,-1,255 }; if (!def) { def = &nul; @@ -890,7 +890,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, SINE_WAVE_FLOOR& w arc("floor_origz", w.floor_origz, def->floor_origz) ("ceiling_origz", w.ceiling_origz, def->ceiling_origz) ("range", w.range, def->range) - ("sector", w.sector, def->sector) + ("sector", w.sectp, def->sectp) ("sintable_ndx", w.sintable_ndx, def->sintable_ndx) ("speed_shift", w.speed_shift, def->speed_shift) ("flags", w.flags, def->flags) diff --git a/source/games/sw/src/sector.cpp b/source/games/sw/src/sector.cpp index ea6889f7c..834ce4c7d 100644 --- a/source/games/sw/src/sector.cpp +++ b/source/games/sw/src/sector.cpp @@ -61,7 +61,7 @@ enum ANIMATOR DoGrating; void DoPlayerBeginForceJump(PLAYERp); -short FindNextSectorByTag(short sectnum, int tag); +sectortype* FindNextSectorByTag(sectortype* sectnum, int tag); short LevelSecrets; bool TestVatorMatchActive(short match); bool TestSpikeMatchActive(short match); @@ -388,14 +388,14 @@ void SectorSetup(void) SectorObject[ndx].xmid = INT32_MAX; } - memset(SineWaveFloor, -1, sizeof(SineWaveFloor)); + memset(SineWaveFloor, 0, sizeof(SineWaveFloor)); memset(SpringBoard, -1, sizeof(SpringBoard)); LevelSecrets = 0; for (i = 0; i < numsectors; i++) { - auto sectp = §or[i]; + auto const sectp = §or[i]; tag = sectp->lotag; // /////////////////////////////////// @@ -465,7 +465,6 @@ void SectorSetup(void) case TAG_SINE_WAVE_BOTH: { SINE_WAVE_FLOOR *swf; - short near_sect = i, base_sect = i; uint16_t swf_ndx = 0; short cnt = 0, sector_cnt; int range; @@ -486,7 +485,7 @@ void SectorSetup(void) { case 0: SET(swf->flags, SINE_FLOOR); - if (TEST(sector[base_sect].floorstat, FLOOR_STAT_SLOPE)) + if (TEST(sectp->floorstat, FLOOR_STAT_SLOPE)) { SET(swf->flags, SINE_SLOPED); } @@ -500,37 +499,36 @@ void SectorSetup(void) } - swf->sector = near_sect; - ASSERT(sector[swf->sector].hitag != 0); - swf->range = range = Z(sector[swf->sector].hitag); - swf->floor_origz = sector[swf->sector].floorz - (range >> 2); - swf->ceiling_origz = sector[swf->sector].ceilingz - (range >> 2); + swf->sectp = sectp; + ASSERT(swf->sectp->hitag != 0); + swf->range = range = Z(swf->sectp->hitag); + swf->floor_origz = swf->sectp->floorz - (range >> 2); + swf->ceiling_origz = swf->sectp->ceilingz - (range >> 2); // look for the rest by distance + auto near_sectp = sectp, base_sectp = sectp; for (swf_ndx = 1, sector_cnt = 1; true; swf_ndx++) { - // near_sect = FindNextSectorByTag(base_sect, - // TAG_SINE_WAVE_FLOOR + swf_ndx); - near_sect = FindNextSectorByTag(base_sect, tag + swf_ndx); + near_sectp = FindNextSectorByTag(base_sectp, tag + swf_ndx); - if (near_sect >= 0) + if (near_sectp != nullptr) { swf = &SineWaveFloor[NextSineWave][swf_ndx]; - if (swf_ndx == 1 && sector[near_sect].hitag) - range_diff = sector[near_sect].hitag; - else if (swf_ndx == 2 && sector[near_sect].hitag) - speed_shift = sector[near_sect].hitag; - else if (swf_ndx == 3 && sector[near_sect].hitag) - peak_dist = sector[near_sect].hitag; + if (swf_ndx == 1 && near_sectp->hitag) + range_diff = near_sectp->hitag; + else if (swf_ndx == 2 && near_sectp->hitag) + speed_shift = near_sectp->hitag; + else if (swf_ndx == 3 && near_sectp->hitag) + peak_dist = near_sectp->hitag; - swf->sector = near_sect; - swf->floor_origz = sector[swf->sector].floorz - (range >> 2); - swf->ceiling_origz = sector[swf->sector].ceilingz - (range >> 2); + swf->sectp = near_sectp; + swf->floor_origz = swf->sectp->floorz - (range >> 2); + swf->ceiling_origz = swf->sectp->ceilingz - (range >> 2); range -= range_diff; swf->range = range; - base_sect = swf->sector; + base_sectp = swf->sectp; sector_cnt++; } else @@ -542,14 +540,14 @@ void SectorSetup(void) // more than 6 waves and something in high tag - set up wave // dissapate - if (sector_cnt > 8 && sector[base_sect].hitag) + if (sector_cnt > 8 && base_sectp->hitag) { - wave_diff = sector[base_sect].hitag; + wave_diff = base_sectp->hitag; } // setup the sintable_ndx based on the actual number of // sectors (swf_ndx) - for (swf = &SineWaveFloor[NextSineWave][0], cnt = 0; swf->sector >= 0 && swf < (SINE_WAVE_FLOORp)&SineWaveFloor[SIZ(SineWaveFloor)]; swf++, cnt++) + for (swf = &SineWaveFloor[NextSineWave][0], cnt = 0; swf->sectp != 0 && swf < (SINE_WAVE_FLOORp)&SineWaveFloor[SIZ(SineWaveFloor)]; swf++, cnt++) { if (peak_dist) swf->sintable_ndx = cnt * (2048 / peak_dist); @@ -579,8 +577,8 @@ void SectorSetup(void) swf->range = Z(4); // reset origz's based on new range - swf->floor_origz = sector[swf->sector].floorz - (swf->range >> 2); - swf->ceiling_origz = sector[swf->sector].ceilingz - (swf->range >> 2); + swf->floor_origz = swf->sectp->floorz - (swf->range >> 2); + swf->ceiling_origz = swf->sectp->ceilingz - (swf->range >> 2); } } @@ -651,7 +649,7 @@ void DoSpringBoardDown(void) return; } -short FindNextSectorByTag(short sect, int tag) +sectortype* FindNextSectorByTag(sectortype* sect, int tag) { for(auto& wal : wallsofsector(sect)) { @@ -659,12 +657,12 @@ short FindNextSectorByTag(short sect, int tag) { if (wal.nextSector()->lotag == tag) { - return sectnum(wal.nextSector()); + return wal.nextSector(); } } } - return -1; + return nullptr; } @@ -2473,7 +2471,7 @@ void DoSineWaveFloor(void) for (wave = 0; wave < MAX_SINE_WAVE; wave++) { - for (swf = &SineWaveFloor[wave][0], flags = swf->flags; swf->sector >= 0 && swf < &SineWaveFloor[wave][SIZ(SineWaveFloor[wave])]; swf++) + for (swf = &SineWaveFloor[wave][0], flags = swf->flags; swf->sectp != nullptr && swf < &SineWaveFloor[wave][SIZ(SineWaveFloor[wave])]; swf++) { swf->sintable_ndx = NORM_ANGLE(swf->sintable_ndx + (synctics << swf->speed_shift)); @@ -2481,13 +2479,13 @@ void DoSineWaveFloor(void) if (TEST(flags, SINE_FLOOR)) { newz = swf->floor_origz + MulScale(swf->range, bsin(swf->sintable_ndx), 14); - sector[swf->sector].floorz = newz; + swf->sectp->floorz = newz; } if (TEST(flags, SINE_CEILING)) { newz = swf->ceiling_origz + MulScale(swf->range, bsin(swf->sintable_ndx), 14); - sector[swf->sector].ceilingz = newz; + swf->sectp->ceilingz = newz; } } @@ -2505,9 +2503,9 @@ void DoSineWaveFloor(void) for (wave = 0; wave < MAX_SINE_WAVE; wave++) { - for (swf = &SineWaveFloor[wave][0], flags = swf->flags; swf->sector >= 0 && swf < &SineWaveFloor[wave][SIZ(SineWaveFloor[wave])]; swf++) + for (swf = &SineWaveFloor[wave][0], flags = swf->flags; swf->sectp != nullptr && swf < &SineWaveFloor[wave][SIZ(SineWaveFloor[wave])]; swf++) { - auto sect = §or[swf->sector]; + auto sect = swf->sectp; if (!TEST(sect->floorstat, FLOOR_STAT_SLOPE)) continue;