Wayverb
engine.h
1 #pragma once
2 
3 #include "raytracer/cl/reflection.h"
4 
5 #include "core/gpu_scene_data.h"
6 
7 #include "utilities/aligned/vector.h"
8 #include "utilities/event.h"
9 
10 #include "glm/fwd.hpp"
11 
12 #include <memory>
13 
14 namespace wayverb {
15 
16 // forward declarations //////////////////////////////////////////////////////
17 
18 namespace core {
19 class compute_context;
20 struct environment;
21 namespace attenuator {
22 class null;
23 class hrtf;
24 class microphone;
25 } // namespace attenuator
26 } // namespace core
27 namespace raytracer {
28 struct simulation_parameters;
29 } // namespace raytracer
30 namespace waveguide {
31 struct voxels_and_mesh;
32 } // namespace waveguide
33 namespace combined {
34 class waveguide_base;
35 
36 // state information /////////////////////////////////////////////////////////
37 
38 enum class state {
39  idle,
40  initialising,
41  starting_raytracer,
42  running_raytracer,
43  finishing_raytracer,
44  starting_waveguide,
45  running_waveguide,
46  finishing_waveguide,
47  postprocessing,
48 };
49 
50 constexpr auto to_string(state s) {
51  switch (s) {
52  case state::idle: return "idle";
53  case state::initialising: return "initialising";
54  case state::starting_raytracer: return "starting raytracer";
55  case state::running_raytracer: return "running raytracer";
56  case state::finishing_raytracer: return "finishing raytracer";
57  case state::starting_waveguide: return "starting waveguide";
58  case state::running_waveguide: return "running waveguide";
59  case state::finishing_waveguide: return "finishing waveguide";
60  case state::postprocessing: return "postprocessing";
61  }
62 }
63 
64 // postprocessing ////////////////////////////////////////////////////////////
65 
67 class intermediate {
68 public:
69  intermediate() = default;
70  intermediate(const intermediate&) = default;
71  intermediate(intermediate&&) noexcept = default;
72  intermediate& operator=(const intermediate&) = default;
73  intermediate& operator=(intermediate&&) noexcept = default;
74  virtual ~intermediate() noexcept = default;
75 
77  virtual util::aligned::vector<float> postprocess(
78  const core::attenuator::null&, double) const = 0;
79 
81  virtual util::aligned::vector<float> postprocess(
82  const core::attenuator::hrtf&, double) const = 0;
83 
85  virtual util::aligned::vector<float> postprocess(
86  const core::attenuator::microphone&, double) const = 0;
87 };
88 
89 // engine ////////////////////////////////////////////////////////////////////
90 
91 class engine final {
92 public:
93  engine(const core::compute_context& compute_context,
94  const core::gpu_scene_data& scene_data,
95  const glm::vec3& source,
96  const glm::vec3& receiver,
97  const core::environment& environment,
99  std::unique_ptr<waveguide_base> waveguide);
100 
101  ~engine() noexcept;
102 
103  std::unique_ptr<intermediate> run(const std::atomic_bool& keep_going) const;
104 
105  // notifications /////////////////////////////////////////////////////////
106 
109 
113 
116  util::aligned::vector<util::aligned::vector<raytracer::reflection>>,
117  glm::vec3>;
118 
119  engine_state_changed::connection connect_engine_state_changed(
120  engine_state_changed::callback_type callback);
121 
122  waveguide_node_pressures_changed::connection
123  connect_waveguide_node_pressures_changed(
124  waveguide_node_pressures_changed::callback_type callback);
125 
127  connect_raytracer_reflections_generated(
128  raytracer_reflections_generated::callback_type callback);
129 
130  // cached data ///////////////////////////////////////////////////////////
131 
132  const waveguide::voxels_and_mesh& get_voxels_and_mesh() const;
133 
134 private:
135  class impl;
136  std::unique_ptr<impl> pimpl_;
137 };
138 
139 } // namespace combined
140 } // namespace wayverb
Definition: scene_data.h:13
Definition: hrtf.h:12
This is badly designed. Really, the capsules should be polymorphic.
Definition: engine.h:67
Definition: traits.cpp:2
Definition: engine.h:91
Definition: pressure.h:22
Definition: environment.h:6
Definition: capsule_base.h:9
invariant: device is a valid device for the context
Definition: common.h:13
Definition: event.h:28
Definition: simulation_parameters.h:9
Super-simple class which maintains microphone invariants.
Definition: microphone.h:10
Definition: engine.cpp:88