Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not spawn particles when jumping to a location instantly #2106

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(not(test), windows_subsystem = "windows")]
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
// Test naming occasionally uses camelCase with underscores to separate sections of
// the test name.
#![cfg_attr(test, allow(non_snake_case))]
Expand Down
124 changes: 65 additions & 59 deletions src/renderer/cursor_renderer/cursor_vfx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub trait CursorVfx {
settings: &CursorSettings,
current_cursor_destination: Point,
cursor_dimensions: Point,
immediate_movement: bool,
dt: f32,
) -> bool;
fn restart(&mut self, position: Point);
Expand Down Expand Up @@ -114,6 +115,7 @@ impl CursorVfx for PointHighlight {
_settings: &CursorSettings,
_current_cursor_destination: Point,
_cursor_dimensions: Point,
_immediate_movement: bool,
dt: f32,
) -> bool {
self.t = (self.t + dt * 5.0).min(1.0); // TODO - speed config
Expand Down Expand Up @@ -222,6 +224,7 @@ impl CursorVfx for ParticleTrail {
settings: &CursorSettings,
current_cursor_dest: Point,
cursor_dimensions: Point,
immediate_movement: bool,
dt: f32,
) -> bool {
// Update lifetimes and remove dead particles
Expand All @@ -245,65 +248,68 @@ impl CursorVfx for ParticleTrail {

// Spawn new particles
if current_cursor_dest != self.previous_cursor_dest {
let travel = current_cursor_dest - self.previous_cursor_dest;
let travel_distance = travel.length();

// Increase amount of particles when cursor travels further
let particle_count = ((travel_distance / cursor_dimensions.y).powf(1.5)
* settings.vfx_particle_density
* 0.01) as usize;

let prev_p = self.previous_cursor_dest;

for i in 0..particle_count {
let t = i as f32 / (particle_count as f32);

let speed = match self.trail_mode {
TrailMode::Railgun => {
let phase = t / std::f32::consts::PI
* settings.vfx_particle_phase
* (travel_distance / cursor_dimensions.y);
Point::new(phase.sin(), phase.cos()) * 2.0 * settings.vfx_particle_speed
}
TrailMode::Torpedo => {
let mut travel_dir = travel;
travel_dir.normalize();
let mut particle_dir = self.rng.rand_dir_normalized() - travel_dir * 1.5;
particle_dir.normalize();
particle_dir * settings.vfx_particle_speed
}
TrailMode::PixieDust => {
let base_dir = self.rng.rand_dir_normalized();
let dir = Point::new(base_dir.x * 0.5, 0.4 + base_dir.y.abs());
dir * 3.0 * settings.vfx_particle_speed
}
};

// Distribute particles along the travel distance
let pos = match self.trail_mode {
TrailMode::Railgun => prev_p + travel * t,
TrailMode::PixieDust | TrailMode::Torpedo => {
prev_p
+ travel * self.rng.next_f32()
+ Point::new(0.0, cursor_dimensions.y * 0.5)
}
};

let rotation_speed = match self.trail_mode {
TrailMode::Railgun => std::f32::consts::PI * settings.vfx_particle_curl,
TrailMode::PixieDust | TrailMode::Torpedo => {
(self.rng.next_f32() - 0.5)
* std::f32::consts::FRAC_PI_2
* settings.vfx_particle_curl
}
};

self.add_particle(
pos,
speed,
rotation_speed,
t * settings.vfx_particle_lifetime,
);
if !immediate_movement {
let travel = current_cursor_dest - self.previous_cursor_dest;
let travel_distance = travel.length();

// Increase amount of particles when cursor travels further
let particle_count = ((travel_distance / cursor_dimensions.y).powf(1.5)
* settings.vfx_particle_density
* 0.01) as usize;

let prev_p = self.previous_cursor_dest;

for i in 0..particle_count {
let t = i as f32 / (particle_count as f32);

let speed = match self.trail_mode {
TrailMode::Railgun => {
let phase = t / std::f32::consts::PI
* settings.vfx_particle_phase
* (travel_distance / cursor_dimensions.y);
Point::new(phase.sin(), phase.cos()) * 2.0 * settings.vfx_particle_speed
}
TrailMode::Torpedo => {
let mut travel_dir = travel;
travel_dir.normalize();
let mut particle_dir =
self.rng.rand_dir_normalized() - travel_dir * 1.5;
particle_dir.normalize();
particle_dir * settings.vfx_particle_speed
}
TrailMode::PixieDust => {
let base_dir = self.rng.rand_dir_normalized();
let dir = Point::new(base_dir.x * 0.5, 0.4 + base_dir.y.abs());
dir * 3.0 * settings.vfx_particle_speed
}
};

// Distribute particles along the travel distance
let pos = match self.trail_mode {
TrailMode::Railgun => prev_p + travel * t,
TrailMode::PixieDust | TrailMode::Torpedo => {
prev_p
+ travel * self.rng.next_f32()
+ Point::new(0.0, cursor_dimensions.y * 0.5)
}
};

let rotation_speed = match self.trail_mode {
TrailMode::Railgun => std::f32::consts::PI * settings.vfx_particle_curl,
TrailMode::PixieDust | TrailMode::Torpedo => {
(self.rng.next_f32() - 0.5)
* std::f32::consts::FRAC_PI_2
* settings.vfx_particle_curl
}
};

self.add_particle(
pos,
speed,
rotation_speed,
t * settings.vfx_particle_lifetime,
);
}
}

self.previous_cursor_dest = current_cursor_dest;
Expand Down
13 changes: 9 additions & 4 deletions src/renderer/cursor_renderer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,9 @@ impl CursorRenderer {
let mut animating = false;

if !center_destination.is_zero() {
let immediate_movement = !settings.animate_in_insert_mode && in_insert_mode
|| !settings.animate_command_line && !changed_to_from_cmdline;
for corner in self.corners.iter_mut() {
let immediate_movement = !settings.animate_in_insert_mode && in_insert_mode
|| !settings.animate_command_line && !changed_to_from_cmdline;

let corner_animating = corner.update(
&settings,
cursor_dimensions,
Expand All @@ -400,7 +399,13 @@ impl CursorRenderer {
}

let vfx_animating = if let Some(vfx) = self.cursor_vfx.as_mut() {
vfx.update(&settings, center_destination, cursor_dimensions, dt)
vfx.update(
&settings,
center_destination,
cursor_dimensions,
immediate_movement,
dt,
)
} else {
false
};
Expand Down