Implement/match Lego3DSound::Create

This commit is contained in:
Christian Semmler 2024-06-01 11:43:00 -04:00
parent df20b05510
commit f34e8df745
2 changed files with 84 additions and 28 deletions

View File

@ -6,6 +6,7 @@
#include <dsound.h> #include <dsound.h>
class LegoActor;
class LegoROI; class LegoROI;
// VTABLE: LEGO1 0x100d5778 // VTABLE: LEGO1 0x100d5778
@ -16,7 +17,7 @@ class Lego3DSound {
virtual ~Lego3DSound(); virtual ~Lego3DSound();
void Init(); void Init();
MxResult Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char*, MxS32 p_volume); MxResult Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name, MxS32 p_volume);
void Destroy(); void Destroy();
undefined4 FUN_100118e0(LPDIRECTSOUNDBUFFER p_directSoundBuffer); undefined4 FUN_100118e0(LPDIRECTSOUNDBUFFER p_directSoundBuffer);
void FUN_10011ca0(); void FUN_10011ca0();
@ -26,15 +27,18 @@ class Lego3DSound {
// Lego3DSound::`scalar deleting destructor' // Lego3DSound::`scalar deleting destructor'
private: private:
undefined m_unk0x04[4]; // 0x04 LPDIRECTSOUND3DBUFFER m_ds3dBuffer; // 0x08
LPDIRECTSOUNDBUFFER m_dsBuffer; // 0x08 LegoROI* m_roi; // 0x0c
LegoROI* m_unk0x0c; // 0x0c LegoROI* m_positionROI; // 0x10
undefined4 m_unk0x10; // 0x10 MxBool m_unk0x14; // 0x14
MxBool m_unk0x14; // 0x14 MxBool m_isCharacter; // 0x15
MxBool m_unk0x15; // 0x15 LegoActor* m_actor; // 0x18
undefined4 m_unk0x18; // 0x18 double m_unk0x20; // 0x20
undefined m_unk0x1c[0x10]; // 0x1c DWORD m_dwFrequency; // 0x28
MxS32 m_volume; // 0x2c MxS32 m_volume; // 0x2c
}; };
// GLOBAL: LEGO1 0x100db6c0
// IID_IDirectSound3DBuffer
#endif // LEGO3DSOUND_H #endif // LEGO3DSOUND_H

View File

@ -1,5 +1,6 @@
#include "lego3dsound.h" #include "lego3dsound.h"
#include "legoactor.h"
#include "legocharactermanager.h" #include "legocharactermanager.h"
#include "misc.h" #include "misc.h"
#include "mxomni.h" #include "mxomni.h"
@ -21,31 +22,82 @@ Lego3DSound::~Lego3DSound()
// FUNCTION: LEGO1 0x10011680 // FUNCTION: LEGO1 0x10011680
void Lego3DSound::Init() void Lego3DSound::Init()
{ {
m_dsBuffer = NULL; m_ds3dBuffer = NULL;
m_unk0x0c = NULL; m_roi = NULL;
m_unk0x10 = 0; m_positionROI = NULL;
m_unk0x18 = 0; m_actor = NULL;
m_unk0x14 = FALSE; m_unk0x14 = FALSE;
m_unk0x15 = FALSE; m_isCharacter = FALSE;
m_volume = 79; m_volume = 79;
} }
// STUB: LEGO1 0x100116a0 // FUNCTION: LEGO1 0x100116a0
// FUNCTION: BETA10 0x10039647 // FUNCTION: BETA10 0x10039647
MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char*, MxS32 p_volume) MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char* p_name, MxS32 p_volume)
{ {
m_volume = p_volume; m_volume = p_volume;
if (MxOmni::IsSound3D()) { if (MxOmni::IsSound3D()) {
p_directSoundBuffer->QueryInterface(IID_IDirectSoundBuffer, (LPVOID*) &m_dsBuffer); p_directSoundBuffer->QueryInterface(IID_IDirectSound3DBuffer, (LPVOID*) &m_ds3dBuffer);
if (m_dsBuffer == NULL) { if (m_ds3dBuffer == NULL) {
return FAILURE; return FAILURE;
} }
// TODO m_ds3dBuffer->SetMinDistance(15.0f, 0);
m_ds3dBuffer->SetMaxDistance(100.0f, 0);
m_ds3dBuffer->SetPosition(0.0f, 0.0f, -40.0f, 0);
m_ds3dBuffer->SetConeOutsideVolume(-10000, 0);
} }
// TODO if (m_ds3dBuffer == NULL || p_name == NULL) {
return SUCCESS;
}
if (CharacterManager()->Exists(p_name)) {
m_roi = CharacterManager()->GetROI(p_name, TRUE);
m_unk0x14 = m_isCharacter = TRUE;
}
else {
m_roi = FindROI(p_name);
}
if (m_roi == NULL) {
m_roi = CharacterManager()->FUN_10085210(NULL, p_name, TRUE);
if (m_roi != NULL) {
m_unk0x14 = TRUE;
}
}
if (m_roi == NULL) {
return SUCCESS;
}
if (m_isCharacter) {
m_positionROI = m_roi->FindChildROI("head", m_roi);
}
else {
m_positionROI = m_roi;
}
if (MxOmni::IsSound3D()) {
const float* position = m_positionROI->GetWorldPosition();
m_ds3dBuffer->SetPosition(position[0], position[1], position[2], 0);
}
LegoEntity* entity = m_roi->GetEntity();
if (entity != NULL && entity->IsA("LegoActor") && ((LegoActor*) entity)->VTable0x50() != 0.0f) {
m_actor = ((LegoActor*) entity);
}
p_directSoundBuffer->GetFrequency(&m_dwFrequency);
if (m_actor != NULL) {
m_unk0x20 = m_actor->VTable0x50();
if (m_unk0x20 != 0.0) {
p_directSoundBuffer->SetFrequency(m_unk0x20 * m_dwFrequency);
}
}
return SUCCESS; return SUCCESS;
} }
@ -53,17 +105,17 @@ MxResult Lego3DSound::Create(LPDIRECTSOUNDBUFFER p_directSoundBuffer, const char
// FUNCTION: LEGO1 0x10011880 // FUNCTION: LEGO1 0x10011880
void Lego3DSound::Destroy() void Lego3DSound::Destroy()
{ {
if (m_dsBuffer) { if (m_ds3dBuffer) {
m_dsBuffer->Release(); m_ds3dBuffer->Release();
m_dsBuffer = NULL; m_ds3dBuffer = NULL;
} }
if (m_unk0x14 && m_unk0x0c && CharacterManager()) { if (m_unk0x14 && m_roi && CharacterManager()) {
if (m_unk0x15) { if (m_isCharacter) {
CharacterManager()->FUN_10083db0(m_unk0x0c); CharacterManager()->FUN_10083db0(m_roi);
} }
else { else {
CharacterManager()->FUN_10083f10(m_unk0x0c); CharacterManager()->FUN_10083f10(m_roi);
} }
} }