<commit_before>#include "particles.h"

#include "utils.h"
#include <iostream>

namespace vot
{
    // Particle {{{
    Particle::Particle() :
        _lifetime(0.0f),
        _total_lifetime(1.0f),
        _active(true),
        _init_scale(1.0f),
        _target_scale(1.0f)
    {

    }

    void Particle::texture(const sf::Texture &texture)
    {
        auto size = texture.getSize();
        setOrigin(size.x * 0.5f, size.y * 0.5f);
        setTexture(texture);
    }

    void Particle::update(float dt)
    {
        if (!_active)
        {
            return;
        }

        _lifetime += dt;
        if (_lifetime < 0.0f)
        {
            return;
        }

        auto dl = _lifetime / _total_lifetime;
        auto position = Utils::lerp(_init_position, _target_position, dl);  
        setPosition(position);
        auto scale = Utils::para_lerp(_init_scale, _target_scale, dl);
        setScale(scale, scale);

        if (_lifetime > _total_lifetime)
        {
            _active = false;
        }
    }

    void Particle::reset()
    {
        _lifetime = 0.0f;
        _active = true;
    }

    void Particle::active(bool value)
    {
        _active = value;
    }
    bool Particle::active() const
    {
        return _active;
    }

    void Particle::lifetime(float value)
    {
        _lifetime = value;
    }
    float Particle::lifetime() const
    {
        return _lifetime;
    }

    void Particle::total_lifetime(float value)
    {
        _total_lifetime = value;
    }
    float Particle::total_lifetime() const
    {
        return _total_lifetime;
    }

    void Particle::scales(float init, float target)
    {
        _init_scale = init;
        _target_scale = target;
    }
    void Particle::positions(const sf::Vector2f &init, const sf::Vector2f &target)
    {
        _init_position = init;
        _target_position = target;
    }
    // }}}

    // ParticleSystem {{{
    ParticleSystem::ParticleSystem(const sf::Texture &texture, uint32_t num_particles) :
        sf::Drawable(),
        sf::Transformable(),
        _texture(texture),
        _particles(num_particles),
        _loop_system(false),
        _system_type(0u)
    {
    }

    void ParticleSystem::init()
    {
        for (auto i = 0u; i < _particles.size(); i++)
        {
            _particles[i] = Particle();
            init_particle(_particles[i]);
        }
    }

    void ParticleSystem::system_type(uint32_t value)
    {
        _system_type = value;
    }
    uint32_t ParticleSystem::system_type() const
    {
        return _system_type;
    }

    void ParticleSystem::loop_system(bool value)
    {
        _loop_system = value;
    }
    bool ParticleSystem::loop_system() const
    {
        return _loop_system;
    }

    bool ParticleSystem::update(float dt)
    {
        auto active = 0u;
        for (auto i = 0u; i < _particles.size(); i++)
        {
            auto &particle = _particles[i]; 
            particle.update(dt);
            if (_loop_system && !particle.active())
            {
                particle.reset();
                init_particle(particle);
            }
            else
            {
                ++active;
            }
        }
        return active > 0u;
    }

    void ParticleSystem::draw(sf::RenderTarget &target, sf::RenderStates states) const
    {
        states.transform *= getTransform();

        for (auto particle : _particles)<commit_msg>- Fixed non looping particle systems not ending.<commit_after>#include "particles.h"

#include "utils.h"
#include <iostream>

namespace vot
{
    // Particle {{{
    Particle::Particle() :
        _lifetime(0.0f),
        _total_lifetime(1.0f),
        _active(true),
        _init_scale(1.0f),
        _target_scale(1.0f)
    {

    }

    void Particle::texture(const sf::Texture &texture)
    {
        auto size = texture.getSize();
        setOrigin(size.x * 0.5f, size.y * 0.5f);
        setTexture(texture);
    }

    void Particle::update(float dt)
    {
        if (!_active)
        {
            return;
        }

        _lifetime += dt;
        if (_lifetime < 0.0f)
        {
            return;
        }

        auto dl = _lifetime / _total_lifetime;
        auto position = Utils::lerp(_init_position, _target_position, dl);  
        setPosition(position);
        auto scale = Utils::para_lerp(_init_scale, _target_scale, dl);
        setScale(scale, scale);

        if (_lifetime > _total_lifetime)
        {
            _active = false;
        }
    }

    void Particle::reset()
    {
        _lifetime = 0.0f;
        _active = true;
    }

    void Particle::active(bool value)
    {
        _active = value;
    }
    bool Particle::active() const
    {
        return _active;
    }

    void Particle::lifetime(float value)
    {
        _lifetime = value;
    }
    float Particle::lifetime() const
    {
        return _lifetime;
    }

    void Particle::total_lifetime(float value)
    {
        _total_lifetime = value;
    }
    float Particle::total_lifetime() const
    {
        return _total_lifetime;
    }

    void Particle::scales(float init, float target)
    {
        _init_scale = init;
        _target_scale = target;
    }
    void Particle::positions(const sf::Vector2f &init, const sf::Vector2f &target)
    {
        _init_position = init;
        _target_position = target;
    }
    // }}}

    // ParticleSystem {{{
    ParticleSystem::ParticleSystem(const sf::Texture &texture, uint32_t num_particles) :
        sf::Drawable(),
        sf::Transformable(),
        _texture(texture),
        _particles(num_particles),
        _loop_system(false),
        _system_type(0u)
    {
    }

    void ParticleSystem::init()
    {
        for (auto i = 0u; i < _particles.size(); i++)
        {
            _particles[i] = Particle();
            init_particle(_particles[i]);
        }
    }

    void ParticleSystem::system_type(uint32_t value)
    {
        _system_type = value;
    }
    uint32_t ParticleSystem::system_type() const
    {
        return _system_type;
    }

    void ParticleSystem::loop_system(bool value)
    {
        _loop_system = value;
    }
    bool ParticleSystem::loop_system() const
    {
        return _loop_system;
    }

    bool ParticleSystem::update(float dt)
    {
        auto active = 0u;
        for (auto i = 0u; i < _particles.size(); i++)
        {
            auto &particle = _particles[i]; 
            particle.update(dt);
            if (!particle.active())
            {
                if (_loop_system)
                {
                    particle.reset();
                    init_particle(particle);
                }
            }
            else
            {
                ++active;
            }
        }
        return active > 0u;
    }

    void ParticleSystem::draw(sf::RenderTarget &target, sf::RenderStates states) const
    {
        states.transform *= getTransform();

        for (auto particle : _particles)
{'fraction_non_alphanumeric': 0.1115092446610291, 'fraction_numerical': 0.008313028522287515, 'mean_word_length': 1.7494089834515367, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2311005', 'n_tokens_mistral': 2230, 'n_tokens_neox': 2145, 'n_words': 407}