9#include <audiopp/logger.h>
18void on_create_component(entt::registry& r, entt::entity e)
20 auto& comp =
r.get<audio_source_component>(
e);
22 if(
r.all_of<active_component>(e))
27void on_destroy_component(entt::registry& r, entt::entity e)
29 auto& comp =
r.get<audio_source_component>(
e);
33void on_create_active_component(entt::registry& r, entt::entity e)
35 if(
auto comp =
r.try_get<audio_source_component>(e))
37 comp->on_play_begin();
40void on_destroy_active_component(entt::registry& r, entt::entity e)
42 if(
auto comp =
r.try_get<audio_source_component>(e))
53 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
55 auto& ev = ctx.get_cached<
events>();
56 ev.
on_frame_update.connect(sentinel_,
this, &audio_system::on_frame_update);
58 ev.on_play_begin.connect(sentinel_, 10,
this, &audio_system::on_play_begin);
59 ev.on_play_end.connect(sentinel_, -10,
this, &audio_system::on_play_end);
60 ev.on_pause.connect(sentinel_, 10,
this, &audio_system::on_pause);
61 ev.on_resume.connect(sentinel_, -10,
this, &audio_system::on_resume);
62 ev.on_skip_next_frame.connect(sentinel_, -10,
this, &audio_system::on_skip_next_frame);
64 audio::set_info_logger(
65 [](
const std::string& s)
69 audio::set_error_logger(
70 [](
const std::string& s)
75 audio::set_trace_logger(
76 [](
const std::string& s)
81 audio::device::print_devices();
82 device_ = std::make_unique<audio::device>();
89 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
96 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
100 auto& registry = *scn.registry;
106 registry.on_construct<
active_component>().connect<&on_create_active_component>();
107 registry.on_destroy<
active_component>().connect<&on_destroy_active_component>();
111 [&](
auto e,
auto&& comp,
auto&& active)
113 comp.on_play_begin();
119 APPLOG_TRACE(
"{}::{}", hpp::type_name_str(*
this), __func__);
123 auto& registry = *scn.registry;
125 registry.view<audio_source_component, active_component>().each(
126 [&](
auto e,
auto&& comp,
auto&& active)
131 registry.on_construct<active_component>().disconnect<&on_create_active_component>();
132 registry.on_destroy<active_component>().disconnect<&on_destroy_active_component>();
134 registry.on_construct<audio_source_component>().disconnect<&on_create_component>();
135 registry.on_destroy<audio_source_component>().disconnect<&on_destroy_component>();
141 auto& scn = ec.get_scene();
142 auto& registry = *scn.registry;
144 registry.view<audio_source_component>().each(
145 [&](
auto e,
auto&& comp)
154 auto& scn = ec.get_scene();
155 auto& registry = *scn.registry;
157 registry.view<audio_source_component>().each(
158 [&](
auto e,
auto&& comp)
167 on_frame_update(ctx, step);
176 auto& scn = ec.get_scene();
177 auto& registry = *scn.registry;
180 registry.view<transform_component, audio_listener_component, active_component>().each(
181 [&](
auto e,
auto&& transform,
auto&& comp,
auto&& active)
183 comp.update(
transform.get_transform_global(), dt);
186 registry.view<transform_component, audio_source_component, active_component>().each(
187 [&](
auto e,
auto&& transform,
auto&& comp,
auto&& active)
189 comp.update(
transform.get_transform_global(), dt);
Class that contains core data for audio sources.
auto init(rtti::context &ctx) -> bool
Initializes the audio system with the given context.
auto deinit(rtti::context &ctx) -> bool
Deinitializes the audio system with the given context.
std::chrono::duration< float > delta_t
#define APPLOG_ERROR(...)
#define APPLOG_TRACE(...)
bgfx::Transform transform
#define APP_SCOPE_PERF(name_literal)
Create a scoped performance timer that records to the timeline profiler. Only accepts string literals...
Manages the entity-component-system (ECS) operations for the ACE framework.
auto get_scene() -> scene &
Gets the current scene.
hpp::event< void(rtti::context &, delta_t)> on_frame_update