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, } 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); } }