From 0431f5ffed4bdf518ee59285f52013ca08fea401 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 20 May 2020 18:10:27 +1000 Subject: [PATCH] SW: Refinements for Q16.16 implementation. --- source/sw/src/draw.cpp | 39 ++++++++++++++++++--------------------- source/sw/src/game.cpp | 3 ++- source/sw/src/jsector.cpp | 8 ++++---- source/sw/src/network.cpp | 4 ++-- source/sw/src/ninja.cpp | 2 +- source/sw/src/sounds.cpp | 2 +- 6 files changed, 28 insertions(+), 30 deletions(-) diff --git a/source/sw/src/draw.cpp b/source/sw/src/draw.cpp index 4381a9721..cb5cb7b96 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 6a098a60b..a5f8d4593 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -586,7 +586,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); @@ -596,6 +596,7 @@ bool LoadLevel(const char *filename) SECRET_SetMapName(currentLevel->DisplayName(), currentLevel->name); STAT_NewLevel(currentLevel->labelName); return true; + Player[0].q16ang = fix16_from_int(q16ang); } void LoadDemoRun(void) diff --git a/source/sw/src/jsector.cpp b/source/sw/src/jsector.cpp index aa57ea598..f2954fd62 100644 --- a/source/sw/src/jsector.cpp +++ b/source/sw/src/jsector.cpp @@ -460,14 +460,14 @@ void JS_InitMirrors(void) // Draw a 3d screen to a specific tile ///////////////////////////////////////////////////// void drawroomstotile(int daposx, int daposy, int daposz, - short daang, fix16_t daq16horiz, short dacursectnum, short tilenume) + fix16_t daq16ang, fix16_t daq16horiz, short dacursectnum, short tilenume) { TileFiles.MakeCanvas(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y); renderSetTarget(tilenume, tilesiz[tilenume].x, tilesiz[tilenume].y); screen->BeginScene(); - drawrooms(daposx, daposy, daposz, daang, daq16horiz, dacursectnum); + renderDrawRoomsQ16(daposx, daposy, daposz, daq16ang, daq16horiz, dacursectnum); analyzesprites(daposx, daposy, daposz, FALSE); renderDrawMasks(); screen->FinishScene(); @@ -703,11 +703,11 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz, fix16_t tpq16ang, fix16_ if (TEST_BOOL11(sp) && numplayers > 1) { - drawroomstotile(cp->posx, cp->posy, cp->posz, cp->pang, cp->horiz, cp->cursectnum, mirror[cnt].campic); + drawroomstotile(cp->posx, cp->posy, cp->posz, cp->q16ang, cp->q16horiz, cp->cursectnum, mirror[cnt].campic); } else { - drawroomstotile(sp->x, sp->y, sp->z, SP_TAG5(sp), camhoriz, sp->sectnum, mirror[cnt].campic); + drawroomstotile(sp->x, sp->y, sp->z, fix16_from_int(SP_TAG5(sp)), fix16_from_int(camhoriz), sp->sectnum, mirror[cnt].campic); } } } diff --git a/source/sw/src/network.cpp b/source/sw/src/network.cpp index 7981d10f4..032acaccb 100644 --- a/source/sw/src/network.cpp +++ b/source/sw/src/network.cpp @@ -955,8 +955,8 @@ faketimerhandler(void) loc.vel = AveragePacket.vel / MovesPerPacket; loc.svel = AveragePacket.svel / MovesPerPacket; - loc.q16avel = AveragePacket.q16avel / fix16_from_int(MovesPerPacket); - loc.q16horz = AveragePacket.q16horz / fix16_from_int(MovesPerPacket); + loc.q16avel = fix16_div(AveragePacket.q16avel, fix16_from_int(MovesPerPacket)); + loc.q16horz = fix16_div(AveragePacket.q16horz, fix16_from_int(MovesPerPacket)); loc.bits = AveragePacket.bits; memset(&AveragePacket, 0, sizeof(AveragePacket)); diff --git a/source/sw/src/ninja.cpp b/source/sw/src/ninja.cpp index e94187920..ed6c0999f 100644 --- a/source/sw/src/ninja.cpp +++ b/source/sw/src/ninja.cpp @@ -2405,7 +2405,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; diff --git a/source/sw/src/sounds.cpp b/source/sw/src/sounds.cpp index 9cf5bba4b..ae4795c4f 100644 --- a/source/sw/src/sounds.cpp +++ b/source/sw/src/sounds.cpp @@ -586,7 +586,7 @@ void DoUpdateSounds(void) PLAYERp pp = Player + screenpeek; SoundListener listener; - listener.angle = -fix16_to_float(pp-q16ang) * pi::pi() / 1024; // Build uses a period of 2048. + listener.angle = -fix16_to_float(pp->q16ang) * pi::pi() / 1024; // Build uses a period of 2048. listener.velocity.Zero(); listener.position = GetSoundPos((vec3_t*)&pp->posx); listener.underwater = false;