Welcome to mirror list, hosted at ThFree Co, Russian Federation.

simulation_state.hpp « bparticles « simulations « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a686afcd52dca6677aa080c64e6aee6c7f0c8c5 (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 "BLI_float_interval.h"

#include "particles_state.hpp"
#include "world_state.hpp"

namespace BParticles {

using BLI::FloatInterval;

class SimulationTimeState {
 private:
  bool m_is_updating = false;
  float m_simulation_time = 0.0f;
  float m_update_start_time = 0.0f;
  float m_update_duration = 0.0f;
  uint m_current_update_index = 0;

 public:
  bool is_updating() const
  {
    return m_is_updating;
  }

  FloatInterval current_update_time() const
  {
    BLI_assert(m_is_updating);
    return FloatInterval(m_update_start_time, m_update_duration);
  }

  uint current_update_index() const
  {
    BLI_assert(m_is_updating);
    return m_current_update_index;
  }

  void start_update(float time_step)
  {
    BLI_assert(time_step >= 0);
    BLI_assert(!m_is_updating);
    m_is_updating = true;
    m_update_start_time = m_simulation_time;
    m_update_duration = time_step;
    m_current_update_index++;
  }

  void end_update()
  {
    BLI_assert(m_is_updating);
    m_is_updating = false;
    m_simulation_time = m_update_start_time + m_update_duration;
  }
};

class SimulationState {
 private:
  ParticlesState m_particles;
  WorldState m_world;
  SimulationTimeState m_time_state;

 public:
  ParticlesState &particles()
  {
    return m_particles;
  }

  WorldState &world()
  {
    return m_world;
  }

  SimulationTimeState &time()
  {
    return m_time_state;
  }
};

}  // namespace BParticles