Mercurial > mm7
annotate Vis.cpp @ 1593:5658d0f3b5ee
Player::GetAttackRecoveryTime removing label, fixing shield skill being ignored, fixing haste being ignored
author | Grumpy7 |
---|---|
date | Sun, 08 Sep 2013 08:01:05 +0200 |
parents | c4ab816fcc5e |
children | 2c71fa8913d2 |
rev | line source |
---|---|
0 | 1 #include "Vis.h" |
2 #include "Outdoor.h" | |
1262 | 3 #include "BSPModel.h" |
0 | 4 #include "Game.h" |
5 #include "Actor.h" | |
6 #include "IndoorCamera.h" | |
1038 | 7 #include "OutdoorCamera.h" |
0 | 8 #include "Viewport.h" |
1038 | 9 #include "Math.h" |
227 | 10 #include "Log.h" |
0 | 11 |
12 #include "mm7_data.h" | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
13 #include "MM7.h" |
0 | 14 |
15 | |
194 | 16 static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; |
17 | |
18 Vis_SelectionFilter vis_sprite_filter_1 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E1C | |
19 Vis_SelectionFilter vis_sprite_filter_2 = {VisObjectType_Sprite, OBJECT_Decoration, 0, 0, 2}; // 00F93E30 | |
20 Vis_SelectionFilter vis_face_filter = {VisObjectType_Face, OBJECT_Any, -1, 0, 0}; // 00F93E44 | |
21 Vis_SelectionFilter vis_door_filter = {VisObjectType_Face, OBJECT_BLVDoor, -1, 0x100000, 0}; // 00F93E58 | |
22 Vis_SelectionFilter vis_sprite_filter_3 = {VisObjectType_Sprite, OBJECT_Decoration, -1, 0, 4}; // 00F93E6C | |
23 Vis_SelectionFilter vis_sprite_filter_4 = {VisObjectType_Any, OBJECT_Item, -1, 0, 0}; // static to sub_44EEA7 | |
0 | 24 |
25 | |
26 | |
27 //----- (004C1026) -------------------------------------------------------- | |
1135 | 28 Vis_ObjectInfo *Vis::DetermineFacetIntersection(BLVFace *face, unsigned int pid, float pick_depth) |
0 | 29 { |
30 char *v4; // eax@4 | |
31 signed int v5; // ecx@4 | |
32 RenderVertexSoft pRay[2]; // [sp+20h] [bp-70h]@17 | |
33 int v20; // [sp+84h] [bp-Ch]@10 | |
34 | |
1177 | 35 static Vis_SelectionList SelectedPointersList;//stru_F8FE00 |
36 SelectedPointersList.uNumPointers = 0; | |
0 | 37 |
38 static bool _init_flag = false; | |
916 | 39 static RenderVertexSoft static_DetermineFacetIntersection_array_F8F200[64]; |
0 | 40 if (!_init_flag) |
41 { | |
42 _init_flag = true; | |
43 for (uint i = 0; i < 64; ++i) | |
916 | 44 static_DetermineFacetIntersection_array_F8F200[i].flt_2C = 0.0f; |
0 | 45 } |
46 | |
196 | 47 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
0 | 48 { |
196 | 49 if ( (signed int)face->uNumVertices > 0 ) |
0 | 50 { |
742 | 51 for ( int i = 0; i < face->uNumVertices; i++) |
0 | 52 { |
916 | 53 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.x = (double)pIndoor->pVertices[face->pVertexIDs[i]].x; |
54 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.y = (double)pIndoor->pVertices[face->pVertexIDs[i]].y; | |
55 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.z = (double)pIndoor->pVertices[face->pVertexIDs[i]].z; | |
0 | 56 } |
196 | 57 } |
58 } | |
59 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
60 { | |
1135 | 61 uint bmodel_id = pid >> 9; |
196 | 62 auto v = (Vec3_int_ *)pOutdoor->pBModels[bmodel_id].pVertices.pVertices; |
63 for (uint i = 0; i < face->uNumVertices; ++i) | |
64 { | |
916 | 65 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.x = v[face->pVertexIDs[i]].x; |
66 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.y = v[face->pVertexIDs[i]].y; | |
67 static_DetermineFacetIntersection_array_F8F200[i].vWorldPosition.z = v[face->pVertexIDs[i]].z; | |
0 | 68 } |
69 } | |
196 | 70 else assert(false); |
71 | |
916 | 72 pGame->pIndoorCameraD3D->ViewTransform(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices); |
73 pGame->pIndoorCameraD3D->Project(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, 1); | |
196 | 74 |
916 | 75 SortVectors_x(static_DetermineFacetIntersection_array_F8F200, 0, face->uNumVertices - 1); |
76 if (static_DetermineFacetIntersection_array_F8F200[0].vWorldViewPosition.x > pick_depth) | |
196 | 77 return nullptr; |
78 | |
79 float screenspace_center_x, | |
80 screenspace_center_y; | |
916 | 81 GetPolygonScreenSpaceCenter(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, &screenspace_center_x, &screenspace_center_y); |
82 if (IsPolygonOccludedByBillboard(static_DetermineFacetIntersection_array_F8F200, face->uNumVertices, screenspace_center_x, screenspace_center_y)) | |
196 | 83 return nullptr; |
84 | |
85 CastPickRay(pRay, screenspace_center_x, screenspace_center_y, pick_depth); | |
86 | |
87 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
1177 | 88 PickOutdoorFaces_Mouse(pick_depth, pRay, &SelectedPointersList, &vis_face_filter, true); |
196 | 89 else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
1177 | 90 PickIndoorFaces_Mouse(pick_depth, pRay, &SelectedPointersList, &vis_face_filter); |
196 | 91 else assert(false); |
92 | |
1177 | 93 SelectedPointersList.create_object_pointers(); |
94 sort_object_pointers(SelectedPointersList.object_pointers, 0, SelectedPointersList.uNumPointers - 1); | |
95 if (!SelectedPointersList.uNumPointers) | |
196 | 96 return nullptr; |
97 | |
1177 | 98 if (!SelectedPointersList.SelectionPointers(VisObjectType_Face, pid)) |
196 | 99 return nullptr; |
100 | |
1177 | 101 if (SelectedPointersList.uNumPointers) |
102 return SelectedPointersList.object_pointers[0]; | |
196 | 103 else return nullptr; |
0 | 104 } |
916 | 105 // F91E08: using guessed type char static_DetermineFacetIntersection_byte_F91E08__init_flags; |
0 | 106 |
107 //----- (004C12C3) -------------------------------------------------------- | |
196 | 108 bool Vis::IsPolygonOccludedByBillboard(RenderVertexSoft *vertices, int num_vertices, float x, float y) |
0 | 109 { |
196 | 110 //signed int v5; // esi@1 |
111 //RenderBillboardD3D *v6; // edi@2 | |
112 //double v7; // st7@9 | |
113 //int v8; // edx@9 | |
114 //RenderVertexSoft *v9; // ecx@10 | |
115 //char result; // al@24 | |
116 //Vis *thisa; // [sp+10h] [bp-8h]@1 | |
117 //float thisb; // [sp+10h] [bp-8h]@9 | |
118 //signed int v13; // [sp+14h] [bp-4h]@1 | |
119 //float a3a; // [sp+28h] [bp+10h]@9 | |
120 //float a4a; // [sp+2Ch] [bp+14h]@9 | |
0 | 121 |
196 | 122 int v13 = -1; |
123 //v5 = 0; | |
124 //thisa = this; | |
125 | |
126 //v6 = pRenderer->pBillboardRenderListD3D; | |
127 for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) | |
82 | 128 { |
196 | 129 auto billboard = pRenderer->pBillboardRenderListD3D + i; |
130 if (IsPointInsideD3DBillboard(billboard, x, y)) | |
0 | 131 { |
196 | 132 if (v13 == -1) |
133 v13 = i; | |
1322 | 134 else if ((unsigned int)pBillboardRenderList[billboard->uParentBillboardID].sZValue < |
135 pBillboardRenderList[pRenderer->pBillboardRenderListD3D[v13].uParentBillboardID].sZValue) | |
196 | 136 v13 = i; |
0 | 137 } |
138 } | |
196 | 139 |
140 if ( v13 == -1 ) | |
141 return false; | |
142 | |
143 //v8 = num_vertices; | |
144 //v7 = 3.4028235e38; | |
145 float min_x = FLT_MAX; | |
146 //a4a = 3.4028235e38; | |
147 float min_y = FLT_MAX; | |
148 //a3a = -3.4028235e38; | |
149 float max_x = -FLT_MAX; | |
150 //thisb = -3.4028235e38; | |
151 float max_y = -FLT_MAX; | |
152 for (uint i = 0; i < num_vertices; ++i) | |
153 { | |
154 //v9 = a1; | |
155 //do | |
156 //{ | |
157 auto v = vertices + i; | |
158 | |
159 if (v->vWorldViewProjX < min_x) | |
160 min_x = v->vWorldViewProjX; | |
161 if (v->vWorldViewProjX > max_x) | |
162 max_x = v->vWorldViewProjX; | |
163 | |
164 if (v->vWorldViewProjY < min_y) | |
165 min_y = v->vWorldViewProjY; | |
166 if (v->vWorldViewProjY > max_y) | |
167 max_y = v->vWorldViewProjY; | |
168 //++v9; | |
169 //--v8; | |
170 //} | |
171 //while ( v8 ); | |
172 } | |
173 | |
1390 | 174 if (min_x < pRenderer->pBillboardRenderListD3D[v13].pQuads[0].pos.x || pRenderer->pBillboardRenderListD3D[v13].pQuads[0].pos.y > min_y || |
175 pRenderer->pBillboardRenderListD3D[v13].pQuads[3].pos.x < max_x || pRenderer->pBillboardRenderListD3D[v13].pQuads[1].pos.y < max_y) | |
196 | 176 return false; |
177 | |
178 return true; | |
0 | 179 } |
180 | |
181 //----- (004C1417) -------------------------------------------------------- | |
182 void Vis::GetPolygonCenter(RenderVertexD3D3 *pVertices, unsigned int uNumVertices, float *pCenterX, float *pCenterY) | |
183 { | |
184 static RenderVertexD3D3 unk_F8EA00[64]; | |
185 | |
186 memcpy(unk_F8EA00, pVertices, 32 * uNumVertices); | |
187 | |
188 SortVerticesByX(unk_F8EA00, 0, uNumVertices - 1); | |
189 *pCenterX = (unk_F8EA00[uNumVertices - 1].pos.x - unk_F8EA00[0].pos.x) * 0.5 + unk_F8EA00[0].pos.x; | |
190 | |
191 SortVerticesByY(unk_F8EA00, 0, uNumVertices - 1); | |
192 *pCenterY = (unk_F8EA00[uNumVertices - 1].pos.y - unk_F8EA00[0].pos.y) * 0.5 + unk_F8EA00[0].pos.y; | |
193 } | |
194 | |
195 //----- (004C1495) -------------------------------------------------------- | |
196 | 196 void Vis::GetPolygonScreenSpaceCenter(RenderVertexSoft *vertices, int num_vertices, float *out_center_x, float *out_center_y) |
0 | 197 { |
198 char *v5; // eax@2 | |
199 signed int v6; // ecx@2 | |
200 float *result; // eax@5 | |
201 | |
202 static RenderVertexSoft static_sub_4C1495_array_F8DDF8[64]; | |
203 | |
196 | 204 memcpy(static_sub_4C1495_array_F8DDF8, vertices, 48 * num_vertices); |
0 | 205 |
196 | 206 SortByScreenSpaceX(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); |
207 *out_center_x = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjX - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjX; | |
208 | |
209 SortByScreenSpaceY(static_sub_4C1495_array_F8DDF8, 0, num_vertices - 1); | |
210 *out_center_y = (static_sub_4C1495_array_F8DDF8[num_vertices - 1].vWorldViewProjY - static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY) * 0.5 + static_sub_4C1495_array_F8DDF8[0].vWorldViewProjY; | |
0 | 211 } |
212 | |
213 //----- (004C1542) -------------------------------------------------------- | |
194 | 214 void Vis::PickBillboards_Mouse(float fPickDepth, float fX, float fY, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 215 { |
194 | 216 for (uint i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) |
0 | 217 { |
916 | 218 auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; |
194 | 219 if (is_part_of_selection((void *)i, filter) && IsPointInsideD3DBillboard(d3d_billboard, fX, fY)) |
0 | 220 { |
194 | 221 if (DoesRayIntersectBillboard(fPickDepth, i)) |
0 | 222 { |
194 | 223 auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; |
224 | |
225 list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); | |
0 | 226 } |
227 } | |
228 } | |
229 } | |
230 | |
231 //----- (004C1607) -------------------------------------------------------- | |
232 bool Vis::IsPointInsideD3DBillboard(RenderBillboardD3D *a1, float x, float y) | |
233 { | |
194 | 234 //RenderBillboardD3D *result; // eax@1 |
0 | 235 double v5; // st7@2 |
236 float v6; // ecx@2 | |
237 float v7; // ST00_4@3 | |
238 __int16 v8; // fps@6 | |
239 double v9; // st6@6 | |
240 char v10; // c0@6 | |
241 char v11; // c2@6 | |
242 char v12; // c3@6 | |
243 __int16 v13; // fps@7 | |
244 double v14; // st6@7 | |
245 unsigned __int8 v15; // c0@7 | |
246 char v16; // c2@7 | |
247 unsigned __int8 v17; // c3@7 | |
248 __int16 v18; // fps@8 | |
249 double v19; // st6@8 | |
250 char v20; // c0@8 | |
251 char v21; // c2@8 | |
252 char v22; // c3@8 | |
253 __int16 v23; // fps@9 | |
254 double v24; // st6@9 | |
255 unsigned __int8 v25; // c0@9 | |
256 char v26; // c2@9 | |
257 unsigned __int8 v27; // c3@9 | |
258 float v28; // [sp+4h] [bp-8h]@2 | |
259 float v29; // [sp+8h] [bp-4h]@2 | |
260 float a1a; // [sp+14h] [bp+8h]@2 | |
261 | |
262 if ( a1->uParentBillboardID == -1 ) | |
194 | 263 return false; |
264 | |
265 //result = a1; | |
1390 | 266 v5 = a1->pQuads[0].pos.x; |
267 a1a = a1->pQuads[3].pos.x; | |
268 v6 = a1->pQuads[0].pos.y; | |
269 //result = (RenderBillboardD3D *)LODWORD(result->pQuads[1].pos.y); | |
0 | 270 v29 = v6; |
1390 | 271 v28 = a1->pQuads[1].pos.y; |
0 | 272 if ( v5 > a1a ) |
273 { | |
274 v7 = v5; | |
194 | 275 //HIWORD(result) = HIWORD(v7); |
0 | 276 v5 = a1a; |
277 a1a = v7; | |
278 } | |
279 if ( v6 > (double)v28 ) | |
280 { | |
194 | 281 //result = (RenderBillboardD3D *)LODWORD(v28); |
0 | 282 v28 = v6; |
194 | 283 v29 = v28; |
0 | 284 } |
285 v9 = x + 1.0; | |
286 //UNDEF(v8); | |
29 | 287 //v10 = v9 < v5; |
288 //v11 = 0; | |
289 //v12 = v9 == v5; | |
290 //BYTE1(result) = HIBYTE(v8);//crash | |
194 | 291 if (v9 >= v5 && |
292 (v14 = x - 1.0, v14<=a1a) &&///*UNDEF(v13),*/ v15 = v14 < a1a, v16 = 0, v17 = v14 == a1a, BYTE1(result) = HIBYTE(v13), v15 | v17) | |
293 (v19 = y + 1.0, v19>=v29) &&///*UNDEF(v18),*/ v20 = v19 < v29, v21 = 0, v22 = v19 == v29, BYTE1(result) = HIBYTE(v18), v19 >= v29) | |
294 (v24 = y - 1.0, v24<=v28))///*UNDEF(v23),*/ v25 = v24 < v28, v26 = 0, v27 = v24 == v28, BYTE1(result) = HIBYTE(v23), v25 | v27) ) | |
295 return true; | |
0 | 296 else |
194 | 297 return false; |
0 | 298 } |
299 | |
300 //----- (004C16B4) -------------------------------------------------------- | |
196 | 301 void Vis::PickIndoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 302 { |
303 int v5; // eax@1 | |
742 | 304 signed int pFaceID; // edi@2 |
0 | 305 int v8; // ecx@7 |
306 int v9; // eax@7 | |
307 unsigned int *pNumPointers; // eax@7 | |
308 unsigned int v11; // ecx@7 | |
194 | 309 Vis_ObjectInfo *v12; // edi@7 |
0 | 310 RenderVertexSoft a1; // [sp+Ch] [bp-44h]@1 |
742 | 311 BLVFace *pFace; // [sp+3Ch] [bp-14h]@7 |
0 | 312 void *v15; // [sp+40h] [bp-10h]@7 |
313 int v17; // [sp+48h] [bp-8h]@1 | |
196 | 314 |
0 | 315 v5 = 0; |
316 v17 = 0; | |
676
ecfb1b3c9a39
BLV: when standing right on the portal (orange wall) everything looks fine
Nomad
parents:
618
diff
changeset
|
317 for ( a1.flt_2C = 0.0; v17 < (signed int)pBspRenderer->num_faces; ++v17 ) |
0 | 318 { |
742 | 319 pFaceID = pBspRenderer->faces[v5].uFaceID; |
320 if ( pFaceID >= 0 ) | |
0 | 321 { |
742 | 322 if ( pFaceID < (signed int)pIndoor->uNumFaces ) |
0 | 323 { |
1053 | 324 auto face = pIndoor->pFaces + pFaceID; |
325 if ( is_part_of_selection(face, filter) ) | |
0 | 326 { |
1053 | 327 if ( !pGame->pIndoorCameraD3D->IsCulled(face) ) |
0 | 328 { |
1053 | 329 if ( Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &a1, face, 0xFFFFFFFFu) ) |
0 | 330 { |
742 | 331 pGame->pIndoorCameraD3D->ViewTransform(&a1, 1); |
1029 | 332 v9 = fixpoint_from_float(/*v8, */a1.vWorldViewPosition.x); |
0 | 333 LOWORD(v9) = 0; |
862 | 334 v15 = (void *)((PID(OBJECT_BModel,pFaceID)) + v9); |
194 | 335 pNumPointers = &list->uNumPointers; |
742 | 336 //v16 = 2; |
337 //v11 = list->uNumPointers; | |
338 pFace = &pIndoor->pFaces[pFaceID]; | |
339 v12 = &list->object_pool[list->uNumPointers]; | |
340 v12->object = &pIndoor->pFaces[pFaceID]; | |
194 | 341 v12 = (Vis_ObjectInfo *)((char *)v12 + 4); |
342 v12->object = v15; | |
742 | 343 v12->sZValue = 2; |
0 | 344 ++*pNumPointers; |
345 } | |
346 } | |
347 } | |
1053 | 348 |
349 if (face->uAttributes & FACE_PICKED) | |
350 face->uAttributes |= FACE_OUTLINED; | |
351 else | |
352 face->uAttributes &= ~FACE_OUTLINED; | |
353 face->uAttributes &= ~FACE_PICKED; | |
0 | 354 } |
355 } | |
356 v5 = v17 + 1; | |
357 } | |
358 } | |
359 | |
360 //----- (004C17CF) -------------------------------------------------------- | |
323 | 361 void Vis::PickOutdoorFaces_Mouse(float fDepth, RenderVertexSoft *pRay, Vis_SelectionList *list, Vis_SelectionFilter *filter, bool only_reachable) |
196 | 362 { |
0 | 363 if (!pOutdoor) |
364 return; | |
196 | 365 |
366 for (uint i = 0; i < pOutdoor->uNumBModels; ++i) | |
0 | 367 { |
323 | 368 int reachable; |
369 if (!IsBModelVisible(i, &reachable)) | |
196 | 370 continue; |
323 | 371 if (!reachable && only_reachable) |
196 | 372 continue; |
373 | |
374 auto bmodel = &pOutdoor->pBModels[i]; | |
375 for (uint j = 0; j < bmodel->uNumFaces; ++j) | |
0 | 376 { |
916 | 377 auto face = &bmodel->pFaces[j]; |
196 | 378 if (is_part_of_selection(face, filter)) |
0 | 379 { |
196 | 380 BLVFace blv_face; |
381 blv_face.FromODM(face); | |
382 | |
383 RenderVertexSoft intersection; | |
384 if (Intersect_Ray_Face(pRay, pRay + 1, &fDepth, &intersection, &blv_face, i)) | |
0 | 385 { |
916 | 386 pGame->pIndoorCameraD3D->ViewTransform(&intersection, 1); |
1029 | 387 int v13 = fixpoint_from_float(/*v12, */intersection.vWorldViewPosition.x); |
388 v13 &= 0xFFFF0000; | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
389 v13 += PID(OBJECT_BModel, j | (i << 6)); |
196 | 390 |
391 list->AddObject(face, VisObjectType_Face, v13); | |
0 | 392 } |
323 | 393 |
1053 | 394 if (blv_face.uAttributes & FACE_PICKED) |
323 | 395 face->uAttributes |= FACE_OUTLINED; |
396 else | |
397 face->uAttributes &= ~FACE_OUTLINED; | |
1053 | 398 blv_face.uAttributes &= ~FACE_PICKED; |
0 | 399 } |
400 } | |
401 } | |
402 } | |
403 | |
404 //----- (004C1930) -------------------------------------------------------- | |
405 //bool Vis::j_DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) | |
406 //{return DoesRayIntersectBillboard(fDepth, uD3DBillboardIdx);} | |
407 | |
408 //----- (004C1944) -------------------------------------------------------- | |
295 | 409 int Vis::PickClosestActor(int object_id, unsigned int pick_depth, int a4, int a5, int a6) |
0 | 410 { |
295 | 411 //float v6; // ST00_4@3 |
412 //int result; // eax@4 | |
194 | 413 Vis_SelectionFilter v8; // [sp+18h] [bp-20h]@3 |
295 | 414 //__int64 v9; // [sp+2Ch] [bp-Ch]@3 |
415 //Vis *v14; // [sp+34h] [bp-4h]@1 | |
0 | 416 |
295 | 417 //v14 = this; |
0 | 418 |
194 | 419 static Vis_SelectionList Vis_static_sub_4C1944_stru_F8BDE8; |
295 | 420 |
421 v8.object_type = VisObjectType_Sprite; | |
194 | 422 v8.object_id = object_id; |
1322 | 423 v8.at_ai_state = a6; |
424 v8.no_at_ai_state = a5; | |
425 v8.select_flags = a4; | |
0 | 426 Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers = 0; |
295 | 427 PickBillboards_Keyboard(pick_depth, &Vis_static_sub_4C1944_stru_F8BDE8, &v8); |
194 | 428 Vis_static_sub_4C1944_stru_F8BDE8.create_object_pointers(Vis_SelectionList::Unique); |
0 | 429 sort_object_pointers( |
194 | 430 Vis_static_sub_4C1944_stru_F8BDE8.object_pointers, |
0 | 431 0, |
432 Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers - 1); | |
295 | 433 |
434 if (!Vis_static_sub_4C1944_stru_F8BDE8.uNumPointers) | |
435 return -1; | |
436 return Vis_static_sub_4C1944_stru_F8BDE8.object_pointers[0]->sZValue; | |
0 | 437 } |
438 | |
439 //----- (004C1A02) -------------------------------------------------------- | |
440 void Vis::_4C1A02() | |
441 { | |
442 RenderVertexSoft v1; // [sp+8h] [bp-C0h]@1 | |
443 RenderVertexSoft v2; // [sp+38h] [bp-90h]@1 | |
444 RenderVertexSoft v3; // [sp+68h] [bp-60h]@1 | |
445 RenderVertexSoft v4; // [sp+98h] [bp-30h]@1 | |
446 | |
447 v4.flt_2C = 0.0; | |
448 v4.vWorldPosition.x = 0.0; | |
449 v4.vWorldPosition.y = 65536.0; | |
450 v4.vWorldPosition.z = 0.0; | |
451 v3.flt_2C = 0.0; | |
452 v3.vWorldPosition.x = 65536.0; | |
453 v3.vWorldPosition.y = 0.0; | |
454 v3.vWorldPosition.z = 0.0; | |
455 memcpy(&v1, &v3, sizeof(v1)); | |
456 v3.flt_2C = 0.0; | |
457 v3.vWorldPosition.x = 0.0; | |
458 v3.vWorldPosition.y = 65536.0; | |
459 v3.vWorldPosition.z = 0.0; | |
460 memcpy(&v2, &v4, sizeof(v2)); | |
461 v4.flt_2C = 0.0; | |
462 v4.vWorldPosition.x = 65536.0; | |
463 v4.vWorldPosition.y = 0.0; | |
464 v4.vWorldPosition.z = 0.0; | |
465 memcpy(&this->stru_200C, &v1, 0x60u); | |
466 memcpy(&v1, &v4, sizeof(v1)); | |
467 memcpy(&v2, &v3, sizeof(v2)); | |
468 memcpy(&this->stru_206C, &v1, 0x60u); | |
469 } | |
470 | |
471 //----- (004C1ABA) -------------------------------------------------------- | |
472 bool Vis::SortVectors_x(RenderVertexSoft *a2, int a3, int a4) | |
473 { | |
474 bool result; // eax@1 | |
475 RenderVertexSoft *v5; // edx@2 | |
476 int v6; // ebx@2 | |
477 int i; // ecx@2 | |
478 int v8; // esi@3 | |
479 int v9; // esi@5 | |
480 RenderVertexSoft *v10; // eax@8 | |
481 RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 | |
482 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 | |
483 int v13; // [sp+64h] [bp-Ch]@7 | |
484 Vis *thisa; // [sp+68h] [bp-8h]@1 | |
485 RenderVertexSoft *v15; // [sp+6Ch] [bp-4h]@2 | |
486 | |
1113
39eaa6b00141
something to bool cast (performance warning) mostly fixed
Grumpy7
parents:
1110
diff
changeset
|
487 result = a4 != 0; |
0 | 488 thisa = this; |
489 if ( a4 > a3 ) | |
490 { | |
491 v5 = a2; | |
492 v15 = &a2[a4]; | |
493 v6 = a3 - 1; | |
494 memcpy(&v12, &a2[a4], sizeof(v12)); | |
495 for ( i = a4; ; i = v13 ) | |
496 { | |
497 v8 = (int)&v5[v6].vWorldViewPosition; | |
498 do | |
499 { | |
500 v8 += 48; | |
501 ++v6; | |
502 } | |
503 while ( *(float *)v8 < (double)v12.vWorldViewPosition.x ); | |
504 v9 = (int)&v5[i].vWorldViewPosition; | |
505 do | |
506 { | |
507 v9 -= 48; | |
508 --i; | |
509 } | |
510 while ( *(float *)v9 > (double)v12.vWorldViewPosition.x ); | |
511 v13 = i; | |
512 if ( v6 >= i ) | |
513 break; | |
514 v10 = &v5[i]; | |
515 memcpy(&v11, &a2[v6], sizeof(v11)); | |
516 v5 = a2; | |
517 memcpy(&a2[v6], v10, sizeof(a2[v6])); | |
518 memcpy(v10, &v11, 0x30u); | |
519 } | |
520 memcpy(&v11, &v5[v6], sizeof(v11)); | |
521 memcpy(&v5[v6], v15, sizeof(v5[v6])); | |
522 memcpy(v15, &v11, 0x30u); | |
523 SortVectors_x(v5, a3, v6 - 1); | |
524 SortVectors_x(a2, v6 + 1, a4); | |
525 } | |
526 return true; | |
527 } | |
528 | |
529 //----- (004C1BAA) -------------------------------------------------------- | |
194 | 530 int Vis::get_object_zbuf_val(Vis_ObjectInfo *info) |
0 | 531 { |
194 | 532 switch (info->object_type) |
533 { | |
534 case VisObjectType_Sprite: | |
535 case VisObjectType_Face: | |
536 return info->sZValue; | |
0 | 537 |
194 | 538 default: |
539 MessageBoxW(nullptr, L"Undefined type requested for: CVis::get_object_zbuf_val()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1037", 0); | |
540 return -1; | |
0 | 541 } |
542 } | |
543 | |
544 //----- (004C1BF1) -------------------------------------------------------- | |
545 int Vis::get_picked_object_zbuf_val() | |
546 { | |
194 | 547 if (!default_list.uNumPointers) |
548 return -1; | |
0 | 549 |
998 | 550 return get_object_zbuf_val(default_list.object_pointers[0]); |
0 | 551 } |
552 | |
553 //----- (004C1C0C) -------------------------------------------------------- | |
1025 | 554 bool Vis::Intersect_Ray_Face(RenderVertexSoft *pRayStart, RenderVertexSoft *pRayEnd, float *pDepth, RenderVertexSoft *Intersection, BLVFace *pFace, unsigned int pBModelID) |
0 | 555 { |
1049 | 556 float c1; // st5@6 |
557 float c2; // st7@11 | |
558 Vec3_short_ IntersectPoint; // ST04_6@11 | |
559 | |
323 | 560 |
1025 | 561 if (pFace->Portal() || pFace->Invisible()) |
323 | 562 return false; |
563 | |
1049 | 564 int ray_dir_x = pRayEnd->vWorldPosition.x - pRayStart->vWorldPosition.x,//calculate the direction vector of the line(âû÷èñëèì âåêòîð íàïðàâëåíèÿ ëèíèé) |
565 ray_dir_y = pRayEnd->vWorldPosition.y - pRayStart->vWorldPosition.y, | |
323 | 566 ray_dir_z = pRayEnd->vWorldPosition.z - pRayStart->vWorldPosition.z; |
567 | |
1025 | 568 //c1 = -d-(n*p0) |
569 c1 = -pFace->pFacePlane.dist -(pFace->pFacePlane.vNormal.x * pRayStart->vWorldPosition.x | |
570 + pFace->pFacePlane.vNormal.y * pRayStart->vWorldPosition.y | |
571 + pFace->pFacePlane.vNormal.z * pRayStart->vWorldPosition.z); | |
1049 | 572 if (c1 > 0) |
573 return false; | |
574 #define EPSILON 1e-6 | |
1025 | 575 //c2 = n*u |
1049 | 576 c2 = pFace->pFacePlane.vNormal.x * ray_dir_y// get length of the line(Ýòî äàåò íàì äëèíó ëèíèè) |
1025 | 577 + pFace->pFacePlane.vNormal.y * ray_dir_x |
578 + pFace->pFacePlane.vNormal.z * ray_dir_z; | |
579 if (c2 > -EPSILON && c2 < EPSILON) // ray faces face's normal ( > 0) or parallel ( == 0) | |
323 | 580 return false; |
581 | |
1025 | 582 //t = -d-(n*p0)/n*u |
1049 | 583 float t = c1 / c2;//How far is crossing the line in percent for 0 to 1(Êàê äàëåêî ïåðåñå÷åíèå ëèíèè â ïðîöåíòàõ îò 0 äî 1 ) |
323 | 584 |
1049 | 585 if (t < 0 || t > 1) |
323 | 586 return false; |
587 | |
1049 | 588 // p(t) = p0 + tu; |
589 Intersection->vWorldPosition.x = pRayStart->vWorldPosition.x + t * ray_dir_y;// add the interest to the start line(ïðèáàâëÿåì ïðîöåíò ëèíèè ê ëèíèè ñòàðòà) | |
590 Intersection->vWorldPosition.y = pRayStart->vWorldPosition.y + t * ray_dir_x; | |
591 Intersection->vWorldPosition.z = pRayStart->vWorldPosition.z + t * ray_dir_z; | |
592 | |
1545 | 593 IntersectPoint.x = Intersection->vWorldPosition.x; |
594 IntersectPoint.y = Intersection->vWorldPosition.y; | |
595 IntersectPoint.z = Intersection->vWorldPosition.z; | |
1049 | 596 |
1050 | 597 if ( !CheckIntersectBModel(pFace, IntersectPoint, pBModelID) ) |
1049 | 598 return false; |
599 | |
600 *pDepth = t;//Record the distance from the origin of the ray (Çàïèñûâàåì äèñòàíöèþ îò íà÷àëà ëó÷à) | |
323 | 601 return true; |
0 | 602 } |
603 | |
604 //----- (004C1D2B) -------------------------------------------------------- | |
1050 | 605 bool Vis::CheckIntersectBModel(BLVFace *pFace, Vec3_short_ IntersectPoint, unsigned int uModelID) |
0 | 606 { |
607 int v5; // esi@10 | |
608 bool v6; // edi@10 | |
609 signed int v10; // ebx@14 | |
1051 | 610 int v15; // [sp+10h] [bp-Ch]@10 |
611 signed int v16; // [sp+18h] [bp-4h]@10 | |
612 | |
613 int a = 0, b = 0; | |
614 | |
615 if (IntersectPoint.x < pFace->pBounding.x1 || IntersectPoint.x > pFace->pBounding.x2 || | |
616 IntersectPoint.y < pFace->pBounding.y1 || IntersectPoint.y > pFace->pBounding.y2 || | |
617 IntersectPoint.z < pFace->pBounding.z1 || IntersectPoint.z > pFace->pBounding.z2 ) | |
618 return false; | |
619 | |
620 if (uModelID != -1) | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1177
diff
changeset
|
621 ODM_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a.data(), intersect_face_vertex_coords_list_b.data(), |
1051 | 622 &IntersectPoint, pFace, uModelID); |
623 else | |
1205
8c02e6f74b29
arrays to std::arrays phase 2 - mm7_data.h converted
Grumpy7
parents:
1177
diff
changeset
|
624 BLV_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a.data(), intersect_face_vertex_coords_list_b.data(), |
1051 | 625 &IntersectPoint, pFace); |
626 v5 = 2 * pFace->uNumVertices; | |
627 v16 = 0; | |
628 intersect_face_vertex_coords_list_a[v5] = intersect_face_vertex_coords_list_a[0]; | |
629 intersect_face_vertex_coords_list_b[v5] = intersect_face_vertex_coords_list_b[0]; | |
630 v6 = intersect_face_vertex_coords_list_b[0] >= b; | |
631 if (v5 <= 0) | |
632 return false; | |
633 for ( uint i = 0; i < v5; ++i ) | |
634 { | |
635 if ( v16 >= 2 ) | |
636 break; | |
1110 | 637 if ( v6 ^ (intersect_face_vertex_coords_list_b[i + 1] >= b) ) |
1051 | 638 { |
639 if ( intersect_face_vertex_coords_list_a[i + 1] >= a ) | |
640 v10 = 0; | |
641 else | |
642 v10 = 2; | |
643 v10 |= intersect_face_vertex_coords_list_a[i] < a ? 1 : 0; | |
644 if ( v10 != 3 ) | |
645 { | |
646 if ( !v10) | |
647 ++v16; | |
648 else | |
649 { | |
650 int _v1 = fixpoint_div(intersect_face_vertex_coords_list_a[i + 1] - intersect_face_vertex_coords_list_a[i], | |
651 intersect_face_vertex_coords_list_b[i + 1] - intersect_face_vertex_coords_list_b[i]); | |
652 int _v2 = fixpoint_mul(b - intersect_face_vertex_coords_list_b[i], _v1) + 32768; | |
653 | |
654 if (intersect_face_vertex_coords_list_a[i] + (_v2 >> 16) >= a) | |
655 ++v16; | |
656 } | |
657 } | |
658 } | |
659 v6 = intersect_face_vertex_coords_list_b[i + 1] >= b; | |
660 } | |
661 | |
662 if ( v16 != 1 ) | |
663 return false; | |
1053 | 664 |
1507 | 665 extern bool show_picked_face; |
666 if ( show_picked_face ) | |
667 pFace->uAttributes |= FACE_PICKED; | |
1051 | 668 return true; |
669 /* | |
670 int v5; // esi@10 | |
671 bool v6; // edi@10 | |
672 signed int v10; // ebx@14 | |
0 | 673 int v11; // edi@16 |
674 signed int v12; // ST28_4@18 | |
675 signed __int64 v13; // qtt@18 | |
676 signed int result; // eax@21 | |
677 int v15; // [sp+10h] [bp-Ch]@10 | |
678 signed int v16; // [sp+18h] [bp-4h]@10 | |
679 | |
1050 | 680 int a = 0, b = 0; |
1049 | 681 |
682 if (IntersectPoint.x < pFace->pBounding.x1 || IntersectPoint.x > pFace->pBounding.x2 || | |
683 IntersectPoint.y < pFace->pBounding.y1 || IntersectPoint.y > pFace->pBounding.y2 || | |
684 IntersectPoint.z < pFace->pBounding.z1 || IntersectPoint.z > pFace->pBounding.z2 ) | |
323 | 685 return false; |
686 | |
1025 | 687 pFace->uAttributes |= 0x80000000; |
1049 | 688 |
323 | 689 if (uModelID != -1) |
1050 | 690 ODM_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a, intersect_face_vertex_coords_list_b, |
1049 | 691 &IntersectPoint, pFace, uModelID); |
323 | 692 else |
1050 | 693 BLV_CreateIntersectFacesVertexCoordList(&a, &b, intersect_face_vertex_coords_list_a, intersect_face_vertex_coords_list_b, |
1049 | 694 &IntersectPoint, pFace); |
1025 | 695 v5 = 2 * pFace->uNumVertices; |
323 | 696 v16 = 0; |
1050 | 697 intersect_face_vertex_coords_list_a[v5] = intersect_face_vertex_coords_list_a[0]; |
698 intersect_face_vertex_coords_list_b[v5] = intersect_face_vertex_coords_list_b[0]; | |
699 v6 = intersect_face_vertex_coords_list_b[0] >= b; | |
323 | 700 if (v5 <= 0) |
701 return false; | |
1049 | 702 for ( uint i = 0; i < v5; ++i ) |
0 | 703 { |
704 if ( v16 >= 2 ) | |
705 break; | |
1050 | 706 if ( v6 ^ intersect_face_vertex_coords_list_b[i + 1] >= b ) |
0 | 707 { |
1050 | 708 if ( intersect_face_vertex_coords_list_a[i + 1] >= a ) |
0 | 709 v10 = 0; |
710 else | |
711 v10 = 2; | |
1050 | 712 v11 = v10 | intersect_face_vertex_coords_list_a[i] < a; |
0 | 713 if ( v11 != 3 ) |
714 { | |
715 if ( !v11 | |
1050 | 716 || (v12 = intersect_face_vertex_coords_list_a[i + 1] - intersect_face_vertex_coords_list_a[i], |
0 | 717 LODWORD(v13) = v12 << 16, |
718 HIDWORD(v13) = v12 >> 16, | |
1050 | 719 intersect_face_vertex_coords_list_a[i] |
720 + ((signed int)(((unsigned __int64)(v13 / (intersect_face_vertex_coords_list_b[i + 1] - intersect_face_vertex_coords_list_b[i]) | |
721 * (signed int)((b - intersect_face_vertex_coords_list_b[i]) << 16)) >> 16) + 32768) >> 16) >= a) ) | |
0 | 722 ++v16; |
723 } | |
724 } | |
1050 | 725 v6 = intersect_face_vertex_coords_list_b[i + 1] >= b; |
0 | 726 } |
1050 | 727 result = true; |
0 | 728 if ( v16 != 1 ) |
1050 | 729 result = false; |
0 | 730 return result; |
1051 | 731 }*/ |
0 | 732 } |
733 | |
734 //----- (004C1EE5) -------------------------------------------------------- | |
1322 | 735 void Vis::BLV_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, |
736 __int16 *intersect_face_vertex_coords_list_b, | |
737 Vec3_short_ *IntersectPoint, BLVFace *pFace) | |
0 | 738 { |
1035 | 739 if (pFace->uAttributes & FACE_XY_PLANE) |
740 { | |
1050 | 741 *a = IntersectPoint->x; |
742 *b = IntersectPoint->y; | |
1035 | 743 |
744 for (uint i = 0; i < pFace->uNumVertices; ++i) | |
745 { | |
1050 | 746 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; |
747 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; | |
1035 | 748 |
1050 | 749 intersect_face_vertex_coords_list_b[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; |
750 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; | |
1035 | 751 } |
752 } | |
753 else if (pFace->uAttributes & FACE_XZ_PLANE) | |
754 { | |
1050 | 755 *a = IntersectPoint->x; |
756 *b = IntersectPoint->z; | |
0 | 757 |
1035 | 758 for (uint i = 0; i < pFace->uNumVertices; ++i) |
0 | 759 { |
1050 | 760 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].x; |
761 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pXInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].x; | |
1035 | 762 |
1050 | 763 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; |
764 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; | |
1035 | 765 } |
766 } | |
767 else if (pFace->uAttributes & FACE_YZ_PLANE) | |
768 { | |
1050 | 769 *a = IntersectPoint->y; |
770 *b = IntersectPoint->z; | |
1035 | 771 |
772 for (uint i = 0; i < pFace->uNumVertices; ++i) | |
773 { | |
1050 | 774 intersect_face_vertex_coords_list_a[2 * i] = pFace->pYInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].y; |
775 intersect_face_vertex_coords_list_a[2 * i + 1] = pFace->pYInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].y; | |
1035 | 776 |
1050 | 777 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pIndoor->pVertices[pFace->pVertexIDs[i]].z; |
778 intersect_face_vertex_coords_list_b[2 * i + 1] = pFace->pZInterceptDisplacements[i + 1] + pIndoor->pVertices[pFace->pVertexIDs[i + 1]].z; | |
0 | 779 } |
780 } | |
1050 | 781 else assert(false); |
0 | 782 } |
783 | |
784 //----- (004C2186) -------------------------------------------------------- | |
1322 | 785 void Vis::ODM_CreateIntersectFacesVertexCoordList(int *a, int *b, __int16 *intersect_face_vertex_coords_list_a, |
786 __int16 *intersect_face_vertex_coords_list_b, | |
787 Vec3_short_ *IntersectPoint, BLVFace *pFace, unsigned int uModelID) | |
0 | 788 { |
1038 | 789 if (pFace->uAttributes & FACE_XY_PLANE) |
0 | 790 { |
1050 | 791 *a = IntersectPoint->x; |
792 *b = IntersectPoint->y; | |
1038 | 793 |
794 for (int i = 0; i < pFace->uNumVertices; ++i) | |
795 { | |
1050 | 796 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; |
797 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; | |
1038 | 798 |
1050 | 799 intersect_face_vertex_coords_list_b[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; |
800 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; | |
1038 | 801 } |
802 } | |
803 else if (pFace->uAttributes & FACE_XZ_PLANE) | |
804 { | |
1050 | 805 *a = IntersectPoint->x; |
806 *b = IntersectPoint->z; | |
1038 | 807 |
808 for (int i = 0; i < pFace->uNumVertices; ++i) | |
0 | 809 { |
1050 | 810 intersect_face_vertex_coords_list_a[2 * i] = pFace->pXInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].x; |
811 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pXInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].x; | |
1038 | 812 |
1050 | 813 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z; |
814 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; | |
1038 | 815 } |
816 } | |
817 else if (pFace->uAttributes & FACE_YZ_PLANE) | |
818 { | |
1050 | 819 *a = IntersectPoint->y; |
820 *b = IntersectPoint->z; | |
1038 | 821 |
822 for (int i = 0; i < pFace->uNumVertices; ++i) | |
823 { | |
1050 | 824 intersect_face_vertex_coords_list_a[2 * i] = pFace->pYInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].y; |
825 intersect_face_vertex_coords_list_a[i * 2 + 1] = pFace->pYInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].y; | |
1038 | 826 |
1050 | 827 intersect_face_vertex_coords_list_b[2 * i] = pFace->pZInterceptDisplacements[i] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i]].z; |
828 intersect_face_vertex_coords_list_b[i * 2 + 1] = pFace->pZInterceptDisplacements[i + 1] + pOutdoor->pBModels[uModelID].pVertices.pVertices[pFace->pVertexIDs[i + 1]].z; | |
0 | 829 } |
830 } | |
1038 | 831 else assert(false); |
832 } | |
833 | |
834 //----- (0046A0A1) -------------------------------------------------------- | |
835 int UnprojectX(int x) | |
836 { | |
837 int v3; // [sp-4h] [bp-8h]@5 | |
838 | |
839 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
840 { | |
841 if ( pRenderer->pRenderD3D ) | |
842 v3 = pGame->pIndoorCameraD3D->fov; | |
843 else | |
844 v3 = pIndoorCamera->flt_1C_fov; | |
845 } | |
0 | 846 else |
847 { | |
1038 | 848 v3 = pOutdoorCamera->int_fov_rad; |
849 } | |
850 return stru_5C6E00->Atan2(x - pViewport->uScreenCenterX, v3) - stru_5C6E00->uIntegerHalfPi; | |
851 } | |
852 | |
853 //----- (0046A0F6) -------------------------------------------------------- | |
854 int UnprojectY(int y) | |
855 { | |
856 int v3; // [sp-4h] [bp-8h]@5 | |
857 | |
858 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
859 { | |
860 if ( pRenderer->pRenderD3D ) | |
861 v3 = pGame->pIndoorCameraD3D->fov; | |
0 | 862 else |
1038 | 863 v3 = pIndoorCamera->flt_1C_fov; |
0 | 864 } |
1038 | 865 else |
866 { | |
867 v3 = pOutdoorCamera->int_fov_rad; | |
868 } | |
869 return stru_5C6E00->Atan2(y - pViewport->uScreenCenterY, v3) - stru_5C6E00->uIntegerHalfPi; | |
0 | 870 } |
871 | |
872 //----- (004C248E) -------------------------------------------------------- | |
873 void Vis::CastPickRay(RenderVertexSoft *pRay, float fMouseX, float fMouseY, float fPickDepth) | |
874 { | |
1025 | 875 int pRotY; // esi@1 |
876 Vec3_int_ pStartR; // ST08_12@1 | |
877 int pRotX; // ST04_4@1 | |
878 int pDepth; // eax@1 | |
0 | 879 RenderVertexSoft v11[2]; // [sp+2Ch] [bp-74h]@1 |
1025 | 880 int outx; |
0 | 881 int outz; // [sp+94h] [bp-Ch]@1 |
882 int outy; // [sp+98h] [bp-8h]@1 | |
883 | |
1545 | 884 pRotY = pIndoorCamera->sRotationY + UnprojectX(fMouseX); |
1025 | 885 pStartR.z = pIndoorCamera->pos.z; |
886 pStartR.x = pIndoorCamera->pos.x; | |
887 pStartR.y = pIndoorCamera->pos.y; | |
1545 | 888 pRotX = pIndoorCamera->sRotationX + UnprojectY(fMouseY); |
1029 | 889 pDepth = fixpoint_from_float(fPickDepth); |
1025 | 890 Vec3_int_::Rotate(pDepth, pRotY, pRotX, pStartR, &outx, &outy, &outz); |
891 | |
0 | 892 v11[0].flt_2C = 0.0; |
1025 | 893 v11[0].vWorldPosition.x = (double)outx; |
0 | 894 v11[0].vWorldPosition.y = (double)outy; |
895 v11[0].vWorldPosition.z = (double)outz; | |
1025 | 896 |
0 | 897 v11[1].flt_2C = 0.0; |
1025 | 898 v11[1].vWorldPosition.x = (double)pIndoorCamera->pos.x; |
899 v11[1].vWorldPosition.y = (double)pIndoorCamera->pos.y; | |
900 v11[1].vWorldPosition.z = (double)pIndoorCamera->pos.z; | |
901 | |
1322 | 902 memcpy(pRay, &v11[1], sizeof(RenderVertexSoft)); |
903 memcpy(&pRay[1], &v11[0], sizeof(RenderVertexSoft)); | |
0 | 904 } |
905 | |
906 //----- (004C2551) -------------------------------------------------------- | |
1177 | 907 Vis_ObjectInfo *Vis_SelectionList::SelectionPointers(int pVisObjectType, int pid) |
0 | 908 { |
1171 | 909 //unsigned int v3; // esi@1 |
1173 | 910 //signed int v4; // edx@1 |
911 //char *v5; // eax@2 | |
912 //Vis_ObjectInfo *result; // eax@6 | |
0 | 913 |
1171 | 914 //v3 = this->uNumPointers; |
1137 | 915 if ( this->uNumPointers > 0 ) |
0 | 916 { |
1137 | 917 for ( uint i = 0; i < this->uNumPointers; ++i ) |
0 | 918 { |
1137 | 919 if ( this->object_pool[i].object_type == pVisObjectType && (this->object_pool[i].sZValue & 0xFFFF) == pid ) |
920 return &this->object_pool[i]; | |
0 | 921 } |
922 } | |
1322 | 923 return nullptr; |
1173 | 924 /*v4 = 0; |
1171 | 925 if ( this->uNumPointers <= 0 ) |
926 return false; | |
0 | 927 else |
928 { | |
1173 | 929 //v5 = (char *)&this->object_pool[0].sZValue; |
930 while ( this->object_pool[v4].object_type != a2 || (this->object_pool[v4].sZValue & 0xFFFF) != a3 ) | |
0 | 931 { |
932 ++v4; | |
1173 | 933 //v5 += 12; |
1171 | 934 if ( v4 >= this->uNumPointers ) |
935 return false; | |
0 | 936 } |
194 | 937 result = &this->object_pool[v4]; |
0 | 938 } |
1173 | 939 return result;*/ |
0 | 940 } |
941 | |
942 //----- (004C2591) -------------------------------------------------------- | |
194 | 943 void Vis_SelectionList::create_object_pointers(PointerCreationType type) |
0 | 944 { |
194 | 945 switch (type) |
946 { | |
947 case All: | |
948 { | |
949 for (uint i = 0; i < uNumPointers; ++i) | |
950 object_pointers[i] = &object_pool[i]; | |
951 } | |
952 break; | |
0 | 953 |
194 | 954 case Unique: // seems quite retarted; the inner if condition will never trigger, since we compare pointers, not values. pointers will always be unique |
955 { // but it may be decompilation error thou | |
956 bool create = true; | |
957 | |
958 for (uint i = 0; i < uNumPointers; ++i) | |
0 | 959 { |
194 | 960 for (uint j = 0; j < i; ++j) |
0 | 961 { |
194 | 962 if (object_pointers[j] == &object_pool[i]) |
0 | 963 { |
194 | 964 create = false; |
965 break; | |
0 | 966 } |
967 } | |
194 | 968 |
969 if (create) | |
970 object_pointers[i] = &object_pool[i]; | |
0 | 971 } |
972 } | |
196 | 973 break; |
194 | 974 |
975 default: | |
0 | 976 MessageBoxW(nullptr, L"Unknown pointer creation flag passed to ::create_object_pointers()", L"E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:1358", 0); |
977 } | |
978 } | |
979 | |
980 //----- (004C264A) -------------------------------------------------------- | |
1322 | 981 void Vis::sort_object_pointers( Vis_ObjectInfo **pPointers, int start, int end ) |
982 { | |
983 int sort_start; // edx@1 | |
984 int forward_sort_index; // esi@2 | |
985 signed int backward_sort_index; // ecx@2 | |
986 unsigned int last_z_val; // eax@3 | |
987 unsigned int more_lz_val; // ebx@4 | |
988 unsigned int less_lz_val; // ebx@6 | |
989 Vis_ObjectInfo *temp_pointer; // eax@7 | |
194 | 990 Vis_ObjectInfo *a3a; // [sp+14h] [bp+Ch]@2 |
0 | 991 |
1322 | 992 sort_start = start; |
993 | |
994 if ( end > start ) | |
0 | 995 { |
1177 | 996 do |
0 | 997 { |
1322 | 998 forward_sort_index = sort_start - 1; |
999 backward_sort_index = end; | |
1000 do | |
0 | 1001 { |
1322 | 1002 last_z_val = pPointers[end]->sZValue&0xFFFF0000; |
1177 | 1003 do |
0 | 1004 { |
1322 | 1005 ++forward_sort_index; |
1006 more_lz_val = pPointers[forward_sort_index]->sZValue&0xFFFF0000; | |
0 | 1007 } |
1322 | 1008 while ( more_lz_val < last_z_val ); |
1009 | |
0 | 1010 do |
1011 { | |
1322 | 1012 if ( backward_sort_index < 1 ) |
0 | 1013 break; |
1322 | 1014 --backward_sort_index; |
1015 less_lz_val = pPointers[backward_sort_index]->sZValue&0xFFFF0000; | |
0 | 1016 } |
1322 | 1017 while ( less_lz_val > last_z_val ); |
1018 | |
1019 temp_pointer = pPointers[forward_sort_index]; | |
1020 if ( forward_sort_index >= backward_sort_index ) | |
1021 { | |
1022 pPointers[forward_sort_index] = pPointers[end]; | |
1023 pPointers[end] = temp_pointer; | |
1024 } | |
1025 else | |
1026 { | |
1027 pPointers[forward_sort_index] = pPointers[backward_sort_index]; | |
1028 pPointers[backward_sort_index] = temp_pointer; | |
1029 } | |
1030 | |
1031 } while ( forward_sort_index < backward_sort_index ); | |
1032 | |
1033 sort_object_pointers(pPointers, sort_start, forward_sort_index - 1); | |
1034 sort_start = forward_sort_index + 1; | |
0 | 1035 } |
1322 | 1036 while ( end > forward_sort_index + 1 ); |
0 | 1037 } |
1038 } | |
1039 | |
1040 //----- (004C26D0) -------------------------------------------------------- | |
1041 bool Vis::SortVerticesByX(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) | |
1042 { | |
1043 bool result; // eax@1 | |
1044 RenderVertexD3D3 *v5; // edx@2 | |
1045 RenderVertexD3D3 *v6; // esi@2 | |
1046 void *v7; // edi@2 | |
1047 unsigned int v8; // ebx@2 | |
1048 RenderVertexD3D3 *v9; // ecx@3 | |
1049 RenderVertexD3D3 *v10; // ecx@5 | |
1050 RenderVertexD3D3 *v11; // eax@8 | |
1051 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 | |
1052 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 | |
1053 Vis *thisa; // [sp+44h] [bp-Ch]@1 | |
1054 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 | |
1055 unsigned int v16; // [sp+4Ch] [bp-4h]@2 | |
1056 | |
1057 result = uEnd; | |
1058 thisa = this; | |
1059 if ( (signed int)uEnd > (signed int)uStart ) | |
1060 { | |
1061 v5 = a2; | |
1062 v6 = &a2[uEnd]; | |
1063 v7 = &v13; | |
1064 v15 = &a2[uEnd]; | |
1065 v8 = uStart - 1; | |
1066 v16 = uEnd; | |
1067 while ( 1 ) | |
1068 { | |
1069 memcpy(v7, v6, 0x20u); | |
1070 v9 = &v5[v8]; | |
1071 do | |
1072 { | |
1073 ++v9; | |
1074 ++v8; | |
1075 } | |
1076 while ( v9->pos.x < (double)v13.pos.x ); | |
1077 v10 = &v5[v16]; | |
1078 do | |
1079 { | |
1080 --v10; | |
1081 --v16; | |
1082 } | |
1083 while ( v10->pos.x > (double)v13.pos.x ); | |
1084 if ( (signed int)v8 >= (signed int)v16 ) | |
1085 break; | |
1086 v11 = &v5[v16]; | |
1087 memcpy(&v12, &a2[v8], sizeof(v12)); | |
1088 v5 = a2; | |
1089 memcpy(&a2[v8], v11, sizeof(a2[v8])); | |
1090 v6 = &v12; | |
1091 v7 = v11; | |
1092 } | |
1093 memcpy(&v12, &v5[v8], sizeof(v12)); | |
1094 memcpy(&v5[v8], v15, sizeof(v5[v8])); | |
1095 memcpy(v15, &v12, 0x20u); | |
1096 SortVerticesByX(v5, uStart, v8 - 1); | |
1097 SortVerticesByX(a2, v8 + 1, uEnd); | |
1098 } | |
1099 return true; | |
1100 } | |
1101 | |
1102 //----- (004C27AD) -------------------------------------------------------- | |
1103 bool Vis::SortVerticesByY(RenderVertexD3D3 *a2, unsigned int uStart, unsigned int uEnd) | |
1104 { | |
1105 bool result; // eax@1 | |
1106 RenderVertexD3D3 *v5; // edx@2 | |
1107 RenderVertexD3D3 *v6; // esi@2 | |
30 | 1108 void *v7; // edi@2 |
0 | 1109 unsigned int v8; // ebx@2 |
30 | 1110 float *v9; // ecx@3 |
1111 float *v10; // ecx@5 | |
1112 RenderVertexD3D3 *v11; // eax@8 | |
0 | 1113 RenderVertexD3D3 v12; // [sp+4h] [bp-4Ch]@8 |
30 | 1114 RenderVertexD3D3 v13; // [sp+24h] [bp-2Ch]@2 |
0 | 1115 Vis *thisa; // [sp+44h] [bp-Ch]@1 |
30 | 1116 RenderVertexD3D3 *v15; // [sp+48h] [bp-8h]@2 |
1117 unsigned int v16; // [sp+4Ch] [bp-4h]@2 | |
0 | 1118 |
1119 result = uEnd; | |
1120 thisa = this; | |
1121 if ( (signed int)uEnd > (signed int)uStart ) | |
1122 { | |
1123 v5 = a2; | |
1124 v6 = &a2[uEnd]; | |
30 | 1125 v7 = &v13; |
1126 v15 = &a2[uEnd]; | |
0 | 1127 v8 = uStart - 1; |
30 | 1128 v16 = uEnd; |
0 | 1129 while ( 1 ) |
1130 { | |
30 | 1131 memcpy(v7, v6, 0x20u); |
1132 v9 = &v5[v8].pos.y; | |
0 | 1133 do |
1134 { | |
30 | 1135 v9+=8; |
0 | 1136 ++v8; |
1137 } | |
30 | 1138 while ( *v9 < (double)v13.pos.y ); |
1139 v10 = &v5[v16].pos.y; | |
0 | 1140 do |
1141 { | |
30 | 1142 v10-=8; |
1143 --v16; | |
0 | 1144 } |
30 | 1145 while ( *v10 > (double)v13.pos.y ); |
1146 if ( (signed int)v8 >= (signed int)v16 ) | |
0 | 1147 break; |
30 | 1148 v11 = &v5[v16]; |
0 | 1149 memcpy(&v12, &a2[v8], sizeof(v12)); |
1150 v5 = a2; | |
30 | 1151 memcpy(&a2[v8], v11, sizeof(a2[v8])); |
0 | 1152 v6 = &v12; |
30 | 1153 v7 = v11; |
0 | 1154 } |
1155 memcpy(&v12, &v5[v8], sizeof(v12)); | |
30 | 1156 memcpy(&v5[v8], v15, sizeof(v5[v8])); |
1157 memcpy(v15, &v12, 0x20u); | |
194 | 1158 SortVerticesByY(v5, uStart, v8 - 1); |
1159 SortVerticesByY(a2, v8 + 1, uEnd); | |
0 | 1160 } |
1161 return true; | |
1162 } | |
1163 | |
1164 //----- (004C288E) -------------------------------------------------------- | |
196 | 1165 bool Vis::SortByScreenSpaceX(RenderVertexSoft *pArray, int sLeft, int sRight) |
0 | 1166 { |
1167 bool result; // eax@1 | |
1168 RenderVertexSoft *v5; // edx@2 | |
1169 int v6; // ebx@2 | |
1170 int i; // ecx@2 | |
1171 int v8; // esi@3 | |
1172 int v9; // esi@5 | |
159 | 1173 //RenderVertexSoft *v10; // eax@8 |
1174 const void *v10; | |
0 | 1175 RenderVertexSoft v11; // [sp+4h] [bp-6Ch]@8 |
1176 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 | |
159 | 1177 //float v13; // [sp+4Ch] [bp-24h]@4 |
0 | 1178 int v14; // [sp+64h] [bp-Ch]@7 |
159 | 1179 //Vis *thisa; // [sp+68h] [bp-8h]@1 |
196 | 1180 //void *thisa; |
159 | 1181 //RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 |
1182 const void *v16; | |
0 | 1183 |
196 | 1184 //thisa = this; |
159 | 1185 if (sRight <= sLeft) |
1186 return true; | |
1187 v5 = pArray; | |
1188 v16 = &pArray[sRight]; | |
1189 v6 = sLeft - 1; | |
1190 memcpy(&v12, &pArray[sRight], sizeof(v12)); | |
1191 for ( i = sRight; ; i = v14 ) | |
0 | 1192 { |
159 | 1193 v8 = (int)&v5[v6].vWorldViewProjX; |
1194 do | |
0 | 1195 { |
159 | 1196 v8 += 48; |
1197 ++v6; | |
1198 } | |
1199 while ( *(float *)v8 < v12.vWorldViewProjX); | |
1200 v9 = (int)&v5[i].vWorldViewProjX; | |
1201 do | |
1202 { | |
1203 v9 -= 48; | |
1204 --i; | |
0 | 1205 } |
159 | 1206 while ( *(float *)v9 > v12.vWorldViewProjX); |
1207 v14 = i; | |
1208 if ( v6 >= i ) | |
1209 break; | |
1210 v10 = &v5[i]; | |
1211 memcpy(&v11, &pArray[v6], sizeof(v11)); | |
1212 v5 = pArray; | |
1213 memcpy(&pArray[v6], v10, sizeof(pArray[v6])); | |
1214 memcpy((void *)v10, &v11, sizeof(0x30u)); | |
0 | 1215 } |
159 | 1216 memcpy(&v11, &v5[v6], sizeof(v11)); |
1217 memcpy(&v5[v6], v16, sizeof(v5[v6])); | |
1218 memcpy((void *)v16, &v11, sizeof(0x30u)); | |
196 | 1219 SortByScreenSpaceX(v5, sLeft, v6 - 1); |
1220 SortByScreenSpaceX(pArray, v6 + 1, sRight); | |
0 | 1221 return true; |
1222 } | |
1223 | |
1224 //----- (004C297E) -------------------------------------------------------- | |
196 | 1225 bool Vis::SortByScreenSpaceY(RenderVertexSoft *pArray, int sLeft, int sRight) |
0 | 1226 { |
159 | 1227 //bool result; // eax@1 |
0 | 1228 RenderVertexSoft *v5; // edx@2 |
1229 int v6; // ebx@2 | |
1230 int i; // ecx@2 | |
1231 int v8; // esi@3 | |
1232 int v9; // esi@5 | |
159 | 1233 //RenderVertexSoft *v10; // eax@8 |
1234 const void *v10; | |
1235 //char v11; // [sp+4h] [bp-6Ch]@8 | |
1236 RenderVertexSoft v11; | |
0 | 1237 RenderVertexSoft v12; // [sp+34h] [bp-3Ch]@2 |
159 | 1238 //float v13; // [sp+50h] [bp-20h]@4 |
0 | 1239 int v14; // [sp+64h] [bp-Ch]@7 |
159 | 1240 //Vis *thisa; // [sp+68h] [bp-8h]@1 |
0 | 1241 RenderVertexSoft *v16; // [sp+6Ch] [bp-4h]@2 |
1242 | |
159 | 1243 if (sRight <= sLeft) |
1244 return true; | |
1245 v5 = pArray; | |
1246 v16 = &pArray[sRight]; | |
1247 v6 = sLeft - 1; | |
1248 memcpy(&v12, &pArray[sRight], sizeof(v12)); | |
1249 for ( i = sRight; ; i = v14 ) | |
0 | 1250 { |
159 | 1251 v8 = (int)&v5[v6].vWorldViewProjY; |
1252 do | |
1253 { | |
1254 v8 += 48; | |
1255 ++v6; | |
1256 } | |
1257 while ( *(float *)v8 < v12.vWorldViewProjY); | |
1258 v9 = (int)&v5[v6].vWorldViewProjY; | |
1259 do | |
0 | 1260 { |
159 | 1261 v9 -= 48; |
1262 --i; | |
0 | 1263 } |
159 | 1264 while ( *(float *)v9 > v12.vWorldViewProjY); |
1265 v14 = i; | |
1266 if ( v6 >= i ) | |
1267 break; | |
1268 v10 = &v5[i]; | |
1269 memcpy(&v11, &pArray[v6], sizeof(0x30)); | |
1270 v5 = pArray; | |
1271 memcpy(&pArray[v6], v10, sizeof(pArray[v6])); | |
1272 memcpy((void *)v10, &v11, sizeof(0x30)); | |
0 | 1273 } |
159 | 1274 memcpy(&v11, &v5[v6], sizeof(0x30)); |
1275 memcpy(&v5[v6], v16, sizeof(v5[v6])); | |
1276 memcpy((void *)v16, &v11, sizeof(0x30)); | |
196 | 1277 SortByScreenSpaceY(v5, sLeft, v6 - 1); |
1278 SortByScreenSpaceY(pArray, v6 + 1, sRight); | |
0 | 1279 return true; |
1280 } | |
1281 | |
1282 //----- (004C04AF) -------------------------------------------------------- | |
1283 Vis::Vis() | |
1284 { | |
1285 RenderVertexSoft v3; // [sp+Ch] [bp-60h]@1 | |
1286 RenderVertexSoft v4; // [sp+3Ch] [bp-30h]@1 | |
1287 | |
1288 v3.flt_2C = 0.0; | |
1289 v3.vWorldPosition.x = 0.0; | |
1290 v3.vWorldPosition.y = 65536.0; | |
1291 v3.vWorldPosition.z = 0.0; | |
1292 v4.flt_2C = 0.0; | |
1293 v4.vWorldPosition.x = 65536.0; | |
1294 v4.vWorldPosition.y = 0.0; | |
1295 v4.vWorldPosition.z = 0.0; | |
196 | 1296 memcpy(&stru_200C, &v4, sizeof(stru_200C)); |
1297 | |
0 | 1298 v4.flt_2C = 0.0; |
1299 v4.vWorldPosition.x = 0.0; | |
1300 v4.vWorldPosition.y = 65536.0; | |
1301 v4.vWorldPosition.z = 0.0; | |
196 | 1302 memcpy(&stru_203C, &v3, sizeof(stru_203C)); |
1303 | |
0 | 1304 v3.flt_2C = 0.0; |
1305 v3.vWorldPosition.x = 65536.0; | |
1306 v3.vWorldPosition.y = 0.0; | |
1307 v3.vWorldPosition.z = 0.0; | |
196 | 1308 memcpy(&stru_206C, &v3, sizeof(stru_206C)); |
1309 memcpy(&stru_209C, &v4, sizeof(stru_209C)); | |
1310 | |
1311 keyboard_pick_depth = 512; | |
0 | 1312 } |
1313 | |
1314 //----- (004C055C) -------------------------------------------------------- | |
194 | 1315 Vis_SelectionList::Vis_SelectionList() |
0 | 1316 { |
1317 for (uint i = 0; i < 512; ++i) | |
1318 { | |
194 | 1319 object_pool[i].object = nullptr; |
1320 object_pool[i].sZValue = -1; | |
1321 object_pool[i].object_type = VisObjectType_Any; | |
0 | 1322 } |
1323 uNumPointers = 0; | |
1324 } | |
1325 | |
1326 //----- (004C05CC) -------------------------------------------------------- | |
194 | 1327 bool Vis::PickKeyboard(Vis_SelectionList *list, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) |
0 | 1328 { |
194 | 1329 if (!list) |
1330 list = &default_list; | |
1331 list->uNumPointers = 0; | |
0 | 1332 |
196 | 1333 PickBillboards_Keyboard(keyboard_pick_depth, list, sprite_filter); |
194 | 1334 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
196 | 1335 PickIndoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); |
194 | 1336 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) |
196 | 1337 PickOutdoorFaces_Keyboard(keyboard_pick_depth, list, face_filter); |
0 | 1338 else |
194 | 1339 assert(false); |
1340 | |
1341 list->create_object_pointers(Vis_SelectionList::Unique); | |
1342 sort_object_pointers(list->object_pointers, 0, list->uNumPointers - 1); | |
1343 | |
0 | 1344 return true; |
1345 } | |
1346 | |
1347 //----- (004C0646) -------------------------------------------------------- | |
194 | 1348 bool Vis::PickMouse(float fDepth, float fMouseX, float fMouseY, Vis_SelectionFilter *sprite_filter, Vis_SelectionFilter *face_filter) |
0 | 1349 { |
1350 RenderVertexSoft pMouseRay[2]; // [sp+1Ch] [bp-60h]@1 | |
1351 | |
194 | 1352 default_list.uNumPointers = 0; |
0 | 1353 CastPickRay(pMouseRay, fMouseX, fMouseY, fDepth); |
194 | 1354 PickBillboards_Mouse(fDepth, fMouseX, fMouseY, &default_list, sprite_filter); |
0 | 1355 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
196 | 1356 PickIndoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter); |
227 | 1357 else if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) |
1358 PickOutdoorFaces_Mouse(fDepth, pMouseRay, &default_list, face_filter, false); | |
0 | 1359 else |
227 | 1360 { |
323 | 1361 Log::Warning(L"Picking mouse in undefined level"); // picking in main menu is default (buggy) game behaviour. should've returned false in Game::PickMouse |
227 | 1362 return false; |
1363 } | |
194 | 1364 default_list.create_object_pointers(Vis_SelectionList::All); |
1365 sort_object_pointers(default_list.object_pointers, 0, default_list.uNumPointers - 1); | |
1366 | |
0 | 1367 return true; |
1368 } | |
1369 | |
1370 //----- (004C06F8) -------------------------------------------------------- | |
196 | 1371 void Vis::PickBillboards_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1372 { |
194 | 1373 for (int i = 0; i < pRenderer->uNumBillboardsToDraw; ++i) |
1374 { | |
1375 auto d3d_billboard = &pRenderer->pBillboardRenderListD3D[i]; | |
0 | 1376 |
194 | 1377 if (is_part_of_selection((void *)i, filter)) |
0 | 1378 { |
194 | 1379 if (DoesRayIntersectBillboard(pick_depth, i)) |
0 | 1380 { |
194 | 1381 auto billboard = &pBillboardRenderList[d3d_billboard->uParentBillboardID]; |
1382 | |
1383 list->AddObject((void *)d3d_billboard->uParentBillboardID, VisObjectType_Sprite, billboard->sZValue); | |
0 | 1384 } |
1385 } | |
1386 } | |
1387 } | |
1388 | |
194 | 1389 |
1390 // tests the object against selection filter to determine whether it can be picked or not | |
0 | 1391 //----- (004C0791) -------------------------------------------------------- |
194 | 1392 bool Vis::is_part_of_selection(void *uD3DBillboardIdx_or_pBLVFace_or_pODMFace, Vis_SelectionFilter *filter) |
0 | 1393 { |
194 | 1394 //stru157 *v3; // esi@1 |
1395 //int result; // eax@1 | |
0 | 1396 int v5; // edx@2 |
194 | 1397 //int v6; // ecx@2 |
1398 //char v7; // zf@3 | |
0 | 1399 int v8; // esi@5 |
1400 std::string *v9; // ecx@7 | |
1401 Actor *v10; // edi@18 | |
194 | 1402 //const char *v12; // [sp-20h] [bp-2Ch]@7 |
0 | 1403 int v13; // [sp-1Ch] [bp-28h]@7 |
194 | 1404 //std::string v14; // [sp-18h] [bp-24h]@7 |
1405 //const char *v15; // [sp-8h] [bp-14h]@7 | |
0 | 1406 int v16; // [sp-4h] [bp-10h]@7 |
1407 | |
194 | 1408 switch (filter->object_type) |
0 | 1409 { |
194 | 1410 case VisObjectType_Any: |
1411 return true; | |
1412 | |
1413 case VisObjectType_Sprite: | |
0 | 1414 { |
1322 | 1415 v5 = filter->select_flags; |
848 | 1416 int object_idx = PID_ID(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid); |
1417 int object_type = PID_TYPE(pBillboardRenderList[pRenderer->pBillboardRenderListD3D[(int)uD3DBillboardIdx_or_pBLVFace_or_pODMFace].uParentBillboardID].object_pid); | |
194 | 1418 if ( v5 & 2 ) |
1419 { | |
1420 if (object_type == filter->object_id) | |
1421 return false; | |
1422 return true; | |
1423 } | |
1424 if ( v5 & 4 ) | |
1425 { | |
1426 v8 = filter->object_id; | |
1427 if ( object_type != filter->object_id) | |
1428 return true; | |
1429 if (v8 != OBJECT_Decoration) | |
1430 { | |
1431 MessageBoxA(nullptr, "Unsupported \"exclusion if no event\" type in CVis::is_part_of_selection", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:207", 0); | |
1432 return true; | |
1433 } | |
1514
965af46e8793
Rename LevelDecoration::field_16_event_id to LevelDecoration::uEventID.
yoctozepto
parents:
1507
diff
changeset
|
1434 if (pLevelDecorations[object_idx].uCog || pLevelDecorations[object_idx].uEventID) |
194 | 1435 return true; |
1436 return pLevelDecorations[object_idx].IsInteractive(); | |
1437 } | |
1438 if (object_type == filter->object_id) | |
1439 { | |
1440 if (object_type != OBJECT_Actor) | |
1441 { | |
1442 MessageBoxA(nullptr, "Default case reached in VIS", "E:\\WORK\\MSDEV\\MM7\\MM7\\Code\\Vis.cpp:245", 0); | |
1443 return true; | |
1444 } | |
1445 | |
1446 v10 = &pActors[object_idx]; | |
1447 int result = 1 << LOBYTE(v10->uAIState); | |
1322 | 1448 if ( result & filter->no_at_ai_state |
1449 || !(result & filter->at_ai_state) | |
194 | 1450 || v5 & 8 && (result = MonsterStats::BelongsToSupertype(v10->pMonsterInfo.uID, MONSTER_SUPERTYPE_UNDEAD)) == 0 ) |
1451 return false; | |
1322 | 1452 if ( !(filter->select_flags & 1) ) |
194 | 1453 return true; |
1454 | |
1455 result = v10->GetActorsRelation(nullptr); | |
1456 if (result == 0) | |
1457 return false; | |
1458 return true; | |
1459 } | |
1460 return false; | |
0 | 1461 } |
194 | 1462 |
1463 case VisObjectType_Face: | |
0 | 1464 { |
194 | 1465 uint face_attrib = 0; |
1466 bool no_event = true; | |
1467 if (uCurrentlyLoadedLevelType == LEVEL_Outdoor) | |
1468 { | |
1469 auto face = (ODMFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; | |
1470 no_event = face->sCogTriggeredID == 0; | |
1471 face_attrib = face->uAttributes; | |
1472 } | |
1473 else if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
1474 { | |
1475 auto face = (BLVFace *)uD3DBillboardIdx_or_pBLVFace_or_pODMFace; | |
1476 no_event = pIndoor->pFaceExtras[face->uFaceExtraID].uEventID == 0; | |
1477 face_attrib = face->uAttributes; | |
1478 } | |
1479 else | |
1480 assert(false); | |
1481 | |
1482 if (filter->object_id != OBJECT_BLVDoor) | |
1483 return true; | |
1322 | 1484 if (no_event || face_attrib & filter->no_at_ai_state) |
194 | 1485 return false; |
1322 | 1486 return (face_attrib & filter->at_ai_state) != 0; |
0 | 1487 } |
194 | 1488 |
1489 default: | |
1490 assert(false); | |
0 | 1491 } |
1492 } | |
1493 | |
1494 //----- (004C091D) -------------------------------------------------------- | |
1495 bool Vis::DoesRayIntersectBillboard(float fDepth, unsigned int uD3DBillboardIdx) | |
1496 { | |
159 | 1497 int v3; // eax@3 |
1498 //signed int v5; // ecx@4 | |
1499 //float v6; // ST04_4@6 | |
1500 //float v7; // ST00_4@7 | |
194 | 1501 //int v8; // eax@10 |
1502 //unsigned int v9; // eax@12 | |
159 | 1503 int v10; // eax@17 |
1504 double v11; // st6@18 | |
1505 double v12; // st7@18 | |
1506 double v13; // st4@18 | |
1507 float v14; // ST0C_4@22 | |
1508 float v15; // ST08_4@22 | |
1509 //float v16; // ST04_4@23 | |
1510 //float v17; // ST00_4@24 | |
194 | 1511 //signed int v18; // eax@27 |
1512 //unsigned int v19; // eax@29 | |
159 | 1513 double v20; // st6@32 |
1514 double v21; // st7@32 | |
1515 int v22; // eax@32 | |
1516 double v23; // st7@36 | |
1517 //void *v24; // esi@40 | |
1518 float v25; // ST08_4@40 | |
1519 //float v26; // ST04_4@41 | |
1520 //float v27; // ST00_4@42 | |
1521 int v28; // eax@45 | |
1522 unsigned int v29; // eax@47 | |
1523 char result; // al@48 | |
1524 struct RenderVertexSoft pPickingRay[2]; | |
1525 //int v31; // [sp+20h] [bp-DCh]@5 | |
1526 struct RenderVertexSoft local_80[2]; | |
1322 | 1527 |
1528 float test_x; | |
1529 float test_y; | |
1530 | |
1531 float t1_x; | |
1532 float t1_y; | |
1533 float t2_x; | |
1534 float t2_y; | |
1535 float swap_temp; | |
194 | 1536 int v37; // [sp+F0h] [bp-Ch]@5 |
1322 | 1537 |
159 | 1538 signed int v40; // [sp+108h] [bp+Ch]@17 |
1322 | 1539 |
0 | 1540 |
194 | 1541 static Vis_SelectionList Vis_static_stru_F91E10; |
0 | 1542 Vis_static_stru_F91E10.uNumPointers = 0; |
159 | 1543 v3 = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].uParentBillboardID; |
1544 if (v3 == -1) | |
1545 return false; | |
1322 | 1546 |
159 | 1547 if (pBillboardRenderList[v3].GetFloatZ() > fDepth) |
1548 return false; | |
1322 | 1549 |
194 | 1550 |
1390 | 1551 GetPolygonCenter(pRenderer->pBillboardRenderListD3D[v3].pQuads, 4, &test_x, &test_y); |
1322 | 1552 CastPickRay(pPickingRay, test_x, test_y, fDepth); |
194 | 1553 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) |
196 | 1554 PickIndoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter); |
0 | 1555 else |
196 | 1556 PickOutdoorFaces_Mouse(fDepth, pPickingRay, &Vis_static_stru_F91E10, &vis_face_filter, false); |
194 | 1557 Vis_static_stru_F91E10.create_object_pointers(); |
1558 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); | |
159 | 1559 if (Vis_static_stru_F91E10.uNumPointers) |
0 | 1560 { |
194 | 1561 if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) |
1322 | 1562 return true; |
159 | 1563 } |
1322 | 1564 else if ((double)(pViewport->uScreen_TL_X) <= test_x && |
1565 (double)pViewport->uScreen_BR_X >= test_x && | |
1566 (double)pViewport->uScreen_TL_Y <= test_y && | |
1567 (double)pViewport->uScreen_BR_Y >= test_y) | |
1568 return true; | |
1569 | |
1570 for (v40 = 0; v40 < 4; ++v40) | |
0 | 1571 { |
1390 | 1572 test_x=pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[v40].pos.x; |
1573 test_y= pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[v40].pos.y; | |
1322 | 1574 if ((double)(pViewport->uScreen_TL_X) <= test_x && |
1575 (double)pViewport->uScreen_BR_X >= test_x && | |
1576 (double)pViewport->uScreen_TL_Y <= test_y && | |
1577 (double)pViewport->uScreen_BR_Y >= test_y) | |
159 | 1578 { |
1322 | 1579 CastPickRay(local_80, test_x, test_y, fDepth); |
1580 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1581 PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter); | |
1582 else | |
1583 PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false); | |
1584 Vis_static_stru_F91E10.create_object_pointers(); | |
1585 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); | |
1586 if ( !Vis_static_stru_F91E10.uNumPointers ) | |
1587 return true; | |
1588 if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) | |
1589 return true; | |
159 | 1590 } |
1322 | 1591 |
0 | 1592 } |
1322 | 1593 |
159 | 1594 if ( v40 >= 4 ) |
0 | 1595 { |
1322 | 1596 if ( uCurrentlyLoadedLevelType != LEVEL_Outdoor ) |
159 | 1597 return false; |
1390 | 1598 t1_x = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[0].pos.x; |
1599 t2_x = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[3].pos.x; | |
1322 | 1600 |
1390 | 1601 t1_y = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[0].pos.y; |
1602 t2_y = pRenderer->pBillboardRenderListD3D[uD3DBillboardIdx].pQuads[1].pos.y; | |
1322 | 1603 if ( t1_x > t2_x ) |
0 | 1604 { |
1322 | 1605 swap_temp = t1_x; |
1606 t1_x = t2_x; | |
1607 t2_x = swap_temp; | |
0 | 1608 } |
1322 | 1609 if ( t1_y > t2_y ) |
1610 test_y = t1_y; | |
1611 else | |
1612 test_y = t2_y; | |
1613 | |
159 | 1614 Vis_static_stru_F91E10.uNumPointers = 0; |
1322 | 1615 |
1616 test_x = (t2_x - t1_x) * 0.5; | |
1617 if ((double)(pViewport->uScreen_TL_X) <= test_x && | |
1618 (double)pViewport->uScreen_BR_X >= test_x && | |
1619 (double)pViewport->uScreen_TL_Y <= test_y && | |
1620 (double)pViewport->uScreen_BR_Y >= test_y) | |
1621 { | |
1622 CastPickRay(local_80, test_x, test_y, fDepth); | |
1623 if ( uCurrentlyLoadedLevelType == LEVEL_Indoor ) | |
1624 PickIndoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter); | |
1625 else | |
1626 PickOutdoorFaces_Mouse(fDepth, local_80, &Vis_static_stru_F91E10, &vis_face_filter, false); | |
1627 Vis_static_stru_F91E10.create_object_pointers(); | |
1628 sort_object_pointers(Vis_static_stru_F91E10.object_pointers, 0, Vis_static_stru_F91E10.uNumPointers - 1); | |
1629 if ( !Vis_static_stru_F91E10.uNumPointers ) | |
1630 return true; | |
1631 if (Vis_static_stru_F91E10.object_pointers[0]->actual_z > pBillboardRenderList[v3].actual_z) | |
1632 return true; | |
1633 | |
1634 } | |
1635 | |
0 | 1636 } |
1322 | 1637 return false; |
0 | 1638 } |
1639 // F93E18: using guessed type char static_byte_F93E18_init; | |
1640 | |
1641 //----- (004C0D32) -------------------------------------------------------- | |
196 | 1642 void Vis::PickIndoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1643 { |
1644 int result; // eax@1 | |
742 | 1645 signed int pFaceID; // esi@2 |
1646 BLVFace *pFace; // edi@4 | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
1647 //unsigned int v7; // eax@6 |
194 | 1648 Vis_ObjectInfo *v8; // eax@6 |
0 | 1649 signed int i; // [sp+18h] [bp-8h]@1 |
1650 | |
1651 result = 0; | |
676
ecfb1b3c9a39
BLV: when standing right on the portal (orange wall) everything looks fine
Nomad
parents:
618
diff
changeset
|
1652 for ( i = 0; i < (signed int)pBspRenderer->num_faces; ++i ) |
0 | 1653 { |
742 | 1654 pFaceID = pBspRenderer->faces[result].uFaceID; |
1655 if ( pFaceID >= 0 ) | |
0 | 1656 { |
742 | 1657 if ( pFaceID < (signed int)pIndoor->uNumFaces ) |
0 | 1658 { |
742 | 1659 pFace = &pIndoor->pFaces[pFaceID]; |
1660 if ( !pGame->pIndoorCameraD3D->IsCulled(&pIndoor->pFaces[pFaceID]) ) | |
0 | 1661 { |
742 | 1662 if ( is_part_of_selection(pFace, filter) ) |
0 | 1663 { |
916 | 1664 v8 = DetermineFacetIntersection(pFace, PID(OBJECT_BModel, pFaceID), pick_depth); |
0 | 1665 if ( v8 ) |
194 | 1666 list->AddObject(v8->object, v8->object_type, v8->sZValue); |
0 | 1667 } |
1668 } | |
1669 } | |
1670 } | |
1671 result = i + 1; | |
1672 } | |
1673 } | |
1674 | |
1675 //----- (004C0DEA) -------------------------------------------------------- | |
196 | 1676 void Vis::PickOutdoorFaces_Keyboard(float pick_depth, Vis_SelectionList *list, Vis_SelectionFilter *filter) |
0 | 1677 { |
196 | 1678 for (uint i = 0; i < pOutdoor->uNumBModels; ++i) |
1679 { | |
1680 int v17; | |
1681 if (!IsBModelVisible(i, &v17)) | |
1682 continue; | |
1683 if (!v17) | |
1684 continue; | |
0 | 1685 |
196 | 1686 auto bmodel = pOutdoor->pBModels + i; |
1687 for (uint j = 0; j < bmodel->uNumFaces; ++j) | |
0 | 1688 { |
916 | 1689 auto face = &bmodel->pFaces[j]; |
196 | 1690 |
1691 if (is_part_of_selection(face, filter) ) | |
0 | 1692 { |
196 | 1693 BLVFace blv_face; |
1694 blv_face.FromODM(face); | |
1695 | |
828
0f56abdcce94
Massive refactors of spells + PID (packed id) macros introduced.
Nomad
parents:
742
diff
changeset
|
1696 int pid = PID(OBJECT_BModel, j | (i << 6)); |
916 | 1697 if (auto object_info = DetermineFacetIntersection(&blv_face, pid, pick_depth)) |
196 | 1698 list->AddObject(object_info->object, object_info->object_type, object_info->sZValue); |
0 | 1699 } |
1700 } | |
1701 } | |
1702 } |