Improve pieces animations

This commit is contained in:
Loic Guegan 2022-12-29 13:08:53 +01:00
parent fdab451352
commit f04f9b7019
2 changed files with 9 additions and 10 deletions

View file

@ -66,15 +66,14 @@ void BoardCanvas::OnPaint(wxPaintEvent &event) {
else {
// Otherwise reuse buffer and animate. TEST CODE FOR NOW:
dc.DrawBitmap(*adata.buffer, 0, 0, true);
double frames=adata.duration/(1000/adata.fps);
double percent=adata.frame/frames;
double percent=adata.frame/adata.frames;
// Draw moving piece
dc.DrawBitmap(*t->Get(adata.piece_moved),
adata.src.x + adata.frame*(adata.transVect.x/frames),
adata.src.y + adata.frame*(adata.transVect.y/frames), false);
adata.src.x + adata.frame*(adata.transVect.x/adata.frames),
adata.src.y + adata.frame*(adata.transVect.y/adata.frames), false);
// end drawing
adata.frame++;
if(adata.frame>=frames){
if(adata.frame>=adata.frames){
adata.reuseBuffer=false;
SetupBoard(adata.final_board, adata.final_is_black_turn, adata.final_captures);
}
@ -125,7 +124,7 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char,
wxMemoryDC memDC(*adata.buffer);
DrawBoard(memDC);
// Now compute piece start position and translation vector (Copy paste from DrawBoard())
// Now compute piece start position and translation vector
std::uint32_t piece_width = t->GetPiecesSizes();
std::uint32_t centrer_offset = (square_width - piece_width) / 2;
if (!black_side) {
@ -153,10 +152,10 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char,
int duration_backup=adata.duration;
adata.duration=faster ? adata.duration_fast : adata.duration;
adata.frame=0;
int frames=adata.duration/(1000/adata.fps); // total number of frames
int time_per_frame=adata.duration/frames;
adata.frames=adata.duration/(1000/adata.fps); // total number of frames
int time_per_frame=adata.duration/adata.frames;
wxStopWatch sw;
for(int i=frames;i>0;i--){
for(int i=adata.frames;i>0;i--){
Refresh();
Update();
int delay=sw.Time()-time_per_frame;

View file

@ -44,7 +44,7 @@ typedef std::tuple<short, short, short> ClockTime;
typedef struct AnimState {
wxBitmap *buffer;
bool reuseBuffer;
int frame,duration,fps,duration_fast;
int frame,frames,duration,fps,duration_fast;
std::string final_board;
bool final_is_black_turn;
std::map<char, std::uint8_t> final_captures;