diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index 41941c3b4..e424a807d 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -87,6 +87,13 @@ extern int cameradist, cameraclock; void loaddefinitionsfile(const char* fn, bool cumulative = false, bool maingrp = false); bool calcChaseCamPos(int* px, int* py, int* pz, spritetype* pspr, int *psectnum, binangle ang, fixedhoriz horiz, double const smoothratio); +inline bool calcChaseCamPos(int* px, int* py, int* pz, spritetype* pspr, sectortype** psectnum, binangle ang, fixedhoriz horiz, double const smoothratio) +{ + int sectnum; + bool res = calcChaseCamPos(px, py, pz, pspr, §num, ang, horiz, smoothratio); + *psectnum = §or[sectnum]; + return res; +} void PlanesAtPoint(const sectortype* sec, int dax, int day, float* ceilz, float* florz); inline void PlanesAtPoint(const sectortype* sec, float dax, float day, float* ceilz, float* florz) // this is just for warning evasion. diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index 03f82dcec..f44c3dc24 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -13,6 +13,7 @@ bool System_WantGuiCapture(); // During playing this tells us whether the game m class FSerializer; struct FRenderViewpoint; struct spritetype; +struct sectortype; struct GameStats { @@ -118,7 +119,7 @@ struct GameInterface virtual void UpdateCameras(double smoothratio) {} virtual void EnterPortal(spritetype* viewer, int type) {} virtual void LeavePortal(spritetype* viewer, int type) {} - virtual bool GetGeoEffect(GeoEffect* eff, int viewsector) { return false; } + virtual bool GetGeoEffect(GeoEffect* eff, sectortype* viewsector) { return false; } virtual int Voxelize(int sprnum) { return -1; } virtual void AddExcludedEpisode(const FString& episode) {} virtual int GetCurrentSkill() { return -1; } diff --git a/source/core/rendering/scene/hw_drawinfo.cpp b/source/core/rendering/scene/hw_drawinfo.cpp index e225515e4..e2b4e9d3c 100644 --- a/source/core/rendering/scene/hw_drawinfo.cpp +++ b/source/core/rendering/scene/hw_drawinfo.cpp @@ -403,7 +403,7 @@ void HWDrawInfo::CreateScene(bool portal) int drawsect = effsect; // RR geometry hack. Ugh... // This just adds to the existing render list, so we must offset the effect areas to the same xy-space as the main one as we cannot change the view matrix. - if (gi->GetGeoEffect(&eff, effsect)) + if (gi->GetGeoEffect(&eff, §or[effsect])) { ingeo = true; geoofs = { (float)eff.geox[0], (float)eff.geoy[0] }; diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 65ffde440..e230126ea 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -67,7 +67,7 @@ struct GameInterface : public ::GameInterface void UpdateCameras(double smoothratio) override; void EnterPortal(spritetype* viewer, int type) override; void LeavePortal(spritetype* viewer, int type) override; - bool GetGeoEffect(GeoEffect* eff, int viewsector) override; + bool GetGeoEffect(GeoEffect* eff, sectortype* viewsector) override; void AddExcludedEpisode(const FString& episode) override; int GetCurrentSkill() override; diff --git a/source/games/duke/src/prediction.cpp b/source/games/duke/src/prediction.cpp index 599c4e4ce..485c3a0c8 100644 --- a/source/games/duke/src/prediction.cpp +++ b/source/games/duke/src/prediction.cpp @@ -117,12 +117,12 @@ void fakedomovethings(void) actions = syn->actions; psect = mycursectnum; - psectlotag = sector[psect].lotag; + psectlotag = psect->lotag; spritebridge = 0; shrunk = (p->GetActor()->s.yrepeat < (isRR()? 8 : 32)); - if( ud.clipping == 0 && ( sector[psect].floorpicnum == MIRROR || psect < 0 || psect >= MAXSECTORS) ) + if( ud.clipping == 0 && ( psect->floorpicnum == MIRROR || psect == nullptr) ) { myx = omyx; myy = omyy; @@ -145,7 +145,7 @@ void fakedomovethings(void) if(clz.type == kHitSector && psectlotag == 1 && abs(myz-j) > gs.playerheight+(16<<8) ) psectlotag = 0; - if( p->aim_mode == 0 && myonground && psectlotag != 2 && (sector[psect].floorstat&2) ) + if( p->aim_mode == 0 && myonground && psectlotag != 2 && (psect->floorstat&2) ) { x = myx + bcos(myang, -5); y = myy + bsin(myang, -5); @@ -296,7 +296,7 @@ void fakedomovethings(void) } if(myz < (fz-(i<<8)) && (floorspace(psect)|ceilingspace(psect)) == 0 ) //falling { - if( (sb_snum&3) == 0 && !(p->OnMotorcycle || p->OnBoat) && myonground && (sector[psect].floorstat&2) && myz >= (fz-(i<<8)-(16<<8) ) ) + if( (sb_snum&3) == 0 && !(p->OnMotorcycle || p->OnBoat) && myonground && (psect->floorstat&2) && myz >= (fz-(i<<8)-(16<<8) ) ) myz = fz-(i<<8); else { diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index 0175398ca..17d2f8d85 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -141,9 +141,9 @@ void GameInterface::LeavePortal(spritetype* viewer, int type) if (type == PORTAL_WALL_MIRROR) display_mirror--; } -bool GameInterface::GetGeoEffect(GeoEffect* eff, int viewsector) +bool GameInterface::GetGeoEffect(GeoEffect* eff, sectortype* viewsector) { - if (isRR() && sector[viewsector].lotag == 848) + if (isRR() && viewsector->lotag == 848) { eff->geocnt = geocnt; eff->geosector = geosector; @@ -252,7 +252,6 @@ static int getdrugmode(player_struct *p, int oyrepeat) void displayrooms(int snum, double smoothratio) { int cposx, cposy, cposz, fz, cz; - int sect; binangle cang, rotscrnang; fixedhoriz choriz; struct player_struct* p; @@ -273,8 +272,8 @@ void displayrooms(int snum, double smoothratio) videoSetCorrectedAspect(); - sect = p->cursectnum; - if (sect < 0 || sect >= MAXSECTORS) return; + auto sect = p->cursector(); + if (sect == nullptr) return; GlobalMapFog = fogactive ? 0x999999 : 0; GlobalFogDensity = fogactive ? 350.f : 0.f; @@ -310,6 +309,7 @@ void displayrooms(int snum, double smoothratio) // set screen rotation. rotscrnang = !SyncInput() ? p->angle.rotscrnang : p->angle.interpolatedrotscrn(smoothratio); +#if 0 if ((snum == myconnectindex) && (numplayers > 1)) { cposx = interpolatedvalue(omyx, myx, smoothratio); @@ -328,6 +328,7 @@ void displayrooms(int snum, double smoothratio) sect = mycursectnum; } else +#endif { cposx = interpolatedvalue(p->oposx, p->pos.x, smoothratio); cposy = interpolatedvalue(p->oposy, p->pos.y, smoothratio); @@ -355,7 +356,7 @@ void displayrooms(int snum, double smoothratio) cposx = spr->pos.x; cposy = spr->pos.y; cposz = spr->pos.z; - sect = spr->sectnum; + sect = spr->sector(); rotscrnang = buildang(0); smoothratio = MaxSmoothRatio; viewer = spr; @@ -394,23 +395,23 @@ void displayrooms(int snum, double smoothratio) else if (cposz > (p->truefz - (4 << 8))) cposz = fz - (4 << 8); } - if (sect >= 0) + if (sect) { - getzsofslope(sect, cposx, cposy, &cz, &fz); + getzsofslopeptr(sect, cposx, cposy, &cz, &fz); if (cposz < cz + (4 << 8)) cposz = cz + (4 << 8); if (cposz > fz - (4 << 8)) cposz = fz - (4 << 8); } choriz = clamp(choriz, q16horiz(gi->playerHorizMin()), q16horiz(gi->playerHorizMax())); - if (isRR() && sector[sect].lotag == 848 && !testnewrenderer) + if (isRR() && sect->lotag == 848 && !testnewrenderer) { renderSetRollAngle((float)rotscrnang.asbuildf()); - geometryEffect(cposx, cposy, cposz, cang, choriz, sect, (int)smoothratio); + geometryEffect(cposx, cposy, cposz, cang, choriz, sectnum(sect), (int)smoothratio); } else { - renderView(viewer, sect, cposx, cposy, cposz, cang, choriz, rotscrnang, (int)smoothratio); + renderView(viewer, sectnum(sect), cposx, cposy, cposz, cang, choriz, rotscrnang, (int)smoothratio); } } //GLInterface.SetMapFog(false);