sw/src/jsector.cpp:JS_DrawCameras: Make camera oscilation

less dependent on the frame rate.
It would probably be better to update this from the game loop side,
like in Duke3D, but it's still better than the preceding situation.
This commit is contained in:
NY00123 2020-04-18 14:01:35 +03:00 committed by Christoph Oelckers
parent 471f0df69d
commit 5a6dd2224f

View file

@ -56,6 +56,7 @@ MIRRORTYPE mirror[MAXMIRRORS];
short mirrorcnt; //, floormirrorcnt; short mirrorcnt; //, floormirrorcnt;
//short floormirrorsector[MAXMIRRORS]; //short floormirrorsector[MAXMIRRORS];
SWBOOL mirrorinview; SWBOOL mirrorinview;
uint32_t oscilationclock;
// Voxel stuff // Voxel stuff
//SWBOOL bVoxelsOn = TRUE; // Turn voxels on by default //SWBOOL bVoxelsOn = TRUE; // Turn voxels on by default
@ -314,6 +315,7 @@ void JS_InitMirrors(void)
// Scan wall tags for mirrors // Scan wall tags for mirrors
mirrorcnt = 0; mirrorcnt = 0;
tileDelete(MIRROR); tileDelete(MIRROR);
oscilationclock = ototalclock;
for (i = 0; i < MAXMIRRORS; i++) for (i = 0; i < MAXMIRRORS; i++)
{ {
@ -533,7 +535,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
SWBOOL bIsWallMirror = FALSE; SWBOOL bIsWallMirror = FALSE;
camloopcnt += (int32_t)(totalclock - ototalclock); camloopcnt += (int32_t) (totalclock - ototalclock);
if (camloopcnt > (60 * 5)) // 5 seconds per player view if (camloopcnt > (60 * 5)) // 5 seconds per player view
{ {
camloopcnt = 0; camloopcnt = 0;
@ -546,6 +548,10 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
longptr = (int*)&gotpic[MIRRORLABEL >> 3]; longptr = (int*)&gotpic[MIRRORLABEL >> 3];
if (longptr && (longptr[0] || longptr[1])) if (longptr && (longptr[0] || longptr[1]))
{ {
uint32_t oscilation_delta = ototalclock - oscilationclock;
oscilation_delta -= oscilation_delta % 4;
oscilationclock += oscilation_delta;
oscilation_delta *= 2;
for (cnt = MAXMIRRORS - 1; cnt >= 0; cnt--) for (cnt = MAXMIRRORS - 1; cnt >= 0; cnt--)
{ {
if (!mirror[cnt].ismagic) continue; // these are definitely not camera textures. if (!mirror[cnt].ismagic) continue; // these are definitely not camera textures.
@ -643,11 +649,12 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
// angle else subtract // angle else subtract
{ {
// Store current angle in TAG5 // Store current angle in TAG5
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + 4)); SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta));
// TAG6 = Turn radius // TAG6 = Turn radius
if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp)) if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp))
{ {
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta));
RESET_BOOL3(sp); // Reverse turn RESET_BOOL3(sp); // Reverse turn
// direction. // direction.
} }
@ -655,11 +662,12 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
else else
{ {
// Store current angle in TAG5 // Store current angle in TAG5
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - 4)); SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) - oscilation_delta));
// TAG6 = Turn radius // TAG6 = Turn radius
if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp)) if (klabs(GetDeltaAngle(SP_TAG5(sp), sp->ang)) >= SP_TAG6(sp))
{ {
SP_TAG5(sp) = NORM_ANGLE((SP_TAG5(sp) + oscilation_delta));
SET_BOOL3(sp); // Reverse turn SET_BOOL3(sp); // Reverse turn
// direction. // direction.
} }