mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-03 10:50:22 +01:00
pch migration to modules [wip]
This commit is contained in:
@@ -1,4 +1,20 @@
|
||||
/*
|
||||
module;
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include "global_include/interfaces/ITexture_macros.h"
|
||||
#include <sndfile.h>
|
||||
#include "utilities/Globals_macros.h"
|
||||
#include "utilities/utilities_macros.h"
|
||||
|
||||
module eu07.audio.audio;
|
||||
import eu07.utilities.globals;
|
||||
import eu07.utilities.logs;
|
||||
import eu07.model.resourcemanager;
|
||||
import eu07.utilities.utilities;
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
@@ -7,15 +23,8 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include <sndfile.h>
|
||||
|
||||
#include "audio/audio.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "model/ResourceManager.h"
|
||||
#include "utilities/utilities.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
|
||||
@@ -1,4 +1,44 @@
|
||||
/*
|
||||
module;
|
||||
#include "global_include/interfaces/ITexture_macros.h"
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#include <OpenAL/al.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#include <OpenAL/alc.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <AL/alc.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <AL/alext.h>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <cstddef>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <string>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <unordered_map>
|
||||
#endif
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#else
|
||||
#include <vector>
|
||||
#endif
|
||||
|
||||
export module eu07.audio.audio;
|
||||
|
||||
export {
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
@@ -7,15 +47,9 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(__APPLE__) && !__has_include(<AL/al.h>)
|
||||
#include <OpenAL/al.h>
|
||||
#include <OpenAL/alc.h>
|
||||
#else
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/alext.h>
|
||||
#endif
|
||||
|
||||
namespace audio {
|
||||
@@ -80,3 +114,5 @@ private:
|
||||
} // audio
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
} // export
|
||||
@@ -1,4 +1,27 @@
|
||||
/*
|
||||
module;
|
||||
#include <AL/alext.h>
|
||||
#include <cmath>
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "audio/audiorenderer_macros.h"
|
||||
#include "utilities/Globals_macros.h"
|
||||
#include "utilities/crashreporter_macros.h"
|
||||
|
||||
module eu07.audio.sound;
|
||||
import eu07.utilities.utilities;
|
||||
import eu07.utilities.globals;
|
||||
import eu07.vehicle.camera;
|
||||
import eu07.utilities.logs;
|
||||
import eu07.simulation.simulation;
|
||||
import eu07.vehicle.train;
|
||||
import eu07.utilities.crashreporter;
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
@@ -7,15 +30,7 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "audio/audiorenderer.h"
|
||||
|
||||
#include "audio/sound.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "vehicle/Camera.h"
|
||||
#include "utilities/Logs.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "vehicle/Train.h"
|
||||
|
||||
namespace audio {
|
||||
|
||||
|
||||
@@ -1,168 +0,0 @@
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio/audio.h"
|
||||
#include "model/ResourceManager.h"
|
||||
#include "application/uitranscripts.h"
|
||||
|
||||
// Dodaj brakujące includy
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
|
||||
// Definicje dla OpenAL 1.25 jeśli brakuje
|
||||
#ifndef ALC_CONNECTED
|
||||
#define ALC_CONNECTED 0x313
|
||||
#endif
|
||||
|
||||
#ifndef ALC_DEFAULT_ALL_DEVICES_SPECIFIER
|
||||
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
|
||||
#endif
|
||||
|
||||
#define EU07_SOUND_PROOFINGUSESRANGE
|
||||
|
||||
class opengl_renderer;
|
||||
class sound_source;
|
||||
|
||||
using uint32_sequence = std::vector<std::uint32_t>;
|
||||
|
||||
enum class sound_category : unsigned int {
|
||||
unknown = 0,
|
||||
vehicle,
|
||||
local,
|
||||
ambient,
|
||||
};
|
||||
|
||||
struct sound_properties {
|
||||
glm::dvec3 location;
|
||||
float pitch { 1.f };
|
||||
sound_category category { sound_category::unknown };
|
||||
float gain { 1.f };
|
||||
float soundproofing { 1.f };
|
||||
std::uintptr_t soundproofing_stamp { ~std::uintptr_t{0} };
|
||||
};
|
||||
|
||||
enum class sync_state {
|
||||
good,
|
||||
bad_distance,
|
||||
bad_resource
|
||||
};
|
||||
|
||||
namespace audio {
|
||||
|
||||
struct openal_source {
|
||||
|
||||
friend class openal_renderer;
|
||||
|
||||
using buffer_sequence = std::vector<audio::buffer_handle>;
|
||||
|
||||
ALuint id { audio::null_resource };
|
||||
sound_source *controller { nullptr };
|
||||
uint32_sequence sounds;
|
||||
int sound_index { 0 };
|
||||
bool sound_change { false };
|
||||
bool is_playing { false };
|
||||
bool is_looping { false };
|
||||
sound_properties properties;
|
||||
sync_state sync { sync_state::good };
|
||||
|
||||
openal_source() = default;
|
||||
|
||||
template <class Iterator_>
|
||||
openal_source &bind( sound_source *Controller, uint32_sequence Sounds, Iterator_ First, Iterator_ Last );
|
||||
|
||||
void play();
|
||||
void update( double const Deltatime, glm::vec3 const &Listenervelocity );
|
||||
void sync_with( sound_properties const &State );
|
||||
void stop();
|
||||
void loop( bool const State );
|
||||
void range( float const Range );
|
||||
void pitch( float const Pitch );
|
||||
void clear();
|
||||
|
||||
private:
|
||||
double update_deltatime { 0.0 };
|
||||
float pitch_variation { 1.f };
|
||||
float sound_range { 50.f };
|
||||
glm::vec3 sound_distance { 0.f };
|
||||
glm::vec3 sound_velocity { 0.f };
|
||||
bool is_in_range { false };
|
||||
bool is_multipart { false };
|
||||
};
|
||||
|
||||
class openal_renderer {
|
||||
|
||||
friend opengl_renderer;
|
||||
|
||||
public:
|
||||
openal_renderer() = default;
|
||||
~openal_renderer();
|
||||
|
||||
audio::buffer_handle fetch_buffer( std::string const &Filename );
|
||||
audio::openal_buffer const &buffer( audio::buffer_handle const Buffer ) const;
|
||||
|
||||
bool init();
|
||||
|
||||
template <class Iterator_>
|
||||
void insert( Iterator_ First, Iterator_ Last, sound_source *Controller, uint32_sequence Sounds ) {
|
||||
m_sources.emplace_back( fetch_source().bind( Controller, Sounds, First, Last ) );
|
||||
}
|
||||
|
||||
void erase( sound_source const *Controller );
|
||||
void update( double const Deltatime );
|
||||
|
||||
glm::dvec3 cached_camerapos;
|
||||
|
||||
private:
|
||||
using source_list = std::list<audio::openal_source>;
|
||||
using source_sequence = std::stack<ALuint>;
|
||||
|
||||
bool init_caps();
|
||||
audio::openal_source fetch_source();
|
||||
|
||||
ALCdevice *m_device { nullptr };
|
||||
ALCcontext *m_context { nullptr };
|
||||
bool m_ready { false };
|
||||
glm::vec3 m_listenervelocity;
|
||||
bool m_freeflymode { true };
|
||||
bool m_windowopen { true };
|
||||
int m_activecab { 0 };
|
||||
|
||||
buffer_manager m_buffers;
|
||||
source_list m_sources;
|
||||
source_sequence m_sourcespares;
|
||||
|
||||
// OpenAL Soft extension entry points, resolved at runtime via al(c)GetProcAddress
|
||||
LPALDEFERUPDATESSOFT m_alDeferUpdatesSOFT { nullptr };
|
||||
LPALPROCESSUPDATESSOFT m_alProcessUpdatesSOFT { nullptr };
|
||||
LPALCDEVICEPAUSESOFT m_alcDevicePauseSOFT { nullptr };
|
||||
LPALCDEVICERESUMESOFT m_alcDeviceResumeSOFT { nullptr };
|
||||
LPALCREOPENDEVICESOFT m_alcReopenDeviceSOFT { nullptr };
|
||||
|
||||
bool m_candetectdisconnect { false };
|
||||
ALCint m_contextattributes[3] { 0, 0, 0 };
|
||||
double m_devicechecktime { 0.0 };
|
||||
|
||||
// ALC_SOFT_system_events: event-driven following of output-device / default-output changes.
|
||||
// Preferred over polling because it reliably catches both device removal and default changes
|
||||
// (e.g. re-plugging headphones), which alcGetString(DEFAULT_ALL_DEVICES) does not report live.
|
||||
LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr };
|
||||
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
|
||||
bool m_usedeviceevents { false };
|
||||
std::atomic<bool> m_outputchanged { false }; // set from the (possibly off-thread) event callback
|
||||
static void ALC_APIENTRY device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ) noexcept;
|
||||
};
|
||||
|
||||
extern openal_renderer renderer;
|
||||
extern bool event_volume_change;
|
||||
|
||||
} // namespace audio
|
||||
@@ -1,5 +1,6 @@
|
||||
// separate file because of include dependecies mess
|
||||
|
||||
#include <cmath>
|
||||
namespace audio {
|
||||
template <class Iterator_>
|
||||
openal_source &
|
||||
|
||||
8
audio/audiorenderer_macros.h
Normal file
8
audio/audiorenderer_macros.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
// Macros cannot cross a module boundary, so they live in a plain header
|
||||
// that consumers pull into their global module fragment. The bodies are
|
||||
// expanded at the use site, where the imported names are in scope, so this
|
||||
// header deliberately includes nothing.
|
||||
|
||||
#define ALC_DEFAULT_ALL_DEVICES_SPECIFIER 0x1012
|
||||
@@ -1,4 +1,35 @@
|
||||
/*
|
||||
module;
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "global_include/interfaces/ITexture_macros.h"
|
||||
#include "utilities/Globals_macros.h"
|
||||
#include "vehicle/DynObj_macros.h"
|
||||
|
||||
module eu07.audio.sound;
|
||||
import eu07.utilities.logs;
|
||||
import eu07.utilities.utilities;
|
||||
import eu07.utilities.parser;
|
||||
import eu07.utilities.globals;
|
||||
import eu07.vehicle.camera;
|
||||
import eu07.vehicle.train;
|
||||
import eu07.simcore;
|
||||
import eu07.simulation.simulation;
|
||||
|
||||
namespace {
|
||||
// sound_source stores its owner as an opaque pointer to keep TDynamicObject out of
|
||||
// the module interface; this puts the type back on where the implementation needs it.
|
||||
inline TDynamicObject const *as_vehicle( void const *Owner ) {
|
||||
return static_cast<TDynamicObject const *>( Owner );
|
||||
}
|
||||
} // namespace
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
@@ -7,15 +38,7 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
#include "audio/sound.h"
|
||||
#include "utilities/parser.h"
|
||||
#include "utilities/Globals.h"
|
||||
#include "vehicle/Camera.h"
|
||||
#include "vehicle/Train.h"
|
||||
#include "vehicle/DynObj.h"
|
||||
#include "simulation/simulation.h"
|
||||
#include "audio/audiorenderer_extra.h"
|
||||
|
||||
// constructors
|
||||
@@ -517,7 +540,7 @@ void
|
||||
sound_source::update( audio::openal_source &Source ) {
|
||||
|
||||
if( m_owner != nullptr
|
||||
&& false == m_owner->bEnabled ) {
|
||||
&& false == as_vehicle( m_owner )->bEnabled ) {
|
||||
// terminate the sound if the owner is gone
|
||||
// TBD, TODO: replace with a listener pattern to receive vehicle removal and cab change events and such?
|
||||
m_stop = true;
|
||||
@@ -914,10 +937,10 @@ sound_source::location() const {
|
||||
}
|
||||
// otherwise combine offset with the location of the carrier
|
||||
return {
|
||||
m_owner->GetPosition()
|
||||
+ m_owner->VectorLeft() * (double)m_offset.x
|
||||
+ m_owner->VectorUp() * (double)m_offset.y
|
||||
+ m_owner->VectorFront() * (double)m_offset.z };
|
||||
as_vehicle( m_owner )->GetPosition()
|
||||
+ as_vehicle( m_owner )->VectorLeft() * (double)m_offset.x
|
||||
+ as_vehicle( m_owner )->VectorUp() * (double)m_offset.y
|
||||
+ as_vehicle( m_owner )->VectorFront() * (double)m_offset.z };
|
||||
}
|
||||
|
||||
void
|
||||
@@ -994,7 +1017,7 @@ sound_source::update_soundproofing() {
|
||||
occupiedcab ) };
|
||||
m_properties.soundproofing = m_soundproofing ? // custom soundproofing has higher priority than that of the owner
|
||||
m_soundproofing.value()[listenerlocation + 1] : // cab indices start from -1 so we have to account for this
|
||||
m_owner->soundproofing(static_cast<int>(placement), listenerlocation);
|
||||
as_vehicle( m_owner )->soundproofing(static_cast<int>(placement), listenerlocation);
|
||||
}
|
||||
if( listenervehicle && listenervehicle != m_owner ) {
|
||||
// if the listener is located in another vehicle, calculate additional proofing of the sound coming from outside
|
||||
|
||||
@@ -1,4 +1,29 @@
|
||||
/*
|
||||
module;
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/alext.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stack>
|
||||
#include <cstdint>
|
||||
#include <atomic>
|
||||
#include "audio/audiorenderer_macros.h"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
export module eu07.audio.sound;
|
||||
import eu07.audio.audio;
|
||||
import eu07.glm;
|
||||
import eu07.utilities.parser;
|
||||
import eu07.application.uitranscripts;
|
||||
import eu07.model.resourcemanager;
|
||||
import eu07.utilities.classes;
|
||||
import eu07.utilities.names;
|
||||
|
||||
export {
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
@@ -7,11 +32,7 @@ obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "audio/audiorenderer.h"
|
||||
#include "utilities/Classes.h"
|
||||
#include "utilities/Names.h"
|
||||
|
||||
float const EU07_SOUND_GLOBALRANGE { -1.f };
|
||||
float const EU07_SOUND_CABCONTROLSCUTOFFRANGE { 7.5f };
|
||||
@@ -54,6 +75,166 @@ auto const EU07_SOUNDPROOFING_VERYSTRONG{ std::sqrt( 0.01f ) };
|
||||
// mini controller and audio dispatcher; issues play commands for the audio renderer,
|
||||
// updates parameters of created audio emitters for the playback duration
|
||||
// TODO: move to simulation namespace after clean up of owner classes
|
||||
// openal_source and sound_source refer to each other, so they must share a
|
||||
// module: neither can forward-declare the other across a module boundary.
|
||||
// The renderer only ever handles a sound_source through a pointer.
|
||||
class sound_source;
|
||||
|
||||
/*
|
||||
This Source Code Form is subject to the
|
||||
terms of the Mozilla Public License, v.
|
||||
2.0. If a copy of the MPL was not
|
||||
distributed with this file, You can
|
||||
obtain one at
|
||||
http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
// Dodaj brakujące includy
|
||||
|
||||
// Definicje dla OpenAL 1.25 jeśli brakuje
|
||||
#ifndef ALC_CONNECTED
|
||||
#define ALC_CONNECTED 0x313
|
||||
#endif
|
||||
|
||||
#ifndef ALC_DEFAULT_ALL_DEVICES_SPECIFIER
|
||||
#endif
|
||||
|
||||
#define EU07_SOUND_PROOFINGUSESRANGE
|
||||
|
||||
|
||||
using uint32_sequence = std::vector<std::uint32_t>;
|
||||
|
||||
enum class sound_category : unsigned int {
|
||||
unknown = 0,
|
||||
vehicle,
|
||||
local,
|
||||
ambient,
|
||||
};
|
||||
|
||||
struct sound_properties {
|
||||
glm::dvec3 location;
|
||||
float pitch { 1.f };
|
||||
sound_category category { sound_category::unknown };
|
||||
float gain { 1.f };
|
||||
float soundproofing { 1.f };
|
||||
std::uintptr_t soundproofing_stamp { ~std::uintptr_t{0} };
|
||||
};
|
||||
|
||||
enum class sync_state {
|
||||
good,
|
||||
bad_distance,
|
||||
bad_resource
|
||||
};
|
||||
|
||||
namespace audio {
|
||||
|
||||
struct openal_source {
|
||||
|
||||
friend class openal_renderer;
|
||||
|
||||
using buffer_sequence = std::vector<audio::buffer_handle>;
|
||||
|
||||
ALuint id { audio::null_resource };
|
||||
sound_source *controller { nullptr };
|
||||
uint32_sequence sounds;
|
||||
int sound_index { 0 };
|
||||
bool sound_change { false };
|
||||
bool is_playing { false };
|
||||
bool is_looping { false };
|
||||
sound_properties properties;
|
||||
sync_state sync { sync_state::good };
|
||||
|
||||
openal_source() = default;
|
||||
|
||||
template <class Iterator_>
|
||||
openal_source &bind( sound_source *Controller, uint32_sequence Sounds, Iterator_ First, Iterator_ Last );
|
||||
|
||||
void play();
|
||||
void update( double const Deltatime, glm::vec3 const &Listenervelocity );
|
||||
void sync_with( sound_properties const &State );
|
||||
void stop();
|
||||
void loop( bool const State );
|
||||
void range( float const Range );
|
||||
void pitch( float const Pitch );
|
||||
void clear();
|
||||
|
||||
private:
|
||||
double update_deltatime { 0.0 };
|
||||
float pitch_variation { 1.f };
|
||||
float sound_range { 50.f };
|
||||
glm::vec3 sound_distance { 0.f };
|
||||
glm::vec3 sound_velocity { 0.f };
|
||||
bool is_in_range { false };
|
||||
bool is_multipart { false };
|
||||
};
|
||||
|
||||
class openal_renderer {
|
||||
public:
|
||||
openal_renderer() = default;
|
||||
~openal_renderer();
|
||||
|
||||
audio::buffer_handle fetch_buffer( std::string const &Filename );
|
||||
audio::openal_buffer const &buffer( audio::buffer_handle const Buffer ) const;
|
||||
|
||||
bool init();
|
||||
|
||||
template <class Iterator_>
|
||||
void insert( Iterator_ First, Iterator_ Last, sound_source *Controller, uint32_sequence Sounds ) {
|
||||
m_sources.emplace_back( fetch_source().bind( Controller, Sounds, First, Last ) );
|
||||
}
|
||||
|
||||
void erase( sound_source const *Controller );
|
||||
void update( double const Deltatime );
|
||||
|
||||
glm::dvec3 cached_camerapos;
|
||||
|
||||
private:
|
||||
using source_list = std::list<audio::openal_source>;
|
||||
using source_sequence = std::stack<ALuint>;
|
||||
|
||||
bool init_caps();
|
||||
audio::openal_source fetch_source();
|
||||
|
||||
ALCdevice *m_device { nullptr };
|
||||
ALCcontext *m_context { nullptr };
|
||||
bool m_ready { false };
|
||||
glm::vec3 m_listenervelocity;
|
||||
bool m_freeflymode { true };
|
||||
bool m_windowopen { true };
|
||||
int m_activecab { 0 };
|
||||
|
||||
buffer_manager m_buffers;
|
||||
source_list m_sources;
|
||||
source_sequence m_sourcespares;
|
||||
|
||||
// OpenAL Soft extension entry points, resolved at runtime via al(c)GetProcAddress
|
||||
LPALDEFERUPDATESSOFT m_alDeferUpdatesSOFT { nullptr };
|
||||
LPALPROCESSUPDATESSOFT m_alProcessUpdatesSOFT { nullptr };
|
||||
LPALCDEVICEPAUSESOFT m_alcDevicePauseSOFT { nullptr };
|
||||
LPALCDEVICERESUMESOFT m_alcDeviceResumeSOFT { nullptr };
|
||||
LPALCREOPENDEVICESOFT m_alcReopenDeviceSOFT { nullptr };
|
||||
|
||||
bool m_candetectdisconnect { false };
|
||||
ALCint m_contextattributes[3] { 0, 0, 0 };
|
||||
double m_devicechecktime { 0.0 };
|
||||
|
||||
// ALC_SOFT_system_events: event-driven following of output-device / default-output changes.
|
||||
// Preferred over polling because it reliably catches both device removal and default changes
|
||||
// (e.g. re-plugging headphones), which alcGetString(DEFAULT_ALL_DEVICES) does not report live.
|
||||
LPALCEVENTCONTROLSOFT m_alcEventControlSOFT { nullptr };
|
||||
LPALCEVENTCALLBACKSOFT m_alcEventCallbackSOFT { nullptr };
|
||||
bool m_usedeviceevents { false };
|
||||
std::atomic<bool> m_outputchanged { false }; // set from the (possibly off-thread) event callback
|
||||
static void ALC_APIENTRY device_event_callback( ALCenum eventtype, ALCenum devicetype, ALCdevice *device, ALCsizei length, ALCchar const *message, void *userparam ) noexcept;
|
||||
};
|
||||
|
||||
extern openal_renderer renderer;
|
||||
extern bool event_volume_change;
|
||||
|
||||
} // namespace audio
|
||||
|
||||
class sound_source {
|
||||
|
||||
public:
|
||||
@@ -96,11 +277,13 @@ public:
|
||||
// sets base pitch of the emitter to specified value
|
||||
sound_source &
|
||||
pitch( float const Pitch );
|
||||
// owner setter/getter
|
||||
// Owner setter. The owning vehicle is stored as an opaque pointer so that this
|
||||
// interface does not name TDynamicObject: the vehicle module imports this one
|
||||
// (vehicles hold sound sources by value), so naming it here would close a cycle
|
||||
// in the module graph, and a forward declaration cannot cross a module boundary.
|
||||
// sound.cpp casts it back before use.
|
||||
void
|
||||
owner( TDynamicObject const *Owner );
|
||||
TDynamicObject const *
|
||||
owner() const;
|
||||
owner( void const *Owner );
|
||||
// sound source offset setter/getter
|
||||
void
|
||||
offset( glm::vec3 const Offset );
|
||||
@@ -224,7 +407,7 @@ private:
|
||||
sound( sound_handle const Sound ) const;
|
||||
|
||||
// members
|
||||
TDynamicObject const * m_owner { nullptr }; // optional, the vehicle carrying this sound source
|
||||
void const * m_owner { nullptr }; // optional, the vehicle carrying this sound source (a TDynamicObject)
|
||||
glm::vec3 m_offset; // relative position of the source, either from the owner or the region centre
|
||||
sound_placement m_placement;
|
||||
float m_range { 50.f }; // audible range of the emitted sounds
|
||||
@@ -245,9 +428,11 @@ private:
|
||||
std::optional< std::array<float, 6> > m_soundproofing; // custom soundproofing parameters
|
||||
};
|
||||
|
||||
// owner setter/getter
|
||||
inline void sound_source::owner( TDynamicObject const *Owner ) { m_owner = Owner; }
|
||||
inline TDynamicObject const * sound_source::owner() const { return m_owner; }
|
||||
} // export -- out-of-line member definitions and explicit
|
||||
// specialisations are not namespace-scope declarations, so they cannot
|
||||
// carry `export`; the class itself is exported and that is what counts.
|
||||
// owner setter
|
||||
inline void sound_source::owner( void const *Owner ) { m_owner = Owner; }
|
||||
// sound source offset setter/getter
|
||||
inline void sound_source::offset( glm::vec3 const Offset ) { m_offset = Offset; }
|
||||
inline glm::vec3 const & sound_source::offset() const { return m_offset; }
|
||||
@@ -260,9 +445,12 @@ inline float const & sound_source::start() const { return m_startoffset; }
|
||||
// custom soundproofing setter/getter
|
||||
inline auto & sound_source::soundproofing() { return m_soundproofing; }
|
||||
inline auto const & sound_source::soundproofing() const { return m_soundproofing; }
|
||||
export {
|
||||
|
||||
|
||||
// collection of sound sources present in the scene
|
||||
class sound_table : public basic_table<sound_source> {
|
||||
|
||||
};
|
||||
|
||||
} // export
|
||||
Reference in New Issue
Block a user