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

Method Tick

src/video/video_driver.cpp:104–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102}
103
104void VideoDriver::Tick()
105{
106 if (!this->is_game_threaded && std::chrono::steady_clock::now() >= this->next_game_tick) {
107 this->GameLoop();
108
109 /* For things like dedicated server, don't run a separate draw-tick. */
110 if (!this->HasGUI()) {
111 ::InputLoop();
112 ::UpdateWindows();
113 this->next_draw_tick = this->next_game_tick;
114 }
115 }
116
117 auto now = std::chrono::steady_clock::now();
118 if (this->HasGUI() && now >= this->next_draw_tick) {
119 this->next_draw_tick += this->GetDrawInterval();
120 /* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
121 if (this->next_draw_tick < now - ALLOWED_DRIFT * this->GetDrawInterval()) this->next_draw_tick = now;
122
123 /* Locking video buffer can block (especially with vsync enabled), do it before taking game state lock. */
124 this->LockVideoBuffer();
125
126 {
127 /* Tell the game-thread to stop so we can have a go. */
128 std::lock_guard<std::mutex> lock_wait(this->game_thread_wait_mutex);
129 std::lock_guard<std::mutex> lock_state(this->game_state_mutex);
130
131 /* Keep the interactive randomizer a bit more random by requesting
132 * new values when-ever we can. */
133 InteractiveRandom();
134
135 this->DrainCommandQueue();
136
137 while (this->PollEvent()) {}
138 this->InputLoop();
139
140 /* Check if the fast-forward button is still pressed. */
141 if (fast_forward_key_pressed && !_networking && _game_mode != GM_MENU) {
142 ChangeGameSpeed(true);
143 this->fast_forward_via_key = true;
144 } else if (this->fast_forward_via_key) {
145 ChangeGameSpeed(false);
146 this->fast_forward_via_key = false;
147 }
148
149 ::InputLoop();
150
151 /* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
152 if (_game_mode == GM_BOOTSTRAP || _switch_mode == SM_NONE || HasModalProgress()) {
153 ::UpdateWindows();
154 }
155
156 this->PopulateSystemSprites();
157 }
158
159 this->CheckPaletteAnim();
160 this->Paint();
161

Callers 4

MainLoopMethod · 0.45
MainLoopMethod · 0.45
LoopOnceMethod · 0.45
MainLoopMethod · 0.45

Calls 15

GameLoopMethod · 0.95
HasGUIMethod · 0.95
GetDrawIntervalMethod · 0.95
LockVideoBufferMethod · 0.95
DrainCommandQueueMethod · 0.95
PollEventMethod · 0.95
InputLoopMethod · 0.95
PopulateSystemSpritesMethod · 0.95
CheckPaletteAnimMethod · 0.95
PaintMethod · 0.95
UnlockVideoBufferMethod · 0.95
nowClass · 0.85

Tested by

no test coverage detected