- SW: Migrate to GZDoom time code like Duke.

This commit is contained in:
Mitchell Richters 2020-08-25 21:46:52 +10:00 committed by Christoph Oelckers
parent d04aa603dd
commit 386661f1ba
11 changed files with 45 additions and 47 deletions

View file

@ -939,7 +939,7 @@ post_analyzesprites(void)
} }
#endif #endif
static ClockTicks mapzoomclock; static int mapzoomclock;
void void
ResizeView(PLAYERp pp) ResizeView(PLAYERp pp)
@ -949,7 +949,7 @@ ResizeView(PLAYERp pp)
if (automapMode != am_off) if (automapMode != am_off)
{ {
int32_t timepassed = (int32_t)(totalclock - mapzoomclock); int32_t timepassed = gameclock - mapzoomclock;
mapzoomclock += timepassed; mapzoomclock += timepassed;
if (buttonMap.ButtonDown(gamefunc_Shrink_Screen)) if (buttonMap.ButtonDown(gamefunc_Shrink_Screen))
zoom = max<int32_t>(zoom - mulscale7(timepassed * synctics, zoom), 48); zoom = max<int32_t>(zoom - mulscale7(timepassed * synctics, zoom), 48);
@ -1199,7 +1199,7 @@ FString GameInterface::statFPS()
//if (LocationInfo) //if (LocationInfo)
{ {
i = (int32_t)totalclock; i = gameclock;
if (i != frameval[framecnt]) if (i != frameval[framecnt])
{ {
out.AppendFormat("FPS: %d\n", ((120 * AVERAGEFRAMES) / (i - frameval[framecnt])) + f_c); out.AppendFormat("FPS: %d\n", ((120 * AVERAGEFRAMES) / (i - frameval[framecnt])) + f_c);
@ -1656,7 +1656,7 @@ void DoPlayerDiveMeter(PLAYERp pp);
void MoveScrollMode2D(PLAYERp pp); void MoveScrollMode2D(PLAYERp pp);
void void
drawscreen(PLAYERp pp) drawscreen(PLAYERp pp, double smoothratio)
{ {
extern SWBOOL CameraTestMode; extern SWBOOL CameraTestMode;
int tx, ty, tz; int tx, ty, tz;
@ -1678,10 +1678,6 @@ drawscreen(PLAYERp pp)
DrawScreen = TRUE; DrawScreen = TRUE;
PreDraw(); PreDraw();
smoothratio = CalcSmoothRatio(totalclock, ototalclock, 120 / synctics);
if (paused && !ReloadPrompt) // The checks were brought over from domovethings
smoothratio = 65536;
PreUpdatePanel(smoothratio); PreUpdatePanel(smoothratio);
if (!ScreenSavePic) if (!ScreenSavePic)
@ -1921,7 +1917,7 @@ drawscreen(PLAYERp pp)
SyncStatMessage(); SyncStatMessage();
#endif #endif
UpdateStatusBar(totalclock); UpdateStatusBar(gameclock);
DrawCrosshair(pp); DrawCrosshair(pp);
DoPlayerDiveMeter(pp); // Do the underwater breathing bar DoPlayerDiveMeter(pp); // Do the underwater breathing bar
@ -1960,7 +1956,7 @@ drawscreen(PLAYERp pp)
bool GameInterface::GenerateSavePic() bool GameInterface::GenerateSavePic()
{ {
ScreenSavePic = TRUE; ScreenSavePic = TRUE;
drawscreen(Player + myconnectindex); drawscreen(Player + myconnectindex, 65536);
ScreenSavePic = FALSE; ScreenSavePic = FALSE;
return true; return true;
} }

View file

@ -316,7 +316,7 @@ void DrawMenuLevelScreen(void)
{ {
const int TITLE_PIC = 2324; const int TITLE_PIC = 2324;
twod->ClearScreen(); twod->ClearScreen();
totalclocklock = totalclock; totalclocklock = gameclock;
DrawTexture(twod, tileGetTexture(TITLE_PIC), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal, DrawTexture(twod, tileGetTexture(TITLE_PIC), 0, 0, DTA_FullscreenEx, FSMode_ScaleToFit43, DTA_LegacyRenderStyle, STYLE_Normal,
DTA_Color, shadeToLight(20), TAG_DONE); DTA_Color, shadeToLight(20), TAG_DONE);
@ -713,7 +713,7 @@ void EndOfLevel()
COVER_SetReverb(0); // Reset reverb COVER_SetReverb(0); // Reset reverb
Player[myconnectindex].Reverb = 0; Player[myconnectindex].Reverb = 0;
StopSound(); StopSound();
soundEngine->UpdateSounds((int)totalclock); soundEngine->UpdateSounds(gameclock);
// NextLevel must be null while the intermission is running, but we still need the value for later // NextLevel must be null while the intermission is running, but we still need the value for later
auto localNextLevel = NextLevel; auto localNextLevel = NextLevel;
NextLevel = nullptr; NextLevel = nullptr;
@ -773,26 +773,31 @@ void GameTicker(void)
ready2send = 1; ready2send = 1;
int const currentTic = I_GetTime();
gameclock = I_GetBuildTime();
if (paused) if (paused)
{ {
ototalclock = (int)totalclock - (120 / synctics);
buttonMap.ResetButtonStates(); buttonMap.ResetButtonStates();
smoothratio = MaxSmoothRatio;
} }
else else
{ {
while (ready2send && (totalclock >= ototalclock + synctics)) while (ready2send && currentTic - lastTic >= 1)
{ {
lastTic = currentTic;
UpdateInputs(); UpdateInputs();
MoveTicker(); MoveTicker();
} }
smoothratio = I_GetTimeFrac() * MaxSmoothRatio;
// Get input again to update q16ang/q16horiz. // Get input again to update q16ang/q16horiz.
if (!PedanticMode) if (!PedanticMode)
getinput(&loc, TRUE); getinput(&loc, TRUE);
} }
drawscreen(Player + screenpeek); drawscreen(Player + screenpeek, smoothratio);
ready2send = 0; ready2send = 0;
} }
if (ExitLevel) if (ExitLevel)
@ -818,8 +823,9 @@ void GameInterface::RunGameFrame()
{ {
default: default:
case GS_STARTUP: case GS_STARTUP:
totalclock = 0; I_ResetTime();
ototalclock = 0; lastTic = -1;
gameclock = 0;
if (userConfig.CommandMap.IsNotEmpty()) if (userConfig.CommandMap.IsNotEmpty())
{ {

View file

@ -2198,7 +2198,9 @@ extern USER puser[MAX_SW_PLAYERS_REG];
// //
/////////////////////////// ///////////////////////////
extern int ototalclock, save_totalclock, gotlastpacketclock; extern int gotlastpacketclock;
extern int gameclock;
extern int lastTic;
extern SWBOOL ready2send; extern SWBOOL ready2send;
extern double smoothratio; extern double smoothratio;
@ -2259,7 +2261,7 @@ void DebugWriteString(char *string); // game.c
void getsyncstat(void); // sync.c void getsyncstat(void); // sync.c
void SyncStatMessage(void); // sync.c void SyncStatMessage(void); // sync.c
void drawscreen(PLAYERp pp); // draw.c void drawscreen(PLAYERp pp, double smoothratio); // draw.c
void post_analyzesprites(void); // draw.c void post_analyzesprites(void); // draw.c
int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c int COVERsetgamemode(int mode, int xdim, int ydim, int bpp); // draw.c
void ScreenCaptureKeys(void); // draw.c void ScreenCaptureKeys(void); // draw.c

View file

@ -300,7 +300,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; oscilationclock = gameclock;
for (i = 0; i < MAXMIRRORS; i++) for (i = 0; i < MAXMIRRORS; i++)
{ {
@ -532,7 +532,7 @@ void JS_DrawCameras(PLAYERp pp, int tx, int ty, int tz)
SWBOOL bIsWallMirror = FALSE; SWBOOL bIsWallMirror = FALSE;
camloopcnt += (int32_t) (totalclock - ototalclock); camloopcnt += gameclock - gameclock;
if (camloopcnt > (60 * 5)) // 5 seconds per player view if (camloopcnt > (60 * 5)) // 5 seconds per player view
{ {
camloopcnt = 0; camloopcnt = 0;
@ -545,7 +545,7 @@ 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; uint32_t oscilation_delta = gameclock - oscilationclock;
oscilation_delta -= oscilation_delta % 4; oscilation_delta -= oscilation_delta % 4;
oscilationclock += oscilation_delta; oscilationclock += oscilation_delta;
oscilation_delta *= 2; oscilation_delta *= 2;

View file

@ -139,7 +139,7 @@ void drawoverheadmap(int cposx, int cposy, int czoom, short cang)
if (Player[p].PlayerSprite == j) if (Player[p].PlayerSprite == j)
{ {
if (sprite[Player[p].PlayerSprite].xvel > 16) if (sprite[Player[p].PlayerSprite].xvel > 16)
pspr_ndx[myconnectindex] = (((int32_t) totalclock>>4)&3); pspr_ndx[myconnectindex] = ((gameclock >> 4)&3);
sprisplayer = TRUE; sprisplayer = TRUE;
goto SHOWSPRITE; goto SHOWSPRITE;

View file

@ -95,9 +95,8 @@ uint8_t syncstat[MAXSYNCBYTES];
int syncvaltail, syncvaltottail; int syncvaltail, syncvaltottail;
void GetSyncInfoFromPacket(uint8_t *packbuf, int packbufleng, int *j, int otherconnectindex); void GetSyncInfoFromPacket(uint8_t *packbuf, int packbufleng, int *j, int otherconnectindex);
// when you set totalclock to 0 also set this one int gameclock;
int ototalclock; int lastTic;
int save_totalclock;
double smoothratio; double smoothratio;
// must start out as 0 // must start out as 0
@ -166,8 +165,9 @@ InitTimingVars(void)
// resettiming(); // resettiming();
totalsynctics = 0; totalsynctics = 0;
totalclock = 0; I_ResetTime();
ototalclock = 0; lastTic = -1;
gameclock = 0;
randomseed = 17L; randomseed = 17L;
MoveSkip8 = 2; MoveSkip8 = 2;
@ -191,8 +191,6 @@ UpdateInputs(void)
int i, j, k; int i, j, k;
PLAYERp pp; PLAYERp pp;
ototalclock += synctics;
//getpackets(); //getpackets();
if (Player[myconnectindex].movefifoend - movefifoplc >= 100) if (Player[myconnectindex].movefifoend - movefifoplc >= 100)

View file

@ -978,7 +978,7 @@ InitWeaponSword(PLAYERp pp)
PlaySound(DIGI_SWORD_UP, pp, v3df_follow|v3df_dontpan); PlaySound(DIGI_SWORD_UP, pp, v3df_follow|v3df_dontpan);
if (pp == Player+myconnectindex && totalclock > 0) if (pp == Player+myconnectindex && gameclock > 0)
{ {
rnd_num = STD_RANDOM_RANGE(1024); rnd_num = STD_RANDOM_RANGE(1024);
if (rnd_num > 900) if (rnd_num > 900)

View file

@ -562,7 +562,7 @@ bool GameInterface::SaveGame(FSaveGameNode *sv)
#endif #endif
#endif #endif
MWRITE(&totalclock,sizeof(totalclock),1,fil); MWRITE(&gameclock,sizeof(gameclock),1,fil);
MWRITE(&NormalVisibility,sizeof(NormalVisibility),1,fil); MWRITE(&NormalVisibility,sizeof(NormalVisibility),1,fil);
MWRITE(&MoveSkip2,sizeof(MoveSkip2),1,fil); MWRITE(&MoveSkip2,sizeof(MoveSkip2),1,fil);
@ -936,7 +936,7 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
#endif #endif
#endif #endif
MREAD(&totalclock,sizeof(totalclock),1,fil); MREAD(&gameclock,sizeof(gameclock),1,fil);
MREAD(&NormalVisibility,sizeof(NormalVisibility),1,fil); MREAD(&NormalVisibility,sizeof(NormalVisibility),1,fil);
@ -1055,10 +1055,6 @@ bool GameInterface::LoadGame(FSaveGameNode* sv)
SetupPreCache(); SetupPreCache();
DoTheCache(); DoTheCache();
// what is this for? don't remember
totalclock = totalsynctics;
ototalclock = totalsynctics;
// this is ok - just duplicating sector list with pointers // this is ok - just duplicating sector list with pointers
for (sop = SectorObject; sop < &SectorObject[SIZ(SectorObject)]; sop++) for (sop = SectorObject; sop < &SectorObject[SIZ(SectorObject)]; sop++)
{ {

View file

@ -770,11 +770,11 @@ private:
imgScale = baseScale / img->GetDisplayHeight(); imgScale = baseScale / img->GetDisplayHeight();
DrawGraphic(img, 1.5, -1, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, imgScale, imgScale); DrawGraphic(img, 1.5, -1, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, imgScale, imgScale);
if (!althud_flashing || u->Health > (u->MaxHealth >> 2) || ((int)totalclock & 32)) if (!althud_flashing || u->Health > (u->MaxHealth >> 2) || (gameclock & 32))
{ {
int s = -8; int s = -8;
if (althud_flashing && u->Health > u->MaxHealth) if (althud_flashing && u->Health > u->MaxHealth)
s += (sintable[((int)totalclock << 5) & 2047] >> 10); s += (sintable[(gameclock << 5) & 2047] >> 10);
int intens = clamp(255 - 4 * s, 0, 255); int intens = clamp(255 - 4 * s, 0, 255);
auto pe = PalEntry(255, intens, intens, intens); auto pe = PalEntry(255, intens, intens, intens);
format.Format("%d", u->Health); format.Format("%d", u->Health);
@ -812,7 +812,7 @@ private:
imgX += (imgX * 0.855) * (strlen - 1); imgX += (imgX * 0.855) * (strlen - 1);
} }
if ((!althud_flashing || (int)totalclock & 32 || pp->WpnAmmo[weapon] > (DamageData[weapon].max_ammo / 10))) if ((!althud_flashing || gameclock & 32 || pp->WpnAmmo[weapon] > (DamageData[weapon].max_ammo / 10)))
{ {
SBar_DrawString(this, &numberFont, format, -1.5, -numberFont.mFont->GetHeight(), DI_TEXT_ALIGN_RIGHT, CR_UNTRANSLATED, 1, 0, 0, 1, 1); SBar_DrawString(this, &numberFont, format, -1.5, -numberFont.mFont->GetHeight(), DI_TEXT_ALIGN_RIGHT, CR_UNTRANSLATED, 1, 0, 0, 1, 1);
} }

View file

@ -304,7 +304,7 @@ static void RestartAmbient(AmbientSound* amb)
int pitch = 0; int pitch = 0;
if (vp.pitch_hi <= vp.pitch_lo) pitch = vp.pitch_lo; if (vp.pitch_hi <= vp.pitch_lo) pitch = vp.pitch_lo;
else pitch = vp.pitch_lo + (STD_RANDOM_RANGE(vp.pitch_hi - vp.pitch_lo)); else pitch = vp.pitch_lo + (STD_RANDOM_RANGE(vp.pitch_hi - vp.pitch_lo));
amb->curIndex = (int)totalclock; amb->curIndex = gameclock;
if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, amb, CHAN_BODY, amb->vocIndex)) if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, amb, CHAN_BODY, amb->vocIndex))
soundEngine->StartSound(SOURCE_Ambient, amb, nullptr, CHAN_BODY, EChanFlags::FromInt(amb->ChanFlags), amb->vocIndex, 1.f, ATTN_NORM, &rolloff, S_ConvertPitch(pitch)); soundEngine->StartSound(SOURCE_Ambient, amb, nullptr, CHAN_BODY, EChanFlags::FromInt(amb->ChanFlags), amb->vocIndex, 1.f, ATTN_NORM, &rolloff, S_ConvertPitch(pitch));
@ -343,7 +343,7 @@ static int RandomizeAmbientSpecials(int handle)
static void DoTimedSound(AmbientSound* amb) static void DoTimedSound(AmbientSound* amb)
{ {
if ((int)totalclock >= amb->curIndex + amb->maxIndex) if (gameclock >= amb->curIndex + amb->maxIndex)
{ {
if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, amb, CHAN_BODY)) if (!soundEngine->IsSourcePlayingSomething(SOURCE_Ambient, amb, CHAN_BODY))
{ {
@ -604,7 +604,7 @@ void DoUpdateSounds(void)
soundEngine->SetListener(listener); soundEngine->SetListener(listener);
UpdateAmbients(); UpdateAmbients();
soundEngine->UpdateSounds((int)totalclock); soundEngine->UpdateSounds(gameclock);
} }
//========================================================================== //==========================================================================

View file

@ -17798,16 +17798,16 @@ InitUzi(PLAYERp pp)
PlayerUpdateAmmo(pp, u->WeaponNum, -1); PlayerUpdateAmmo(pp, u->WeaponNum, -1);
if (uziclock > totalclock) if (uziclock > gameclock)
{ {
uziclock = (int32_t) totalclock; uziclock = gameclock;
FireSnd = TRUE; FireSnd = TRUE;
} }
clockdiff = (int32_t) totalclock - uziclock; clockdiff = gameclock - uziclock;
if (clockdiff > UZIFIRE_WAIT) if (clockdiff > UZIFIRE_WAIT)
{ {
uziclock = (int32_t) totalclock; uziclock = gameclock;
FireSnd = TRUE; FireSnd = TRUE;
} }