Skip to content

Commit

Permalink
- made cursectnum et. al. real pointers.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Dec 4, 2021
1 parent d2144aa commit 86bd606
Show file tree
Hide file tree
Showing 20 changed files with 240 additions and 285 deletions.
4 changes: 2 additions & 2 deletions source/games/sw/src/bunny.cpp
Expand Up @@ -1032,7 +1032,7 @@ int DoBunnyQuickJump(DSWActor* actor)
if (pp == Player+myconnectindex)
{
choose_snd = STD_RANDOM_RANGE(2<<8)>>8;
if (FAFcansee(sp->x,sp->y,SPRITEp_TOS(sp),sp->sector(),pp->posx, pp->posy, pp->posz, pp->cursector()) && Facing(actor, u->targetActor))
if (FAFcansee(sp->x,sp->y,SPRITEp_TOS(sp),sp->sector(),pp->posx, pp->posy, pp->posz, pp->cursector) && Facing(actor, u->targetActor))
PlayerSound(fagsnds[choose_snd], v3df_doppler|v3df_follow|v3df_dontpan,pp);
}
}
Expand All @@ -1047,7 +1047,7 @@ int DoBunnyQuickJump(DSWActor* actor)
if (pp == Player+myconnectindex)
{
choose_snd = STD_RANDOM_RANGE(3<<8)>>8;
if (FAFcansee(sp->x,sp->y,SPRITEp_TOS(sp),sp->sector(),pp->posx, pp->posy, pp->posz, pp->cursector()) && Facing(actor, u->targetActor))
if (FAFcansee(sp->x,sp->y,SPRITEp_TOS(sp),sp->sector(),pp->posx, pp->posy, pp->posz, pp->cursector) && Facing(actor, u->targetActor))
PlayerSound(straightsnds[choose_snd], v3df_doppler|v3df_follow|v3df_dontpan,pp);
}
}
Expand Down
41 changes: 13 additions & 28 deletions source/games/sw/src/draw.cpp
Expand Up @@ -1091,8 +1091,8 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, sectortype** tsect, binan
ang_test = getincangle(ang.asbuild(), sp->ang) < sp->lotag;

FAFcansee_test =
(FAFcansee(sp->x, sp->y, sp->z, sp->sector(), *tx, *ty, *tz, pp->cursector()) ||
FAFcansee(sp->x, sp->y, sp->z, sp->sector(), *tx, *ty, *tz + SPRITEp_SIZE_Z(&pp->Actor()->s()), pp->cursector()));
(FAFcansee(sp->x, sp->y, sp->z, sp->sector(), *tx, *ty, *tz, pp->cursector) ||
FAFcansee(sp->x, sp->y, sp->z, sp->sector(), *tx, *ty, *tz + SPRITEp_SIZE_Z(&pp->Actor()->s()), pp->cursector));

player_in_camera = ang_test && FAFcansee_test;

Expand Down Expand Up @@ -1429,18 +1429,14 @@ drawscreen(PLAYERp pp, double smoothratio)
int tx, ty, tz;
binangle tang, trotscrnang;
fixedhoriz thoriz;
int tsectnum;
sectortype* tsect;
short i,j;
int bob_amt = 0;
int quake_z, quake_x, quake_y;
short quake_ang;
extern bool FAF_DebugView;
PLAYERp camerapp; // prediction player if prediction is on, else regular player

// last valid stuff
static short lv_sectnum = -1;
static int lv_x, lv_y, lv_z;

int const viewingRange = viewingrange;

DrawScreen = true;
Expand Down Expand Up @@ -1482,18 +1478,9 @@ drawscreen(PLAYERp pp, double smoothratio)
thoriz = pp->horizon.sum();
trotscrnang = pp->angle.rotscrnang;
}
tsectnum = camerapp->cursectnum;

updatesector(tx, ty, &tsectnum);
tsect = camerapp->cursector;

if (tsectnum >= 0)
{
// last valid stuff
lv_sectnum = tsectnum;
lv_x = tx;
lv_y = ty;
lv_z = tz;
}
updatesector(tx, ty, &tsect);

if (pp->sop_riding || pp->sop_control)
{
Expand All @@ -1505,8 +1492,8 @@ drawscreen(PLAYERp pp, double smoothratio)
tz = pp->posz;
tang = pp->angle.ang;
}
tsectnum = pp->cursectnum;
updatesectorz(tx, ty, tz, &tsectnum);
tsect = pp->cursector;
updatesectorz(tx, ty, tz, &tsect);
}

pp->six = tx;
Expand All @@ -1531,15 +1518,14 @@ drawscreen(PLAYERp pp, double smoothratio)
tang = bvectangbam(pp->sop_remote->xmid - tx, pp->sop_remote->ymid - ty);
}

auto pSect = &sector[tsectnum];
if (TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE))
{
tz -= 8448;

if (!calcChaseCamPos(&tx, &ty, &tz, &pp->Actor()->s(), &pSect, tang, thoriz, smoothratio))
if (!calcChaseCamPos(&tx, &ty, &tz, &pp->Actor()->s(), &tsect, tang, thoriz, smoothratio))
{
tz += 8448;
calcChaseCamPos(&tx, &ty, &tz, &pp->Actor()->s(), &pSect, tang, thoriz, smoothratio);
calcChaseCamPos(&tx, &ty, &tz, &pp->Actor()->s(), &tsect, tang, thoriz, smoothratio);
}
}
else
Expand All @@ -1548,10 +1534,9 @@ drawscreen(PLAYERp pp, double smoothratio)

if (CameraTestMode)
{
CameraView(camerapp, &tx, &ty, &tz, &pSect, &tang, &thoriz);
CameraView(camerapp, &tx, &ty, &tz, &tsect, &tang, &thoriz);
}
}
tsectnum = sectnum(pSect);

if (!TEST(pp->Flags, PF_VIEW_FROM_CAMERA|PF_VIEW_FROM_OUTSIDE))
{
Expand All @@ -1575,12 +1560,12 @@ drawscreen(PLAYERp pp, double smoothratio)
if (!testnewrenderer)
{
renderSetRollAngle((float)trotscrnang.asbuildf());
polymost_drawscreen(pp, tx, ty, tz, tang, thoriz, pSect);
polymost_drawscreen(pp, tx, ty, tz, tang, thoriz, tsect);
}
else
{
UpdateWallPortalState();
render_drawrooms(&pp->Actor()->s(), { tx, ty, tz }, tsectnum, tang, thoriz, trotscrnang, smoothratio);
render_drawrooms(&pp->Actor()->s(), { tx, ty, tz }, sectnum(tsect), tang, thoriz, trotscrnang, smoothratio);
RestorePortalState();
}

Expand All @@ -1595,7 +1580,7 @@ drawscreen(PLAYERp pp, double smoothratio)
}


MarkSectorSeen(pp->cursectnum);
MarkSectorSeen(sectnum(pp->cursector));

if ((automapMode != am_off) && pp == Player+myconnectindex)
{
Expand Down
4 changes: 3 additions & 1 deletion source/games/sw/src/game.cpp
Expand Up @@ -327,7 +327,9 @@ void InitLevel(MapRecord *maprec)

int16_t ang;
currentLevel = maprec;
engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &Player[0].cursectnum);
int cursect;
engineLoadBoard(maprec->fileName, SW_SHAREWARE ? 1 : 0, &Player[0].pos, &ang, &cursect);
Player[0].cursector = &sector[cursect];

SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name);
STAT_NewLevel(currentLevel->fileName);
Expand Down
17 changes: 8 additions & 9 deletions source/games/sw/src/game.h
Expand Up @@ -737,7 +737,6 @@ struct PLAYERstruct
int oposx, oposy, oposz;

// holds last valid move position
int lv_sectnum;
int lv_x,lv_y,lv_z;

REMOTE_CONTROL remote;
Expand Down Expand Up @@ -769,12 +768,14 @@ struct PLAYERstruct
int16_t circle_camera_ang;
int16_t camera_check_time_delay;

int cursectnum,lastcursectnum;
sectortype* cursector() { return cursectnum < 0? nullptr : &sector[cursectnum]; }
sectortype* lastcursector() { return lastcursectnum < 0 ? nullptr : &sector[lastcursectnum]; }
void setcursector(sectortype* s) { cursectnum = sectnum(s); }
bool insector() const { return cursectnum >= 0; }
void backupcursector() { lastcursectnum = cursectnum; }

sectortype
* cursector,
* lastcursector,
* lv_sector;

void setcursector(sectortype* s) { cursector = s; }
bool insector() const { return cursector != nullptr; }
fixed_t turn180_target; // 180 degree turn

// variables that do not fit into sprite structure
Expand Down Expand Up @@ -905,8 +906,6 @@ struct PLAYERstruct
int cookieTime;

uint8_t WpnReloadState;

sectortype* cursector() const { return &sector[cursectnum]; }
};

extern PLAYER Player[MAX_SW_PLAYERS_REG+1];
Expand Down
10 changes: 5 additions & 5 deletions source/games/sw/src/jsector.cpp
Expand Up @@ -417,7 +417,7 @@ void JS_InitMirrors(void)
// Draw a 3d screen to a specific tile
/////////////////////////////////////////////////////
void drawroomstotile(int daposx, int daposy, int daposz,
binangle ang, fixedhoriz horiz, short dacursectnum, short tilenume, double smoothratio)
binangle ang, fixedhoriz horiz, sectortype* dacursect, short tilenume, double smoothratio)
{
auto canvas = renderSetTarget(tilenume);
if (!canvas) return;
Expand All @@ -426,13 +426,13 @@ void drawroomstotile(int daposx, int daposy, int daposz,
{
if (!testnewrenderer)
{
renderDrawRoomsQ16(daposx, daposy, daposz, ang.asq16(), horiz.asq16(), dacursectnum, false);
renderDrawRoomsQ16(daposx, daposy, daposz, ang.asq16(), horiz.asq16(), sectnum(dacursect), false);
analyzesprites(pm_tsprite, pm_spritesortcnt, daposx, daposy, daposz, ang.asbuild());
renderDrawMasks();
}
else
{
render_camtex(nullptr, { daposx, daposy, daposz }, dacursectnum, ang, horiz, buildang(0), tileGetTexture(tilenume), rect, smoothratio);
render_camtex(nullptr, { daposx, daposy, daposz }, sectnum(dacursect), ang, horiz, buildang(0), tileGetTexture(tilenume), rect, smoothratio);
}
});

Expand Down Expand Up @@ -657,11 +657,11 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz, double smoothratio)

if (TEST_BOOL11(sp) && numplayers > 1)
{
drawroomstotile(cp->posx, cp->posy, cp->posz, cp->angle.ang, cp->horizon.horiz, cp->cursectnum, mirror[cnt].campic, smoothratio);
drawroomstotile(cp->posx, cp->posy, cp->posz, cp->angle.ang, cp->horizon.horiz, cp->cursector, mirror[cnt].campic, smoothratio);
}
else
{
drawroomstotile(sp->x, sp->y, sp->z, buildang(SP_TAG5(sp)), camhoriz, sp->sectnum, mirror[cnt].campic, smoothratio);
drawroomstotile(sp->x, sp->y, sp->z, buildang(SP_TAG5(sp)), camhoriz, sp->sector(), mirror[cnt].campic, smoothratio);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/jweapon.cpp
Expand Up @@ -1315,7 +1315,7 @@ int PlayerInitChemBomb(PLAYERp pp)

// Spawn a shot
// Inserting and setting up variables
auto actorNew = SpawnActor(STAT_MISSILE, CHEMBOMB, s_ChemBomb, pp->cursector(),
auto actorNew = SpawnActor(STAT_MISSILE, CHEMBOMB, s_ChemBomb, pp->cursector,
nx, ny, nz, pp->angle.ang.asbuild(), CHEMBOMB_VELOCITY);

wp = &actorNew->s();
Expand Down Expand Up @@ -1738,7 +1738,7 @@ int PlayerInitCaltrops(PLAYERp pp)
ny = pp->posy;
nz = pp->posz + pp->bob_z + Z(8);

auto spawnedActor = SpawnActor(STAT_DEAD_ACTOR, CALTROPS, s_Caltrops, pp->cursector(),
auto spawnedActor = SpawnActor(STAT_DEAD_ACTOR, CALTROPS, s_Caltrops, pp->cursector,
nx, ny, nz, pp->angle.ang.asbuild(), (CHEMBOMB_VELOCITY + RandomRange(CHEMBOMB_VELOCITY)) / 2);

wp = &spawnedActor->s();
Expand Down
20 changes: 7 additions & 13 deletions source/games/sw/src/mclip.cpp
Expand Up @@ -64,10 +64,7 @@ Collision MultiClipMove(PLAYERp pp, int z, int floor_dist)
xvect = sop->clipbox_vdist[i] * bcos(ang);
yvect = sop->clipbox_vdist[i] * bsin(ang);
Collision coll;
#pragma message(__FILE__ "remove workaround");
sectortype* cursect = pp->cursector();
clipmove(spos, &cursect, xvect, yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll, 1);
pp->setcursector(cursect);
clipmove(spos, &pp->cursector, xvect, yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll, 1);

if (coll.type != kHitNone)
{
Expand Down Expand Up @@ -100,10 +97,7 @@ Collision MultiClipMove(PLAYERp pp, int z, int floor_dist)
pos[i].z = z;

// move the box
#pragma message(__FILE__ "remove workaround");
sectortype* cursect = pp->cursector();
clipmove(pos[i], &cursect, pp->xvect, pp->yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll);
pp->setcursector(cursect);
clipmove(pos[i], &pp->cursector, pp->xvect, pp->yvect, (int)sop->clipbox_dist[i], Z(4), floor_dist, CLIPMASK_PLAYER, coll);

// save the dist moved
dist = ksqrt(SQ(pos[i].x - opos[i].x) + SQ(pos[i].y - opos[i].y));
Expand Down Expand Up @@ -132,7 +126,7 @@ short MultiClipTurn(PLAYERp pp, short new_ang, int z, int floor_dist)
int x,y;
short ang;
int xvect, yvect;
auto cursect = pp->cursector();
auto cursect = pp->cursector;

for (i = 0; i < sop->clipbox_num; i++)
{
Expand Down Expand Up @@ -206,7 +200,7 @@ int RectClipMove(PLAYERp pp, int *qx, int *qy)
}

//Given the 4 points: x[4], y[4]
if (testquadinsect(&point_num, xy, pp->cursector()))
if (testquadinsect(&point_num, xy, pp->cursector))
{
pp->posx += (pp->xvect>>14);
pp->posy += (pp->yvect>>14);
Expand All @@ -223,7 +217,7 @@ int RectClipMove(PLAYERp pp, int *qx, int *qy)
xy[i].x = qx[i] - (pp->yvect>>15);
xy[i].y = qy[i] + (pp->xvect>>15);
}
if (testquadinsect(&point_num, xy, pp->cursector()))
if (testquadinsect(&point_num, xy, pp->cursector))
{
pp->posx -= (pp->yvect>>15);
pp->posy += (pp->xvect>>15);
Expand All @@ -239,7 +233,7 @@ int RectClipMove(PLAYERp pp, int *qx, int *qy)
xy[i].x = qx[i] + (pp->yvect>>15);
xy[i].y = qy[i] - (pp->xvect>>15);
}
if (testquadinsect(&point_num, xy, pp->cursector()))
if (testquadinsect(&point_num, xy, pp->cursector))
{
pp->posx += (pp->yvect>>15);
pp->posy -= (pp->xvect>>15);
Expand Down Expand Up @@ -290,7 +284,7 @@ short RectClipTurn(PLAYERp pp, short new_ang, int *qx, int *qy, int *ox, int *oy
}

//Given the 4 points: x[4], y[4]
if (testquadinsect(&point_num, xy, pp->cursector()))
if (testquadinsect(&point_num, xy, pp->cursector))
{
// move to new pos
for (i = 0; i < 4; i++)
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/ninja.cpp
Expand Up @@ -2360,7 +2360,7 @@ void InitPlayerSprite(PLAYERp pp)

COVER_SetReverb(0); // Turn off any echoing that may have been going before
pp->Reverb = 0;
auto actor = SpawnActor(STAT_PLAYER0 + pnum, NINJA_RUN_R0, nullptr, pp->cursector(), pp->posx,
auto actor = SpawnActor(STAT_PLAYER0 + pnum, NINJA_RUN_R0, nullptr, pp->cursector, pp->posx,
pp->posy, pp->posz, pp->angle.ang.asbuild(), 0);

pp->actor = actor;
Expand Down Expand Up @@ -2434,7 +2434,7 @@ void SpawnPlayerUnderSprite(PLAYERp pp)
int pnum = int(pp - Player);

pp->PlayerUnderActor = SpawnActor(STAT_PLAYER_UNDER0 + pnum,
NINJA_RUN_R0, nullptr, pp->cursector(), pp->posx, pp->posy, pp->posz, pp->angle.ang.asbuild(), 0);
NINJA_RUN_R0, nullptr, pp->cursector, pp->posx, pp->posy, pp->posz, pp->angle.ang.asbuild(), 0);

sp = &pp->PlayerUnderActor->s();
u = pp->PlayerUnderActor->u();
Expand Down
4 changes: 2 additions & 2 deletions source/games/sw/src/panel.cpp
Expand Up @@ -6719,7 +6719,7 @@ pDisplaySprites(PLAYERp pp, double smoothratio)
int16_t floorshade = 0;
if (pp->insector())
{
sectp = pp->cursector();
sectp = pp->cursector;
pal = sectp->floorpal;
floorshade = sectp->floorshade;

Expand All @@ -6740,7 +6740,7 @@ pDisplaySprites(PLAYERp pp, double smoothratio)
SET(flags, RS_TRANS1);
}

//shade = overlay_shade = DIV2(pp->cursector()->floorshade + pp->cursector()->ceilingshade);
//shade = overlay_shade = DIV2(pp->cursector->floorshade + pp->cursector->ceilingshade);
shade = overlay_shade = floorshade - 10;

if (TEST(psp->PlayerP->Flags, PF_VIEW_FROM_OUTSIDE))
Expand Down

0 comments on commit 86bd606

Please sign in to comment.