VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
ParticleEmitterLogic.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef PARTICLEEMITTERLOGIC_H
18 #define PARTICLEEMITTERLOGIC_H
19 
20 #include <Engine/particles/WaterParticleSet.h>
21 #include "EmitterLogic.h"
22 
29  Q_OBJECT
30 
34  Q_PROPERTY(QColor color READ getColor WRITE setColor NOTIFY colorChanged)
38  Q_PROPERTY(float pauseDistance READ getPauseDistance WRITE setPauseDistance
43  Q_PROPERTY(ParticleLayer* layer READ getLayer WRITE setLayer NOTIFY layerChanged)
44 
45 public:
49  QColor getColor() const { return mColor; }
54  void setColor(const QColor& color);
58  float getPauseDistance() const { return mPauseDistance; }
63  void setPauseDistance(float value);
67  ParticleLayer* getLayer() const { return mLayer; }
72  void setLayer(ParticleLayer* value);
73 
74  virtual int getEntityCount() const override { return mParticles.getParticleCount(); }
79  virtual void update() override;
80 
81 signals:
85  void colorChanged();
89  void pauseDistanceChanged();
93  void layerChanged();
94 
95 protected:
99  WaterParticleSet& getWaterParticleSet() { return mParticles; }
104  virtual void emitEntity(const SpawnParameters& parameters) override;
108  virtual void onPausedChanged() override;
112  virtual QRectF getEmitterWorldBounds();
113 
114 private:
115  QColor mColor = QColor(0x76A8FF);
116  float mPauseDistance = 8.0f;
117  WaterParticleSet mParticles;
118  ParticleLayer* mLayer = nullptr;
119 };
120 Q_DECLARE_METATYPE(ParticleEmitterLogic*)
121 
122 #endif // PARTICLEEMITTERLOGIC_H
void setColor(const QColor &color)
Sets color.
QColor color
Color of spawned particles.
Definition: ParticleEmitterLogic.h:34
virtual QRectF getEmitterWorldBounds()
Returns the bounding box of this emitter in world coordinates.
virtual void onPausedChanged() override
Empties the internal WaterParticleSet when the emitter is paused.
void colorChanged()
Emitted when color changes.
ParticleLayer * getLayer() const
Returns layer.
Definition: ParticleEmitterLogic.h:67
void pauseDistanceChanged()
Emitted when pauseDistance changes.
void setPauseDistance(float value)
Sets pauseDistance.
A collection of WaterParticles which can perform updates each frame.
Definition: WaterParticleSet.h:31
float getPauseDistance() const
Returns pauseDistance.
Definition: ParticleEmitterLogic.h:58
Spawns WaterParticles into the world (i.e. an unbounded WaterParticleSet).
Definition: ParticleEmitterLogic.h:28
float pauseDistance
Distance units from viewport edge to automatically pause the emitter.
Definition: ParticleEmitterLogic.h:39
void setLayer(ParticleLayer *value)
Sets layer.
virtual int getEntityCount() const override
Returns entityCount.
Definition: ParticleEmitterLogic.h:74
ParticleLayer layer
Layer to spawn particles on.
Definition: ParticleEmitterLogic.h:43
int getParticleCount() const
Returns the number of WaterParticles in this set.
Definition: WaterParticleSet.h:42
void layerChanged()
Emitted when layer changes.
virtual void emitEntity(const SpawnParameters &parameters) override
Spawns a new WaterParticle into an internal WaterParticleSet.
QColor getColor() const
Returns color.
Definition: ParticleEmitterLogic.h:49
Abstract base class to spawn generic entities into the Game based on configurable parameters...
Definition: EmitterLogic.h:35
Wrapper around a b2ParticleSystem, which represents an independent layer of particles.
Definition: ParticleLayer.h:32
virtual void update() override
Pauses the emitter if necessary and updates the internal WaterParticleSet into which particles are sp...
WaterParticleSet & getWaterParticleSet()
Returns the backing WaterParticleSet.
Definition: ParticleEmitterLogic.h:99