Skip to content

Commit 0ebbbed

Browse files
committed
Change api
1 parent bf4116f commit 0ebbbed

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

examples/1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ fn main() -> Result<(), String> {
5757
.with_effect(lib::ParticleEffect::LinearMovement{velocity_x:random_velocity_x,velocity_y: -200.0})
5858
.build();
5959

60-
particles_state.emit(5, emitting_type, 400.0, 300.0);
60+
particles_state.emit(5, &emitting_type, 400.0, 300.0);
6161
particles_state.update(dt);
6262

6363
canvas.set_draw_color(Color::RGB(0, 128, 255));

examples/2.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn main() -> Result<(), String> {
5959
.with_effect(lib::ParticleEffect::FadeOut{delay: Duration::from_secs_f32(1.0)})
6060
.build();
6161

62-
particles_state.emit(5, emitting_type, 400.0, 600.0);
62+
particles_state.emit(5, &emitting_type, 400.0, 600.0);
6363
particles_state.update(dt);
6464

6565
canvas.set_draw_color(Color::RGB(0, 128, 255));

src/lib.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ParticlesState {
3333
pub fn emit(
3434
self: &mut Self,
3535
emitting_count: u32,
36-
emitting_type: ParticleType,
36+
emitting_type: &ParticleType,
3737
pos_x: f32,
3838
pos_y: f32,
3939
) {
@@ -117,6 +117,8 @@ pub struct ParticlesState {
117117
pool: Vec<Particle>,
118118
emitting_index: usize,
119119
}
120+
121+
#[derive(Clone)]
120122
struct Particle {
121123
pos_x: f32,
122124
pos_y: f32,
@@ -152,13 +154,16 @@ impl Particle {
152154
}
153155
}
154156

157+
#[derive(Clone)]
155158
pub struct ParticleType {
156159
effects: Vec<ParticleEffect>,
157160
lifetime: f32,
158161
size_x: u32,
159162
size_y: u32,
160163
color: Color,
161164
}
165+
166+
#[derive(Clone, Copy)]
162167
pub enum ParticleEffect {
163168
ConstantRotation{angle:f32},
164169
LinearMovement{velocity_x:f32, velocity_y:f32},
@@ -238,7 +243,7 @@ mod tests {
238243
let ptype = crate::ParticleTypeBuilder::new(16, 16, Duration::from_secs(4))
239244
.with_effect(crate::ParticleEffect::LinearMovement{velocity_x:5.0, velocity_y:4.0})
240245
.build();
241-
particles_state.emit(4, ptype, 0.0, 0.0);
246+
particles_state.emit(4, &ptype, 0.0, 0.0);
242247
particles_state.update(Duration::from_secs(2));
243248
let last = particles_state.pool.get_mut(3).unwrap();
244249
assert_eq!(last.pos_x, 10.0);
@@ -253,7 +258,7 @@ mod tests {
253258
let ptype = crate::ParticleTypeBuilder::new(16, 16, Duration::from_secs(4))
254259
.with_effect(crate::ParticleEffect::FadeOut{delay: Duration::from_secs_f32(2.0)})
255260
.build();
256-
particles_state.emit(4, ptype, 0.0, 0.0);
261+
particles_state.emit(4, &ptype, 0.0, 0.0);
257262
{
258263
let last = particles_state.pool.get_mut(3).unwrap();
259264
assert_eq!(last.alpha, 255.0);

0 commit comments

Comments
 (0)