diff --git a/flake.nix b/flake.nix index 138422f..a5ff1b9 100644 --- a/flake.nix +++ b/flake.nix @@ -76,7 +76,7 @@ inherit pkgs; buildRustCrateForPkgs = customBuildInfo; rootFeatures = [ "screenplay" ]; - release = false; + release = true; }).rootCrate.build; }; }; diff --git a/kifu/kifu-gtk/src/main.rs b/kifu/kifu-gtk/src/main.rs index 0a7e41c..d1ce77d 100644 --- a/kifu/kifu-gtk/src/main.rs +++ b/kifu/kifu-gtk/src/main.rs @@ -3,7 +3,7 @@ use gtk::prelude::*; use kifu_core::{CoreApp, Request, Response}; use kifu_gtk::{ui::PlayingField, CoreApi}; use std::{ - sync::{Arc, Mutex}, + sync::{Arc, Mutex, RwLock}, time::Duration, }; use tokio::{ @@ -52,12 +52,23 @@ fn main() { gtk_rx.attach(None, { let api = api.clone(); + let playing_field = Arc::new(RwLock::new(None)); move |message| { match message { Response::PlayingFieldView(view) => { let api = api.clone(); - let playing_field = PlayingField::new(api, view); - window.set_child(Some(&playing_field)); + + let start = std::time::Instant::now(); + let mut playing_field = playing_field.write().unwrap(); + if playing_field.is_none() { + let field = PlayingField::new(api, view); + window.set_child(Some(&field)); + *playing_field = Some(field); + } else { + playing_field.as_ref().map(|field| field.update_view(view)); + } + let end = std::time::Instant::now(); + println!("Time to render the playing field: {:?}", end - start); } } Continue(true) diff --git a/kifu/kifu-gtk/src/ui/board.rs b/kifu/kifu-gtk/src/ui/board.rs index 6024b42..de9b561 100644 --- a/kifu/kifu-gtk/src/ui/board.rs +++ b/kifu/kifu-gtk/src/ui/board.rs @@ -82,6 +82,7 @@ impl ObjectImpl for BoardPrivate { self.drawing_area .set_draw_func(move |_, context, width, height| { + let render_start = std::time::Instant::now(); let board = board.borrow(); match background { Ok(Some(ref background)) => { @@ -125,11 +126,10 @@ impl ObjectImpl for BoardPrivate { (0..19).for_each(|col| { (0..19).for_each(|row| { match board.stone(row, col) { - IntersectionElement::Unplayable => {} - IntersectionElement::Empty(request) => {} IntersectionElement::Filled(stone) => { pen.stone(&context, row, col, stone.color); } + _ => {} }; }) }); @@ -144,6 +144,8 @@ impl ObjectImpl for BoardPrivate { ), _ => {} } + let render_end = std::time::Instant::now(); + println!("board rendering time: {:?}", render_end - render_start); }); let motion_controller = gtk::EventControllerMotion::new(); diff --git a/kifu/kifu-gtk/src/ui/playing_field.rs b/kifu/kifu-gtk/src/ui/playing_field.rs index b4fa490..1738cf3 100644 --- a/kifu/kifu-gtk/src/ui/playing_field.rs +++ b/kifu/kifu-gtk/src/ui/playing_field.rs @@ -85,6 +85,13 @@ impl PlayingField { s } + + pub fn update_view(&self, view: PlayingFieldView) { + self.imp().board.borrow().as_ref().map(|board| { + board.set_board(view.board); + board.set_current_player(view.current_player); + }); + } } #[cfg(feature = "screenplay")]