Improve code

This commit is contained in:
Loic Guegan 2022-12-29 15:02:17 +01:00
parent 796ba531ea
commit 834387d7b2
2 changed files with 6 additions and 5 deletions

View file

@ -110,7 +110,7 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn,
Refresh();
}
void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst,bool faster){
void BoardCanvas::Animate(const std::string &board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst,bool faster){
adata.final_board=board;
adata.final_is_black_turn=is_black_turn;
adata.final_captures=captures;
@ -151,15 +151,16 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char,
adata.reuseBuffer=true;
int duration_backup=adata.duration;
adata.duration=faster ? adata.duration_fast : adata.duration;
int frame_duration=(1000/adata.fps);
adata.frame=0;
adata.frames=adata.duration/(1000/adata.fps); // total number of frames
adata.frames=adata.duration/frame_duration; // total number of frames
int time_per_frame=adata.duration/adata.frames;
wxStopWatch sw;
for(int i=adata.frames;i>0;i--){
Refresh();
Update();
int delay=sw.Time()-time_per_frame;
if(delay>10){
int delay=sw.Time()-frame_duration;
if(delay>5){ // 5ms tolerance
wxMilliSleep(delay);
}
sw.Start(0);

View file

@ -100,7 +100,7 @@ public:
void Swap();
void SetupBoard(std::string board, bool is_black_turn,
std::map<char, std::uint8_t> captures);
void Animate(std::string board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst,bool faster);
void Animate(const std::string &board, bool is_black_turn, std::map<char, std::uint8_t> captures, std::string src, std::string dst,bool faster);
void SetClockTime(short hours, short min, short sec, bool IsBlack);
DECLARE_EVENT_TABLE()
};