Skip to content

Commit 1006f80

Browse files
committed
调整fps计算位置
1 parent 473eb25 commit 1006f80

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

dsclient/src/client.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ fn draw(host: String, pwd: String) {
290290
let mut b = Vec::<u8>::with_capacity(dlen);
291291
let c = Vec::<u8>::with_capacity(dlen);
292292
let mut unzip = DefDecoder::new(c);
293+
// FPS
294+
let mut last = std::time::Instant::now();
295+
let mut fps = 0u8;
296+
let mut fpscount = 0u8;
293297
// 接收第一帧数据
294298
let mut header = [0u8; 3];
295299
if let Err(_) = conn.read_exact(&mut header) {
@@ -325,15 +329,7 @@ fn draw(host: String, pwd: String) {
325329
if let Ok(mut _buf) = work_buf.write() {
326330
_buf.copy_from_slice(&a);
327331
}
328-
tx.send(Msg::Draw);
329-
}
330-
});
331-
let mut last = std::time::Instant::now();
332-
let mut fps = 0u8;
333-
let mut fpscount = 0u8;
334-
while app::wait() {
335-
match rx.recv() {
336-
Some(Msg::Draw) => {
332+
{
337333
let cur = std::time::Instant::now();
338334
let dur = cur.duration_since(last);
339335
fpscount += 1;
@@ -345,6 +341,13 @@ fn draw(host: String, pwd: String) {
345341
fps = fpscount;
346342
fpscount = 0;
347343
}
344+
}
345+
tx.send(Msg::Draw);
346+
}
347+
});
348+
while app::wait() {
349+
match rx.recv() {
350+
Some(Msg::Draw) => {
348351
frame.redraw();
349352
}
350353
_ => {}

0 commit comments

Comments
 (0)