-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52949f6
commit 2b9a02d
Showing
10 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/// @file | ||
/// @brief Component @ref cubos::engine::AudioListener. | ||
/// @ingroup audio-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Component which adds an AudioListener to the entitiy | ||
/// @ingroup audio-plugin | ||
|
||
struct CUBOS_ENGINE_API AudioListener | ||
{ | ||
CUBOS_REFLECT; | ||
|
||
bool active; // is the listener active (assigned to an entity) | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/// @dir | ||
/// @brief @ref audio-plugin plugin directory. | ||
|
||
/// @file | ||
/// @brief Plugin entry point. | ||
/// @ingroup audio-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/engine/audio/audio.hpp> | ||
#include <cubos/engine/audio/listener.hpp> | ||
#include <cubos/engine/audio/source.hpp> | ||
#include <cubos/engine/prelude.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @defgroup audio-plugin Audio | ||
/// @ingroup engine | ||
/// @brief Adds audio management to @b Cubos | ||
/// | ||
/// ## Settings | ||
/// - `audio.listenerCount` - number of listeners per audio device (default: `4`). | ||
/// | ||
/// ## Dependencies | ||
/// - @ref settings-plugin | ||
|
||
/// @brief Initializes the audio manager (after @ref settingsTag). | ||
CUBOS_ENGINE_API extern Tag audioInitTag; | ||
|
||
/// @brief Systems which add bridges to the audio manager should be tagged with this. | ||
CUBOS_ENGINE_API extern Tag audioBridgeTag; | ||
|
||
/// @brief Startup systems which load audios should be tagged with this. | ||
CUBOS_ENGINE_API extern Tag audioTag; | ||
|
||
/// @brief Plugin entry function. | ||
/// @param cubos @b Cubos main class. | ||
/// @ingroup assets-plugin | ||
CUBOS_ENGINE_API void audioPlugin(Cubos& cubos); | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/// @file | ||
/// @brief Component @ref cubos::engine::AudioSource. | ||
/// @ingroup audio-plugin | ||
|
||
#pragma once | ||
|
||
#include <cubos/core/reflection/reflect.hpp> | ||
|
||
#include <cubos/engine/api.hpp> | ||
|
||
namespace cubos::engine | ||
{ | ||
/// @brief Component which adds an AudioSource to the entitiy | ||
/// @ingroup audio-plugin | ||
|
||
struct CUBOS_ENGINE_API AudioSource | ||
{ | ||
CUBOS_REFLECT; | ||
}; | ||
} // namespace cubos::engine |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <cubos/core/ecs/reflection.hpp> | ||
#include <cubos/core/reflection/external/primitives.hpp> | ||
|
||
#include <cubos/engine/audio/listener.hpp> | ||
|
||
CUBOS_REFLECT_IMPL(cubos::engine::AudioListener) | ||
{ | ||
return core::ecs::TypeBuilder<AudioListener>("cubos::engine::AudioListener") | ||
.withField("active", &AudioListener::active) | ||
.build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include <cubos/core/al/audio_context.hpp> | ||
|
||
#include <cubos/engine/assets/plugin.hpp> | ||
#include <cubos/engine/audio/bridge.hpp> | ||
#include <cubos/engine/audio/plugin.hpp> | ||
#include <cubos/engine/settings/plugin.hpp> | ||
|
||
CUBOS_DEFINE_TAG(cubos::engine::audioInitTag); | ||
CUBOS_DEFINE_TAG(cubos::engine::audioBridgeTag); | ||
CUBOS_DEFINE_TAG(cubos::engine::audioTag); | ||
|
||
using cubos::core::al::AudioContext; | ||
|
||
void cubos::engine::audioPlugin(Cubos& cubos) | ||
{ | ||
cubos.depends(settingsPlugin); | ||
|
||
cubos.component<AudioSource>(); | ||
cubos.component<AudioListener>(); | ||
|
||
cubos.startupTag(audioTag); | ||
cubos.startupTag(audioInitTag).after(settingsTag); | ||
cubos.startupTag(audioBridgeTag).after(audioInitTag).before(audioTag); | ||
|
||
cubos.startupSystem("initalize Audio plugin").tagged(audioInitTag).call([](Assets& assets, Settings& settings) { | ||
auto audioContext = AudioContext::create(); | ||
|
||
unsigned int listenerCount = static_cast<unsigned int>( | ||
settings.getInteger("audio.listener.count", static_cast<int>(MA_ENGINE_MAX_LISTENERS))); | ||
|
||
auto audioDevice = audioContext->createDevice("MiniAudioDevice", listenerCount); | ||
|
||
auto bridge = std::make_shared<AudioBridge>(audioContext); | ||
assets.registerBridge(".wav", bridge); | ||
assets.registerBridge(".mp3", bridge); | ||
assets.registerBridge(".flac", bridge); | ||
assets.registerBridge(".ogg", bridge); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <cubos/core/ecs/reflection.hpp> | ||
#include <cubos/core/reflection/external/primitives.hpp> | ||
|
||
#include <cubos/engine/audio/source.hpp> | ||
|
||
CUBOS_REFLECT_IMPL(cubos::engine::AudioSource) | ||
{ | ||
return core::ecs::TypeBuilder<AudioSource>("cubos::engine::AudioSource").build(); | ||
} |