-
Notifications
You must be signed in to change notification settings - Fork 0
/
ParticleManager.pde
47 lines (38 loc) · 1.03 KB
/
ParticleManager.pde
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
class ParticleManager {
List<Particle> particles;
List<Particle> addParticles;
List<Particle> remParticles;
ParticleManager() {
this.particles = new ArrayList<Particle>();
this.addParticles = new ArrayList<Particle>();
this.remParticles = new ArrayList<Particle>();
}
void add(Particle particle) {
this.addParticles.add(particle);
}
void remove(Particle particle) {
this.remParticles.add(particle);
}
int getCount() {
return this.particles.size();
}
void OnTick() {
this.particles.addAll(this.addParticles);
this.addParticles.clear();
this.particles.removeAll(this.remParticles);
this.remParticles.clear();
for (Particle particle : this.particles) {
particle.OnTick();
}
}
void OnDraw(Camera camera) {
List<Particle> particlesSnapshot;
synchronized (this.particles) {
particlesSnapshot = new ArrayList<Particle>(this.particles);
}
for (Particle particle : particlesSnapshot) {
if (particle == null || !camera.getIsNodeVisible(particle)) continue;
particle.OnDrawInternal();
}
}
}