Merge branch 'master' into jgrpp
This commit is contained in:
@@ -16,13 +16,18 @@
|
||||
#include "../gfx_func.h"
|
||||
#include "../settings_type.h"
|
||||
#include "../zoom_type.h"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
extern std::string _ini_videodriver;
|
||||
extern std::vector<Dimension> _resolutions;
|
||||
extern Dimension _cur_resolution;
|
||||
extern bool _rightclick_emulate;
|
||||
extern bool _video_hw_accel;
|
||||
|
||||
/** The base of all video drivers. */
|
||||
class VideoDriver : public Driver {
|
||||
@@ -30,6 +35,8 @@ class VideoDriver : public Driver {
|
||||
const uint DEFAULT_WINDOW_HEIGHT = 480u; ///< Default window height.
|
||||
|
||||
public:
|
||||
VideoDriver() : is_game_threaded(true), change_blitter(nullptr) {}
|
||||
|
||||
/**
|
||||
* Mark a particular area dirty.
|
||||
* @param left The left most line of the dirty area.
|
||||
@@ -61,7 +68,6 @@ public:
|
||||
|
||||
/**
|
||||
* Callback invoked after the blitter was changed.
|
||||
* This may only be called between AcquireBlitterLock and ReleaseBlitterLock.
|
||||
* @return True if no error.
|
||||
*/
|
||||
virtual bool AfterBlitterChange()
|
||||
@@ -69,18 +75,6 @@ public:
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire any lock(s) required to be held when changing blitters.
|
||||
* These lock(s) may not be acquired recursively.
|
||||
*/
|
||||
virtual void AcquireBlitterLock() { }
|
||||
|
||||
/**
|
||||
* Release any lock(s) required to be held when changing blitters.
|
||||
* These lock(s) may not be acquired recursively.
|
||||
*/
|
||||
virtual void ReleaseBlitterLock() { }
|
||||
|
||||
virtual bool ClaimMousePointer()
|
||||
{
|
||||
return true;
|
||||
@@ -95,6 +89,11 @@ public:
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Populate all sprites in cache.
|
||||
*/
|
||||
virtual void PopulateSystemSprites() {}
|
||||
|
||||
/**
|
||||
* Clear all cached sprites.
|
||||
*/
|
||||
@@ -150,6 +149,15 @@ public:
|
||||
*/
|
||||
virtual void EditBoxGainedFocus() {}
|
||||
|
||||
/**
|
||||
* Get a list of refresh rates of each available monitor.
|
||||
* @return A vector of the refresh rates of all available monitors.
|
||||
*/
|
||||
virtual std::vector<int> GetListOfMonitorRefreshRates()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a suggested default GUI zoom taking screen DPI into account.
|
||||
*/
|
||||
@@ -162,6 +170,17 @@ public:
|
||||
return ZOOM_LVL_OUT_4X;
|
||||
}
|
||||
|
||||
/**
|
||||
* Queue a request to change the blitter. This is not executed immediately,
|
||||
* but instead on the next draw-tick.
|
||||
*/
|
||||
void ChangeBlitter(const char *new_blitter)
|
||||
{
|
||||
this->change_blitter = new_blitter;
|
||||
}
|
||||
|
||||
void GameLoopPause();
|
||||
|
||||
/**
|
||||
* Get the currently active instance of the video driver.
|
||||
*/
|
||||
@@ -240,11 +259,6 @@ protected:
|
||||
*/
|
||||
virtual void Paint() {}
|
||||
|
||||
/**
|
||||
* Thread function for threaded drawing.
|
||||
*/
|
||||
virtual void PaintThread() {}
|
||||
|
||||
/**
|
||||
* Process any pending palette animation.
|
||||
*/
|
||||
@@ -257,16 +271,29 @@ protected:
|
||||
virtual bool PollEvent() { return false; };
|
||||
|
||||
/**
|
||||
* Run the game for a single tick, processing boththe game-tick and draw-tick.
|
||||
* @returns True if the driver should redraw the screen.
|
||||
* Start the loop for game-tick.
|
||||
*/
|
||||
bool Tick();
|
||||
void StartGameThread();
|
||||
|
||||
/**
|
||||
* Stop the loop for the game-tick. This can still tick at most one time before truly shutting down.
|
||||
*/
|
||||
void StopGameThread();
|
||||
|
||||
/**
|
||||
* Give the video-driver a tick.
|
||||
* It will process any potential game-tick and/or draw-tick, and/or any
|
||||
* other video-driver related event.
|
||||
*/
|
||||
void Tick();
|
||||
|
||||
/**
|
||||
* Sleep till the next tick is about to happen.
|
||||
*/
|
||||
void SleepTillNextTick();
|
||||
|
||||
void InvalidateGameOptionsWindow();
|
||||
|
||||
std::chrono::steady_clock::duration GetGameInterval()
|
||||
{
|
||||
/* If we are paused, run on normal speed. */
|
||||
@@ -287,6 +314,20 @@ protected:
|
||||
|
||||
bool fast_forward_key_pressed; ///< The fast-forward key is being pressed.
|
||||
bool fast_forward_via_key; ///< The fast-forward was enabled by key press.
|
||||
|
||||
bool is_game_threaded;
|
||||
std::thread game_thread;
|
||||
std::mutex game_state_mutex;
|
||||
std::mutex game_thread_wait_mutex;
|
||||
|
||||
static void GameThreadThunk(VideoDriver *drv);
|
||||
|
||||
private:
|
||||
void GameLoop();
|
||||
void GameThread();
|
||||
void RealChangeBlitter(const char *repl_blitter);
|
||||
|
||||
const char *change_blitter; ///< Request to change the blitter. nullptr if no pending request.
|
||||
};
|
||||
|
||||
#endif /* VIDEO_VIDEO_DRIVER_HPP */
|
||||
|
||||
Reference in New Issue
Block a user