Skip to content

Commit

Permalink
Merge pull request #2 from nidhoggfgg/master
Browse files Browse the repository at this point in the history
improve performance
  • Loading branch information
Wayoung7 committed Apr 30, 2024
2 parents a75d197 + de656dc commit cafb248
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 21 deletions.
8 changes: 3 additions & 5 deletions src/fireworks.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `firework` module provides functions to define, create and update fireworks

use std::time::{Duration, SystemTime};
use std::{collections::VecDeque, time::{Duration, SystemTime}};

use glam::Vec2;
use rand::{seq::IteratorRandom, thread_rng};
Expand Down Expand Up @@ -373,8 +373,6 @@ pub enum FireworkInstallForm {
DynamicInstall,
}

fn init_trail(init_pos: Vec2, n: usize) -> Vec<Vec2> {
let mut res = Vec::new();
(0..n).for_each(|_| res.push(init_pos));
res
fn init_trail(init_pos: Vec2, n: usize) -> VecDeque<Vec2> {
VecDeque::from(vec![init_pos; n])
}
13 changes: 6 additions & 7 deletions src/particle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `particle` module provides functions to define, create and update particles

use std::time::Duration;
use std::{collections::VecDeque, time::Duration};

use glam::Vec2;

Expand All @@ -23,7 +23,7 @@ pub struct Particle {
pub pos: Vec2,
pub vel: Vec2,
/// Records a `trail_length` of previous positions of the `Particle`
pub trail: Vec<Vec2>,
pub trail: VecDeque<Vec2>,
pub life_state: LifeState,
/// `Duration` since initialization of this `Particle`
pub time_elapsed: Duration,
Expand All @@ -35,7 +35,7 @@ impl Default for Particle {
Self {
pos: Vec2::ZERO,
vel: Vec2::ZERO,
trail: Vec::new(),
trail: VecDeque::new(),
life_state: LifeState::Alive,
time_elapsed: Duration::ZERO,
config: ParticleConfig::default(),
Expand All @@ -52,8 +52,7 @@ impl Particle {
life_time: Duration,
color: (u8, u8, u8),
) -> Self {
let mut trail = Vec::with_capacity(trail_length);
(0..trail_length).for_each(|_| trail.push(pos));
let trail = VecDeque::from(vec![pos; trail_length]);
let life_state = LifeState::Alive;
Self {
pos,
Expand Down Expand Up @@ -97,8 +96,8 @@ impl Particle {
self.pos += TIME_STEP * self.vel;
t += TIME_STEP;
}
self.trail.remove(0);
self.trail.push(self.pos);
self.trail.pop_front();
self.trail.push_back(self.pos);
}
}

Expand Down
12 changes: 3 additions & 9 deletions src/term.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@ fn get_char_alive(density: f32, cjk: bool) -> char {
} else {
"oahkbdpqwmZO0QLCJUYXzcvunxrjft*"
}
} else {
if cjk {
} else if cjk {
"𰻞"
// "東京福岡横浜縄"
} else {
"$@B%8&WM#"
}
};
palette
.chars()
Expand Down Expand Up @@ -319,13 +317,11 @@ fn get_char_declining(density: f32, cjk: bool) -> char {
} else {
"/\\| ()1{}[ ]?"
}
} else {
if cjk {
} else if cjk {
"繁荣昌盛国泰民安龍龖龠龜耋"
// "時間言葉目覚"
} else {
"xrjft*"
}
};
palette
.chars()
Expand All @@ -340,13 +336,11 @@ fn get_char_dying(density: f32, cjk: bool) -> char {
} else {
". ,`. ^,' . "
}
} else {
if cjk {
} else if cjk {
"|¥人 上十入乙小 下"
// "イントマトナイフ"
} else {
" /\\| ( ) 1{} [ ]?i !l I;: ,\"^ "
}
};
palette
.chars()
Expand Down

0 comments on commit cafb248

Please sign in to comment.