Unravel Engine C++ Reference
Loading...
Searching...
No Matches
particle_system.cpp
Go to the documentation of this file.
1#include "particle_system.h"
6#include <logging/logging.h>
7
8
9#define POOLSTL_STD_SUPPLEMENT 1
10#include <poolstl/poolstl.hpp>
11
12
13namespace unravel
14{
15
17{
18 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
19
20 // Initialize the particle system with default parameters
21 // 64 max emitters, using default allocator
22 psInit(4096 * 4, nullptr);
23
24 initialized_ = true;
25
26 return true;
27}
28
30{
31 APPLOG_TRACE("{}::{}", hpp::type_name_str(*this), __func__);
32
33 if(initialized_)
34 {
35 // Shutdown the particle system
36 psShutdown();
37 initialized_ = false;
38 }
39
40 return true;
41}
42
44{
45 if(!initialized_)
46 {
47 return;
48 }
49
50 APP_SCOPE_PERF("Particles/System Update");
51
52 auto& registry = *scn.registry;
53
54 // Update all particle emitter components that have both transform and particle emitter components
56
57 // this code should be thread safe as each task works with a whole hierarchy and
58 // there is no interleaving between tasks.
59 std::for_each(std::execution::par,
60 view.begin(),
61 view.end(),
62 [&](entt::entity entity)
63 {
64 auto& transform_comp = view.get<transform_component>(entity);
65 auto& emitter_comp = view.get<particle_emitter_component>(entity);
66
67 // Get the world transform and pass it to the emitter
68 const auto& world_transform = transform_comp.get_transform_global();
69 emitter_comp.update_emitter(world_transform, dt);
70 });
71
72}
73
74} // namespace unravel
Component that wraps particle system emitter functionality.
auto deinit(rtti::context &ctx) -> bool
Deinitializes the particle system.
auto init(rtti::context &ctx) -> bool
Initializes the particle system.
void on_frame_before_render(scene &scn, delta_t dt)
Updates all particle emitters in the scene.
Component that handles transformations (position, rotation, scale, etc.) in the ACE framework.
std::chrono::duration< float > delta_t
#define APPLOG_TRACE(...)
Definition logging.h:17
void psShutdown()
void psInit(uint16_t _maxEmitters, bx::AllocatorI *_allocator)
#define APP_SCOPE_PERF(name)
Create a scoped performance timer that only accepts string literals.
Definition profiler.h:160
entt::entity entity
Represents a scene in the ACE framework, managing entities and their relationships.
Definition scene.h:21
std::unique_ptr< entt::registry > registry
The registry that manages all entities in the scene.
Definition scene.h:117