comparison Engine/Graphics/Outdoor.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 1bcadc6dd203
children b6140dfeac27
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 #include "../ErrorHandling.h" 6
7 #include "Engine/Engine.h"
7 8
8 #include "stru6.h" 9 #include "stru6.h"
9 #include "Weather.h" 10 #include "Weather.h"
10 #include "Sprites.h" 11 #include "Sprites.h"
11 #include "LightmapBuilder.h" 12 #include "LightmapBuilder.h"
12 #include "Outdoor.h" 13 #include "Outdoor.h"
13 #include "../Party.h" 14 #include "Engine/Party.h"
14 #include "../Objects/SpriteObject.h" 15 #include "Engine/Objects/SpriteObject.h"
15 #include "../LOD.h" 16 #include "Engine/LOD.h"
16 #include "PaletteManager.h" 17 #include "PaletteManager.h"
17 #include "GUI/GUIProgressBar.h" 18 #include "GUI/GUIProgressBar.h"
18 #include "Media/Audio/AudioPlayer.h" 19 #include "Media/Audio/AudioPlayer.h"
19 #include "DecorationList.h" 20 #include "DecorationList.h"
20 #include "../OurMath.h" 21 #include "Engine/OurMath.h"
21 #include "../Objects/ObjectList.h" 22 #include "Engine/Objects/ObjectList.h"
22 #include "../Game.h" 23 #include "Engine/Objects/Actor.h"
23 #include "../Objects/Actor.h" 24 #include "Engine/Objects/Chest.h"
24 #include "../Objects/Chest.h" 25 #include "Engine/stru123.h"
25 #include "../stru123.h" 26 #include "Engine/Timer.h"
26 #include "../Timer.h"
27 #include "Viewport.h" 27 #include "Viewport.h"
28 #include "../Events.h" 28 #include "Engine/Events.h"
29 #include "ParticleEngine.h" 29 #include "ParticleEngine.h"
30 #include "../TurnEngine/TurnEngine.h" 30 #include "Engine/TurnEngine/TurnEngine.h"
31 31
32 #include "../MM7.h"
33 #include "Lights.h" 32 #include "Lights.h"
34 33
35 #include "GUI/GUIWindow.h" 34 #include "GUI/GUIWindow.h"
36 #include "Level/Decoration.h" 35 #include "Level/Decoration.h"
37 #include "../ZlibWrapper.h" 36 #include "Engine/ZlibWrapper.h"
38 #include "../MMT.h" 37 #include "Engine/MMT.h"
39 38
40 MapStartPoint uLevel_StartingPointType; // weak 39 MapStartPoint uLevel_StartingPointType; // weak
41 40
42 OutdoorLocation *pOutdoor = new OutdoorLocation; 41 OutdoorLocation *pOutdoor = new OutdoorLocation;
43 ODMRenderParams *pODMRenderParams; 42 ODMRenderParams *pODMRenderParams;
82 81
83 //----- (0047A59E) -------------------------------------------------------- 82 //----- (0047A59E) --------------------------------------------------------
84 void OutdoorLocation::ExecDraw(unsigned int bRedraw) 83 void OutdoorLocation::ExecDraw(unsigned int bRedraw)
85 { 84 {
86 85
87 pGame->pIndoorCameraD3D->debug_flags = 0; 86 pEngine->pIndoorCameraD3D->debug_flags = 0;
88 if (viewparams->draw_d3d_outlines) 87 if (viewparams->draw_d3d_outlines)
89 pGame->pIndoorCameraD3D->debug_flags |= ODM_RENDER_DRAW_D3D_OUTLINES; 88 pEngine->pIndoorCameraD3D->debug_flags |= ODM_RENDER_DRAW_D3D_OUTLINES;
90 89
91 if (bRedraw || true/*pRenderer->pRenderD3D*/) 90 if (bRedraw || true/*pRenderer->pRenderD3D*/)
92 { 91 {
93 //pODMRenderParams->RotationToInts(); 92 //pODMRenderParams->RotationToInts();
94 sub_481ED9_MessWithODMRenderParams(); 93 sub_481ED9_MessWithODMRenderParams();
103 sub_487DA9(); 102 sub_487DA9();
104 } 103 }
105 if ( pParty->uCurrentMinute != pOutdoor->uLastSunlightUpdateMinute ) 104 if ( pParty->uCurrentMinute != pOutdoor->uLastSunlightUpdateMinute )
106 pOutdoor->UpdateSunlightVectors(); 105 pOutdoor->UpdateSunlightVectors();
107 pOutdoor->UpdateFog(); 106 pOutdoor->UpdateFog();
108 //pGame->pIndoorCameraD3D->sr_Reset_list_0037C(); 107 //pEngine->pIndoorCameraD3D->sr_Reset_list_0037C();
109 108
110 //if (pRenderer->pRenderD3D) // d3d - redraw always 109 //if (pRenderer->pRenderD3D) // d3d - redraw always
111 { 110 {
112 pRenderer->DrawOutdoorSkyD3D(); 111 pRenderer->DrawOutdoorSkyD3D();
113 pRenderer->DrawBuildingsD3D(); 112 pRenderer->DrawBuildingsD3D();
131 pMobileLightsStack->uNumLightsActive = 0; 130 pMobileLightsStack->uNumLightsActive = 0;
132 pStationaryLightsStack->uNumLightsActive = 0; 131 pStationaryLightsStack->uNumLightsActive = 0;
133 /*if ( !pRenderer->pRenderD3D ) 132 /*if ( !pRenderer->pRenderD3D )
134 { 133 {
135 pRenderer->ExecOutdoorDrawSW(); 134 pRenderer->ExecOutdoorDrawSW();
136 pGame->pIndoorCameraD3D->sr_438240_draw_lits(); 135 pEngine->pIndoorCameraD3D->sr_438240_draw_lits();
137 }*/ 136 }*/
138 pGame->PushStationaryLights(-1); 137 pEngine->PushStationaryLights(-1);
139 pGame->PrepareBloodsplats(); 138 pEngine->PrepareBloodsplats();
140 if (bRedraw) 139 if (bRedraw)
141 pOutdoor->UpdateDiscoveredArea(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y), 1); 140 pOutdoor->UpdateDiscoveredArea(WorldPosToGridCellX(pParty->vPosition.x), WorldPosToGridCellZ(pParty->vPosition.y), 1);
142 pGame->uFlags2 &= 0xFFFFFFFEu;//~0x00000001 141 pEngine->uFlags2 &= 0xFFFFFFFEu;//~0x00000001
143 if (/*pRenderer->pRenderD3D*/true && pRenderer->bUsingSpecular) 142 if (/*pRenderer->pRenderD3D*/true && pRenderer->bUsingSpecular)
144 pGame->pLightmapBuilder->uFlags |= 1; 143 pEngine->pLightmapBuilder->uFlags |= 1;
145 else 144 else
146 pGame->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;//~0x00000001 145 pEngine->pLightmapBuilder->uFlags &= 0xFFFFFFFEu;//~0x00000001
147 146
148 uNumDecorationsDrawnThisFrame = 0; 147 uNumDecorationsDrawnThisFrame = 0;
149 uNumSpritesDrawnThisFrame = 0; 148 uNumSpritesDrawnThisFrame = 0;
150 uNumBillboardsToDraw = 0; 149 uNumBillboardsToDraw = 0;
151 150
160 159
161 //----- (00441CFF) -------------------------------------------------------- 160 //----- (00441CFF) --------------------------------------------------------
162 void OutdoorLocation::Draw() 161 void OutdoorLocation::Draw()
163 { 162 {
164 bool redrawWorld = true; 163 bool redrawWorld = true;
165 if ( !(pParty->uFlags & 2) && !(pGame->uFlags2 & 1) ) 164 if ( !(pParty->uFlags & 2) && !(pEngine->uFlags2 & 1) )
166 redrawWorld = false; 165 redrawWorld = false;
167 pOutdoor->ExecDraw(redrawWorld); 166 pOutdoor->ExecDraw(redrawWorld);
168 167
169 pGame->DrawParticles(); 168 pEngine->DrawParticles();
170 //pWeather->Draw();//если раскомментировать скорость снега быстрее 169 //pWeather->Draw();//если раскомментировать скорость снега быстрее
171 trail_particle_generator.UpdateParticles(); 170 trail_particle_generator.UpdateParticles();
172 } 171 }
173 172
174 //----- (00488E23) -------------------------------------------------------- 173 //----- (00488E23) --------------------------------------------------------
621 if ( v24 != 0.0 || v25 != 0.0 || v26 != 0.0 ) 620 if ( v24 != 0.0 || v25 != 0.0 || v26 != 0.0 )
622 break; 621 break;
623 currVertex--; 622 currVertex--;
624 } 623 }
625 624
626 if ( ((double)pGame->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26 625 if ( ((double)pEngine->pIndoorCameraD3D->vPartyPos.x - a2->vWorldPosition.x) * v26
627 + ((double)pGame->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25 626 + ((double)pEngine->pIndoorCameraD3D->vPartyPos.z - a2->vWorldPosition.z) * v25
628 + ((double)pGame->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 ) 627 + ((double)pEngine->pIndoorCameraD3D->vPartyPos.y - a2->vWorldPosition.y) * v24 > 0.0 )
629 { 628 {
630 629
631 v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x; 630 v19 = a2[1].vWorldViewPosition.x - a2->vWorldViewPosition.x;
632 v18 = a2[1].vWorldViewPosition.y - a2->vWorldViewPosition.y; 631 v18 = a2[1].vWorldViewPosition.y - a2->vWorldViewPosition.y;
633 v20 = a2[1].vWorldViewPosition.z - a2->vWorldViewPosition.z; 632 v20 = a2[1].vWorldViewPosition.z - a2->vWorldViewPosition.z;
2436 z += floorf(pActors[i].uActorHeight * 0.5f + 0.5f); 2435 z += floorf(pActors[i].uActorHeight * 0.5f + 0.5f);
2437 } 2436 }
2438 else 2437 else
2439 { 2438 {
2440 v49 = 1; 2439 v49 = 1;
2441 pGame->pStru6Instance->_4A7F74(pActors[i].vPosition.x, pActors[i].vPosition.y, z); 2440 pEngine->pStru6Instance->_4A7F74(pActors[i].vPosition.x, pActors[i].vPosition.y, z);
2442 v4 = (1.0 - (double)pActors[i].uCurrentActionTime / (double)pActors[i].uCurrentActionLength) * 2441 v4 = (1.0 - (double)pActors[i].uCurrentActionTime / (double)pActors[i].uCurrentActionLength) *
2443 (double)(2 * pActors[i].uActorHeight); 2442 (double)(2 * pActors[i].uActorHeight);
2444 z -= floorf(v4 + 0.5f); 2443 z -= floorf(v4 + 0.5f);
2445 if ( z > pActors[i].vPosition.z ) 2444 if ( z > pActors[i].vPosition.z )
2446 z = pActors[i].vPosition.z; 2445 z = pActors[i].vPosition.z;
2447 } 2446 }
2448 } 2447 }
2449 v8 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pGame->pIndoorCameraD3D->vPartyPos.x, 2448 v8 = stru_5C6E00->Atan2(pActors[i].vPosition.x - pEngine->pIndoorCameraD3D->vPartyPos.x,
2450 pActors[i].vPosition.y - pGame->pIndoorCameraD3D->vPartyPos.y); 2449 pActors[i].vPosition.y - pEngine->pIndoorCameraD3D->vPartyPos.y);
2451 LOWORD(v9) = pActors[i].uYawAngle; 2450 LOWORD(v9) = pActors[i].uYawAngle;
2452 v41 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v9 - v8) >> 8) & 7; 2451 v41 = ((signed int)(stru_5C6E00->uIntegerPi + ((signed int)stru_5C6E00->uIntegerPi >> 3) + v9 - v8) >> 8) & 7;
2453 if ( pParty->bTurnBasedModeOn ) 2452 if ( pParty->bTurnBasedModeOn )
2454 { 2453 {
2455 v12 = pActors[i].uCurrentActionTime; 2454 v12 = pActors[i].uCurrentActionTime;
2484 if ( v15->uGlowRadius ) 2483 if ( v15->uGlowRadius )
2485 { 2484 {
2486 //LOBYTE(v16) = _4E94D3_light_type; 2485 //LOBYTE(v16) = _4E94D3_light_type;
2487 pMobileLightsStack->AddLight(x, y, z, 0, v15->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type); 2486 pMobileLightsStack->AddLight(x, y, z, 0, v15->uGlowRadius, 0xFFu, 0xFFu, 0xFFu, _4E94D3_light_type);
2488 } 2487 }
2489 v17 = (x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16; 2488 v17 = (x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16;
2490 if (pGame->pIndoorCameraD3D->sRotationX) 2489 if (pEngine->pIndoorCameraD3D->sRotationX)
2491 { 2490 {
2492 v18 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16; 2491 v18 = (y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
2493 v47 = (fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_sine_y)); 2492 v47 = (fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y) + fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_sine_y));
2494 v50 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_sine_y); 2493 v50 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_sine_y);
2495 v53 = fixpoint_mul(v18, pGame->pIndoorCameraD3D->int_cosine_y); 2494 v53 = fixpoint_mul(v18, pEngine->pIndoorCameraD3D->int_cosine_y);
2496 v44 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16; 2495 v44 = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
2497 v19 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x)); 2496 v19 = (fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_cosine_x));
2498 X = fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_cosine_x); 2497 X = fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_sine_x) + fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_cosine_x);
2499 if ( v19 < 262144 || v19 > pODMRenderParams->shading_dist_mist << 16 ) 2498 if ( v19 < 262144 || v19 > pODMRenderParams->shading_dist_mist << 16 )
2500 continue; 2499 continue;
2501 v20 = v53 - v50; 2500 v20 = v53 - v50;
2502 v42 = v53 - v50; 2501 v42 = v53 - v50;
2503 v21 = (fixpoint_mul(v44, pGame->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v47, pGame->pIndoorCameraD3D->int_sine_x)); 2502 v21 = (fixpoint_mul(v44, pEngine->pIndoorCameraD3D->int_cosine_x) - fixpoint_mul(v47, pEngine->pIndoorCameraD3D->int_sine_x));
2504 } 2503 }
2505 else 2504 else
2506 { 2505 {
2507 v48 = (y - pGame->pIndoorCameraD3D->vPartyPos.y) << 16; 2506 v48 = (y - pEngine->pIndoorCameraD3D->vPartyPos.y) << 16;
2508 v51 = fixpoint_mul(v17, pGame->pIndoorCameraD3D->int_cosine_y); 2507 v51 = fixpoint_mul(v17, pEngine->pIndoorCameraD3D->int_cosine_y);
2509 v22 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_sine_y); 2508 v22 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_sine_y);
2510 X = v22 + v51; 2509 X = v22 + v51;
2511 if ( v22 + v51 < 262144 || v22 + v51 > pODMRenderParams->shading_dist_mist << 16 ) 2510 if ( v22 + v51 < 262144 || v22 + v51 > pODMRenderParams->shading_dist_mist << 16 )
2512 continue; 2511 continue;
2513 v23 = fixpoint_mul(((x - pGame->pIndoorCameraD3D->vPartyPos.x) << 16), pGame->pIndoorCameraD3D->int_sine_y); 2512 v23 = fixpoint_mul(((x - pEngine->pIndoorCameraD3D->vPartyPos.x) << 16), pEngine->pIndoorCameraD3D->int_sine_y);
2514 v20 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23; 2513 v20 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_cosine_y) - v23;
2515 v42 = fixpoint_mul(v48, pGame->pIndoorCameraD3D->int_cosine_y) - v23; 2514 v42 = fixpoint_mul(v48, pEngine->pIndoorCameraD3D->int_cosine_y) - v23;
2516 v21 = (z - pGame->pIndoorCameraD3D->vPartyPos.z) << 16; 2515 v21 = (z - pEngine->pIndoorCameraD3D->vPartyPos.z) << 16;
2517 } 2516 }
2518 v45 = v21; 2517 v45 = v21;
2519 v24 = abs(v20); 2518 v24 = abs(v20);
2520 if ( abs(X) >= v24 ) 2519 if ( abs(X) >= v24 )
2521 { 2520 {
2543 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(v15->scale, v57); 2542 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(v15->scale, v57);
2544 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 ) 2543 if ( pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0 )
2545 { 2544 {
2546 if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 ) 2545 if ( pActors[i].pActorBuffs[ACTOR_BUFF_MASS_DISTORTION].uExpireTime > 0 )
2547 { 2546 {
2548 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pGame->pStru6Instance->_4A806F(&pActors[i]), 2547 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat = fixpoint_mul(pEngine->pStru6Instance->_4A806F(&pActors[i]),
2549 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat); 2548 pBillboardRenderList[uNumBillboardsToDraw - 1]._screenspace_y_scaler_packedfloat);
2550 LOWORD(v27) = v43; 2549 LOWORD(v27) = v43;
2551 } 2550 }
2552 } 2551 }
2553 else 2552 else
4537 pOutdoor->MessWithLUN(); 4536 pOutdoor->MessWithLUN();
4538 v7 = strlen("levels\\"); 4537 v7 = strlen("levels\\");
4539 strcpy(Source, &pFilename[v7]); 4538 strcpy(Source, &pFilename[v7]);
4540 strcpy(pOutdoor->pLevelFilename, Source); 4539 strcpy(pOutdoor->pLevelFilename, Source);
4541 pWeather->Initialize(); 4540 pWeather->Initialize();
4542 pGame->pIndoorCameraD3D->sRotationY = pParty->sRotationY; 4541 pEngine->pIndoorCameraD3D->sRotationY = pParty->sRotationY;
4543 pGame->pIndoorCameraD3D->sRotationX = pParty->sRotationX; 4542 pEngine->pIndoorCameraD3D->sRotationX = pParty->sRotationX;
4544 //pODMRenderParams->RotationToInts(); 4543 //pODMRenderParams->RotationToInts();
4545 pOutdoor->UpdateSunlightVectors(); 4544 pOutdoor->UpdateSunlightVectors();
4546 4545
4547 float fov_rad; 4546 float fov_rad;
4548 float fov_rad_inv; 4547 float fov_rad_inv;