changeset 2540:abc6a9d079b9

.
author a.parshin
date Sat, 09 May 2015 12:55:58 +0200
parents 407263babde8
children a902abdfc7f2
files Engine/Game.cpp Media/Audio/AudioPlayer.h Media/MediaPlayer.cpp
diffstat 3 files changed, 136 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/Engine/Game.cpp	Sat May 09 12:19:09 2015 +0200
+++ b/Engine/Game.cpp	Sat May 09 12:55:58 2015 +0200
@@ -1022,8 +1022,123 @@
       }
     }
 }
+
+
+
+void DoThatMessageThing()
+{
+    if (pMessageQueue_50CBD0->uNumMessages)
+        pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+}
+
+
+
+void Game_StartDialogue(unsigned int actor_id)
+{
+    if (uActiveCharacter)
+    {
+        viewparams->field_48 = 1;
+
+        DoThatMessageThing();
+
+        dword_5B65D0_dialogue_actor_npc_id = pActors[actor_id].sNPC_ID;
+        GameUI_InitializeDialogue(&pActors[actor_id], true);
+    }
+}
+
+void Game_StartHirelingDialogue(unsigned int hireling_id)
+{
+    if (bNoNPCHiring || pCurrentScreen != 0)
+        return;
+
+    DoThatMessageThing();
+
+    uint hireling_slot = 0;
+    for (uint i = 0; i < 2; ++i)
+    {
+        if (pParty->pHirelings[i].pName)
+            pTmpBuf[hireling_slot++] = i;
+    }
+
+    for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
+    {
+        NPCData *npc = &pNPCStats->pNewNPCData[i];
+        if (npc->Hired()
+            && (!pParty->pHirelings[0].pName || strcmp(npc->pName, pParty->pHirelings[0].pName))
+            && (!pParty->pHirelings[1].pName || strcmp(npc->pName, pParty->pHirelings[1].pName)))
+            {
+                pTmpBuf[hireling_slot++] = i + 2;
+            }
+        }
+
+        if ((signed int)hireling_id + (signed int)pParty->hirelingScrollPosition < hireling_slot)
+        {
+            Actor actor;
+            memset(&actor, 0, sizeof(actor));
+            actor.sNPC_ID += -1 - pParty->hirelingScrollPosition - hireling_id;
+            GameUI_InitializeDialogue(&actor, true);
+        }
+}
+
+
+void Game_StartNewGameWhilePlaying(bool force_start)
+{
+    if (dword_6BE138 == 124 || force_start)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        DoThatMessageThing();
+        pGUIWindow_CurrentMenu->Release();
+        uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
+        pCurrentScreen = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 124;
+    }
+    stru_506E40.Release();
+}
+
+void Game_QuitGameWhilePlaying(bool force_quit)
+{
+    if (dword_6BE138 == 132 || force_quit)
+    {
+        pIcons_LOD->SyncLoadedFilesCount();
+        pIcons_LOD->RemoveTexturesPackFromTextureList();
+        if (pMessageQueue_50CBD0->uNumMessages)
+            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
+        pGUIWindow_CurrentMenu->Release();
+        pCurrentScreen = SCREEN_GAME;
+        viewparams->bRedrawGameUI = 1;
+        pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 0, 0, -1, 0, 0, 0, 0);
+        uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
+    }
+    else
+    {
+        ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
+        pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
+        dword_6BE138 = 132;
+    }
+    stru_506E40.Release();
+}
+
+void Game_OpenLoadGameDialog()
+{
+    pIcons_LOD->SyncLoadedFilesCount();
+    pIcons_LOD->RemoveTexturesPackFromTextureList();
+    DoThatMessageThing();
+    pGUIWindow_CurrentMenu->Release();
+    pCurrentScreen = SCREEN_LOADGAME;
+    LoadUI_Load(1);
+}
+
+
+
 //----- (004304E7) --------------------------------------------------------
-void  GameUI_MsgProc()
+void GameUI_MsgProc()
 {
   unsigned int v2; // edx@7
   Actor *pActor; // ecx@13
@@ -1180,139 +1295,18 @@
           pArcomageGame->bGameInProgress = 1;
           ArcomageGame::PrepareArcomage();
           continue;
-        case UIMSG_StartNPCDialogue:
-          if ( !uActiveCharacter )
-            continue;
-          viewparams->field_48 = 1;
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          dword_5B65D0_dialogue_actor_npc_id = pActors[uMessageParam].sNPC_ID;
-          pActor = &pActors[uMessageParam];
-          //goto _actor_init_dlg;
-          GameUI_InitializeDialogue(pActor, true);
-          continue;
+
+        case UIMSG_StartNPCDialogue:          Game_StartDialogue(uMessageParam); continue;
         case UIMSG_StartHireling1Dialogue:
-        case UIMSG_StartHireling2Dialogue:
-        {
-          if (bNoNPCHiring || pCurrentScreen)
-            continue;
-
-            if ( pMessageQueue_50CBD0->uNumMessages )
-              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-            uAction = 0;
-            int hireling_idx = uMessage - UIMSG_StartHireling1Dialogue;
-            v4 = 0;
-
-            for (uint i = 0; i < 2; ++i)
-            //pNPCData0 = pParty->pHirelings;
-            //do
-            {
-              if (pParty->pHirelings[i].pName)
-              //{
-                //v6 = uAction++;
-                pTmpBuf[uAction++] = i;
-              //}
-              //++pNPCData0;
-              //++v4;
-            }
-            //while ( (signed int)pNPCData0 < (signed int)&pParty->pPickedItem );
-
-            //_this = 0;
-            for (uint i = 0; i < pNPCStats->uNumNewNPCs; ++i)
-            {
-              NPCData* npc = &pNPCStats->pNewNPCData[i];
-              //do
-              //{
-                if (npc->Hired() &&
-                    (!pParty->pHirelings[0].pName || strcmp(npc->pName, pParty->pHirelings[0].pName)) &&
-                    (!pParty->pHirelings[1].pName || strcmp(npc->pName, pParty->pHirelings[1].pName)) )
-                {
-                  //v7 =;
-                  pTmpBuf[uAction++] = i + 2;
-                }
-                //++_this;
-                //++pNPCData4;
-              //}
-              //while ( _this < (signed int)pNPCStats->uNumNewNPCs );
-            }
-
-            if ( (signed int)(hireling_idx + pParty->hirelingScrollPosition) < uAction )
-            {
-              //Actor::Actor(&actor);
-              memset(&actor, 0, 0x344u);
-              actor.sNPC_ID += -1 - pParty->hirelingScrollPosition - hireling_idx;
-              pActor = &actor;
-              GameUI_InitializeDialogue(&actor, true);
-            }
-          }
-          continue;
-
-        case UIMSG_BuyInShop_Identify_Repair:
-          UIShop_Buy_Identify_Repair();
-          continue;
-        case UIMSG_ClickNPCTopic:
-          ClickNPCTopic(uMessageParam);
-          continue;
-        case UIMSG_SelectShopDialogueOption:
-          OnSelectShopDialogueOption(uMessageParam);
-          continue;
-        case UIMSG_SelectNPCDialogueOption:
-          OnSelectNPCDialogueOption((DIALOGUE_TYPE)uMessageParam);
-          continue;
-        case UIMSG_ClickHouseNPCPortrait:
-          _4B4224_UpdateNPCTopics(uMessageParam);
-          continue;
-        case UIMSG_StartNewGame:
-          if ( dword_6BE138 == 124 || uMessageParam )
-          {
-            pIcons_LOD->SyncLoadedFilesCount();
-            pIcons_LOD->RemoveTexturesPackFromTextureList();
-            if ( pMessageQueue_50CBD0->uNumMessages )
-              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-            pGUIWindow_CurrentMenu->Release();
-            uGameState = GAME_STATE_NEWGAME_OUT_GAMEMENU;
-            pCurrentScreen = SCREEN_GAME;
-            viewparams->bRedrawGameUI = 1;
-          }
-          else
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[201], 2);// "Are you sure?  Click again to start a New Game"
-            pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-            dword_6BE138 = 124;
-          }
-          stru_506E40.Release();
-          continue;
-        case UIMSG_Game_OpenLoadGameDialog:
-          pIcons_LOD->SyncLoadedFilesCount();
-          pIcons_LOD->RemoveTexturesPackFromTextureList();
-          if ( pMessageQueue_50CBD0->uNumMessages )
-            pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-          pGUIWindow_CurrentMenu->Release();
-          pCurrentScreen = SCREEN_LOADGAME;
-          LoadUI_Load(1);
-          continue;
-        case UIMSG_Quit:
-          if ( dword_6BE138 == 132 || uMessageParam )
-          {
-            pIcons_LOD->SyncLoadedFilesCount();
-            pIcons_LOD->RemoveTexturesPackFromTextureList();
-            if ( pMessageQueue_50CBD0->uNumMessages )
-              pMessageQueue_50CBD0->uNumMessages = pMessageQueue_50CBD0->pMessages[0].field_8 != 0;
-            pGUIWindow_CurrentMenu->Release();
-            pCurrentScreen = SCREEN_GAME;
-            viewparams->bRedrawGameUI = 1;
-            if ( !uMessageParam )
-              pAudioPlayer->PlaySound((SoundID)SOUND_wooddrclose, 0, 0, -1, 0, 0, 0, 0);
-            uGameState = GAME_STATE_GAME_QUITTING_TO_MAIN_MENU;
-          }
-          else
-          {
-            ShowStatusBarString(pGlobalTXT_LocalizationStrings[82], 2);// "Are you sure?  Click again to quit"
-            pAudioPlayer->PlaySound(SOUND_quest, 0, 0, -1, 0, 0, 0, 0);
-            dword_6BE138 = 132;
-          }
-          stru_506E40.Release();
-          continue;
+        case UIMSG_StartHireling2Dialogue:    Game_StartHirelingDialogue(uMessage - UIMSG_StartHireling1Dialogue); continue;
+        case UIMSG_BuyInShop_Identify_Repair: UIShop_Buy_Identify_Repair(); continue;
+        case UIMSG_ClickNPCTopic:             ClickNPCTopic(uMessageParam); continue;
+        case UIMSG_SelectShopDialogueOption:  OnSelectShopDialogueOption(uMessageParam); continue;
+        case UIMSG_SelectNPCDialogueOption:   OnSelectNPCDialogueOption((DIALOGUE_TYPE)uMessageParam); continue;
+        case UIMSG_ClickHouseNPCPortrait:     _4B4224_UpdateNPCTopics(uMessageParam); continue;
+        case UIMSG_StartNewGame:              Game_StartNewGameWhilePlaying(uMessageParam); continue;
+        case UIMSG_Game_OpenLoadGameDialog:   Game_OpenLoadGameDialog(); continue;
+        case UIMSG_Quit:                      Game_QuitGameWhilePlaying(uMessageParam); continue;
         case UIMSG_80:
 			__debugbreak();
           pIcons_LOD->SyncLoadedFilesCount();
@@ -2170,7 +2164,7 @@
                           continue;
                       }
                       GetHouseGoodbyeSpeech();
-                      pAudioPlayer->PlaySound(SOUND_wooddrclose, 814, 0, -1, 0, 0, 0, 0);
+                      pAudioPlayer->PlaySound(SOUND_WoodDoorClosing, 814, 0, -1, 0, 0, 0, 0);
                       pMediaPlayer->Unload();
                       pGUIWindow_CurrentMenu = window_SpeakInHouse;
                       if ( pGUIWindow_Settings )
--- a/Media/Audio/AudioPlayer.h	Sat May 09 12:19:09 2015 +0200
+++ b/Media/Audio/AudioPlayer.h	Sat May 09 12:55:58 2015 +0200
@@ -75,7 +75,7 @@
 {
   SOUND_Invalid = 0,
   SOUND_enter = 6,
-  SOUND_wooddrclose = 7,
+  SOUND_WoodDoorClosing = 7,
   SOUND_fireBall = 0x8,
   SOUND_ClickMinus = 0x14,//20
   SOUND_ClickMovingSelector = 0x15,//21
--- a/Media/MediaPlayer.cpp	Sat May 09 12:19:09 2015 +0200
+++ b/Media/MediaPlayer.cpp	Sat May 09 12:55:58 2015 +0200
@@ -319,7 +319,8 @@
 
       if (swr_init(converter) < 0)
       {
-        __debugbreak();
+          Log::Warning(L"swr_init: failed");
+        //__debugbreak();
         swr_free(&converter);
         return;
       }
@@ -329,16 +330,18 @@
       //int dst_nb_channels = av_get_channel_layout_nb_channels(dst_channel_layout);
       if (av_samples_alloc_array_and_samples(&dst_channels, dst_linesize, 2, num_channels * num_samples, AV_SAMPLE_FMT_S16, 0) < 0)
       {
-        __debugbreak();
+          Log::Warning(L"av_samples_alloc_array_and_samples: failed");
+        //__debugbreak();
         swr_free(&converter);
         return;
       }
 
       if (swr_convert(converter, dst_channels, num_channels * num_samples, (const uint8_t **)channels, num_channels * num_samples) >= 0) //Invalid partial memory access, Uninitialized memory access
 
-        stream->Write(dst_channels[0], num_channels * num_samples * sizeof(__int16));
+          stream->Write(dst_channels[0], num_channels * num_samples * sizeof(__int16));
       else
-        __debugbreak();
+          //__debugbreak();
+          Log::Warning(L"swr_convert: failed");
 
       av_free(dst_channels[0]);
       swr_free(&converter);