| 76 | } |
| 77 | |
| 78 | void CParticles::Update(float TimePassed) |
| 79 | { |
| 80 | if(TimePassed <= 0.0f) |
| 81 | return; |
| 82 | |
| 83 | m_FrictionFraction += TimePassed; |
| 84 | |
| 85 | if(m_FrictionFraction > 2.0f) // safety measure |
| 86 | m_FrictionFraction = 0; |
| 87 | |
| 88 | int FrictionCount = 0; |
| 89 | while(m_FrictionFraction > 0.05f) |
| 90 | { |
| 91 | FrictionCount++; |
| 92 | m_FrictionFraction -= 0.05f; |
| 93 | } |
| 94 | |
| 95 | for(int &FirstPart : m_aFirstPart) |
| 96 | { |
| 97 | int i = FirstPart; |
| 98 | while(i != -1) |
| 99 | { |
| 100 | int Next = m_aParticles[i].m_NextPart; |
| 101 | m_aParticles[i].m_Vel.y += m_aParticles[i].m_Gravity * TimePassed; |
| 102 | |
| 103 | for(int f = 0; f < FrictionCount; f++) // apply friction |
| 104 | m_aParticles[i].m_Vel *= m_aParticles[i].m_Friction; |
| 105 | |
| 106 | // move the point |
| 107 | vec2 Vel = m_aParticles[i].m_Vel * TimePassed; |
| 108 | if(m_aParticles[i].m_Collides) |
| 109 | { |
| 110 | Collision()->MovePoint(&m_aParticles[i].m_Pos, &Vel, random_float(0.1f, 1.0f), nullptr); |
| 111 | } |
| 112 | else |
| 113 | { |
| 114 | m_aParticles[i].m_Pos += Vel; |
| 115 | } |
| 116 | m_aParticles[i].m_Vel = Vel * (1.0f / TimePassed); |
| 117 | |
| 118 | m_aParticles[i].m_Life += TimePassed; |
| 119 | m_aParticles[i].m_Rot += TimePassed * m_aParticles[i].m_Rotspeed; |
| 120 | |
| 121 | // check particle death |
| 122 | if(m_aParticles[i].m_Life > m_aParticles[i].m_LifeSpan) |
| 123 | { |
| 124 | // remove it from the group list |
| 125 | if(m_aParticles[i].m_PrevPart != -1) |
| 126 | m_aParticles[m_aParticles[i].m_PrevPart].m_NextPart = m_aParticles[i].m_NextPart; |
| 127 | else |
| 128 | FirstPart = m_aParticles[i].m_NextPart; |
| 129 | |
| 130 | if(m_aParticles[i].m_NextPart != -1) |
| 131 | m_aParticles[m_aParticles[i].m_NextPart].m_PrevPart = m_aParticles[i].m_PrevPart; |
| 132 | |
| 133 | // insert to the free list |
| 134 | if(m_FirstFree != -1) |
| 135 | m_aParticles[m_FirstFree].m_PrevPart = i; |
nothing calls this directly
no test coverage detected