comparison Indoor.cpp @ 791:346f7069676a

Indoor::GetSector and various stuff
author Nomad
date Mon, 25 Mar 2013 05:27:18 +0200
parents f004c7ceb7bd
children 290afbd48b6b
comparison
equal deleted inserted replaced
790:1e2be0f5eb30 791:346f7069676a
21 #include "Log.h" 21 #include "Log.h"
22 #include "TurnEngine.h" 22 #include "TurnEngine.h"
23 #include "PaletteManager.h" 23 #include "PaletteManager.h"
24 #include "MapInfo.h" 24 #include "MapInfo.h"
25 #include "IndoorCamera.h" 25 #include "IndoorCamera.h"
26 #include "GUIWindow.h"
27 #include "GUIButton.h"
28 #include "GUIFont.h"
26 29
27 #include "mm7_data.h" 30 #include "mm7_data.h"
28 31
29 32
30 33
373 if (viewparams->draw_sw_outlines) 376 if (viewparams->draw_sw_outlines)
374 _this.uFlags |= INDOOR_CAMERA_DRAW_SW_OUTLINES; 377 _this.uFlags |= INDOOR_CAMERA_DRAW_SW_OUTLINES;
375 if (viewparams->draw_d3d_outlines) 378 if (viewparams->draw_d3d_outlines)
376 _this.uFlags |= INDOOR_CAMERA_DRAW_D3D_OUTLINES; 379 _this.uFlags |= INDOOR_CAMERA_DRAW_D3D_OUTLINES;
377 380
381 _this.uFlags |= INDOOR_CAMERA_DRAW_D3D_OUTLINES;
382 _this.uFlags |= INDOOR_CAMERA_DRAW_SW_OUTLINES;
383 //INDOOR_CAMERA_DRAW_TERRAIN_OUTLINES
384
378 _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed; 385 _this.field_0_timer = pEventTimer->uTotalGameTimeElapsed;
379 _this.field_1C_mb_fov = 65; 386 _this.field_1C_mb_fov = 65;
380 _this.vPosition.x = pParty->vPosition.x - ((stru_5C6E00->Cos(pParty->sRotationY) * (signed __int64)pParty->y_rotation_granularity) >> 16); 387 _this.vPosition.x = pParty->vPosition.x - fixpoint_mul(stru_5C6E00->Cos(pParty->sRotationY), pParty->y_rotation_granularity);
381 _this.vPosition.y = pParty->vPosition.y - ((stru_5C6E00->Sin(pParty->sRotationY) * (signed __int64)pParty->y_rotation_granularity) >> 16); 388 _this.vPosition.y = pParty->vPosition.y - fixpoint_mul(stru_5C6E00->Sin(pParty->sRotationY), pParty->y_rotation_granularity);
382 _this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel; 389 _this.vPosition.z = pParty->vPosition.z + pParty->sEyelevel;
383 _this.sRotationX = pParty->sRotationX; 390 _this.sRotationX = pParty->sRotationX;
384 _this.sRotationY = pParty->sRotationY; 391 _this.sRotationY = pParty->sRotationY;
385 _this.pRenderTarget = pRenderer->pTargetSurface; 392 _this.pRenderTarget = pRenderer->pTargetSurface;
386 _this.uViewportX = pViewport->uScreen_TL_X; 393 _this.uViewportX = pViewport->uScreen_TL_X;
535 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0); 542 pGame->pLightmapBuilder->ApplyLights(&stru_F8AD28, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0);
536 543
537 if (pDecalBuilder->uNumDecals > 0) 544 if (pDecalBuilder->uNumDecals > 0)
538 pDecalBuilder->ApplyDecals(a4a, 1, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0, pFace->uSectorID); 545 pDecalBuilder->ApplyDecals(a4a, 1, &stru_F7B60C, uNumVerticesa, array_507D30, pVertices, 0, pFace->uSectorID);
539 546
540 if (pFace->Animated() && 547 if (pFace->Fluid() &&
541 pFace->uBitmapID == pRenderer->hd_water_tile_id ) 548 pFace->uBitmapID == pRenderer->hd_water_tile_id )
542 { 549 {
543 __debugbreak(); 550 __debugbreak();
544 v23 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame]; 551 v23 = pRenderer->pHDWaterBitmapIDs[pRenderer->hd_water_current_frame];
545 goto LABEL_42; 552 goto LABEL_42;
546 } 553 }
547 554
548 if (pFace->Animated()) 555 if (pFace->Fluid())
549 { 556 {
550 //auto v24 = GetTickCount() / 4; 557 //auto v24 = GetTickCount() / 4;
551 //auto v25 = v24 - stru_5C6E00->uIntegerHalfPi; 558 //auto v25 = v24 - stru_5C6E00->uIntegerHalfPi;
552 uint eightSeconds = GetTickCount() % 8000; 559 uint eightSeconds = GetTickCount() % 8000;
553 float angle = (eightSeconds / 8000.0f) * 2 * 3.1415f; 560 float angle = (eightSeconds / 8000.0f) * 2 * 3.1415f;
1465 AddBspNodeToRenderList(v30); 1472 AddBspNodeToRenderList(v30);
1466 } 1473 }
1467 } 1474 }
1468 if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_SW_OUTLINES) 1475 if (pBLVRenderParams->uFlags & INDOOR_CAMERA_DRAW_SW_OUTLINES)
1469 pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF); 1476 pGame->pIndoorCameraD3D->PrepareAndDrawDebugOutline(pFace, 0x1E1EFF);
1477 //pGame->pIndoorCameraD3D->DebugDrawPortal(pFace);
1470 } 1478 }
1471 } 1479 }
1472 1480
1473 1481
1474 //----- (004AFB86) -------------------------------------------------------- 1482 //----- (004AFB86) --------------------------------------------------------
3119 //int v27; // edx@26 3127 //int v27; // edx@26
3120 //signed __int64 v28; // qtt@26 3128 //signed __int64 v28; // qtt@26
3121 ///Vec3_short_ *v29; // eax@26 3129 ///Vec3_short_ *v29; // eax@26
3122 //Vec3_short_ *v30; // edx@26 3130 //Vec3_short_ *v30; // edx@26
3123 //int v31; // edx@26 3131 //int v31; // edx@26
3124 signed int v32; // edi@27 3132 //signed int v32; // edi@27
3125 signed __int64 v33; // qtt@27 3133 signed __int64 v33; // qtt@27
3126 //Vec3_short_ *v34; // edx@27 3134 //Vec3_short_ *v34; // edx@27
3127 int v35; // edx@32 3135 //int v35; // edx@32
3128 int v37; // edi@38 3136 int v37; // edi@38
3129 int pSectorID; // ebx@40 3137 int pSectorID; // ebx@40
3130 int v39; // eax@41 3138 int v39; // eax@41
3131 BLVFace *pFace; // esi@42 3139 BLVFace *pFace; // esi@42
3132 PolygonType pPolygonType; // dl@42 3140 PolygonType pPolygonType; // dl@42
3148 int v57; // [sp+108h] [bp-Ch]@16 3156 int v57; // [sp+108h] [bp-Ch]@16
3149 //Vec3_short_ *v58; // [sp+10Ch] [bp-8h]@20 3157 //Vec3_short_ *v58; // [sp+10Ch] [bp-8h]@20
3150 int v59; // [sp+110h] [bp-4h]@16 3158 int v59; // [sp+110h] [bp-4h]@16
3151 3159
3152 v4 = 0; 3160 v4 = 0;
3153 //v7 = __OFSUB__(this->uNumSectors, 1); 3161 v43[0] = 0;
3154 //v5 = this->uNumSectors == 1; 3162
3155 //v6 = this->uNumSectors - 1 < 0;
3156 v55 = 0; 3163 v55 = 0;
3157 v43[0] = 0; 3164
3158 //v56 = 1;
3159 if (uNumSectors < 2) 3165 if (uNumSectors < 2)
3160 return 0; 3166 return 0;
3161 3167
3162 for (uint i = 1; i < uNumSectors; ++i) 3168 for (uint i = 1; i < uNumSectors; ++i)
3163 { 3169 {
3164 auto pSector = pSectors + i; 3170 auto pSector = pSectors + i;
3165 3171
3166 if (pSector->pBounding.x1 <= sX && pSector->pBounding.x2 >= sX) 3172 if (pSector->pBounding.x1 > sX || pSector->pBounding.x2 < sX ||
3167 if (pSector->pBounding.y1 <= sY && pSector->pBounding.y2 >= sY) 3173 pSector->pBounding.y1 > sY || pSector->pBounding.y2 < sY ||
3168 if (pSector->pBounding.z1 - 64 <= sZ && pSector->pBounding.z2 + 64 >= sZ) 3174 pSector->pBounding.z1 - 64 > sZ || pSector->pBounding.z2 + 64 < sZ)
3175 continue;
3176
3177 //Log::Warning(L"Sector[%u]", i);
3178 v51 = pSector->uNumFloors + pSector->uNumPortals;
3179 if (!v51)
3180 continue;
3181
3182
3183 for (uint j = 0; j < v51; ++j)
3184 {
3185 uint uFaceID;
3186 if (j < pSector->uNumFloors)
3187 uFaceID = pSector->pFloors[j];
3188 else
3189 uFaceID = pSector->pPortals[j - pSector->uNumFloors];
3190
3191 auto pFace = pFaces + uFaceID;
3192 if (pFace->uPolygonType != POLYGON_Floor &&
3193 pFace->uPolygonType != POLYGON_InBetweenFloorAndWall)
3194 continue;
3195
3196 v54 = 0;
3197 v50 = pVertices[pFace->pVertexIDs[0]].y >= sY;
3198
3199 for (uint k = 1; k < pFace->uNumVertices; k++)
3200 {
3201 v59 = v50;
3202
3203 if (v54 >= 2)
3204 break;
3205
3206 auto v2 = &pVertices[pFace->pVertexIDs[k]];
3207 v50 = v2->y >= sY;
3208
3209 if ( v59 == v50 )
3210 continue;
3211
3212 auto v1 = &pVertices[pFace->pVertexIDs[k - 1]];
3213 v25 = v2->x >= sX ? 0 : 2;
3214 v26 = v25 | (v1->x < sX);
3215
3216 if (v26 == 3)
3217 continue;
3218
3219 if (!v26)
3220 ++v54;
3221 else
3169 { 3222 {
3170 //Log::Warning(L"Sector[%u]", i); 3223 if (v1->x >= v2->x)
3171 v51 = pSector->uNumFloors + pSector->uNumPortals; 3224 {
3172 if (!v51) 3225 /*int _a58;
3173 continue;
3174
3175 //v9 = pSector->uNumFloors;
3176 //v10 = v9 + pSector->uNumPortals;
3177 //v11 = 0;
3178 //v44 = v9;
3179 //v48 = 0;
3180
3181 //v12 = -2 * v9;
3182 //v53 = -2 * v9;
3183 for (uint j = 0; j < v51; ++j)
3184 {
3185 unsigned int uFaceID;
3186 if (j < pSector->uNumFloors)
3187 uFaceID = pSector->pFloors[j];
3188 else
3189 uFaceID = pSector->pPortals[j - pSector->uNumFloors];
3190
3191 auto pFace = pFaces + uFaceID;
3192 //v14 = (signed __int16)v13;
3193 //v15 = this->pFaces;
3194 //v46 = v13;
3195 //v14 *= 96;
3196 //v45 = v13 * sizeof(BLVFace);
3197 //v16 = pFaces + uFaceID;
3198 //v17 = v16->uPolygonType;
3199 if (pFace->uPolygonType == POLYGON_Floor ||
3200 pFace->uPolygonType == POLYGON_InBetweenFloorAndWall)
3201 {
3202 //pVertexIDs = pFace->pVertexIDs;
3203 //v19 = this->pVertices;
3204 //v20 = pVertices[pFace->pVertexIDs[0]].y;
3205 v54 = 0;
3206 //v57 = 0;
3207 //v5 = v16->uNumVertices == 0;
3208 v59 = pVertices[pFace->pVertexIDs[0]].y >= sY;
3209
3210 //v21 = pFace->pVertexIDs + 1;
3211 for (uint k = 0; k < pFace->uNumVertices; k++)
3212 {
3213 if (v54 >= 2)
3214 break;
3215
3216 //v49 = &pVertices[pFace->pVertexIDs[k]];
3217 auto v2 = &pVertices[pFace->pVertexIDs[k]];
3218 //v22 = pVertex->y;
3219 //v47 = pVertex->y;
3220 v50 = v2->y >= sY;
3221 if ( v59 != v50 )
3222 {
3223 //v58 = &pVertices[pFace->pVertexIDs[k - 1]];
3224 auto v1 = &pVertices[pFace->pVertexIDs[k]];
3225 //v23 = v58->x;
3226 //HIWORD(v24) = HIWORD(v49);
3227 //LOWORD(v24) = v49->x;
3228 //v49 = v24;
3229 //v59 = v49->x;
3230 v25 = v1->x >= sX ? 0 : 2;
3231 v26 = v25 | v2->x < sX;
3232 if ( v26 != 3 )
3233 {
3234 if (!v26)
3235 ++v54;
3236 else
3237 {
3238 if (v1->x >= v2->x)
3239 {
3240 int _a58;
3241 int _a59; 3226 int _a59;
3242 3227
3243 v32 = v1->x - v2->x; 3228 v32 = v1->x - v2->x;
3244 LODWORD(v33) = v32 << 16; 3229 LODWORD(v33) = v32 << 16;
3245 HIDWORD(v33) = v32 >> 16; 3230 HIDWORD(v33) = v32 >> 16;*/
3246 _a58 = v33 / (v1->y - v2->y); 3231 //fixpoint_div(v1->x - v2->x, v1->y - v2->y);
3247 _a59 = (unsigned __int64)(_a58 * (__int64)(sY - v2->y)) >> 16; 3232 //_a58 = v33 / (v1->y - v2->y);
3248 3233 //_a59 = fixpoint_mul(_a58, sY - v2->y);
3249 if (v59 + pVertices[k].x > sX) 3234 auto x_div_y = fixpoint_div(v1->x - v2->x, v1->y - v2->y);
3250 ++v54; 3235 auto rval = fixpoint_mul(x_div_y, sY - v2->y); // a / b * c - looks like projection
3251 } 3236 if (rval + v2->x > sX)
3252 else 3237 ++v54;
3253 { 3238 }
3254 int _a58; 3239 else
3240 {
3241 auto x_div_y = fixpoint_div(v2->x - v1->x, v2->y - v1->y);
3242 auto res = fixpoint_mul(x_div_y, sY - v1->y);
3243
3244 if (res + v1->x > sX)
3245 ++v54;
3246
3247 /*int _a58;
3255 int _a59; 3248 int _a59;
3256 v32 = v2->x - v1->x; 3249 auto v32 = v2->x - v1->x;
3257 LODWORD(v33) = v32 << 16; 3250 LODWORD(v33) = v32 << 16;
3258 HIDWORD(v33) = v32 >> 16; 3251 HIDWORD(v33) = v32 >> 16;
3259 _a58 = v33 / (v2->y - v1->y); 3252 _a58 = v33 / (v2->y - v1->y);
3260 _a59 = (unsigned __int64)(_a58 * (signed __int64)(sY - v1->y)) >> 16; 3253 _a59 = fixpoint_mul(_a58, sY - v1->y);
3261 3254
3262 if (_a59 + pVertices[k].x > sX) 3255 if (_a59 + pVertices[k].x > sX)
3263 ++v54; 3256 ++v54;*/
3264 }
3265 }
3266 }
3267 }
3268
3269 v59 = v50;
3270 }
3271
3272 if (pFace->uNumVertices)
3273 {
3274 if (v54 == 1)
3275 {
3276 v35 = v55++;
3277 v43[v35] = uFaceID;
3278 }
3279 }
3280 }
3281 } 3257 }
3282 v4 = v43[0];
3283 } 3258 }
3284 } 3259 }
3285 3260
3261 if (pFace->uNumVertices && v54 == 1)
3262 v43[v55++] = uFaceID;
3263 }
3264 }
3265
3266 v4 = v43[0];
3286 if ( v55 == 1 ) 3267 if ( v55 == 1 )
3287 return this->pFaces[v4].uSectorID; 3268 return this->pFaces[v4].uSectorID;
3288 v37 = 0; 3269 v37 = 0;
3289 if ( !v55 ) 3270 if ( !v55 )
3290 return 0; 3271 return 0;