//
// Created by sfd on 25-5-21.
//

#ifndef PARTICLESYSTEM_H
#define PARTICLESYSTEM_H

#include <Hazel.h>
#include <glad/glad.h>

struct ParticleProp
{
    glm::vec2 Position;
    glm::vec2 Velocity, VelocityVariation;
    glm::vec4 ColorBegin, ColorEnd;
    float SizeBegin, SizeEnd, SizeVariation;
    float LifeTime = 1.0f;
};

class ParticleSystem
{
public:
    ParticleSystem();

    void OnUpdate(Hazel::TimeStep& ts);
    void OnRender(Hazel::OrthographicCamera& camera);

    void Emit(const ParticleProp& particuleProps);

private:
    struct Particle
    {
        glm::vec2 Position;
        glm::vec2 Velocity;
        glm::vec4 ColorBegin, ColorEnd;
        float Rotation = 0.0f;
        float SizeBegin, SizeEnd;

        float LifeTime = 1.0f;
        float LifeRemaing = 0.0f;

        bool Active = false;
    };

    std::vector<Particle>               m_particlePool;
    uint32_t                            m_PoolIndex =  1000;
};


#endif //PARTICLESYSTEM_H
