Muto 0.0.1
Cross-Platform Application Template
GitHub Repo | Muto Updates | Muto's Author
Loading...
Searching...
No Matches
ParticleSystem.h
Go to the documentation of this file.
1#pragma once
2/// @file ParticleSystem.h
3/// @author Damon S. Green II
4/// @brief Defines the ParticleSystem class, which is responsible for rendering a simple particle system. This is a temporary implementation and will be replaced with a more robust implementation in the future.
5
6#include <glm/glm.hpp>
7#include "Core/Timestep.h"
8
9namespace Muto {
10
12 {
13 glm::vec3 Position = { 0.0f, 0.0f, 0.0f };
14 glm::vec3 PositionVariation = { 0.0f, 0.0f, 0.0f };
15 glm::vec3 Velocity = { 0.0f, 0.0f, 0.0f };
16 glm::vec3 VelocityVariation = { 0.0f, 0.0f, 0.0f };
17 glm::vec4 ColorBegin = { 1.0f, 1.0f, 1.0f, 1.0f };
18 glm::vec4 ColorEnd = { 1.0f, 1.0f, 1.0f, 1.0f };
19 float SizeBegin = 1.0f;
20 float SizeEnd = 0.0f;
21 float SizeVariation = 0.0f;
22 float Rotation = 0.0f;
23 float RotationVariation = 0.0f;
24 float Lifetime = 1.0f;
25 float LifetimeVariation = 0.0f;
26 };
27
28 struct Particle
29 {
34 float Rotation;
35 float Lifetime = 0.0f;
36 float LifeRemaining = 0.0f;
37 bool Active = false;
38 };
39
40 /// @class ParticleSystem
41 /// @brief A simple particle system for stress testing the renderer. This is a temporary starter particle system and will be replaced with a more robust implementation in the future.
42 /// @note Temporary implementation is not optimized for performance and is intended for testing purposes only.
43 /// It uses a simple pool of particles and updates them each frame. The particle properties can be set using the ParticleProps struct, which allows for variation in velocity, size, rotation, and lifetime.
45 {
46 public:
48 ParticleSystem(uint32_t maxParticles);
49
50 void OnUpdate(Timestep ts);
51 void OnRender();
52 void Emit(const ParticleProps& particleProps);
53 void SetParticleProps(const ParticleProps& particleProps) { m_Props = particleProps; }
54 void ResetSystem() { m_PoolIndex = m_ParticlePool.size() - 1; m_TimeSinceLastEmit = 0.0f; m_IsEmitting = true; }
55 void ResetParticle(Particle& particle, const ParticleProps& particleProps);
56 private:
58 uint32_t m_PoolIndex = 999;
60 public:
62 float m_TimeSinceLastEmit = 0.0f;
63 bool m_IsEmitting = true;
64 int m_EmitRate = 100; // Particles per second
65 bool m_Loop = true;
66 };
67
68
69}
#define MU_CORE_ASSERT(x,...)
Definition Asserts.h:32
#define MU_BIND_EVENT_FN(fn)
Binds a member function as an event handler.
Definition Defines_Macros.h:17
static const uint32_t s_MapHeight
Definition EditorLayer.cpp:14
static const char * s_MapTiles
Definition EditorLayer.cpp:15
static const uint32_t s_MapWidth
Definition EditorLayer.cpp:13
#define MU_PROFILE_SCOPE(name)
Definition Instrumentor.h:239
#define MU_PROFILE_FUNCTION()
Definition Instrumentor.h:240
#define MU_CORE_ERROR(...)
error: indicates an error that has occurred
Definition Log.h:42
#define MU_CORE_INFO(...)
info: general information about application flow
Definition Log.h:38
The core application class that manages the main loop, window, layers, and event handling.
Definition Application.h:70
void Close()
Closes the application.
Definition Application.cpp:103
ImGuiLayer * GetImGuiLayer()
Retrieves the ImGui layer.
Definition Application.h:104
static Application & Get()
Retrieves the singleton instance of the Application.
Definition Application.h:107
Definition EditorCamera.h:20
Definition EditorLayer.h:13
bool useEntityScene
Definition EditorLayer.h:90
OrthographicCameraController m_CameraController
Definition EditorLayer.h:52
bool m_PrimaryCamera
Definition EditorLayer.h:46
virtual void OnAttach() override
Called when the layer is attached to the application.
Definition EditorLayer.cpp:46
bool scene3
Definition EditorLayer.h:89
glm::vec2 m_ViewportBounds[2]
Definition EditorLayer.h:45
Ref< Scene > m_ActiveScene
Definition EditorLayer.h:34
Ref< Scene > m_EditorScene
Definition EditorLayer.h:35
ParticleProps m_ParticleProps
Definition EditorLayer.h:86
glm::vec4 m_TextureTintColor2
Definition EditorLayer.h:94
Ref< SubTexture2D > m_SubTextureSmoke
Definition EditorLayer.h:70
void OpenScene()
Definition EditorLayer.cpp:539
glm::vec4 m_SpecialQuadColor
Definition EditorLayer.h:97
bool scene2
Definition EditorLayer.h:89
EditorCamera m_EditorCamera
Definition EditorLayer.h:78
bool scene1
Definition EditorLayer.h:89
int m_GizmoType
Definition EditorLayer.h:49
Ref< Shader > m_FlatColorShader
Definition EditorLayer.h:59
bool OnKeyPressed(KeyPressedEvent &e)
Definition EditorLayer.cpp:480
Entity m_CameraEntity
Definition EditorLayer.h:47
EditorLayer()
Definition EditorLayer.cpp:38
void NewScene()
Definition EditorLayer.cpp:532
Ref< Framebuffer > m_Framebuffer
Definition EditorLayer.h:76
Entity m_FireEntity
Definition EditorLayer.h:55
float m_textureScale
Definition EditorLayer.h:80
void SaveSceneAs()
Definition EditorLayer.cpp:555
Ref< Texture2D > m_SpriteSheetFire
Definition EditorLayer.h:62
Ref< SubTexture2D > m_SubTextureFire
Definition EditorLayer.h:69
bool scene4
Definition EditorLayer.h:89
std::unordered_map< char, Ref< SubTexture2D > > s_TextureMap
Definition EditorLayer.h:100
virtual void OnDetach() override
Called when the layer is detached from the application.
Definition EditorLayer.cpp:230
SceneHierarchyPanel m_SceneHierarchyPanel
Definition EditorLayer.h:32
float m_squareRotation
Definition EditorLayer.h:81
bool m_UseSpecialQuadColor
Definition EditorLayer.h:98
glm::vec4 m_ClearColor
Definition EditorLayer.h:96
float lastFrameTime
Definition EditorLayer.h:54
virtual void OnEvent(Event &e) override
Called when an event is dispatched to the layer.
Definition EditorLayer.cpp:468
virtual ~EditorLayer()=default
glm::vec4 m_SquareColor
Definition EditorLayer.h:92
virtual void OnUpdate(Timestep ts) override
Called every frame to update the layer with the given timestep.
Definition EditorLayer.cpp:235
ParticleSystem m_ParticleSystem
Definition EditorLayer.h:85
glm::vec4 m_TextureTintColor1
Definition EditorLayer.h:93
void ResetScene()
Definition EditorLayer.cpp:566
glm::vec2 m_ViewportSize
Definition EditorLayer.h:44
float m_TranslationSnap
Definition EditorLayer.h:50
SceneState m_SceneState
Definition EditorLayer.h:41
float m_ScaleSnap
Definition EditorLayer.h:50
Ref< Texture2D > m_SpriteSheetTown
Definition EditorLayer.h:64
Ref< Texture2D > m_CheckerboardTexture
Definition EditorLayer.h:60
bool m_ViewportFocused
Definition EditorLayer.h:43
Ref< Texture2D > m_SpriteSheetRocks
Definition EditorLayer.h:66
Ref< VertexArray > m_SquareVA
Definition EditorLayer.h:58
float m_RotationSnap
Definition EditorLayer.h:50
int m_ParticleEmitCount
Definition EditorLayer.h:83
glm::vec4 m_BackgroundColor
Definition EditorLayer.h:95
Ref< Texture2D > m_SpriteSheetSmoke
Definition EditorLayer.h:63
virtual void OnImGuiRender() override
Called when the layer should render its ImGui components.
Definition EditorLayer.cpp:281
SceneState
Definition EditorLayer.h:38
Entity m_SmokeEntity
Definition EditorLayer.h:55
bool m_ViewportHovered
Definition EditorLayer.h:43
float m_specialQuadRotation
Definition EditorLayer.h:82
Ref< SubTexture2D > m_SubTextureTown
Definition EditorLayer.h:71
Ref< Texture2D > m_SpriteSheetCursedLands
Definition EditorLayer.h:67
Ref< Texture2D > m_SpriteSheetCrystals
Definition EditorLayer.h:65
Represents an entity in a scene.
Definition Entity.h:17
Stack-based templated event dispatcher.
Definition Event.h:66
EventDispatcher(Event &event)
Construct an EventDispatcher for a specific event.
Definition Event.h:76
Abstract base class for all events.
Definition Event.h:35
Cross-platform file dialog utilities.
Definition PlatformUtils.h:13
static std::string SaveFile(const char *filter)
Opens a file dialog to select a location to save a file.
Definition LinuxPlatformUtils.cpp:165
static std::string OpenFile(const char *filter)
Opens a file dialog to select a file to open.
Definition LinuxPlatformUtils.cpp:160
WIP.
Definition PlatformUtils.h:31
static std::string m_RootEditorDirectory
Definition PlatformUtils.h:41
static std::string m_RootEngineDirectory
Definition PlatformUtils.h:40
static std::string m_ProjectsDirectory
Definition PlatformUtils.h:44
static std::string m_AssetsDirectory
Definition PlatformUtils.h:43
static bool IsInitialized()
Definition PlatformUtils.h:37
static void Initialize()
Definition FileSystem.cpp:16
static bool m_Initialized
Definition PlatformUtils.h:39
static std::string GetAbsolutePath(const std::string &relativePath)
Definition FileSystem.cpp:38
static std::string GetCurrentWorkingDirectory()
Definition FileSystem.cpp:33
static std::string m_ResourcesDirectory
Definition PlatformUtils.h:42
static std::string m_CurrentProjectDirectory
Definition PlatformUtils.h:45
static std::string GetTravelingUpPath(const std::string &path)
Definition FileSystem.cpp:43
virtual void SetBlockEvents(bool block)
Definition ImGuiLayer.h:29
Base input class for querying input states.
Definition Input.h:15
static bool IsKeyPressed(int keycode)
Checks if the specified key is currently pressed.
Definition WindowsInput.cpp:9
int GetKeyCode() const
Get the key code associated with the event.
Definition KeyEvent.h:20
Event for registering key press.
Definition KeyEvent.h:37
int GetRepeatCount() const
Get the repeat count of the key press event.
Definition KeyEvent.h:48
Represents a reusable application layer that receives lifecycle callbacks (attach,...
Definition Layer.h:17
Definition OrthographicCameraController.h:30
A simple particle system for stress testing the renderer. This is a temporary starter particle system...
Definition ParticleSystem.h:45
int m_EmitRate
Definition ParticleSystem.h:64
ParticleSystem(uint32_t maxParticles)
Definition ParticleSystem.cpp:18
void ResetParticle(Particle &particle, const ParticleProps &particleProps)
Definition ParticleSystem.cpp:120
void OnRender()
Definition ParticleSystem.cpp:76
bool m_Loop
Definition ParticleSystem.h:65
bool m_IsEmitting
Definition ParticleSystem.h:63
uint32_t m_PoolIndex
Definition ParticleSystem.h:58
void OnUpdate(Timestep ts)
Definition ParticleSystem.cpp:24
ParticleProps m_Props
Definition ParticleSystem.h:61
float m_TimeSinceLastEmit
Definition ParticleSystem.h:62
ParticleSystem()
Definition ParticleSystem.cpp:11
void SetParticleProps(const ParticleProps &particleProps)
Definition ParticleSystem.h:53
std::vector< Particle > m_ParticlePool
Definition ParticleSystem.h:57
void Emit(const ParticleProps &particleProps)
Definition ParticleSystem.cpp:96
void ResetSystem()
Definition ParticleSystem.h:54
int m_activeParticleCount
Definition ParticleSystem.h:59
A static class that provides an interface for issuing rendering commands.
Definition RenderCommand.h:13
static void Clear()
Clears the rendering buffers.
Definition RenderCommand.h:35
A 2D renderer for drawing quads and sprites.
Definition Renderer2D.h:21
static void ResetStats()
Resets the rendering statistics.
Definition Renderer2D.cpp:516
static Statistics GetStats()
Retrieves the current rendering statistics.
Definition Renderer2D.cpp:521
Definition SceneHierarchyPanel.h:12
Handles serialization and deserialization of scenes.
Definition SceneSerializer.h:16
void Serialize(const std::string &filepath)
Definition SceneSerializer.cpp:179
bool Deserialize(const std::string &filepath)
Definition SceneSerializer.cpp:206
Represents a time step in seconds.
Definition Timestep.h:11
static glm::vec4 Brown()
Returns a vec4 representing the color brown.
Definition Color.h:44
static glm::vec4 StripAlpha(const glm::vec4 &color)
Strips the alpha component from the given color, setting it to 1.0 (fully opaque).
Definition Color.h:49
static glm::vec4 Cyan()
Returns a vec4 representing the color cyan.
Definition Color.h:38
static glm::vec4 Indigo()
Returns a vec4 representing the color indigo.
Definition Color.h:33
static glm::vec4 Orange()
Returns a vec4 representing the color orange.
Definition Color.h:25
static glm::vec4 Black()
Returns a vec4 representing the color black.
Definition Color.h:18
static glm::vec4 SetAlpha(const glm::vec4 &color, float alpha=0.0f)
Sets the alpha component of the given color to the specified value.
Definition Color.h:51
static glm::vec4 Yellow()
Returns a vec4 representing the color yellow.
Definition Color.h:27
static glm::vec4 Purple()
Returns a vec4 representing the color purple.
Definition Color.h:35
static glm::vec4 Gray()
Returns a vec4 representing the color gray.
Definition Color.h:20
static glm::vec4 Pink()
Returns a vec4 representing the color pink.
Definition Color.h:42
static glm::vec4 White()
Returns a vec4 representing the color white.
Definition Color.h:16
static glm::vec4 Green()
Returns a vec4 representing the color green.
Definition Color.h:29
static glm::vec4 Blue()
Returns a vec4 representing the color blue.
Definition Color.h:31
static glm::vec4 Transparent()
Returns a vec4 representing a fully transparent color.
Definition Color.h:46
static glm::vec4 Red()
Returns a vec4 representing the color red.
Definition Color.h:23
static glm::vec4 Magenta()
Returns a vec4 representing the color magenta.
Definition Color.h:40
@ RightControl
Definition KeyCodes.h:147
@ NumLock
Definition KeyCodes.h:93
@ KP_9
Definition KeyCodes.h:132
@ Enter
Definition KeyCodes.h:78
@ KP_1
Definition KeyCodes.h:124
@ RightAlt
Definition KeyCodes.h:148
@ A
Definition KeyCodes.h:41
@ F16
Definition KeyCodes.h:111
@ D9
Definition KeyCodes.h:36
@ F23
Definition KeyCodes.h:118
@ F2
Definition KeyCodes.h:97
@ KP_SUBTRACT
Definition KeyCodes.h:136
@ F4
Definition KeyCodes.h:99
@ J
Definition KeyCodes.h:50
@ Equal
Definition KeyCodes.h:39
@ Home
Definition KeyCodes.h:89
@ E
Definition KeyCodes.h:45
@ World1
Definition KeyCodes.h:73
@ C
Definition KeyCodes.h:43
@ P
Definition KeyCodes.h:56
@ PrintScreen
Definition KeyCodes.h:94
@ F12
Definition KeyCodes.h:107
@ GraveAccent
Definition KeyCodes.h:71
@ LeftControl
Definition KeyCodes.h:143
@ LeftSuper
Definition KeyCodes.h:145
@ S
Definition KeyCodes.h:59
@ Backslash
Definition KeyCodes.h:69
@ F25
Definition KeyCodes.h:120
@ RightBracket
Definition KeyCodes.h:70
@ F11
Definition KeyCodes.h:106
@ R
Definition KeyCodes.h:58
@ K
Definition KeyCodes.h:51
@ F
Definition KeyCodes.h:46
@ Z
Definition KeyCodes.h:66
@ KP_DECIMAL
Definition KeyCodes.h:133
@ Period
Definition KeyCodes.h:24
@ F3
Definition KeyCodes.h:98
@ End
Definition KeyCodes.h:90
@ F14
Definition KeyCodes.h:109
@ Up
Definition KeyCodes.h:86
@ PageDown
Definition KeyCodes.h:88
@ PageUp
Definition KeyCodes.h:87
@ W
Definition KeyCodes.h:63
@ KP_4
Definition KeyCodes.h:127
@ LeftBracket
Definition KeyCodes.h:68
@ D0
Definition KeyCodes.h:27
@ F20
Definition KeyCodes.h:115
@ Menu
Definition KeyCodes.h:150
@ Left
Definition KeyCodes.h:84
@ N
Definition KeyCodes.h:54
@ Space
Definition KeyCodes.h:20
@ Minus
Definition KeyCodes.h:23
@ D8
Definition KeyCodes.h:35
@ Tab
Definition KeyCodes.h:79
@ KP_MULTIPLY
Definition KeyCodes.h:135
@ F22
Definition KeyCodes.h:117
@ KP_DIVIDE
Definition KeyCodes.h:134
@ D3
Definition KeyCodes.h:30
@ KP_5
Definition KeyCodes.h:128
@ KP_EQUAL
Definition KeyCodes.h:139
@ F7
Definition KeyCodes.h:102
@ KP_7
Definition KeyCodes.h:130
@ F21
Definition KeyCodes.h:116
@ CapsLock
Definition KeyCodes.h:91
@ F19
Definition KeyCodes.h:114
@ Y
Definition KeyCodes.h:65
@ F18
Definition KeyCodes.h:113
@ KP_6
Definition KeyCodes.h:129
@ Apostrophe
Definition KeyCodes.h:21
@ Delete
Definition KeyCodes.h:82
@ KP_0
Definition KeyCodes.h:123
@ Q
Definition KeyCodes.h:57
@ F5
Definition KeyCodes.h:100
@ O
Definition KeyCodes.h:55
@ F6
Definition KeyCodes.h:101
@ Pause
Definition KeyCodes.h:95
@ KP_ENTER
Definition KeyCodes.h:138
@ X
Definition KeyCodes.h:64
@ LeftShift
Definition KeyCodes.h:142
@ KP_ADD
Definition KeyCodes.h:137
@ RightShift
Definition KeyCodes.h:146
@ B
Definition KeyCodes.h:42
@ D1
Definition KeyCodes.h:28
@ D4
Definition KeyCodes.h:31
@ LeftAlt
Definition KeyCodes.h:144
@ I
Definition KeyCodes.h:49
@ F17
Definition KeyCodes.h:112
@ F24
Definition KeyCodes.h:119
@ Insert
Definition KeyCodes.h:81
@ D
Definition KeyCodes.h:44
@ D6
Definition KeyCodes.h:33
@ F8
Definition KeyCodes.h:103
@ F15
Definition KeyCodes.h:110
@ RightSuper
Definition KeyCodes.h:149
@ Right
Definition KeyCodes.h:83
@ ScrollLock
Definition KeyCodes.h:92
@ KP_3
Definition KeyCodes.h:126
@ Semicolon
Definition KeyCodes.h:38
@ Escape
Definition KeyCodes.h:77
@ KP_2
Definition KeyCodes.h:125
@ KP_8
Definition KeyCodes.h:131
@ F1
Definition KeyCodes.h:96
@ Slash
Definition KeyCodes.h:25
@ G
Definition KeyCodes.h:47
@ F10
Definition KeyCodes.h:105
@ L
Definition KeyCodes.h:52
@ M
Definition KeyCodes.h:53
@ D7
Definition KeyCodes.h:34
@ V
Definition KeyCodes.h:62
@ T
Definition KeyCodes.h:60
@ F13
Definition KeyCodes.h:108
@ H
Definition KeyCodes.h:48
@ U
Definition KeyCodes.h:61
@ D5
Definition KeyCodes.h:32
@ Down
Definition KeyCodes.h:85
@ World2
Definition KeyCodes.h:74
@ D2
Definition KeyCodes.h:29
@ F9
Definition KeyCodes.h:104
@ Comma
Definition KeyCodes.h:22
@ Backspace
Definition KeyCodes.h:80
MouseButtonCodes
Enumeration of mouse button codes.
Definition MouseButtonCodes.h:17
@ MBC_Button4
Definition MouseButtonCodes.h:23
@ MBC_Button2
Definition MouseButtonCodes.h:21
@ MBC_Button6
Definition MouseButtonCodes.h:25
@ MBC_Button1
Definition MouseButtonCodes.h:20
@ MBC_ButtonRight
Definition MouseButtonCodes.h:30
@ MBC_ButtonLast
Definition MouseButtonCodes.h:28
@ MBC_ButtonMiddle
Definition MouseButtonCodes.h:31
@ MBC_Button3
Definition MouseButtonCodes.h:22
@ MBC_Button5
Definition MouseButtonCodes.h:24
@ MBC_Button7
Definition MouseButtonCodes.h:26
@ MBC_Button0
Definition MouseButtonCodes.h:19
@ MBC_ButtonLeft
Definition MouseButtonCodes.h:29
Definition Random.h:17
glm::vec3 RangeF3(float min, float max)
Definition Random.h:129
glm::vec3 Float3()
Definition Random.h:124
glm::vec2 RangeF2(float min1, float max1, float min2, float max2)
Definition Random.h:113
float RangeF1(float min, float max)
Definition Random.h:87
glm::vec3 RangeF3(const glm::vec2 &range1, const glm::vec2 &range2, const glm::vec2 &range3)
Definition Random.h:139
std::string String(size_t length)
Definition Random.h:46
glm::vec2 Float2()
Definition Random.h:103
std::mt19937 & GetRNG()
Definition Random.h:19
uint32_t UInt1(uint32_t max)
Definition Random.h:28
bool Bool1(float trueChance)
Definition Random.h:34
glm::vec2 RangeF2(float min, float max)
Definition Random.h:108
std::string HexString(size_t length)
Definition Random.h:60
void Seed(uint32_t seed)
Definition Random.h:24
glm::vec3 RangeF3(float min1, float max1, float min2, float max2, float min3, float max3)
Definition Random.h:134
float Float1()
Definition Random.h:79
unsigned char Char()
Definition Random.h:40
float RangeF1_Inclusive(float min, float max)
Definition Random.h:95
glm::vec4 Float4()
Definition Random.h:144
std::string UUID()
Definition Random.h:73
glm::vec2 RangeF2(const glm::vec2 &minRange, const glm::vec2 &maxRange)
Definition Random.h:118
glm::vec4 RangeF4(float min, float max)
Definition Random.h:149
The main namespace for the Muto engine.
Definition Application.cpp:15
float LifeRemaining
Definition ParticleSystem.h:36
float SizeVariation
Definition ParticleSystem.h:21
float SizeBegin
Definition ParticleSystem.h:19
uint32_t Height
Definition Framebuffer.h:15
glm::vec4 ColorBegin
Definition ParticleSystem.h:32
glm::vec3 Position
Definition ParticleSystem.h:13
float Lifetime
Definition ParticleSystem.h:35
float SizeEnd
Definition ParticleSystem.h:33
float RotationVariation
Definition ParticleSystem.h:23
float Lifetime
Definition ParticleSystem.h:24
glm::vec3 Velocity
Definition ParticleSystem.h:31
uint32_t Width
Definition Framebuffer.h:15
float Rotation
Definition ParticleSystem.h:34
glm::vec4 ColorEnd
Definition ParticleSystem.h:18
glm::vec3 VelocityVariation
Definition ParticleSystem.h:16
bool Active
Definition ParticleSystem.h:37
glm::vec4 ColorBegin
Definition ParticleSystem.h:17
glm::vec4 ColorEnd
Definition ParticleSystem.h:32
glm::vec3 PositionVariation
Definition ParticleSystem.h:14
float SizeBegin
Definition ParticleSystem.h:33
float LifetimeVariation
Definition ParticleSystem.h:25
float Rotation
Definition ParticleSystem.h:22
glm::vec3 Velocity
Definition ParticleSystem.h:15
glm::vec3 Position
Definition ParticleSystem.h:30
float SizeEnd
Definition ParticleSystem.h:20
Specification for creating a Framebuffer.
Definition Framebuffer.h:14
Definition ParticleSystem.h:29
Definition ParticleSystem.h:12
Component that holds the transform of an entity.
Definition Components.h:68