1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
use glam::Vec2;
use crate::content::vfx::VfxMaterialId;
pub struct VfxLine {
pub a: Vec2,
pub b: Vec2,
pub width: f32,
pub material: VfxMaterialId,
pub alive_for: f32,
pub lifetime: f32,
}
impl VfxLine {
pub fn new(a: Vec2, b: Vec2, width: f32, material: VfxMaterialId, lifetime: f32) -> Self {
VfxLine {
a,
b,
width,
material,
alive_for: 0.0,
lifetime,
}
}
}
pub trait VfxWriter {
fn write_vfx_line(&mut self, line: VfxLine) -> ();
}
pub struct VfxManager {
pub lines: Vec<VfxLine>,
}
impl VfxManager {
pub fn after_render(&mut self, delta_time: f32) {
let mut i = 0;
while i < self.lines.len() {
let l = &mut self.lines[i];
l.alive_for += delta_time;
if l.alive_for > l.lifetime {
self.lines.swap_remove(i);
continue;
}
i += 1;
}
}
pub fn new() -> Self {
VfxManager { lines: Vec::new() }
}
}
impl VfxWriter for VfxManager {
fn write_vfx_line(&mut self, line: VfxLine) -> () {
self.lines.push(line);
}
}
|