Skip to content

Commit

Permalink
fix(performance): not passing huge string here, and there: printing i…
Browse files Browse the repository at this point in the history
…n function app.render_univ(). Also moving back cursor to 0,0
  • Loading branch information
JeromeSchmied committed Feb 25, 2024
1 parent 1f7690c commit bdbd6d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ impl App {
pub fn poll_t(&self) -> Duration {
self.poll_t
}
pub fn render_universe(&self) -> String {
self.universe.to_string()
pub fn render_universe(&self) {
println!("{}", self.universe);
}

pub fn play_pause(&mut self, prev_poll_t: &mut Duration) {
Expand Down
13 changes: 3 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ fn main() -> io::Result<()> {
}

use crossterm::{
cursor::MoveTo,
event::{poll, read},
execute,
terminal::{
Expand All @@ -30,14 +31,6 @@ fn print_events() -> io::Result<()> {

let mut app = App::default();

// widht and height, as they're the same
// let mut wh = DEF_WH;

// let mut i: usize = 0;
// let mut universe = shapes::get(wh, i).unwrap();

// let mut poll_t = DEF_DUR;
// let mut paused = false;
let mut prev_poll_t = app.poll_t();

loop {
Expand Down Expand Up @@ -89,8 +82,8 @@ fn print_events() -> io::Result<()> {
}
} else {
// Timeout expired, updating life state
execute!(io::stdout(), Clear(ClearType::All))?;
println!("{}", app.render_universe());
execute!(io::stdout(), MoveTo(0, 0), Clear(ClearType::All))?;
app.render_universe();
app.tick();
}
}
Expand Down

0 comments on commit bdbd6d9

Please sign in to comment.