| 1 | // This file is part of Dust Racing 2D. |
| 2 | // Copyright (C) 2015 Jussi Lind <[email protected]> |
| 3 | // |
| 4 | // Dust Racing 2D is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // Dust Racing 2D is distributed in the hope that it will be useful, |
| 9 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | // GNU General Public License for more details. |
| 12 | // |
| 13 | // You should have received a copy of the GNU General Public License |
| 14 | // along with Dust Racing 2D. If not, see <http://www.gnu.org/licenses/>. |
| 15 | |
| 16 | #ifndef PARTICLEFACTORY_HPP |
| 17 | #define PARTICLEFACTORY_HPP |
| 18 | |
| 19 | #include <MCParticle> |
| 20 | #include <MCParticleRendererBase> |
| 21 | |
| 22 | #include <MCVector3d> |
| 23 | |
| 24 | #include <memory> |
| 25 | #include <vector> |
| 26 | |
| 27 | class MCSurfaceParticle; |
| 28 | |
| 29 | //! ParticleFactory takes care of spawning and recycling particles. |
| 30 | class ParticleFactory |
| 31 | { |
| 32 | public: |
| 33 | enum ParticleType |
| 34 | { |
| 35 | DamageSmoke = 0, |
| 36 | SkidSmoke, |
| 37 | Smoke, |
| 38 | OffTrackSmoke, |
| 39 | OnTrackSkidMark, |
| 40 | OffTrackSkidMark, |
| 41 | Sparkle, |
| 42 | Mud, |
| 43 | Leaf, |
| 44 | NumParticleTypes |
| 45 | }; |
| 46 | |
| 47 | //! Constructor. |
| 48 | ParticleFactory(); |
| 49 | |
| 50 | //! Destructor. |
| 51 | ~ParticleFactory(); |
| 52 | |
| 53 | static ParticleFactory & instance(); |
| 54 | |
| 55 | void doParticle( |
| 56 | ParticleType type, |
| 57 | MCVector3dFR location, |
| 58 | MCVector3dFR initialVelocity = MCVector3dF(0, 0, 0), |
| 59 | int angle = 0); |
| 60 | |
| 61 | private: |
| 62 | void doDamageSmoke(MCVector3dFR location, MCVector3dFR velocity) const; |
| 63 | |
| 64 | void doSkidSmoke(MCVector3dFR location, MCVector3dFR velocity) const; |
| 65 | |
| 66 | void doSmoke(MCVector3dFR location, MCVector3dFR velocity) const; |
| 67 | |
| 68 | void doOffTrackSmoke(MCVector3dFR location) const; |
| 69 | |
| 70 | void doOnTrackSkidMark(MCVector3dFR location, int angle) const; |
| 71 | |
| 72 | void doOffTrackSkidMark(MCVector3dFR location, int angle) const; |
| 73 | |
| 74 | void doSparkle(MCVector3dFR location, MCVector3dFR velocity) const; |
| 75 | |
| 76 | void doMud(MCVector3dFR location, MCVector3dFR velocity) const; |
| 77 | |
| 78 | void doLeaf(MCVector3dFR location, MCVector3dFR velocity) const; |
| 79 | |
| 80 | void preCreateParticles(); |
| 81 | |
| 82 | void preCreateSurfaceParticles(size_t count, std::string typeId, ParticleType typeEnum, MCSurfacePtr surface, bool alphaBlend = false, bool hasShadow = false); |
| 83 | |
| 84 | MCSurfaceParticle * newSurfaceParticle(ParticleType typeEnum) const; |
| 85 | |
| 86 | // Free lists (recycling) for different types of particles. |
| 87 | mutable MCParticle::ParticleFreeList m_freeLists[NumParticleTypes]; |
| 88 | |
| 89 | // Renderers for different particle types. |
| 90 | MCParticleRendererPtr m_particleRenderers[NumParticleTypes]; |
| 91 | |
| 92 | // Particles to delete. |
| 93 | std::vector<std::unique_ptr<MCParticle>> m_delete; |
| 94 | |
| 95 | static ParticleFactory * m_instance; |
| 96 | }; |
| 97 | |
| 98 | #endif // PARTICLEFACTORY_HPP |