MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GameThread

Method GameThread

src/video/video_driver.cpp:45–62  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

43}
44
45void 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,

Callers 1

GameThreadThunkMethod · 0.80

Calls 2

GameLoopMethod · 0.95
nowClass · 0.85

Tested by

no test coverage detected