SuperTuxKart
Loading...
Searching...
No Matches
cpu_particle_manager.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2017 SuperTuxKart-Team
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18#ifndef HEADER_CPU_PARTICLE_MANAGER_HPP
19#define HEADER_CPU_PARTICLE_MANAGER_HPP
20
21#ifndef SERVER_ONLY
22
23#include "graphics/gl_headers.hpp"
24#include "utils/constants.hpp"
25#include "mini_glm.hpp"
26#include "utils/no_copy.hpp"
27#include "utils/singleton.hpp"
28
29#include <dimension2d.h>
30#include <IBillboardSceneNode.h>
31#include <vector3d.h>
32#include <SColor.h>
33
34#include <cassert>
35#include <string>
36#include <memory>
37#include <unordered_map>
38#include <unordered_set>
39#include <vector>
40
41using namespace irr;
42
44{
45 core::vector3df m_position;
46 video::SColor m_color_lifetime;
47 short m_size[2];
48 // ------------------------------------------------------------------------
49 CPUParticle(const core::vector3df& position,
50 const core::vector3df& color_from,
51 const core::vector3df& color_to, float lf_time, float size);
52 // ------------------------------------------------------------------------
53 CPUParticle(scene::IBillboardSceneNode* node);
54};
55
56
57class STKParticle;
58class Material;
59
60class CPUParticleManager : public Singleton<CPUParticleManager>, NoCopy
61{
62private:
63 struct GLParticle : public NoCopy
64 {
65 GLuint m_vao;
66 GLuint m_vbo;
67 unsigned m_size;
68 // --------------------------------------------------------------------
69 GLParticle(bool flips);
70 // --------------------------------------------------------------------
72 {
73 glDeleteVertexArrays(1, &m_vao);
74 glDeleteBuffers(1, &m_vbo);
75 }
76 };
77
78 std::unordered_map<std::string, std::vector<STKParticle*> >
79 m_particles_queue;
80
81 std::unordered_map<std::string, std::vector<scene::IBillboardSceneNode*> >
82 m_billboards_queue;
83
84 std::unordered_map<std::string, std::vector<CPUParticle> >
85 m_particles_generated;
86
87 std::unordered_map<std::string, std::unique_ptr<GLParticle> >
88 m_gl_particles;
89
90 std::unordered_map<std::string, Material*> m_material_map;
91
92 std::unordered_set<std::string> m_flips_material, m_sky_material;
93
94 static GLuint m_particle_quad;
95
96 // ------------------------------------------------------------------------
97 bool isFlipsMaterial(const std::string& name)
98 { return m_flips_material.find(name) != m_flips_material.end(); }
99
100public:
101 // ------------------------------------------------------------------------
103 // ------------------------------------------------------------------------
105 {
106 glDeleteBuffers(1, &m_particle_quad);
107 m_particle_quad = 0;
108 }
109 // ------------------------------------------------------------------------
110 void addParticleNode(STKParticle* node);
111 // ------------------------------------------------------------------------
112 void addBillboardNode(scene::IBillboardSceneNode* node);
113 // ------------------------------------------------------------------------
114 void generateAll();
115 // ------------------------------------------------------------------------
116 void uploadAll();
117 // ------------------------------------------------------------------------
118 void drawAll();
119 // ------------------------------------------------------------------------
120 void reset()
121 {
122 for (auto& p : m_particles_queue)
123 {
124 p.second.clear();
125 }
126 for (auto& p : m_billboards_queue)
127 {
128 p.second.clear();
129 }
130 for (auto& p : m_particles_generated)
131 {
132 p.second.clear();
133 }
134 }
135 // ------------------------------------------------------------------------
136 void cleanMaterialMap()
137 {
138 m_material_map.clear();
139 m_flips_material.clear();
140 m_sky_material.clear();
141 }
142
143};
144
145#endif
146
147#endif
Definition: cpu_particle_manager.hpp:61
Definition: material.hpp:48
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
Definition: stk_particle.hpp:39
Definition: singleton.hpp:87
Definition: cpu_particle_manager.hpp:64
Definition: cpu_particle_manager.hpp:44