Advertisement
Guest User

High-Resoluting-Timer-patch-for-ZA_3.1.diff

a guest
Apr 25th, 2022
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 6.87 KB | None | 0 0
  1. diff -r 4178904d7698 src/gl/textures/gl_material.cpp
  2. --- a/src/gl/textures/gl_material.cpp   Sat Dec 11 16:35:55 2021 -0500
  3. +++ b/src/gl/textures/gl_material.cpp   Mon Apr 25 21:04:13 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 4178904d7698 src/r_utility.cpp
  32. --- a/src/r_utility.cpp Sat Dec 11 16:35:55 2021 -0500
  33. +++ b/src/r_utility.cpp Mon Apr 25 21:04:13 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 ns)
  40.  bool           r_NoInterpolate;
  41.  bool           r_showviewer;
  42.  
  43. diff -r 4178904d7698 src/r_utility.h
  44. --- a/src/r_utility.h   Sat Dec 11 16:35:55 2021 -0500
  45. +++ b/src/r_utility.h   Mon Apr 25 21:04:13 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 4178904d7698 src/sdl/i_system.cpp
  56. --- a/src/sdl/i_system.cpp  Sat Dec 11 16:35:55 2021 -0500
  57. +++ b/src/sdl/i_system.cpp  Mon Apr 25 21:04:13 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,71 +142,81 @@
  68.  {
  69.  }
  70.  
  71. -
  72. -static DWORD TicStart;
  73. -static DWORD TicNext;
  74. -static DWORD BaseTime;
  75. +static QWORD TicStart;
  76. +static QWORD BaseTime;
  77.  static int TicFrozen;
  78.  
  79.  // Signal based timer.
  80.  static Semaphore timerWait;
  81.  static int tics;
  82. -static DWORD sig_start, sig_next;
  83. +static QWORD sig_start;
  84.  
  85.  void I_SelectTimer();
  86.  
  87. -// [RH] Returns time in milliseconds
  88. -unsigned int I_MSTime (void)
  89. +static QWORD GetClockTimeNS()
  90. +{
  91. +   using namespace std::chrono;
  92. +   return (QWORD)(duration_cast<nanoseconds>(steady_clock::now().time_since_epoch()).count());
  93. +}
  94. +
  95. +
  96. +static QWORD NSToMS(QWORD ns)
  97.  {
  98. -   unsigned int time = SDL_GetTicks ();
  99. -   return time - BaseTime;
  100. +   return static_cast<QWORD>(ns / 1'000'000);
  101. +}
  102. +
  103. +
  104. +
  105. +// [RH] Returns time in milliseconds
  106. +unsigned long I_MSTime(void)
  107. +{
  108. +   QWORD time = GetClockTimeNS();
  109. +   return NSToMS(time - BaseTime);
  110.  }
  111.  
  112.  // Exactly the same thing, but based does no modification to the time.
  113. -unsigned int I_FPSTime()
  114. +unsigned long I_FPSTime()
  115.  {
  116. -   return SDL_GetTicks();
  117. +   return NSToMS(GetClockTimeNS());
  118.  }
  119.  
  120.  //
  121.  // I_GetTime
  122.  // returns time in 1/35th second tics
  123.  //
  124. -int I_GetTimeSelect (bool saveMS)
  125. +int I_GetTimeSelect (bool saveNS)
  126.  {
  127.     I_SelectTimer();
  128. -   return I_GetTime (saveMS);
  129. +   return I_GetTime (saveNS);
  130.  }
  131.  
  132. -int I_GetTimePolled (bool saveMS)
  133. +int I_GetTimePolled (bool saveNS)
  134.  {
  135.     if (TicFrozen != 0)
  136.     {
  137.         return TicFrozen;
  138.     }
  139.  
  140. -   DWORD tm = SDL_GetTicks();
  141. +   QWORD tm = GetClockTimeNS();
  142.  
  143. -   if (saveMS)
  144. +   if (saveNS)
  145.     {
  146.         // [Leo] Replaced the expressions for TicStart and TicNext below.
  147.         /*
  148.         TicStart = tm;
  149. -       TicNext = Scale((Scale (tm, TICRATE, 1000) + 1), 1000, TICRATE);
  150.         */
  151. -       DWORD CurrentTic = ((tm - BaseTime) * TICRATE) / 1000;
  152. -       TicStart = (CurrentTic * 1000 / TICRATE) + BaseTime;
  153. -       TicNext = ((CurrentTic + 1) * 1000 / TICRATE) + BaseTime;
  154. +       QWORD CurrentTic = ((tm - BaseTime) * TICRATE) / 1'000'000'000;
  155. +       TicStart = (CurrentTic * 1'000'000'000 / TICRATE) + BaseTime;
  156.     }
  157. -   return Scale(tm - BaseTime, TICRATE, 1000);
  158. +
  159. +   return ((tm - BaseTime) * TICRATE) / 1'000'000'000;
  160.  }
  161.  
  162. -int I_GetTimeSignaled (bool saveMS)
  163. +int I_GetTimeSignaled (bool saveNS)
  164.  {
  165. -   if (saveMS)
  166. -   {
  167. +    if (saveNS)
  168. +   {
  169.         TicStart = sig_start;
  170. -       TicNext = sig_next;
  171.     }
  172.     return tics;
  173.  }
  174. @@ -251,7 +263,7 @@
  175.         int froze = TicFrozen;
  176.         TicFrozen = 0;
  177.         int now = I_GetTimePolled(false);
  178. -       BaseTime += (now - froze) * 1000 / TICRATE;
  179. +       BaseTime += (now - froze) * 1'000'000'000 / TICRATE;
  180.     }
  181.  }
  182.  
  183. @@ -274,8 +286,7 @@
  184.  {
  185.     if(!TicFrozen)
  186.         tics++;
  187. -   sig_start = SDL_GetTicks();
  188. -   sig_next = Scale((Scale (sig_start, TICRATE, 1000) + 1), 1000, TICRATE);
  189. +   sig_start = GetClockTimeNS();
  190.     SEMAPHORE_SIGNAL(timerWait)
  191.  }
  192.  
  193. @@ -315,18 +326,17 @@
  194.  }
  195.  
  196.  // Returns the fractional amount of a tic passed since the most recent tic
  197. -fixed_t I_GetTimeFrac (uint32 *ms)
  198. +fixed_t I_GetTimeFrac (uint64_t *ns)
  199.  {
  200. -   DWORD now = SDL_GetTicks ();
  201. -   if (ms) *ms = TicNext;
  202. -   DWORD step = TicNext - TicStart;
  203. -   if (step == 0)
  204. +   QWORD now = GetClockTimeNS();
  205. +   if (ns) *ns = TicStart + (1'000'000'000 / TICRATE);
  206. +   if (TicStart == 0)
  207.     {
  208.         return FRACUNIT;
  209.     }
  210.     else
  211.     {
  212. -       fixed_t frac = clamp<fixed_t> ((now - TicStart)*FRACUNIT/step, 0, FRACUNIT);
  213. +       fixed_t frac = clamp<fixed_t> ((now - TicStart)*FRACUNIT*TICRATE/1'000'000'000, 0, FRACUNIT);
  214.         return frac;
  215.     }
  216.  }
  217. @@ -356,6 +366,8 @@
  218.     I_GetTime = I_GetTimeSelect;
  219.     I_WaitForTic = I_WaitForTicSelect;
  220.     I_FreezeTime = I_FreezeTimeSelect;
  221. +
  222. +   BaseTime = GetClockTimeNS();
  223.     atterm (I_ShutdownSound);
  224.      I_InitSound ();
  225.  }
  226. diff -r 4178904d7698 src/sdl/i_system.h
  227. --- a/src/sdl/i_system.h    Sat Dec 11 16:35:55 2021 -0500
  228. +++ b/src/sdl/i_system.h    Mon Apr 25 21:04:13 2022 +0300
  229. @@ -62,7 +62,7 @@
  230.  // tic will never arrive (unless it's the current one).
  231.  extern void (*I_FreezeTime) (bool frozen);
  232.  
  233. -fixed_t I_GetTimeFrac (uint32 *ms);
  234. +fixed_t I_GetTimeFrac (uint64_t *ns);
  235.  
  236.  // Return a seed value for the RNG.
  237.  unsigned int I_MakeRNGSeed();
  238. @@ -124,8 +124,8 @@
  239.  bool I_WriteIniFailed ();
  240.  
  241.  // [RH] Returns millisecond-accurate time
  242. -unsigned int I_MSTime (void);
  243. -unsigned int I_FPSTime();
  244. +unsigned long I_MSTime (void);
  245. +unsigned long I_FPSTime();
  246.  
  247.  class FTexture;
  248.  bool I_SetCursor(FTexture *);
  249. diff -r 4178904d7698 src/textures/textures.h
  250. --- a/src/textures/textures.h   Sat Dec 11 16:35:55 2021 -0500
  251. +++ b/src/textures/textures.h   Mon Apr 25 21:04:13 2022 +0300
  252. @@ -570,7 +570,7 @@
  253.     void SetSpeed(float fac) { Speed = fac; }
  254.     FTexture *GetRedirect(bool wantwarped);
  255.  
  256. -   DWORD GenTime;
  257. +   QWORD GenTime;
  258.  protected:
  259.     FTexture *SourcePic;
  260.     BYTE *Pixels;
  261.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement