Isle
Loading...
Searching...
No Matches
legosoundmanager.cpp
Go to the documentation of this file.
1#include "legosoundmanager.h"
2
4#include "mxautolock.h"
5#include "mxomni.h"
6
7#include <assert.h>
8
10
11// FUNCTION: LEGO1 0x100298a0
13{
14 Init();
15}
16
17// FUNCTION: LEGO1 0x10029940
19{
21}
22
23// FUNCTION: LEGO1 0x100299a0
24void LegoSoundManager::Init()
25{
26 m_cacheSoundManager = NULL;
27 m_listener = NULL;
28}
29
30// FUNCTION: LEGO1 0x100299b0
31void LegoSoundManager::Destroy(MxBool p_fromDestructor)
32{
33 delete m_cacheSoundManager;
34 Init();
35
36 if (!p_fromDestructor) {
38 }
39}
40
41// FUNCTION: LEGO1 0x100299f0
42// FUNCTION: BETA10 0x100d0129
43MxResult LegoSoundManager::Create(MxU32 p_frequencyMS, MxBool p_createThread)
44{
45 MxBool locked = FALSE;
46 MxResult result = FAILURE;
47
50 locked = TRUE;
51
52 if (MxOmni::IsSound3D()) {
53 if (m_dsBuffer->QueryInterface(IID_IDirectSound3DListener, (LPVOID*) &m_listener) != DS_OK) {
54 goto done;
55 }
56
58 LPDIRECTSOUND sound;
59
60 if (omni && omni->GetSoundManager() && (sound = omni->GetSoundManager()->GetDirectSound())) {
61 DSCAPS caps;
62 memset(&caps, 0, sizeof(DSCAPS));
63 caps.dwSize = sizeof(DSCAPS);
64
65 if (sound->GetCaps(&caps) == S_OK && caps.dwMaxHw3DAllBuffers == 0) {
66 m_listener->SetDistanceFactor(0.026315790f, 0);
67 m_listener->SetRolloffFactor(10, 0);
68 }
69 }
70 }
71
72 m_cacheSoundManager = new LegoCacheSoundManager;
73 assert(m_cacheSoundManager);
74 result = SUCCESS;
75 }
76
77done:
78 if (result != SUCCESS) {
79 Destroy();
80 }
81
82 if (locked) {
84 }
85
86 return result;
87}
88
89// FUNCTION: LEGO1 0x1002a390
90// FUNCTION: BETA10 0x100d02ed
92{
94}
95
96// FUNCTION: LEGO1 0x1002a3a0
97// FUNCTION: BETA10 0x100d030d
99{
101
103 return m_cacheSoundManager->Tickle();
104}
105
106// FUNCTION: LEGO1 0x1002a410
107// FUNCTION: BETA10 0x100d03a5
109 const float* p_position,
110 const float* p_direction,
111 const float* p_up,
112 const float* p_velocity
113)
114{
115 if (m_listener != NULL) {
116 if (p_position != NULL) {
117 m_listener->SetPosition(p_position[0], p_position[1], p_position[2], DS3D_DEFERRED);
118 }
119
120 if (p_direction != NULL && p_up != NULL) {
121 m_listener->SetOrientation(
122 p_direction[0],
123 p_direction[1],
124 p_direction[2],
125 p_up[0],
126 p_up[1],
127 p_up[2],
129 );
130 }
131
132 if (p_velocity != NULL) {
133 m_listener->SetVelocity(p_velocity[0], p_velocity[1], p_velocity[2], DS3D_DEFERRED);
134 }
135
136 if (p_position != NULL || (p_direction != NULL && p_up != NULL) || p_velocity != NULL) {
137 m_listener->CommitDeferredSettings();
138 }
139 }
140}
[AI] Manages caching, reuse, and playback of LegoCacheSound objects.
virtual MxResult Tickle()
[AI] Advances or cleans up all managed sounds.
[AI] Manages 3D sound effects and music playback for LEGO Island, integrating with DirectSound and pr...
void Destroy() override
[AI] Cleans up and releases all resources used by the sound manager and its cache.
MxResult Tickle() override
[AI] Performs periodic processing, such as updating the cache sound manager.
void UpdateListener(const float *p_position, const float *p_direction, const float *p_up, const float *p_velocity)
[AI] Updates the 3D sound listener properties in DirectSound, reflecting player/world changes.
~LegoSoundManager() override
[AI] Destructor. Cleans up resources, optionally as part of destruction.
MxResult Create() override
[AI] Initializes audio subsystem resources and registers an instance for global audio management.
virtual MxResult Tickle()
[AI] Called by tickle managers to allow the object to update itself.
Definition: mxcore.h:31
void Enter()
[AI] Acquires/gains entry to the critical section or mutex, blocking if not available.
void Leave()
[AI] Releases/leaves the critical section or mutex.
MxCriticalSection m_criticalSection
[AI] Critical section object used for guarding access to the presenter list and internal members for ...
[AI] Central subsystem coordinator and singleton of the LEGO Island engine.
Definition: mxomni.h:32
static MxOmni * GetInstance()
[AI] Returns the singleton instance of the MxOmni subsystem coordinator.
Definition: mxomni.cpp:289
static MxBool IsSound3D()
[AI] Returns current state of 3D sound configuration.
Definition: mxomni.cpp:387
MxSoundManager * GetSoundManager() const
[AI] Gets the engine's sound manager used for playing/controlling sounds.
Definition: mxomni.h:228
LPDIRECTSOUND GetDirectSound()
[AI] Gets pointer to internal DirectSound interface.
void Destroy() override
[AI] Releases sound resources and unregisters from tickle system.
LPDIRECTSOUNDBUFFER m_dsBuffer
[AI] Primary DirectSound buffer interface for setting output format/volume.
LPSTR LPSTR LPVOID
Definition: d3dcaps.h:216
#define TRUE
Definition: d3drmdef.h:28
#define FALSE
Definition: d3drmdef.h:27
#define DECOMP_SIZE_ASSERT(T, S)
Definition: decomp.h:19
#define DS3D_DEFERRED
Definition: dsound.h:778
struct IDirectSound * LPDIRECTSOUND
Definition: dsound.h:46
#define DS_OK
Definition: dsound.h:690
struct _DSCAPS DSCAPS
#define NULL
[AI] Null pointer value (C/C++ semantics).
Definition: legotypes.h:26
#define FAILURE
[AI] Used to indicate a failed operation in result codes.
Definition: legotypes.h:34
#define SUCCESS
[AI] Used to indicate a successful operation in result codes.
Definition: legotypes.h:30
#define AUTOLOCK(CS)
[AI] Macro for automatic locking using the MxAutoLock class. This macro instantiates an MxAutoLock ob...
Definition: mxautolock.h:5
MxU8 MxBool
[AI]
Definition: mxtypes.h:124
MxLong MxResult
[AI]
Definition: mxtypes.h:106
unsigned int MxU32
[AI]
Definition: mxtypes.h:32
Definition: dsound.h:55
DWORD dwSize
Definition: dsound.h:56
DWORD dwMaxHw3DAllBuffers
Definition: dsound.h:67