comparison GUI/UI/UiGame.cpp @ 2541:a902abdfc7f2

1. Renamed class Game to class Engine. 2. Separated game logic as state of FSM from game logic as engine. 3. Found out that many UI screen initializers were optimized away, intially they all returned newly created window as separate object like it is done in CharacterUI_Initialize.
author a.parshin
date Sun, 10 May 2015 01:29:11 +0200
parents c7264ab7132f
children c674d547cc7c
comparison
equal deleted inserted replaced
2540:abc6a9d079b9 2541:a902abdfc7f2
1 #define _CRTDBG_MAP_ALLOC 1 #define _CRTDBG_MAP_ALLOC
2 #include <stdlib.h> 2 #include <stdlib.h>
3 #include <crtdbg.h> 3 #include <crtdbg.h>
4 4
5 #define _CRT_SECURE_NO_WARNINGS 5 #define _CRT_SECURE_NO_WARNINGS
6
7 #include "Engine/Engine.h"
8
6 #include "..\../Engine/Events.h" 9 #include "..\../Engine/Events.h"
7 #include "..\../Engine/Graphics/Texture.h" 10 #include "..\../Engine/Graphics/Texture.h"
8 #include "..\../Engine/MM7.h"
9 #include "..\../Engine/ErrorHandling.h"
10 11
11 #include "..\../IO/Mouse.h" 12 #include "..\../IO/Mouse.h"
12 #include "..\../IO/Keyboard.h" 13 #include "..\../IO/Keyboard.h"
13 #include "..\../Engine/mm7_data.h"
14 14
15 #include "..\../Engine/Graphics/Vis.h" 15 #include "..\../Engine/Graphics/Vis.h"
16 #include "..\../Engine/MapInfo.h" 16 #include "..\../Engine/MapInfo.h"
17 #include "..\../Engine/Game.h"
18 #include "..\../GUI/GUIWindow.h" 17 #include "..\../GUI/GUIWindow.h"
19 #include "..\../GUI/GUIFont.h" 18 #include "..\../GUI/GUIFont.h"
20 #include "..\../Engine/Party.h" 19 #include "..\../Engine/Party.h"
21 #include "..\../Media/Audio/AudioPlayer.h" 20 #include "..\../Media/Audio/AudioPlayer.h"
22 #include "..\../Engine/Graphics/Outdoor.h" 21 #include "..\../Engine/Graphics/Outdoor.h"
66 } 65 }
67 if( player->CanAct() || !pPlayers[uActiveCharacter]->CanAct() ) 66 if( player->CanAct() || !pPlayers[uActiveCharacter]->CanAct() )
68 player->PlaySound(SPEECH_NoRoom, 0); 67 player->PlaySound(SPEECH_NoRoom, 0);
69 } 68 }
70 69
71 if (pCurrentScreen == SCREEN_GAME) 70 if (current_screen_type == SCREEN_GAME)
72 { 71 {
73 viewparams->bRedrawGameUI = true; 72 viewparams->bRedrawGameUI = true;
74 if ( uActiveCharacter != uPlayerID ) 73 if ( uActiveCharacter != uPlayerID )
75 { 74 {
76 if ( pPlayers[uPlayerID]->uTimeToRecovery ) 75 if ( pPlayers[uPlayerID]->uTimeToRecovery )
77 return; 76 return;
78 77
79 uActiveCharacter = uPlayerID; 78 uActiveCharacter = uPlayerID;
80 return; 79 return;
81 } 80 }
82 pGUIWindow_CurrentMenu = CharacterUI_Initialize(7); 81 pGUIWindow_CurrentMenu = CharacterUI_Initialize(SCREEN_CHARACTERS);
83 return; 82 return;
84 } 83 }
85 if ( pCurrentScreen == SCREEN_SPELL_BOOK ) 84 if ( current_screen_type == SCREEN_SPELL_BOOK )
86 return; 85 return;
87 if ( pCurrentScreen == SCREEN_CHEST ) 86 if ( current_screen_type == SCREEN_CHEST )
88 { 87 {
89 viewparams->bRedrawGameUI = true; 88 viewparams->bRedrawGameUI = true;
90 if ( uActiveCharacter == uPlayerID ) 89 if ( uActiveCharacter == uPlayerID )
91 { 90 {
92 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103; 91 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
93 pCurrentScreen = SCREEN_CHEST_INVENTORY; 92 current_screen_type = SCREEN_CHEST_INVENTORY;
94 uActiveCharacter = uPlayerID; 93 uActiveCharacter = uPlayerID;
95 return; 94 return;
96 } 95 }
97 if ( pPlayers[uPlayerID]->uTimeToRecovery ) 96 if ( pPlayers[uPlayerID]->uTimeToRecovery )
98 return; 97 return;
99 uActiveCharacter = uPlayerID; 98 uActiveCharacter = uPlayerID;
100 return; 99 return;
101 } 100 }
102 if ( pCurrentScreen != SCREEN_HOUSE ) 101 if ( current_screen_type != SCREEN_HOUSE )
103 { 102 {
104 if ( pCurrentScreen == SCREEN_E ) 103 if ( current_screen_type == SCREEN_E )
105 { 104 {
106 uActiveCharacter = uPlayerID; 105 uActiveCharacter = uPlayerID;
107 return; 106 return;
108 } 107 }
109 if ( pCurrentScreen != SCREEN_CHEST_INVENTORY ) 108 if ( current_screen_type != SCREEN_CHEST_INVENTORY )
110 { 109 {
111 viewparams->bRedrawGameUI = true; 110 viewparams->bRedrawGameUI = true;
112 uActiveCharacter = uPlayerID; 111 uActiveCharacter = uPlayerID;
113 if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 102 ) 112 if ( pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] == 102 )
114 FillAwardsData(); 113 FillAwardsData();
116 } 115 }
117 viewparams->bRedrawGameUI = true; 116 viewparams->bRedrawGameUI = true;
118 if ( uActiveCharacter == uPlayerID ) 117 if ( uActiveCharacter == uPlayerID )
119 { 118 {
120 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103; 119 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
121 pCurrentScreen = SCREEN_CHEST_INVENTORY; 120 current_screen_type = SCREEN_CHEST_INVENTORY;
122 uActiveCharacter = uPlayerID; 121 uActiveCharacter = uPlayerID;
123 return; 122 return;
124 } 123 }
125 if ( pPlayers[uPlayerID]->uTimeToRecovery ) 124 if ( pPlayers[uPlayerID]->uTimeToRecovery )
126 return; 125 return;
137 } 136 }
138 if (dialog_menu_id == HOUSE_DIALOGUE_SHOP_BUY_STANDARD || dialog_menu_id == HOUSE_DIALOGUE_SHOP_6) 137 if (dialog_menu_id == HOUSE_DIALOGUE_SHOP_BUY_STANDARD || dialog_menu_id == HOUSE_DIALOGUE_SHOP_6)
139 { 138 {
140 __debugbreak(); // fix indexing 139 __debugbreak(); // fix indexing
141 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103; 140 pWindowList_at_506F50_minus1_indexing_buttons____and_an_int_[0] = 103;
142 pGUIWindow_CurrentMenu = CharacterUI_Initialize(14); 141 pGUIWindow_CurrentMenu = CharacterUI_Initialize(SCREEN_E);
143 return; 142 return;
144 } 143 }
145 } 144 }
146 // 4E28F8: using guessed type int pCurrentScreen;
147 // F8B19C: using guessed type int dword_F8B19C;
148 145
149 //----- (00416B01) -------------------------------------------------------- 146 //----- (00416B01) --------------------------------------------------------
150 void GameUI_DrawNPCPopup(void *_this)//PopupWindowForBenefitAndJoinText 147 void GameUI_DrawNPCPopup(void *_this)//PopupWindowForBenefitAndJoinText
151 { 148 {
152 int v1; // edi@2 149 int v1; // edi@2
972 { 969 {
973 GameUI_RightPanel_BookFlashTimer = pParty->uTimePlayed; 970 GameUI_RightPanel_BookFlashTimer = pParty->uTimePlayed;
974 971
975 static bool byte_50697C = false; // 50697C 972 static bool byte_50697C = false; // 50697C
976 byte_50697C = !byte_50697C; 973 byte_50697C = !byte_50697C;
977 if ( byte_50697C && pCurrentScreen != SCREEN_REST ) 974 if ( byte_50697C && current_screen_type != SCREEN_REST )
978 { 975 {
979 if (bFlashQuestBook) pRenderer->DrawTextureIndexedAlpha(493, 355, pIcons_LOD->GetTexture(uTextureID_ib_td1_A)); 976 if (bFlashQuestBook) pRenderer->DrawTextureIndexedAlpha(493, 355, pIcons_LOD->GetTexture(uTextureID_ib_td1_A));
980 if (bFlashAutonotesBook) pRenderer->DrawTextureIndexedAlpha(527, 353, pIcons_LOD->GetTexture(uTextureID_ib_td2_A)); 977 if (bFlashAutonotesBook) pRenderer->DrawTextureIndexedAlpha(527, 353, pIcons_LOD->GetTexture(uTextureID_ib_td2_A));
981 if (bFlashHistoryBook) pRenderer->DrawTextureIndexedAlpha(600, 361, pIcons_LOD->GetTexture(uTextureID_ib_td5_A)); 978 if (bFlashHistoryBook) pRenderer->DrawTextureIndexedAlpha(600, 361, pIcons_LOD->GetTexture(uTextureID_ib_td5_A));
982 } 979 }
1174 1171
1175 pMouse->uPointingObjectID = 0; 1172 pMouse->uPointingObjectID = 0;
1176 pMouse->GetClickPos(&pX, &pY); 1173 pMouse->GetClickPos(&pX, &pY);
1177 if ( pX < 0 || pX > window->GetWidth() - 1 || pY < 0 || pY > window->GetHeight() - 1 ) 1174 if ( pX < 0 || pX > window->GetWidth() - 1 || pY < 0 || pY > window->GetHeight() - 1 )
1178 return; 1175 return;
1179 if ( pCurrentScreen == SCREEN_GAME ) 1176 if ( current_screen_type == SCREEN_GAME )
1180 { 1177 {
1181 if ( pX <= (window->GetWidth() - 1) * 0.73125 && pY <= (window->GetHeight() - 1) * 0.73125 ) 1178 if ( pX <= (window->GetWidth() - 1) * 0.73125 && pY <= (window->GetHeight() - 1) * 0.73125 )
1182 { 1179 {
1183 //if ( pRenderer->pRenderD3D ) // inlined mm8::4C1E01 1180 //if ( pRenderer->pRenderD3D ) // inlined mm8::4C1E01
1184 { 1181 {
1185 pickedObjectPID = pGame->pVisInstance->get_picked_object_zbuf_val(); 1182 pickedObjectPID = pEngine->pVisInstance->get_picked_object_zbuf_val();
1186 if ( pX < (unsigned int)pViewport->uScreen_TL_X || pX > (unsigned int)pViewport->uScreen_BR_X 1183 if ( pX < (unsigned int)pViewport->uScreen_TL_X || pX > (unsigned int)pViewport->uScreen_BR_X
1187 || pY < (unsigned int)pViewport->uScreen_TL_Y || pY > (unsigned int)pViewport->uScreen_BR_Y ) 1184 || pY < (unsigned int)pViewport->uScreen_TL_Y || pY > (unsigned int)pViewport->uScreen_BR_Y )
1188 pickedObjectPID = -1; 1185 pickedObjectPID = -1;
1189 if ( pickedObjectPID == -1 ) 1186 if ( pickedObjectPID == -1 )
1190 { 1187 {
1381 return; 1378 return;
1382 } 1379 }
1383 } 1380 }
1384 //The game never gets to this point even in the original. It's also bugged(neither branch displays anything). 1381 //The game never gets to this point even in the original. It's also bugged(neither branch displays anything).
1385 //TODO fix these and move them up before the window check loop. 1382 //TODO fix these and move them up before the window check loop.
1386 if ( pCurrentScreen == SCREEN_CHEST ) 1383 if ( current_screen_type == SCREEN_CHEST )
1387 { 1384 {
1388 Chest::ChestUI_WritePointedObjectStatusString(); 1385 Chest::ChestUI_WritePointedObjectStatusString();
1389 if ( uLastPointedObjectID != 0 ) 1386 if ( uLastPointedObjectID != 0 )
1390 { 1387 {
1391 pFooterString[0] = 0; 1388 pFooterString[0] = 0;
1392 bForceDrawFooter = 1; 1389 bForceDrawFooter = 1;
1393 } 1390 }
1394 uLastPointedObjectID = 0; 1391 uLastPointedObjectID = 0;
1395 return; 1392 return;
1396 } 1393 }
1397 else if ( pCurrentScreen == SCREEN_HOUSE ) 1394 else if ( current_screen_type == SCREEN_HOUSE )
1398 { 1395 {
1399 if ( dialog_menu_id != HOUSE_DIALOGUE_SHOP_BUY_STANDARD 1396 if ( dialog_menu_id != HOUSE_DIALOGUE_SHOP_BUY_STANDARD
1400 || (v16 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]], v16 == 0) 1397 || (v16 = pRenderer->pActiveZBuffer[pX + pSRZBufferLineOffsets[pY]], v16 == 0)
1401 || v16 == -65536 ) 1398 || v16 == -65536 )
1402 { 1399 {
1539 v0 + 20 * pPartySpellbuffsUI_smthns[i], 0, 63); 1536 v0 + 20 * pPartySpellbuffsUI_smthns[i], 0, 63);
1540 } 1537 }
1541 //++v1; 1538 //++v1;
1542 } 1539 }
1543 //while ( v1 < 14 ); 1540 //while ( v1 < 14 );
1544 if (pCurrentScreen == SCREEN_GAME || pCurrentScreen == SCREEN_NPC_DIALOGUE) 1541 if (current_screen_type == SCREEN_GAME || current_screen_type == SCREEN_NPC_DIALOGUE)
1545 { 1542 {
1546 if (pParty->FlyActive()) 1543 if (pParty->FlyActive())
1547 { 1544 {
1548 if ( pParty->bFlying ) 1545 if ( pParty->bFlying )
1549 spell_texture = pIcons_LOD->GetTexture(pIconsFrameTable->GetFrame(uIconIdx_FlySpell, v0)->uTextureID); 1546 spell_texture = pIcons_LOD->GetTexture(pIconsFrameTable->GetFrame(uIconIdx_FlySpell, v0)->uTextureID);
2021 } 2018 }
2022 2019
2023 //----- (00441498) -------------------------------------------------------- 2020 //----- (00441498) --------------------------------------------------------
2024 void GameUI_DrawTorchlightAndWizardEye() 2021 void GameUI_DrawTorchlightAndWizardEye()
2025 { 2022 {
2026 if (pCurrentScreen == SCREEN_GAME 2023 if (current_screen_type == SCREEN_GAME
2027 || pCurrentScreen == SCREEN_MENU 2024 || current_screen_type == SCREEN_MENU
2028 || pCurrentScreen == SCREEN_OPTIONS 2025 || current_screen_type == SCREEN_OPTIONS
2029 || pCurrentScreen == SCREEN_REST 2026 || current_screen_type == SCREEN_REST
2030 || pCurrentScreen == SCREEN_SPELL_BOOK 2027 || current_screen_type == SCREEN_SPELL_BOOK
2031 || pCurrentScreen == SCREEN_CHEST 2028 || current_screen_type == SCREEN_CHEST
2032 || pCurrentScreen == SCREEN_SAVEGAME 2029 || current_screen_type == SCREEN_SAVEGAME
2033 || pCurrentScreen == SCREEN_LOADGAME 2030 || current_screen_type == SCREEN_LOADGAME
2034 || pCurrentScreen == SCREEN_CHEST_INVENTORY 2031 || current_screen_type == SCREEN_CHEST_INVENTORY
2035 || pCurrentScreen == SCREEN_BOOKS 2032 || current_screen_type == SCREEN_BOOKS
2036 || pCurrentScreen == SCREEN_BRANCHLESS_NPC_DIALOG ) 2033 || current_screen_type == SCREEN_BRANCHLESS_NPC_DIALOG )
2037 { 2034 {
2038 if (pParty->TorchlightActive()) 2035 if (pParty->TorchlightActive())
2039 { 2036 {
2040 IconFrame* icon = pIconsFrameTable->GetFrame((signed __int16)pUIAnum_Torchlight->uIconID, pEventTimer->Time()); 2037 IconFrame* icon = pIconsFrameTable->GetFrame((signed __int16)pUIAnum_Torchlight->uIconID, pEventTimer->Time());
2041 pRenderer->DrawTextureIndexedAlpha(pUIAnum_Torchlight->x, pUIAnum_Torchlight->y, pIcons_LOD->GetTexture(icon->uTextureID)); 2038 pRenderer->DrawTextureIndexedAlpha(pUIAnum_Torchlight->x, pUIAnum_Torchlight->y, pIcons_LOD->GetTexture(icon->uTextureID));
2045 IconFrame* icon = pIconsFrameTable->GetFrame((signed __int16)pUIAnim_WizardEye->uIconID, pEventTimer->Time()); 2042 IconFrame* icon = pIconsFrameTable->GetFrame((signed __int16)pUIAnim_WizardEye->uIconID, pEventTimer->Time());
2046 pRenderer->DrawTextureIndexedAlpha(pUIAnim_WizardEye->x, pUIAnim_WizardEye->y, pIcons_LOD->GetTexture(icon->uTextureID)); 2043 pRenderer->DrawTextureIndexedAlpha(pUIAnim_WizardEye->x, pUIAnim_WizardEye->y, pIcons_LOD->GetTexture(icon->uTextureID));
2047 } 2044 }
2048 } 2045 }
2049 } 2046 }
2050 // 4E28F8: using guessed type int pCurrentScreen; 2047 // 4E28F8: using guessed type int current_screen_type;
2051 2048
2052 2049
2053 //----- (00491F87) -------------------------------------------------------- 2050 //----- (00491F87) --------------------------------------------------------
2054 void GameUI_DrawHiredNPCs() 2051 void GameUI_DrawHiredNPCs()
2055 { 2052 {