File diff r24849:01243a72f255 → r24850:df6b081a960b
src/video/sdl2_v.cpp
Show inline comments
 
@@ -798,15 +798,15 @@ void VideoDriver_SDL::LoopOnce()
 
			/* Avoid next_game_tick getting behind more and more if it cannot keep up. */
 
			if (next_game_tick < cur_ticks - ALLOWED_DRIFT * this->GetGameInterval()) next_game_tick = cur_ticks;
 
		}
 

	
 
		/* The gameloop is the part that can run asynchronously. The rest
 
		 * except sleeping can't. */
 
		if (_draw_mutex != nullptr) draw_lock.unlock();
 
		this->UnlockVideoBuffer();
 
		GameLoop();
 
		if (_draw_mutex != nullptr) draw_lock.lock();
 
		this->LockVideoBuffer();
 
	}
 

	
 
	/* Prevent drawing when switching mode, as windows can be removed when they should still appear. */
 
	if (cur_ticks >= next_draw_tick && (_switch_mode == SM_NONE || HasModalProgress())) {
 
		next_draw_tick += this->GetDrawInterval();
 
		/* Avoid next_draw_tick getting behind more and more if it cannot keep up. */
 
@@ -831,15 +831,15 @@ void VideoDriver_SDL::LoopOnce()
 
	if (!_fast_forward || _pause_mode) {
 
		/* See how much time there is till we have to process the next event, and try to hit that as close as possible. */
 
		auto next_tick = std::min(next_draw_tick, next_game_tick);
 
		auto now = std::chrono::steady_clock::now();
 

	
 
		if (next_tick > now) {
 
			if (_draw_mutex != nullptr) draw_lock.unlock();
 
			this->UnlockVideoBuffer();
 
			std::this_thread::sleep_for(next_tick - now);
 
			if (_draw_mutex != nullptr) draw_lock.lock();
 
			this->LockVideoBuffer();
 
		}
 
	}
 
#endif
 
}
 

	
 
void VideoDriver_SDL::MainLoop()
 
@@ -983,6 +983,17 @@ Dimension VideoDriver_SDL::GetScreenSize
 
{
 
	SDL_DisplayMode mode;
 
	if (SDL_GetCurrentDisplayMode(this->startup_display, &mode) != 0) return VideoDriver::GetScreenSize();
 

	
 
	return { static_cast<uint>(mode.w), static_cast<uint>(mode.h) };
 
}
 

	
 
bool VideoDriver_SDL::LockVideoBuffer()
 
{
 
	if (_draw_threaded) this->draw_lock.lock();
 
	return true;
 
}
 

	
 
void VideoDriver_SDL::UnlockVideoBuffer()
 
{
 
	if (_draw_threaded) this->draw_lock.unlock();
 
}