summaryrefslogtreecommitdiffstats
path: root/src/imports/particles/particle.cpp
blob: 175e3dfe0324af2a75b5dcebece3fc7ca8cfc6e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "particle.h"
#include <QDebug>
QT_BEGIN_NAMESPACE
ParticleType::ParticleType(QSGItem *parent) :
    QSGItem(parent),
    m_system(0)
{
    connect(this, SIGNAL(xChanged()),
            this, SLOT(calcSystemOffset()));
    connect(this, SIGNAL(yChanged()),
            this, SLOT(calcSystemOffset()));
}

void ParticleType::setSystem(ParticleSystem *arg)
{
    if (m_system != arg) {
        m_system = arg;
        if(m_system){
            m_system->registerParticleType(this);
            connect(m_system, SIGNAL(xChanged()),
                    this, SLOT(calcSystemOffset()));
            connect(m_system, SIGNAL(yChanged()),
                    this, SLOT(calcSystemOffset()));
            calcSystemOffset();
        }
        emit systemChanged(arg);
    }
}

void ParticleType::load(ParticleData*)
{
}

void ParticleType::reload(ParticleData*)
{
}

void ParticleType::setCount(int c)
{
    if(c == m_count)
        return;
    m_count = c;
    emit countChanged();
}

int ParticleType::count()
{
    return m_count;
}


int ParticleType::particleTypeIndex(ParticleData* d)
{
    if(!m_particleStarts.contains(d->group)){
        m_particleStarts.insert(d->group, m_lastStart);
        m_lastStart += m_system->m_groupData[d->group]->size;
    }
    return m_particleStarts[d->group] + d->particleIndex;
}


void ParticleType::calcSystemOffset()
{
    if(!m_system)
        return;
    QPointF lastOffset = m_systemOffset;
    m_systemOffset = this->mapFromItem(m_system, QPointF());
    if(lastOffset != m_systemOffset){
        //Reload all particles
        foreach(const QString &g, m_particles){
            int gId = m_system->m_groupIds[g];
            for(int i=0; i<m_system->m_groupData[gId]->size; i++)
                reload(m_system->m_data[m_system->m_groupData[gId]->start + i]);
        }
    }
}
QT_END_NAMESPACE