Skip to content

Commit

Permalink
Responsivity improvement: swap view and update steps (#73)
Browse files Browse the repository at this point in the history
* Responsivity improvement: swap view and update steps

* cargo fmt
  • Loading branch information
matthewhammer authored Jul 13, 2021
1 parent 34450e6 commit 60b5c00
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 64 deletions.
112 changes: 56 additions & 56 deletions src/bin/ic-mt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
extern crate garcon;
extern crate futures;
extern crate garcon;
extern crate ic_agent;
extern crate ic_types;
extern crate icmt;
Expand Down Expand Up @@ -64,13 +64,14 @@ async fn create_agent(url: &str) -> IcmtResult<Agent> {
let rng = SystemRandom::new();
let pkcs8_bytes = ring::signature::Ed25519KeyPair::generate_pkcs8(&rng)?;
let key_pair = ring::signature::Ed25519KeyPair::from_pkcs8(pkcs8_bytes.as_ref())?;
let ident = ic_agent::identity::BasicIdentity::from_key_pair(key_pair);
let ident = ic_agent::identity::BasicIdentity::from_key_pair(key_pair);
let agent = Agent::builder()
.with_url(url)
.with_identity(ident)
.build()?;
info!("built agent.");
if true { // to do -- CLI switch.
if true {
// to do -- CLI switch.
agent.fetch_root_key().await?;
}
info!("got root key.");
Expand Down Expand Up @@ -436,6 +437,57 @@ async fn local_event_loop(ctx: ConnectCtx) -> Result<(), IcmtError> {
))?;
}
}
if quit_request {
write_gifs(
&ctx.cfg.cli_opt,
&window_dim,
dump_events,
&dump_graphics,
&engiffen_paths,
)?;
{
print!("Stopping view task... ");
view_out.send(None)?;
println!("Done.");
}
println!("All done.");
return Ok(());
} else
/* attend to view task */
{
match view_in.try_recv() {
Ok(rr) => {
view_responses += 1;
info!("view_responses = {}", view_responses);

do_redraw(
&(ctx.cfg).cli_opt,
&window_dim,
&mut window_canvas,
&mut file_canvas,
&mut engiffen_paths,
&rr,
)
.await?;

ready_flag = true;
}
Err(mpsc::TryRecvError::Empty) => { /* not ready; do nothing */ }
Err(e) => error!("{:?}", e),
};

if dirty_flag && ready_flag {
dirty_flag = false;
ready_flag = false;
let mut events = update_events.clone();
events.append(&mut (view_events.clone()));

view_out.send(Some((window_dim.clone(), events)))?;

view_requests += 1;
debug!("view_requests = {}", view_requests);
}
};

/* attend to update task */
if is_live || !quit_request {
Expand Down Expand Up @@ -502,58 +554,6 @@ async fn local_event_loop(ctx: ConnectCtx) -> Result<(), IcmtError> {
}
};

if quit_request {
write_gifs(
&ctx.cfg.cli_opt,
&window_dim,
dump_events,
&dump_graphics,
&engiffen_paths,
)?;
{
print!("Stopping view task... ");
view_out.send(None)?;
println!("Done.");
}
println!("All done.");
return Ok(());
} else
/* attend to view task */
{
match view_in.try_recv() {
Ok(rr) => {
view_responses += 1;
debug!("view_responses = {}", view_responses);

do_redraw(
&(ctx.cfg).cli_opt,
&window_dim,
&mut window_canvas,
&mut file_canvas,
&mut engiffen_paths,
&rr,
)
.await?;

ready_flag = true;
}
Err(mpsc::TryRecvError::Empty) => { /* not ready; do nothing */ }
Err(e) => error!("{:?}", e),
};

if dirty_flag && ready_flag {
dirty_flag = false;
ready_flag = false;
let mut events = update_events.clone();
events.append(&mut (view_events.clone()));

view_out.send(Some((window_dim.clone(), events)))?;

view_requests += 1;
debug!("view_requests = {}", view_requests);
}
};

// attend to next batch of local events, and loop everything above
continue 'running;
}
Expand Down Expand Up @@ -745,6 +745,6 @@ async fn main() -> IcmtResult<()> {
};
run(cfg).await?;
}
};
};
Ok(())
}
12 changes: 5 additions & 7 deletions src/lib/draw.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Draw.
use log::{trace, warn, error};
use log::{error, trace, warn};

use crate::{
color::*,
Expand Down Expand Up @@ -118,12 +118,10 @@ pub async fn draw<T: RenderTarget>(
warn!("unrecognized redraw elements {:?}", elms);
}
}
graphics::Result::Err(opt_message) => {
match opt_message {
None => error!("Error result from server. No message."),
Some(ref m) => error!("Error message from server: {}", m),
}
}
graphics::Result::Err(opt_message) => match opt_message {
None => error!("Error result from server. No message."),
Some(ref m) => error!("Error message from server: {}", m),
},
};
canvas.present();
// to do -- if enabled, dump canvas as .BMP file to next output image file in the stream that we are producing
Expand Down
2 changes: 1 addition & 1 deletion src/lib/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub mod graphics {
#[serde(rename = "rect")]
Rect(Rect, Fill),
#[serde(rename = "node")]
Node(Box<Node>)
Node(Box<Node>),
}
/// Elements
pub type Elms = Vec<Elm>;
Expand Down

0 comments on commit 60b5c00

Please sign in to comment.