Skip to content

Commit

Permalink
resolved conflicts between force field and main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
eliotbo committed Apr 6, 2022
1 parent d839894 commit 1410134
Show file tree
Hide file tree
Showing 6 changed files with 377 additions and 69 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ exclude = ["examples/*.gif", ".github"]
[dependencies]
bytemuck = "1.5"
rand = "0.8"
rand_pcg = "0.3"
serde = { version = "1.0", features = ["derive"] }
anyhow = "1.0"
ron = "0.7"
Expand Down
2 changes: 1 addition & 1 deletion examples/force_field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn setup(
}
.init(PositionSphereModifier {
radius: BALL_RADIUS,
speed: 0.2,
speed: Value::Uniform((0.1, 0.3)),
dimension: ShapeDimension::Surface,
..Default::default()
})
Expand Down
13 changes: 13 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ impl ToWgslString for Vec4 {
}
}

impl ToWgslString for Value<f32> {
fn to_wgsl_string(&self) -> String {
match self {
Self::Single(x) => x.to_wgsl_string(),
Self::Uniform((a, b)) => format!(
"rand() * ({1} - {0}) + {0}",
a.to_wgsl_string(),
b.to_wgsl_string(),
),
}
}
}

/// Visual effect made of particles.
///
/// The particle effect component represent a single instance of a visual effect. The
Expand Down
42 changes: 3 additions & 39 deletions src/modifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use bevy::prelude::*;
use crate::{
asset::{InitLayout, RenderLayout, UpdateLayout},
gradient::Gradient,
// render::FFNUM,
ToWgslString,
ToWgslString, Value,
};

/// Maximum number of components in the force field.
Expand Down Expand Up @@ -54,7 +53,7 @@ pub struct PositionCircleModifier {
/// The circle radius.
pub radius: f32,
/// The radial speed of the particles on spawn.
pub speed: f32,
pub speed: Value<f32>,
/// The shape dimension to spawn from.
pub dimension: ShapeDimension,
}
Expand Down Expand Up @@ -125,7 +124,7 @@ pub struct PositionSphereModifier {
/// The sphere radius.
pub radius: f32,
/// The radial speed of the particles on spawn.
pub speed: f32,
pub speed: Value<f32>,
/// The shape dimension to spawn from.
pub dimension: ShapeDimension,
}
Expand Down Expand Up @@ -231,41 +230,6 @@ impl UpdateModifier for AccelModifier {
}
}

// /// The [`ForceFieldParam`] allows for an either an attractive or a repulsive force originating
// /// from a point source.
// #[derive(Clone, Copy, PartialEq)]
// pub enum ForceType {
// /// Linear attractive or repulsive force.
// Linear,

// /// Quadratic attractive or repulsive force.
// Quadratic,

// /// Cubic attractive or repulsive force.
// Cubic,

// /// None is the default. No force field is applied.
// None,
// }

// impl Default for ForceType {
// fn default() -> Self {
// ForceType::None
// }
// }

// impl ForceType {
// /// Converts the instance of ForceType into an integer, preparing to be sent to the GPU.
// pub fn to_int(self) -> i32 {
// match self {
// ForceType::Linear => 1,
// ForceType::Quadratic => 2,
// ForceType::Cubic => 3,
// ForceType::None => -1,
// }
// }
// }

/// Parameters for the components making the force field.
#[derive(Clone, Copy)]
pub struct ForceFieldParam {
Expand Down
4 changes: 3 additions & 1 deletion src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use std::{borrow::Cow, cmp::Ordering, num::NonZeroU64, ops::Range};
use crate::{
asset::EffectAsset,
modifiers::{ForceFieldParam, FFNUM},
spawn::{new_rng, Random},
Gradient, ParticleEffect, ToWgslString,
};

Expand Down Expand Up @@ -776,7 +777,8 @@ pub(crate) fn extract_effects(

// Tick the effect's spawner to determine the spawn count for this frame
let spawner = effect.spawner(&asset.spawner);
let spawn_count = spawner.tick(dt);
let rng = &mut new_rng();
let spawn_count = spawner.tick(dt, rng);

// Extract the acceleration
let accel = asset.update_layout.accel;
Expand Down
Loading

0 comments on commit 1410134

Please sign in to comment.