blob: 651eb7e1cd6bef5ac08fa861eb602872421746d4 (
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
|
#pragma once
#include "particle_allocator.hpp"
#include "simulation_state.hpp"
namespace BParticles {
class EmitterInterface {
private:
SimulationState &m_simulation_state;
ParticleAllocator &m_particle_allocator;
FloatInterval m_time_span;
public:
EmitterInterface(SimulationState &simulation_state,
ParticleAllocator &particle_allocator,
FloatInterval time_span)
: m_simulation_state(simulation_state),
m_particle_allocator(particle_allocator),
m_time_span(time_span)
{
}
~EmitterInterface() = default;
ParticleAllocator &particle_allocator()
{
return m_particle_allocator;
}
/**
* Time span that new particles should be emitted in.
*/
FloatInterval time_span()
{
return m_time_span;
}
uint time_step()
{
return m_simulation_state.time().current_update_index();
}
/**
* True when this is the first time step in a simulation, otherwise false.
*/
bool is_first_step()
{
return m_simulation_state.time().current_update_index() == 1;
}
};
/**
* An emitter creates new particles of possibly different types within a certain time span.
*/
class Emitter {
public:
virtual ~Emitter()
{
}
/**
* Create new particles within a time span.
*
* In general it works like so:
* 1. Prepare vectors with attribute values for e.g. position and velocity of the new
* particles.
* 2. Request an emit target that can contain a given amount of particles of a specific type.
* 3. Copy the prepared attribute arrays into the target. Other attributes are initialized with
* some default value.
* 4. Specify the exact birth times of every particle within the time span. This will allow the
* framework to simulate the new particles for partial time steps to avoid stepping.
*
* To create particles of different types, multiple emit targets have to be requested.
*/
virtual void emit(EmitterInterface &interface) = 0;
};
} // namespace BParticles
|