Brunot
Loading...
Searching...
No Matches
ParticleEmitter.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20
21#pragma once
25
26
31class ParticleEmitter final
32{
33public:
36 ParticleEmitter(const ParticleEmitter& other);
37 ParticleEmitter(ParticleEmitter&& other) noexcept;
38 auto operator=(const ParticleEmitter& other) -> ParticleEmitter&;
39 auto operator=(ParticleEmitter&& other) noexcept -> ParticleEmitter&;
40
47 auto setParentTransform(const AffineMatrix& affineMatrix, Vector4D scale, float rot) -> void;
48
50 auto registerWithParticles() const -> void;
51
56 auto update(float dt) -> void;
57
61 auto showMenu() -> void;
62
66 auto reset() -> void;
67
72 auto destroyed() -> bool;
73 auto destroy() -> void;
74
75 auto setParticleSpawnerColor(const Vector4D& vec) -> void;
76 auto setParticleSpawnerEndColor(const Vector4D& vec) -> void;
77
78 [[nodiscard]] auto getName() const -> std::string;
79
80 auto setName(const std::string& setName) -> void;
81
82 auto save(Stream& stream) const -> void;
83 auto load(const Stream& stream) -> void;
84
85 friend auto to_json(json& j, const ParticleEmitter& n) -> void;
86 friend auto from_json(const json& j, ParticleEmitter& n) -> void;
87
88private:
90 std::string name = "Emitter";
92 std::shared_ptr<ParticleBlock> block;
94 std::unique_ptr<ParticleSpawner> spawner;
95
101 float parentRot = 0;
103 float spawnsPerSecond = 1.f;
105 float timeToNextSpawn = 0.f;
106
108 bool isDestroyed = false;
109
111 auto getTimeBetweenSpawns() const -> float;
112
113};
sys::Json Stream
Definition AudioObject.h:20
nlohmann::json json
Definition Json.cpp:19
A container for holding and updating particles that are all the same type.
Creates Particles, based on initial conditions set in the editor, with potential randomness.
auto operator=(const ParticleEmitter &other) -> ParticleEmitter &
Definition ParticleEmitter.cpp:72
std::shared_ptr< ParticleBlock > block
where the particles generated by the emitter are stored. this block is also referenced by sys::Partic...
Definition ParticleEmitter.h:92
auto setParentTransform(const AffineMatrix &affineMatrix, Vector4D scale, float rot) -> void
set the transforms for the parent Entity, so that Particles will be generated at the right scale and ...
Definition ParticleEmitter.cpp:104
ParticleEmitter()
Definition ParticleEmitter.cpp:33
friend auto to_json(json &j, const ParticleEmitter &n) -> void
Definition ParticleEmitter.cpp:305
float parentRot
parent rotation, as last set by setParentTransform
Definition ParticleEmitter.h:101
auto setParticleSpawnerEndColor(const Vector4D &vec) -> void
Definition ParticleEmitter.cpp:270
std::unique_ptr< ParticleSpawner > spawner
the ParticleSpawner is what actually creates the particles
Definition ParticleEmitter.h:94
auto reset() -> void
resets the timer on the emitter, so that particles will be emitted next time it updates
Definition ParticleEmitter.cpp:250
~ParticleEmitter()
Definition ParticleEmitter.cpp:39
friend auto from_json(const json &j, ParticleEmitter &n) -> void
Definition ParticleEmitter.cpp:315
AffineMatrix parentTransform
parent transform, as last set by setParentTransform
Definition ParticleEmitter.h:97
float timeToNextSpawn
how long until particles will spawn next
Definition ParticleEmitter.h:105
auto destroyed() -> bool
check if the emitter was deleted via the ImGui Menu
Definition ParticleEmitter.cpp:255
float spawnsPerSecond
how often particles should spawn
Definition ParticleEmitter.h:103
auto setName(const std::string &setName) -> void
Definition ParticleEmitter.cpp:280
auto save(Stream &stream) const -> void
Definition ParticleEmitter.cpp:285
auto setParticleSpawnerColor(const Vector4D &vec) -> void
Definition ParticleEmitter.cpp:265
auto load(const Stream &stream) -> void
Definition ParticleEmitter.cpp:290
Vector4D parentScale
parent scale, as last set by setParentTransform
Definition ParticleEmitter.h:99
std::string name
The name of the emitter, for ease of reference in editor.
Definition ParticleEmitter.h:90
auto registerWithParticles() const -> void
registers the ParticleEmitter with sys::ParticleManager, so that the particles can be updated
Definition ParticleEmitter.cpp:28
auto getTimeBetweenSpawns() const -> float
helper function for calculating time between spawns, based on how many spawnsPerSecond
Definition ParticleEmitter.cpp:295
auto update(float dt) -> void
runs update for the emitter, the emitter will automatically count down to decide when to emit particl...
Definition ParticleEmitter.cpp:112
bool isDestroyed
if the particleEmitter should be removed because it was deleted in the menu
Definition ParticleEmitter.h:108
auto destroy() -> void
Definition ParticleEmitter.cpp:260
auto showMenu() -> void
Draw the ImGui menu for the Emitter, has controls for what types of particles are emitted,...
Definition ParticleEmitter.cpp:130
auto getName() const -> std::string
Definition ParticleEmitter.cpp:275
Definition AffineMatrix.h:30
Definition Vector4D.h:28