diff --git a/source/common/utility/i_time.cpp b/source/common/utility/i_time.cpp index 2db0d4918..20c5ac831 100644 --- a/source/common/utility/i_time.cpp +++ b/source/common/utility/i_time.cpp @@ -69,6 +69,11 @@ static int NSToTic(uint64_t ns) return static_cast(ns * GameTicRate / 1'000'000'000); } +static int NSToBuildTic(uint64_t ns) +{ + return static_cast(ns * 120 / 1'000'000'000); +} + static uint64_t TicToNS(int tic) { return static_cast(tic) * 1'000'000'000 / GameTicRate; @@ -160,6 +165,11 @@ int I_GetTime() return NSToTic(CurrentFrameStartTime - FirstFrameStartTime); } +int I_GetBuildTime() +{ + return NSToBuildTic(CurrentFrameStartTime - FirstFrameStartTime); +} + double I_GetTimeFrac() { int currentTic = NSToTic(CurrentFrameStartTime - FirstFrameStartTime); diff --git a/source/common/utility/i_time.h b/source/common/utility/i_time.h index 71f436dbf..1146cbd7d 100644 --- a/source/common/utility/i_time.h +++ b/source/common/utility/i_time.h @@ -12,6 +12,9 @@ int I_GetTime(); // same, but using nanoseconds uint64_t I_GetTimeNS(); +// Called by Build games in liew of totalclock, returns current time in tics at ticrate of 120. +int I_GetBuildTime(); + double I_GetTimeFrac(); // like I_GetTime, except it waits for a new tic before returning diff --git a/source/games/duke/src/animatesprites_d.cpp b/source/games/duke/src/animatesprites_d.cpp index 2e3cc1ef3..9c5a19b76 100644 --- a/source/games/duke/src/animatesprites_d.cpp +++ b/source/games/duke/src/animatesprites_d.cpp @@ -153,7 +153,7 @@ void animatesprites_d(int x,int y,int a,int smoothratio) case SECTOREFFECTOR: if(t->lotag == 27 && ud.recstat == 1) { - t->picnum = 11+(((int)totalclock>>3)&1); + t->picnum = 11+((gameclock>>3)&1); t->cstat |= 128; } else @@ -250,7 +250,7 @@ void animatesprites_d(int x,int y,int a,int smoothratio) t->z -= (4<<8); break; case CRYSTALAMMO: - t->shade = (sintable[((int)totalclock<<4)&2047]>>10); + t->shade = (sintable[(gameclock<<4)&2047]>>10); continue; case VIEWSCREEN: case VIEWSCREEN2: @@ -268,10 +268,10 @@ void animatesprites_d(int x,int y,int a,int smoothratio) break; case SHRINKSPARK: - t->picnum = SHRINKSPARK+( ((int)totalclock>>4)&3 ); + t->picnum = SHRINKSPARK+( (gameclock>>4)&3 ); break; case GROWSPARK: - t->picnum = GROWSPARK+( ((int)totalclock>>4)&3 ); + t->picnum = GROWSPARK+( (gameclock>>4)&3 ); break; case RPG: /*if (bpp > 8 && usemodels && md_tilehasmodel(s->picnum) >= 0) { @@ -646,7 +646,7 @@ void animatesprites_d(int x,int y,int a,int smoothratio) if(t->picnum == EXPLOSION2) { ps[screenpeek].visibility = -127; - lastvisinc = (int)totalclock+32; + lastvisinc = gameclock+32; } t->shade = -127; break; diff --git a/source/games/duke/src/animatesprites_r.cpp b/source/games/duke/src/animatesprites_r.cpp index 50277d911..2892806fe 100644 --- a/source/games/duke/src/animatesprites_r.cpp +++ b/source/games/duke/src/animatesprites_r.cpp @@ -142,7 +142,7 @@ void animatesprites_r(int x,int y,int a,int smoothratio) case SECTOREFFECTOR: if (t->lotag == 27 && ud.recstat == 1) { - t->picnum = 11 + (((int)totalclock >> 3) & 1); + t->picnum = 11 + ((gameclock >> 3) & 1); t->cstat |= 128; } else @@ -180,7 +180,7 @@ void animatesprites_r(int x,int y,int a,int smoothratio) case RESPAWNMARKERRED: case RESPAWNMARKERYELLOW: case RESPAWNMARKERGREEN: - t->picnum = 861+( ((int)totalclock>>4) & 13); + t->picnum = 861+( (gameclock>>4) & 13); if (s->picnum == RESPAWNMARKERRED) t->pal = 0; else if (s->picnum == RESPAWNMARKERYELLOW) @@ -247,21 +247,21 @@ void animatesprites_r(int x,int y,int a,int smoothratio) t->z -= (4<<8); break; case CRYSTALAMMO: - t->shade = (sintable[((int)totalclock<<4)&2047]>>10); + t->shade = (sintable[(gameclock<<4)&2047]>>10); break; case SHRINKSPARK: if ((sprite[s->owner].picnum == CHEER || sprite[s->owner].picnum == CHEERSTAYPUT) && isRRRA()) { - t->picnum = CHEERBLADE+( ((int)totalclock>>4)&3 ); + t->picnum = CHEERBLADE+( (gameclock>>4)&3 ); t->shade = -127; } else - t->picnum = SHRINKSPARK+( ((int)totalclock>>4)&7 ); + t->picnum = SHRINKSPARK+( (gameclock>>4)&7 ); break; case CHEERBOMB: if (isRRRA()) { - t->picnum = CHEERBOMB + (((int)totalclock >> 4) & 3); + t->picnum = CHEERBOMB + ((gameclock >> 4) & 3); break; } else goto default_case; @@ -269,10 +269,10 @@ void animatesprites_r(int x,int y,int a,int smoothratio) if(isRRRA()) { if (sprite[s->owner].picnum == MINION && sprite[s->owner].pal == 8) - t->picnum = RRTILE3500 + (((int)totalclock >> 4) % 6); + t->picnum = RRTILE3500 + ((gameclock >> 4) % 6); else if (sprite[s->owner].picnum == MINION && sprite[s->owner].pal == 19) { - t->picnum = RRTILE5090 + (((int)totalclock >> 4) & 3); + t->picnum = RRTILE5090 + ((gameclock >> 4) & 3); t->shade = -127; } else if (sprite[s->owner].picnum == MAMA) @@ -288,10 +288,10 @@ void animatesprites_r(int x,int y,int a,int smoothratio) t->picnum = RRTILE7274 + k; } else - t->picnum = SPIT + (((int)totalclock >> 4) & 3); + t->picnum = SPIT + ((gameclock >> 4) & 3); } else - t->picnum = SPIT + (((int)totalclock >> 4) & 3); + t->picnum = SPIT + ((gameclock >> 4) & 3); break; case EMPTYBIKE: if (!isRRRA()) goto default_case; @@ -796,12 +796,12 @@ void animatesprites_r(int x,int y,int a,int smoothratio) if(t->picnum == EXPLOSION2) { ps[screenpeek].visibility = -127; - lastvisinc = (int)totalclock+32; + lastvisinc = gameclock+32; t->pal = 0; } else if(t->picnum == FIRELASER) { - t->picnum = FIRELASER+(((int)totalclock>>2)&5); + t->picnum = FIRELASER+((gameclock>>2)&5); } t->shade = -127; break; @@ -897,11 +897,11 @@ void animatesprites_r(int x,int y,int a,int smoothratio) t->shade = -127; break; case RRTILE2034: - t->picnum = RRTILE2034+((int)totalclock&1); + t->picnum = RRTILE2034+(gameclock&1); break; case RRTILE2944: t->shade = -127; - t->picnum = RRTILE2944+(((int)totalclock>>2)&4); + t->picnum = RRTILE2944+((gameclock>>2)&4); break; case PLAYERONWATER: diff --git a/source/games/duke/src/cheats.cpp b/source/games/duke/src/cheats.cpp index 235bf505d..3ce0c9e87 100644 --- a/source/games/duke/src/cheats.cpp +++ b/source/games/duke/src/cheats.cpp @@ -228,7 +228,7 @@ static bool cheatView(cheatseq_t *) { ps[myconnectindex].over_shoulder_on = 1; cameradist = 0; - cameraclock = (int)totalclock; + cameraclock = gameclock; } //FTA(22,&ps[myconnectindex]); this message makes no sense. } diff --git a/source/games/duke/src/d_menu.cpp b/source/games/duke/src/d_menu.cpp index 656241b14..4c9524e5d 100644 --- a/source/games/duke/src/d_menu.cpp +++ b/source/games/duke/src/d_menu.cpp @@ -67,9 +67,9 @@ static void Menu_DrawCursor(double x, double y, double scale, bool right) { const int frames = isRR() ? 16 : 7; int picnum; - if (!right) picnum = TILE_SPINNINGNUKEICON + (((int)totalclock >> 3) % frames); - else picnum = TILE_SPINNINGNUKEICON + frames - 1 - ((frames - 1 + ((int)totalclock >> 3)) % frames); - int light = int(224 + 31 * sin((int)totalclock / 20.)); + if (!right) picnum = TILE_SPINNINGNUKEICON + ((gameclock >> 3) % frames); + else picnum = TILE_SPINNINGNUKEICON + frames - 1 - ((frames - 1 + (gameclock >> 3)) % frames); + int light = int(224 + 31 * sin(gameclock / 20.)); PalEntry pe(255, light, light, light); DrawTexture(twod, tileGetTexture(picnum), x, y, DTA_FullscreenScale, FSMode_Fit320x200, DTA_ScaleX, scale, DTA_ScaleY, scale, DTA_Color, pe, DTA_CenterOffsetRel, true, TAG_DONE); } @@ -153,7 +153,7 @@ class DukeMainMenu : public DukeListMenu DrawTexture(twod, tileGetTexture(TILE_INGAMEDUKETHREEDEE), x, origin.Y + 29, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_CenterOffsetRel, true, TAG_DONE); if (PLUTOPAK) { - int light = 224 + 31 * sin(int(totalclock) / 40.); + int light = 224 + 31 * sin(gameclock / 40.); PalEntry pe(255, light, light, light); DrawTexture(twod, tileGetTexture(TILE_PLUTOPAKSPRITE + 2), x + 100, origin.Y + 36, DTA_FullscreenScale, FSMode_Fit320x200Top, DTA_Color, pe, DTA_CenterOffsetRel, true, TAG_DONE); } @@ -186,7 +186,7 @@ void GameInterface::DrawNativeMenuText(int fontnum, int state, double oxpos, dou else if (state == NIT_SelectedState) { trans = 0; - int light = 224 + 31 * sin(int(totalclock) / 20.); + int light = 224 + 31 * sin(gameclock / 20.); pe = PalEntry(255, light, light, light); } else @@ -219,7 +219,7 @@ void GameInterface::MenuOpened() if (ud.multimode < 2) { ready2send = 0; - totalclock = ototalclock; + //I_FreezeTime(true); screenpeek = myconnectindex; } } @@ -261,8 +261,8 @@ void GameInterface::MenuClosed() if (ud.multimode < 2 && ud.recstat != 2) { ready2send = 1; - totalclock = ototalclock; - cameraclock = (int32_t)totalclock; + //I_FreezeTime(false); + cameraclock = gameclock; cameradist = 65536; } } @@ -347,7 +347,7 @@ static int GetPlayerColor(int color) void GameInterface::DrawPlayerSprite(const DVector2& origin, bool onteam) { int color = TRANSLATION(Translation_Remap, playercolor2lookup(playercolor)); - int tile = isRR() ? 3845 + 36 - ((((8 - (totalclock >> 4))) & 7) * 5) : 1441 - ((((4 - (totalclock >> 4))) & 3) * 5); + int tile = isRR() ? 3845 + 36 - ((((8 - (gameclock >> 4))) & 7) * 5) : 1441 - ((((4 - (gameclock >> 4))) & 3) * 5); auto tex = tileGetTexture(tile); if (!tex) return; double x = origin.X + 260, y = origin.Y + tex->GetDisplayHeight() * (isRR()? 0.25 : 0.5); diff --git a/source/games/duke/src/game.cpp b/source/games/duke/src/game.cpp index 1ec0363ef..4a333deb8 100644 --- a/source/games/duke/src/game.cpp +++ b/source/games/duke/src/game.cpp @@ -350,7 +350,7 @@ static void Startup(void) SetDispatcher(); S_InitSound(); - timerInit(GameTicRate); + timerInit(TICRATE); loadcons(); fi.initactorflags(); diff --git a/source/games/duke/src/game_misc.cpp b/source/games/duke/src/game_misc.cpp index cd764d77f..9a1a30e89 100644 --- a/source/games/duke/src/game_misc.cpp +++ b/source/games/duke/src/game_misc.cpp @@ -149,7 +149,7 @@ void FTA(int q, struct player_struct* p) if (q < 0 || !(p->gm & MODE_GAME)) return; - if (p->ftq != q || (totalclock - p->ftt > TICRATE && q != QUOTE_DEAD)) + if (p->ftq != q || (gameclock - p->ftt > TICRATE && q != QUOTE_DEAD)) { p->ftq = q; auto qu = quoteMgr.GetQuote(q); @@ -167,7 +167,7 @@ void FTA(int q, struct player_struct* p) } } } - p->ftt = totalclock; + p->ftt = gameclock; } //========================================================================== @@ -639,7 +639,7 @@ void drawoverheadmap(int cposx, int cposy, int czoom, int cang) { auto& pp = ps[p]; if (sprite[pp.i].xvel > 16 && pp.on_ground) - i = TILE_APLAYERTOP + (((int)totalclock >> 4) & 3); + i = TILE_APLAYERTOP + ((gameclock >> 4) & 3); else i = TILE_APLAYERTOP; @@ -675,16 +675,16 @@ void cameratext(int i) drawitem(TILE_CAMCORNER + 1, 24, 163, true, true); drawitem(TILE_CAMCORNER + 1, 320 - 26, 163, false, true); - if ((int)totalclock & 16) + if (gameclock & 16) drawitem(TILE_CAMLIGHT, 46, 32, false, false); } else { - int flipbits = ((int)totalclock << 1) & 48; + int flipbits = (gameclock << 1) & 48; for (int x = -64; x < 394; x += 64) for (int y = 0; y < 200; y += 64) - drawitem(TILE_STATIC, x, y, !!((int)totalclock & 8), !!((int)totalclock & 16)); + drawitem(TILE_STATIC, x, y, !!(gameclock & 8), !!(gameclock & 16)); } } diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 49c45dd84..52e9dfde3 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -1042,7 +1042,7 @@ int ParseState::parse(void) resetweapons(g_p); //cameradist = 0; - //cameraclock = totalclock; + //cameraclock = gameclock; } setpal(&ps[g_p]); break; diff --git a/source/games/duke/src/gameloop.cpp b/source/games/duke/src/gameloop.cpp index bbbe19b7a..b0f75d1a5 100644 --- a/source/games/duke/src/gameloop.cpp +++ b/source/games/duke/src/gameloop.cpp @@ -329,11 +329,13 @@ bool GameTicker() gameupdatetime.Reset(); gameupdatetime.Clock(); - int currentTic = I_GetTime(); + int const currentTic = I_GetTime(); + gameclock = I_GetBuildTime(); if (playrunning() && currentTic - lastTic >= 1) { lastTic = currentTic; + gameclock = currentTic << 2; GetInput(); auto const pPlayer = &ps[myconnectindex]; @@ -356,11 +358,10 @@ bool GameTicker() moveloop(); } } - if (!playrunning()) - { - ototalclock = totalclock - 1; - } - double const smoothRatio = I_GetTimeFrac() * 65536.; + + //I_FreezeTime(!playrunning()); + + double const smoothRatio = playrunning() ? I_GetTimeFrac() * MaxSmoothRatio : MaxSmoothRatio; gameupdatetime.Unclock(); @@ -414,7 +415,7 @@ void GameInterface::RunGameFrame() default: case GS_STARTUP: totalclock = 0; - ototalclock = 0; + gameclock = 0; lockclock = 0; ps[myconnectindex].ftq = 0; diff --git a/source/games/duke/src/global.cpp b/source/games/duke/src/global.cpp index 138b67dfd..be6e1a7d6 100644 --- a/source/games/duke/src/global.cpp +++ b/source/games/duke/src/global.cpp @@ -53,7 +53,7 @@ int max_player_health; int max_armour_amount; int lasermode; -int cameradist = 0, cameraclock = 0; +int gameclock = 0, cameradist = 0, cameraclock = 0; int otherp; TileInfo tileinfo[MAXTILES]; // This is not from EDuke32. ActorInfo actorinfo[MAXTILES]; @@ -69,7 +69,6 @@ int gamequit; int playerswhenstarted; int show_shareware; int screenpeek; -ClockTicks ototalclock; diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index c6d198feb..15125498a 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -37,6 +37,7 @@ extern int max_player_health; extern int max_armour_amount; extern int lasermode; +extern int gameclock; extern int cameraclock; extern int cameradist; extern int otherp; // transient helper, MP only @@ -56,7 +57,6 @@ extern int gamequit; extern int playerswhenstarted; extern int show_shareware; extern int screenpeek; -extern ClockTicks ototalclock; // Variables that must be saved extern uint8_t sectorextra[MAXSECTORS]; // these hold fields that were formerly in sprite and sector. Move these back into the base structs! diff --git a/source/games/duke/src/hudweapon_r.cpp b/source/games/duke/src/hudweapon_r.cpp index 77c267b57..fc0559d85 100644 --- a/source/games/duke/src/hudweapon_r.cpp +++ b/source/games/duke/src/hudweapon_r.cpp @@ -77,7 +77,7 @@ void displaymasks_r(int snum) { int pin = 0; if (!(duke3d_globalflags & DUKE3D_NO_WIDESCREEN_PINNING)) pin = RS_STRETCH; - hud_drawsprite((320 - (tilesiz[SCUBAMASK].x >> 1) - 15), (200 - (tilesiz[SCUBAMASK].y >> 1) + (calcSinTableValue(totalclock) / 1024.)), 49152, 0, SCUBAMASK, 0, p, 2 + 16 + pin); + hud_drawsprite((320 - (tilesiz[SCUBAMASK].x >> 1) - 15), (200 - (tilesiz[SCUBAMASK].y >> 1) + (calcSinTableValue(gameclock) / 1024.)), 49152, 0, SCUBAMASK, 0, p, 2 + 16 + pin); hud_drawsprite((320 - tilesiz[SCUBAMASK + 4].x), (200 - tilesiz[SCUBAMASK + 4].y), 65536, 0, SCUBAMASK + 4, 0, p, 2 + 16 + pin); hud_drawsprite(tilesiz[SCUBAMASK + 4].x, (200 - tilesiz[SCUBAMASK + 4].y), 65536, 0, SCUBAMASK + 4, 0, p, 2 + 4 + 16 + pin); hud_drawsprite(35, (-1), 65536, 0, SCUBAMASK + 3, 0, p, 2 + 16 + pin); diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 73e26e49d..e40eb1255 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -104,7 +104,7 @@ void nonsharedkeys(void) { ps[myconnectindex].over_shoulder_on = 1; cameradist = 0; - cameraclock = (int)totalclock; + cameraclock = gameclock; } FTA(QUOTE_VIEW_MODE_OFF + ps[myconnectindex].over_shoulder_on, &ps[myconnectindex]); } @@ -113,15 +113,15 @@ void nonsharedkeys(void) if (automapMode != am_off) { int j; - if (nonsharedtimer > 0 || totalclock < nonsharedtimer) + if (nonsharedtimer > 0 || gameclock < nonsharedtimer) { - j = (int)totalclock - nonsharedtimer; + j = gameclock - nonsharedtimer; nonsharedtimer += j; } else { j = 0; - nonsharedtimer = (int)totalclock; + nonsharedtimer = gameclock; } if (buttonMap.ButtonDown(gamefunc_Enlarge_Screen)) @@ -712,8 +712,8 @@ static void checkCrouchToggle(player_struct* p) int getticssincelastupdate() { - int tics = lastcontroltime == 0 || (int)totalclock < lastcontroltime ? 0 : (int)totalclock - lastcontroltime; - lastcontroltime = (int)totalclock; + int tics = lastcontroltime == 0 || gameclock < lastcontroltime ? 0 : gameclock - lastcontroltime; + lastcontroltime = gameclock; return tics; } diff --git a/source/games/duke/src/player.cpp b/source/games/duke/src/player.cpp index bd9d9322e..701d92123 100644 --- a/source/games/duke/src/player.cpp +++ b/source/games/duke/src/player.cpp @@ -1265,8 +1265,8 @@ bool view(struct player_struct* pp, int* vx, int* vy, int* vz, short* vsectnum, *vy = (*vy) + mulscale16(ny, cameradist); *vz = (*vz) + mulscale16(nz, cameradist); - cameradist = min(cameradist + (((int)totalclock - cameraclock) << 10), 65536); - cameraclock = (int)totalclock; + cameradist = min(cameradist + ((gameclock - cameraclock) << 10), 65536); + cameraclock = gameclock; updatesectorz(*vx, *vy, *vz, vsectnum); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index b676966d5..9ab4be089 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1485,7 +1485,7 @@ int doincrements_d(struct player_struct* p) p->knuckle_incs++; if (p->knuckle_incs == 10 && !isWW2GI()) { - if ((int)totalclock > 1024) + if (gameclock > 1024) if (snum == screenpeek || ud.coop == 1) { if (rand() & 1) @@ -2162,7 +2162,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { fi.shoot(pi, SHOTSPARK1); S_PlayActorSound(PISTOL_FIRE, pi); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; } @@ -2221,7 +2221,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) S_PlayActorSound(SHOTGUN_FIRE, pi); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; } @@ -2274,7 +2274,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) S_PlayActorSound(CHAINGUN_FIRE, pi); fi.shoot(pi, CHAINGUN); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; checkavailweapon(p); @@ -2325,7 +2325,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { // make them visible if not set... p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; } checkavailweapon(p); //#endif @@ -2339,7 +2339,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { // make them visible if not set... p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; } checkavailweapon(p); } @@ -2358,7 +2358,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { p->visibility = 0; //flashColor = 176 + (252 << 8) + (120 << 16); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; checkavailweapon(p); } } @@ -2366,7 +2366,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { p->okickback_pic = p->kickback_pic = 0; p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; checkavailweapon(p); } else p->kickback_pic++; @@ -2384,7 +2384,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) (p->kickback_pic & 1)) { p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; fi.shoot(pi, RPG); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); @@ -2394,7 +2394,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) else if (p->kickback_pic & 1) { p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; fi.shoot(pi, RPG); p->ammo_amount[DEVISTATOR_WEAPON]--; checkavailweapon(p); @@ -2414,7 +2414,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) p->ammo_amount[p->curr_weapon]--; p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; fi.shoot(pi, FREEZEBLAST); checkavailweapon(p); } @@ -2497,7 +2497,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) if (p->kickback_pic == 4) { p->ammo_amount[RPG_WEAPON]--; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; fi.shoot(pi, RPG); checkavailweapon(p); diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 77eaaa72c..882a935fc 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1399,7 +1399,7 @@ int doincrements_r(struct player_struct* p) } S_PlayActorSound(snd, p->i); } - else if (totalclock > 1024) + else if (gameclock > 1024) if (snum == screenpeek || ud.coop == 1) { if (rand() & 1) @@ -2851,7 +2851,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) p->noise_radius = 8192; madenoise(snum); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; if (psectlotag != 857) { @@ -2930,7 +2930,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) p->noise_radius = 8192; madenoise(snum); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; } @@ -3041,7 +3041,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) fi.shoot(pi, CHAINGUN); p->noise_radius = 8192; madenoise(snum); - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; if (psectlotag != 857) @@ -3097,7 +3097,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) if (p->kickback_pic == 2 || p->kickback_pic == 4) { p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; S_PlayActorSound(CHAINGUN_FIRE, pi); fi.shoot(pi, SHOTSPARK1); p->noise_radius = 16384; @@ -3124,7 +3124,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) if (p->kickback_pic == 2 || p->kickback_pic == 4) { p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; S_PlayActorSound(CHAINGUN_FIRE, pi); fi.shoot(pi, CHAINGUN); p->noise_radius = 16384; @@ -3182,7 +3182,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) { p->ammo_amount[ALIENBLASTER_WEAPON]--; p->visibility = 0; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; checkavailweapon(p); } else if (p->kickback_pic == 12) @@ -3291,7 +3291,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) p->ammo_amount[CROSSBOW_WEAPON]--; if (p->ammo_amount[DYNAMITE_WEAPON]) p->ammo_amount[DYNAMITE_WEAPON]--; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; fi.shoot(pi, RPG); p->noise_radius = 32768; @@ -3309,7 +3309,7 @@ static void operateweapon(int snum, ESyncBits sb_snum, int psect) if (p->kickback_pic == 4) { p->ammo_amount[CHICKEN_WEAPON]--; - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; fi.shoot(pi, RPG2); p->noise_radius = 32768; diff --git a/source/games/duke/src/player_w.cpp b/source/games/duke/src/player_w.cpp index b65eb92f3..cc23579be 100644 --- a/source/games/duke/src/player_w.cpp +++ b/source/games/duke/src/player_w.cpp @@ -77,7 +77,7 @@ void DoFire(struct player_struct *p, short snum) if(! (aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE )) { // make them visible if not set... - lastvisinc = (int)totalclock+32; + lastvisinc = gameclock+32; p->visibility = 0; } @@ -400,7 +400,7 @@ void operateweapon_ww(int snum, ESyncBits sb_snum, int psect) if (!(aplWeaponFlags[p->curr_weapon][snum] & WEAPON_FLAG_NOVISIBLE)) { // make them visible if not set... - lastvisinc = (int)totalclock + 32; + lastvisinc = gameclock + 32; p->visibility = 0; } SetGameVarID(g_iWeaponVarID, p->curr_weapon, p->i, snum); diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index bd9bbe370..b10f08d6b 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -757,9 +757,9 @@ void prelevel_common(int g) void resettimevars(void) { totalclock = 0; + gameclock = 0; cloudtotalclock = 0; levelTextTime = 85; - ototalclock = 0; lockclock = 0; ready2send = 1; if (camsprite >= 0) diff --git a/source/games/duke/src/render.cpp b/source/games/duke/src/render.cpp index afa0b9d8c..4d2e5aa8f 100644 --- a/source/games/duke/src/render.cpp +++ b/source/games/duke/src/render.cpp @@ -643,7 +643,7 @@ void displayrooms(int snum, int smoothratio) if (!isRRRA() || !fogactive) { - if (totalclock < lastvisinc) + if (gameclock < lastvisinc) { if (abs(p->visibility - ud.const_visibility) > 8) p->visibility += (ud.const_visibility - p->visibility) >> 2; diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index b07719d3a..7eb5f0393 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -480,8 +480,7 @@ void GameInterface::SerializeGameState(FSerializer& arc) ("thunder_brightness", thunder_brightness) // Todo: move to backend - ("totalclock", totalclock) - ("ototalclock", ototalclock) + ("gameclock", gameclock) ("totalclocklock", totalclocklock) ("lockclock", lockclock) @@ -544,10 +543,6 @@ void GameInterface::SerializeGameState(FSerializer& arc) FX_SetReverb(0); } - else - { - ototalclock = totalclock; - } ready2send = 1; } } diff --git a/source/games/duke/src/sbar_d.cpp b/source/games/duke/src/sbar_d.cpp index fa5b3f84f..d5acf5e62 100644 --- a/source/games/duke/src/sbar_d.cpp +++ b/source/games/duke/src/sbar_d.cpp @@ -129,11 +129,11 @@ public: imgScale = baseScale / img->GetDisplayHeight(); DrawGraphic(img, 2, -1.5, DI_ITEM_LEFT_BOTTOM, 1., -1, -1, imgScale, imgScale); - if (!althud_flashing || p->last_extra > (max_player_health >> 2) || ((int)totalclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) + if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (gameclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) { int s = -8; if (althud_flashing && p->last_extra > max_player_health) - s += (sintable[((int)totalclock << 5) & 2047] >> 10); + s += (sintable[(gameclock << 5) & 2047] >> 10); int intens = clamp(255 - 4 * s, 0, 255); auto pe = PalEntry(255, intens, intens, intens); format.Format("%d", p->last_extra); @@ -170,7 +170,7 @@ public: imgX += (imgX * 0.6) * (strlen - 1); } - if (p->curr_weapon != KNEE_WEAPON && (!althud_flashing || (int)totalclock & 32 || p->ammo_amount[weapon] > (max_ammo_amount[weapon] / 10))) + if (p->curr_weapon != KNEE_WEAPON && (!althud_flashing || gameclock & 32 || p->ammo_amount[weapon] > (max_ammo_amount[weapon] / 10))) { SBar_DrawString(this, &numberFont, format, -3, texty, DI_TEXT_ALIGN_RIGHT, CR_UNTRANSLATED, 1, 0, 0, 1, 1); } diff --git a/source/games/duke/src/sbar_r.cpp b/source/games/duke/src/sbar_r.cpp index 0c23863fb..e7f322bd9 100644 --- a/source/games/duke/src/sbar_r.cpp +++ b/source/games/duke/src/sbar_r.cpp @@ -106,11 +106,11 @@ public: imgScale = baseScale / img->GetDisplayHeight(); DrawGraphic(img, 2, -2, DI_ITEM_LEFT_BOTTOM, 1, 0, 0, imgScale, imgScale); - if (!althud_flashing || p->last_extra > (max_player_health >> 2) || ((int)totalclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) + if (!althud_flashing || p->last_extra > (max_player_health >> 2) || (gameclock & 32) || (sprite[p->i].pal == 1 && p->last_extra < 2)) { int s = -8; if (althud_flashing && p->last_extra > max_player_health) - s += (sintable[((int)totalclock << 5) & 2047] >> 10); + s += (sintable[(gameclock << 5) & 2047] >> 10); int intens = clamp(255 - 4 * s, 0, 255); auto pe = PalEntry(255, intens, intens, intens); format.Format("%d", p->last_extra); @@ -155,7 +155,7 @@ public: imgX += (imgX * 0.755) * (strlen - 1); } - if (p->curr_weapon != KNEE_WEAPON && p->curr_weapon != SLINGBLADE_WEAPON && (!althud_flashing || (int)totalclock & 32 || p->ammo_amount[weapon] > (max_ammo_amount[weapon] / 10))) + if (p->curr_weapon != KNEE_WEAPON && p->curr_weapon != SLINGBLADE_WEAPON && (!althud_flashing || gameclock & 32 || p->ammo_amount[weapon] > (max_ammo_amount[weapon] / 10))) { SBar_DrawString(this, &numberFont, format, -1, -numberFont.mFont->GetHeight() * scale + 4, DI_TEXT_ALIGN_RIGHT, CR_UNTRANSLATED, 1, 0, 0, scale, scale); } diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 55a9451ca..c87aac25b 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -1142,9 +1142,9 @@ void allignwarpelevators(void) void moveclouds(void) { - if (totalclock > cloudtotalclock || totalclock < (cloudtotalclock - 7)) + if (gameclock > cloudtotalclock || gameclock < (cloudtotalclock - 7)) { - cloudtotalclock = totalclock + 6; + cloudtotalclock = gameclock + 6; // cloudx/y were an array, but all entries were always having the same value so a single pair is enough. cloudx += (sintable[(ps[screenpeek].getang() + 512) & 2047] >> 9); diff --git a/source/games/duke/src/sounds.cpp b/source/games/duke/src/sounds.cpp index 1e2c71bae..66e02cad2 100644 --- a/source/games/duke/src/sounds.cpp +++ b/source/games/duke/src/sounds.cpp @@ -353,7 +353,7 @@ void S_Update(void) } listener.ListenerObject = ud.camerasprite == -1 ? nullptr : &sprite[ud.camerasprite]; soundEngine->SetListener(listener); - soundEngine->UpdateSounds((int)totalclock); + soundEngine->UpdateSounds(gameclock); }