diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-11 19:48:18 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-11 19:48:18 +0100 |
commit | 141c4831be82654a692d03fdb0fbf87fa27dea88 (patch) | |
tree | 02bc3294cf44e3f962595d05bbdfcc0484d0d9f3 /src/crepe/system/ParticleSystem.h | |
parent | ca878336da5cdd120a929e6ce84f565ce5365248 (diff) | |
parent | e42d0877592aa1e88afbe0bc65822cd53a82205d (diff) |
Merge branch 'jaro/particle-system-master' into niels/RenderingParticle
Diffstat (limited to 'src/crepe/system/ParticleSystem.h')
-rw-r--r-- | src/crepe/system/ParticleSystem.h | 64 |
1 files changed, 60 insertions, 4 deletions
diff --git a/src/crepe/system/ParticleSystem.h b/src/crepe/system/ParticleSystem.h index 3ac1d3f..3155df1 100644 --- a/src/crepe/system/ParticleSystem.h +++ b/src/crepe/system/ParticleSystem.h @@ -1,18 +1,74 @@ #pragma once -#include "../api/ParticleEmitter.h" +#include <cstdint> namespace crepe { - +class ParticleEmitter; +class Transform; +/** + * \brief ParticleSystem class responsible for managing particle emission, updates, and bounds checking. + */ class ParticleSystem { public: + /** + * \brief Default constructor. + */ ParticleSystem(); + + /** + * \brief Updates all particle emitters by emitting particles, updating particle states, and checking bounds. + */ void update(); private: - void emit_particle(ParticleEmitter & emitter); //emits a new particle + /** + * \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); - float elapsed_time; //elapsed time since the last emission + /** + * \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. + uint32_t update_count = 0; + //! Determines the lowest amount of emission rate (1000 = 0.001 = 1 particle per 1000 updates). + static constexpr uint32_t MAX_UPDATE_COUNT = 100; }; } // namespace crepe |