From d78d046bad6c1679fff32efaa98bc6b4478d20eb Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Sun, 29 Mar 2020 19:38:56 +1100 Subject: [PATCH] SW: Minor repairs for Q16.16 implementation. --- source/sw/src/draw.cpp | 39 ++++++++++++++++++--------------------- source/sw/src/game.cpp | 3 ++- source/sw/src/ninja.cpp | 2 +- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 927c53e3d..fc8b2b1b5 100644 --- a/source/sw/src/draw.cpp +++ b/source/sw/src/draw.cpp @@ -1141,7 +1141,7 @@ ViewOutsidePlayerRecurse(PLAYERp pp, int32_t* vx, int32_t* vy, int32_t* vz, int1 void -BackView(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) +BackView(int *nx, int *ny, int *nz, short *vsect, fix16_t *nq16ang, short horiz) { vec3_t n = { *nx, *ny, *nz }; SPRITEp sp; @@ -1153,7 +1153,7 @@ BackView(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) ASSERT(*vsect >= 0 && *vsect < MAXSECTORS); - ang = *nang + pp->view_outside_dang; + ang = fix16_to_int(*nq16ang) + pp->view_outside_dang; // Calculate the vector (nx,ny,nz) to shoot backwards vx = (sintable[NORM_ANGLE(ang + 1536)] >> 3); @@ -1215,7 +1215,7 @@ BackView(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) flag_backup = hsp->cstat; RESET(hsp->cstat, CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); ASSERT(*vsect >= 0 && *vsect < MAXSECTORS); - BackView(nx, ny, nz, vsect, nang, horiz); + BackView(nx, ny, nz, vsect, nq16ang, horiz); hsp->cstat = flag_backup; return; } @@ -1256,11 +1256,11 @@ BackView(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) // Make sure vsect is correct updatesectorz(*nx, *ny, *nz, vsect); - *nang = ang; + *nq16ang = fix16_from_int(ang); } void -CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) +CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nq16ang, short horiz) { vec3_t n = { *nx, *ny, *nz }; SPRITEp sp; @@ -1270,7 +1270,7 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) PLAYERp pp = &Player[screenpeek]; short ang; - ang = *nang + pp->circle_camera_ang; + ang = fix16_to_int(*nq16ang) + pp->circle_camera_ang; // Calculate the vector (nx,ny,nz) to shoot backwards vx = (sintable[NORM_ANGLE(ang + 1536)] >> 4); @@ -1336,7 +1336,7 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) flag_backup = hsp->cstat; RESET(hsp->cstat, CSTAT_SPRITE_BLOCK|CSTAT_SPRITE_BLOCK_HITSCAN); - CircleCamera(nx, ny, nz, vsect, nang, horiz); + CircleCamera(nx, ny, nz, vsect, nq16ang, horiz); hsp->cstat = flag_backup; return; } @@ -1365,7 +1365,7 @@ CircleCamera(int *nx, int *ny, int *nz, short *vsect, int *nang, short horiz) // Make sure vsect is correct updatesectorz(*nx, *ny, *nz, vsect); - *nang = ang; + *nq16ang = fix16_from_int(ang); } FString GameInterface::statFPS() @@ -1576,7 +1576,7 @@ void DrawCrosshair(PLAYERp pp) } -void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, int *tang, int *thoriz) +void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, fix16_t *tq16ang, fix16_t *tq16horiz) { int i,nexti; short ang; @@ -1617,7 +1617,7 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, int *tan { case 1: pp->last_camera_sp = sp; - CircleCamera(tx, ty, tz, tsectnum, tang, 100); + CircleCamera(tx, ty, tz, tsectnum, tq16ang, 100); found_camera = TRUE; break; @@ -1643,14 +1643,14 @@ void CameraView(PLAYERp pp, int *tx, int *ty, int *tz, short *tsectnum, int *tan zvect = 0; // new horiz to player - *thoriz = 100 - (zvect/256); - *thoriz = max(*thoriz, PLAYER_HORIZ_MIN); - *thoriz = min(*thoriz, PLAYER_HORIZ_MAX); + *tq16horiz = fix16_from_int(100 - (zvect/256)); + *tq16horiz = fix16_max(*tq16horiz, fix16_from_int(PLAYER_HORIZ_MIN)); + *tq16horiz = fix16_min(*tq16horiz, fix16_from_int(PLAYER_HORIZ_MAX)); - //DSPRINTF(ds,"xvect %d,yvect %d,zvect %d,thoriz %d",xvect,yvect,zvect,*thoriz); + //DSPRINTF(ds,"xvect %d,yvect %d,zvect %d,tq16horiz %d",xvect,yvect,zvect,*tq16horiz); MONO_PRINT(ds); - *tang = ang; + *tq16ang = fix16_from_int(ang); *tx = sp->x; *ty = sp->y; *tz = sp->z; @@ -1930,7 +1930,7 @@ void drawscreen(PLAYERp pp) { extern SWBOOL DemoMode,CameraTestMode; - int tx, ty, tz, tinthoriz, tintang; + int tx, ty, tz; fix16_t tq16horiz, tq16ang; short tsectnum; short i,j; @@ -2084,8 +2084,7 @@ drawscreen(PLAYERp pp) //if (TEST(camerapp->Flags, PF_VIEW_FROM_OUTSIDE)) if (TEST(pp->Flags, PF_VIEW_FROM_OUTSIDE)) { - tintang = fix16_to_int(tq16ang); - BackView(&tx, &ty, &tz, &tsectnum, &tintang, fix16_to_int(tq16horiz)); + BackView(&tx, &ty, &tz, &tsectnum, &tq16ang, fix16_to_int(tq16horiz)); } else { @@ -2093,9 +2092,7 @@ drawscreen(PLAYERp pp) if (DemoMode || CameraTestMode) { - tinthoriz = fix16_to_int(tq16horiz); - tintang = fix16_to_int(tq16ang); - CameraView(camerapp, &tx, &ty, &tz, &tsectnum, &tintang, &tinthoriz); + CameraView(camerapp, &tx, &ty, &tz, &tsectnum, &tq16ang, &tq16horiz); } } diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index ecf281ad1..b928fcda1 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -588,7 +588,7 @@ void TerminateGame(void) bool LoadLevel(const char *filename) { - int16_t q16ang = fix16_to_int(Player[0].q16ang); + int16_t q16ang; if (engineLoadBoard(filename, SW_SHAREWARE ? 1 : 0, (vec3_t *)&Player[0], &q16ang, &Player[0].cursectnum) == -1) { Printf("Level not found: %s", filename); @@ -597,6 +597,7 @@ bool LoadLevel(const char *filename) currentLevel = &mapList[Level]; SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); STAT_NewLevel(currentLevel->labelName); + Player[0].q16ang = fix16_from_int(q16ang); return true; } diff --git a/source/sw/src/ninja.cpp b/source/sw/src/ninja.cpp index c878c705a..2fe8f42f5 100644 --- a/source/sw/src/ninja.cpp +++ b/source/sw/src/ninja.cpp @@ -2406,7 +2406,7 @@ InitPlayerSprite(PLAYERp pp) COVER_SetReverb(0); // Turn off any echoing that may have been going before pp->Reverb = 0; sp_num = pp->PlayerSprite = SpawnSprite(STAT_PLAYER0 + pnum, NINJA_RUN_R0, NULL, pp->cursectnum, pp->posx, - pp->posy, pp->posz, fix16_to_int(pp->q16ang), 50); + pp->posy, pp->posz, fix16_to_int(pp->q16ang), 0); pp->SpriteP = sp = &sprite[sp_num]; pp->pnum = pnum;