mirror of
https://gitlab.com/manzerbredes/ochess.git
synced 2025-04-07 02:26:29 +02:00
Improve code
This commit is contained in:
parent
796ba531ea
commit
834387d7b2
2 changed files with 6 additions and 5 deletions
|
@ -110,7 +110,7 @@ void BoardCanvas::SetupBoard(std::string board, bool is_black_turn,
|
||||||
Refresh();
|
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_board=board;
|
||||||
adata.final_is_black_turn=is_black_turn;
|
adata.final_is_black_turn=is_black_turn;
|
||||||
adata.final_captures=captures;
|
adata.final_captures=captures;
|
||||||
|
@ -151,15 +151,16 @@ void BoardCanvas::Animate(std::string board, bool is_black_turn, std::map<char,
|
||||||
adata.reuseBuffer=true;
|
adata.reuseBuffer=true;
|
||||||
int duration_backup=adata.duration;
|
int duration_backup=adata.duration;
|
||||||
adata.duration=faster ? adata.duration_fast : adata.duration;
|
adata.duration=faster ? adata.duration_fast : adata.duration;
|
||||||
|
int frame_duration=(1000/adata.fps);
|
||||||
adata.frame=0;
|
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;
|
int time_per_frame=adata.duration/adata.frames;
|
||||||
wxStopWatch sw;
|
wxStopWatch sw;
|
||||||
for(int i=adata.frames;i>0;i--){
|
for(int i=adata.frames;i>0;i--){
|
||||||
Refresh();
|
Refresh();
|
||||||
Update();
|
Update();
|
||||||
int delay=sw.Time()-time_per_frame;
|
int delay=sw.Time()-frame_duration;
|
||||||
if(delay>10){
|
if(delay>5){ // 5ms tolerance
|
||||||
wxMilliSleep(delay);
|
wxMilliSleep(delay);
|
||||||
}
|
}
|
||||||
sw.Start(0);
|
sw.Start(0);
|
||||||
|
|
|
@ -100,7 +100,7 @@ public:
|
||||||
void Swap();
|
void Swap();
|
||||||
void SetupBoard(std::string board, bool is_black_turn,
|
void SetupBoard(std::string board, bool is_black_turn,
|
||||||
std::map<char, std::uint8_t> captures);
|
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);
|
void SetClockTime(short hours, short min, short sec, bool IsBlack);
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue