Mercurial > mm7
diff AudioPlayer.cpp @ 378:50875632e776
AudioPlayer::UpdateSounds (004AAFCF) take 1
author | Nomad |
---|---|
date | Fri, 22 Feb 2013 21:59:28 +0200 |
parents | 8e23edf57e27 |
children | 5bea494a2365 |
line wrap: on
line diff
--- a/AudioPlayer.cpp Fri Feb 22 18:40:38 2013 +0200 +++ b/AudioPlayer.cpp Fri Feb 22 21:59:28 2013 +0200 @@ -1,4 +1,5 @@ #include <string> +#include <assert.h> #include "AudioPlayer.h" #include "Allocator.h" @@ -13,6 +14,8 @@ #include "OSInfo.h" #include "Math.h" #include "MapInfo.h" +#include "Actor.h" +#include "GUIWindow.h" #include "Log.h" #include "Bink_Smacker.h" @@ -602,7 +605,7 @@ v6 = v2->pMixerChannels; do { - if ( v6->dword_000004 == a2 ) + if ( v6->source_pid == a2 ) { if ( AIL_sample_status(v6->hSample) == 4 ) { @@ -780,7 +783,7 @@ pMixerChannel = pAudioPlayer->pMixerChannels; do { - if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->dword_000004 == a3 + if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->source_pid == a3 && AIL_sample_status(pMixerChannel->hSample) == 4 ) { if ( pMixerChannel->uSourceTrackIdx == pNum ) @@ -903,7 +906,7 @@ AIL_set_sample_loop_count(pMixerChannel5->hSample, uNumRepeats - 1); v85 = pMixerChannel5->hSample; pMixerChannel5->uSourceTrackIdx = pNum; - pMixerChannel5->dword_000004 = v76; + pMixerChannel5->source_pid = v76; pMixerChannel5->uSourceTrackID = eSoundID; AIL_start_sample(v85); if ( sPlaybackRate ) @@ -1340,13 +1343,13 @@ //----- (004AAFCF) -------------------------------------------------------- -void AudioPlayer::_4AAFCF() +void AudioPlayer::UpdateSounds() { - AudioPlayer *pAudioPlayer; // edi@1 + //AudioPlayer *pAudioPlayer; // edi@1 int v2; // ebx@1 - unsigned __int8 v3; // zf@1 - int *v4; // eax@2 - unsigned __int8 v5; // sf@4 + //unsigned __int8 v3; // zf@1 + //int *v4; // eax@2 + //unsigned __int8 v5; // sf@4 AudioPlayer_3DSample *v6; // esi@5 int v7; // ebx@6 int v8; // ebx@9 @@ -1369,20 +1372,20 @@ int v25; // eax@32 float v26; // ST10_4@34 float v27; // ST08_4@34 - MixerChannel *v28; // esi@38 - unsigned __int8 v29; // of@43 - MixerChannel *v30; // esi@44 - int v31; // eax@45 - LayingItem *v32; // eax@49 - Actor *v33; // edi@50 - int v34; // eax@50 - unsigned int v35; // edx@51 - unsigned int v36; // ecx@51 - LayingItem *v37; // edi@53 + //MixerChannel *v28; // esi@38 + //unsigned __int8 v29; // of@43 + //MixerChannel *v30; // esi@44 + //int v31; // eax@45 + //LayingItem *v32; // eax@49 + //Actor *v33; // edi@50 + //int v34; // eax@50 + //unsigned int v35; // edx@51 + //unsigned int v36; // ecx@51 + //LayingItem *v37; // edi@53 int v38; // eax@53 - BLVDoor *v39; // edi@56 - int v40; // eax@57 - int v41; // eax@60 + //BLVDoor *v39; // edi@56 + //int v40; // eax@57 + //int v41; // eax@60 MixerChannel *v42; // edi@65 int v43; // ebx@68 LevelDecoration *v44; // esi@68 @@ -1401,27 +1404,32 @@ int uNumRepeats; // [sp+5Ch] [bp-10h]@15 float v58; // [sp+60h] [bp-Ch]@23 int v59; // [sp+64h] [bp-8h]@4 - AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 + //AudioPlayer *thisa; // [sp+68h] [bp-4h]@1 - pAudioPlayer = this; + //pAudioPlayer = this; v2 = 0; - thisa = this; - v3 = this->bPlayerReady == 0; - a1.flt_2C = 0.0; - if ( !v3 ) + //thisa = this; + //v3 = this->bPlayerReady == 0; + //a1.flt_2C = 0.0; + if (!bPlayerReady) + return; + + if (field_2D0_time_left <= pEventTimer->uTimeElapsed) + field_2D0_time_left = 32; + else { - v4 = &this->field_2D0_time_left; - *v4 -= pEventTimer->uTimeElapsed; - if ( this->field_2D0_time_left <= 0 ) - { - v3 = this->b3DSoundInitialized == 0; - *v4 = 32; - if ( !v3 ) + field_2D0_time_left -= pEventTimer->uTimeElapsed; + return; + } + + //v3 = this->b3DSoundInitialized == 0; + if (b3DSoundInitialized) { - v3 = this->uNum3DSamples == 0; - v5 = this->uNum3DSamples < 0; + __debugbreak(); // refactor refactor + //v3 = this->uNum3DSamples == 0; + //v5 = this->uNum3DSamples < 0; v59 = 0; - if ( !(v5 | v3) ) + if (uNum3DSamples > 0) { v6 = this->p3DSamples; while ( 1 ) @@ -1459,6 +1467,7 @@ goto LABEL_37; } } + v9 = v8 - 1; if ( v9 ) { @@ -1561,105 +1570,109 @@ goto LABEL_35; } } + + + + + + + LABEL_37: - if ( pAudioPlayer->uMixerChannels > v2 ) + for (uint i = 0; i < uMixerChannels; ++i) + { + auto channel = pMixerChannels + i; + + AIL_end_sample(channel->hSample); + _4ABE55(channel); + } + + //v59 = 0; + for (uint i = 0; i < uMixerChannels; ++i) + { + //v30 = pAudioPlayer->pMixerChannels; + auto channel = pMixerChannels + i; + //while ( 1 ) + //{ + //v31 = v30->dword_000004; + int source_type = channel->source_pid & 7, + source_id = channel->source_pid >> 3; + int source_x, + source_y, + source_z; + + switch (source_type) + { + case 0: + case OBJECT_Player: + continue; + + case OBJECT_BLVDoor: { - v28 = pAudioPlayer->pMixerChannels; - do - { - if ( AIL_sample_status(v28->hSample) == 2 ) - { - AIL_end_sample(v28->hSample); - pAudioPlayer->_4ABE55(v28); - } - ++v2; - ++v28; - } - while ( v2 < pAudioPlayer->uMixerChannels ); - v2 = 0; + assert(uCurrentlyLoadedLevelType == LEVEL_Indoor); + + assert(source_id < pIndoor->uNumDoors); + auto door = pIndoor->pDoors + source_id; + if (!door->uDoorID) + continue; + + source_x = door->pXOffsets[0]; + source_y = door->pYOffsets[0]; + source_z = door->pZOffsets[0]; } - //v29 = __OFSUB__(v1->uMixerChannels, v2); - v29 = pAudioPlayer->uMixerChannels > v2; - v3 = pAudioPlayer->uMixerChannels == v2; - v5 = pAudioPlayer->uMixerChannels - v2 < 0; - v59 = v2; - if ( !((unsigned __int8)(v5 ^ v29) | v3) ) + break; + + case OBJECT_Item: + case OBJECT_Decoration: { - v30 = pAudioPlayer->pMixerChannels; - while ( 1 ) + LayingItem *object = nullptr; + if (source_type == OBJECT_Item) { - v31 = v30->dword_000004; - if ( (v30->dword_000004 & 7) == 1 ) - { - if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) - { - v39 = &pIndoor->pDoors[v31 >> 3]; - if ( !v39->uDoorID ) - { -LABEL_61: - pAudioPlayer = thisa; - goto LABEL_62; - } - v40 = GetSoundStrengthByDistanceFromParty(*v39->pXOffsets, *v39->pYOffsets, *v39->pZOffsets); - if ( !v40 ) - { -LABEL_58: - AIL_end_sample(v30->hSample); - thisa->_4ABE55(v30); - goto LABEL_61; - } - AIL_set_sample_volume(v30->hSample, v40); - v35 = *v39->pYOffsets; - v36 = *v39->pXOffsets; -LABEL_60: - v41 = sub_4AB66C(v36, v35); - AIL_set_sample_pan(v30->hSample, v41); - goto LABEL_61; - } - } - else - { - if ( (v30->dword_000004 & 7) == 2 ) - { - v32 = &pLayingItems[v31 >> 3]; - goto LABEL_53; - } - if ( (v30->dword_000004 & 7) == 3 ) - { - v33 = &pActors[v31 >> 3]; - v34 = GetSoundStrengthByDistanceFromParty(v33->vPosition.x, v33->vPosition.y, v33->vPosition.z); - if ( !v34 ) - goto LABEL_58; - AIL_set_sample_volume(v30->hSample, v34); - v35 = v33->vPosition.y; - v36 = v33->vPosition.x; - goto LABEL_60; - } - if ( (v30->dword_000004 & 7) == 5 ) - { - v32 = (LayingItem *)&pLevelDecorations[v31 >> 3]; -LABEL_53: - v37 = v32; - v38 = GetSoundStrengthByDistanceFromParty(v32->vPosition.x, v32->vPosition.y, v32->vPosition.z); - if ( !v38 ) - goto LABEL_58; - AIL_set_sample_volume(v30->hSample, v38); - v35 = v37->vPosition.y; - v36 = v37->vPosition.x; - goto LABEL_60; - } - } -LABEL_62: - ++v59; - ++v30; - if ( v59 >= pAudioPlayer->uMixerChannels ) - { - v2 = 0; - break; - } + assert(source_id < uNumLayingItems); + object = &pLayingItems[source_id]; + } + else + { + assert(source_id < uNumLevelDecorations); + object = (LayingItem *)&pLevelDecorations[source_id]; } + + source_x = object->vPosition.x; + source_y = object->vPosition.y; + source_z = object->vPosition.z; } - if ( pCurrentScreen != v2 ) + break; + + case OBJECT_Actor: + { + assert(source_id < uNumActors); + auto actor = pActors + source_id; + + source_x = actor->vPosition.x; + source_y = actor->vPosition.y; + source_z = actor->vPosition.z; + } + break; + + default: + assert(false); + continue; + } + + if (auto sound_strength = GetSoundStrengthByDistanceFromParty(source_x, source_y, source_z)) + { + AIL_set_sample_volume(channel->hSample, sound_strength); + AIL_set_sample_pan(channel->hSample, sub_4AB66C(source_x, source_y)); + } + else + { + AIL_end_sample(channel->hSample); + _4ABE55(channel); + } + } + + + v55 = 0; + if ( pCurrentScreen != SCREEN_GAME ) { v42 = &pAudioPlayer->pMixerChannels[4]; if ( AIL_sample_status(v42->hSample) == 4 ) @@ -1724,7 +1737,7 @@ { v53 = 8 * *(int *)v43; LOBYTE(v53) = v53 | 5; - thisa->PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); + PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); } goto LABEL_89; } @@ -1732,8 +1745,6 @@ if ( !v44->field_1A ) v44->field_1A = (rand() % 15 + 1) << 7; goto LABEL_87; - } - } } @@ -1825,7 +1836,7 @@ { AIL_end_sample(pChannel->hSample); _4ABE55(pChannel); - pChannel->dword_000004 = 0; + pChannel->source_pid = 0; } ++v6; ++pChannel;