SW: Refinements for Q16.16 implementation.

This commit is contained in:
Mitchell Richters 2020-05-20 18:10:27 +10:00 committed by Christoph Oelckers
parent a4fdabd860
commit 0431f5ffed
6 changed files with 28 additions and 30 deletions

View file

@ -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);
}
}

View file

@ -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)

View file

@ -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);
}
}
}

View file

@ -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));

View file

@ -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;

View file

@ -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;