diff --git a/src/d_main.cpp b/src/d_main.cpp index f94d158b5..75605b2e7 100644 --- a/src/d_main.cpp +++ b/src/d_main.cpp @@ -941,7 +941,7 @@ void D_Display () else { // wipe update - unsigned int wipestart, nowtime, diff; + uint64_t wipestart, nowtime, diff; bool done; GSnd->SetSfxPaused(true, 1); diff --git a/src/d_net.cpp b/src/d_net.cpp index ba1262025..e8711bda5 100644 --- a/src/d_net.cpp +++ b/src/d_net.cpp @@ -113,9 +113,9 @@ bool remoteresend[MAXNETNODES]; // set when local needs tics int resendto[MAXNETNODES]; // set when remote needs tics int resendcount[MAXNETNODES]; -unsigned int lastrecvtime[MAXPLAYERS]; // [RH] Used for pings -unsigned int currrecvtime[MAXPLAYERS]; -unsigned int lastglobalrecvtime; // Identify the last time a packet was received. +uint64_t lastrecvtime[MAXPLAYERS]; // [RH] Used for pings +uint64_t currrecvtime[MAXPLAYERS]; +uint64_t lastglobalrecvtime; // Identify the last time a packet was received. bool hadlate; int netdelay[MAXNETNODES][BACKUPTICS]; // Used for storing network delay times. int lastaverage; diff --git a/src/dobject.cpp b/src/dobject.cpp index 9046d7337..df8bb1acb 100644 --- a/src/dobject.cpp +++ b/src/dobject.cpp @@ -615,7 +615,7 @@ void DObject::CheckIfSerialized () const DEFINE_ACTION_FUNCTION(DObject, MSTime) { - ACTION_RETURN_INT(I_msTime()); + ACTION_RETURN_INT((uint32_t)I_msTime()); } void *DObject::ScriptVar(FName field, PType *type) diff --git a/src/g_level.h b/src/g_level.h index 2df5af946..e7305e9da 100644 --- a/src/g_level.h +++ b/src/g_level.h @@ -362,7 +362,7 @@ struct level_info_t int outsidefogdensity; int skyfog; float pixelstretch; - + // Redirection: If any player is carrying the specified item, then // you go to the RedirectMap instead of this one. FName RedirectType; diff --git a/src/g_levellocals.h b/src/g_levellocals.h index b7f4f9aa3..505d797b6 100644 --- a/src/g_levellocals.h +++ b/src/g_levellocals.h @@ -67,6 +67,8 @@ struct FLevelLocals FString F1Pic; EMapType maptype; + uint64_t ShaderStartTime = 0; // tell the shader system when we started the level (forces a timer restart) + TArray vertexes; TArray sectors; TArray linebuffer; // contains the line lists for the sectors. diff --git a/src/gl/models/gl_models.cpp b/src/gl/models/gl_models.cpp index 541a4c36c..963518a99 100644 --- a/src/gl/models/gl_models.cpp +++ b/src/gl/models/gl_models.cpp @@ -53,9 +53,9 @@ #include "gl/renderer/gl_renderstate.h" #include "gl/shaders/gl_shader.h" -static inline float GetTimeFloat() +static inline double GetTimeFloat() { - return (float)screen->FrameTime * (float)TICRATE / 1000.0f; + return (double)screen->FrameTime * (double)TICRATE / 1000.; } CVAR(Bool, gl_interpolate_model_frames, true, CVAR_ARCHIVE) @@ -890,7 +890,7 @@ void gl_RenderFrameModels( const FSpriteModelFrame *smf, // [BB] In case the tic counter is frozen we have to leave ticFraction at zero. if ( ConsoleState == c_up && menuactive != MENU_On && !(level.flags2 & LEVEL2_FROZEN) ) { - float time = GetTimeFloat(); + double time = GetTimeFloat(); ticFraction = (time - static_cast(time)); } inter = static_cast(curState->Tics - curTics - ticFraction)/static_cast(curState->Tics); @@ -999,8 +999,8 @@ void gl_RenderModel(GLSprite * spr) if( smf->flags & MDL_ROTATING ) { - const float time = smf->rotationSpeed*GetTimeFloat()/200.f; - rotateOffset = float((time - xs_FloorToInt(time)) *360.f ); + const double time = smf->rotationSpeed*GetTimeFloat()/200.; + rotateOffset = double((time - xs_FloorToInt(time)) *360. ); } // Added MDL_USEACTORPITCH and MDL_USEACTORROLL flags processing. diff --git a/src/gl/renderer/gl_renderstate.cpp b/src/gl/renderer/gl_renderstate.cpp index 1427e2350..c37ccbb99 100644 --- a/src/gl/renderer/gl_renderstate.cpp +++ b/src/gl/renderer/gl_renderstate.cpp @@ -37,6 +37,7 @@ #include "gl/renderer/gl_colormap.h" #include "gl/dynlights//gl_lightbuffer.h" #include "gl/renderer/gl_renderbuffers.h" +#include "g_levellocals.h" void gl_SetTextureMode(int type); @@ -118,6 +119,12 @@ void FRenderState::Reset() bool FRenderState::ApplyShader() { + static uint64_t firstFrame = 0; + // if firstFrame is not yet initialized, initialize it to current time + // if we're going to overflow a float (after ~4.6 hours, or 24 bits), re-init to regain precision + if ((firstFrame == 0) || (screen->FrameTime - firstFrame >= 1<<24) || level.ShaderStartTime >= firstFrame) + firstFrame = screen->FrameTime; + static const float nulvec[] = { 0.f, 0.f, 0.f, 0.f }; if (mSpecialEffect > EFF_NONE) { @@ -161,7 +168,7 @@ bool FRenderState::ApplyShader() activeShader->muInterpolationFactor.Set(mInterpolationFactor); activeShader->muClipHeight.Set(mClipHeight); activeShader->muClipHeightDirection.Set(mClipHeightDirection); - activeShader->muTimer.Set(screen->FrameTime * mShaderTimer / 1000.f); + activeShader->muTimer.Set((double)(screen->FrameTime - firstFrame) * mShaderTimer / 1000.f); activeShader->muAlphaThreshold.Set(mAlphaThreshold); activeShader->muLightIndex.Set(mLightIndex); // will always be -1 for now activeShader->muClipSplit.Set(mClipSplit); diff --git a/src/gl/scene/gl_scene.cpp b/src/gl/scene/gl_scene.cpp index 92d378521..329ac6484 100644 --- a/src/gl/scene/gl_scene.cpp +++ b/src/gl/scene/gl_scene.cpp @@ -800,8 +800,8 @@ sector_t * GLSceneDrawer::RenderViewpoint (AActor * camera, GL_IRECT * bounds, f GLRenderer->mAngles.Roll.Degrees = r_viewpoint.Angles.Roll.Degrees; // Scroll the sky - GLRenderer->mSky1Pos = (float)fmod(screen->FrameTime * level.skyspeed1, 1024.f) * 90.f/256.f; - GLRenderer->mSky2Pos = (float)fmod(screen->FrameTime * level.skyspeed2, 1024.f) * 90.f/256.f; + GLRenderer->mSky1Pos = (double)fmod(screen->FrameTime * level.skyspeed1, 1024.f) * 90./256.; + GLRenderer->mSky2Pos = (double)fmod(screen->FrameTime * level.skyspeed2, 1024.f) * 90./256.; diff --git a/src/gl/utility/gl_clock.cpp b/src/gl/utility/gl_clock.cpp index 8ad3b1cc8..df96fb6b8 100644 --- a/src/gl/utility/gl_clock.cpp +++ b/src/gl/utility/gl_clock.cpp @@ -187,8 +187,8 @@ static void AppendLightStats(FString &out) ADD_STAT(rendertimes) { static FString buff; - static int lasttime=0; - int t=I_msTime(); + static int64_t lasttime=0; + int64_t t=I_msTime(); if (t-lasttime>1000) { buff.Truncate(0); @@ -217,7 +217,7 @@ void AppendMissingTextureStats(FString &out); static int printstats; static bool switchfps; -static unsigned int waitstart; +static uint64_t waitstart; EXTERN_CVAR(Bool, vid_fps) void CheckBench() diff --git a/src/i_time.cpp b/src/i_time.cpp index 050bb1ebc..4be0a8b82 100644 --- a/src/i_time.cpp +++ b/src/i_time.cpp @@ -60,9 +60,9 @@ static uint64_t MSToNS(unsigned int ms) return static_cast(ms) * 1'000'000; } -static uint32_t NSToMS(uint64_t ns) +static uint64_t NSToMS(uint64_t ns) { - return static_cast(ns / 1'000'000); + return static_cast(ns / 1'000'000); } static int NSToTic(uint64_t ns) @@ -125,7 +125,7 @@ uint64_t I_nsTime() return GetClockTimeNS(); } -unsigned int I_msTime() +uint64_t I_msTime() { return NSToMS(I_nsTime()); } diff --git a/src/i_time.h b/src/i_time.h index 160596969..33907ded2 100644 --- a/src/i_time.h +++ b/src/i_time.h @@ -20,7 +20,7 @@ int I_WaitForTic(int); void I_FreezeTime(bool frozen); // [RH] Returns millisecond-accurate time -unsigned int I_msTime(); +uint64_t I_msTime(); // Nanosecond-accurate time uint64_t I_nsTime(); diff --git a/src/p_glnodes.cpp b/src/p_glnodes.cpp index bac573565..e1510145e 100644 --- a/src/p_glnodes.cpp +++ b/src/p_glnodes.cpp @@ -955,7 +955,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) if (!loaded) { // none found - we have to build new ones! - unsigned int startTime, endTime; + uint64_t startTime, endTime; startTime = I_msTime (); TArray polyspots, anchors; @@ -973,7 +973,7 @@ bool P_CheckNodes(MapData * map, bool rebuilt, int buildtime) builder.Extract (level); endTime = I_msTime (); DPrintf (DMSG_NOTIFY, "BSP generation took %.3f sec (%u segs)\n", (endTime - startTime) * 0.001, level.segs.Size()); - buildtime = endTime - startTime; + buildtime = (int32_t)(endTime - startTime); } } diff --git a/src/p_setup.cpp b/src/p_setup.cpp index 02522d3df..dfa7ecb26 100644 --- a/src/p_setup.cpp +++ b/src/p_setup.cpp @@ -3627,6 +3627,8 @@ void P_SetupLevel (const char *lumpname, int position) bool buildmap; const int *oldvertextable = NULL; + level.ShaderStartTime = I_msTime(); // indicate to the shader system that the level just started + // This is motivated as follows: bool RequireGLNodes = Renderer->RequireGLNodes() || am_textured; @@ -3931,7 +3933,7 @@ void P_SetupLevel (const char *lumpname, int position) } else reloop = true; - unsigned int startTime=0, endTime=0; + uint64_t startTime=0, endTime=0; bool BuildGLNodes; if (ForceNodeBuild) @@ -3988,7 +3990,7 @@ void P_SetupLevel (const char *lumpname, int position) // If the original nodes being loaded are not GL nodes they will be kept around for // use in P_PointInSubsector to avoid problems with maps that depend on the specific // nodes they were built with (P:AR E1M3 is a good example for a map where this is the case.) - reloop |= P_CheckNodes(map, BuildGLNodes, endTime - startTime); + reloop |= P_CheckNodes(map, BuildGLNodes, (uint32_t)(endTime - startTime)); hasglnodes = true; } else diff --git a/src/r_sky.cpp b/src/r_sky.cpp index eb31e2064..cc84f9fbb 100644 --- a/src/r_sky.cpp +++ b/src/r_sky.cpp @@ -165,7 +165,7 @@ void R_InitSkyMap () // //========================================================================== -void R_UpdateSky (uint32_t mstime) +void R_UpdateSky (uint64_t mstime) { // Scroll the sky double ms = (double)mstime * FRACUNIT; diff --git a/src/r_sky.h b/src/r_sky.h index 39ac77f27..e186ad3ae 100644 --- a/src/r_sky.h +++ b/src/r_sky.h @@ -44,6 +44,6 @@ extern int freelookviewheight; // Called whenever the sky changes. void R_InitSkyMap (); -void R_UpdateSky (uint32_t mstime); +void R_UpdateSky (uint64_t mstime); #endif //__R_SKY_H__ diff --git a/src/textures/animations.cpp b/src/textures/animations.cpp index 7b2aab98b..a9fa4c1bf 100644 --- a/src/textures/animations.cpp +++ b/src/textures/animations.cpp @@ -876,7 +876,7 @@ FDoorAnimation *FTextureManager::FindAnimatedDoor (FTextureID picnum) // //========================================================================== -void FAnimDef::SetSwitchTime (uint32_t mstime) +void FAnimDef::SetSwitchTime (uint64_t mstime) { int speedframe = bDiscrete ? CurFrame : 0; @@ -917,7 +917,7 @@ void FTextureManager::SetTranslation (FTextureID fromtexnum, FTextureID totexnum // //========================================================================== -void FTextureManager::UpdateAnimations (uint32_t mstime) +void FTextureManager::UpdateAnimations (uint64_t mstime) { for (unsigned int j = 0; j < mAnimations.Size(); ++j) { diff --git a/src/textures/textures.h b/src/textures/textures.h index 96bd8d3ca..539d38c43 100644 --- a/src/textures/textures.h +++ b/src/textures/textures.h @@ -90,7 +90,7 @@ struct FAnimDef uint16_t CurFrame; uint8_t AnimType; bool bDiscrete; // taken out of AnimType to have better control - uint32_t SwitchTime; // Time to advance to next frame + uint64_t SwitchTime; // Time to advance to next frame struct FAnimFrame { uint32_t SpeedMin; // Speeds are in ms, not tics @@ -106,7 +106,7 @@ struct FAnimDef ANIM_Random }; - void SetSwitchTime (uint32_t mstime); + void SetSwitchTime (uint64_t mstime); }; struct FSwitchDef @@ -505,7 +505,7 @@ public: int NumTextures () const { return (int)Textures.Size(); } - void UpdateAnimations (uint32_t mstime); + void UpdateAnimations (uint64_t mstime); int GuesstimateNumTextures (); FSwitchDef *FindSwitch (FTextureID texture); @@ -604,8 +604,8 @@ public: void SetSpeed(float fac) { Speed = fac; } FTexture *GetRedirect(bool wantwarped); - uint32_t GenTime; - uint32_t GenTimeBgra; + uint64_t GenTime; + uint64_t GenTimeBgra; float Speed; int WidthOffsetMultiplier, HeightOffsetMultiplier; // [mxd] protected: @@ -613,7 +613,7 @@ protected: uint8_t *Pixels; Span **Spans; - virtual void MakeTexture (uint32_t time); + virtual void MakeTexture (uint64_t time); int NextPo2 (int v); // [mxd] void SetupMultipliers (int width, int height); // [mxd] }; diff --git a/src/textures/warpbuffer.h b/src/textures/warpbuffer.h index 668c40aeb..62b0db13d 100644 --- a/src/textures/warpbuffer.h +++ b/src/textures/warpbuffer.h @@ -35,7 +35,7 @@ #include "textures/textures.h" template -void WarpBuffer(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, unsigned time, float Speed, int warptype) +void WarpBuffer(TYPE *Pixels, const TYPE *source, int width, int height, int xmul, int ymul, uint64_t time, float Speed, int warptype) { int ymask = height - 1; int x, y; diff --git a/src/textures/warptexture.cpp b/src/textures/warptexture.cpp index 43a215a2b..2e073c186 100644 --- a/src/textures/warptexture.cpp +++ b/src/textures/warptexture.cpp @@ -86,7 +86,7 @@ bool FWarpTexture::CheckModified () const uint8_t *FWarpTexture::GetPixels () { - uint32_t time = screen->FrameTime; + uint64_t time = screen->FrameTime; if (Pixels == NULL || time != GenTime) { @@ -97,7 +97,7 @@ const uint8_t *FWarpTexture::GetPixels () const uint32_t *FWarpTexture::GetPixelsBgra() { - uint32_t time = screen->FrameTime; + uint64_t time = screen->FrameTime; if (Pixels == NULL || time != GenTime) MakeTexture(time); @@ -119,7 +119,7 @@ const uint32_t *FWarpTexture::GetPixelsBgra() const uint8_t *FWarpTexture::GetColumn (unsigned int column, const Span **spans_out) { - uint32_t time =screen->FrameTime; + uint64_t time =screen->FrameTime; if (Pixels == NULL || time != GenTime) { @@ -148,7 +148,7 @@ const uint8_t *FWarpTexture::GetColumn (unsigned int column, const Span **spans_ } -void FWarpTexture::MakeTexture(uint32_t time) +void FWarpTexture::MakeTexture(uint64_t time) { const uint8_t *otherpix = SourcePic->GetPixels(); diff --git a/src/v_video.cpp b/src/v_video.cpp index 5f774a648..01ae8b428 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -870,8 +870,8 @@ void DFrameBuffer::DrawRateStuff () // Draws frame time and cumulative fps if (vid_fps) { - uint32_t ms = screen->FrameTime; - uint32_t howlong = ms - LastMS; + uint64_t ms = screen->FrameTime; + uint64_t howlong = ms - LastMS; if ((signed)howlong >= 0) { char fpsbuff[40]; @@ -888,7 +888,7 @@ void DFrameBuffer::DrawRateStuff () DTA_VirtualHeight, screen->GetHeight() / textScale, DTA_KeepRatio, true, TAG_DONE); - uint32_t thisSec = ms/1000; + uint32_t thisSec = (uint32_t)(ms/1000); if (LastSec < thisSec) { LastCount = FrameCount / (thisSec - LastSec); @@ -903,8 +903,8 @@ void DFrameBuffer::DrawRateStuff () // draws little dots on the bottom of the screen if (ticker) { - int i = I_GetTime(); - int tics = i - LastTic; + int64_t i = I_GetTime(); + int64_t tics = i - LastTic; uint8_t *buffer = GetBuffer(); LastTic = i; @@ -931,6 +931,7 @@ void DFrameBuffer::DrawRateStuff () } else { + int i; for (i = 0; i < tics*2; i += 2) Clear(i, Height-1, i+1, Height, 255, 0); for ( ; i < 20*2; i += 2) Clear(i, Height-1, i+1, Height, 0, 0); } diff --git a/src/v_video.h b/src/v_video.h index 5934a3706..1cbf565af 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -442,7 +442,7 @@ public: virtual void ScaleCoordsFromWindow(int16_t &x, int16_t &y) {} - uint32_t GetLastFPS() const { return LastCount; } + uint64_t GetLastFPS() const { return LastCount; } #ifdef _WIN32 virtual void PaletteChanged () = 0; @@ -453,7 +453,7 @@ public: // The original size of the framebuffer as selected in the video menu. int VideoWidth = 0; int VideoHeight = 0; - uint32_t FrameTime = 0; + uint64_t FrameTime = 0; protected: void DrawRateStuff (); @@ -463,7 +463,7 @@ protected: DFrameBuffer () {} private: - uint32_t LastMS, LastSec, FrameCount, LastCount, LastTic; + uint64_t LastMS, LastSec, FrameCount, LastCount, LastTic; bool isIn2D = false; };