package main 

import rl "vendor:raylib"
import "core:math/ease"
import "core:slice"

Trail :: struct {
    pos : vec3,
    lifetime: f32,
    time: f32,
    max_size: f32,
    color: rl.Color,
}
trails_buf := [1024]Trail{}
trails : [dynamic]Trail


trail :: proc(pos: vec3, max_size, lifetime: f32, color: rl.Color = rl.WHITE) {
    append(&trails, Trail{
        pos = pos,
        lifetime = lifetime,
        max_size = max_size,
        color = color
    })
}

trail_init :: proc() {
    trails = slice.into_dynamic(trails_buf[:])
}

trail_update :: proc(delta: f32) {
    #reverse for &t, i in trails {
        t.time += delta
        if t.time >= t.lifetime {unordered_remove(&trails, i)}
    }
}

trail_draw :: proc() {
    // rl.BeginBlendMode(rl.BlendMode.ADD_COLORS)
    for t in trails {
        d := t.time / t.lifetime
        step1 := ease.ease(ease.Ease.Back_Out, d)
        step2 := ease.ease(ease.Ease.Cubic_In_Out, 1 - d)
        size := step1 * step2
        // alpha := ease.ease(ease.Ease.Cubic_Out, d)
        rl.DrawSphereEx(t.pos, size, 5, 4, t.color)
    }
    // rl.EndBlendMode()
}