#pragma once

#include <string>
#include <vector>
#include <mutex>
#include "parameters.h"
#include <common.h>
#include <render/sprite/atlas.h>

namespace render{
namespace fx{

    class collection;
    class object;
    class objectInfo;
    class effect;
    class effectInfo;

    class emitter;
    class particlesSpawner;
    class particlesSpawnerRect;
    class particlesSpawnerRound;
    class particlesSpawnerRing;

    struct particle
    {
        vec2f vert;
        vec2f scale;
        float angle;
        vec4f tex;
        vec4f tex2;
        float blend;
        vec3f color;
        float alpha;
    };

    struct particleData
    {
        _listParam<vec3f> color;
        _listParam<float> alpha;
        _listParam<vec2f> scale;
        _listParam<float> speed;
        _listParam<float> angle;
        _textureAnimation textureAnimation;
        vec2f pos;
        vec2f direction;
        float lifeTime, timer;
        vec4f *texCoord;
    };

    struct textureAtlasInfo
    {
        render::sprite::textureAtlas atlas;
        std::string id;
    };

    struct textureAnimationInfo
    {
        float time;
        std::vector<uint32_t> nodes;
    };

    struct emissionParam
    {
        _loopedParam<vec2f> lifeTime;
        _loopedParam<float> emission;
        _loopedParam<vec2f> direction;
        particlesSpawner *spawner;
    };

    struct particlesParam
    {
        _emitterParam<float> angle;
        _emitterParam<float> speed;
        _emitterParam<float> alpha;
        _emitterParam<vec2f> scale;
        _emitterParam<vec3f> color;
        std::vector<textureIndexParam> texAnim;
    };

    struct particlesUpdateInfo
    {
        std::mutex *locker;
        uint32_t *drawCount;
        std::vector<particleData> *data;
        std::vector<particle> *rdata;

        emissionParam *emission;
        particlesParam *particles;

        const vec4f *texNodes;
        float *time, *oldTime, *spawnCount, ctime;
        vec2f pos, *oldPos;
        float workTime;
        bool *updated, looped, running;

        ///=======particles spawn values
        float life;
        float direction;
        vec2f position;
        float delta;

        size_t size;
        particle *rdataPtr;
        particleData *dataPtr;
    };
}}
