Skip to content

Commit

Permalink
- SW: Cut q16horiz/q16horizoff over to PlayerHorizon struct.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr4077au committed Oct 7, 2020
1 parent 6da756c commit 6476430
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 94 deletions.
33 changes: 16 additions & 17 deletions source/sw/src/draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ void DrawCrosshair(PLAYERp pp)
}
}

void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fixed_t *tq16ang, fixed_t *tq16horiz)
void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fixed_t *tq16ang, fixedhoriz *thoriz)
{
int i,nexti;
short ang;
Expand Down Expand Up @@ -1326,9 +1326,9 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fixed_t
zvect = 0;

// new horiz to player
*tq16horiz = clamp(-(zvect << 8), gi->playerHorizMin(), gi->playerHorizMax());
*thoriz = q16horiz(clamp(-(zvect << 8), gi->playerHorizMin(), gi->playerHorizMax()));

//DSPRINTF(ds,"xvect %d,yvect %d,zvect %d,tq16horiz %d",xvect,yvect,zvect,*tq16horiz);
//DSPRINTF(ds,"xvect %d,yvect %d,zvect %d,thoriz %d",xvect,yvect,zvect,*thoriz.asbuild());
MONO_PRINT(ds);

*tq16ang = IntToFixed(ang);
Expand Down Expand Up @@ -1602,7 +1602,8 @@ drawscreen(PLAYERp pp, double smoothratio)
{
extern bool CameraTestMode;
int tx, ty, tz;
fixed_t tq16horiz, tq16ang, tq16rotscrnang;
fixed_t tq16ang, tq16rotscrnang;
fixedhoriz thoriz;
short tsectnum;
short i,j;
int bob_amt = 0;
Expand Down Expand Up @@ -1650,15 +1651,13 @@ drawscreen(PLAYERp pp, double smoothratio)
fixed_t ang = camerapp->q16ang + camerapp->q16look_ang;
tq16ang = oang + xs_CRoundToInt(fmulscale16(NORM_Q16ANGLE(ang + dang - oang) - dang, smoothratio));

fixed_t ohoriz = camerapp->oq16horiz + camerapp->oq16horizoff;
fixed_t horiz = camerapp->q16horiz + camerapp->q16horizoff;
tq16horiz = ohoriz + xs_CRoundToInt(fmulscale16(horiz - ohoriz, smoothratio));
thoriz = camerapp->horizon.interpolatedsum(smoothratio);
tq16rotscrnang = camerapp->oq16rotscrnang + xs_CRoundToInt(fmulscale16(NORM_Q16ANGLE(camerapp->q16rotscrnang + dang - camerapp->oq16rotscrnang) - dang, smoothratio));
}
else
{
tq16ang = pp->q16ang + pp->q16look_ang;
tq16horiz = pp->q16horiz + pp->q16horizoff;
thoriz = pp->horizon.sum();
tq16rotscrnang = pp->q16rotscrnang;
}
tsectnum = camerapp->cursectnum;
Expand Down Expand Up @@ -1700,7 +1699,7 @@ drawscreen(PLAYERp pp, double smoothratio)
tz = tz + quake_z;
tx = tx + quake_x;
ty = ty + quake_y;
//tq16horiz = tq16horiz + IntToFixed(quake_x);
//thoriz += buildhoriz(quake_x);
tq16ang = NORM_Q16ANGLE(tq16ang + IntToFixed(quake_ang));

if (pp->sop_remote)
Expand All @@ -1715,10 +1714,10 @@ drawscreen(PLAYERp pp, double smoothratio)
{
tz -= 8448;

if (!BackView(&tx, &ty, &tz, &tsectnum, &tq16ang, tq16horiz))
if (!BackView(&tx, &ty, &tz, &tsectnum, &tq16ang, thoriz.asq16()))
{
tz += 8448;
BackView(&tx, &ty, &tz, &tsectnum, &tq16ang, tq16horiz);
BackView(&tx, &ty, &tz, &tsectnum, &tq16ang, thoriz.asq16());
}
}
else
Expand All @@ -1727,7 +1726,7 @@ drawscreen(PLAYERp pp, double smoothratio)

if (CameraTestMode)
{
CameraView(camerapp, &tx, &ty, &tz, &tsectnum, &tq16ang, &tq16horiz);
CameraView(camerapp, &tx, &ty, &tz, &tsectnum, &tq16ang, &thoriz);
}
}

Expand All @@ -1740,7 +1739,7 @@ drawscreen(PLAYERp pp, double smoothratio)
}

// recoil only when not in camera
tq16horiz = clamp(tq16horiz + pp->recoil_horizoff, gi->playerHorizMin(), gi->playerHorizMax());
thoriz = q16horiz(clamp(thoriz.asq16() + pp->recoil_horizoff, gi->playerHorizMin(), gi->playerHorizMax()));
}

if (automapMode != am_full)// && !ScreenSavePic)
Expand All @@ -1753,20 +1752,20 @@ drawscreen(PLAYERp pp, double smoothratio)
videoSetCorrectedAspect();
renderSetAspect(xs_CRoundToInt(double(viewingrange)* tan(r_fov* (PI / 360.))), yxaspect);
OverlapDraw = true;
DrawOverlapRoom(tx, ty, tz, tq16ang, tq16horiz, tsectnum);
DrawOverlapRoom(tx, ty, tz, tq16ang, thoriz.asq16(), tsectnum);
OverlapDraw = false;

if (automapMode != am_full)// && !ScreenSavePic)
{
// TEST this! Changed to camerapp
//JS_DrawMirrors(camerapp, tx, ty, tz, tq16ang, tq16horiz);
JS_DrawMirrors(pp, tx, ty, tz, tq16ang, tq16horiz);
//JS_DrawMirrors(camerapp, tx, ty, tz, tq16ang, thoriz.asq16());
JS_DrawMirrors(pp, tx, ty, tz, tq16ang, thoriz.asq16());
}

// TODO: This call is redundant if the tiled overhead map is shown, but the
// HUD elements should be properly outputted with hardware rendering first.
if (!FAF_DebugView)
FAF_DrawRooms(tx, ty, tz, tq16ang, tq16horiz, tsectnum);
FAF_DrawRooms(tx, ty, tz, tq16ang, thoriz.asq16(), tsectnum);

analyzesprites(tx, ty, tz, false);
post_analyzesprites();
Expand Down
5 changes: 3 additions & 2 deletions source/sw/src/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ struct PLAYERstruct
// interpolation
int
oposx, oposy, oposz;
fixed_t oq16horiz, oq16horizoff, oq16ang;
fixed_t oq16ang;
fixed_t oq16look_ang, oq16rotscrnang;

// holds last valid move position
Expand Down Expand Up @@ -882,7 +882,8 @@ struct PLAYERstruct

// variables that do not fit into sprite structure
int hvel,tilt,tilt_dest;
fixed_t q16horiz, q16horizoff, q16ang;
PlayerHorizon horizon;
fixed_t q16ang;
fixed_t q16look_ang, q16rotscrnang;
short recoil_amt;
short recoil_speed;
Expand Down
7 changes: 6 additions & 1 deletion source/sw/src/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ void GameInterface::GetInput(InputPacket *packet, ControlInfo* const hidInput)
DoPlayerTurnTurret(pp, input.q16avel);
}

playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust);
// temporary vals to pass through to playerProcessHelpers().
fixed_t horiz = 0;
fixed_t target = 0;
double adjust = 0;
playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &horiz, &adjust, &target, scaleAdjust);
pp->horizon.processhelpers(scaleAdjust);
}

if (packet)
Expand Down
2 changes: 1 addition & 1 deletion source/sw/src/jsector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)

if (TEST_BOOL11(sp) && numplayers > 1)
{
drawroomstotile(cp->posx, cp->posy, cp->posz, cp->q16ang, cp->q16horiz, cp->cursectnum, mirror[cnt].campic);
drawroomstotile(cp->posx, cp->posy, cp->posz, cp->q16ang, cp->horizon.horiz.asq16(), cp->cursectnum, mirror[cnt].campic);
}
else
{
Expand Down
10 changes: 5 additions & 5 deletions source/sw/src/jweapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1418,10 +1418,10 @@ PlayerInitChemBomb(PLAYERp pp)
if (TEST(pp->Flags, PF_DIVING) || SpriteInUnderwaterArea(wp))
SET(wu->Flags, SPR_UNDERWATER);

wp->zvel = -pp->q16horiz >> 9;
wp->zvel = -pp->horizon.horiz.asq16() >> 9;

// //DSPRINTF(ds,"horiz %d, ho %d, ho+ho %d",FixedToInt(pp->q16horiz), FixedToInt(pp->q16horizoff),
// FixedToInt(pp->q16horizoff + pp->q16horiz));
// //DSPRINTF(ds,"horiz %d, ho %d, ho+ho %d", pp->horizon.horiz.asbuild(), pp->horizon.horizoff.asbuild(),
// pp->horizon.horizoff.asbuild() + pp->horizon.horiz.asbuild());
// MONO_PRINT(ds);

oclipdist = pp->SpriteP->clipdist;
Expand Down Expand Up @@ -1862,7 +1862,7 @@ PlayerInitCaltrops(PLAYERp pp)
// They go out at different angles
// wp->ang = NORM_ANGLE(FixedToInt(pp->q16ang) + (RANDOM_RANGE(50) - 25));

wp->zvel = -pp->q16horiz >> 9;
wp->zvel = -pp->horizon.horiz.asq16() >> 9;

oclipdist = pp->SpriteP->clipdist;
pp->SpriteP->clipdist = 0;
Expand Down Expand Up @@ -2496,7 +2496,7 @@ InitShell(int16_t SpriteNum, int16_t ShellNum)

if (u->PlayerP)
{
wp->z += xs_CRoundToInt(-fmulscale16(u->PlayerP->q16horiz, HORIZ_MULT / 3.));
wp->z += xs_CRoundToInt(-fmulscale16(u->PlayerP->horizon.horiz.asq16(), HORIZ_MULT / 3.));
}

switch (wu->ID)
Expand Down
2 changes: 1 addition & 1 deletion source/sw/src/osdcmds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static int osdcmd_warptocoords(CCmdFuncPtr parm)

if (parm->numparms == 5)
{
Player->oq16horiz = Player->q16horiz = IntToFixed(atoi(parm->parms[4]));
Player->horizon.ohoriz = Player->horizon.horiz = buildhoriz(atoi(parm->parms[4]));
}

return CCMD_OK;
Expand Down
41 changes: 20 additions & 21 deletions source/sw/src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1706,29 +1706,29 @@ PlayerAutoLook(PLAYERp pp, double const scaleAdjust)
// accordingly
if ((pp->cursectnum == tempsect) || (klabs(getflorzofslope(tempsect, x, y) - k) <= (4 << 8)))
{
pp->q16horizoff += xs_CRoundToInt(scaleAdjust * ((j - k) * 160));
pp->horizon.horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * ((j - k) * 160)));
}
}
}
}

if (TEST(pp->Flags, PF_CLIMBING) && pp->q16horizoff < IntToFixed(100))
if (TEST(pp->Flags, PF_CLIMBING) && pp->horizon.horizoff.asq16() < IntToFixed(100))
{
// tilt when climbing but you can't even really tell it.
pp->q16horizoff += xs_CRoundToInt(scaleAdjust * (((IntToFixed(100) - pp->q16horizoff) >> 3) + FRACUNIT));
pp->horizon.horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * (((IntToFixed(100) - pp->horizon.horizoff.asq16()) >> 3) + FRACUNIT)));
}
else
{
// Make q16horizoff grow towards 0 since q16horizoff is not modified when you're not on a slope.
if (pp->q16horizoff > 0)
// Make horizoff grow towards 0 since horizoff is not modified when you're not on a slope.
if (pp->horizon.horizoff.asq16() > 0)
{
pp->q16horizoff -= xs_CRoundToInt(scaleAdjust * ((pp->q16horizoff >> 3) + FRACUNIT));
pp->q16horizoff = max(pp->q16horizoff, 0);
pp->horizon.horizoff -= q16horiz(xs_CRoundToInt(scaleAdjust * ((pp->horizon.horizoff.asq16() >> 3) + FRACUNIT)));
pp->horizon.horizoff = q16horiz(max(pp->horizon.horizoff.asq16(), 0));
}
if (pp->q16horizoff < 0)
if (pp->horizon.horizoff.asq16() < 0)
{
pp->q16horizoff += xs_CRoundToInt(scaleAdjust * ((pp->q16horizoff >> 3) + FRACUNIT));
pp->q16horizoff = min(pp->q16horizoff, 0);
pp->horizon.horizoff += q16horiz(xs_CRoundToInt(scaleAdjust * ((pp->horizon.horizoff.asq16() >> 3) + FRACUNIT)));
pp->horizon.horizoff = q16horiz(min(pp->horizon.horizoff.asq16(), 0));
}
}
}
Expand All @@ -1741,7 +1741,7 @@ DoPlayerHorizon(PLAYERp pp, fixed_t const q16horz, double const scaleAdjust)
PlayerAutoLook(pp, scaleAdjust);

// apply default horizon from backend
sethorizon2(&pp->q16horiz, q16horz, &pp->input.actions, scaleAdjust);
sethorizon(&pp->horizon.horiz, q16horz, &pp->input.actions, scaleAdjust);
}

void
Expand Down Expand Up @@ -6138,14 +6138,14 @@ DoPlayerBeginDie(PLAYERp pp)
void
DoPlayerDeathHoriz(PLAYERp pp, short target, short speed)
{
if ((pp->q16horiz - IntToFixed(target)) > FRACUNIT)
if ((pp->horizon.horiz.asq16() - IntToFixed(target)) > FRACUNIT)
{
playerAddHoriz2(&pp->q16horiz, &pp->horizAdjust, -speed);
pp->horizon.addadjustment(-speed);
}

if ((IntToFixed(target) - pp->q16horiz) > FRACUNIT)
if ((IntToFixed(target) - pp->horizon.horiz.asq16()) > FRACUNIT)
{
playerAddHoriz2(&pp->q16horiz, &pp->horizAdjust, speed);
pp->horizon.addadjustment(speed);
}
}

Expand Down Expand Up @@ -6299,7 +6299,7 @@ void DoPlayerDeathCheckKeys(PLAYERp pp)
sp->yrepeat = PLAYER_NINJA_YREPEAT;

//pp->tilt = 0;
pp->q16horiz = 0;
pp->horizon.horiz = q16horiz(0);
DoPlayerResetMovement(pp);
u->ID = NINJA_RUN_R0;
PlayerDeathReset(pp);
Expand Down Expand Up @@ -6971,11 +6971,10 @@ MoveSkipSavePos(void)
pp->oposy = pp->posy;
pp->oposz = pp->posz;
pp->oq16ang = pp->q16ang;
pp->oq16horiz = pp->q16horiz;
pp->oq16horizoff = pp->q16horizoff;
pp->obob_z = pp->bob_z;
pp->oq16look_ang = pp->q16look_ang;
pp->oq16rotscrnang = pp->q16rotscrnang;
pp->horizon.backup();
}

// save off stats for skip4
Expand Down Expand Up @@ -7352,7 +7351,7 @@ InitAllPlayers(void)

//getzsofslope(pfirst->cursectnum, pfirst->posx, pfirst->posy, &cz, &fz);
//pfirst->posz = fz - PLAYER_HEIGHT;
pfirst->q16horiz = 0;
pfirst->horizon.horiz = q16horiz(0);

// Initialize all [MAX_SW_PLAYERS] arrays here!
for (pp = Player; pp < &Player[MAX_SW_PLAYERS]; pp++)
Expand All @@ -7361,7 +7360,7 @@ InitAllPlayers(void)
pp->posy = pp->oposy = pfirst->posy;
pp->posz = pp->oposz = pfirst->posz;
pp->q16ang = pp->oq16ang = pfirst->q16ang;
pp->q16horiz = pp->oq16horiz = pfirst->q16horiz;
pp->horizon.horiz = pp->horizon.ohoriz = pfirst->horizon.horiz;
pp->cursectnum = pfirst->cursectnum;
// set like this so that player can trigger something on start of the level
pp->lastcursectnum = pfirst->cursectnum+1;
Expand Down Expand Up @@ -7398,7 +7397,7 @@ InitAllPlayers(void)
pp->FadeAmt = 0;
pp->FadeTics = 0;
pp->StartColor = 0;
pp->q16horizoff = 0;
pp->horizon.horizoff = q16horiz(0);

INITLIST(&pp->PanelSpriteList);
}
Expand Down
11 changes: 6 additions & 5 deletions source/sw/src/predict.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ PLAYERp ppp = &PredictPlayer;
typedef struct
{
int x,y,z;
fixed_t q16horiz, q16ang;
fixed_t q16ang;
fixedhoriz horiz;
short filler;
} PREDICT, *PREDICTp;

Expand Down Expand Up @@ -99,7 +100,7 @@ DoPrediction(PLAYERp ppp)
ppp->oposx = ppp->posx;
ppp->oposy = ppp->posy;
ppp->oposz = ppp->posz;
ppp->oq16horiz = ppp->q16horiz;
ppp->horizon.backup();

// go through the player MOVEMENT code only
Prediction = true;
Expand All @@ -117,7 +118,7 @@ DoPrediction(PLAYERp ppp)
Predict[predictmovefifoplc & (MOVEFIFOSIZ-1)].x = ppp->posx;
Predict[predictmovefifoplc & (MOVEFIFOSIZ-1)].y = ppp->posy;
Predict[predictmovefifoplc & (MOVEFIFOSIZ-1)].z = ppp->posz;
Predict[predictmovefifoplc & (MOVEFIFOSIZ-1)].q16horiz = ppp->q16horiz;
Predict[predictmovefifoplc & (MOVEFIFOSIZ-1)].horiz = ppp->horizon.horiz;
predictmovefifoplc++;
#endif
}
Expand All @@ -139,13 +140,13 @@ CorrectPrediction(int actualfifoplc)
predict->x == Player[myconnectindex].posx &&
predict->y == Player[myconnectindex].posy &&
predict->z == Player[myconnectindex].posz &&
predict->q16horiz == Player[myconnectindex].q16horiz
predict->horiz == Player[myconnectindex].horizon.horiz
)
{
return;
}

// //DSPRINTF(ds,"PREDICT ERROR: %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", FixedToInt(predict->q16ang), FixedToInt(Player[myconnectindex].q16ang), predict->x, Player[myconnectindex].posx, predict->y, Player[myconnectindex].posy, predict->z, Player[myconnectindex].posz, FixedToInt(predict->q16horiz),FixedToInt(Player[myconnectindex].q16horiz));
// //DSPRINTF(ds,"PREDICT ERROR: %ld %ld %ld %ld %ld %ld %ld %ld %ld %ld", FixedToInt(predict->q16ang), FixedToInt(Player[myconnectindex].q16ang), predict->x, Player[myconnectindex].posx, predict->y, Player[myconnectindex].posy, predict->z, Player[myconnectindex].posz, predict->horiz.asbuild(), Player[myconnectindex].horizon.horiz.asbuild()));
// MONO_PRINT(ds);

InitPrediction(&Player[myconnectindex]);
Expand Down

0 comments on commit 6476430

Please sign in to comment.