blob: 0acc2b966529905d8811a2eddc64f7b09b26d2b0 (
plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
#pragma once
#include <cstdint>
#include "System.h"
#include "System.h"
namespace crepe {
class ParticleEmitter;
class Transform;
/**
* \brief ParticleSystem class responsible for managing particle emission,
* updates, and bounds checking.
*/
class ParticleSystem : public System {
public:
using System::System;
/**
* \brief Updates all particle emitters by emitting particles, updating
* particle states, and checking bounds.
*/
void update() override;
private:
/**
* \brief Emits a particle from the specified emitter based on its emission
* properties.
*
* \param emitter Reference to the ParticleEmitter.
* \param transform Const reference to the Transform component associated
* with the emitter.
*/
void emit_particle(ParticleEmitter & emitter, const Transform & transform);
/**
* \brief Calculates the number of times particles should be emitted based on
* emission rate and update count.
*
* \param count Current update count.
* \param emission Emission rate.
* \return The number of particles to emit.
*/
int calculate_update(int count, double emission) const;
/**
* \brief Checks whether particles are within the emitter’s boundary, resets
* or stops particles if they exit.
*
* \param emitter Reference to the ParticleEmitter.
* \param transform Const reference to the Transform component associated
* with the emitter.
*/
void check_bounds(ParticleEmitter & emitter, const Transform & transform);
/**
* \brief Generates a random angle for particle emission within the specified
* range.
*
* \param min_angle Minimum emission angle in degrees.
* \param max_angle Maximum emission angle in degrees.
* \return Random angle in degrees.
*/
double generate_random_angle(double min_angle, double max_angle) const;
/**
* \brief Generates a random speed for particle emission within the specified
* range.
*
* \param min_speed Minimum emission speed.
* \param max_speed Maximum emission speed.
* \return Random speed.
*/
double generate_random_speed(double min_speed, double max_speed) const;
private:
//! Counter to count updates to determine how many times emit_particle is
// called.
unsigned int update_count = 0;
//! Determines the lowest amount of emission rate (1000 = 0.001 = 1 particle
// per 1000 updates).
static constexpr unsigned int MAX_UPDATE_COUNT = 100;
};
} // namespace crepe
|