| 43 | } |
| 44 | |
| 45 | void VideoDriver::GameThread() |
| 46 | { |
| 47 | while (!_exit_game) { |
| 48 | this->GameLoop(); |
| 49 | |
| 50 | auto now = std::chrono::steady_clock::now(); |
| 51 | if (this->next_game_tick > now) { |
| 52 | std::this_thread::sleep_for(this->next_game_tick - now); |
| 53 | } else { |
| 54 | /* Ensure we yield this thread if drawings wants to take a lock on |
| 55 | * the game state. This is mainly because most OSes have an |
| 56 | * optimization that if you unlock/lock a mutex in the same thread |
| 57 | * quickly, it will never context switch even if there is another |
| 58 | * thread waiting to take the lock on the same mutex. */ |
| 59 | std::lock_guard<std::mutex> lock(this->game_thread_wait_mutex); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Pause the game-loop for a bit, releasing the game-state lock. This allows, |
no test coverage detected