Merge pull request #697 from wesnoth/flickerfix

Hacky fix for the flickering when a screen is fully redrawn.
This commit is contained in:
Andreas 2016-07-16 19:05:08 +12:00 committed by GitHub
commit b2f86b6b07
4 changed files with 31 additions and 2 deletions

View file

@ -2720,6 +2720,7 @@ void display::draw(bool update,bool force) {
}
if (dirty_) {
flip_locker flip_lock(screen_);
dirty_ = false;
redraw_everything();
return;

View file

@ -471,6 +471,7 @@ void pump()
}
case DRAW_ALL_EVENT:
{
flip_locker flip_lock(CVideo::get_singleton());
/* iterate backwards as the most recent things will be at the top */
for( std::deque<context>::iterator i = event_contexts.begin() ; i != event_contexts.end(); ++i) {
const std::vector<sdl_handler*>& event_handlers = (*i).handlers;

View file

@ -220,7 +220,8 @@ CVideo::CVideo(FAKE_TYPES type) :
mode_changed_(false),
fake_screen_(false),
help_string_(0),
updatesLocked_(0)
updatesLocked_(0),
flip_locked_(0)
{
assert(!singleton_);
singleton_ = this;
@ -495,7 +496,7 @@ void CVideo::delay(unsigned int milliseconds)
void CVideo::flip()
{
if(fake_screen_)
if(fake_screen_ || flip_locked_ > 0)
return;
#ifdef SDL_GPU
assert(render_target_);
@ -716,3 +717,11 @@ void CVideo::set_resolution(const unsigned width, const unsigned height)
preferences::_set_resolution(std::make_pair(width, height));
preferences::_set_maximized(false);
}
void CVideo::lock_flips(bool lock) {
if (lock) {
++flip_locked_;
} else {
--flip_locked_;
}
}

View file

@ -209,6 +209,8 @@ public:
*/
std::vector<std::pair<int, int> > get_available_resolutions(const bool include_current = false);
void lock_flips(bool);
private:
static CVideo* singleton_;
@ -242,6 +244,7 @@ private:
int help_string_;
int updatesLocked_;
int flip_locked_;
};
//an object which will lock the display for the duration of its lifetime.
@ -269,6 +272,21 @@ private:
bool unlock;
};
class flip_locker
{
public:
flip_locker(CVideo &video) : video_(video) {
video_.lock_flips(true);
}
~flip_locker() {
video_.lock_flips(false);
}
private:
CVideo& video_;
};
namespace video2 {
class draw_layering: public events::sdl_handler {
protected: