# HG changeset patch # User Nomad # Date 1361564811 -7200 # Node ID 5bea494a2365edc22dd7a54b47c7f6e3a19c490d # Parent 50875632e7769a1de6710c1e71b749b1d9707856 AudioPlayer::UpdateSounds (004AAFCF) take 2 diff -r 50875632e776 -r 5bea494a2365 AudioPlayer.cpp --- a/AudioPlayer.cpp Fri Feb 22 21:59:28 2013 +0200 +++ b/AudioPlayer.cpp Fri Feb 22 22:26:51 2013 +0200 @@ -607,7 +607,7 @@ { if ( v6->source_pid == a2 ) { - if ( AIL_sample_status(v6->hSample) == 4 ) + if ( AIL_sample_status(v6->hSample) == AIL::Sample::Playing) { AIL_end_sample(v6->hSample); _4ABE55(v6); @@ -623,10 +623,6 @@ } } } -// 4D82F4: using guessed type int __stdcall AIL_3D_sample_status(int); -// 4D82F8: using guessed type int __stdcall AIL_sample_status(int); -// 4D82FC: using guessed type int __stdcall AIL_end_sample(int); -// 4D8300: using guessed type int __stdcall AIL_end_3D_sample(int); //----- (004AA306) -------------------------------------------------------- void AudioPlayer::PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int PartyX, signed int PartyY, int a7, unsigned int uVolume, int sPlaybackRate) @@ -783,8 +779,8 @@ pMixerChannel = pAudioPlayer->pMixerChannels; do { - if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->source_pid == a3 - && AIL_sample_status(pMixerChannel->hSample) == 4 ) + if ( AIL_sample_status(pMixerChannel->hSample) == AIL::Sample::Playing && pMixerChannel->source_pid == a3 + && AIL_sample_status(pMixerChannel->hSample) == AIL::Sample::Playing) { if ( pMixerChannel->uSourceTrackIdx == pNum ) return; @@ -804,7 +800,7 @@ if ( varC <= v96 ) { pMixerChannel2 = &pAudioPlayer->pMixerChannels[varC]; - while ( AIL_sample_status(pMixerChannel2->hSample) != 2 ) + while ( AIL_sample_status(pMixerChannel2->hSample) != AIL::Sample::Done) { ++v62; ++pMixerChannel2; @@ -1386,17 +1382,17 @@ //BLVDoor *v39; // edi@56 //int v40; // eax@57 //int v41; // eax@60 - MixerChannel *v42; // edi@65 - int v43; // ebx@68 - LevelDecoration *v44; // esi@68 - int v45; // ST1C_4@68 - int v46; // edi@68 - int v47; // eax@68 - DecorationDesc *v48; // edi@69 - __int16 v49; // ax@69 - __int16 v50; // ax@70 + //MixerChannel *v42; // edi@65 + //int v43; // ebx@68 + //LevelDecoration *v44; // esi@68 + //int v45; // ST1C_4@68 + //int v46; // edi@68 + //int v47; // eax@68 + //DecorationDesc *v48; // edi@69 + //__int16 v49; // ax@69 + //__int16 v50; // ax@70 __int16 v51; // ax@71 - __int16 v52; // ax@73 + //__int16 v52; // ax@73 signed int v53; // eax@88 RenderVertexSoft a1; // [sp+24h] [bp-48h]@1 float v55; // [sp+54h] [bp-18h]@22 @@ -1586,14 +1582,9 @@ _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, @@ -1622,19 +1613,20 @@ break; case OBJECT_Item: + { + assert(source_id < uNumLayingItems); + auto object = &pLayingItems[source_id]; + + source_x = object->vPosition.x; + source_y = object->vPosition.y; + source_z = object->vPosition.z; + } + break; + case OBJECT_Decoration: { - LayingItem *object = nullptr; - if (source_type == OBJECT_Item) - { - assert(source_id < uNumLayingItems); - object = &pLayingItems[source_id]; - } - else - { - assert(source_id < uNumLevelDecorations); - object = (LayingItem *)&pLevelDecorations[source_id]; - } + assert(source_id < uNumLevelDecorations); + auto object = (LayingItem *)&pLevelDecorations[source_id]; source_x = object->vPosition.x; source_y = object->vPosition.y; @@ -1671,80 +1663,88 @@ } + + if (pCurrentScreen != SCREEN_GAME) + { + auto channel = &pMixerChannels[4]; + if (AIL_sample_status(channel->hSample) == AIL::Sample::Playing) + AIL_end_sample(channel->hSample); + return; + } + if (!_6807E0_num_decorations_with_sounds_6807B8) + return; + v55 = 0; - if ( pCurrentScreen != SCREEN_GAME ) - { - v42 = &pAudioPlayer->pMixerChannels[4]; - if ( AIL_sample_status(v42->hSample) == 4 ) - AIL_end_sample(v42->hSample); - return; - } - v59 = v2; - if ( _6807E0_num_decorations_with_sounds_6807B8 <= v2 ) - return; - while ( 1 ) - { + //v59 = 0; + for (uint i = 0; i < _6807E0_num_decorations_with_sounds_6807B8; ++i) + { + //while ( 1 ) + //{ LODWORD(v56) = 1; - v43 = 4 * v59 + 6817720; - v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]]; - v45 = abs(v44->vPosition.z - pParty->vPosition.z); - v46 = abs(v44->vPosition.y - pParty->vPosition.y); - v47 = abs(v44->vPosition.x - pParty->vPosition.x); - if ( int_get_vector_length(v47, v46, v45) <= 8192 ) - break; -LABEL_89: - ++v59; - if ( v59 >= _6807E0_num_decorations_with_sounds_6807B8 ) - return; - } - v48 = &pDecorationList->pDecorations[v44->uDecorationDescID]; - v49 = v48->uFlags; - uNumRepeats = (~(unsigned __int8)v48->uFlags & 0x40) >> 6; - if ( HIBYTE(v49) & 3 ) - { - v50 = v44->field_1A; + //v43 = _6807B8_level_decorations_ids[v59]; + //v44 = &pLevelDecorations[_6807B8_level_decorations_ids[v59]]; + //v45 = abs(v44->vPosition.z - pParty->vPosition.z); + //v46 = abs(v44->vPosition.y - pParty->vPosition.y); + //v47 = abs(v44->vPosition.x - pParty->vPosition.x); + auto decor = &pLevelDecorations[_6807B8_level_decorations_ids[i]]; + if (int_get_vector_length(decor->vPosition.x - pParty->vPosition.x, + decor->vPosition.y - pParty->vPosition.y, + decor->vPosition.z - pParty->vPosition.z) > 8192) + continue; + + auto decor_desc = &pDecorationList->pDecorations[decor->uDecorationDescID]; + //v48 = &pDecorationList->pDecorations[decor->uDecorationDescID]; + //v49 = v48->uFlags; + uNumRepeats = (~(unsigned __int8)decor_desc->uFlags & 0x40) >> 6; + + if (decor_desc->SoundOnDawn() || decor_desc->SoundOnDusk()) + { + //v50 = decor->field_1A; v55 = 0.0; uNumRepeats = 2; - if ( v50 ) + if (decor->field_1A) { - v51 = v50 - 32; - v44->field_1A = v51; + v51 = decor->field_1A - 32; + decor->field_1A = v51; if ( v51 < 0 ) - v44->field_1A = 0; + decor->field_1A = 0; } - } - v52 = v48->uFlags; - if ( !(HIBYTE(v52) & 1) ) - { - if ( !(HIBYTE(v52) & 2) ) - goto LABEL_84; - if ( v55 != 0.0 ) - goto LABEL_85; - } - v56 = 0.0; - if ( pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 - || pParty->uCurrentHour >= 0x14 && pParty->uCurrentHour < 0x15 ) - { - if ( !v44->field_1A && rand() % 100 < 100 ) + } + + //v52 = v48->uFlags; + if (!decor_desc->SoundOnDawn()) + { + if (!decor_desc->SoundOnDusk()) + goto LABEL_84; + if ( v55 != 0.0 ) + goto LABEL_85; + } + v56 = 0.0; + + if (pParty->uCurrentHour >= 5 && pParty->uCurrentHour < 6 || + pParty->uCurrentHour >= 20 && pParty->uCurrentHour < 21) + { + if ( !decor->field_1A && rand() % 100 < 100 ) LODWORD(v56) = 1; LODWORD(v55) = 1; - } + } LABEL_84: if ( v55 == 0.0 ) { LABEL_87: if ( v56 != 0.0 ) { - v53 = 8 * *(int *)v43; - LOBYTE(v53) = v53 | 5; - PlaySound((SoundID)v48->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); + v53 = 8 * _6807B8_level_decorations_ids[i]; + LOBYTE(v53) = v53 | OBJECT_Decoration; + PlaySound((SoundID)decor_desc->uSoundID, v53, uNumRepeats, -1, 0, 0, 0, 0); } - goto LABEL_89; + continue; } LABEL_85: - if ( !v44->field_1A ) - v44->field_1A = (rand() % 15 + 1) << 7; + if ( !decor->field_1A ) + decor->field_1A = (rand() % 15 + 1) << 7; goto LABEL_87; + } } @@ -2200,7 +2200,7 @@ v9 = *(int *)v7; ++v16; v14[v8] = v2; - if ( AIL_sample_status((HSAMPLE)v9) == 4 ) + if ( AIL_sample_status((HSAMPLE)v9) == AIL::Sample::Playing) ++v15; } ++v2; @@ -2230,8 +2230,6 @@ } } } -// 4D82F8: using guessed type int __stdcall AIL_sample_status(int); -// 4ABE55: using guessed type int var_48[16]; diff -r 50875632e776 -r 5bea494a2365 DecorationList.h --- a/DecorationList.h Fri Feb 22 21:59:28 2013 +0200 +++ b/DecorationList.h Fri Feb 22 22:26:51 2013 +0200 @@ -25,6 +25,9 @@ #pragma pack(push, 1) struct DecorationDesc { + inline bool SoundOnDawn() {return uFlags & DECORATION_SOUND_ON_DAWN;} + inline bool SoundOnDusk() {return uFlags & DECORATION_SOUND_ON_DUSK;} + char pName[32]; char field_20[32]; __int16 uType;