Rise
The Vieneo Province
Loading...
Searching...
No Matches
buildings.cpp
Go to the documentation of this file.
1#include "buildings.h"
2#include "Viewscreen.h"
3#include "RtsTerrainSurface.h"
4#include "CitySignQuad.h"
5#include "RunwayEdgeLights.h"
6#include "LampContact.h"
9#include <optional>
10#include <array>
11
12#include <fcntl.h> // For _O_RDWR, _O_BINARY, _O_RDONLY, O_TEXT
13#include <sys/stat.h> // For _S_IWRITE, _S_IREAD
14#include "io.h" // needed for the _write
15#include <algorithm> // std::sort
16
17#include "../MathUtilities.h"
18
19
21{
22 viewscreen = ptr;
23 logger = ptr->logger;
24
25#pragma region Rocks
26
27 char msg[99] = {};
28 char file[99] = {};
29 int handle;
30 RiseMath::Vector3 tempnormal;
31
32 sprintf_s(file, sizeof file, "Meshes\\40 Rocks reduced.daw");
33 _sopen_s(&handle, file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
34 if (handle == -1)
35 {
36 sprintf_s(msg, sizeof msg, "buildings ctor failed to load \"%s\"", file);
38 return;
39 }
40
41 short tempvertices;
42 _lseek(handle, 0L, SEEK_SET);
43 _read(handle, &tempvertices, 2);
44
45 sprintf_s(msg, sizeof msg, "buildings ctor scanning %i file vertices (%i primitives)...", tempvertices, tempvertices / 3);
46 logger->Log(msg);
47
48 rockVertexBuffer = new RiseVertex2Vertex[tempvertices];
49
50 for (short r = 0; r < tempvertices; r++)
51 {
52 _read(handle, &tempnormal, 12);
53 rockVertexBuffer[r].x = tempnormal.x;
54 rockVertexBuffer[r].y = tempnormal.y;
55 rockVertexBuffer[r].z = tempnormal.z;
56 _read(handle, &tempnormal, 12);
57 rockVertexBuffer[r].nx = -tempnormal.x;
58 rockVertexBuffer[r].ny = tempnormal.y;
59 rockVertexBuffer[r].nz = tempnormal.z;
60 _read(handle, &tempnormal.x, 4);
61 //rockVertexBuffer[r].tu = tempnormal.x;
62 _read(handle, &tempnormal.y, 4);
63 //rockVertexBuffer[r].tv = tempnormal.y;
64 }
65
66 _close(handle);
67
68
69 // for each distinct vertex we want a variagated color
70 std::vector<RiseMath::Vector3> vertices;
71 for (short r = 0; r < tempvertices; r++)
72 {
74 if (std::find(vertices.begin(), vertices.end(), vec) == vertices.end())
75 {
76 vertices.emplace_back(vec);
77 float variegation = RandomFloat() * 0.15f - 0.1f;
78 for (short s = 0; s < tempvertices; s++)
79 {
80 if (rockVertexBuffer[s].x == vec.x && rockVertexBuffer[s].y == vec.y && rockVertexBuffer[s].z == vec.z)
81 rockVertexBuffer[s].tv2 = variegation;
82 }
83 }
84 }
85
86 sprintf_s(file, sizeof file, "Meshes\\40 Rocks reduced.dix");
87 _sopen_s(&handle, file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
88 if (handle == -1)
89 {
90 sprintf_s(msg, sizeof msg, "buildings ctor failed to load \"%s\"", file);
92 return;
93 }
94
95 _lseek(handle, 0, SEEK_SET);
96 _read(handle, &rockComponents, 2);
97
100 {
101 sprintf_s(msg, sizeof(msg), "buildings ctor Failed to initialize %i component(s) for rocks", rockComponents);
103 }
104 else
105 {
106 viewscreen->gameclass->AddTrackedResource("rockComponentArray"); // managed, memory only
107
108 sprintf_s(msg, sizeof(msg), "buildings ctor initialized %i component(s) for rocks", rockComponents);
109 logger->Log(msg);
110 }
111
112 short i_temp;
113 for (short s = 0; s < rockComponents; s++)
114 {
115 _lseek(handle, static_cast<long>(s) * 100L + 99L, SEEK_SET); // To 0
116 _read(handle, &i_temp, 2); // 0
118 _read(handle, &i_temp, 2); // 2
119 rockComponentArray[s].primitives = i_temp;
120 _read(handle, &rockComponentArray[s].nominalxyz, 12); // 4
121 _read(handle, &rockComponentArray[s].nominalypr, 12); // 16
122 _read(handle, &rockComponentArray[s].boundsphere, 4); // 28
123 _read(handle, &rockComponentArray[s].extendby, 12); // 32
124 _read(handle, &rockComponentArray[s].texture, 2); // 44
125 _read(handle, &rockComponentArray[s].nominalCG, 12); // 46
126 _read(handle, &rockComponentArray[s].type, 1); // 58
127 _read(handle, &rockComponentArray[s].speedExtend, 4); // 59
128 _read(handle, &rockComponentArray[s].hingeaxis, 12); // 63
129 _read(handle, &rockComponentArray[s].hingeCG, 12); // 75
130 _read(handle, &rockComponentArray[s].hingeextent, 4); // 87
131 _read(handle, &rockComponentArray[s].attachto, 2); // 87
132
133 // Dynamic
135 }
136
137 _close(handle);
138
139#pragma endregion
140}
141
143{
145
146#pragma region Rocks
147
150 viewscreen->gameclass->UpdateTrackedResource("rockComponentArray", 3);
151
152#pragma endregion
153}
154
156{
157 // Local terrain geometry also owns native D3D11 resources. Release it
158 // before creating the replacement device, including cached runway lights.
159 for (short u = 0; u < lclC; ++u)
160 for (short v = 0; v < lclC; ++v)
161 {
162 SAFE_RELEASE(curbVB[u][v]);
163 SAFE_RELEASE(rockVB[u][v]);
164 curbPrims[u][v] = rockPrims[u][v] = 0;
165 curbBounds[u][v] = rockBounds[u][v] = {};
166 }
168 runwayLightInstances.clear();
169}
170
172{
173 if (grid.type == PlotType::UserTownship)
174 {
175 // these are the transparent domes that were added 15 years later to the parks
176 if (r == 113) return CheckLayout(82, grid);
177 if (r == 114) return CheckLayout(81, grid);
178 if (r == 115) return CheckLayout(80, grid);
179 }
180
181 return
182 r < 32 && 0x80000000 >> r & grid.layout1 ||
183 r >= 32 && r < 64 && 0x80000000 >> (r - 32) & grid.layout2 ||
184 r >= 64 && r < 96 && 0x80000000 >> (r - 64) & grid.layout3 ||
185 r >= 96 && 0x80000000 >> (r - 96) & grid.layout4;
186}
187
188float buildings::determinant(float A[8][8], int n) const
189{
190 float D = 0; // Initialize result
191
192 // Base case : if matrix contains single element
193 if (n == 1)
194 return A[0][0];
195
196 float temp[8][8]; // To store cofactors
197
198 float sign = 1; // To store sign multiplier
199
200 // Iterate for each element of first row
201 for (int f = 0; f < n; f++)
202 {
203 // Getting Cofactor of A[0][f]
204 getCofactor(A, temp, 0, f, n);
205 D += sign * A[0][f] * determinant(temp, n - 1);
206
207 // terms are to be added with alternate sign
208 sign = -sign;
209 }
210
211 return D;
212}
213
214void buildings::adjoint(float A[8][8], float adj[8][8]) const
215{
216 // temp is used to store cofactors of A[][]
217 float temp[8][8];
218
219 for (int i = 0; i < 8; i++)
220 {
221 for (int j = 0; j < 8; j++)
222 {
223 // Get cofactor of A[i][j]
224 getCofactor(A, temp, i, j, 8);
225
226 // sign of adj[j][i] positive if sum of row
227 // and column indexes is even.
228 float sign = ((i + j) % 2 == 0) ? 1.0f : -1.0f;
229
230 // Interchanging rows and columns to get the
231 // transpose of the cofactor matrix
232 adj[j][i] = sign * determinant(temp, 7);
233 }
234 }
235}
236
237void buildings::inverse(float A[8][8], float inverse[8][8]) const
238{
239 // Find determinant of A[][]
240 float det = determinant(A, 8);
241 if (det == 0)
242 throw std::exception("Singular matrix, can't find its inverse");
243
244 // Find adjoint
245 float adj[8][8];
246 adjoint(A, adj);
247
248 // Find Inverse using formula "inverse(A) = adj(A)/det(A)"
249 for (int i = 0; i < 8; i++)
250 for (int j = 0; j < 8; j++)
251 inverse[i][j] = adj[i][j] / float(det);
252}
253
254void buildings::getCofactor(float A[8][8], float temp[8][8], int p, int q, int n) const
255{
256 int i = 0, j = 0;
257
258 // Looping for each element of the matrix
259 for (int row = 0; row < n; row++)
260 {
261 for (int col = 0; col < n; col++)
262 {
263 // Copying into temporary matrix only those element
264 // which are not in given row and column
265 if (row != p && col != q)
266 {
267 temp[i][j++] = A[row][col];
268
269 // Row is filled, so increase row index and
270 // reset col index
271 if (j == n - 1)
272 {
273 j = 0;
274 i++;
275 }
276 }
277 }
278 }
279}
280
282{
283 UINT r;
284 char msg[999];
285 HRESULT hr;
286
287 short buildzoneOrdinal = static_cast<short>(buildzones.size());
288 sprintf_s(msg, sizeof msg, "Building() will be using slot %i...", buildzoneOrdinal);
289 logger->Log(msg);
290 gridarray[t][s].buildzoneOrdinal = buildzoneOrdinal;
291
292 BUILDZONE buildzone = BUILDZONE();
293
294 buildzone.u = t - 31 + viewscreen->ptrGrid->tcp.u; buildzone.v = s - 31 + viewscreen->ptrGrid->tcp.v;
295 // Physical plot identity survives vector compaction and camera-relative shifts.
296 buildzone.adEntity = (uint64_t(ourstarC) << 56) | (uint64_t(ourplanetC) << 48) | (uint64_t(ourmoonC) << 40) |
297 (uint64_t(uint8_t(viewscreen->ptrGrid->cube)) << 32) | (uint64_t(uint16_t(buildzone.u)) << 16) | uint16_t(buildzone.v);
298
299 sprintf_s(msg, sizeof msg, "Building() %i loading type %i @ %i %i (u%i v%i)...", buildzoneOrdinal, gridarray[t][s].type, t, s, buildzone.u, buildzone.v);
300 logger->Log(msg);
301 buildzone.type = gridarray[t][s].type;
302 buildzone.powered = gridarray[t][s].powered;
303
304
305 char file[99];
306 int handle;
307
308 switch (buildzone.type)
309 {
311 sprintf_s(file, sizeof file, "meshes\\deois-financial.dix");
312 buildzone.emissive = 0.5f;
313 buildzone.newVersion = true;
314 break;
316 sprintf_s(file, sizeof file, "meshes\\house1.dix");
317 buildzone.emissive = 0.1f;
318 break;
320 sprintf_s(file, sizeof file, "meshes\\mining1.dix");
321 buildzone.emissive = 0.2f;
322 buildzone.newVersion = true;
323 break;
325 sprintf_s(file, sizeof file, "meshes\\Deois-industrial.dix");
326 buildzone.emissive = 0.5f;
327 break;
329 sprintf_s(file, sizeof file, "meshes\\Deois-city center.dix");
330 buildzone.emissive = 0.5f;
331 buildzone.newVersion = true;
332 break;
334 sprintf_s(file, sizeof file, "meshes\\Deois-transit district.dix");
335 buildzone.emissive = 0.5f;
336 buildzone.newVersion = true;
337 break;
338 //case PlotType::Noizni:
339 //sprintf_s(file, sizeof file, "meshes\\noizni.dix");
340 //buildzone.emissive = 0.2f;
341 //break;
343 sprintf_s(file, sizeof file, "meshes\\NorthPole.dix");
344 buildzone.emissive = 0.2f;
345 buildzone.newVersion = true;
346 break;
348 sprintf_s(file, sizeof file, "meshes\\chojeir.dix");
349 buildzone.emissive = 0.4f;
350 buildzone.newVersion = true;
351 break;
353 sprintf_s(file, sizeof file, "meshes\\farm1.dix");
354 buildzone.emissive = 0.1f;
355 buildzone.newVersion = true;
356 break;
358 sprintf_s(file, sizeof file, "meshes\\town1.dix");
359 buildzone.emissive = 0.2f;
360 buildzone.newVersion = true;
361 break;
363 sprintf_s(file, sizeof file, "meshes\\sea-arcridge.dix");
364 buildzone.emissive = 0.3f;
365 break;
367 sprintf_s(file, sizeof file, "meshes\\Deois-port.dix");
368 buildzone.emissive = 0.5f;
369 break;
371 sprintf_s(file, sizeof file, "meshes\\airfield.dix");
372 buildzone.emissive = 0.1f;
373 buildzone.newVersion = true;
374 break;
375 //case PlotType::UserSalvage:
376 //sprintf_s(file, sizeof file, "meshes\\salvage1.dix");
377 //buildzone.emissive = 0.2f;
378 //break;
380 sprintf_s(file, sizeof file, "meshes\\refinery.dix");
381 buildzone.emissive = 0.1f;
382 buildzone.newVersion = true;
383 break;
385 sprintf_s(file, sizeof file, "meshes\\O-4 ruin 1-1.dix");
386 buildzone.emissive = 0.0f;
387 break;
389 sprintf_s(file, sizeof file, "meshes\\O-4 ruin 1-2.dix");
390 buildzone.emissive = 0.0f;
391 break;
393 sprintf_s(file, sizeof file, "meshes\\O-4 ruin 1-3.dix");
394 buildzone.emissive = 0.0f;
395 break;
397 sprintf_s(file, sizeof file, "meshes\\O-4 ruin 1-4.dix");
398 buildzone.emissive = 0.0f;
399 break;
400 default:
401 sprintf_s(msg, sizeof msg, "Building() %i DIX could not match a type %i!", buildzoneOrdinal, buildzone.type);
403 return E_UNEXPECTED;
404 }
405
406 // this is stored on the grid and then used for the clouds ... I am guessing it is too late at that point? or we need to prompt a SRenderPoint?
407 gridarray[t][s].emissive = buildzone.emissive * RiseMath::Color(0.0853626f, 0.0980091f, 0.1011710f, 1);
408
409 _sopen_s(&handle, file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
410 if (handle == -1)
411 {
412 sprintf_s(msg, sizeof msg, "Building() %i failed to load \"%s\"!", buildzoneOrdinal, file);
414 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
415 }
416
417 unsigned short filecomponents;
418 _lseek(handle, 0, SEEK_SET);
419 _read(handle, &filecomponents, 2);
420 buildzone.components = 0;
421
422 // need to figure up total based on number of 1's in layout
423 if (gridarray[t][s].layout1 == 0L && gridarray[t][s].layout2 == 0L && gridarray[t][s].layout3 == 0L && gridarray[t][s].layout4 == 0L)
424 {
425 assert(!gridarray[t][s].IsUserColony());
426 buildzone.components = filecomponents; // this will run for cities!
427 }
428 else
429 {
430 for (r = 0; r < filecomponents; r++)
431 {
432 if (CheckLayout(r, gridarray[t][s]))
433 buildzone.components++;
434 }
435 }
436
437
438 //sprintf_s(msg, sizeof msg, "buildzone[%i].componentarray", buildzoneOrdinal);
439 if (buildzone.componentarray)
440 {
442 //viewscreen->gameclass->UpdateTrackedResource(msg, 3);
443 }
444 buildzone.componentarray = new s_mesh_component[buildzone.components];
445 if (buildzone.componentarray == nullptr)
446 {
447 sprintf_s(msg, sizeof msg, "Building() %i could not create component array for \"%s\"", buildzoneOrdinal, file);
449 return E_OUTOFMEMORY;
450 }
451 //viewscreen->gameclass->AddTrackedResource(msg); // managed, it is just memory
452
453
454 sprintf_s(msg, sizeof msg, "Building() %i loading %i of %i components for \"%s\"", buildzoneOrdinal, buildzone.components, filecomponents, file);
455 logger->Log(msg);
456
457 long vertices = 0;
458 short tempr = 0;
459 for (r = 0; r < filecomponents; r++)
460 {
461 bool add;
462 if (gridarray[t][s].layout1 != 0L || gridarray[t][s].layout2 != 0L || gridarray[t][s].layout3 != 0L || gridarray[t][s].layout4 != 0L)
463 add = CheckLayout(r, gridarray[t][s]);
464 else
465 add = true; // city
466
467 if (add)
468 {
469 short i_temp;
470 _lseek(handle, static_cast<long>(r) * 100L + 99L, SEEK_SET); // To 0
471 // @todo should probably be checking the version field ... if loading in changes to Deois ever fails this is probably why!
472 if (!buildzone.newVersion)
473 {
474 _read(handle, &i_temp, 2); // 0
475 buildzone.componentarray[tempr].startvertex = i_temp;
476 _read(handle, &i_temp, 2); // 2
477 buildzone.componentarray[tempr].primitives = i_temp;
478 }
479 else
480 {
481 _read(handle, &buildzone.componentarray[tempr].startvertex, 4); // 0
482 _read(handle, &buildzone.componentarray[tempr].primitives, 4); // 4
483 }
484 _read(handle, &buildzone.componentarray[tempr].nominalxyz, 12); // 4
485 _read(handle, &buildzone.componentarray[tempr].nominalypr, 12); // 16
486 _read(handle, &buildzone.componentarray[tempr].boundsphere, 4); // 28
487 _read(handle, &buildzone.componentarray[tempr].extendby, 12); // 32
488 _read(handle, &buildzone.componentarray[tempr].texture, 2); // 44
489 _lseek(handle, 12L, SEEK_CUR); // To 58 (SKIP CG 12)
490 _read(handle, &buildzone.componentarray[tempr].type, 1); // 58
491 _lseek(handle, 32L, SEEK_CUR); // To 91 (SKIP SPEED 4, HINGE AXIS 12, HINGE CG 12, HINGE EXTENT 4)
492 _read(handle, &buildzone.componentarray[tempr].attachto, 2); // 91
493
494 if (buildzone.componentarray[tempr].texture < 0 ||
495 buildzone.componentarray[tempr].texture >= citytextureC)
496 {
497 sprintf_s(msg, sizeof msg, "Building type %i component %i had out-of-bounds texture: %i", gridarray[t][s].type, tempr, buildzone.componentarray[tempr].texture);
499 buildzone.componentarray[tempr].texture = 0;
500 }
501
502 buildzone.componentarray[tempr].extended = 0.0f; // Current extended %
503 vertices += buildzone.componentarray[tempr].primitives * 3;
504
505 tempr++;
506 }
507 }
508
509 _close(handle);
510
511 // RTS
512 if (gridarray[t][s].UsesRts())
513 {
514 sprintf_s(msg, sizeof msg, "Building() %i loading RTS grid for \"%s\"", buildzoneOrdinal, file);
515 logger->Log(msg);
516
517 buildzone.rts = new RTSGRID[26 * 26];
518 if (!buildzone.rts)
519 {
520 sprintf_s(msg, sizeof msg, "Building() %i could not create RTS array for \"%s\"", buildzoneOrdinal, file);
522 return E_OUTOFMEMORY;
523 }
524 //sprintf_s(msg, sizeof msg, "buildzone[%i].rts", buildzoneOrdinal);
525 //viewscreen->gameclass->AddTrackedResource(msg); // managed, it is just memory
526
527 // so back in the day we had a 2048x2048 image that represented the RTS from the air
528 // but that only looked good from the air ... so we broke it into a 26x26 grid each with 1440x1440 images ?? why ... not power of 2?
529 // each grid piece is approximately 77x77 meters
530 // many of these are reused, rotated ... total of 73 (not counting light layers)
531 // so that enhanced the detail level by a factor of 18+ but did nothing for the depth (curbs)
532 // so we had Georgi do a whole set of these where he extruded the curbs!
533 // but it is complicated because the CTY files are now stored as the "skewed" version (using the GetSkewMatrix and Edit->Modify)
534 // that was done to fix the buildings (were not terrain comforming) not aligning with the depth map (terrain conforming)
535 // Bill is testing usability of RTS global value (to be moved to viewscreen)
536 // need a place to make a 4096 vertex buffer of primitives ... gets updated every time rts changes... current rts plus 8 surrounding ...
537 // has to support crossing into neighboring RTS grids
538 // we want to render the curbs before we render the rtsvb ... worried about bias/aliasing
539
540
541 // saving these out to separate RTS files
542 int rtsHandle = -1;
543 char rtsFile[MAX_PATH];
544 strcpy_s(rtsFile, MAX_PATH, file);
545 int tt = strlen(file) - 3;
546 rtsFile[tt++] = 'r';
547 rtsFile[tt++] = 't';
548 rtsFile[tt] = 's';
549 //_sopen_s(&rtsHandle, rtsFile, _O_WRONLY | _O_CREAT | _O_TRUNC | O_BINARY, _SH_DENYWR, _S_IWRITE);
550 _sopen_s(&rtsHandle, rtsFile, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
551 if (rtsHandle == -1)
552 {
553 sprintf_s(msg, sizeof msg, "Building() %i failed to load \"%s\"!", buildzoneOrdinal, rtsFile);
555 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
556 }
557 //_write(rtsHandle, buildzone[VB].rts, sizeof RTSGRID * 26 * 26);
558 _read(rtsHandle, buildzone.rts, sizeof RTSGRID * 26 * 26);
559 _close(rtsHandle);
560
561 if (FAILED(Rendering::ClientRenderer()->CreateVertexBuffer(26 * 26 * 3 * 2 * sizeof RiseVertex2Vertex,
563 Rendering::ResourcePool::Managed, &buildzone.RTSVB, NULL)))
564 {
565 sprintf_s(msg, sizeof msg, "Building() %i could not create RTS memory (%i vertices) for \"%s\"", buildzoneOrdinal, 26 * 26 * 3 * 2, file);
567 return E_OUTOFMEMORY;
568 }
569
570 //sprintf_s(msg, sizeof msg, "buildzone[%i].RTSVB", buildzoneOrdinal);
571 //viewscreen->gameclass->AddTrackedResource(msg); // managed
572
573 sprintf_s(msg, sizeof msg, "buildzone[%i].rtscomponentarray", buildzoneOrdinal);
575 if (buildzone.rtscomponentarray == nullptr)
576 {
577 sprintf_s(msg, sizeof msg, "Building() %i could not create RTS component array for \"%s\"", buildzoneOrdinal, file);
579 return E_OUTOFMEMORY;
580 }
581 //viewscreen->gameclass->AddTrackedResource(msg); // managed, it is just memory
582 }
583
584
585
587 &buildzone.VB, NULL)))
588 {
589 sprintf_s(msg, sizeof msg, "Building() %i could not create memory (%i vertices) for \"%s\"", buildzoneOrdinal, vertices, file);
591 return E_OUTOFMEMORY;
592 }
593 sprintf_s(msg, sizeof msg, "Building() %i created VB (%i vertices) for \"%s\"", buildzoneOrdinal, vertices, file);
594 logger->Log(msg);
595 //sprintf_s(msg, sizeof msg, "buildzone[%i].VB", buildzoneOrdinal);
596 //viewscreen->gameclass->AddTrackedResource(msg); // managed
597
598
599 // Vertices -----------------------------------------------------------------------------
600 switch (gridarray[t][s].type)
601 {
603 sprintf_s(file, sizeof file, "Meshes\\deois-financial.daw");
604 break;
606 sprintf_s(file, sizeof file, "Meshes\\house1.daw");
607 break;
609 sprintf_s(file, sizeof file, "Meshes\\mining1.daw");
610 break;
612 sprintf_s(file, sizeof file, "Meshes\\Deois-industrial.daw");
613 break;
615 sprintf_s(file, sizeof file, "Meshes\\Deois-city center.daw");
616 break;
618 sprintf_s(file, sizeof file, "Meshes\\Deois-transit district.daw");
619 break;
620 /*case PlotType::Noizni:
621 sprintf_s(file, sizeof file, "Meshes\\noizni.daw");
622 break;*/
624 sprintf_s(file, sizeof file, "Meshes\\NorthPole.daw");
625 break;
627 sprintf_s(file, sizeof file, "Meshes\\chojeir.daw");
628 break;
630 sprintf_s(file, sizeof file, "Meshes\\farm1.daw");
631 break;
633 sprintf_s(file, sizeof file, "Meshes\\town1.daw");
634 break;
636 sprintf_s(file, sizeof file, "Meshes\\sea-arcridge.daw");
637 break;
639 sprintf_s(file, sizeof file, "Meshes\\Deois-port.daw");
640 break;
642 sprintf_s(file, sizeof file, "Meshes\\airfield.daw");
643 break;
644 /*case PlotType::UserSalvage:
645 sprintf_s(file, sizeof file, "Meshes\\salvage1.daw");
646 break;*/
648 sprintf_s(file, sizeof file, "Meshes\\refinery.daw");
649 break;
651 sprintf_s(file, sizeof file, "Meshes\\O-4 ruin 1-1.daw");
652 break;
654 sprintf_s(file, sizeof file, "Meshes\\O-4 ruin 1-2.daw");
655 break;
657 sprintf_s(file, sizeof file, "Meshes\\O-4 ruin 1-3.daw");
658 break;
660 sprintf_s(file, sizeof file, "Meshes\\O-4 ruin 1-4.daw");
661 break;
662 default:
663 sprintf_s(msg, sizeof msg, "Building() %i DAW could not match a type %i!", buildzoneOrdinal, buildzone.type);
665 return E_UNEXPECTED;
666 }
667 _sopen_s(&handle, file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
668 if (handle == -1)
669 {
670 sprintf_s(msg, sizeof msg, "Building() %i failed to load \"%s\"", buildzoneOrdinal, file);
672 return HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
673 }
674
675 UINT tempvertices;
676 _lseek(handle, 0L, SEEK_SET);
677 if (!buildzone.newVersion)
678 {
679 short i_temp;
680 _read(handle, &i_temp, 2);
681 tempvertices = i_temp;
682 }
683 else
684 _read(handle, &tempvertices, 4);
685
686 sprintf_s(msg, sizeof msg, "Building() %i scanning %i file vertices...", buildzoneOrdinal, tempvertices);
687 logger->Log(msg);
688
689 RiseVertex2Vertex* tempdax = new RiseVertex2Vertex[tempvertices]{};
690 RiseMath::Vector3 tempnormal;
691
692 for (r = 0; r < tempvertices; r++)
693 {
694 _read(handle, &tempnormal, 12);
695 tempdax[r].x = tempnormal.x;
696 tempdax[r].y = tempnormal.y;
697 tempdax[r].z = tempnormal.z;
698 _read(handle, &tempnormal, 12);
699 tempdax[r].nx = -tempnormal.x;
700 tempdax[r].ny = tempnormal.y;
701 tempdax[r].nz = tempnormal.z;
702 _read(handle, &tempnormal.x, 4);
703 tempdax[r].tu = tempnormal.x;
704 _read(handle, &tempnormal.y, 4);
705 tempdax[r].tv = tempnormal.y;
706 }
707
708 // TERPOS
709
710 // UL 0 >UL
711 //
712 // 1 2 >1
713 //
714 // vUL v0 >vUL
715
716 RiseMath::Matrix matrixTemp, matrixWorld, matrixRotation;
717 RiseMath::Vector3 ul, ll, ur, lr, leftvec, rightvec, northvector, result;
718 // first determine CG location --------------------------------------------------------------
719 switch (gridarray[t][s].zone)
720 {
721 case 0: // Along diagonal for cities only
722 ul = gridarray[t][s].position;
723 ll = gridarray[t][s + 1].position;
724 ur = gridarray[t + 1][s].position;
725 lr = gridarray[t + 1][s + 1].position;
726
727 // Center
728 buildzone.terpos = insidearray[t][s][2];
729 break;
730
731 case 1: // Along center beam (TOP LEFT)
732 ul = gridarray[t][s].position;
733 ll = insidearray[t][s][1];
734 ur = insidearray[t][s][0];
735 lr = insidearray[t][s][2];
736
737 // Center
738 buildzone.terpos = (ul + lr) * 0.5f;
739 break;
740
741 case 2: // Along center beam (TOP RIGHT)
742 ul = insidearray[t][s][0];
743 ur = gridarray[t + 1][s].position;
744 ll = insidearray[t][s][2];
745 lr = insidearray[t + 1][s][1];
746
747 // Center
748 buildzone.terpos = (ul + lr) * 0.5f;
749 break;
750
751 case 3: // Along center beam (LOWER RIGHT)
752 ul = insidearray[t][s][2];
753 ur = insidearray[t + 1][s][1];
754 ll = insidearray[t][s + 1][0];
755 lr = gridarray[t + 1][s + 1].position;
756
757 // Center
758 buildzone.terpos = (ul + lr) * 0.5f;
759 break;
760
761 case 4: // Along center beam (LOWER LEFT)
762 ul = insidearray[t][s][1];
763 ur = insidearray[t][s][2];
764 ll = gridarray[t][s + 1].position;
765 lr = insidearray[t][s + 1][0];
766
767 // Center
768 buildzone.terpos = (ul + lr) * 0.5f;
769 break;
770
771 default:
772 sprintf_s(msg, sizeof msg, "Building() %i zone %i!", buildzoneOrdinal, gridarray[t][s].zone);
774 return E_UNEXPECTED;
775 }
776
777 // Find north vector
778 RiseMath::Vec3Subtract(&leftvec, &ul, &ll);
779 RiseMath::Vec3Subtract(&rightvec, &ur, &lr);
780 RiseMath::Vec3Add(&result, &leftvec, &rightvec);
781 RiseMath::Vec3Normalize(&northvector, &result);
782
783 // plotskew and cross product so the layout/depth maps make sense
784 RiseMath::Vector3 topedge = ul - ur;
785 RiseMath::Vector3 bottomedge = ll - lr;
786 const float skewWidth = (RiseMath::Vec3Length(&topedge) + RiseMath::Vec3Length(&bottomedge)) * 0.5f;
787 const float skewHeight = (RiseMath::Vec3Length(&leftvec) + RiseMath::Vec3Length(&rightvec)) * 0.5f;
788
789#ifdef _DEBUG
790#define FindMakeshipGrid
791#endif
792
793 // Find plumb line, except for O-4 ruins
794 RiseMath::Vector3 plumb;
795#ifndef FindMakeshipGrid
796 if (gridarray[t][s].IsO4())
797 {
798 RiseMath::Vector3 eastvector = topedge + bottomedge;
799 RiseMath::Vec3Normalize(&eastvector, &eastvector);
800 RiseMath::Vec3Cross(&plumb, &northvector, &eastvector);
801 RiseMath::Vec3Normalize(&plumb, &plumb);
802 }
803 else
804#endif
805 {
806 RiseMath::Vec3Normalize(&plumb, &buildzone.terpos);
807 }
808 RiseMath::MatrixLookAtLH(&matrixTemp, &centerC, &plumb, &northvector);
809 RiseMath::MatrixInverse(&buildzone.matrixBase, nullptr, &matrixTemp);
810
811
812 if (gridarray[t][s].UsesRts())
813 {
814 RiseMath::Vector3 makeShipUl;
815 RiseMath::Vector3 makeShipLl;
816 RiseMath::Vector3 makeShipUr;
817 RiseMath::Vector3 makeShipLr;
818 RiseMath::Vec3TransformCoord(&makeShipUl, &ul, &matrixTemp);
819 RiseMath::Vec3TransformCoord(&makeShipLl, &ll, &matrixTemp);
820 RiseMath::Vec3TransformCoord(&makeShipUr, &ur, &matrixTemp);
821 RiseMath::Vec3TransformCoord(&makeShipLr, &lr, &matrixTemp);
822
823 // for determining the grid in Makeship
824 RiseMath::Vector2 to[4] = { {-1.014f, 1.014f}, { -1.014f, -1.014f}, {1.014f, 1.014f}, {1.014f, -1.014f} };
825 RiseMath::Vector2 from[4];
826 from[0] = RiseMath::Vector2(makeShipUl.x, makeShipUl.y);
827 from[1] = RiseMath::Vector2(makeShipLl.x, makeShipLl.y);
828 from[2] = RiseMath::Vector2(makeShipUr.x, makeShipUr.y);
829 from[3] = RiseMath::Vector2(makeShipLr.x, makeShipLr.y);
830 // !!! these are the numbers we take to Makeship!
831 bool returnInverse = true; // maybe?
832 if (!returnInverse)
833 {
834 for (int i = 0; i < 4; i++)
835 {
836 to[i] *= 520.0f / 2.0f / 1.014f;
837 from[i] *= 520.0f / 2.0f / 1.014f;
838 }
839 }
840 else
841 {
842 RiseMath::Vector2 temp[4];
843 memcpy(temp, from, sizeof from);
844 memcpy(from, to, sizeof to);
845 memcpy(to, temp, sizeof temp);
846 }
847
848 float A[8][8] = {
849 { from[0].x, from[0].y, 1, 0, 0, 0, -from[0].x * to[0].x, -from[0].y * to[0].x },
850 { 0, 0, 0, from[0].x, from[0].y, 1, -from[0].x * to[0].y, -from[0].y * to[0].y },
851 { from[1].x, from[1].y, 1, 0, 0, 0, -from[1].x * to[1].x, -from[1].y * to[1].x },
852 { 0, 0, 0, from[1].x, from[1].y, 1, -from[1].x * to[1].y, -from[1].y * to[1].y },
853 { from[2].x, from[2].y, 1, 0, 0, 0, -from[2].x * to[2].x, -from[2].y * to[2].x },
854 { 0, 0, 0, from[2].x, from[2].y, 1, -from[2].x * to[2].y, -from[2].y * to[2].y },
855 { from[3].x, from[3].y, 1, 0, 0, 0, -from[3].x * to[3].x, -from[3].y * to[3].x },
856 { 0, 0, 0, from[3].x, from[3].y, 1, -from[3].x * to[3].y, -from[3].y * to[3].y }
857 };
858
859 float inv[8][8];
860 inverse(A, inv);
861
862 float b[8][1] = { to[0].x, to[0].y, to[1].x, to[1].y, to[2].x, to[2].y, to[3].x, to[3].y };
863
864 float h[8][1];
865 for (int i = 0; i < 8; ++i)
866 {
867 for (int j = 0; j < 1; ++j)
868 {
869 h[i][j] = 0;
870 for (int k = 0; k < 8; ++k)
871 {
872 h[i][j] += inv[i][k] * b[k][j];
873 }
874 }
875 }
876
877 RiseMath::Matrix matSkew = {
878 h[0][0], h[1][0], 0, h[2][0],
879 h[3][0], h[4][0], 0, h[5][0],
880 0, 0, 1, 0,
881 h[6][0], h[7][0], 0, 1
882 };
883
884 // verified 5/8 that we DO have to transpose it
885 RiseMath::MatrixTranspose(&buildzone.matSkew, &matSkew);
886 }
887
888 // so we have the numbers used for the skew in Makeship ... we want to use this to compute the transpose matrix so that we can "fix" the RTS curbs
889 // we must skew and scale (because Georigi did -500 to 500 for the curbs arbitrarily)
890
891
892
893 sprintf_s(msg, sizeof msg, "Building() %i zone %i powered %i", buildzoneOrdinal, gridarray[t][s].zone, gridarray[t][s].powered);
894 logger->Log(msg);
895
896
897#pragma region Lights
898
899 buildzone.effects.clear();
900 if (gridarray[t][s].powered)
901 {
902 short fileEffects;
903 _read(handle, &fileEffects, 2);
904 sprintf_s(msg, sizeof msg, "Loading up to %i lights for buildingZoneOrdinal %i...", fileEffects, buildzoneOrdinal);
905 logger->Log(msg);
906
907 for (r = 0; r < static_cast<unsigned int>(fileEffects); r++)
908 {
909 s_light_effect tempEffect;
910 _read(handle, &tempEffect.position, 12);
911 _read(handle, &tempEffect.normal, 12);
912 DWORD diffuse;
913 _read(handle, &diffuse, 4);
914 tempEffect.diffuse = diffuse;
915 _read(handle, &tempEffect.sequencing, 4);
916 _read(handle, &tempEffect.speed, 4); // unused
917 _read(handle, &tempEffect.power, 4);
918 _read(handle, &tempEffect.attachto, 2);
919 tempEffect.primitive = 0;
920
921 if (gridarray[t][s].zone > 0)
922 {
923 for (int q = 0; q < buildzone.components; q++)
924 {
925 if (tempEffect.attachto == buildzone.componentarray[q].attachto &&
926 buildzone.componentarray[q].nominalxyz.z == 0.0f)
927 {
928 float adjustX = skewWidth / 1.024f * buildzone.componentarray[q].nominalxyz.x - buildzone.componentarray[q].nominalxyz.x;
929 float adjustY = skewHeight / 1.024f * buildzone.componentarray[q].nominalxyz.y - buildzone.componentarray[q].nominalxyz.y;
930 tempEffect.position.x += adjustX;
931 tempEffect.position.y += adjustY;
932 break;
933 }
934 }
935 }
936 RiseMath::Vec3TransformCoord(&tempEffect.position, &tempEffect.position, &buildzone.matrixBase);
937 tempEffect.position += buildzone.terpos;
938 RiseMath::Vec3TransformNormal(&tempEffect.normal, &tempEffect.normal, &matrixTemp);
939
940 bool connected = true;
941 if (tempEffect.attachto > 0) // runways and cities are excluded by this check
942 {
943 connected = false;
944 for (int c = 0; c < buildzone.components; c++)
945 {
946 if (buildzone.componentarray[c].attachto == tempEffect.attachto)
947 {
948 connected = true;
949 break;
950 }
951 }
952 }
953 if (connected)
954 buildzone.effects.emplace_back(tempEffect);
955 }
956
957 _close(handle);
958
959 sprintf_s(msg, sizeof msg, "Building() %i built TEMPDAX with %i vertices for %zu added lights", buildzoneOrdinal, tempvertices, buildzone.effects.size());
960 logger->Log(msg);
961
962#pragma region REIL (Runway End Identifier Lights)
963 if (gridarray[t][s].type == PlotType::UserAirfield && CheckLayout(99, gridarray[t][s]))
964 {
965 if (CheckLayout(98, gridarray[t][s])) // the same runway/light switches as the ground texture
966 {
968 {gridarray[t][s].position - buildzone.terpos, insidearray[t][s][0] - buildzone.terpos, gridarray[t + 1][s].position - buildzone.terpos},
969 {insidearray[t][s][1] - buildzone.terpos, insidearray[t][s][2] - buildzone.terpos, insidearray[t + 1][s][1] - buildzone.terpos},
970 {gridarray[t][s + 1].position - buildzone.terpos, insidearray[t][s + 1][0] - buildzone.terpos, gridarray[t + 1][s + 1].position - buildzone.terpos}
971 } };
973 RunwayEdgeLights::ForEachAnchor([&](float u, float v) {
974 // Ten centimeters avoids coplanar depth loss while keeping
975 // the visible source anchored to its painted ground glow.
976 buildzone.runwayEdgeLights.push_back(RunwayEdgeLights::SurfacePoint(surface, u, v) + plumb * .0001f);
977 });
978 }
979 s_light_effect newarray[28];
980 for (r = 0; r < 6; r++)
981 {
982 newarray[r].normal = -northvector;
983 newarray[r].diffuse = Rendering::ColorARGB(255, 0, 255, 0);
984 newarray[r].sequencing = 4294967295UL;
985 newarray[r].primitive = 0;
986 newarray[r].power = 1.0f; // bulb
987 newarray[r].attachto = -1;
988 }
989 //0.73857 && Tex.x < 0.76143) // 0.02286
990 RiseMath::Vec3Lerp(&newarray[0].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 1.0f / 8.0f) * 2.0f);
991 RiseMath::Vec3Lerp(&newarray[1].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 2.0f / 8.0f) * 2.0f);
992 RiseMath::Vec3Lerp(&newarray[2].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 3.0f / 8.0f) * 2.0f);
993 RiseMath::Vec3Lerp(&newarray[3].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 5.0f / 8.0f) * 2.0f);
994 RiseMath::Vec3Lerp(&newarray[4].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 6.0f / 8.0f) * 2.0f);
995 RiseMath::Vec3Lerp(&newarray[5].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 7.0f / 8.0f) * 2.0f);
996 for (r = 6; r < 12; r++)
997 {
998 newarray[r].normal = northvector;
999 newarray[r].diffuse = Rendering::ColorARGB(255, 255, 0, 0);
1000 newarray[r].sequencing = 4294967295UL;
1001 newarray[r].primitive = 0;
1002 newarray[r].power = 1.0f; // bulb
1003 newarray[r].attachto = -1;
1004 }
1005 //0.73857 && Tex.x < 0.76143) // 0.02286
1006 RiseMath::Vec3Lerp(&newarray[6].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 1.0f / 8.0f) * 2.0f);
1007 RiseMath::Vec3Lerp(&newarray[7].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 2.0f / 8.0f) * 2.0f);
1008 RiseMath::Vec3Lerp(&newarray[8].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 3.0f / 8.0f) * 2.0f);
1009 RiseMath::Vec3Lerp(&newarray[9].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 5.0f / 8.0f) * 2.0f);
1010 RiseMath::Vec3Lerp(&newarray[10].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 6.0f / 8.0f) * 2.0f);
1011 RiseMath::Vec3Lerp(&newarray[11].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 7.0f / 8.0f) * 2.0f);
1012 for (r = 12; r < 18; r++)
1013 {
1014 newarray[r].normal = northvector;
1015 newarray[r].diffuse = Rendering::ColorARGB(255, 0, 255, 0);
1016 newarray[r].sequencing = 4294967295UL;
1017 newarray[r].primitive = 0;
1018 newarray[r].power = 1.0f; // bulb
1019 newarray[r].attachto = -1;
1020 }
1021 //0.73857 && Tex.x < 0.76143) // 0.02286
1022 // need to find the 25% down
1023 RiseMath::Vector3 topLeft, topRight;
1024 RiseMath::Vec3Lerp(&topLeft, &insidearray[t][s][0], &insidearray[t][s][2], 0.5f);
1025 RiseMath::Vec3Lerp(&topRight, &gridarray[t + 1][s].position, &insidearray[t + 1][s][1], 0.5f);
1026
1027 RiseMath::Vec3Lerp(&newarray[12].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 1.0f / 8.0f) * 2.0f);
1028 RiseMath::Vec3Lerp(&newarray[13].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 2.0f / 8.0f) * 2.0f);
1029 RiseMath::Vec3Lerp(&newarray[14].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 3.0f / 8.0f) * 2.0f);
1030 RiseMath::Vec3Lerp(&newarray[15].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 5.0f / 8.0f) * 2.0f);
1031 RiseMath::Vec3Lerp(&newarray[16].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 6.0f / 8.0f) * 2.0f);
1032 RiseMath::Vec3Lerp(&newarray[17].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 7.0f / 8.0f) * 2.0f);
1033 for (r = 18; r < 24; r++)
1034 {
1035 newarray[r].normal = -northvector;
1036 newarray[r].diffuse = Rendering::ColorARGB(255, 255, 0, 0);
1037 newarray[r].sequencing = 4294967295UL;
1038 newarray[r].primitive = 0;
1039 newarray[r].power = 1.0f; // bulb
1040 newarray[r].attachto = -1;
1041 }
1042 //0.73857 && Tex.x < 0.76143) // 0.02286
1043 RiseMath::Vec3Lerp(&newarray[18].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 1.0f / 8.0f) * 2.0f);
1044 RiseMath::Vec3Lerp(&newarray[19].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 2.0f / 8.0f) * 2.0f);
1045 RiseMath::Vec3Lerp(&newarray[20].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 3.0f / 8.0f) * 2.0f);
1046 RiseMath::Vec3Lerp(&newarray[21].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 5.0f / 8.0f) * 2.0f);
1047 RiseMath::Vec3Lerp(&newarray[22].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 6.0f / 8.0f) * 2.0f);
1048 RiseMath::Vec3Lerp(&newarray[23].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 7.0f / 8.0f) * 2.0f);
1049
1050 for (r = 24; r < 26; r++)
1051 {
1052 newarray[r].normal = northvector;
1053 newarray[r].diffuse = Rendering::ColorARGB(255, 255, 255, 255);
1054 newarray[r].sequencing = 65537UL;
1055 newarray[r].primitive = 0;
1056 newarray[r].power = 1.0f; // bulb
1057 newarray[r].attachto = -1;
1058 }
1059 for (r = 26; r < 28; r++)
1060 {
1061 newarray[r].normal = -northvector;
1062 newarray[r].diffuse = Rendering::ColorARGB(255, 255, 255, 255);
1063 newarray[r].sequencing = 65537UL;
1064 newarray[r].primitive = 0;
1065 newarray[r].power = 1.0f; // bulb
1066 newarray[r].attachto = -1;
1067 }
1068 RiseMath::Vec3Lerp(&newarray[24].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * -1.0f / 8.0f) * 2.0f);
1069 RiseMath::Vec3Lerp(&newarray[25].position, &topLeft, &topRight, (-0.5f + 0.73857f + 0.02286f * 9.0f / 8.0f) * 2.0f);
1070 RiseMath::Vec3Lerp(&newarray[26].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * -1.0f / 8.0f) * 2.0f);
1071 RiseMath::Vec3Lerp(&newarray[27].position, &insidearray[t][s + 1][0], &gridarray[t + 1][s + 1].position, (-0.5f + 0.73857f + 0.02286f * 9.0f / 8.0f) * 2.0f);
1072
1073 for (r = 0; r < 28; r++)
1074 buildzone.effects.emplace_back(newarray[r]);
1075 }
1076#pragma endregion
1077
1078 }
1079
1080#pragma endregion
1081
1082
1083 // ZAP+RTS, first go though and find all modules in contact with floor
1084 for (unsigned int q = 0; q < buildzone.components; q++)
1085 {
1086 buildzone.componentarray[q].nominalCG.x = 0.0f;
1087 buildzone.componentarray[q].nominalCG.y = 0.0f;
1088 buildzone.componentarray[q].nominalCG.z = 999.0f;
1089 }
1090
1091 // This isn't ZAP yet, this just figures out where the x and y coordinates need to be for the skewed/scaled plot
1092 if (gridarray[t][s].zone) // not cities, they are permaforce
1093 {
1094 for (short q = 0; q < buildzone.components; q++)
1095 {
1096 // Is this a ground elevation vertex?
1097 if (buildzone.componentarray[q].nominalCG.z == 999.0f &&
1098 buildzone.componentarray[q].nominalxyz.z == 0.0f)
1099 {
1100 buildzone.componentarray[q].nominalCG.x = skewWidth / 1.024f * buildzone.componentarray[q].nominalxyz.x - buildzone.componentarray[q].nominalxyz.x;
1101 buildzone.componentarray[q].nominalCG.y = skewHeight / 1.024f * buildzone.componentarray[q].nominalxyz.y - buildzone.componentarray[q].nominalxyz.y;
1102
1103 // go through and set all buildings of this structure (except q) to this value
1104 for (r = 0; r < buildzone.components; r++)
1105 {
1106 if (buildzone.componentarray[r].attachto == buildzone.componentarray[q].attachto && q != r)
1107 {
1108 buildzone.componentarray[r].nominalCG = buildzone.componentarray[q].nominalCG;
1109 }
1110 }
1111 }
1112 }
1113 }
1114
1115 sprintf_s(msg, sizeof msg, "Building() %i ZAP+RTS tempdaw to new buffer...", buildzoneOrdinal);
1116 logger->Log(msg);
1117
1118 // Now go though the modules, take the part of the tempdaw they use, and make a new buffer
1119 unsigned int vertex = 0, i_temp;
1120 bool sample = true;
1121 RiseVertex2Vertex* vtx;
1122 buildzone.signOverlayUV.resize(buildzone.components, false);
1123 buildzone.obstacleBounds.resize(buildzone.components);
1124 buildzone.obstacleTops.resize(buildzone.components,-FLT_MAX);
1125
1126 V(buildzone.VB->Lock(0, 0, reinterpret_cast<void**>(&vtx), 0));
1127 sprintf_s(msg, sizeof msg, "Building() %i ZAP+RTS locked VB successfully...", buildzoneOrdinal);
1128 logger->Log(msg);
1129
1130 for (short q = 0; q < buildzone.components; q++) // for each module
1131 {
1132 // Turret vertices rotate after upload; their static bounds are insufficient.
1133 buildzone.hasAnimatedGeometry |= buildzone.componentarray[q].type == 78;
1134 i_temp = buildzone.componentarray[q].startvertex;
1135 if (buildzone.componentarray[q].type == 26 && i_temp <= tempvertices && tempvertices - i_temp >= 6)
1136 buildzone.signOverlayUV[q] = CitySignQuadUV(tempdax + i_temp, buildzone.componentarray[q].primitives * 3);
1137 assert(i_temp < (unsigned)tempvertices);
1138 buildzone.componentarray[q].startvertex = vertex; // new start vertex
1139 auto& drawBounds = AppendBuildingDrawBatch(buildzone.drawBatches, unsigned(q), vertex,
1140 buildzone.componentarray[q].primitives, buildzone.componentarray[q].texture, buildzone.componentarray[q].type);
1141
1142 RiseMath::Matrix matrixConform;
1143 if (buildzone.componentarray[q].type == 8 || // algae farms
1144 buildzone.componentarray[q].type == 84) // do not plumb
1145 {
1146 // find normal to plane, note Y is flipped because that is how it looks in makeship
1147 RiseMath::Vector3 ur2 = RiseMath::Vector3(1.014f, 1.014f, -1.0f);
1148 RiseMath::Vector3 lr2 = RiseMath::Vector3(1.014f, -1.014f, -1.0f);
1149 RiseMath::Vector3 ll2 = RiseMath::Vector3(-1.014f, -1.014f, -1.0f);
1150 RiseMath::Vector3 ul2 = RiseMath::Vector3(-1.014f, 1.014f, -1.0f);
1151 RiseMath::Vector3 dir = RiseMath::Vector3(0.0f, 0.0f, -1.0f);
1152 float uhit, vhit, dist;
1153 // Need to determine which side he is on...
1154 if (RiseMath::IntersectTri(&ul2, &ur2, &ll2, &buildzone.componentarray[q].nominalxyz, &dir, &uhit, &vhit, &dist))
1156 //if (newbz.componentarray[q].nominalxyz.x + newbz.componentarray[q].nominalxyz.y )
1157 {
1158 //RiseMath::Plane plane;
1159 //RiseMath::PlaneFromPoints(&plane, &ul, &ur, &ll);
1160 //RiseMath::PlaneNormalize(&plane, &plane);
1161 //result = -RiseMath::Vector3(plane.a, plane.b, plane.c);
1162 RiseMath::Vector3 side1 = ul - ur;
1163 RiseMath::Vec3Normalize(&side1, &side1);
1164 RiseMath::Vector3 side2 = ul - ll;
1165 RiseMath::Vec3Normalize(&side2, &side2);
1166 RiseMath::Vec3Cross(&result, &side2, &side1);
1167 RiseMath::Vec3Normalize(&result, &result);
1168
1169 RiseMath::MatrixLookAtLH(&matrixConform, &centerC, &result, &northvector);
1170 RiseMath::MatrixInverse(&matrixConform, nullptr, &matrixConform);
1171 }
1172 else if (RiseMath::IntersectTri(&ur2, &lr2, &ll2, &buildzone.componentarray[q].nominalxyz, &dir, &uhit, &vhit, &dist))
1173 {
1174 //RiseMath::Plane plane;
1175 //RiseMath::PlaneFromPoints(&plane, &ur, &lr, &ll);
1176 //RiseMath::PlaneNormalize(&plane, &plane);
1177 //result = -RiseMath::Vector3(plane.a, plane.b, plane.c);
1178 RiseMath::Vector3 side1 = lr - ur;
1179 RiseMath::Vec3Normalize(&side1, &side1);
1180 RiseMath::Vector3 side2 = lr - ll;
1181 RiseMath::Vec3Normalize(&side2, &side2);
1182 RiseMath::Vec3Cross(&result, &side1, &side2);
1183 RiseMath::Vec3Normalize(&result, &result);
1184
1185 RiseMath::MatrixLookAtLH(&matrixConform, &centerC, &result, &northvector);
1186 RiseMath::MatrixInverse(&matrixConform, nullptr, &matrixConform);
1187 }
1188 else
1189 {
1190 matrixConform = buildzone.matrixBase;
1191
1192 sprintf_s(msg, sizeof msg, "%i CROP %i was %f %f %f NO HIT!", buildzoneOrdinal, q, buildzone.componentarray[q].nominalxyz.x, buildzone.componentarray[q].nominalxyz.y, buildzone.componentarray[q].nominalxyz.z);
1194 }
1195 }
1196 else
1197 {
1198 matrixConform = buildzone.matrixBase;
1199 }
1200
1201
1202 // Go through all vertices individually and make adjustments first ----------------------
1203 if (gridarray[t][s].zone && gridarray[t][s].type != PlotType::UserAirfield) // conform to ground
1204 {
1205 if (buildzone.componentarray[q].nominalCG.z > 99.0f) // not set
1206 {
1207 RiseMath::MatrixRotationZ(&matrixRotation, buildzone.componentarray[q].nominalypr.z);
1208 RiseMath::MatrixTranslation(&matrixTemp,
1209 buildzone.componentarray[q].nominalxyz.x + buildzone.componentarray[q].nominalCG.x,
1210 buildzone.componentarray[q].nominalxyz.y + buildzone.componentarray[q].nominalCG.y,
1211 buildzone.componentarray[q].nominalxyz.z);
1212 RiseMath::MatrixMultiply(&matrixWorld, &matrixTemp, &matrixConform);
1213
1214 if (buildzone.componentarray[q].type == 8 || // algae farms
1215 buildzone.componentarray[q].type == 84) // do not plumb
1216 {
1217 if (buildzone.componentarray[q].nominalxyz.z == 0.0f)
1218 {
1219 tempnormal.x = 0;
1220 tempnormal.y = 0;
1221 tempnormal.z = 0;
1222
1223 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixRotation);
1224 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixWorld);
1225 tempnormal = -tempnormal;
1226 tempnormal -= buildzone.terpos;
1227 tempnormal = -tempnormal;
1228 RiseMath::Vector3 normalizedTempNormal;
1229 RiseMath::Vec3Normalize(&normalizedTempNormal, &tempnormal);
1230
1231 // find the AGL altitude of this point, these ul ur lr are for the zones and map to grid ul, innerarray 0-2, etc
1232 float pu, pv, dist;
1233 if (RiseMath::IntersectTri(&ul, &ur, &ll, &centerC, &normalizedTempNormal, &pu, &pv, &dist))
1234 {
1235 dist -= RiseMath::Vec3Length(&tempnormal); // 8/17/2019 I switched to this because it looks like that is what we do elsewhere
1236 }
1237 else if (RiseMath::IntersectTri(&ur, &lr, &ll, &centerC, &normalizedTempNormal, &pu, &pv, &dist))
1238 {
1239 dist -= RiseMath::Vec3Length(&tempnormal); // 8/17/2019 I switched to this because it looks like that is what we do elsewhere
1240 }
1241 else
1242 {
1243 // problem, dump 4 corners and this guys position
1244 sprintf_s(msg, sizeof msg, "Problem1 with gridarray[t][s].type %i", gridarray[t][s].type);
1246 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", tempnormal.x, tempnormal.y, tempnormal.z);
1248 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t][s].position.x, gridarray[t][s].position.y, gridarray[t][s].position.z);
1250 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t + 1][s].position.x, gridarray[t + 1][s].position.y, gridarray[t + 1][s].position.z);
1252 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t + 1][s + 1].position.x, gridarray[t + 1][s + 1].position.y, gridarray[t + 1][s + 1].position.z);
1254 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t][s + 1].position.x, gridarray[t][s + 1].position.y, gridarray[t][s + 1].position.z);
1256 dist = 0.01f;
1257 }
1258
1259 buildzone.componentarray[q].nominalCG.z = dist;// +0.0004f; // 16 inches
1260 }
1261 }
1262 else
1263 {
1264 float fabsbias = -999.0f;
1265 for (r = 0; r < buildzone.componentarray[q].primitives * 3; r++)
1266 {
1267 // Is this is a ground elevation vertex?
1268 if (buildzone.componentarray[q].nominalxyz.z == 0.0f && tempdax[i_temp + r].z == 0.0f)
1269 {
1270 tempnormal.x = tempdax[i_temp + r].x;
1271 tempnormal.y = tempdax[i_temp + r].y;
1272 tempnormal.z = 0;
1273
1274 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixRotation);
1275 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixWorld);
1276 tempnormal = -tempnormal;
1277 tempnormal -= buildzone.terpos;
1278 tempnormal = -tempnormal;
1279 RiseMath::Vector3 normalizedTempNormal;
1280 RiseMath::Vec3Normalize(&normalizedTempNormal, &tempnormal);
1281
1282 // find the AGL altitude of this point, these ul ur lr are for the zones and map to grid ul, innerarray 0-2, etc
1283 float pu, pv, dist;
1284 if (RiseMath::IntersectTri(&ul, &ur, &ll, &centerC, &normalizedTempNormal, &pu, &pv, &dist) ||
1285 RiseMath::IntersectTri(&ur, &lr, &ll, &centerC, &normalizedTempNormal, &pu, &pv, &dist))
1286 {
1287
1288 }
1289 else
1290 {
1291 // problem, dump 4 corners and this guys position
1292 sprintf_s(msg, sizeof msg, "Problem2 with gridarray[t][s].type %i", gridarray[t][s].type);
1294 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", tempnormal.x, tempnormal.y, tempnormal.z);
1296 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t][s].position.x, gridarray[t][s].position.y, gridarray[t][s].position.z);
1298 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t + 1][s].position.x, gridarray[t + 1][s].position.y, gridarray[t + 1][s].position.z);
1300 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t + 1][s + 1].position.x, gridarray[t + 1][s + 1].position.y, gridarray[t + 1][s + 1].position.z);
1302 sprintf_s(msg, sizeof msg, " %+.3f ,%+.3f ,%+.3f ,", gridarray[t][s + 1].position.x, gridarray[t][s + 1].position.y, gridarray[t][s + 1].position.z);
1304 }
1305
1306 //f_temp -= RiseMath::Vec3Length(&tempnormal); // 8/17/2019 I switched to this because it looks like that is what we do elsewhere
1307 dist -= RiseMath::Vec3Length(&buildzone.terpos);
1308
1309 // take the highest AGL altitude point and raise/lower to ground level
1310 if (dist > fabsbias)
1311 {
1312 buildzone.componentarray[q].nominalCG.z = dist + 0.0004f; // 8 inches exposure of concrete
1313 fabsbias = dist;
1314 }
1315 }
1316 }
1317 }
1318
1319 for (r = 0; r < buildzone.components; r++)
1320 {
1321 if (buildzone.componentarray[r].attachto == buildzone.componentarray[q].attachto && q != r)
1322 {
1323 buildzone.componentarray[r].nominalCG.z = buildzone.componentarray[q].nominalCG.z;
1324 }
1325 }
1326 }
1327 if (buildzone.componentarray[q].nominalCG.z > 99.0f)
1328 {
1329 sprintf_s(msg, sizeof msg, "Building() %i component %i type %i (%i) ZAP bias STILL NOT SET %f", buildzoneOrdinal, q, buildzone.componentarray[q].type, buildzone.type, buildzone.componentarray[q].nominalCG.z);
1330 logger->Log(msg, Logger::Error);
1331 }
1332
1333 if (sample)
1334 {
1335 sprintf_s(msg, sizeof msg, "Building() %i example of ZAP bias %f", buildzoneOrdinal, buildzone.componentarray[q].nominalCG.z);
1336 logger->Log(msg);
1337 sample = false;
1338 }
1339 }
1340 else
1341 buildzone.componentarray[q].nominalCG.z = 0.0f; // city floors and airfield
1342
1343
1344
1345 assert(i_temp < static_cast<unsigned>(tempvertices));
1346
1347 RiseMath::MatrixTranslation(&matrixTemp,
1348 buildzone.componentarray[q].nominalxyz.x + buildzone.componentarray[q].nominalCG.x,
1349 buildzone.componentarray[q].nominalxyz.y + buildzone.componentarray[q].nominalCG.y,
1350 buildzone.componentarray[q].nominalxyz.z + buildzone.componentarray[q].nominalCG.z); // -bias pulls into ground
1351 RiseMath::MatrixMultiply(&matrixWorld, &matrixTemp, &matrixConform);
1352
1353 RiseMath::MatrixRotationZ(&matrixRotation, buildzone.componentarray[q].nominalypr.z);
1354 RiseMath::Matrix invMatrixRotation;
1355 RiseMath::MatrixInverse(&invMatrixRotation, nullptr, &matrixRotation);
1356
1357 // Go through all vertices individually and make new vertex buffer ----------------------
1358 for (r = 0; r < buildzone.componentarray[q].primitives * 3; r++) // vertices
1359 {
1360 tempnormal.x = tempdax[i_temp].x;
1361 tempnormal.y = tempdax[i_temp].y;
1362 tempnormal.z = tempdax[i_temp].z;
1363 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixRotation);
1364 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixWorld);
1365 vtx->x = tempnormal.x; vtx->y = tempnormal.y; vtx->z = tempnormal.z;
1366 buildzone.bounds.Include(tempnormal);
1367 drawBounds.Include(tempnormal);
1368 buildzone.obstacleBounds[q].Include(tempnormal);
1369 const auto obstacleWorld = tempnormal+buildzone.terpos;
1370 const float obstacleHeight = float(std::sqrt(double(obstacleWorld.x)*obstacleWorld.x +
1371 double(obstacleWorld.y)*obstacleWorld.y + double(obstacleWorld.z)*obstacleWorld.z)-double(radiusC));
1372 buildzone.obstacleTops[q] = (std::max)(buildzone.obstacleTops[q],obstacleHeight);
1373
1374 tempnormal.x = tempdax[i_temp].nx;
1375 tempnormal.y = tempdax[i_temp].ny;
1376 tempnormal.z = tempdax[i_temp].nz;
1377 RiseMath::Vec3TransformNormal(&tempnormal, &tempnormal, &invMatrixRotation);
1378 vtx->nx = tempnormal.x; vtx->ny = tempnormal.y; vtx->nz = tempnormal.z;
1379
1380 vtx->tu = tempdax[i_temp].tu; vtx->tv = tempdax[i_temp].tv;
1381 vtx->tu2 = tempdax[i_temp].tu2; vtx->tv2 = tempdax[i_temp].tv2;
1382 vtx++; vertex++; i_temp++;
1383 }
1384 }
1385
1386 SAFE_DELETE_ARRAY(tempdax);
1387 V(buildzone.VB->Unlock());
1388 sprintf_s(msg, sizeof msg, "Building() %i filled %i/%i vertices for \"%s\"", buildzoneOrdinal, vertex, vertices, file);
1389 logger->Log(msg);
1390
1391 buildzone.rtscomponents = 0; // keep everyone else from rendering an RTS grid
1392
1393#pragma region RTS Grid (for rendering after the buildings)
1394 if (gridarray[t][s].UsesRts())
1395 {
1396 // Use the same nine vertices as the terrain and its collision surface.
1397 // Bilinear interpolation of the four world-space corners can both round
1398 // tile edges by decimeters and lift tiles off the terrain's triangles.
1399 const RtsTerrain::Surface<RiseMath::Vector3> surface = { {
1400 { gridarray[t][s].position - buildzone.terpos,
1401 insidearray[t][s][0] - buildzone.terpos,
1402 gridarray[t + 1][s].position - buildzone.terpos },
1403 { insidearray[t][s][1] - buildzone.terpos,
1404 insidearray[t][s][2] - buildzone.terpos,
1405 insidearray[t + 1][s][1] - buildzone.terpos },
1406 { gridarray[t][s + 1].position - buildzone.terpos,
1407 insidearray[t][s + 1][0] - buildzone.terpos,
1408 gridarray[t + 1][s + 1].position - buildzone.terpos }
1409 } };
1410
1411 i_temp = 0;
1412 RiseVertex2Vertex* vtx2;
1413 V(buildzone.RTSVB->Lock(0, 0, reinterpret_cast<void**>(&vtx2), 0));
1414 vertex = 0;
1415 for (r = 0; r < RTStextureC; r++)
1416 {
1417 buildzone.rtscomponentarray[buildzone.rtscomponents].primitives = 0;
1418 buildzone.rtscomponentarray[buildzone.rtscomponents].texture = r;
1419 buildzone.rtscomponentarray[buildzone.rtscomponents].startvertex = vertex;
1420
1421 // for each type, go through and see if we have one of them
1422 for (t = 0; t < 26; t++)
1423 {
1424 for (s = 0; s < 26; s++)
1425 {
1426 RTSGRID rtsGrid = buildzone.rts[t * 26 + s];
1427 if (rtsGrid.texture == r)
1428 {
1429 buildzone.rtscomponentarray[buildzone.rtscomponents].primitives += 2;
1430
1431 for (const auto corner : RtsTerrain::TileCorners)
1432 {
1433 const int east = t + corner.east;
1434 const int north = s + corner.north;
1435 const RiseMath::Vector3 position = surface.Sample(east, north);
1436 vtx2->x = position.x; vtx2->y = position.y; vtx2->z = position.z;
1437 buildzone.rtsBounds.Include(position);
1438 vtx2->nx = -buildzone.terpos.x;
1439 vtx2->ny = -buildzone.terpos.y;
1440 vtx2->nz = -buildzone.terpos.z;
1441
1442 const auto tex = RtsTerrain::TextureCoordinate(corner, rtsGrid.rotation);
1443 vtx2->tu = tex.u; vtx2->tv = tex.v;
1444 vtx2->tu2 = static_cast<float>(east) / RtsTerrain::TileCount;
1445 vtx2->tv2 = static_cast<float>(north) / RtsTerrain::TileCount;
1446 vtx2++; vertex++;
1447 }
1448 }
1449 }
1450 }
1451 if (buildzone.rtscomponentarray[buildzone.rtscomponents].primitives > 0) // had at least one)
1452 {
1453 i_temp += buildzone.rtscomponentarray[buildzone.rtscomponents].primitives;
1454 buildzone.rtscomponents++;
1455 }
1456 }
1457
1458 V(buildzone.RTSVB->Unlock());
1459 sprintf_s(msg, sizeof msg, "Building() %i filled %i RTS primitives for \"%s\"", buildzoneOrdinal, i_temp, file);
1460 logger->Log(msg);
1461 }
1462#pragma endregion
1463
1464 buildzones.emplace_back(buildzone);
1465 sortme.emplace_back(buildzoneOrdinal);
1466
1467 return S_OK;
1468}
1469
1471{
1472 logger->AddToCallStack("buildings::Sort");
1473
1474 if (buildzones.empty())
1475 return;
1476
1477 if (buildzones.size() != sortme.size())
1478 {
1479 logger->Log("Uh oh ... buildzones count not equal to sortme count in buildings::Sort", Logger::Fatal);
1480 }
1481
1482 for (size_t t = 0; t < buildzones.size(); t++)
1483 {
1484 RiseMath::Vector3 diff = -playerships[0].position - buildzones.at(t).terpos;
1485 buildzones.at(t).dist = RiseMath::Vec3Length(&diff);
1486 }
1487
1488 bool swapflag;
1489 do
1490 {
1491 swapflag = false;
1492 for (size_t t = 0; t < sortme.size() - 1; t++)
1493 {
1494 if (sortme.at(t) >= buildzones.size() || sortme.at(t + 1) >= buildzones.size())
1495 logger->Log("Uh oh ... sortme index is higher than buildzones capacity buildings::Sort", Logger::Fatal);
1496
1497 if (buildzones.at(sortme.at(t)).dist > buildzones.at(sortme.at(t + 1)).dist)
1498 {
1499 size_t sortmetemp = sortme.at(t);
1500 sortme.at(t) = sortme.at(t + 1);
1501 sortme.at(t + 1) = sortmetemp;
1502 swapflag = true;
1503 }
1504 }
1505 } while (swapflag);
1506}
1507
1508void buildings::RemoveBuildZone(size_t ordinal)
1509{
1510 char msg[99];
1511 //sprintf_s(msg, sizeof msg, "buildings::RemoveBuildZone %i (counts were %i and %i)", ordinal, buildzones.size(), sortme.size());
1512 //logger->Log(msg);
1513
1514 SAFE_RELEASE(buildzones.at(ordinal).VB);
1515 SAFE_RELEASE(buildzones.at(ordinal).RTSVB);
1516 SAFE_DELETE_ARRAY(buildzones.at(ordinal).rts);
1517 SAFE_DELETE_ARRAY(buildzones.at(ordinal).componentarray);
1518 SAFE_DELETE_ARRAY(buildzones.at(ordinal).rtscomponentarray);
1519
1520 buildzones.erase(buildzones.begin() + ordinal);
1521
1522 //sprintf_s(msg, sizeof msg, "buildings::RemoveBuildZone counts now %i and %i", buildzones.size(), sortme.size());
1523 //logger->Log(msg);
1524
1525 // gotta find and pull out the one that is gone and lower the ordinal for the ones left
1526 int remove = -1;
1527 for (size_t i = 0; i < sortme.size(); i++)
1528 {
1529 if (sortme.at(i) == ordinal && remove == -1)
1530 {
1531 remove = i;
1532 //sprintf_s(msg, sizeof msg, " sortme dump %i = %i (removing!)", i, sortme.at(i));
1533 //logger->Log(msg);
1534 }
1535 else if (sortme.at(i) > ordinal)
1536 {
1537 //sprintf_s(msg, sizeof msg, " sortme dump %i = %i (now %i)", i, sortme.at(i), sortme.at(i) - 1);
1538 //logger->Log(msg);
1539 sortme.at(i)--;
1540 }
1541 else
1542 {
1543 //sprintf_s(msg, sizeof msg, " sortme dump %i = %i (untouched!)", i, sortme.at(i));
1544 //logger->Log(msg);
1545 }
1546 }
1547
1548 if (remove == -1)
1549 {
1550 sprintf_s(msg, sizeof msg, "RemoveBuildZone %zu not found in sortme!", ordinal);
1552 }
1553
1554 sortme.erase(sortme.begin() + remove);
1555
1556 if (sortme.size() != buildzones.size())
1557 {
1558 sprintf_s(msg, sizeof msg, "RemoveBuildZone sortme %zu and buildzones %zu!", sortme.size(), buildzones.size());
1560 }
1561}
1562
1563void buildings::RenderRts(Rendering::RenderDevice* pd3dDevice, float lightFromStreet) const
1564{
1565 Rendering::ProfileScope11 timing("RTS ground overlays");
1566 HRESULT hr;
1567
1568 RiseMath::Matrix matrixTemp, mWorldViewProj;
1572
1573 for (size_t t = 0; t < sortme.size(); t++)
1574 {
1575 const BUILDZONE& buildzone = buildzones.at(sortme.at(t));
1576 if (!buildzone.rtscomponents)
1577 continue;
1578
1579 VECTOR2SHORT actual;
1580 actual.u = buildzone.u - viewscreen->ptrGrid->tcp.u;
1581 actual.v = buildzone.v - viewscreen->ptrGrid->tcp.v;
1582
1583 actual.u += 31;
1584 actual.v += 31;
1585 RiseMath::MatrixTranslation(&matrixTemp,
1586 static_cast<float>(playerships[0].precisionx + static_cast<double>(buildzone.terpos.x)),
1587 static_cast<float>(playerships[0].precisiony + static_cast<double>(buildzone.terpos.y)),
1588 static_cast<float>(playerships[0].precisionz + static_cast<double>(buildzone.terpos.z)));
1589 if (playerships[0].isSimulator)
1590 mWorldViewProj = matrixTemp * viewscreen->matrixView * viewscreen->matrixProjSim;
1591 else
1592 mWorldViewProj = matrixTemp * viewscreen->matrixLook * viewscreen->matrixProj;
1593
1594 if (buildzone.rtsBounds.IntersectsFrustum(mWorldViewProj))
1595 {
1596
1597 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
1598 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
1599
1600 // Match the packed colors consumed by the terrain shader at this plot's
1601 // edges. Read current grid colors, since lighting can change after loading.
1602 RiseMath::Vector4 roadEmission[4] = {};
1603 if (actual.u >= 0 && actual.u < 63 && actual.v >= 0 && actual.v < 63)
1604 {
1605 for (int corner = 0; corner < 4; ++corner)
1606 {
1607 const RiseMath::Color color(static_cast<Rendering::PackedColor>(gridarray[actual.u + corner % 2][actual.v + corner / 2].emissive));
1608 roadEmission[corner] = RiseMath::Vector4(color.r, color.g, color.b, 0);
1609 }
1610 }
1611 V(viewscreen->gameclass->graphics->g_pEffect->SetVectorArray("RtsRoadEmission", roadEmission, 4));
1612 viewscreen->ptrRenderer->SetSceneShipLights(buildzone.rtsBounds,matrixTemp);
1614
1615 short oldtexture = -1;
1616
1617 RiseMath::Vector4 features;
1618 features.x = 0.0f; // UNUSED
1619 features.y = 0.0f; // city-to-player road half
1620 features.z = buildzone.emissive * lightFromStreet; // emissive
1621 features.w = 0; // light map flag
1622 pd3dDevice->SetStreamSource(0, buildzone.RTSVB, 0, sizeof RiseVertex2Vertex);
1623
1624 for (unsigned short r = 0; r < buildzone.rtscomponents; r++)
1625 {
1626 short newTexture = buildzone.rtscomponentarray[r].texture;
1627 if (!newTexture || !viewscreen->m_pddsRTSTexture[newTexture])
1628 continue;
1629
1630 if (oldtexture != newTexture)
1631 {
1632 oldtexture = newTexture;
1633 features.y = oldtexture == 62 ? 1.0f : (oldtexture == 63 ? 2.0f : 0.0f);
1635
1636 if (!viewscreen->m_pddsRTSLights[oldtexture] || !buildzone.powered)
1637 {
1638 features.w = 0.0f;
1639 }
1640 else
1641 {
1642 features.w = 1.0f;
1644 }
1645 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("Features", &features));
1647 }
1648
1650 }
1651
1653 }
1654 }
1656}
1657
1658void buildings::RenderCurbs(Rendering::RenderDevice* pd3dDevice, float lightFromStreet) const
1659{
1660 Rendering::ProfileScope11 timing("Curbs");
1661 logger->AddToCallStack("buildings::RenderCurbs BEGIN");
1662
1663 HRESULT hr;
1664
1665 RiseMath::Matrix matrixTemp, mWorldViewProj;
1666
1667 RiseMath::MatrixTranslation(&matrixTemp,
1668 static_cast<float>(playerships[0].precisionx + static_cast<double>(curbTerpos.x)),
1669 static_cast<float>(playerships[0].precisiony + static_cast<double>(curbTerpos.y)),
1670 static_cast<float>(playerships[0].precisionz + static_cast<double>(curbTerpos.z)));
1671 mWorldViewProj = matrixTemp * viewscreen->matrixLook * viewscreen->matrixProj;
1672 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
1673 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
1674
1676
1677 short oldtexture = -1;
1678
1679 RiseMath::Vector4 features;
1680 features.x = 0.0f; // colorize
1681 features.y = 0.0f; // UNUSED
1682 features.z = 0.5f * lightFromStreet; // emissive @todo need to track by buildzone.emissive but right now it is only Deois
1683 features.w = 0; // light map flag
1684 for (short rtsu = 0; rtsu < lclC; rtsu++)
1685 {
1686 for (short rtsv = 0; rtsv < lclC; rtsv++)
1687 {
1688 if (!curbVB[rtsu][rtsv])
1689 continue;
1690
1691 pd3dDevice->SetStreamSource(0, curbVB[rtsu][rtsv], 0, sizeof RiseVertex2Vertex);
1692
1693 short newTexture = curbTexture[rtsu][rtsv];
1694 if (oldtexture != newTexture)
1695 {
1696 oldtexture = newTexture;
1698
1699 //if (!viewscreen->m_pddsRTSLights[oldtexture] || !true) // @todo need to track with buildzone.powered
1700 //{
1701 features.w = 0.0f;
1702 //}
1703 //else
1704 //{
1705 // features.w = 1.0f;
1706 // V(viewscreen->gameclass->graphics->g_pEffect->SetTexture("ColorMap2", viewscreen->m_pddsRTSLights[oldtexture]));
1707 //}
1708 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("Features", &features));
1710 }
1711
1712
1713 viewscreen->ptrRenderer->SetSceneShipLights(curbBounds[rtsu][rtsv],matrixTemp);
1715 pd3dDevice->DrawPrimitive(Rendering::Primitive::TriangleList, 0, curbPrims[rtsu][rtsv]);
1716 }
1717 }
1718
1720
1722 logger->AddToCallStack("buildings::RenderCurbs DONE");
1723}
1724
1726{
1727 Rendering::ProfileScope11 timing("Rocks");
1728 logger->AddToCallStack("buildings::RenderRocks BEGIN");
1729
1730 HRESULT hr;
1731
1732 RiseMath::Matrix matrixTemp, mWorldViewProj;
1733
1734 RiseMath::MatrixTranslation(&matrixTemp,
1735 static_cast<float>(playerships[0].precisionx + static_cast<double>(rockTerpos.x)),
1736 static_cast<float>(playerships[0].precisiony + static_cast<double>(rockTerpos.y)),
1737 static_cast<float>(playerships[0].precisionz + static_cast<double>(rockTerpos.z)));
1738 mWorldViewProj = matrixTemp * viewscreen->matrixLook * viewscreen->matrixProj;
1739 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
1740 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
1741
1743
1744 RiseMath::Vector4 features;
1745 features.x = 1.0f; // colorize
1746 features.y = 0.0f; // UNUSED
1747 features.z = 0.0f; // emissive
1748 features.w = 0; // light map flag
1749 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("Features", &features));
1751
1752 for (short rtsu = 0; rtsu < lclC; rtsu++)
1753 {
1754 for (short rtsv = 0; rtsv < lclC; rtsv++)
1755 {
1756 if (!rockVB[rtsu][rtsv])
1757 continue;
1758
1759 pd3dDevice->SetStreamSource(0, rockVB[rtsu][rtsv], 0, sizeof RiseVertex2Vertex);
1760
1761 viewscreen->ptrRenderer->SetSceneShipLights(rockBounds[rtsu][rtsv],matrixTemp);
1763 pd3dDevice->DrawPrimitive(Rendering::Primitive::TriangleList, 0, rockPrims[rtsu][rtsv]);
1764 }
1765 }
1766
1768
1770 logger->AddToCallStack("buildings::RenderRocks DONE");
1771}
1772
1773float buildings::CheckRtsBumpMap(VECTOR2SHORT rts, VECTOR2SHORT bump, short u, short v)
1774{
1775 logger->AddToCallStack("Viewscreen::CheckRtsBumpMap");
1776
1777 if (!gridarray[u][v].UsesRts())
1778 {
1779 g_bRoad = false;
1780 return 0.0f;
1781 }
1782
1783 if (rts.u == -2)
1784 return citystuff.curbelev;
1785
1786 g_bRoad = false;
1787 if (rts.u >= 0 && rts.u < 26 && rts.v >= 0 && rts.v < 26 &&
1788 bump.u >= 0 && bump.u < 256 && bump.v >= 0 && bump.v < 256 &&
1789 gridarray[u][v].buildzoneOrdinal != -1 &&
1790 buildzones.at(gridarray[u][v].buildzoneOrdinal).rtscomponents > 0)
1791 {
1792 const BUILDZONE& buildzone = buildzones.at(gridarray[u][v].buildzoneOrdinal);
1793 char file[MAX_PATH];
1794 int rtsOrdinal = rts.u * 26 + rts.v;
1795 switch (buildzone.rts[rtsOrdinal].texture)
1796 {
1797 case 1: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1a_BUMP.bmp"); break;
1798 case 2: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1b_BUMP.bmp"); break;
1799 case 3: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f1c_BUMP.bmp"); break;
1800 case 4: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2a_BUMP.bmp"); break;
1801 case 5: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2b_BUMP.bmp"); break;
1802 case 6: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f2c_BUMP.bmp"); break;
1803 case 7: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f3a_BUMP.bmp"); break;
1804 case 8: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f3b_BUMP.bmp"); break;
1805 case 9: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f4a_BUMP.bmp"); break;
1806 case 10: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f4b_BUMP.bmp"); break;
1807 case 11: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f5a_BUMP.bmp"); break;
1808 case 12: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6a_BUMP.bmp"); break;
1809 case 13: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6b_BUMP.bmp"); break;
1810 case 14: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6c_BUMP.bmp"); break;
1811 case 15: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6d_BUMP.bmp"); break;
1812 case 16: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f6e_BUMP.bmp"); break;
1813 case 17: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7a_BUMP.bmp"); break;
1814 case 18: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7b_BUMP.bmp"); break;
1815 case 19: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f7c_BUMP.bmp"); break;
1816 case 20: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8a_BUMP.bmp"); break;
1817 case 21: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8b_BUMP.bmp"); break;
1818 case 22: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8c_BUMP.bmp"); break;
1819 case 23: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9a_BUMP.bmp"); break;
1820 case 24: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9b_BUMP.bmp"); break;
1821 case 25: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10a_BUMP.bmp"); break;
1822 case 26: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10b_BUMP.bmp"); break;
1823 case 27: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10c_BUMP.bmp"); break;
1824 case 28: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f10d_BUMP.bmp"); break;
1825 case 29: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f11a_BUMP.bmp"); break;
1826 case 30: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-above_BUMP.bmp"); break;
1827 case 31: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f12b_BUMP.bmp"); break;
1828 case 32: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-above_BUMP.bmp"); break;
1829 case 33: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f13b_BUMP.bmp"); break;
1830 //case 34: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f14a_BUMP.bmp"); break;
1831 case 35: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f14b_BUMP.bmp"); break;
1832 case 36: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15a_BUMP.bmp"); break;
1833 case 37: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15b_BUMP.bmp"); break;
1834 case 38: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15c_BUMP.bmp"); break;
1835 case 39: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15d_BUMP.bmp"); break;
1836 g_bRoad = true;
1837 return 0.0f;
1838 case 40: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15e_BUMP.bmp"); break;
1839 //case 41: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_Exit-aboveBUMP.bmp"); break;
1840 case 42: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f17_BUMP.bmp"); break;
1841 return 0.00020312817392f; // 144
1842 case 43: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f18_BUMP.bmp"); break;
1843 case 44: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f19_BUMP.bmp"); break;
1844 case 45: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f20_BUMP.bmp"); break;
1845 case 46: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f21_BUMP.bmp"); break;
1846 case 47: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f22_BUMP.bmp"); break;
1847 case 48: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f23_BUMP.bmp"); break;
1848 case 49: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f24_BUMP.bmp"); break;
1849 case 50: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f25_BUMP.bmp"); break;
1850 g_bRoad = true;
1851 return 0.0f;
1852 case 51: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f26_BUMP.bmp"); break;
1853 case 52: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f27_BUMP.bmp"); break;
1854 case 53: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f28_BUMP.bmp"); break;
1855 case 54: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f29_BUMP.bmp"); break;
1856 case 55: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f30_BUMP.bmp"); break;
1857 case 56: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15f_BUMP.bmp"); break;
1858 case 57: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f15g_BUMP.bmp"); break;
1859 case 58: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
1860 case 59: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
1861 case 60: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f33_BUMP.bmp"); break;
1862 case 61: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f34_BUMP.bmp"); break;
1863 case 62: strcpy_s(file, MAX_PATH, "Textures\\RTS\\city2playerN_BUMP.bmp"); break;
1864 case 63: strcpy_s(file, MAX_PATH, "Textures\\RTS\\city2playerS_BUMP.bmp"); break;
1865 case 64: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
1866 case 65: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f32_BUMP.bmp"); break;
1867 case 66: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
1868 case 67: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
1869 case 68: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
1870 case 69: //strcpy_s(file, MAX_PATH, "Textures\\RTS\\f31_BUMP.bmp"); break;
1871 g_bRoad = true;
1872 return 0.0f;
1873 case 70: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f8bpark_BUMP.bmp"); break;
1874 case 71: strcpy_s(file, MAX_PATH, "Textures\\RTS\\f9bpark_BUMP.bmp"); break;
1875 default:
1876 return 0.0f;
1877 }
1878
1879 int deoisbump;
1880 _sopen_s(&deoisbump, file, _O_RDONLY | O_BINARY, _SH_DENYWR, _S_IWRITE);
1881 if (deoisbump == -1)
1882 {
1883 char msg[99];
1884 sprintf_s(msg, sizeof msg, "Could not find bump file %i for type %i!", buildzone.rts[rtsOrdinal].texture, gridarray[u][v].type);
1886 }
1887 const unsigned long bpr = 256L; // VERIFIED WITH SPE greyscale 2039, 2039 has 1024 additional header
1888
1889 const unsigned char rotation = buildzone.rts[rtsOrdinal].rotation;
1890 VECTOR2SHORT rotbump = VECTOR2SHORT();
1891 // this is because the textures are upside down in Makeship
1892 if (rotation == 2 || rotation == 6)
1893 {
1894 rotbump.u = bump.u;
1895 rotbump.v = bump.v;
1896 }
1897 else if (rotation == 1 || rotation == 5)
1898 {
1899 rotbump.v = bump.u;
1900 rotbump.u = 255 - bump.v;
1901 }
1902 else if (rotation == 0 || rotation == 4)
1903 {
1904 rotbump.u = 255 - bump.u;
1905 rotbump.v = 255 - bump.v;
1906 }
1907 else if (rotation == 3 || rotation == 7)
1908 {
1909 rotbump.v = 255 - bump.u;
1910 rotbump.u = bump.v;
1911 }
1912 if (rotation > 3)
1913 rotbump.u = 255 - rotbump.u;
1914
1915 unsigned char uch_temp;
1916 unsigned long k = 54L + 1024L + rotbump.u + (bpr - rotbump.v - 1L) * bpr;
1917 _lseek(deoisbump, k, SEEK_SET);
1918 _read(deoisbump, &uch_temp, 1);
1919 _close(deoisbump);
1920
1921 if (uch_temp == 128)
1922 g_bRoad = true;
1923
1924 return (static_cast<float>(uch_temp) - 128.0f) * 0.00001269551087f; // 0.5" per increment
1925 }
1926
1927 return 0.0f;
1928}
1929
1930void buildings::DamageLandingLightContacts(const RiseMath::Vector3& velocity, float seconds) const
1931{
1932 if (playerships[0].isSimulator || deathinhibit || !(seconds > 0) ||
1936 if (!count) return;
1937 RiseMath::Matrix toBody, toWorld;
1938 RiseMath::MatrixRotationQuaternion(&toBody, &playerships[0].orientation);
1939 RiseMath::MatrixInverse(&toWorld, nullptr, &toBody);
1940 const auto exteriorVelocity = -velocity;
1941 RiseMath::Vector3 velocityBody;
1942 RiseMath::Vec3TransformNormal(&velocityBody, &exteriorVelocity, &toBody);
1943 std::array<LandingLights::Sweep, LandingLights::MaxLights> sweeps{};
1944 float reach = 0;
1945 bool moving = false;
1946 for (unsigned i = 0; i < count; ++i)
1947 {
1948 RiseMath::Vector3 mount;
1950 RiseMath::Vec3TransformNormal(&sweeps[i].start, &mount, &toWorld);
1951 const auto localVelocity = viewscreen->LandingLightImpactVelocity(i, velocityBody);
1952 RiseMath::Vec3TransformNormal(&sweeps[i].velocity, &localVelocity, &toWorld);
1953 sweeps[i].seconds = seconds;
1954 moving |= ourcockpit.vdat.landing[i] > 0 && RiseMath::Vec3LengthSq(&sweeps[i].velocity) > .0000005625f;
1955 reach = RiseMath::Max(reach, RiseMath::Vec3Length(&mount) +
1956 RiseMath::Vec3Length(&sweeps[i].velocity) * seconds + LandingLights::HousingKm);
1957 }
1958 if (!moving) return;
1959 for (const auto& zone : buildzones)
1960 {
1961 // Preserve precision when subtracting planetary coordinates. Uploaded
1962 // building vertices are already transformed into axes local to terpos.
1963 const RiseMath::Vector3 center(
1964 float(-playerships[0].precisionx - double(zone.terpos.x)),
1965 float(-playerships[0].precisiony - double(zone.terpos.y)),
1966 float(-playerships[0].precisionz - double(zone.terpos.z)));
1967 if (!zone.VB || !zone.bounds.IsWithinDistance(center, reach)) continue;
1968 RiseVertex2Vertex* vertices = nullptr;
1969 for (const auto& batch : zone.drawBatches)
1970 {
1971 // Same solid-surface exclusions as hull collision; animated turrets
1972 // have no static contact surface at their uploaded rest position.
1973 if (batch.type == 8 || batch.type == 53 || batch.type == 54 || batch.type == 78 ||
1974 !batch.bounds.IsWithinDistance(center, reach)) continue;
1975 if (!vertices && FAILED(zone.VB->Lock(0, 0, reinterpret_cast<void**>(&vertices), Rendering::LockFlags::READONLY))) break;
1976 for (unsigned i = 0; i < count; ++i)
1977 {
1978 if (ourcockpit.vdat.landing[i] <= 0) continue;
1979 auto sweep = sweeps[i];
1980 sweep.start += center;
1981 const float travel = RiseMath::Vec3Length(&sweep.velocity) * seconds + LandingLights::HousingKm;
1982 if (!batch.bounds.IsWithinDistance(sweep.start, travel)) continue;
1983 float closing = 0;
1984 for (unsigned triangle = 0; triangle < batch.primitives; ++triangle)
1985 {
1986 const auto* p = vertices + batch.first + triangle * 3;
1987 closing = RiseMath::Max(closing, sweep.Triangle({p[0].x,p[0].y,p[0].z},
1988 {p[1].x,p[1].y,p[1].z}, {p[2].x,p[2].y,p[2].z}));
1989 }
1990 if (closing > 0) viewscreen->DamageLandingLight(i, 0, closing, "building mesh");
1991 }
1992 }
1993 if (vertices) zone.VB->Unlock();
1994 }
1995}
1996
1997bool buildings::CheckCollision(short buildZoneOrdinal, RiseMath::Vector3 position, RiseMath::Vector3 velocity, float bound, float ElapsedTime, RiseMath::Vector3* cross) const
1998{
1999 if (cross)
2000 logger->AddToCallStack("buildings::CheckCollision VEHICLE");
2001 else
2002 logger->AddToCallStack("buildings::CheckCollision WEAPON");
2003
2004 HRESULT hr;
2005 const BUILDZONE& buildzone = buildzones.at(buildZoneOrdinal);
2006 RiseMath::Vector3 oldpos, result1, result2, result3;
2007 oldpos = -position - buildzone.terpos;
2008 RiseMath::Vector3 newpos = -velocity;
2009 float magvel = RiseMath::Vec3Length(&velocity);
2010 RiseMath::Vec3Normalize(&newpos, &newpos);
2011 RiseVertex2Vertex* dawverts;
2012 bool hit1 = false;
2013 float pu, pv, dist;
2014
2015 V(buildzone.VB->Lock(0, 0, reinterpret_cast<void**>(&dawverts), Rendering::LockFlags::READONLY));
2016
2017 for (unsigned short s = 0; s < buildzone.components; s++)
2018 {
2019 // types to skip: field crops/algae fields, no bounding sphere, interior of cargo bay (hangar bay?)
2020 if (buildzone.componentarray[s].type == 8 || buildzone.componentarray[s].type == 53 || buildzone.componentarray[s].type == 54)
2021 continue;
2022
2023 for (unsigned short r = 0; r < buildzone.componentarray[s].primitives; r++)
2024 {
2025 long offset = r * 3 + buildzone.componentarray[s].startvertex;
2026 result1.x = (*(dawverts + offset)).x;
2027 result1.y = (*(dawverts + offset)).y;
2028 result1.z = (*(dawverts + offset)).z;
2029 offset++;
2030 result2.x = (*(dawverts + offset)).x;
2031 result2.y = (*(dawverts + offset)).y;
2032 result2.z = (*(dawverts + offset)).z;
2033 offset++;
2034 result3.x = (*(dawverts + offset)).x;
2035 result3.y = (*(dawverts + offset)).y;
2036 result3.z = (*(dawverts + offset)).z;
2037
2038 // this is testing for polygon collision with buildings not the ground
2039 if (RiseMath::IntersectTri(&result1, &result2, &result3, &oldpos, &newpos, &pu, &pv, &dist))
2040 {
2041 const float f_temp = dist - playerships[0].bound;
2042 if (f_temp < (magvel * ElapsedTime))
2043 {
2044 hit1 = true;
2045
2046 if (cross)
2047 {
2048 // find perpendicular to surface (normal)
2049 RiseMath::Vector3 side1 = result2 - result1, side2 = result3 - result2;
2050 RiseMath::Vec3Normalize(&side1, &side1);
2051 RiseMath::Vec3Normalize(&side2, &side2);
2052 RiseMath::Vec3Cross(cross, &side1, &side2);
2053 side1 = *cross * f_temp; // distance on vector
2054
2055 char msg[199];
2056 sprintf_s(msg, sizeof msg, "Collision hit colony polygon %i of module %i at %f %f (dist %f, magvel %f, bound %f)", r, s, pu, pv, dist, magvel, bound);
2057 logger->Log(msg);
2058
2059 RiseMath::Matrix matrixInverse; // need to make new one because we have moved since
2060 RiseMath::QuaternionNormalize(&playerships[0].orientation, &playerships[0].orientation);
2061 RiseMath::MatrixRotationQuaternion(&matrixInverse, &playerships[0].orientation);
2062 RiseMath::Vec3TransformNormal(cross, &side1, &matrixInverse);
2063 }
2064
2065 break;
2066 }
2067 }
2068 }
2069
2070 if (hit1)
2071 break;
2072 }
2073
2074 V(buildzone.VB->Unlock());
2075
2076 logger->AddToCallStack("buildings::CheckCollision DONE");
2077
2078 return hit1;
2079}
2080
2081void buildings::Render(Rendering::RenderDevice* pd3dDevice, double* fTime, bool drawTransparancy) const
2082{
2083 Rendering::ProfileScope11 timing(drawTransparancy ? "Transparent buildings" : "Opaque buildings");
2084 HRESULT hr;
2085 DWORD originalFvf = 0;
2086 pd3dDevice->GetFVF(&originalFvf);
2087 pd3dDevice->SetFVF(RISE_FVF_VERTEX2);
2088 V(viewscreen->gameclass->graphics->g_pEffect->SetInt("CityOverlayEnabled", 0));
2089 V(viewscreen->gameclass->graphics->g_pEffect->SetTexture("CityOverlayMap", nullptr));
2090 Rendering::Viewport viewport;
2091 const bool hasViewport = SUCCEEDED(pd3dDevice->GetViewport(&viewport)) && viewport.Width && viewport.Height;
2092 // One pixel covers the legacy half-pixel shader shift and MSAA edge samples.
2093 const float guardX = hasViewport ? 2.0f / viewport.Width : 0.0f;
2094 const float guardY = hasViewport ? 2.0f / viewport.Height : 0.0f;
2095
2096 if (drawTransparancy)
2097 logger->AddToCallStack("renderer::RenderBuildings TRUE");
2098 else
2099 logger->AddToCallStack("renderer::RenderBuildings FALSE");
2100
2101 RiseMath::Matrix matrixTemp;
2102 RiseMath::Matrix matrixWorld;
2103
2104 // Don't have to exclude these by distance because they are only painted on their associated grid areas
2106 //pd3dDevice->SetRenderState(Rendering::RenderState::ALPHABLENDENABLE, drawTransparancy); // for field crops
2107#ifdef _DEBUG
2108 //DWORD pValue;
2109 //pd3dDevice->GetRenderState(Rendering::RenderState::STENCILFUNC, &pValue); //greater
2110 //pd3dDevice->GetRenderState(Rendering::RenderState::STENCILREF, &pValue); // 3
2111 //pd3dDevice->GetRenderState(Rendering::RenderState::STENCILENABLE, &pValue); // enabled
2112 //pd3dDevice->GetRenderState(Rendering::RenderState::ALPHABLENDENABLE, &pValue); // for field crops
2113 //pd3dDevice->GetRenderState(Rendering::RenderState::ZENABLE, &pValue); // for field crops
2114#endif
2115
2116 RiseMath::Vector4 temp4;
2117 // 0.81639451247543304392886672218378 magnitude
2118 // mag should be 0.082352941176470588235294117647059
2119 // @todo can't do it this way ... we would need a "specular" property passed in to augment the light
2120 //temp4.x = RiseMath::Max(viewscreen->ptrWeather->bcllight.r, 0.0853626f*buildzone[sortme[t].buildzone].specular);
2121 //temp4.y = RiseMath::Max(viewscreen->ptrWeather->bcllight.g, 0.0980091f*buildzone[sortme[t].buildzone].specular);
2122 //temp4.z = RiseMath::Max(viewscreen->ptrWeather->bcllight.b, 0.1011710f*buildzone[sortme[t].buildzone].specular);
2123 // we are 208 average (times 0.5 is 104), should be 21
2124 temp4.x = viewscreen->alphascreen.r;
2125 temp4.y = viewscreen->alphascreen.g;
2126 temp4.z = viewscreen->alphascreen.b;
2128 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("ambient", &temp4));
2129
2130
2131
2132
2134
2135 // Preserve draw order (including transparency). Bound timestamp overhead
2136 // when a view alternates between many city and colony zones.
2137 std::optional<Rendering::ProfileScope11> categoryTiming;
2138 const char* lastCategory = nullptr;
2139 unsigned categoryRuns = 0;
2140 const auto category = [](PlotType type) {
2141 switch (type)
2142 {
2146 case PlotType::Arcridge: case PlotType::DeoisPort: return "City buildings";
2150 case PlotType::UserRefinery: return "Colony buildings";
2151 default: return "Other buildings";
2152 }
2153 };
2154 for (size_t t = 0; t < sortme.size(); t++)
2155 {
2156 const BUILDZONE& buildzone = buildzones.at(sortme.at(t));
2157 const char* name = categoryRuns >= 24 ? "Remaining building zones" : category(buildzone.type);
2158 if (!lastCategory || strcmp(lastCategory, name) != 0)
2159 {
2160 categoryTiming.reset(); categoryTiming.emplace(name);
2161 lastCategory = name; ++categoryRuns;
2162 }
2163
2164 RiseMath::MatrixTranslation(&matrixTemp,
2165 static_cast<float>(playerships[0].precisionx + static_cast<double>(buildzone.terpos.x)),
2166 static_cast<float>(playerships[0].precisiony + static_cast<double>(buildzone.terpos.y)),
2167 static_cast<float>(playerships[0].precisionz + static_cast<double>(buildzone.terpos.z)));
2168
2169 RiseMath::Matrix mWorldViewProj;
2170 if (playerships[0].isSimulator)
2171 mWorldViewProj = matrixTemp * viewscreen->matrixView * viewscreen->matrixProjSim;
2172 else
2173 mWorldViewProj = matrixTemp * viewscreen->matrixLook * viewscreen->matrixProj;
2174
2175 if (buildzone.hasAnimatedGeometry || buildzone.bounds.IntersectsFrustum(mWorldViewProj, guardX, guardY))
2176 {
2177 RiseMath::Vector4 clouduv;
2178 clouduv.x = 0.0f; // UNUSED
2179 clouduv.y = 0.0f; // UNUSED
2180 clouduv.w = powf(1.0f - viewscreen->sunlight.Diffuse.a, 2.0f); // light blend
2181 clouduv.z = buildzone.emissive * clouduv.w; // emissive
2182 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("clouduv", &clouduv));
2183
2184
2185 //if (!gridarray[actual.u][actual.v].powered)
2186 //{
2187 // V(viewscreen->gameclass->graphics->g_pEffect->SetTexture("ColorMap2", nullptr));
2188 //}
2189
2190 V(pd3dDevice->SetStreamSource(0, buildzone.VB, 0, sizeof RiseVertex2Vertex));
2191 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
2192 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
2193
2194 short oldtexture = -1;
2195
2196 for (const auto& batch : buildzone.drawBatches)
2197 {
2198 const s_mesh_component& mesh_component = buildzone.componentarray[batch.component];
2199 Rendering::RenderTexture* overlay = nullptr;
2200 // Simulator billboards use the base material, even with cached campaign artwork.
2201 if (!playerships[0].isSimulator && mesh_component.type == 26 && buildzone.signOverlayUV[batch.component])
2202 overlay = viewscreen->cityCampaignLogos.Texture(static_cast<int32_t>(mesh_component.attachto));
2203 V(viewscreen->gameclass->graphics->g_pEffect->SetTexture("CityOverlayMap", overlay));
2204 V(viewscreen->gameclass->graphics->g_pEffect->SetInt("CityOverlayEnabled", overlay != nullptr));
2205
2206 // skip the control tower in the Deois Port district when we are inside
2207 // gjenner found that we weren't checking this for being in a building (old bldg value uncleared)
2210 buildzone.type == PlotType::DeoisPort && mesh_component.type == 94)
2211 continue;
2212
2213 // this is specifically for the domes at the township colonies, transparency atrium, and flame towers
2214 if ((!drawTransparancy && (mesh_component.texture == 164 || mesh_component.type == 57 || mesh_component.type == 141)) ||
2215 (drawTransparancy && (mesh_component.texture != 164 && mesh_component.type != 57 && mesh_component.type != 141)))
2216 continue;
2217
2218 clouduv.x = mesh_component.type;
2219 clouduv.y = static_cast<float>(fmod(*fTime, 6.4)) * 0.15625f * 32.0f;
2220 clouduv.w = 0.0f; // UNUSED
2221 clouduv.z = 0.0f; // UNUSED
2222 V(viewscreen->gameclass->graphics->g_pEffect->SetVector("Features", &clouduv));
2223
2224 if (oldtexture != mesh_component.texture)
2225 {
2226 oldtexture = mesh_component.texture;
2227
2228 if (mesh_component.type == 141)
2229 {
2230 viewscreen->gameclass->graphics->g_pEffect->SetTexture("ColorMap", nullptr);
2231 viewscreen->gameclass->graphics->g_pEffect->SetTexture("ColorMap2", nullptr);
2233 }
2234 else
2235 {
2237 if (buildzone.powered)
2239 else
2240 viewscreen->gameclass->graphics->g_pEffect->SetTexture("ColorMap2", nullptr);
2241 }
2242 }
2243
2244 if (mesh_component.texture == 164 || mesh_component.type == 57 || mesh_component.type == 141) // transparency
2245 {
2249 }
2250
2251 if (mesh_component.type == 250) // no backface culling
2253
2254 if (mesh_component.type == 8) // algae fields
2255 {
2257
2258 // we need the bias to be higher when the item is closer
2259 // so -0.001 when it is 0.5km, -0.00001 works great at like 1k+?
2260
2261 //float bias = RiseMath::Min(0.7f, RiseMath::Max(0.2f, sortme[t].dist)); // 0.5km and 1km
2262 //bias = bias - 0.2f; // 0-0.5km
2263 //bias = bias / 0.5f; // 0-1 scalar
2264 //bias = 100.0f*(1.0f - bias); // 100-0 scalar
2265 //bias = (bias * -0.00001f) - 0.00001f;
2266
2267
2268 float bias = -0.00001f; // -0.001 works good but makes things further away look obviously sorted wrong
2269 pd3dDevice->SetRenderState(Rendering::RenderState::DEPTHBIAS, *reinterpret_cast<DWORD*>(&bias));
2270 //float bias2 = 0.001f;
2271 //pd3dDevice->SetRenderState(Rendering::RenderState::SLOPESCALEDEPTHBIAS, *((DWORD*)&bias2));
2272 }
2273
2274 if (mesh_component.type == 78) // guns turrets
2275 {
2276 // tried WT WU WT on side
2277 // tried TW WU WT PERFECT!
2278
2279 // Undo location
2280 RiseMath::Matrix undomat, matTemp;
2282 mesh_component.nominalxyz.x + mesh_component.nominalCG.x,
2283 mesh_component.nominalxyz.y + mesh_component.nominalCG.y,
2284 mesh_component.nominalxyz.z + mesh_component.nominalCG.z);
2285 RiseMath::MatrixMultiply(&undomat, &matTemp, &buildzone.matrixBase);
2286 RiseMath::MatrixInverse(&matTemp, nullptr, &undomat);
2287
2288 // rotate
2289 RiseMath::MatrixRotationZ(&matrixWorld, sinf(static_cast<float>(*fTime)));
2290 matrixWorld = matTemp * matrixWorld;
2291 // redo location
2292 matrixWorld = matrixWorld * undomat;
2293 // apply view
2294 matrixWorld = matrixWorld * matrixTemp;
2295
2296 if (playerships[0].isSimulator)
2297 mWorldViewProj = matrixWorld * viewscreen->matrixView * viewscreen->matrixProjSim;
2298 else
2299 mWorldViewProj = matrixWorld * viewscreen->matrixLook * viewscreen->matrixProj;
2300 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
2301 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixWorld));
2302 }
2303
2305 mesh_component.type==78 ? matrixWorld : matrixTemp);
2306 if (buildzone.dist < 4.0f) // physical km, independent of cube-grid orientation
2307 {
2308 V(viewscreen->gameclass->graphics->g_pEffect->BeginPass(2)); // close buildings
2309 }
2310 else
2311 {
2312 V(viewscreen->gameclass->graphics->g_pEffect->BeginPass(3)); // far buildings
2313 }
2314
2315 // Keep material/state updates in their original order, including
2316 // hidden batches: following components can inherit these values.
2317 // Turrets use their animated matrix above; depth-biased algae retain
2318 // the original path. Only provably off-screen triangles are skipped.
2319 if (!hasViewport || mesh_component.type == 8 ||
2320 batch.bounds.IntersectsFrustum(mWorldViewProj, guardX, guardY))
2321 {
2322 V(pd3dDevice->DrawPrimitive(Rendering::Primitive::TriangleList, batch.first, batch.primitives));
2323 if (overlay)
2324 viewscreen->cityCampaignLogos.MarkDrawn(static_cast<int32_t>(mesh_component.attachto));
2325 if (overlay && viewscreen->adDiagnostics.Collecting())
2326 {
2327 const auto measurement = viewscreen->cityCampaignLogos.Measure(static_cast<int32_t>(mesh_component.attachto));
2328 if (measurement.filename)
2329 {
2330 AdViewability::Placement placement;
2332 placement.entity = buildzone.adEntity; placement.component = batch.first;
2333 placement.creative = *measurement.filename; placement.creativeHash = measurement.hash;
2334 viewscreen->adDiagnostics.RegisterSignDraw(*pd3dDevice, placement, measurement.metadata, measurement.lifetime,
2335 measurement.frame, measurement.frameCount, measurement.average, buildzone.VB->Geometry(), batch.first, batch.primitives,
2336 buildzone.dist < 4.0f ? 2 : 3, matrixTemp, viewscreen->matrixLook, viewscreen->matrixProj, buildzone.dist);
2337 }
2338 }
2339 }
2340
2342
2343 // restore settings for next pass
2344 if (mesh_component.texture == 164 || mesh_component.type == 57 || mesh_component.type == 141) // transparency
2345 {
2347 }
2348
2349 if (mesh_component.type == 250) // no backface culling
2351
2352 if (mesh_component.type == 78)
2353 {
2354 if (playerships[0].isSimulator)
2355 mWorldViewProj = matrixTemp * viewscreen->matrixView * viewscreen->matrixProjSim;
2356 else
2357 mWorldViewProj = matrixTemp * viewscreen->matrixLook * viewscreen->matrixProj;
2358 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
2359 V(viewscreen->gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
2360 }
2361
2362 if (mesh_component.type == 8) // algae fields
2363 {
2365 }
2366 }
2367 }
2368 }
2369
2370
2371 categoryTiming.reset();
2374
2375
2376 logger->AddToCallStack("renderer::RenderBuildings END");
2377 V(viewscreen->gameclass->graphics->g_pEffect->SetInt("CityOverlayEnabled", 0));
2378 V(viewscreen->gameclass->graphics->g_pEffect->SetTexture("CityOverlayMap", nullptr));
2379 pd3dDevice->SetFVF(originalFvf);
2380}
2381
2382void buildings::RenderLights(Rendering::RenderDevice* pd3dDevice, const double* fTime) const
2383{
2384 RiseMath::Matrix matrixTemp;
2385 RiseMath::Vector3 result;
2386 float f_temp;
2387 HRESULT hr;
2388 const bool volumeClouds = viewscreen->VolumeCloudsEnabled();
2389 CloudVolume::Point cloudEye{};
2390 if (volumeClouds)
2391 {
2392 RiseMath::Matrix inverseView;
2393 RiseMath::MatrixInverse(&inverseView, nullptr, &viewscreen->matrixLook);
2394 const auto eye = -playerships[0].position + RiseMath::Vector3(inverseView._41, inverseView._42, inverseView._43);
2395 cloudEye = { eye.x, eye.y, eye.z };
2396 }
2397
2398 for (size_t t = 0; t < sortme.size(); t++)
2399 {
2400 const BUILDZONE& buildzone = buildzones.at(sortme.at(t));
2401 for (size_t r = 0; r < buildzone.effects.size(); r++)
2402 {
2403 s_light_effect effect = buildzone.effects.at(r);
2404 const RiseMath::Color sourceColor = effect.diffuse;
2405 float cloudTransmission = 1.0f;
2406 if (effect.sequencing & citystuff.compare[buildzone.type])
2407 {
2409 const float dist = RiseMath::Vec3Length(&diff);
2410 const float alphafog = Clamp((viewscreen->ptrWeather->fFogEndHorizon - dist * 0.5f) / viewscreen->ptrWeather->fFogEndHorizon, 0, 1);
2411 if (alphafog == 0.0f)
2412 continue;
2413
2414 // we used to use precision position but the little offset makes the lights look more realistic, flickery
2415 RiseMath::MatrixTranslation(&matrixTemp, diff.x, diff.y, diff.z);
2416 V(pd3dDevice->SetTransform(Rendering::TransformSlot::WORLD, &matrixTemp));
2417
2418 const float psize = 64.0f / powf(dist, 0.75f) * viewscreen->gameclass->displayscale * RiseMath::ToRadian(115.0f) / g_fFOV;
2419
2420 effect.diffuse.r *= alphafog;
2421 effect.diffuse.g *= alphafog;
2422 effect.diffuse.b *= alphafog;
2423 if (effect.power == 1.5f) // rotating light (only use case is the airport rotating beacon)
2424 {
2425 // turn beacon on if it's night OR if ceiling ≤ 1 000 ft AGL OR visibility < 3 SM
2426 if (viewscreen->ptrWeather->elevation <= 0.0f || // sun at or below horizon
2427 viewscreen->ptrWeather->GetCloudCeilingKm() <= 0.3048f || // 1 000 ft ≈ 0.3048 km
2428 viewscreen->ptrWeather->GetVisibilityKm() < 4.828f) // 3 SM ≈ 4.828 km
2429 {
2430 RiseMath::Vec3Normalize(&result, &buildzone.terpos); // plumb
2431 RiseMath::MatrixRotationAxis(&matrixTemp, &result, RiseMath::Tau * fmodf(static_cast<float>(*fTime), 8.888f) / 8.888f);
2432 RiseMath::Vec3TransformNormal(&result, &effect.normal, &matrixTemp);
2433 }
2434 else
2435 {
2436 continue;
2437 }
2438 }
2439 else
2440 {
2441 result = effect.normal;
2442 }
2443
2444
2445 diff /= dist; // normalize
2446
2447 if (effect.power != 0.0f) // new light supported on christmas tree
2448 {
2449 f_temp = -RiseMath::Vec3Dot(&result, &diff);
2450 if (effect.power != 1.5f)
2451 f_temp += 0.5f; // should be able to see from ground level 30�
2452 if (f_temp < 0.0f)
2453 f_temp = 0.0f;
2454 else if (f_temp > 1.0f)
2455 f_temp = 1.0f;
2456 }
2457 else
2458 {
2459 f_temp = psize * 0.25f;
2460 }
2461
2462 if (effect.power == 1.0f) // bulb
2463 f_temp = psize * f_temp;
2464 else if (effect.power == 0.5f) // strobe
2465 {
2466 if (f_temp > 0.0f)
2467 f_temp = psize * 2.0f; // all directions
2468 }
2469 else if (effect.power == 1.5f) // rotating
2470 {
2471 if (f_temp > 0.0f)
2472 f_temp = psize * 4.0f * powf(f_temp, 16.0f);
2473 }
2474 else if (effect.power == 2.0f) // beam
2475 f_temp = psize * 4.0f * powf(f_temp, 8.0f);
2476
2477 if (f_temp > 0.0f)
2478 {
2479 // These additive sprites are drawn after the cloud composite and
2480 // write no depth. Integrate to the actual lamp, as for ship lights;
2481 // distance fog alone cannot hide a beacon inside an opaque deck.
2482 if (volumeClouds)
2483 {
2484 const auto& lamp = effect.position; // planet-fixed render coordinates
2485 const float transmission = CloudVolume::Transmittance(cloudEye, { lamp.x, lamp.y, lamp.z },
2487 if (transmission < .001f) continue;
2488 cloudTransmission = transmission;
2489 effect.diffuse.r *= transmission;
2490 effect.diffuse.g *= transmission;
2491 effect.diffuse.b *= transmission;
2492 }
2494 SignalLightAttenuation::Apply(*pd3dDevice, sourceColor, alphafog * cloudTransmission, playerships[0].isSimulator);
2495 if (f_temp > 256.0f)
2496 f_temp = 256.0f;
2497 // Tried just casting float to DWORD but didn't work
2498 V(pd3dDevice->SetRenderState(Rendering::RenderState::POINTSIZE, *reinterpret_cast<DWORD*>(&f_temp)));
2500 }
2501 }
2502 }
2503 }
2504
2505 // All user-airfield edge sources share one compact draw. Their ground
2506 // illumination remains the existing terrain texture, with no dynamic lights.
2507 runwayLightInstances.clear();
2508 const float night = powf(1.0f - viewscreen->sunlight.Diffuse.a, 2.0f);
2509 if (night > 0 && viewscreen->m_pddsRunwayEdgeLight1)
2510 {
2511 const auto& draws = pd3dDevice->Draws();
2512 DirectX::XMFLOAT4X4 viewProjection;
2513 DirectX::XMStoreFloat4x4(&viewProjection, DirectX::XMMatrixMultiply(
2514 DirectX::XMLoadFloat4x4(&pd3dDevice->Draws().Fixed().view),
2515 DirectX::XMLoadFloat4x4(&pd3dDevice->Draws().Fixed().projection)));
2516 const auto& viewport = draws.Viewport();
2517 const float scale = viewscreen->gameclass->displayscale * RiseMath::ToRadian(115.0f) / g_fFOV;
2518 for (const auto ordinal : sortme)
2519 {
2520 const auto& zone = buildzones.at(ordinal);
2521 // Use the same precise camera-relative origin as the ground overlays.
2522 const RiseMath::Vector3 origin(
2523 float(playerships[0].precisionx + double(zone.terpos.x)),
2524 float(playerships[0].precisiony + double(zone.terpos.y)),
2525 float(playerships[0].precisionz + double(zone.terpos.z)));
2526 for (const auto& local : zone.runwayEdgeLights)
2527 {
2528 const auto position = origin + local;
2529 const float distance = RiseMath::Vec3Length(&position);
2530 const auto appearance = RunwayEdgeLights::SizeAndIntensity(distance, scale, night);
2531 if (appearance.intensity <= 0) continue;
2532 GeometryBounds bounds; bounds.Include(position);
2533 if (!bounds.IntersectsFrustum(viewProjection, (appearance.diameter + 2) / viewport.Width,
2534 (appearance.diameter + 2) / viewport.Height)) continue;
2535 const float fogEnd = viewscreen->ptrWeather->fFogEndHorizon;
2536 if (fogEnd <= 0) continue;
2537 float transmission = Clamp(1 - distance / (2 * fogEnd), 0, 1);
2538 if (transmission <= 0) continue;
2539 if (volumeClouds)
2540 {
2541 const auto lamp = zone.terpos + local;
2542 const float cloud = CloudVolume::Transmittance(cloudEye, { lamp.x,lamp.y,lamp.z },
2544 if (cloud < .001f) continue;
2545 transmission *= cloud;
2546 }
2547 runwayLightInstances.push_back({ {position.x,position.y,position.z},appearance.diameter,
2548 appearance.intensity * SignalLightAttenuation::EmissionTransmission(transmission,playerships[0].isSimulator) });
2549 }
2550 }
2552 }
2553}
2554
2556{
2557 char msg[99];
2558 sprintf_s(msg, sizeof msg, "buildings::BuildCurbs %i,%i", rts.u, rts.v);
2559 logger->AddToCallStack(msg);
2560
2561 if (rts.u == -2 && rts.v == -2)
2562 return;
2563
2564 if (f_AGL > 0.078f)
2565 return;
2566
2567 if (gridarray[31][31].buildzoneOrdinal != -1)
2568 curbTerpos = buildzones.at(gridarray[31][31].buildzoneOrdinal).terpos;
2569 else
2570 curbTerpos = gridarray[31][31].position;
2571
2572 // @todo so we should be able to track oldRts and shift left/right up/down like we do with terrain?
2573 for (short rtsu = -1; rtsu <= 1; rtsu++)
2574 for (short rtsv = -1; rtsv <= 1; rtsv++)
2575 BuildCurb(rts, rtsu, rtsv);
2576
2577 logger->AddToCallStack("buildings::BuildCurbs DONE");
2578}
2579
2581{
2582 char msg[99];
2583 sprintf_s(msg, sizeof msg, "buildings::BuildRocks we are zone %i", viewscreen->zone);
2584 logger->AddToCallStack(msg);
2585
2586 if (!viewscreen->zone) // couldn't calculate
2587 return;
2588
2589 if (f_AGL > 0.78f)
2590 return;
2591
2592 rockTerpos = gridarray[31][31].position;
2593
2594 // @todo so we should be able to track oldRts and shift left/right up/down like we do with terrain?
2595 for (short rtsu = -1; rtsu <= 1; rtsu++)
2596 for (short rtsv = -1; rtsv <= 1; rtsv++)
2597 BuildRock(rtsu + 1, rtsv + 1);
2598
2599 logger->AddToCallStack("buildings::BuildRocks DONE");
2600}
2601
2602void buildings::BuildCurb(VECTOR2SHORT origRts, short rtsu, short rtsv)
2603{
2604 // so we know the rts grid and gridarray[31][31]...
2605 char msg[99];
2606 sprintf_s(msg, sizeof msg, "OrigRts %i,%i Surr %i,%i", origRts.u, origRts.v, rtsu, rtsv);
2607 logger->Log(msg);
2608
2609 VECTOR2SHORT rts;
2610 rts.u = static_cast<short>(origRts.u + rtsu);
2611 rts.v = static_cast<short>(origRts.v + rtsv);
2612 // so if rts.u goes <0 or >=26
2613
2614 short gridU = 31, gridV = 31;
2615 if (rts.u < 0)
2616 {
2617 gridU = 30;
2618 rts.u += 26;
2619 }
2620 else if (rts.u > 25)
2621 {
2622 gridU = 32;
2623 rts.u -= 26;
2624 }
2625 if (rts.v < 0)
2626 {
2627 gridV = 30;
2628 rts.v += 26;
2629 }
2630 else if (rts.v > 25)
2631 {
2632 gridV = 32;
2633 rts.v -= 26;
2634 }
2635
2636 sprintf_s(msg, sizeof msg, "Grid %i,%i NewRts %i,%i", gridU, gridV, rts.u, rts.v);
2637 logger->Log(msg);
2638
2639 const int rtsuo = rtsu + 1, rtsvo = rtsv + 1;
2640
2641 SAFE_RELEASE(curbVB[rtsuo][rtsvo]);
2642 curbBounds[rtsuo][rtsvo]={};
2643
2644 short buildzoneOrdinal = gridarray[gridU][gridV].buildzoneOrdinal;
2645 if (buildzoneOrdinal == -1)
2646 return;
2647
2648 const BUILDZONE& buildzone = buildzones.at(buildzoneOrdinal);
2649 if (!buildzone.rts)
2650 return;
2651
2652 char file[99] = {};
2653 int handle;
2654
2655 RTSGRID rtsgrid = buildzone.rts[rts.u * 26 + rts.v];
2656 if (rtsu == 0 && rtsv == 0)
2657 {
2660 }
2661
2662 curbTexture[rtsuo][rtsvo] = rtsgrid.texture;
2663 switch (rtsgrid.texture)
2664 {
2665 case 1: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f1a_hex.daw");
2666 break;
2667 case 2: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f1b_hex.daw");
2668 break;
2669 case 3: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f1c_hex.daw");
2670 break;
2671 case 4: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f2a_hex.daw");
2672 break;
2673 case 5: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f2b_hex.daw");
2674 break;
2675 case 6: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f2c_hex.daw");
2676 break;
2677 case 7: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f3a_hex.daw");
2678 break;
2679 case 8: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f3b_hex.daw");
2680 break;
2681 case 9: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f4a_hex.daw");
2682 break;
2683 case 10: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f4b_hex.daw");
2684 break;
2685 case 11: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f5a_hex.daw");
2686 break;
2687 case 12: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f6a_hex.daw");
2688 break;
2689 case 13: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f6b_hex.daw");
2690 break;
2691 case 14: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f6c_hex.daw");
2692 break;
2693 case 15: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f6d_hex.daw");
2694 break;
2695 case 16: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f6e_hex.daw");
2696 break;
2697 case 17: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f7a_hex.daw");
2698 break;
2699 case 18: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f7b_hex.daw");
2700 break;
2701 case 19: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f7c_hex.daw");
2702 break;
2703 case 20: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f8a_hex.daw");
2704 break;
2705 case 21: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f8b_hex.daw");
2706 break;
2707 case 22: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f8c_hex.daw");
2708 break;
2709 case 23: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f9a_hex.daw");
2710 break;
2711 case 24: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f9b_hex.daw");
2712 break;
2713 case 25: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f10a_hex.daw");
2714 break;
2715 case 26: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f10b_hex.daw");
2716 break;
2717 case 27: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f10c_hex.daw");
2718 break;
2719 case 28: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f10d_hex.daw");
2720 break;
2721 case 29: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f11a_hex.daw");
2722 break;
2723 case 30: // completely flat
2724 return;
2725 case 31: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f12b_hex.daw");
2726 break;
2727 case 32: // completely flat
2728 return;
2729 case 33: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f13b_hex.daw");
2730 break;
2731 case 34: // completely flat
2732 return;
2733 case 35: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f14b_hex.daw");
2734 break;
2735 case 36: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f15a_hex.daw");
2736 break;
2737 case 37: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f15b_hex.daw");
2738 break;
2739 case 38: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f15c_hex.daw");
2740 break;
2741 case 39: // completely flat
2742 return;
2743 case 40: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f15e_hex.daw");
2744 break;
2745 case 41: // completely flat
2746 return;
2747 case 42: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f17_hex.daw");
2748 break;
2749 case 43: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f18_hex.daw");
2750 break;
2751 case 44: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f19_hex.daw");
2752 break;
2753 case 45: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f20_hex.daw");
2754 break;
2755 case 46: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f21_hex.daw");
2756 break;
2757 case 47: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f22_hex.daw");
2758 break;
2759 case 48: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f23_hex.daw");
2760 break;
2761 case 49: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f24_hex.daw");
2762 break;
2763 case 50: // completely flat
2764 return;
2765 case 51: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f26_hex.daw");
2766 break;
2767 case 52: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f27_hex.daw");
2768 break;
2769 case 53: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f28_hex.daw");
2770 break;
2771 case 54: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f29_hex.daw");
2772 break;
2773 case 55: sprintf_s(file, sizeof file, "Meshes\\Curbs\\f30_hex.daw");
2774 break;
2775 default:
2776 return;
2777 }
2778
2779 _sopen_s(&handle, file, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, _SH_DENYWR, _S_IWRITE);
2780 if (handle == -1)
2781 {
2782 sprintf_s(msg, sizeof msg, "Curbs() %i failed to load \"%s\"", buildzoneOrdinal, file);
2784 return;
2785 }
2786
2787 _lseek(handle, 0L, SEEK_SET);
2788 short i_temp;
2789 _read(handle, &i_temp, 2);
2790 UINT tempvertices = i_temp;
2791 curbPrims[rtsuo][rtsvo] = tempvertices / 3;
2792
2793 sprintf_s(msg, sizeof msg, "Curbs(%i,%i) %i scanning %i file vertices (%i primitives)...", rtsu, rtsv, buildzoneOrdinal, tempvertices, curbPrims[rtsuo][rtsvo]);
2794 logger->Log(msg);
2795
2796 RiseVertexVertex* tempdax = new RiseVertexVertex[tempvertices];
2797 RiseMath::Vector3 tempnormal;
2798
2799 RiseMath::Matrix matrixRotation;
2800 RiseMath::MatrixRotationZ(&matrixRotation, RiseMath::ToRadian(180 - 90 * rtsgrid.rotation));
2801 RiseMath::Matrix invMatrixRotation;
2802 RiseMath::MatrixInverse(&invMatrixRotation, nullptr, &matrixRotation);
2803
2804 for (UINT r = 0; r < tempvertices; r++)
2805 {
2806 _read(handle, &tempnormal, 12);
2807 if (rtsgrid.rotation > 3)
2808 tempnormal.x = -tempnormal.x;
2809 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixRotation);
2810 // this sets the corner to 0,0
2811 tempnormal.x += 500.0f * 0.000348f;
2812 tempnormal.y -= 500.0f * 0.000348f;
2813 // the middle of the grid is 13,12
2814 tempnormal.x += (rts.u - 13) * 1000.0f * 0.000348f;
2815 tempnormal.y += (rts.v - 12) * 1000.0f * 0.000348f;
2816 tempnormal *= 0.22413793103448275862068965517241f; // RTS standard is 0.078 km wide ... Giorgi gave us 1000x0.000348=.348km
2817 tempnormal.z *= 0.74432234432234432234432234432236f; // He gave us curbs 3.5 units tall ... after the above adjustment we scaled them to 8"
2818 tempdax[r].x = tempnormal.x;
2819 tempdax[r].y = tempnormal.y;
2820 tempdax[r].z = tempnormal.z;
2821 _read(handle, &tempnormal, 12);
2822 if (rtsgrid.rotation > 3)
2823 tempnormal.x = -tempnormal.x;
2824 RiseMath::Vec3TransformNormal(&tempnormal, &tempnormal, &invMatrixRotation);
2825 tempdax[r].nx = -tempnormal.x;
2826 tempdax[r].ny = tempnormal.y;
2827 tempdax[r].nz = tempnormal.z;
2828 _read(handle, &tempnormal.x, 4);
2829 tempdax[r].tu = tempnormal.x;
2830 _read(handle, &tempnormal.y, 4);
2831 tempdax[r].tv = tempnormal.y;
2832 }
2833
2834 _close(handle);
2835
2836 HRESULT hr;
2837
2838 if (FAILED(hr = Rendering::ClientRenderer()->CreateVertexBuffer(tempvertices * sizeof RiseVertex2Vertex, Rendering::BufferUsage::WRITEONLY, RISE_FVF_VERTEX2, Rendering::ResourcePool::Managed, &curbVB[rtsuo][rtsvo], NULL)))
2839 {
2840 sprintf_s(msg, sizeof msg, "BuildCurbs() could not create curbVB memory (%i vertices) for \"%s\"", tempvertices, file);
2842 return;
2843 }
2844
2845
2846 RiseVertex2Vertex* vtx;
2847 if (FAILED(hr = curbVB[rtsuo][rtsvo]->Lock(0, 0, reinterpret_cast<void**>(&vtx), 0)))
2848 {
2849 sprintf_s(msg, sizeof msg, "BuildCurbs() could not lock curbVB memory (%i vertices) for \"%s\"", tempvertices, file);
2851 return;
2852 }
2853
2854 RiseMath::Matrix matrixWorld;// = buildzone.matrixBase;
2855 RiseMath::MatrixMultiply(&matrixWorld, &buildzone.matSkew, &buildzone.matrixBase); // buildzone.matrixConform?
2856
2857 // Go through all vertices individually and make new vertex buffer ----------------------
2858 UINT start = 0;
2859 int inc = 1;
2860 if (rtsgrid.rotation > 3)
2861 {
2862 start = tempvertices - 1;
2863 inc = -1;
2864 }
2865 for (UINT r = start; r < tempvertices && r >= 0; r += inc)
2866 {
2867 tempnormal.x = tempdax[r].x;
2868 tempnormal.y = tempdax[r].y;
2869 tempnormal.z = tempdax[r].z;
2870 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &matrixWorld);
2871 vtx->x = tempnormal.x; vtx->y = tempnormal.y; vtx->z = tempnormal.z;
2872 curbBounds[rtsuo][rtsvo].Include(tempnormal);
2873
2874 tempnormal.x = tempdax[r].nx;
2875 tempnormal.y = tempdax[r].ny;
2876 tempnormal.z = tempdax[r].nz;
2877 RiseMath::Vec3TransformNormal(&tempnormal, &tempnormal, &matrixWorld);
2878 vtx->nx = tempnormal.x; vtx->ny = tempnormal.y; vtx->nz = tempnormal.z;
2879
2880 vtx->tu = tempdax[r].tu; vtx->tv = tempdax[r].tv;
2881
2882 // @todo I think we have to use the matrixRotation here so the clouds track over correctly
2883 // @todo also the fact that we are flipping the geometry means we probably have to flip the cloud shadow?
2884 vtx->tu2 = (tempdax[r].tu + static_cast<float>(rts.u)) / 26.0f; vtx->tv2 = (tempdax[r].tv + static_cast<float>(rts.v)) / 26.0f;
2885 vtx++;
2886 }
2887
2888 SAFE_DELETE_ARRAY(tempdax);
2889
2890 if (FAILED(hr = curbVB[rtsuo][rtsvo]->Unlock()))
2891 {
2892 sprintf_s(msg, sizeof msg, "BuildCurbs() could not unlock curbVB memory (%i vertices) for \"%s\"", tempvertices, file);
2894 }
2895}
2896
2897void buildings::PushRocksOffRunway(short gridu, short gridv, unsigned char zone, float* leftToRight, float* topToBottom)
2898{
2899 const float leftBound = (0.73857f - 0.0225f - 0.5f) * 2.0f;
2900 const float rightBound = (0.76143f + 0.0225f - 0.5f) * 2.0f;
2901 const float topOfRunway = 0.5f; // 1/4 down the plot ... 1/2 down the zone
2902 const float topBound = 0.5f - 0.24f;
2903 if (gridarray[gridu][gridv].type == PlotType::UserAirfield && buildings::CheckLayout(98, gridarray[gridu][gridv]))
2904 {
2905 // @ref ICAO recommended RESA
2906 if (zone == 2)
2907 {
2908 // push rocks 240 meters north of runway north edge
2909 if (*leftToRight > leftBound && *leftToRight < rightBound && *topToBottom > topBound && *topToBottom < topOfRunway)
2910 *topToBottom = topBound;
2911 // we clear everything to the LEFT of the runway towards the airfield buildings off to the right
2912 else if (*leftToRight > leftBound && *leftToRight < rightBound && *topToBottom > topOfRunway)
2913 *leftToRight = rightBound;
2914 }
2915 else if (zone == 3)
2916 {
2917 // clear everything to the left or right (whichever is closer)
2918 if (*leftToRight > leftBound && *leftToRight < rightBound)
2919 {
2920 if (*leftToRight < 0.5f)
2921 *leftToRight = leftBound;
2922 else if (*leftToRight > 0.5f)
2923 *leftToRight = rightBound;
2924 }
2925 }
2926 }
2927 else if (zone == 2 && gridarray[gridu][gridv - 1].type == PlotType::UserAirfield && buildings::CheckLayout(98, gridarray[gridu][gridv - 1]))
2928 {
2929 // @ref ICAO recommended RESA
2930 // if the plot to the north is a runway we have to clear the approach path 240 meters from the north edge if within 45 meters of runway
2931 if (*leftToRight > leftBound && *leftToRight < rightBound && *topToBottom < 0.24f)
2932 *topToBottom = 0.24f;
2933 }
2934}
2935
2936void buildings::PushRocksOffRoad(unsigned char roads, unsigned char zone, float* leftToRight, float* topToBottom)
2937{
2938 if (roads >= 8) // segment 0, north, zone 1 and 2
2939 {
2940 if (zone == 1 && *leftToRight > 0.99f)
2941 *leftToRight = 0.99f;
2942 else if (zone == 2 && *leftToRight < 0.01f)
2943 *leftToRight = 0.01f;
2944 }
2945 if ((roads >= 4 && roads <= 7) || roads >= 12) // segment 1, south, zone 4 and 3
2946 {
2947 if (zone == 4 && *leftToRight > 0.99f)
2948 *leftToRight = 0.99f;
2949 else if (zone == 3 && *leftToRight < 0.01f)
2950 *leftToRight = 0.01f;
2951 }
2952 if (roads == 2 || roads == 3 || roads == 6 || roads == 7 ||
2953 roads == 10 || roads == 11 || roads >= 14) // segment 2, west, zones 1 and 4
2954 {
2955 if (zone == 1 && *topToBottom > 0.99f)
2956 *topToBottom = 0.99f;
2957 else if (zone == 4 && *topToBottom < 0.01f)
2958 *topToBottom = 0.01f;
2959 }
2960 if (roads % 2 == 1) // segment 3, east, zones 2 and 3
2961 {
2962 if (zone == 2 && *topToBottom > 0.99f)
2963 *topToBottom = 0.99f;
2964 else if (zone == 3 && *topToBottom < 0.01f)
2965 *topToBottom = 0.01f;
2966 }
2967}
2968
2969void buildings::BuildRock(short rtsuo, short rtsvo)
2970{
2971 rockPrims[rtsuo][rtsvo] = 0;
2972 rockBounds[rtsuo][rtsvo]={};
2973 SAFE_RELEASE(rockVB[rtsuo][rtsvo]);
2974
2975 unsigned char zone = viewscreen->zone;
2976
2977 int gridu = 31, gridv = 31;
2978 if (rtsuo < 1)
2979 {
2980 if (zone == 1)
2981 {
2982 gridu--;
2983 zone = 2;
2984 }
2985 else if (zone == 4)
2986 {
2987 gridu--;
2988 zone = 3;
2989 }
2990 else if (zone == 2)
2991 zone = 1;
2992 else
2993 zone = 4;
2994 }
2995 else if (rtsuo > 1)
2996 {
2997 if (zone == 2)
2998 {
2999 gridu++;
3000 zone = 1;
3001 }
3002 else if (zone == 3)
3003 {
3004 gridu++;
3005 zone = 4;
3006 }
3007 else if (zone == 1)
3008 zone = 2;
3009 else
3010 zone = 3;
3011 }
3012 if (rtsvo < 1)
3013 {
3014 if (zone == 1)
3015 {
3016 gridv--;
3017 zone = 4;
3018 }
3019 else if (zone == 2)
3020 {
3021 gridv--;
3022 zone = 3;
3023 }
3024 else if (zone == 4)
3025 zone = 1;
3026 else
3027 zone = 2;
3028 }
3029 else if (rtsvo > 1)
3030 {
3031 if (zone == 4)
3032 {
3033 gridv++;
3034 zone = 1;
3035 }
3036 else if (zone == 3)
3037 {
3038 gridv++;
3039 zone = 2;
3040 }
3041 else if (zone == 1)
3042 zone = 4;
3043 else
3044 zone = 3;
3045 }
3046
3047 if (gridarray[gridu][gridv].zone == zone) // this is the colony build zone
3048 return;
3049
3050 // @todo someday we can put rocks down in certain zones
3051 if (gridarray[gridu][gridv].pri_landform == 1) // water
3052 {
3053 //if (gridarray[gridu][gridv].pri_transition == 0) // all water
3054 return;
3055 //if (gridarray[gridu][gridv].pri_transition == )
3056 }
3057
3058 //short buildzoneOrdinal = gridarray[gridu][gridv].buildzoneOrdinal;
3059 //if (buildzoneOrdinal != -1 && buildzones.at(buildzoneOrdinal).rts)
3060 // return;
3061
3062 if (gridarray[gridu][gridv].UsesRts())
3063 return;
3064
3065 RiseMath::Vector3 ul, ll, lr, ur;
3066 switch (zone)
3067 {
3068 case 3: // south east
3069 ul = insidearray[gridu][gridv][2];
3070 ur = insidearray[gridu + 1][gridv][1];
3071 ll = insidearray[gridu][gridv + 1][0];
3072 lr = gridarray[gridu + 1][gridv + 1].position;
3073 break;
3074 case 4: // south west
3075 ul = insidearray[gridu][gridv][1];
3076 ur = insidearray[gridu][gridv][2];
3077 ll = gridarray[gridu][gridv + 1].position;
3078 lr = insidearray[gridu][gridv + 1][0];
3079 break;
3080 case 2: // north east
3081 ul = insidearray[gridu][gridv][0];
3082 ur = gridarray[gridu + 1][gridv].position;
3083 ll = insidearray[gridu][gridv][2];
3084 lr = insidearray[gridu + 1][gridv][1];
3085 break;
3086 default: // north west
3087 ul = gridarray[gridu][gridv].position;
3088 ll = insidearray[gridu][gridv][1];
3089 ur = insidearray[gridu][gridv][0];
3090 lr = insidearray[gridu][gridv][2];
3091 break;
3092 }
3093
3094 // grid is 26x26 sectors ... patch is 13x13 sectors
3095 // figure out the 4 corners of the SECTOR from the PATCH above
3096 ul -= rockTerpos;
3097 ur -= rockTerpos;
3098 ll -= rockTerpos;
3099 lr -= rockTerpos;
3100
3101 // Preserve the existing random sequence and vertex cap, but plan the
3102 // instances first so unused capacity is never allocated on CPU or GPU.
3103 constexpr size_t maxVertices = 204800;
3104 struct RockInstance
3105 {
3106 int index;
3107 RiseMath::Matrix rotation;
3108 RiseMath::Vector3 position;
3109 float size;
3110 };
3111 std::array<RockInstance, 230> instances;
3112 size_t instanceCount = 0, vertexCount = 0;
3113 char msg[128];
3114 HRESULT hr;
3115
3116 srand((gridarray[gridu][gridv].tcp.u + 2038L) * 6114L + (gridarray[gridu][gridv].tcp.v + 2038L) * zone);
3117
3118 // how many rocks based on land type? up to 36?
3119 const int totalRocks = rand() % 173 + 57; // 230 max ... based on rock average ...
3120 //const int triangleUl = static_cast<int>((RandomFloat() * 0.5f + 0.25f) * totalRocks); // 25% to 75% of the plot rocks in this zone
3121 float leftToRight = RandomFloat();
3122 float topToBottom = RandomFloat();
3123
3124 for (int i = 0; i < totalRocks; i++) // we found 143 mostly worked for all zones ... that is the average we are trying to achieve
3125 {
3126 // start with what kind of rock 0-35 (36 types) so we can check primitive totals
3127 int rockIndex = rand() % 36;
3128 int tempvertices = rockComponentArray[rockIndex].primitives * 3;
3129 if ((vertexCount + tempvertices) >= maxVertices)
3130 {
3131 //sprintf_s(msg, sizeof msg, "Too many vertices for rocks somehow %i,%i total %i!", rtsuo, rtsvo, totalRocks);
3132 //logger->Log(msg, Logger::Level::Error);
3133 break;
3134 }
3135 vertexCount += tempvertices;
3136
3137
3138 // Sobol sequence
3139 float distanceToNext = powf(RandomFloat(), 2.0f) * 0.092f + 0.008f; // min 8 max 1km weighted shorter
3140 RiseMath::Vector2 direction = RiseMath::Vector2(RandomFloat() * 2.0f - 1.0f, RandomFloat() * 2.0f - 1.0f);
3141 RiseMath::Vec2Normalize(&direction, &direction);
3142 leftToRight += direction.x * distanceToNext;
3143 topToBottom += direction.y * distanceToNext;
3144 if (leftToRight > 1.0f) // so 1.1 we want to be 0.9 so 1.1-1 is 0.1
3145 leftToRight = 1.0f - (leftToRight - 1.0f);
3146 else if (leftToRight < 0.0f)
3147 leftToRight = -leftToRight;
3148 if (topToBottom > 1.0f)
3149 topToBottom = 1.0f - (topToBottom - 1.0f);
3150 else if (topToBottom < 0.0f)
3151 topToBottom = -topToBottom;
3152
3153
3154 if (gridarray[gridu][gridv].roads)
3155 PushRocksOffRoad(gridarray[gridu][gridv].roads, zone, &leftToRight, &topToBottom);
3156 PushRocksOffRunway(gridu, gridv, zone, &leftToRight, &topToBottom);
3157
3158 // V1 + f(V2-V1) + g(V3-V1)
3159 RiseMath::Vector3 theCoordinate;
3160 if ((leftToRight + topToBottom) <= 1.0f)
3161 RiseMath::Vec3BaryCentric(&theCoordinate, &ul, &ur, &ll, leftToRight, topToBottom);
3162 else
3163 RiseMath::Vec3BaryCentric(&theCoordinate, &lr, &ll, &ur, 1.0f - leftToRight, 1.0f - topToBottom);
3164
3165 RiseMath::Matrix ypr;
3167
3168 // what size of rock based on distro ... 1-8m max diameter ... right now they are 1m on average in the DAW
3169 float rockSize = powf(RandomFloat(), 2.0f) * 7.0f + 1.0f;
3170 // so rand()*7+1 is 1-8 linearly ... rand()^2*7+1 is 50% is 2.75
3171
3172 instances[instanceCount++] = {rockIndex, ypr, theCoordinate, rockSize};
3173 }
3174 if (!vertexCount) return;
3175 const UINT bytes = static_cast<UINT>(vertexCount * sizeof(RiseVertex2Vertex));
3176 if (FAILED(hr = Rendering::ClientRenderer()->CreateVertexBuffer(bytes, Rendering::BufferUsage::WRITEONLY,
3178 {
3179 sprintf_s(msg, "BuildRock() could not create rockVB memory (%zu vertices, %u bytes)", vertexCount, bytes);
3180 logger->Log(msg, Logger::Level::Error, hr);
3181 return;
3182 }
3183 RiseVertex2Vertex* vtx;
3184 if (FAILED(hr = rockVB[rtsuo][rtsvo]->Lock(0, 0, reinterpret_cast<void**>(&vtx), 0)))
3185 {
3186 SAFE_RELEASE(rockVB[rtsuo][rtsvo]);
3187 logger->Log("BuildRock() could not lock rockVB memory", Logger::Level::Error, hr);
3188 return;
3189 }
3190 for (size_t i = 0; i < instanceCount; ++i)
3191 {
3192 const auto& instance = instances[i];
3193 const int rockIndex = instance.index;
3194 const auto& ypr = instance.rotation;
3195 const auto& theCoordinate = instance.position;
3196 const float rockSize = instance.size;
3197 const int tempvertices = rockComponentArray[rockIndex].primitives * 3;
3198 int startVertex = rockComponentArray[rockIndex].startvertex;
3199 RiseVertex2Vertex* tempdax = &rockVertexBuffer[startVertex];
3200
3201 // Go through all vertices individually and make new vertex buffer ----------------------
3202 RiseMath::Vector3 tempnormal;
3203 for (short r = 0; r < tempvertices; r++)
3204 {
3205 tempnormal.x = tempdax[r].x * rockSize;
3206 tempnormal.y = tempdax[r].y * rockSize;
3207 tempnormal.z = tempdax[r].z * rockSize;
3208 RiseMath::Vec3TransformCoord(&tempnormal, &tempnormal, &ypr);
3209 tempnormal += theCoordinate;
3210 vtx->x = tempnormal.x; vtx->y = tempnormal.y; vtx->z = tempnormal.z;
3211 rockBounds[rtsuo][rtsvo].Include(tempnormal);
3212
3213 tempnormal.x = tempdax[r].nx;
3214 tempnormal.y = tempdax[r].ny;
3215 tempnormal.z = tempdax[r].nz;
3216 RiseMath::Vec3TransformNormal(&tempnormal, &tempnormal, &ypr);
3217 vtx->nx = tempnormal.x; vtx->ny = tempnormal.y; vtx->nz = tempnormal.z;
3218
3219 // variegation of rock based on ground color?
3220 vtx->tu = tempdax[r].tv2 + gridarray[gridu][gridv].raster.r;
3221 vtx->tv = tempdax[r].tv2 + gridarray[gridu][gridv].raster.g;
3222 vtx->tu2 = tempdax[r].tv2 + gridarray[gridu][gridv].raster.b;
3223
3224 // @todo I think we have to use the matrixRotation here so the clouds track over correctly
3225 // @todo also the fact that we are flipping the geometry means we probably have to flip the cloud shadow?
3226 //vtx->tu2 = (tempdax[r].tu + static_cast<float>(rts.u)) / 26.0f; vtx->tv2 = (tempdax[r].tv + static_cast<float>(rts.v)) / 26.0f;
3227 vtx++;
3228 }
3229 }
3230
3231 if (FAILED(hr = rockVB[rtsuo][rtsvo]->Unlock()))
3232 {
3233 SAFE_RELEASE(rockVB[rtsuo][rtsvo]);
3234 rockBounds[rtsuo][rtsvo] = {};
3235 logger->Log("BuildRock() could not unlock rockVB memory", Logger::Level::Error, hr);
3236 return;
3237 }
3238 rockPrims[rtsuo][rtsvo] = static_cast<UINT>(vertexCount / 3);
3239}
3240
3241
3242void buildings::CollectTerrainObstacles(std::vector<TerrainAwareness::Obstacle>& result) const
3243{
3244 result.clear();
3245 for (const auto& zone : buildzones)
3246 {
3247 for (size_t i = 0; i < zone.obstacleBounds.size(); ++i)
3248 {
3249 const auto& bounds = zone.obstacleBounds[i];
3250 const auto& component = zone.componentarray[i];
3251 // Match hull-collision exclusions, including non-solid crop fields.
3252 if (!bounds.valid || component.type == 8 || component.type == 53 || component.type == 54)
3253 continue;
3255 obstacle.topKm = zone.obstacleTops[i];
3256 // Rotating turret bounds include a conservative rotation allowance.
3257 const float padding = component.type == 78 ? component.boundsphere * 2 : 0;
3258 for (int corner = 0; corner < 8; ++corner)
3259 obstacle.corners[corner] = {
3260 zone.terpos.x + ((corner&1) ? bounds.high[0]+padding : bounds.low[0]-padding),
3261 zone.terpos.y + ((corner&2) ? bounds.high[1]+padding : bounds.low[1]-padding),
3262 zone.terpos.z + ((corner&4) ? bounds.high[2]+padding : bounds.low[2]-padding)};
3263 result.push_back(obstacle);
3264 }
3265 }
3266}
GeometryBounds & AppendBuildingDrawBatch(std::vector< BuildingDrawBatch > &batches, unsigned component, unsigned first, unsigned primitives, short texture, unsigned char type)
bool CitySignQuadUV(Vertex *vertices, unsigned count)
Definition CitySignQuad.h:8
#define SAFE_DELETE_ARRAY(value)
#define SAFE_RELEASE(value)
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
float RandomFloat()
constexpr auto Clamp(T1 val, T2 min, T3 max)
PlotType
@ UserSalvage
@ DeoisIndustrial
@ NorthPole
@ UserTownship
@ O4Ruin4
@ DeoisPort
@ Arcridge
@ DeoisFinancial
@ O4Ruin3
@ UserAirfield
@ DeoisTransit
@ Chojeir
@ UserFarming
@ UserEstate
@ UserMining
@ DeoisCityCenter
@ UserRefinery
@ O4Ruin2
@ O4Ruin1
const RiseMath::Vector3 centerC
@ REF_BUILDING
Definition ServerTypes.h:46
#define lclC
Definition buildings.h:18
short DebugRtsRotation
Definition Bus.h:563
short DebugRtsTexture
Definition Bus.h:562
Rendering::RenderTexture * Texture(int32_t group) const
void MarkDrawn(int32_t group) const
Measurement Measure(int32_t group) const
std::unique_ptr< Bus > bus
Definition GameClass.h:108
std::unique_ptr< HMI > GUI
Definition GameClass.h:106
void AddTrackedResource(const char *name, Rendering::ResourcePool pool=Rendering::ResourcePool::Managed)
void UpdateTrackedResource(const char *name, int status)
float displayscale
Definition GameClass.h:130
std::unique_ptr< Graphics > graphics
Definition GameClass.h:105
Rendering::RenderMaterial * g_pEffect
Definition Graphics.h:30
SPlayerData player[MAX_ONLINEPLAYERS]
Definition gui.h:1093
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
@ Warn
Definition Logger.h:26
@ Fatal
Definition Logger.h:29
@ Error
Definition Logger.h:28
void RegisterSignDraw(RenderDevice &device, const AdViewability::Placement &placement, const CreativeMetadata *metadata, const std::weak_ptr< void > &lifetime, unsigned animationFrame, unsigned animationFrames, const AnimatedAdMetadata::Summary &average, Geometry11 &geometry, unsigned first, unsigned count, unsigned material, const DirectX::XMFLOAT4X4 &world, const DirectX::XMFLOAT4X4 &view, const DirectX::XMFLOAT4X4 &projection, float distanceKm)
FixedState11 & Fixed()
HRESULT Lock(UINT offset, UINT bytes, void **output, DWORD flags)
HRESULT DrawPrimitive(Primitive type, UINT first, UINT count)
HRESULT GetFVF(DWORD *value) const
HRESULT GetViewport(Viewport *value) const
DrawContext11 & Draws()
HRESULT SetStreamSource(UINT stream, RenderBuffer *buffer, UINT offset, UINT stride)
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT SetFVF(DWORD value)
HRESULT SetTransform(DWORD slot, const RiseMath::Matrix *value)
HRESULT SetInt(const char *name, int value)
HRESULT SetVectorArray(const char *name, const RiseMath::Vector4 *value, UINT count)
HRESULT SetVector(const char *name, const RiseMath::Vector4 *value)
HRESULT Begin(UINT *count, DWORD flags)
HRESULT BeginPass(UINT pass)
HRESULT SetTexture(const char *name, RenderTexture *value)
HRESULT SetMatrix(const char *name, const RiseMath::Matrix *value)
ID3D11ShaderResourceView * View() const
HRESULT Draw(DrawContext11 &draws, ID3D11ShaderResourceView *groundLightTexture, const std::vector< RunwayLightInstance11 > &lights)
Rendering::RenderTexture * m_pddsFlame
Definition Viewscreen.h:263
std::unique_ptr< renderer > ptrRenderer
Definition Viewscreen.h:433
RiseMath::Matrix matrixProjSim
Definition Viewscreen.h:345
CloudVolumeRenderer cloudVolume
Definition Viewscreen.h:396
void DamageLandingLight(unsigned lamp, float clearanceKm, float closingMps, const char *cause)
RiseMath::Vector3 LandingLightImpactVelocity(unsigned lamp, const RiseMath::Vector3 &velocityBody) const
bool VolumeCloudsEnabled() const
Definition Viewscreen.h:404
GameClass * gameclass
Definition Viewscreen.h:439
RiseMath::Matrix matrixView
Definition Viewscreen.h:346
RiseMath::Matrix matrixLook
Definition Viewscreen.h:346
Rendering::RenderTexture * m_pddsCityTexture[citytextureC]
Definition Viewscreen.h:295
std::unique_ptr< weather > ptrWeather
Definition Viewscreen.h:434
std::unique_ptr< grid > ptrGrid
Definition Viewscreen.h:426
Rendering::Light sunlight
Definition Viewscreen.h:328
unsigned char zone
Definition Viewscreen.h:141
Rendering::RenderTexture * m_pddsRunwayEdgeLight1
Definition Viewscreen.h:303
Rendering::AdDiagnostics11 adDiagnostics
Definition Viewscreen.h:401
Rendering::RenderTexture * m_pddsRoad
Definition Viewscreen.h:304
CityCampaignLogos cityCampaignLogos
Definition Viewscreen.h:309
Rendering::RenderTexture * m_pddsRTSLights[RTStextureC]
Definition Viewscreen.h:294
RiseMath::Color alphascreen
Definition Viewscreen.h:364
Rendering::RenderTexture * m_pddsCityLights[citytextureC]
Definition Viewscreen.h:296
Rendering::RenderTexture * m_pddsRTSTexture[RTStextureC]
Definition Viewscreen.h:293
Logger * logger
Definition Viewscreen.h:440
RiseMath::Matrix matrixProj
Definition Viewscreen.h:345
UINT curbPrims[lclC][lclC]
Definition buildings.h:96
Rendering::RenderBuffer * curbVB[lclC][lclC]
Definition buildings.h:91
Logger * logger
Definition buildings.h:85
static bool CheckLayout(unsigned i, LOCALGRID2 localgrid2)
void BuildCurbs(VECTOR2SHORT rts)
float determinant(float A[8][8], int n) const
void RenderRocks(Rendering::RenderDevice *pd3dDevice) const
unsigned short rockComponents
Definition buildings.h:100
buildings(Viewscreen *ptr)
Definition buildings.cpp:20
void DamageLandingLightContacts(const RiseMath::Vector3 &velocity, float seconds) const
void BuildRock(short rtsu, short rtsv)
bool g_bRoad
Definition buildings.h:62
void CollectTerrainObstacles(std::vector< TerrainAwareness::Obstacle > &result) const
RiseMath::Vector3 curbTerpos
Definition buildings.h:94
float CheckRtsBumpMap(VECTOR2SHORT rts, VECTOR2SHORT bump, short u, short v)
void Render(Rendering::RenderDevice *pd3dDevice, double *fTime, bool drawTransparancy) const
void BuildRocks()
GeometryBounds curbBounds[lclC][lclC]
Definition buildings.h:98
RiseMath::Vector3 rockTerpos
Definition buildings.h:95
void RenderRts(Rendering::RenderDevice *pd3dDevice, float lightFromStreet) const
Rendering::RenderBuffer * rockVB[lclC][lclC]
Definition buildings.h:92
void OnDestroyDevice()
void Sort()
void RemoveBuildZone(size_t ordinal)
Rendering::RunwayLights11 runwayLightBatch
Definition buildings.h:88
RiseVertex2Vertex * rockVertexBuffer
Definition buildings.h:99
static void PushRocksOffRunway(short gridu, short gridv, unsigned char zone, float *leftToRight, float *topToBottom)
std::vector< size_t > sortme
Definition buildings.h:90
short curbTexture[lclC][lclC]
Definition buildings.h:93
void RenderCurbs(Rendering::RenderDevice *pd3dDevice, float lightFromStreet) const
bool CheckCollision(short buildZoneOrdinal, RiseMath::Vector3 position, RiseMath::Vector3 velocity, float bound, float ElapsedTime, RiseMath::Vector3 *cross) const
std::vector< BUILDZONE > buildzones
Definition buildings.h:87
GeometryBounds rockBounds[lclC][lclC]
Definition buildings.h:98
void adjoint(float A[8][8], float adj[8][8]) const
HRESULT Building(short t, short s)
void inverse(float A[8][8], float inverse[8][8]) const
std::vector< Rendering::RunwayLightInstance11 > runwayLightInstances
Definition buildings.h:89
Viewscreen * viewscreen
Definition buildings.h:84
s_mesh_component * rockComponentArray
Definition buildings.h:101
void RenderLights(Rendering::RenderDevice *pd3dDevice, const double *fTime) const
void getCofactor(float A[8][8], float temp[8][8], int p, int q, int n) const
void BuildCurb(VECTOR2SHORT rts, short rtsu, short rtsv)
UINT rockPrims[lclC][lclC]
Definition buildings.h:97
static void PushRocksOffRoad(unsigned char roads, unsigned char zone, float *leftToRight, float *topToBottom)
Definition grid.h:14
char cube
Definition grid.h:45
VECTOR2SHORT tcp
Definition grid.h:44
void SetSceneShipLights(const GeometryBounds &bounds, const RiseMath::Matrix &world)
void ClearSceneShipLights()
float GetRenderVisibilityKm() const
Definition weather.h:176
float GetCloudCeilingKm() const
Definition weather.cpp:1491
float elevation
Definition weather.h:197
CloudVolume::Parameters cloudParameters
Definition weather.h:216
float GetVisibilityKm() const
Definition weather.cpp:1411
float fFogEndHorizon
Definition weather.h:207
s_city_stuff citystuff
Definition globals.cpp:110
unsigned char ourplanetC
Definition globals.cpp:25
float f_AGL
Definition globals.cpp:9
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
unsigned char ourmoonC
Definition globals.cpp:21
RiseMath::Vector3 insidearray[63][63][3]
Definition globals.cpp:102
float deathinhibit
Definition globals.cpp:39
Scockpit ourcockpit
Definition globals.cpp:114
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
float g_fFOV
Definition globals.cpp:80
unsigned char ourstarC
Definition globals.cpp:24
#define RTStextureC
Definition globals.h:54
#define citytextureC
Definition globals.h:53
#define radiusC
Definition globals.h:87
#define RISE_FVF_VERTEX2
Definition globals.h:119
float Transmittance(Point from, Point to, const Parameters &params, uint32_t seed=DefaultSeed)
constexpr unsigned MaxLights
constexpr float HousingKm
Definition LampContact.h:9
constexpr uint32_t INVSRCALPHA
constexpr uint32_t SRCALPHA
constexpr uint32_t WRITEONLY
constexpr uint32_t LESS
constexpr uint32_t CW
constexpr uint32_t NONE
constexpr uint32_t READONLY
constexpr uint32_t SRCBLEND
constexpr uint32_t CULLMODE
constexpr uint32_t ALPHABLENDENABLE
constexpr uint32_t DEPTHBIAS
constexpr uint32_t POINTSIZE
constexpr uint32_t DESTBLEND
constexpr uint32_t TEXTUREFACTOR
constexpr uint32_t ZFUNC
constexpr uint32_t WORLD
RenderDevice * ClientRenderer()
constexpr PackedColor ColorARGB(unsigned a, unsigned r, unsigned g, unsigned b)
uint32_t PackedColor
auto ToRadian(T value)
Definition ClientMath.h:13
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
Vector3 * Vec3Cross(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:105
constexpr auto Min(A first, B second)
Definition ClientMath.h:15
bool IntersectTri(const Vector3 *a, const Vector3 *b, const Vector3 *c, const Vector3 *origin, const Vector3 *direction, float *u, float *v, float *distance)
Definition ClientMath.h:197
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
Vector3 * Vec3Add(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:96
Matrix * MatrixMultiply(Matrix *out, const Matrix *a, const Matrix *b)
Definition ClientMath.h:116
Matrix * MatrixRotationQuaternion(Matrix *out, const Quaternion *q)
Definition ClientMath.h:135
Quaternion * QuaternionNormalize(Quaternion *out, const Quaternion *q)
Definition ClientMath.h:165
Vector3 * Vec3Lerp(Vector3 *out, const Vector3 *a, const Vector3 *b, float t)
Definition ClientMath.h:99
float Vec3LengthSq(const Vector3 *a)
Definition ClientMath.h:94
Vector3 * Vec3Subtract(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:97
Matrix * MatrixLookAtLH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Definition ClientMath.h:139
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:107
Matrix * MatrixRotationYawPitchRoll(Matrix *out, float yaw, float pitch, float roll)
Definition ClientMath.h:137
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Definition ClientMath.h:118
Vector2 * Vec2Normalize(Vector2 *out, const Vector2 *a)
Definition ClientMath.h:101
constexpr float Tau
Definition ClientMath.h:12
Matrix * MatrixRotationAxis(Matrix *out, const Vector3 *axis, float angle)
Definition ClientMath.h:129
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
Vector3 * Vec3BaryCentric(Vector3 *out, const Vector3 *a, const Vector3 *b, const Vector3 *c, float u, float v)
Definition ClientMath.h:100
Matrix * MatrixTranspose(Matrix *out, const Matrix *a)
Definition ClientMath.h:117
Matrix * MatrixRotationZ(Matrix *out, float value)
Definition ClientMath.h:128
constexpr auto Max(A first, B second)
Definition ClientMath.h:16
Matrix * MatrixTranslation(Matrix *out, float x, float y, float z)
Definition ClientMath.h:125
constexpr TileCorner TileCorners[6]
TexCoord TextureCoordinate(TileCorner corner, unsigned char rotation)
constexpr int TileCount
Appearance SizeAndIntensity(float distanceKm, float displayScale, float night)
void ForEachAnchor(Emit emit)
Vector SurfacePoint(const RtsTerrain::Surface< Vector > &surface, float u, float v)
constexpr unsigned LampsPerSide
void Apply(Rendering::RenderDevice &device, const RiseMath::Color &emission, float transmission, bool isSimulator)
float EmissionTransmission(float transmission, bool isSimulator)
float dist
Definition buildings.h:56
float emissive
Definition buildings.h:46
std::vector< float > obstacleTops
Definition buildings.h:32
RiseMath::Matrix matSkew
Definition buildings.h:42
std::vector< RiseMath::Vector3 > runwayEdgeLights
Definition buildings.h:38
GeometryBounds rtsBounds
Definition buildings.h:29
bool newVersion
Definition buildings.h:48
s_mesh_component * rtscomponentarray
Definition buildings.h:53
RiseMath::Vector3 terpos
Definition buildings.h:41
std::vector< BuildingDrawBatch > drawBatches
Definition buildings.h:30
Rendering::RenderBuffer * VB
Definition buildings.h:35
short u
Definition buildings.h:43
s_mesh_component * componentarray
Definition buildings.h:52
GeometryBounds bounds
Definition buildings.h:29
bool powered
Definition buildings.h:47
short v
Definition buildings.h:43
RiseMath::Matrix matrixBase
Definition buildings.h:42
PlotType type
Definition buildings.h:45
uint64_t adEntity
Definition buildings.h:44
unsigned short components
Definition buildings.h:51
std::vector< GeometryBounds > obstacleBounds
Definition buildings.h:31
bool hasAnimatedGeometry
Definition buildings.h:34
std::vector< bool > signOverlayUV
Definition buildings.h:33
unsigned short rtscomponents
Definition buildings.h:51
std::vector< s_light_effect > effects
Definition buildings.h:39
RTSGRID * rts
Definition buildings.h:54
Rendering::RenderBuffer * RTSVB
Definition buildings.h:36
void Include(const Vector &p)
bool IntersectsFrustum(const Matrix &m, float guardX=0, float guardY=0) const
PlotType type
Definition globals.h:276
RiseMath::Color raster
Definition globals.h:283
short buildzoneOrdinal
Definition globals.h:286
bool powered
Definition globals.h:292
RiseMath::Vector3 position
Definition globals.h:273
RiseMath::Color emissive
Definition globals.h:274
VECTOR2SHORT tcp
Definition globals.h:290
unsigned char texture
Definition globals.h:432
unsigned char rotation
Definition globals.h:432
DirectX::XMFLOAT4X4 view
DirectX::XMFLOAT4X4 projection
RiseMath::Color Diffuse
Vector Sample(int east, int north) const
unsigned char bldg
char landing[2]
short ourplyrC
Definition globals.h:682
int landingDamageVehicleId
Definition globals.h:606
SVesselDC vdat
Definition globals.h:664
std::array< LandingLights::Light, LandingLights::MaxLights > landingLights
Definition globals.h:604
unsigned landingLightCount
Definition globals.h:605
std::array< Point, 8 > corners
float curbelev
Definition globals.h:477
unsigned long compare[PlotType::PlotTypeEnum]
Definition globals.h:479
RiseMath::Vector3 normal
Definition globals.h:350
RiseMath::Vector3 position
Definition globals.h:350
unsigned long sequencing
Definition globals.h:352
short attachto
Definition globals.h:354
RiseMath::Color diffuse
Definition globals.h:351
unsigned char primitive
Definition globals.h:349
RiseMath::Vector3 nominalxyz
Definition globals.h:413
RiseMath::Vector3 nominalypr
Definition globals.h:414
unsigned char type
Definition globals.h:403
float boundsphere
Definition globals.h:410
RiseMath::Vector3 extendby
Definition globals.h:419
RiseMath::Vector3 nominalCG
Definition globals.h:416
RiseMath::Vector3 position
Definition globals.h:511
double precisionz
Definition globals.h:512
unsigned short vehicleId
Definition globals.h:537
double precisiony
Definition globals.h:512
RiseMath::Matrix matrixBase
Definition globals.h:519