changeset 383:c3a0d94c07a5

Merge
author Gloval
date Fri, 22 Feb 2013 23:47:26 +0400
parents a4a5996fea5b (current diff) 39a60868e9c7 (diff)
children c31e87e41131 b509ef97807a d95a91011d57 7189d0bddf07
files Indoor.cpp
diffstat 6 files changed, 228 insertions(+), 214 deletions(-) [+]
line wrap: on
line diff
--- a/AudioPlayer.cpp	Fri Feb 22 23:46:31 2013 +0400
+++ b/AudioPlayer.cpp	Fri Feb 22 23:47:26 2013 +0400
@@ -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,9 +605,9 @@
             v6 = v2->pMixerChannels;
             do
             {
-              if ( v6->dword_000004 == a2 )
+              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);
@@ -620,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)
@@ -780,8 +779,8 @@
             pMixerChannel = pAudioPlayer->pMixerChannels;
             do
             {
-              if ( AIL_sample_status(pMixerChannel->hSample) == 4 && pMixerChannel->dword_000004 == 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;
@@ -801,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;
@@ -903,7 +902,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 +1339,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,31 +1368,31 @@
   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
-  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
+  //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
   __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
@@ -1401,27 +1400,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 +1463,7 @@
               goto LABEL_37;
             }
           }
+
           v9 = v8 - 1;
           if ( v9 )
           {
@@ -1561,178 +1566,184 @@
           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);
+  }
+
+  for (uint i = 0; i < uMixerChannels; ++i)
+  {
+    auto channel = pMixerChannels + i;
+    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:
+      {
+        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:
       {
-        v30 = pAudioPlayer->pMixerChannels;
-        while ( 1 )
-        {
-          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 < uNumLevelDecorations);
+        auto object = (LayingItem *)&pLevelDecorations[source_id];
+
+        source_x = object->vPosition.x;
+        source_y = object->vPosition.y;
+        source_z = object->vPosition.z;
+      }
+      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;
       }
-      if ( pCurrentScreen != v2 )
-      {
-        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 )
-      {
+      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);
+    }
+  }
+
+
+
+  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;
+      //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;
-          thisa->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;
-    }
   }
 }
 
@@ -1825,7 +1836,7 @@
         {
           AIL_end_sample(pChannel->hSample);
           _4ABE55(pChannel);
-          pChannel->dword_000004 = 0;
+          pChannel->source_pid = 0;
         }
         ++v6;
         ++pChannel;
@@ -2189,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;
@@ -2219,8 +2230,6 @@
     }
   }
 }
-// 4D82F8: using guessed type int __stdcall AIL_sample_status(int);
-// 4ABE55: using guessed type int var_48[16];
 
 
 
--- a/AudioPlayer.h	Fri Feb 22 23:46:31 2013 +0400
+++ b/AudioPlayer.h	Fri Feb 22 23:47:26 2013 +0400
@@ -56,11 +56,11 @@
 struct MixerChannel
 {
   inline MixerChannel():
-    hSample(nullptr), dword_000004(0), uSourceTrackIdx(0), uSourceTrackID(0)
+    hSample(nullptr), source_pid(0), uSourceTrackIdx(0), uSourceTrackID(0)
   {}
 
   _SAMPLE *hSample;
-  int dword_000004;
+  int source_pid;
   unsigned int uSourceTrackIdx;
   unsigned int uSourceTrackID;
 };
@@ -144,7 +144,7 @@
   void SetMasterVolume(float fVolume);
   void _4AA258(int a2);
   void PlaySound(SoundID eSoundID, signed int a3, unsigned int uNumRepeats, signed int a5, signed int a6, int a7, unsigned int uVolume, int sPlaybackRate);
-  void _4AAFCF();
+  void UpdateSounds();
   void StopChannels(int uStartChannel, int uEndChannel);
   void LoadAudioSnd();
   void Initialize(HWND hWnd);
--- a/DecorationList.h	Fri Feb 22 23:46:31 2013 +0400
+++ b/DecorationList.h	Fri Feb 22 23:47:26 2013 +0400
@@ -25,6 +25,11 @@
 #pragma pack(push, 1)
 struct DecorationDesc
 {
+  inline bool CanMoveThrough() {return uFlags & DECORATION_MOVE_THROUGH;}
+  inline bool DontDraw()       {return uFlags & DECORATION_DONT_DRAW;} 
+  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;
--- a/Game.cpp	Fri Feb 22 23:46:31 2013 +0400
+++ b/Game.cpp	Fri Feb 22 23:47:26 2013 +0400
@@ -328,7 +328,7 @@
         v16 = 0;
         viewparams->bRedrawGameUI = true;
       }
-      //pAudioPlayer->_4AAFCF();//Ritor1: it's temporarily, game crash. decorations sounds
+      pAudioPlayer->UpdateSounds();
       if (uGameState == 1)
         //goto LABEL_96;
       {
--- a/Indoor.cpp	Fri Feb 22 23:46:31 2013 +0400
+++ b/Indoor.cpp	Fri Feb 22 23:47:26 2013 +0400
@@ -4616,7 +4616,7 @@
     if ( !(pDecortaion->field_2 & 0x20) )
     {
       v17 = &pDecorationList->pDecorations[pDecortaion->uDecorationDescID];
-      if ( !((unsigned __int8)2 & v17->uFlags) )
+      if (!v17->DontDraw())
         {
           v18 = v17->uLightRadius;
           if ( v18 )
--- a/mm7_4.cpp	Fri Feb 22 23:46:31 2013 +0400
+++ b/mm7_4.cpp	Fri Feb 22 23:47:26 2013 +0400
@@ -1165,7 +1165,7 @@
     if ( !(v1->field_2 & 0x20) )
     {
       v2 = &pDecorationList->pDecorations[v1->uDecorationDescID];
-      if ( !(v2->uFlags & 1) )
+      if (!v2->CanMoveThrough())
       {
         v3 = v2->uRadius;
         v4 = v1->vPosition.x;
@@ -1274,7 +1274,7 @@
                 if ( !(v5->field_2 & 0x20) )
                 {
                   v6 = &pDecorationList->pDecorations[v5->uDecorationDescID];
-                  if ( !(v6->uFlags & 1) )
+                  if (!v6->CanMoveThrough())
                   {
                     v7 = v6->uRadius;
                     v8 = v5->vPosition.x;