| 118 | } |
| 119 | |
| 120 | int 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 | |
| 150 | uint64_t I_nsTime() |
| 151 | { |
no test coverage detected