10#ifndef VIDEO_VIDEO_DRIVER_HPP
11#define VIDEO_VIDEO_DRIVER_HPP
51 virtual void MakeDirty(
int left,
int top,
int width,
int height) = 0;
197 std::lock_guard<std::mutex>
lock(this->cmd_queue_mutex);
199 this->cmd_queue.emplace_back(std::forward<std::function<
void()>>(func));
324 std::chrono::steady_clock::duration GetGameInterval()
326#ifdef DEBUG_DUMP_COMMANDS
328 extern bool _ddc_fastforward;
329 if (_ddc_fastforward)
return std::chrono::microseconds(0);
332 TicToc::Tick(
"GameTick");
337 if (
_game_speed == 0)
return std::chrono::microseconds(0);
342 std::chrono::steady_clock::duration GetDrawInterval()
344 TicToc::Tick(
"DrawTick");
354 std::vector<std::function<void()>> cmds{};
360 std::lock_guard<std::mutex>
lock(this->cmd_queue_mutex);
361 cmds.swap(this->cmd_queue);
364 for (
auto &f : cmds) {
369 std::chrono::steady_clock::time_point next_game_tick;
370 std::chrono::steady_clock::time_point next_draw_tick;
372 std::thread game_thread;
373 std::mutex game_state_mutex;
374 std::mutex game_thread_wait_mutex;
388 std::mutex cmd_queue_mutex;
389 std::vector<std::function<void()>> cmd_queue;
static std::unique_ptr< Driver > & GetActiveDriver(Driver::Type type)
Get the active driver for the given type.
A driver for communicating with the user.
virtual std::string_view GetName() const =0
Get the name of this driver.
virtual void InputLoop()
Handle input logic, is CTRL pressed, should we fast-forward, etc.
virtual bool ToggleFullscreen(bool fullscreen)=0
Change the full screen setting.
int anim_pitch
Pitch of the animation buffer if supported/used.
virtual Dimension GetScreenSize() const
Get the resolution of the main screen.
virtual void PopulateSystemSprites()
Populate all sprites in cache.
void QueueOnMainThread(std::function< void()> &&func)
Queue a function to be called on the main thread with game state lock held and video buffer locked.
virtual std::string_view GetInfoString() const
Get some information about the selected driver/backend to be shown to the user.
const uint DEFAULT_WINDOW_WIDTH
Default window width.
bool fast_forward_key_pressed
The fast-forward key is being pressed.
virtual void ClearSystemSprites()
Clear all cached sprites.
virtual bool UseSystemCursor()
Get whether the mouse cursor is drawn by the video driver.
virtual void SetScreensaverInhibited(bool inhibited)
Prevents the system from going to sleep.
void Tick()
Give the video-driver a tick.
const uint DEFAULT_WINDOW_HEIGHT
Default window height.
const bool supports_animation_buffer
Whether this driver supports hardware accelerated animation.
virtual void MakeDirty(int left, int top, int width, int height)=0
Mark a particular area dirty.
void SleepTillNextTick()
Sleep till the next tick is about to happen.
void StartGameThread()
Start the loop for game-tick.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
virtual bool ChangeResolution(int w, int h)=0
Change the resolution of the window.
virtual bool HasGUI() const
Whether the driver has a graphical user interface with the end user.
static std::string GetCaption()
Get the caption to use for the game's title bar.
virtual void ToggleVsync(bool vsync)
Change the vsync setting.
virtual bool AfterBlitterChange()
Callback invoked after the blitter was changed.
void StopGameThread()
Stop the loop for the game-tick.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
const uint ALLOWED_DRIFT
How many times videodriver can miss deadlines without it being overly compensated.
virtual void MainLoop()=0
Perform the actual drawing.
virtual void EditBoxGainedFocus()
An edit box gained the input focus.
virtual bool PollEvent()
Process a single system event.
VideoDriver(bool uses_hardware_acceleration=false, bool supports_animation_buffer=false)
Create the video driver.
virtual bool HasEfficient8Bpp() const
Has this video driver an efficient code path for palette animated 8-bpp sprites?
virtual void Paint()
Paint the window.
virtual void UnlockVideoBuffer()
Unlock a previously locked video buffer.
uint8_t * anim_buffer
The animation buffer if supported/used.
bool fast_forward_via_key
The fast-forward was enabled by key press.
constexpr bool SupportsAnimationBuffer() const
Does this video driver support a separate animation buffer in addition to the colour buffer?
virtual void ClaimMousePointer()
Claim the exclusive rights for the mouse pointer.
virtual std::vector< int > GetListOfMonitorRefreshRates()
Get a list of refresh rates of each available monitor.
constexpr uint8_t * GetAnimBuffer() const
Get a pointer to the animation buffer of the video back-end.
virtual void CheckPaletteAnim()
Process any pending palette animation.
virtual bool LockVideoBuffer()
Make sure the video buffer is ready for drawing.
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
void DrainCommandQueue()
Execute all queued commands.
void UpdateAutoResolution()
Apply resolution auto-detection and clamp to sensible defaults.
const bool uses_hardware_acceleration
Whether hardware acceleration is used or not.
bool is_game_threaded
Whether the game is allowed to use threads; cleared in the driver implementation constructors if requ...
constexpr int GetAnimBufferPitch() const
Get the animation buffer pitch in uint8_t elements per row.
Functions related to debugging.
std::string _ini_videodriver
The video driver a stored in the configuration file.
std::vector< Dimension > _resolutions
List of resolutions.
Dimension _cur_resolution
The current resolution.
bool _rightclick_emulate
Whether right clicking is emulated.
Base for all drivers (video, sound, music, etc).
All geometry types in OpenTTD.
uint16_t _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
PauseModes _pause_mode
The current pause mode.
Functions related to the gfx engine.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
constexpr uint ClampU(const uint a, const uint min, const uint max)
Clamp an unsigned integer between an interval.
ClientSettings _settings_client
The current settings for this game.
Types related to global configuration settings.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
uint16_t refresh_rate
How often we refresh the screen (time between draw-ticks).
bool unlock
Stores if the lock did anything that has to be undone.
VideoBufferLocker()
Lock the video buffer.
~VideoBufferLocker()
Release the video buffer.
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).
bool _video_hw_accel
Whether to consider hardware accelerated video drivers on startup.
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).
Dimension _cur_resolution
The current resolution.
std::mutex lock
synchronization for playback status fields