MCPcopy Create free account
hub / github.com/ZDoom/Raze / I_WaitForTic

Function I_WaitForTic

source/common/utility/i_time.cpp:120–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

118}
119
120int I_WaitForTic(int prevtic, double const ticrate)
121{
122 // Waits until the current tic is greater than prevtic. Time must not be frozen.
123
124 int time;
125 while ((time = I_GetTime(ticrate)) <= prevtic)
126 {
127 // Windows-specific note:
128 // The minimum amount of time a thread can sleep is controlled by timeBeginPeriod.
129 // We set this to 1 ms in DoMain.
130
131 const uint64_t next = FirstFrameStartTime + TicToNS(prevtic + 1, ticrate);
132 const uint64_t now = I_nsTime();
133
134 if (next > now)
135 {
136 const uint64_t sleepTime = NSToMS(next - now);
137
138 if (sleepTime > 2)
139 {
140 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime - 2));
141 }
142 }
143
144 I_SetFrameTime();
145 }
146
147 return time;
148}
149
150uint64_t I_nsTime()
151{

Callers 1

TryRunTicsFunction · 0.85

Calls 5

I_GetTimeFunction · 0.85
TicToNSFunction · 0.85
I_nsTimeFunction · 0.85
NSToMSFunction · 0.85
I_SetFrameTimeFunction · 0.85

Tested by

no test coverage detected