From 756c888145f4c1046b25cad062af11c13596d50e Mon Sep 17 00:00:00 2001 From: Loic Guegan Date: Thu, 29 Dec 2022 11:52:24 +0100 Subject: [PATCH] Improve animation consistency --- src/game_tab/left_panel/board/BoardCanvas.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/game_tab/left_panel/board/BoardCanvas.cpp b/src/game_tab/left_panel/board/BoardCanvas.cpp index ad6ba65..58c3fd6 100644 --- a/src/game_tab/left_panel/board/BoardCanvas.cpp +++ b/src/game_tab/left_panel/board/BoardCanvas.cpp @@ -17,7 +17,7 @@ BoardCanvas::BoardCanvas(wxFrame *parent) SetBackgroundStyle(wxBG_STYLE_PAINT); duration=200; duration_fast=100; - fps=180; + fps=30; Bind(wxEVT_KEY_DOWN, &BoardCanvas::OnKeyEvent, this); Bind(wxEVT_KEY_UP, &BoardCanvas::OnKeyEvent, this); @@ -121,9 +121,9 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::mapboard[pfile + 8 * (7-prank)]=' '; - SetupBoard(this->board,this->is_black_turn,this->captures); - Update(); // Since refresh in SetupBoard is not synchronous, this call wait the end of Refresh() - + wxMemoryDC memDC(*buffer); + DrawBoard(memDC); + // Now compute piece start position and translation vector (Copy paste from DrawBoard()) std::uint32_t piece_width = t->GetPiecesSizes(); std::uint32_t centrer_offset = (square_width - piece_width) / 2; @@ -153,10 +153,16 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map0;i--){ Refresh(); Update(); - wxMilliSleep((1000/(fps*2))); + int delay=sw.Time()-time_per_frame; + if(delay>10){ + wxMilliSleep(delay); + } + sw.Start(0); } duration=faster ? duration_backup : duration_backup; reuseBuffer=false;