Peoplemon  0.1.0
Peoplemon 3 game source documentation
PeoplemonSpark.hpp
Go to the documentation of this file.
1 #ifndef CORE_BATTLES_VIEW_PEOPLEMONSPARK_HPP
2 #define CORE_BATTLES_VIEW_PEOPLEMONSPARK_HPP
3 
4 #include <BLIB/Particles.hpp>
5 #include <BLIB/Util/Random.hpp>
6 #include <Core/Properties.hpp>
7 #include <glm/glm.hpp>
8 
9 namespace core
10 {
11 namespace battle
12 {
13 namespace view
14 {
21  glm::vec2 position;
22  glm::vec2 velocity;
23  float radius;
24  float time;
25  float lifetime;
26 
27  PeoplemonSpark() = default;
28 };
29 
36  glm::vec2 position;
37  float radius;
38  float lifetime;
39 
40  PeoplemonSparkGpu() = default;
41 
43  position = s.position;
44  radius = s.radius;
45  lifetime = s.time / s.lifetime;
46  return *this;
47  }
48 };
49 
57 };
58 
59 } // namespace view
60 } // namespace battle
61 } // namespace core
62 
63 namespace bl
64 {
65 namespace pcl
66 {
70 
71 template<>
72 struct RenderConfigMap<PeoplemonSpark> {
73  static constexpr std::uint32_t PipelineId = core::Properties::BattlePeoplemonSparkPipelineId;
74  static constexpr bool ContainsTransparency = true;
75 
76  static constexpr bool CreateRenderPipeline = true;
77 
78  static constexpr std::initializer_list<std::uint32_t> RenderPassIds =
79  RenderConfigDefaults<PeoplemonSpark>::RenderPassIds;
80 
83  RenderConfigDescriptorList<rc::ds::Scene2DFactory,
84  DescriptorSetFactory<PeoplemonSpark, GpuPeoplemonSpark>>;
85 
86  static constexpr bool EnableDepthTesting = false;
87  static constexpr VkPrimitiveTopology Topology = VK_PRIMITIVE_TOPOLOGY_POINT_LIST;
88  static constexpr const char* VertexShader = "Resources/Shaders/Particles/battleSpark.vert.spv";
89  static constexpr const char* FragmentShader =
90  "Resources/Shaders/Particles/battleSpark.frag.spv";
91 };
92 } // namespace pcl
93 } // namespace bl
94 
95 namespace core
96 {
97 namespace battle
98 {
99 namespace view
100 {
101 
107 class SparkExplosionEmitter : public bl::pcl::Emitter<PeoplemonSpark> {
108 public:
109  static constexpr float CreateRate = 200.f;
110  static constexpr unsigned int MaxSpawn = 50;
111 
112  SparkExplosionEmitter(const glm::vec2& origin)
113  : origin(origin)
114  , residual(0.f)
115  , enabled(false) {}
116 
117  virtual ~SparkExplosionEmitter() = default;
118 
119  void setEnabled(bool e) { enabled = e; }
120 
121 private:
122  const glm::vec2 origin;
123  float residual;
124  bool enabled;
125 
126  virtual void update(Proxy& proxy, float dt, float) override {
127  constexpr float SquareSize = 200.f;
128 
129  if (enabled) {
130  residual += CreateRate * dt;
131  while (proxy.getManager().getParticleCount() < MaxSpawn && residual >= 1.f) {
132  residual -= 1.f;
133  auto& sp = proxy.emit();
134 
135  const float a = bl::util::Random::get<float>(0.f, 360.f);
136  const float d = bl::util::Random::get<float>(1.f, 3.f);
137  const float v = bl::util::Random::get<float>(150.f, 900.f);
138  const float c = bl::math::cos(a);
139  const float s = bl::math::sin(a);
140  sp.position.x = origin.x + SquareSize * 0.5f + d * c;
141  sp.position.y = origin.y + SquareSize * 0.5f + d * s;
142  sp.velocity.x = v * c;
143  sp.velocity.y = v * s;
144  sp.time = 0.f;
145  sp.lifetime = bl::util::Random::get<float>(0.6f, 1.1f);
146  sp.radius = bl::util::Random::get<float>(2.f, 12.f);
147  }
148  }
149  }
150 };
151 
157 class SparkImplosionEmitter : public bl::pcl::Emitter<PeoplemonSpark> {
158 public:
159  static constexpr float CreateRate = 200.f;
160  static constexpr unsigned int MaxSpawn = 50;
161 
163  : residual(0.f)
164  , enabled(false) {}
165 
166  virtual ~SparkImplosionEmitter() = default;
167 
168  void setEnabled(bool e, const glm::vec2& origin = {}) {
169  enabled = e;
170  implodeOrigin = origin;
171  }
172 
173 private:
174  glm::vec2 implodeOrigin;
175  float residual;
176  bool enabled;
177 
178  virtual void update(Proxy& proxy, float dt, float) override {
179  if (enabled) {
180  residual += CreateRate * dt;
181  while (proxy.getManager().getParticleCount() < MaxSpawn && residual >= 1.f) {
182  residual -= 1.f;
183  auto& sp = proxy.emit();
184 
185  const float a = bl::util::Random::get<float>(0.f, 360.f);
186  const float d = bl::util::Random::get<float>(190.f, 210.f);
187  const float v = bl::util::Random::get<float>(450.f, 900.f);
188  const float c = bl::math::cos(a);
189  const float s = bl::math::sin(a);
190  sp.position.x = implodeOrigin.x + d * c;
191  sp.position.y = implodeOrigin.y + d * s;
192  sp.velocity.x = v * -c;
193  sp.velocity.y = v * -s;
194  sp.time = 0.f;
195  sp.lifetime = d / v;
196  sp.radius = bl::util::Random::get<float>(2.f, 12.f);
197  }
198  }
199  }
200 };
201 
207 class SparkAffector : public bl::pcl::Affector<PeoplemonSpark> {
208 public:
209  virtual ~SparkAffector() = default;
210 
211 private:
212  virtual void update(Proxy& proxy, float dt, float) override {
213  for (auto& spark : proxy.particles()) {
214  spark.position += spark.velocity * dt;
215  spark.time += dt;
216  }
217  }
218 };
219 
225 class SparkSink : public bl::pcl::Sink<PeoplemonSpark> {
226 public:
227  virtual ~SparkSink() = default;
228 
229 private:
230  virtual void update(Proxy& proxy, std::span<PeoplemonSpark> particles, float, float) override {
231  for (PeoplemonSpark& spark : particles) {
232  if (spark.time >= spark.lifetime) { proxy.destroy(spark); }
233  }
234  }
235 };
236 
237 } // namespace view
238 } // namespace battle
239 } // namespace core
240 
241 #endif
Core classes and functionality for both the editor and game.
core::battle::view::PeoplemonSpark PeoplemonSpark
core::battle::view::PeoplemonSparkGlobalShaderPayload GlobalShaderStruct
Particle system spark for peoplemon animations.
Particle system spark GPU payload for peoplemon animations.
PeoplemonSparkGpu & operator=(const PeoplemonSpark &s)
Global descriptor set payload for spark particle system renderer.
RenderConfigDescriptorList< rc::ds::Scene2DFactory, DescriptorSetFactory< PeoplemonSpark, GpuPeoplemonSpark > > DescriptorSets
Particle system spark emitter for explosions.
static constexpr unsigned int MaxSpawn
SparkExplosionEmitter(const glm::vec2 &origin)
Particle system spark emitter for implosions.
static constexpr unsigned int MaxSpawn
void setEnabled(bool e, const glm::vec2 &origin={})
Particle system spark affector.
Particle system spark sink.
virtual ~SparkSink()=default
static constexpr std::uint32_t BattlePeoplemonSparkPipelineId
Definition: Properties.hpp:143