Advertisement
Guest User

High-Resoluting-Timer-patch-for-c770f5a41612.diff

a guest
Apr 25th, 2022
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.59 KB | None | 0 0
  1. diff -r c770f5a41612 src/gl/textures/gl_material.cpp
  2. --- a/src/gl/textures/gl_material.cpp   Sun Mar 27 21:17:25 2022 +0200
  3. +++ b/src/gl/textures/gl_material.cpp   Mon Apr 25 21:09:35 2022 +0300
  4. @@ -203,7 +203,7 @@
  5.     static_cast<FWarpTexture*>(tex)->GenTime = r_FrameTime;
  6.  
  7.     static DWORD linebuffer[256];   // anything larger will bring down performance so it is excluded above.
  8. -   DWORD timebase = DWORD(r_FrameTime*Speed*23/28);
  9. +   QWORD timebase = QWORD(r_FrameTime*Speed*23/28);
  10.     int xsize = Width;
  11.     int ysize = Height;
  12.     int xmask = xsize - 1;
  13. @@ -225,7 +225,7 @@
  14.                 *dest = *(source+(yf<<ds_xbits));
  15.             }
  16.         }
  17. -       timebase = DWORD(r_FrameTime*Speed*32/28);
  18. +       timebase = QWORD(r_FrameTime*Speed*32/28);
  19.         int y;
  20.         for (y = ysize-1; y >= 0; y--)
  21.         {
  22. @@ -244,7 +244,7 @@
  23.         int ybits;
  24.         for(ybits=-1,i=ysize; i; i>>=1, ybits++);
  25.  
  26. -       DWORD timebase = (r_FrameTime * Speed * 40 / 28);
  27. +       QWORD timebase = (r_FrameTime * Speed * 40 / 28);
  28.         for (x = xsize-1; x >= 0; x--)
  29.         {
  30.             for (int y = ysize-1; y >= 0; y--)
  31. diff -r c770f5a41612 src/r_utility.cpp
  32. --- a/src/r_utility.cpp Sun Mar 27 21:17:25 2022 +0200
  33. +++ b/src/r_utility.cpp Mon Apr 25 21:09:35 2022 +0300
  34. @@ -130,7 +130,7 @@
  35.  AActor         *camera;    // [RH] camera to draw from. doesn't have to be a player
  36.  
  37.  fixed_t            r_TicFrac;          // [RH] Fractional tic to render
  38. -DWORD          r_FrameTime;        // [RH] Time this frame started drawing (in ms)
  39. +QWORD          r_FrameTime;        // [RH] Time this frame started drawing (in nsG)
  40.  bool           r_NoInterpolate;
  41.  bool           r_showviewer;
  42.  
  43. diff -r c770f5a41612 src/r_utility.h
  44. --- a/src/r_utility.h   Sun Mar 27 21:17:25 2022 +0200
  45. +++ b/src/r_utility.h   Mon Apr 25 21:09:35 2022 +0300
  46. @@ -34,7 +34,7 @@
  47.  extern int             WidescreenRatio;
  48.  
  49.  extern fixed_t         r_TicFrac;
  50. -extern DWORD           r_FrameTime;
  51. +extern QWORD           r_FrameTime;
  52.  extern int             extralight;
  53.  extern unsigned int        R_OldBlend;
  54.  
  55. diff -r c770f5a41612 src/sdl/i_system.cpp
  56. --- a/src/sdl/i_system.cpp  Sun Mar 27 21:17:25 2022 +0200
  57. +++ b/src/sdl/i_system.cpp  Mon Apr 25 21:09:35 2022 +0300
  58. @@ -82,6 +82,8 @@
  59.  #include "cl_main.h"
  60.  #include "v_text.h"
  61.  
  62. +#include <chrono>
  63. +
  64.  #ifdef USE_XCURSOR
  65.  // Xlib has its own GC, so don't let it interfere.
  66.  #define GC XGC
  67. @@ -140,66 +142,80 @@
  68.  {
  69.  }
  70.  
  71. -
  72. -static DWORD TicStart;
  73. -static DWORD BaseTime;
  74. +static QWORD TicStart;
  75. +static QWORD BaseTime;
  76.  static int TicFrozen;
  77.  
  78.  // Signal based timer.
  79.  static Semaphore timerWait;
  80.  static int tics;
  81. -static DWORD sig_start;
  82. +static QWORD sig_start;
  83.  
  84.  void I_SelectTimer();
  85.  
  86. -// [RH] Returns time in milliseconds
  87. -unsigned int I_MSTime (void)
  88. +static QWORD GetClockTimeNS()
  89. +{
  90. +   using namespace std::chrono;
  91. +   return (QWORD)(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
  92. +}
  93. +
  94. +
  95. +static QWORD NSToMS(QWORD ns)
  96.  {
  97. -   unsigned int time = SDL_GetTicks ();
  98. -   return time - BaseTime;
  99. +   return static_cast<QWORD>(ns / 1'000'000);
  100. +}
  101. +
  102. +
  103. +
  104. +// [RH] Returns time in milliseconds
  105. +unsigned long I_MSTime(void)
  106. +{
  107. +   QWORD time = GetClockTimeNS();
  108. +   return NSToMS(time - BaseTime);
  109.  }
  110.  
  111.  // Exactly the same thing, but based does no modification to the time.
  112. -unsigned int I_FPSTime()
  113. +unsigned long I_FPSTime()
  114.  {
  115. -   return SDL_GetTicks();
  116. +   return NSToMS(GetClockTimeNS());
  117.  }
  118.  
  119.  //
  120.  // I_GetTime
  121.  // returns time in 1/35th second tics
  122.  //
  123. -int I_GetTimeSelect (bool saveMS)
  124. +int I_GetTimeSelect (bool saveNS)
  125.  {
  126.     I_SelectTimer();
  127. -   return I_GetTime (saveMS);
  128. +   return I_GetTime (saveNS);
  129.  }
  130.  
  131. -int I_GetTimePolled (bool saveMS)
  132. +int I_GetTimePolled (bool saveNS)
  133.  {
  134.     if (TicFrozen != 0)
  135.     {
  136.         return TicFrozen;
  137.     }
  138.  
  139. -   DWORD tm = SDL_GetTicks();
  140. +   QWORD tm = GetClockTimeNS();
  141.  
  142. -   if (saveMS)
  143. +   if (saveNS)
  144.     {
  145.         // [Leo] Replaced the expressions for TicStart and TicNext below.
  146.         /*
  147.         TicStart = tm;
  148.         */
  149. -       DWORD CurrentTic = ((tm - BaseTime) * TICRATE) / 1000;
  150. -       TicStart = (CurrentTic * 1000 / TICRATE) + BaseTime;
  151. +       QWORD CurrentTic = ((tm - BaseTime) * TICRATE) / 1'000'000'000;
  152. +       TicStart = (CurrentTic * 1'000'000'000 / TICRATE) + BaseTime;
  153.     }
  154. -   return Scale(tm - BaseTime, TICRATE, 1000);
  155. +
  156. +   return ((tm - BaseTime) * TICRATE) / 1'000'000'000;
  157.  }
  158.  
  159. -int I_GetTimeSignaled (bool saveMS)
  160. +int I_GetTimeSignaled (bool saveNS)
  161.  {
  162. -   if (saveMS)
  163. -   {
  164. +   if (saveNS)
  165. +   {        
  166.         TicStart = sig_start;
  167.     }
  168.     return tics;
  169. @@ -247,7 +263,7 @@
  170.         int froze = TicFrozen;
  171.         TicFrozen = 0;
  172.         int now = I_GetTimePolled(false);
  173. -       BaseTime += (now - froze) * 1000 / TICRATE;
  174. +       BaseTime += (now - froze) * 1'000'000'000 / TICRATE;
  175.     }
  176.  }
  177.  
  178. @@ -270,7 +286,7 @@
  179.  {
  180.     if(!TicFrozen)
  181.         tics++;
  182. -   sig_start = SDL_GetTicks();
  183. +   sig_start = GetClockTimeNS();
  184.     SEMAPHORE_SIGNAL(timerWait)
  185.  }
  186.  
  187. @@ -310,17 +326,17 @@
  188.  }
  189.  
  190.  // Returns the fractional amount of a tic passed since the most recent tic
  191. -fixed_t I_GetTimeFrac (uint32 *ms)
  192. +fixed_t I_GetTimeFrac (uint64_t *ns)
  193.  {
  194. -   DWORD now = SDL_GetTicks ();
  195. -   if (ms) *ms = TicStart + (1000 / TICRATE);
  196. +   QWORD now = GetClockTimeNS();
  197. +   if (ns) *ns = TicStart + (1'000'000'000 / TICRATE);
  198.     if (TicStart == 0)
  199.     {
  200.         return FRACUNIT;
  201.     }
  202.     else
  203.     {
  204. -       fixed_t frac = clamp<fixed_t> ((now - TicStart)*FRACUNIT*TICRATE/1000, 0, FRACUNIT);
  205. +       fixed_t frac = clamp<fixed_t> ((now - TicStart)*FRACUNIT*TICRATE/1'000'000'000, 0, FRACUNIT);
  206.         return frac;
  207.     }
  208.  }
  209. @@ -350,6 +366,8 @@
  210.     I_GetTime = I_GetTimeSelect;
  211.     I_WaitForTic = I_WaitForTicSelect;
  212.     I_FreezeTime = I_FreezeTimeSelect;
  213. +
  214. +   BaseTime = GetClockTimeNS();
  215.     atterm (I_ShutdownSound);
  216.      I_InitSound ();
  217.  }
  218. diff -r c770f5a41612 src/sdl/i_system.h
  219. --- a/src/sdl/i_system.h    Sun Mar 27 21:17:25 2022 +0200
  220. +++ b/src/sdl/i_system.h    Mon Apr 25 21:09:35 2022 +0300
  221. @@ -62,7 +62,7 @@
  222.  // tic will never arrive (unless it's the current one).
  223.  extern void (*I_FreezeTime) (bool frozen);
  224.  
  225. -fixed_t I_GetTimeFrac (uint32 *ms);
  226. +fixed_t I_GetTimeFrac (uint64_t *ns);
  227.  
  228.  // Return a seed value for the RNG.
  229.  unsigned int I_MakeRNGSeed();
  230. @@ -124,8 +124,8 @@
  231.  bool I_WriteIniFailed ();
  232.  
  233.  // [RH] Returns millisecond-accurate time
  234. -unsigned int I_MSTime (void);
  235. -unsigned int I_FPSTime();
  236. +unsigned long I_MSTime (void);
  237. +unsigned long I_FPSTime();
  238.  
  239.  class FTexture;
  240.  bool I_SetCursor(FTexture *);
  241. diff -r c770f5a41612 src/textures/textures.h
  242. --- a/src/textures/textures.h   Sun Mar 27 21:17:25 2022 +0200
  243. +++ b/src/textures/textures.h   Mon Apr 25 21:09:35 2022 +0300
  244. @@ -570,7 +570,7 @@
  245.     void SetSpeed(float fac) { Speed = fac; }
  246.     FTexture *GetRedirect(bool wantwarped);
  247.  
  248. -   DWORD GenTime;
  249. +   QWORD GenTime;
  250.  protected:
  251.     FTexture *SourcePic;
  252.     BYTE *Pixels;
  253.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement