2019-09-19 15:18:50 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file sdl2_v.h Base of the SDL2 video driver. */
|
|
|
|
|
|
|
|
#ifndef VIDEO_SDL_H
|
|
|
|
#define VIDEO_SDL_H
|
|
|
|
|
|
|
|
#include "video_driver.hpp"
|
|
|
|
|
|
|
|
/** The SDL video driver. */
|
|
|
|
class VideoDriver_SDL : public VideoDriver {
|
|
|
|
public:
|
2020-05-17 21:32:08 +00:00
|
|
|
const char *Start(const StringList ¶m) override;
|
2019-09-19 15:18:50 +00:00
|
|
|
|
|
|
|
void Stop() override;
|
|
|
|
|
|
|
|
void MakeDirty(int left, int top, int width, int height) override;
|
|
|
|
|
|
|
|
void MainLoop() override;
|
|
|
|
|
|
|
|
bool ChangeResolution(int w, int h) override;
|
|
|
|
|
|
|
|
bool ToggleFullscreen(bool fullscreen) override;
|
|
|
|
|
|
|
|
bool AfterBlitterChange() override;
|
|
|
|
|
|
|
|
void AcquireBlitterLock() override;
|
|
|
|
|
|
|
|
void ReleaseBlitterLock() override;
|
|
|
|
|
|
|
|
bool ClaimMousePointer() override;
|
|
|
|
|
2019-11-04 18:16:34 +00:00
|
|
|
void EditBoxGainedFocus() override;
|
|
|
|
|
|
|
|
void EditBoxLostFocus() override;
|
|
|
|
|
2019-09-19 15:18:50 +00:00
|
|
|
const char *GetName() const override { return "sdl"; }
|
2021-01-14 20:53:06 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
Dimension GetScreenSize() const override;
|
2021-02-19 10:01:49 +00:00
|
|
|
void InputLoop() override;
|
2021-02-20 09:49:27 +00:00
|
|
|
bool LockVideoBuffer() override;
|
|
|
|
void UnlockVideoBuffer() override;
|
2021-02-20 10:08:20 +00:00
|
|
|
void Paint() override;
|
|
|
|
void PaintThread() override;
|
2021-01-14 20:53:06 +00:00
|
|
|
|
2019-09-19 15:18:50 +00:00
|
|
|
private:
|
|
|
|
int PollEvent();
|
2020-12-06 19:38:34 +00:00
|
|
|
void LoopOnce();
|
|
|
|
void MainLoopCleanup();
|
2019-09-19 15:18:50 +00:00
|
|
|
bool CreateMainSurface(uint w, uint h, bool resize);
|
2021-01-24 10:54:36 +00:00
|
|
|
bool CreateMainWindow(uint w, uint h);
|
2021-01-24 11:08:37 +00:00
|
|
|
void CheckPaletteAnim();
|
2019-11-04 18:16:34 +00:00
|
|
|
|
2020-12-05 20:57:47 +00:00
|
|
|
#ifdef __EMSCRIPTEN__
|
|
|
|
/* Convert a constant pointer back to a non-constant pointer to a member function. */
|
|
|
|
static void EmscriptenLoop(void *self) { ((VideoDriver_SDL *)self)->LoopOnce(); }
|
|
|
|
#endif
|
|
|
|
|
2019-11-04 18:16:34 +00:00
|
|
|
/**
|
|
|
|
* This is true to indicate that keyboard input is in text input mode, and SDL_TEXTINPUT events are enabled.
|
|
|
|
*/
|
|
|
|
bool edit_box_focused;
|
2020-12-06 19:38:34 +00:00
|
|
|
|
2021-02-17 13:46:19 +00:00
|
|
|
std::chrono::steady_clock::time_point cur_ticks;
|
2021-02-17 13:49:45 +00:00
|
|
|
std::chrono::steady_clock::time_point last_realtime_tick;
|
Add: draw the screen at a steady pace, also during fast-forward
During fast-forward, the game was drawing as fast as it could. This
means that the fast-forward was limited also by how fast we could
draw, something that people in general don't expect.
To give an extreme case, if you are fully zoomed out on a busy
map, fast-forward would be mostly limited because of the time it
takes to draw the screen.
By decoupling the draw-tick and game-tick, we can keep the pace
of the draw-tick the same while speeding up the game-tick. To use
the extreme case as example again, if you are fully zoomed out
now, the screen only redraws 33.33 times per second, fast-forwarding
or not. This means fast-forward is much more likely to go at the
same speed, no matter what you are looking at.
2021-02-17 14:04:46 +00:00
|
|
|
std::chrono::steady_clock::time_point next_game_tick;
|
|
|
|
std::chrono::steady_clock::time_point next_draw_tick;
|
2020-12-06 19:38:34 +00:00
|
|
|
|
2021-01-14 22:29:29 +00:00
|
|
|
int startup_display;
|
2020-12-06 19:38:34 +00:00
|
|
|
std::thread draw_thread;
|
|
|
|
std::unique_lock<std::recursive_mutex> draw_lock;
|
2021-02-20 10:08:20 +00:00
|
|
|
|
|
|
|
static void PaintThreadThunk(VideoDriver_SDL *drv);
|
2019-09-19 15:18:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Factory for the SDL video driver. */
|
|
|
|
class FVideoDriver_SDL : public DriverFactoryBase {
|
|
|
|
public:
|
|
|
|
FVideoDriver_SDL() : DriverFactoryBase(Driver::DT_VIDEO, 5, "sdl", "SDL Video Driver") {}
|
|
|
|
Driver *CreateInstance() const override { return new VideoDriver_SDL(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* VIDEO_SDL_H */
|