Rise
The Vieneo Province
render.cpp
Go to the documentation of this file.
1 #include "Viewscreen.h"
2 #include "../MathUtilities.h"
3 
4 //--------------------------------------------------------------------------------------------
5 // Name: Render()
6 // Desc: Renders the scene.
7 //--------------------------------------------------------------------------------------------
8 void Viewscreen::OnFrameRender(IDirect3DDevice9* pd3dDevice, double fTime) const
9 {
10  logger->AddToCallStack("Viewscreen::OnFrameRender");
11 
12  HRESULT hr;
13 
14  const D3DSURFACE_DESC* pp = DXUTGetD3D9BackBufferSurfaceDesc();
15 
16  short r, s, t; // For debug
17 
18  D3DXMATRIX matrixTemp, matrixWorld, matrixLookAtHorizon, matrixLookAtSkydome, matrixLookAtLocal;
19  D3DXVECTOR3 result, vieneohit;
20 
21  float f_temp;
22 
23  // Determine g_bAboveClouds flag before clearing backbuffer
24  // Everything after this would/could be in the atmosphere...
25  const D3DXVECTOR3 Xsunlight = sunlight.Direction; // Start of the ray
26 
27 
28  // Clear the back-buffer
29  if (dead)
30  {
31  logger->AddToCallStack("Viewscreen::OnFrameRender DEAD");
32 
33  WCHAR str1[99], str2[99];
34 
35  for (int i = 0; i < MAX_ENGINES; i++)
36  {
38  gameclass->bus->EngineThrustLever[i] = 0.1f;
39  else
40  gameclass->bus->EngineThrustLever[i] = 0.0f;
41  gameclass->bus->EngineThrustLever[i] = 0.0f;
42  }
43 
44  ourcockpit.gearshift = -2;
46 
47  // Begin the scene either simulator or RL
48  if (playerships[0].simulator)
49  {
51  gameclass->beginScene = 2; // proj is 2
52  }
53  else
54  {
55  V(pd3dDevice->BeginScene());
56  gameclass->beginScene = 1; // prim is 1
57  }
58 
59  // Alternate shades of red
60  if ((static_cast<int>(fTime) % 2) == 1)
61  {
62  V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0x00800000, 1.0f, 0));
63  }
64  else
65  {
66  V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_TARGET, 0x00A00000, 1.0f, 0));
67  }
68 
69  // Text and GUI button
70  if (!playerships[0].simulator)
71  {
72  if (deathinhibit == 0.0f)
73  {
74  swprintf_s(str2, 99, gameclass->GUI->strings[L_DEAD_REJOIN].c_str());
75  gameclass->GUI->g_HUD.GetButton(IDC_REJOINBTN)->SetEnabled(true);
76  }
77  else
78  {
79  swprintf_s(str2, 99, gameclass->GUI->strings[L_DEAD_COUNTDOWN].c_str(), ceilf(deathinhibit));
80  gameclass->GUI->g_HUD.GetButton(IDC_REJOINBTN)->SetEnabled(false);
81  }
82 
83  WCHAR strcom[199];
84  swprintf_s(strcom, 199, L"%s\n%s", gameclass->GUI->strings[L_DEAD_BUTTON + dead].c_str(), str2);
85  gameclass->GUI->g_HUD.GetStatic(IDC_REJOINTEXT)->SetText(strcom);
86 
87  gameclass->GUI->g_HUD.GetButton(IDC_REJOINBTN)->SetVisible(true);
88  gameclass->GUI->g_HUD.GetStatic(IDC_REJOINTEXT)->SetVisible(true);
89  }
90  }
91  else // not dead
92  {
93  logger->AddToCallStack("Viewscreen::OnFrameRender ALIVE");
94 
95  if (gameclass->GUI->g_HUD.GetButton(IDC_REJOINBTN))
96  gameclass->GUI->g_HUD.GetButton(IDC_REJOINBTN)->SetVisible(false);
97  else
98  logger->Log("IDC_REJOINBTN is nullptr!", Logger::Level::Fatal);
99  if (gameclass->GUI->g_HUD.GetStatic(IDC_REJOINTEXT))
100  gameclass->GUI->g_HUD.GetStatic(IDC_REJOINTEXT)->SetVisible(false);
101  else
102  logger->Log("IDC_REJOINTEXT is nullptr!", Logger::Level::Fatal);
103 
104  // Begin the scene
105  if (playerships[0].simulator)
106  {
107  // using a texture instead of the video card
109  {
111  gameclass->beginScene = 2; // proj is 2
112  }
113  else
114  logger->Log("m_pRenderToSurfaceNextGen is nullptr!", Logger::Level::Fatal);
115 
116  // note: no viewport, full canvas
117 
118  // straight ahead
119  if (pd3dDevice)
120  {
121  V(pd3dDevice->SetTransform(D3DTS_VIEW, &matrixView));
122  }
123  else
124  logger->Log("pd3dDevice is nullptr!", Logger::Level::Fatal);
125  }
126  else
127  {
128  if (pd3dDevice)
129  {
130  V(pd3dDevice->BeginScene());
131  gameclass->beginScene = 1; // prim is 1
132  }
133  else
134  logger->Log("pd3dDevice is nullptr!", Logger::Level::Fatal);
135  }
136 
137  if (g_bAboveClouds)
138  {
139  V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL | D3DCLEAR_TARGET, ptrWeather->dwFogColorZenith, 1.0f, 0));
140  }
141  else
142  {
143  // keeps seams from showing on horizon
144  D3DXCOLOR bob = alphascreen;
145  V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL | D3DCLEAR_TARGET, bob, 1.0f, 0));
146  }
147  }
148 
149 
150  // All Skydome
151  float bury, inner;
152 
153 
154  if (!dead) // only draw outside stuff if we are not dead, simulator or otherwise
155  {
156 #pragma region Outside
157  logger->AddToCallStack("Viewscreen::OnFrameRender OUTSIDE");
158 
160  result.x = 0.0f; result.y = 0.0f; result.z = -1.0f;
161  D3DXVECTOR3 result1 = D3DXVECTOR3(0.0f, 1.0f, 0.0f); // We want this oriented sideways to the ship
162  D3DXVec3TransformNormal(&result, &result, &playerships[0].matrixWorld);
163  D3DXVec3TransformCoord(&result1, &result1, &playerships[0].matrixWorld);
164  // This one is oriented to be level with the horizon (good for smoke, weapons, skydome)
165  D3DXMatrixLookAtRH(&matrixLookAtSkydome, &centerC, &posnorml, &result); // eye at up
166  D3DXMatrixInverse(&matrixLookAtSkydome, nullptr, &matrixLookAtSkydome);
167  // This one is oriented with our ship (good for light flares, some weapons with flare effect)
168  D3DXMatrixLookAtRH(&matrixLookAtLocal, &centerC, &result1, &result); // eye at up
169  D3DXMatrixInverse(&matrixLookAtLocal, nullptr, &matrixLookAtLocal);
170  if (!playerships[0].simulator)
171  D3DXMatrixMultiply(&matrixLookAtLocal, &matrixLookAtLocal, &matrixLookAdj); // for weapons?
172  // the horizon should always face the viewer, not be dependant on the viewer's direction
173  result.x = 0.0f; result.y = 0.0f; result.z = -1.0f;
174  if (!playerships[0].simulator)
175  D3DXMatrixInverse(&matrixTemp, nullptr, &matrixLookAdj);
176  else
177  D3DXMatrixIdentity(&matrixTemp);
178  matrixTemp = matrixTemp * playerships[0].matrixWorld;
179  D3DXVec3TransformNormal(&result, &result, &matrixTemp);
180  D3DXMatrixLookAtRH(&matrixLookAtHorizon, &centerC, &posnorml, &result); // eye at up
181  D3DXMatrixInverse(&matrixLookAtHorizon, nullptr, &matrixLookAtHorizon);
182 
183 
184 
185  V(pd3dDevice->SetFVF(D3DFVF_VERTEX));
186 
187 
188  // replaces areas where the cockpit is rendered (sans the windshield and hud) with stencil 3
189  // Since we are rendering to a projection surface we don't want to render the cockpit right now
190  if (!playerships[0].simulator)
191  {
192  ptrCockpit->Render(pd3dDevice);
193  }
194  else
195  {
196  // here is where we can override the ACL lighting?
197  D3DLIGHT9 templight = sunlight;
198  templight.Ambient.r = templight.Ambient.g = templight.Ambient.b = 1.0f;
199  templight.Diffuse = D3DCOLORVALUE();
200  pd3dDevice->SetLight(0, &templight);
201  }
202 
203  // sprintf_s(msg, sizeof(msg), "Narrow down 2" );
204  // _write(logfile, msg, strlen(msg));
205 
206 
207 
208 #pragma region Upper Cloud Layer Stencil
209  if (g_bAboveClouds) // replaces stencil with 1
210  {
211  logger->AddToCallStack("Viewscreen::OnFrameRender STENCIL");
212 
214  D3DSKYDOME* vtx2;
215  inner = sinf(ptrWeather->cloudHorizonAngle) * ptrWeather->cloudHorizonDistance; // radius of stencil (2a)
216  bury = (f_MSL + radiusC) - ptrWeather->cloudHorizonDistance * cosf(ptrWeather->cloudHorizonAngle); // difference between 1c and 2b
217  V(m_avSkyDome->Lock(0, 0, reinterpret_cast<void**>(&vtx2), D3DLOCK_DISCARD));
218  (*vtx2).x = 0.0f; (*vtx2).y = 0.0f; (*vtx2).z = -bury;
219  (*vtx2).diffuse = ptrWeather->dwFogColorHorizon;
220  vtx2++;
221  for (s = 0; s < skydomeC; s++)
222  {
223  (*vtx2).x = cosf(radperseg * static_cast<float>(s)) * inner;
224  (*vtx2).y = sinf(radperseg * static_cast<float>(s)) * inner;
225  (*vtx2).z = -bury;
226  (*vtx2).diffuse = ptrWeather->dwFogColorHorizon;
227  vtx2++;
228  }
229  (*vtx2).x = inner; (*vtx2).y = 0.0f; (*vtx2).z = -bury;
230  (*vtx2).diffuse = ptrWeather->dwFogColorHorizon;
231  V(m_avSkyDome->Unlock());
232  matrixWorld = matrixLookAtSkydome;
234  matrixWorld._41 = -position.x; matrixWorld._42 = -position.y; matrixWorld._43 = -position.z;
235  // Fix those who are beyond clipping plane
236  f_temp = D3DXVec3Length(&position);
237  if (f_temp > cutplaneC)
238  {
239  f_temp = cutplaneC / f_temp; // If it is 2x as far, this value is 0.5f
240 
241  // Scale apparent scale in matrix
242  D3DXMatrixScaling(&matrixTemp, f_temp, f_temp, f_temp);
243  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
244 
245  // Scale location in matrix
246  D3DXVec3Scale(&result, &position, 1.0f - f_temp);
247  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
248  D3DXMatrixMultiply(&matrixWorld, &matrixWorld, &matrixTemp);
249  }
250 
251  pd3dDevice->SetFVF(D3DFVF_SKYDOME);
252 
253  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
254  // If succeeds, replaces stencil bit
255  pd3dDevice->SetRenderState(D3DRS_STENCILREF, 1); // was 4 from cockpit (not sim) or else 0
256  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); // with 1
257  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); // 0 only
258  pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); // Far or underside
259  pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
260  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);
261  pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0L);
262  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
263 
264  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
265  pd3dDevice->SetStreamSource(0, m_avSkyDome, 0, sizeof(D3DSKYDOME));
266  // total primitives minus the first two on the fan
267  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, skydomeC);
268 
269  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
270  pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE,
271  D3DCOLORWRITEENABLE_BLUE |
272  D3DCOLORWRITEENABLE_GREEN |
273  D3DCOLORWRITEENABLE_RED);
274  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
275  pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); // Normal
276  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
277  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL); // 1 or 0
278  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // was 1
279  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
280  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
281  }
282 #pragma endregion
283 
284  V(pd3dDevice->SetFVF(D3DFVF_VERTEX));
285 
286 
287  if (!g_bAboveClouds) // Start setting up in the middle of the cloud layer
288  {
289 
290 #pragma region Vieneo Cities and Terrain
291  // when they ARE close, it is important to draw them first!
292  // Ahhh but we can't if we are doing the domes!
293 #ifdef _DEBUG
294  cityTimer->startTimer();
295 #endif
296  if (playerships[0].reference != REF_SIMBAY)
297  ptrRenderer->RenderBuildings(pd3dDevice, &fTime, false);
298 #ifdef _DEBUG
299  cityTimer->stopTimer();
300 #endif
301 
302 
303  logger->AddToCallStack("Viewscreen::OnFrameRender TERRAIN setup");
304 
305  D3DXMatrixTranslation(&matrixTemp,
306  static_cast<float>(playerships[0].precisionx + terprecisionx),
307  static_cast<float>(playerships[0].precisiony + terprecisiony),
308  static_cast<float>(playerships[0].precisionz + terprecisionz));
309 
310  D3DXMATRIX mWorldViewProj;
311  if (playerships[0].simulator)
312  mWorldViewProj = matrixTemp * matrixView * matrixProjSim;
313  else
314  mWorldViewProj = matrixTemp * matrixLook * matrixProj;
315  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
316  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
317 
318 
319 
320  // NEW FOR WATER SHADER ... we already have look vector and cloud normal (inverse of normalvector) and cloudUV
321  // need to calculate normal from center, north vector and east vector? it is essentially constant for all visible plates!
322  D3DXVECTOR3 northvector = gridarray[31][31].position - gridarray[31][30].position; // then
323  D3DXVec3Normalize(&northvector, &northvector);
324  D3DXVECTOR4 temp4 = D3DXVECTOR4(northvector.x, northvector.y, northvector.z, 0.0f); // w unused
325  V(gameclass->graphics->g_pEffect->SetVector("Tangent", &temp4));
326  D3DXVECTOR3 eastvector = gridarray[30][31].position - gridarray[31][31].position;
327  D3DXVec3Normalize(&eastvector, &eastvector);
328  temp4 = D3DXVECTOR4(eastvector.x, eastvector.y, eastvector.z, 0.0f); // w unused
329  V(gameclass->graphics->g_pEffect->SetVector("Sunlight", &temp4));
330  D3DXVECTOR3 normalvector;
331  D3DXVec3Normalize(&normalvector, &gridarray[31][31].position);
332  temp4 = D3DXVECTOR4(normalvector.x, normalvector.y, normalvector.z, 0.0f); // w unused
333  V(gameclass->graphics->g_pEffect->SetVector("Radiosity", &temp4));
334 
335 
336  D3DXVECTOR4 ambient;
337  ambient.x = alphascreen.r; ambient.y = alphascreen.g; ambient.z = alphascreen.b; ambient.w = ptrWeather->fFogEndHorizon;
338  V(gameclass->graphics->g_pEffect->SetVector("ambient", &ambient));
339 
340 
341  temp4.x = -static_cast<float>(BCLoffsetu); // clouds
342  temp4.y = -static_cast<float>(BCLoffsetv); // clouds
343  temp4.z = H2Ooffsetu; // water
344  temp4.w = 0.0f; // unused, water?
345  if (!playerships[0].simulator) // this is for the cloud shadow on the ground ... we should skip altogether?
346  temp4.x += allobjects[BCLobjC].rotprog;
347  V(gameclass->graphics->g_pEffect->SetVector("clouduv", &temp4));
348 
349 
350 
351  V(pd3dDevice->SetFVF(D3DFVF_LOCALGRID2));
352 
353  V(pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW));
354 
355  V(pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL)); // 1 or 0
356  V(pd3dDevice->SetRenderState(D3DRS_STENCILREF, 1));
357 
358  //pd3dDevice->SetIndices(m_aiLocalGrid);
359  V(pd3dDevice->SetStreamSource(0, m_avLocalGrid, 0, sizeof(D3DLOCALGRID2)));
360 
361  // shadows on ground from clouds
362  if (!playerships[0].simulator)
363  {
364  V(gameclass->graphics->g_pEffect->SetTexture("CloudMap", m_pddsCloudDetailBelow));
365  }
366 
367  // V(g_pEffect->SetTexture("HFreqMap", m_pddsDetail1));
368 
369 
370 
371 
372 
373 
374 
375  unsigned char old_pri_landform = 255, old_pri_transition = 255;
376  unsigned char old_sec_landform = 255, old_sec_transition = 255;
377  unsigned char old_ter_landform = 255;
378 
379  logger->AddToCallStack("Viewscreen::OnFrameRender TERRAIN begin");
380 
381  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
382 
383  for (r = 0; r < drawlistC; r++)
384  {
385  // the 255 is a server flag, not in DB that way
386  if (drawlist[r].pri_landform == 255)
387  continue;
388 
389  ptrRenderer->temp.x = static_cast<float>(drawlist[r].u - 31);
390  ptrRenderer->temp.y = static_cast<float>(drawlist[r].v - 31);
391  D3DXVec2TransformNormal(&ptrRenderer->temp, &ptrRenderer->temp, &matGridRot);
392  ptrRenderer->u = static_cast<short>(ptrRenderer->temp.x) + 31;
393  ptrRenderer->v = static_cast<short>(ptrRenderer->temp.y) + 31;
394  if (ptrRenderer->u < 0 || ptrRenderer->u > 63 || ptrRenderer->v < 0 || ptrRenderer->v > 63)
395  continue;
396 
397  // this optimization was disabled because of @bug https://jira.risetvp.com/view.php?id=1343
399  continue;
400 
401  if (old_pri_landform != drawlist[r].pri_landform)
402  {
403  if (drawlist[r].pri_landform == 1)
404  {
405  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsWaterNormal));
406  }
407  else
408  {
409  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsLandform[drawlist[r].pri_landform]));
410  }
411  old_pri_landform = drawlist[r].pri_landform;
412  }
413 
414  if (drawlist[r].sec_landform == 255) // flag for RTS grid overlay (stencil) which means pri_transition is 0?
415  {
416  V(pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE));
417  }
418 
419  if (drawlist[r].pri_transition)
420  {
421  if (old_pri_transition != drawlist[r].pri_transition)
422  {
423  // NOTE: 0 indexed
424  V(gameclass->graphics->g_pEffect->SetTexture("AlphaMap", m_pddsTransition[drawlist[r].pri_transition - 1]));
425  old_pri_transition = drawlist[r].pri_transition;
426  }
427 
428  if (old_sec_landform != drawlist[r].sec_landform)
429  {
430  if (drawlist[r].sec_landform == 1)
431  {
432  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsWaterNormal));
433  }
434  else
435  {
436  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsLandform[drawlist[r].sec_landform]));
437  }
438  old_sec_landform = drawlist[r].sec_landform;
439  }
440 
441  if (drawlist[r].sec_transition)
442  {
443  if (old_sec_transition != drawlist[r].sec_transition)
444  {
445  // NOTE: 0 indexed
446  V(gameclass->graphics->g_pEffect->SetTexture("AlphaMap2", m_pddsTransition[drawlist[r].sec_transition - 1]));
447  old_sec_transition = drawlist[r].sec_transition;
448  }
449 
450  if (old_ter_landform != drawlist[r].ter_landform)
451  {
452  if (drawlist[r].ter_landform == 1)
453  {
454  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap3", m_pddsWaterNormal));
455  }
456  else
457  {
458  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap3", m_pddsLandform[drawlist[r].ter_landform]));
459  }
460  old_ter_landform = drawlist[r].ter_landform;
461  }
462  }
463  else
464  {
465  old_sec_transition = old_ter_landform = 255;
466  }
467  }
468  else
469  {
470  old_pri_transition = old_sec_landform = 255;
471  }
472 
473  D3DXVECTOR4 features;
474  if (drawlist[r].runways == 1) // airfield
475  {
476  if (drawlist[r].runwayLights == 1)
477  {
478  features.x = 2.0f; // runway and edge lights
479  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap3", m_pddsRunwayEdgeLight1));
480  }
481  else
482  features.x = 1.0f; // runway only
483  features.w = powf(1.0f - sunlight.Diffuse.a, 2.0f);
485  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap4", m_pddsMarston1));
486  }
487  else if (drawlist[r].roads) // roads
488  {
489  features.x = 3.0f; // roads
490  features.w = drawlist[r].roads;
491  // east west 2 discreet segments, north south 2 discreet segments
492  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap4", m_pddsRoad));
493  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap3", m_pddsIntersection));
494  }
495  else
496  features.x = features.w = 0.0f;
497  features.y = features.z = 0.0f; // unused
498  V(gameclass->graphics->g_pEffect->SetVector("Features", &features));
499 
500  /*BOOL boolArray[5];
501  boolArray[0] = drawlist[r].pri_landform == 1;
502  boolArray[1] = drawlist[r].pri_transition;
503  boolArray[2] = drawlist[r].sec_landform == 1;
504  boolArray[3] = drawlist[r].sec_transition;
505  boolArray[4] = drawlist[r].ter_landform == 1;
506  V(gameclass->graphics->g_pEffect->SetBoolArray("flags", boolArray, 5));*/
507 
508  INT boolArray[5];
509  boolArray[0] = drawlist[r].pri_landform;
510  boolArray[1] = drawlist[r].pri_transition;
511  boolArray[2] = drawlist[r].sec_landform;
512  boolArray[3] = drawlist[r].sec_transition;
513  boolArray[4] = drawlist[r].ter_landform;
514  V(gameclass->graphics->g_pEffect->SetIntArray("flags", boolArray, 5));
515 
516 
517  // was 2km, went a little further for pixel fog... should make a separate pass that does this without spotlight if it works better
518  if (fabs(ptrRenderer->temp.x) < 4 && fabs(ptrRenderer->temp.y) < 4 && !playerships[0].simulator)
519  {
520  V(gameclass->graphics->g_pEffect->BeginPass(0));
521  }
522  else
523  {
524  V(gameclass->graphics->g_pEffect->BeginPass(1));
525  }
526 
527  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, drawlist[r].startindex, drawlist[r].primitives));
528 
529  V(gameclass->graphics->g_pEffect->EndPass());
530 
531  if (drawlist[r].sec_landform == 255) // flag for RTS grid overlay (stencil)
532  {
533  V(pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_ZERO));
534  // pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL ); // 1 or 0
535  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
536  }
537  }
538 
539  V(gameclass->graphics->g_pEffect->End());
540 
541  logger->AddToCallStack("Viewscreen::OnFrameRender TERRAIN end");
542 
543  V(pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW)); // Far or underside
544 
545  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT );
546  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
547  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
548 
549 
550  // pd3dDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE );
551 
552  //change
553  // pd3dDevice->SetVertexShader( NULL );
554  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
555  V(pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR));
556  V(pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR));
557  V(pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT));
558 
559 
560  // transparency at the end!
561  if (playerships[0].reference != REF_SIMBAY)
562  {
563  V(pd3dDevice->SetFVF(D3DFVF_VERTEX));
564  ptrRenderer->RenderBuildings(pd3dDevice, &fTime, true);
565  }
566 
567 
568 
569  // } //!g_bAboveClouds
570  // Vieneo -----------------------------------------------------------------------------------
571 #pragma endregion
572 
573  logger->AddToCallStack("Viewscreen::OnFrameRender BCL");
574 
575 
576  // @todo he uses fixed-function pipeline still... needs to be converted to a shader so we can get rid of the FFP fog
577 #pragma region BCL Cloud Bases
578  // Lower Cloud Layer ------------------------------------------------------------------------
579 // if (!g_bAboveClouds) // Start setting up in the middle of the cloud layer
580 // {
581 
582  pd3dDevice->SetRenderState(D3DRS_FOGENABLE, true);
583  pd3dDevice->SetRenderState(D3DRS_FOGCOLOR, alphascreen);
584  pd3dDevice->SetRenderState(D3DRS_FOGEND, *reinterpret_cast<DWORD*>(&ptrWeather->fFogEndHorizon));
585 
586 
587  D3DLIGHT9 templight = sunlight;
588  templight.Ambient = sunlight.Diffuse;
589  pd3dDevice->SetLight(0, &templight);
590 
591 
592  const D3DXVECTOR3 offsetClouds = posnorml * min(ptrWeather->GetCloudCeilingMslKm(), cloudTopsMslC);
593  D3DXMatrixTranslation(&matrixWorld,
594  static_cast<float>(playerships[0].precisionx + cloudprecisionx) + offsetClouds.x,
595  static_cast<float>(playerships[0].precisiony + cloudprecisiony) + offsetClouds.y,
596  static_cast<float>(playerships[0].precisionz + cloudprecisionz) + offsetClouds.z);
597 
598  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
599 
600  D3DXMatrixIdentity(&matrixTemp); // declared in d3dutil.h
601  matrixTemp._31 = allobjects[BCLobjC].rotprog;
602  pd3dDevice->SetTransform(D3DTS_TEXTURE0, &matrixTemp);
603  pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_COUNT2);
604 
605  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
606 
607  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
608 
609  //pd3dDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1);
610  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE4X);
611  //pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
612  //pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_CURRENT);
613  //pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
614  //pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
615  pd3dDevice->SetFVF(D3DFVF_LOCALGRID);
616 
617  if (!playerships[0].simulator)
618  {
619  pd3dDevice->SetTexture(0, m_pddsCloudDetailBelow);
620 
621  pd3dDevice->SetIndices(m_aiCloudGrid);
622  pd3dDevice->SetStreamSource(0, m_avCloudGrid, 0, sizeof(D3DLOCALGRID));
623  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR );
624  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR );
625  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_POINT );
626 
627  pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4096, 0, 6002);
628  }
629  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
630  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
631  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
632 
633  pd3dDevice->SetFVF(D3DFVF_VERTEX);
634 
635  pd3dDevice->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE);
636 
637  //pd3dDevice->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
638  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
639 
640  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
641 
642  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, true ); // should be on already
643  pd3dDevice->LightEnable(0, true);
644  pd3dDevice->LightEnable(1, playerships[0].headlight && gameclass->GUI->player[ourcockpit.ourplyrC].frame == 0 && ourcockpit.power > 0.5f); // not interior
645 
646  pd3dDevice->SetRenderState(D3DRS_FOGENABLE, false);
647 
648 #pragma endregion
649 
650  logger->AddToCallStack("Viewscreen::OnFrameRender RTS");
651 
652 #pragma region RTS Grid
653  // RTS grid time! -------------------------------------------------------------------------------
654  //pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // from RTSday
655  //pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
656  //pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // carry through
657  //pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
658 
659  D3DXVECTOR4 clouduv;
660  clouduv.x = -static_cast<float>(BCLoffsetu); // clouds
661  if (!playerships[0].simulator) // this is for the cloud shadow on the ground ... we should skip altogether?
662  clouduv.x += allobjects[BCLobjC].rotprog;
663  clouduv.y = -static_cast<float>(BCLoffsetv); // clouds
664  clouduv.z = 0.0f; // UNUSED
665  clouduv.w = powf(1.0f - sunlight.Diffuse.a, 2.0f); // light blend
666  V(gameclass->graphics->g_pEffect->SetVector("clouduv", &clouduv));
667 
668 
669  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
670  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); // 1
671  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
672 
673  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
674  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);
675  V(pd3dDevice->SetFVF(D3DFVF_VERTEX2));
676 
677  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
678  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
679  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
680 
681  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
682 
683  short oldtexture = -1;
684  for (t = 0; t < buildingVBC; t++)
685  {
686  if (sortme[t].dist >= 99.0f)
687  continue;
688 
689  BUILDZONE buildzone1 = buildzone[sortme[t].buildzone];
690  if (!buildzone1.rtscomponents)
691  continue;
692 
693  ptrRenderer->temp.x = static_cast<float>(buildzone1.u - ptrGrid->tcp.u);
694  ptrRenderer->temp.y = static_cast<float>(buildzone1.v - ptrGrid->tcp.v);
695  D3DXVec2TransformNormal(&ptrRenderer->temp, &ptrRenderer->temp, &matGridRot);
696 
697  ptrRenderer->u = static_cast<short>(ptrRenderer->temp.x) + 31;
698  ptrRenderer->v = static_cast<short>(ptrRenderer->temp.y) + 31;
699  if (ptrRenderer->u >= 0 && ptrRenderer->u < 63 && ptrRenderer->v >= 0 && ptrRenderer->v < 63)
700  {
702  {
703  D3DXMatrixTranslation(&matrixTemp,
704  static_cast<float>(playerships[0].precisionx + static_cast<double>(buildzone1.terpos.x)),
705  static_cast<float>(playerships[0].precisiony + static_cast<double>(buildzone1.terpos.y)),
706  static_cast<float>(playerships[0].precisionz + static_cast<double>(buildzone1.terpos.z)));
707  if (playerships[0].simulator)
708  mWorldViewProj = matrixTemp * matrixView * matrixProjSim;
709  else
710  mWorldViewProj = matrixTemp * matrixLook * matrixProj;
711  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
712  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixTemp));
713 
714 
715  pd3dDevice->SetStreamSource(0, buildzone1.RTSVB, 0, sizeof(D3DVERTEX2));
716 
717  D3DXVECTOR4 features;
718  features.x = 0.0f; // UNUSED
719  features.y = 0.0f; // UNUSED
720  features.z = buildzone1.emissive * clouduv.w; // emissive
721  features.w = 0; // light map flag
722  for (r = 0; r < buildzone1.rtscomponents; r++)
723  {
724  short newTexture = buildzone1.rtscomponentarray[r].texture;
725  if (!newTexture || !m_pddsRTSTexture[newTexture])
726  continue;
727 
728  if (oldtexture != newTexture)
729  {
730  oldtexture = newTexture;
731  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsRTSTexture[oldtexture]));
732 
733  if (!m_pddsRTSLights[oldtexture] || !gridarray[ptrRenderer->u][ptrRenderer->v].powered)
734  {
735  features.w = 0.0f;
736  }
737  else
738  {
739  features.w = 1.0f;
740  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsRTSLights[oldtexture]));
741  }
742  }
743  V(gameclass->graphics->g_pEffect->SetVector("Features", &features));
744 
745  V(gameclass->graphics->g_pEffect->BeginPass(11));
746  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, buildzone1.rtscomponentarray[r].startvertex, buildzone1.rtscomponentarray[r].primitives);
747  V(gameclass->graphics->g_pEffect->EndPass());
748  }
749  }
750  }
751  }
752 
753  V(gameclass->graphics->g_pEffect->End());
754 
755 
756 
757 
758  // pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
759  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL); // 1 or 2
760 
761  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
762  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
763 
764  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
765 
766 
767 #pragma endregion
768 
769 
770  if (playerships[0].simulator)
771  {
772  // here is where we can override the ACL lighting?
773  D3DLIGHT9 templight = sunlight;
774  templight.Ambient.r = templight.Ambient.g = templight.Ambient.b = 1.0f;
775  templight.Diffuse = D3DCOLORVALUE();
776  pd3dDevice->SetLight(0, &templight);
777  }
778  else
779  pd3dDevice->SetLight(0, &sunlight);
780 
781 
782  }
783 
784 
785 
786 
787  logger->AddToCallStack("Viewscreen::OnFrameRender CELEST");
788 
789  // Do all the cellestial objects -----------------------------------------------------------
790  for (t = 0; t < maxstarC; t++)
791  {
792  // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
793  switch (allobjects[t].type)
794  {
795 #pragma region Upper cloud layer
796  case -2: // Upper cloud layer (only drawn where stencil equals 1, smooths the edges ---
797  if (g_bAboveClouds) // Draw only when we are above upper cloud layer, sorted in framemove
798  {
799  // Fix those who are beyond clipping plane
800  result.x = -allobjects[t].matrixWorld._41; // Relative to our position
801  result.y = -allobjects[t].matrixWorld._42; // Relative to our position
802  result.z = -allobjects[t].matrixWorld._43; // Relative to our position
803  f_temp = D3DXVec3Length(&result);
804  if (f_temp > cutplaneC)
805  {
806  f_temp = cutplaneC / f_temp; // If it is 2x as far, this value is 0.5f
807 
808  // Scale apparent scale in matrix
809  D3DXMatrixScaling(&matrixTemp, f_temp, f_temp, f_temp);
810  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &matrixTemp, &allobjects[t].matrixWorld);
811 
812  // Scale location in matrix
813  D3DXVec3Scale(&result, &result, 1.0f - f_temp);
814  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
815  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixWorld, &matrixTemp);
816  }
817 
818 
819 
820  UINT renderpolygons = static_cast<unsigned long>(fabsf(atanf(f_MSL / 1591.0f) / D3DX_HALFPI * 2250.0f)) + 9; // 9 at ground level, 68% at 45°
821  if (renderpolygons > 2250)
822  renderpolygons = 2250;
823 
824 
825  //pd3dDevice->LightEnable(1, false); // on my laptop you could see headlight and weapon
826 
827  D3DXVECTOR4 temp4;
828  temp4.x = alphascreen.r;
829  temp4.y = alphascreen.g;
830  temp4.z = alphascreen.b;
831  temp4.w = alphascreen.a;
832  V(gameclass->graphics->g_pEffect->SetVector("ambient", &temp4));
833 
834  D3DXVECTOR4 Sunlight;
835  Sunlight.x = -sunlight.Direction.x; Sunlight.y = -sunlight.Direction.y; Sunlight.z = -sunlight.Direction.z;
836  Sunlight.w = 1; // no shadow since this is the moon
837  V(gameclass->graphics->g_pEffect->SetVector("Sunlight", &Sunlight));
838 
839 #pragma region Radiosity
840  D3DXVECTOR4 radiosity = D3DXVECTOR4(0, 0, 0, 0);
841  if (!playerships[0].simulator)
842  {
843  /*D3DLIGHT9 templight;
844  ZeroMemory(&templight, sizeof D3DLIGHT9);
845  templight.Type = D3DLIGHT_DIRECTIONAL;*/
846 
847  D3DXVec3Normalize(&result, &allobjects[ourplanetC].position);
848  //templight.Direction = result; // sunlight comes from the moon
849  float radio = D3DXVec3Dot(&Xsunlight, &result); // angular difference
850  if (radio >= 1.0f)
851  f_temp = 0.0f;
852  else if (radio <= -1.0f)
853  f_temp = D3DX_HALFPI;
854  else
855  f_temp = acosf(radio);
856  radio = (D3DX_TAU - f_temp) / D3DX_TAU; // percent of 180° that is visible
857  radio /= 5.0f;
858 
859  radiosity.x = result.x; radiosity.y = result.y; radiosity.z = -result.z;
860  radiosity.w = radio;
861  //templight.Diffuse.r = 0.3525f*radio; templight.Diffuse.g = 0.41f*radio; templight.Diffuse.b = 0.57f*radio;
862  //pd3dDevice->SetLight(2, &templight); // Radiosity
863  //pd3dDevice->LightEnable(2, true);
864  }
865  V(gameclass->graphics->g_pEffect->SetVector("Radiosity", &radiosity));
866 #pragma endregion
867 
868  //pd3dDevice->SetTransform(D3DTS_WORLD, &allobjects[t].matrixWorld);
869  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &allobjects[t].matrixWorld));
870  D3DXMATRIX mWorldViewProj;
871  if (playerships[0].simulator)
872  mWorldViewProj = allobjects[t].matrixWorld * matrixView * matrixProjSim;
873  else
874  mWorldViewProj = allobjects[t].matrixWorld * matrixLook * matrixProj;
875  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
876 
877  pd3dDevice->SetFVF(D3DFVF_VERTEX);
878 
879  D3DXCOLOR tempcolor;
880  if (f_ACL > 500.0f)
881  {
882  if (f_ACL < 1000.0f)
883  tempcolor.a = 1.0f - (f_ACL - 500.0f) / 500.0f;
884  else
885  tempcolor.a = 0.0f;
886  }
887  else
888  tempcolor.a = 1.0f;
889  //tempcolor.r = tempcolor.g = tempcolor.b = 0.5f; // must be 0.5 for the MODULATE2X
890  //pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, tempcolor);
891  temp4.x = 0; // UNUSED
892  temp4.y = 0; // UNUSED
893  temp4.z = 0; // UNUSED
894  temp4.w = tempcolor.a;
895  V(gameclass->graphics->g_pEffect->SetVector("clouduv", &temp4));
896 
897 
898  /*pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
899  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
900  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);*/
901 
902 
903  //pd3dDevice->SetTexture(0, m_pddsCloudDetailAbove);
904  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsCloudDetailAbove));
905 
906 
907 
908 
909  /*pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
910  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
911  pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 1);
912 
913  pd3dDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
914  pd3dDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
915  pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);*/
916 
917  //pd3dDevice->SetTexture(1, m_pddsCloudBaseMap);
918  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsCloudBaseMap));
919 
920  //pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
921  //pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
922  //pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
923 
924 
926  //pd3dDevice->SetTexture(2, nullptr);
927  //pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_MODULATE);
928  //pd3dDevice->SetTextureStageState(2, D3DTSS_COLORARG2, D3DTA_CURRENT);
929  //pd3dDevice->SetTextureStageState(2, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
930 
931 
932  // lessequal seemed to get rid of some artifacts when extremely distant
933  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESSEQUAL);
934 
935  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_EQUAL); // equal to 1
936  // pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
937  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
938 
939  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
940  V(gameclass->graphics->g_pEffect->BeginPass(14)); // cloud tops
941 
942  pd3dDevice->DrawPrimitiveUP(D3DPT_TRIANGLELIST, renderpolygons, polyextras2.vertexbackup, sizeof(D3DVERTEX));
943 
944  V(gameclass->graphics->g_pEffect->EndPass()); // cloud tops
945  V(gameclass->graphics->g_pEffect->End());
946 
947  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL); // only if 0
948  // pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
949  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
950 
951  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
952 
953  //pd3dDevice->LightEnable(2, false);
954 
955  //pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
956  //pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
957  //pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
958  //pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
959  //pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
960  //pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
961 
962 
964  //if (f_ACL > 0.0f && f_ACL < 5000.0f && !playerships[0].simulator) // && lightningabove[s].inuse)
965  //{
966  // /// @todo in theory this only needs to be changed when new lightning above is instantiated and can be done in framemove
967  // D3DSKYRING* vtxs;
968  // // Lock the vertex buffer
969  // V(m_avLightning->Lock(0, 0, reinterpret_cast<void**>(&vtxs), D3DLOCK_DISCARD));
970  // float bright = powf(1.0f - f_ACL / 5000.0f, 2.0f);
971  // for (s = 0; s < ACLlightningC; s++)
972  // {
973  // tempcolor.a = tempcolor.r = tempcolor.g = tempcolor.b = lightningabove[s].intensity*bright;
974 
975  // (*vtxs).x = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 0].x; (*vtxs).y = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 0].y; (*vtxs).z = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 0].z;
976  // (*vtxs).diffuse = tempcolor;
977  // (*vtxs).tu = 0.5f; (*vtxs).tv = 0.0f;
978  // vtxs++;
979  // (*vtxs).x = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 1].x; (*vtxs).y = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 1].y; (*vtxs).z = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 1].z;
980  // (*vtxs).diffuse = tempcolor;
981  // (*vtxs).tu = 1.0f; (*vtxs).tv = 1.0f;
982  // vtxs++;
983  // (*vtxs).x = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 2].x; (*vtxs).y = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 2].y; (*vtxs).z = polyextras2.vertexbackup[lightningabove[s].panel * 3 + 2].z;
984  // (*vtxs).diffuse = tempcolor;
985  // (*vtxs).tu = 0.0f; (*vtxs).tv = 1.0f;
986  // vtxs++;
987  // } // end of lightning loop
988 
989  // V(m_avLightning->Unlock());
990  // pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
991  // pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
992  // pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
993  // pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
994  // pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
995  // pd3dDevice->SetFVF(D3DFVF_SKYRING);
996  // // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
997  // pd3dDevice->SetStreamSource(0, m_avLightning, 0, sizeof(D3DSKYRING));
998 
999  // for (s = 0; s < ACLlightningC; s++)
1000  // {
1001  // pd3dDevice->SetTexture(0, m_pddsLightningAbove[lightningabove[s].texture]);
1002  // pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, s * 3, 1);
1003  // }
1004 
1005  // pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1006  // pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
1007  // pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
1008  //} // end of lightning above
1009 
1010  //pd3dDevice->SetFVF(D3DFVF_VERTEX);
1011 
1013  //pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1014  //pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1015  }
1016  break; // Upper cloud layer
1017 #pragma endregion
1018 
1019 #pragma region Iomere
1020  case -3: // Iomere
1021  if (g_bAboveClouds && !playerships[0].simulator)
1022  {
1023  // Fix those who are beyond clipping plane
1024  result.x = -allobjects[t].matrixWorld._41;
1025  result.y = -allobjects[t].matrixWorld._42;
1026  result.z = -allobjects[t].matrixWorld._43;
1027  f_temp = D3DXVec3Length(&result);
1028  if (f_temp > cutplaneC)
1029  {
1030  f_temp = cutplaneC / f_temp; // If it is 2x as far, this value is 0.5f
1031  //f_temp=0.5f;
1032 
1033  // Scale apparent scale in matrix
1034  D3DXMatrixScaling(&matrixTemp, f_temp, f_temp, f_temp);
1035  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &matrixTemp, &allobjects[t].matrixWorld);
1036 
1037  // Scale location in matrix
1038  D3DXVec3Scale(&result, &result, 1.0f - f_temp);
1039  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
1040  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixWorld, &matrixTemp);
1041  }
1042 
1043 
1044  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
1045  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);
1046 
1047  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); // less than 1
1048  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_REPLACE); // set to 1
1049  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
1050 
1051  pd3dDevice->SetTexture(0, m_pddsWorld2a1);
1052  // pd3dDevice->SetTexture( 1, m_pddsWorld2a1Bump );
1053  // pd3dDevice->SetTexture( 2, NULL );
1054  //pd3dDevice->SetTextureStageState( 1, D3DTSS_TEXCOORDINDEX, 0 );
1055  //pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BUMPENVMAPLUMINANCE);
1056  //pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TEXTURE );
1057  //pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
1058  //pd3dDevice->SetTextureStageState( 1, D3DTSS_BUMPENVMAT00, F2DW(1.0f) );
1059  //pd3dDevice->SetTextureStageState( 1, D3DTSS_BUMPENVMAT01, F2DW(0.0f) );
1060  //pd3dDevice->SetTextureStageState( 1, D3DTSS_BUMPENVMAT10, F2DW(0.0f) );
1061  //pd3dDevice->SetTextureStageState( 1, D3DTSS_BUMPENVMAT11, F2DW(1.0f) );
1062 
1063  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, ptrWeather->dwFogFactorZenith);
1064  pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
1065  pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TFACTOR);
1066  pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
1067 
1068  pd3dDevice->SetTransform(D3DTS_WORLD, &allobjects[t].matrixWorld);
1069  pd3dDevice->SetStreamSource(0, polyobjects[0].VB, 0, sizeof(D3DVERTEX));
1070  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, polyobjects[0].polygons);
1071 
1072  // pd3dDevice->SetTextureStageState( 2, D3DTSS_COLOROP, D3DTOP_DISABLE ); // leave on for static stars
1073  // pd3dDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA );
1074  // pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG1, D3DTA_TFACTOR );
1075  // pd3dDevice->SetTextureStageState( 1, D3DTSS_COLORARG2, D3DTA_CURRENT );
1076  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP);
1077 
1078  // We are assuming that the SetRenderState Lighting FALSE overrides these later
1079  pd3dDevice->LightEnable(1, playerships[0].headlight && gameclass->GUI->player[ourcockpit.ourplyrC].frame == 0 && ourcockpit.power > 0.5f);
1080  }
1081  break;
1082 #pragma endregion
1083 
1084 #pragma region Static Stars
1085  case -5: // Render the static stars -----------------------------------------------------
1086  if (g_bAboveClouds && !playerships[0].simulator)
1087  {
1088  V(pd3dDevice->SetFVF(D3DFVF_STATICSTARS));
1089  pd3dDevice->SetTexture(0, m_pddsStarTexture);
1090  pd3dDevice->SetStreamSource(0, m_avStaticStars, 0, sizeof(D3DSTATICSTARS));
1091 
1092  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); // Always pass
1093  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false); // Don't modify
1094 
1095  D3DXMatrixRotationZ(&matrixTemp, -allobjects[ourmoonC].rotprog); // barycentric
1096  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixBase, &matrixTemp);
1097 
1098  pd3dDevice->SetTransform(D3DTS_WORLD, &allobjects[t].matrixWorld);
1099 
1100  // If it passes, don't change the value from 0 to 1
1101  // still pass only if less than 1
1102  // pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_GREATEREQUAL ); // only if 0
1103  // pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
1104  // pd3dDevice->SetRenderState( D3DRS_STENCILREF, 1 ); // 0 is default
1105 
1106  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, ptrWeather->dwFogFactorZenith);
1107  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1108  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1109  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE); // color of star
1110  pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA); // left on from Iomere
1111  pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TFACTOR); // left on from Iomere
1112  pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT); // left on from Iomere
1113  pd3dDevice->SetTextureStageState(2, D3DTSS_COLOROP, D3DTOP_DISABLE);
1114  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1115  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1116  pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
1117  pd3dDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1118  pd3dDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1119  pd3dDevice->SetSamplerState(1, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
1120  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1121  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_INVDESTCOLOR);
1122  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_DESTCOLOR);
1123  pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
1124 
1125  if (!m_bPsize) // https://jira.risetvp.com/view.php?id=211
1126  {
1127  float psize = 4.0f;
1128  V(pd3dDevice->SetRenderState(D3DRS_POINTSIZE, *reinterpret_cast<DWORD*>(&psize)));
1129  }
1130  pd3dDevice->DrawPrimitive(D3DPT_POINTLIST, 0, starsC);
1131 
1132  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
1133  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1134  // pd3dDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
1135  pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
1136  // pd3dDevice->SetSamplerState( 1, D3DSAMP_MINFILTER, D3DTEXF_POINT );
1137  // pd3dDevice->SetSamplerState( 1, D3DSAMP_MAGFILTER, D3DTEXF_POINT );
1138  // pd3dDevice->SetSamplerState( 1, D3DSAMP_MIPFILTER, D3DTEXF_NONE );
1139  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
1140  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
1141  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
1142  pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
1143 
1144  // Leave off through Yonmara
1145  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, true );
1146  }
1147  break; // Done with static stars --------------------------------------------------------
1148 #pragma endregion
1149 
1150 #pragma region Yonmara
1151  case -7: // Yonmara
1152  if (g_bAboveClouds && !playerships[0].simulator)
1153  {
1154  // Fix those who are beyond clipping plane
1155  result.x = -allobjects[t].matrixWorld._41;
1156  result.y = -allobjects[t].matrixWorld._42;
1157  result.z = -allobjects[t].matrixWorld._43;
1158  f_temp = D3DXVec3Length(&result);
1159  if (f_temp > cutplaneC)
1160  {
1161  f_temp = cutplaneC / f_temp; // If it is 2x as far, this value is 0.5f
1162 
1163  // Scale apparent scale in matrix
1164  D3DXMatrixScaling(&matrixTemp, f_temp, f_temp, f_temp);
1165  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &matrixTemp, &allobjects[t].matrixWorld);
1166 
1167  // Scale location in matrix
1168  D3DXVec3Scale(&result, &result, 1.0f - f_temp);
1169  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
1170  D3DXMatrixMultiply(&allobjects[t].matrixWorld, &allobjects[t].matrixWorld, &matrixTemp);
1171  }
1172 
1173  // Off since static stars
1174  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
1175 
1176 
1177  const short rgb = 255 - static_cast<short>(255.0f * alphascreen.a);
1178  const D3DCOLOR sunblend = D3DCOLOR_XRGB(rgb, rgb, rgb);
1179  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, sunblend);
1180  // but we have to fix based on alphascreen
1181  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TFACTOR);
1182  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
1183  pd3dDevice->SetTransform(D3DTS_WORLD, &allobjects[t].matrixWorld);
1184 
1185 
1186  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1187  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1188 
1189  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1190  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
1191  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
1192 
1193  pd3dDevice->SetFVF(D3DFVF_NONORMAL);
1194  pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
1195 
1196  pd3dDevice->SetStreamSource(0, m_avSunVertices, 0, sizeof(D3DNONORMAL));
1197  pd3dDevice->SetTexture(0, m_pddsSunTexture);
1198  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
1199 
1200  // will be fixed in skyring
1201  // pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW );
1202  // pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, false );
1203 
1204  // pd3dDevice->SetFVF( D3DFVF_VERTEX );
1205 
1206  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1207  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1208 
1209  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
1210  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1211 
1212  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); // only if 0
1213  // pd3dDevice->SetRenderState( D3DRS_STENCILPASS, D3DSTENCILOP_KEEP );
1214  pd3dDevice->SetRenderState(D3DRS_STENCILREF, 2); // 0 is default
1215 
1216  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1217 
1218  // Leave off through skyring
1219  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, true );
1220  // pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, true );
1221  }
1222  break;
1223 #pragma endregion
1224 
1225 #pragma region Skyring
1226  case -9: // Skyring ---------------------------------------------------------------------
1227  if (g_bAboveClouds && !playerships[0].simulator)
1228  {
1230  D3DSKYRING* vtx3;
1231  V(m_avSkyRing->Lock(0, 0, reinterpret_cast<void**>(&vtx3), D3DLOCK_DISCARD));
1232  float bright;
1233 
1234  inner = sinf(ptrWeather->cloudHorizonAngle) * ptrWeather->cloudHorizonDistance - aftersdC; // radius of stencil (2a)
1235  bury = ((f_MSL + radiusC) - ptrWeather->cloudHorizonDistance * cosf(ptrWeather->cloudHorizonAngle)); // difference between 1c and 2b
1236 
1237  const float outer = sinf(ptrWeather->cloudHorizonAngle) * ptrWeather->cloudHorizonDistance + aftersdC; // radius of stencil (2a)
1238  const float upper = -aftersdC * sinf(ptrWeather->cloudHorizonAngle); // upper radius
1239  const float lower = -upper;// aftersdC * sinf(ptrWeather->cloudHorizonAngle);
1240 
1241  D3DXCOLOR tempcolor;
1242  for (s = 0; s < skydomeC; s++)
1243  {
1244  result.x = cosf(radperseg * static_cast<float>(s)) * inner;
1245  result.y = sinf(radperseg * static_cast<float>(s)) * inner;
1246  result.z = lower - bury;
1247  (*vtx3).x = result.x; (*vtx3).y = result.y; (*vtx3).z = result.z;
1248 
1249  D3DXVec3TransformNormal(&result, &result, &matrixLookAtSkydome);
1250  D3DXVec3Normalize(&result, &result);
1251 
1252  f_temp = -D3DXVec3Dot(&result, &Xsunlight) - f_MSL / 70000.0f;
1253  if (f_temp < -0.3f)
1254  bright = 0.0f;
1255  else if (f_temp >= -0.3f && f_temp < 0.0f)
1256  bright = (f_temp + 0.3f) / 0.3f;
1257  else
1258  bright = 1.0f;
1259 
1260  tempcolor.r = ptrWeather->colorhorizon.r * bright;
1261  tempcolor.g = ptrWeather->colorhorizon.g * bright;
1262  tempcolor.b = ptrWeather->colorhorizon.b * bright;
1263  D3DXColorLerp(&tempcolor, &tempcolor, &alphascreen, alphascreen.a);
1264 
1265 
1266  // This is handled by the &sunlight (light 0) ambient color now!
1267  tempcolor.a = 1.0f;//f_temp; // doesn't matter, it gets it from the texture
1268 
1269  (*vtx3).diffuse = tempcolor;
1270  (*vtx3).tu = static_cast<float>(s); (*vtx3).tv = 1.0f;
1271  vtx3++;
1272 
1273  result.x = cosf(radperseg * static_cast<float>(s)) * outer;
1274  result.y = sinf(radperseg * static_cast<float>(s)) * outer;
1275  result.z = upper - bury;
1276  (*vtx3).x = result.x; (*vtx3).y = result.y; (*vtx3).z = result.z;
1277  (*vtx3).diffuse = tempcolor;
1278  (*vtx3).tu = static_cast<float>(s); (*vtx3).tv = 0.0f;
1279  vtx3++;
1280  }
1281  result.x = inner; result.y = 0.0f; result.z = lower - bury;
1282  (*vtx3).x = result.x; (*vtx3).y = result.y; (*vtx3).z = result.z;
1283  (*vtx3).diffuse = tempcolor;
1284  (*vtx3).tu = static_cast<float>(s + 1); (*vtx3).tv = 1.0f;
1285  vtx3++;
1286 
1287  result.x = outer; result.y = 0.0f; result.z = upper - bury;
1288  (*vtx3).x = result.x; (*vtx3).y = result.y; (*vtx3).z = result.z;
1289  (*vtx3).diffuse = tempcolor;
1290  (*vtx3).tu = static_cast<float>(s + 1); (*vtx3).tv = 0.0f;
1291 
1292  V(m_avSkyRing->Unlock());
1293 
1294 
1295  matrixWorld = matrixLookAtSkydome;
1296  matrixWorld._41 = -position.x; matrixWorld._42 = -position.y; matrixWorld._43 = -position.z;
1297 
1298  // Fix those who are beyond clipping plane
1299  f_temp = D3DXVec3Length(&position);
1300  if (f_temp > cutplaneC)
1301  {
1302  f_temp = cutplaneC / f_temp; // If it is 2x as far, this value is 0.5f
1303 
1304  // Scale apparent scale in matrix
1305  D3DXMatrixScaling(&matrixTemp, f_temp, f_temp, f_temp);
1306  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
1307 
1308  // Scale location in matrix closer
1309  D3DXVec3Scale(&result, &position, 1.0f - f_temp);
1310  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
1311  D3DXMatrixMultiply(&matrixWorld, &matrixWorld, &matrixTemp);
1312  }
1313 
1314  // Off since static stars
1315  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, false );
1316  // pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Set in Yonmara
1317  // pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
1318 
1319  pd3dDevice->SetFVF(D3DFVF_SKYRING);
1320  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1321  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1322  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); // MODULATE is default
1323  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // SELECTARG1 is default
1324  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // TEXTURE is default
1325  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1326  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS); // *** COCKPIT ALWAYS
1327 
1328  pd3dDevice->SetTexture(0, m_pddsAtmosphere);
1329  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
1330  pd3dDevice->SetStreamSource(0, m_avSkyRing, 0, sizeof(D3DSKYRING));
1331  // total primitives minus the first two on the strip
1332  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, skydomeC * 2);
1333 
1334  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1335  // pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); benjey2
1336  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
1337  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1338 
1339  // This also fixes for Yonmara
1340  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
1341  pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CW); // Normal
1342  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
1343  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
1344 
1345  }
1346  break; // Skyring -----------------------------------------------------------------------
1347 #pragma endregion
1348  } // End of switch
1349  } // End of loop
1350  // Do all the cellestial objects and docks --------------------------------------------------
1351 
1352 
1353 
1354 
1355  pd3dDevice->SetFVF(D3DFVF_VERTEX);
1356  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1357  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1358  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1359 
1360  // has to be here because otherwise the skyring overwrites them
1361  //if (g_bAboveClouds)
1362  //{
1363  ptrRenderer->RenderDocks(pd3dDevice, &Xsunlight);
1364  //}
1365 
1366 
1367 #ifdef _DEBUG
1368  shipTimer->startTimer();
1369 #endif
1370 
1371  // has to be here because otherwise the skyring overwrites them
1372  ptrRenderer->RenderShips(pd3dDevice, &Xsunlight);
1373 
1374 #ifdef _DEBUG
1375  shipTimer->stopTimer();
1376 #endif
1377 
1378 
1379 
1380 
1381  // Rain
1382  if (raindrops > 0)
1383  {
1384  logger->AddToCallStack("Viewscreen::OnFrameRender RAIN");
1385 
1386  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG2);
1387  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG2);
1388  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
1389 
1390  D3DXMatrixLookAtRH(&matrixTemp, &centerC, &headlightvec, &posnorml); // eye at up
1391  // always oriented to our space
1392 
1393  D3DXMatrixInverse(&matrixWorld, nullptr, &matrixTemp);
1394 
1395  pd3dDevice->SetFVF(D3DFVF_RAINDROP);
1396  pd3dDevice->SetStreamSource(0, m_avRainDrops, 0, sizeof(D3DRAINDROP));
1397  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
1398 
1399  pd3dDevice->LightEnable(1, true);
1400  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
1401 
1402  pd3dDevice->DrawPrimitive(D3DPT_LINELIST, 0, static_cast<unsigned int>(raindrops));
1403 
1404  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1405  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
1406  }
1407 
1408 
1409 
1410 
1411 #ifdef _DEBUG
1412  liteTimer->startTimer();
1413 #endif
1414 
1415  ptrRenderer->RenderLights(pd3dDevice, &fTime);
1416 
1417 #ifdef _DEBUG
1418  liteTimer->stopTimer();
1419 #endif
1420 
1421 
1422 
1423  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
1424 
1425 
1426 
1427  // Technically somehow we should have the sun drawn at this point ideally
1428  if (g_bAboveClouds && m_bDeviceSupportsVizQuery) // test for sun visibility
1429  {
1430  m_pLightSunVizQuery->Issue(D3DISSUE_BEGIN);
1431  pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, 0);
1432 
1433  D3DXMatrixScaling(&matrixTemp, 0.164f, 0.164f, 0.164f);
1434  D3DXMatrixMultiply(&matrixTemp, &matrixTemp, &allobjects[ourstarC].matrixWorld);
1435  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixTemp);
1436 
1437  pd3dDevice->SetFVF(D3DFVF_VERTEX);
1438  pd3dDevice->SetStreamSource(0, polyobjects[0].VB, 0, sizeof(D3DVERTEX));
1439  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, polyobjects[0].polygons);
1440 
1441  pd3dDevice->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_BLUE |
1442  D3DCOLORWRITEENABLE_GREEN |
1443  D3DCOLORWRITEENABLE_RED);
1444 
1445  m_pLightSunVizQuery->Issue(D3DISSUE_END);
1446  }
1447 
1448 
1449 
1450 
1451  // Weapons and BCL lightning and fireworks? Oh my! --------------------------------------------------------------
1452 
1453 
1454  pd3dDevice->SetFVF(D3DFVF_NONORMAL);
1455  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1456  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
1457  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
1458  pd3dDevice->SetStreamSource(0, m_avSunVertices, 0, sizeof(D3DNONORMAL));
1459 
1460 
1461 
1462  // these are used by the explosion not the weapon, weapon is color based blending
1463  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1); // SELECTARG1 is default
1464  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE); // SELECTARG1 is default
1465  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
1466 
1467  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false); // was always before cockpit
1468 
1469  if (!playerships[0].simulator)
1470  ptrWeapon->Render(pd3dDevice, &matrixLookAtLocal);
1471 
1472  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true); // was always before cockpit
1473 
1474 
1475  D3DXMatrixRotationX(&matrixTemp, -D3DX_PI); // 1.5
1476  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixLookAtHorizon);
1477 
1478  D3DXMatrixScaling(&matrixTemp, 0.25f, 0.25f, 0.25f);
1479  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
1480  D3DXMatrixRotationY(&matrixTemp, -D3DX_HALFPI);
1481  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld); // matrixWorld is scaled lookat matrix
1482 
1483  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, false);
1484  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1485 
1486  if (!playerships[0].simulator)
1487  {
1488  // fireworks
1489  for (t = 0; t < fireworksC; t++)
1490  {
1491  if (fireworks[t].inuse)
1492  {
1493  matrixTemp = matrixWorld;
1494 
1495  result = fireworks[t].position - playerships[0].position;
1496  matrixTemp._41 = -result.x;
1497  matrixTemp._42 = -result.y;
1498  matrixTemp._43 = -result.z;
1499 
1500  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixTemp);
1501  float limit;
1502  if (fireworks[t].type == 0)
1503  {
1504  pd3dDevice->SetTexture(0, m_pddsFirework1[fireworks[t].texture]);
1505  limit = (float)fireworks[t].texture / 16.0f;
1506  }
1507  else if (fireworks[t].type == 1)
1508  {
1509  pd3dDevice->SetTexture(0, m_pddsFirework2[fireworks[t].texture]);
1510  limit = (float)fireworks[t].texture / 16.0f;
1511  }
1512  else
1513  {
1514  pd3dDevice->SetTexture(0, m_pddsFirework3[fireworks[t].texture]);
1515  limit = (float)fireworks[t].texture / 16.0f;
1516  }
1517 
1518  D3DXCOLOR tempcolor = 0xFFFFFFFF;
1519  if (limit > 1.0f)
1520  limit = 1.0f;
1521  D3DXColorLerp(&tempcolor, &tempcolor, &fireworks[t].color, limit);
1522  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, tempcolor);
1523  pd3dDevice->SetStreamSource(0, m_avSunVertices, 0, sizeof(D3DNONORMAL));
1525  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
1526  }
1527  }
1528  }
1529 
1530 #ifdef smoketestC
1531  D3DXMatrixScaling(&matrixTemp, 0.03f, 0.03f, 0.03f);
1532  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixLookAtHorizon);
1533  // pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR); // works good for reentry and explosions
1534  // pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE); // works good for reentry and explosions
1535  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); // for smoke
1536  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA); // for smoke
1537  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
1538  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1539  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
1540  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
1541 
1542 
1543  // smoke trails
1544  for (t = 0; t < MAX_WEAPONS; t++)
1545  {
1546  if (weaponarray[t].active)
1547  {
1548  for (s = 0; s < smoketrailC; s++)
1549  // for (s=(smoketrailC-1); s>-1; s--)
1550  {
1551  if (weaponarray[t].smoketrail[s].animate < smoketrailC)
1552  {
1553  matrixTemp = matrixWorld; // reset to scaled lookat matrix
1554  result.x = (float)(weaponarray[t].precisionx - playerships[0].precisionx) - weaponarray[t].smoketrail[s].offset.x;
1555  result.y = (float)(weaponarray[t].precisiony - playerships[0].precisiony) - weaponarray[t].smoketrail[s].offset.y;
1556  result.z = (float)(weaponarray[t].precisionz - playerships[0].precisionz) - weaponarray[t].smoketrail[s].offset.z;
1557  matrixTemp._41 = -result.x;
1558  matrixTemp._42 = -result.y;
1559  matrixTemp._43 = -result.z;
1560 
1561  if (f_MSL < 63.0f)
1562  {
1563  r = (int)(192.0f * (fFogEndHorizon - D3DXVec3Length(&result)) / (fFogEndHorizon - fFogStartHorizon));
1564  if (r < 0)
1565  r = 0;
1566  else if (r > 192)
1567  r = 192;
1568  }
1569  else
1570  r = 192;
1571  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, r << 24);
1572 
1573  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixTemp);
1574  pd3dDevice->SetTexture(0, m_pddsSmoke[weaponarray[t].smoketrail[s].animate]);
1575 
1576  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
1577  }
1578  }
1579  }
1580  }
1581 
1582 
1583 #endif
1584  // put back from the way it handled explosions to just handle lightning
1585  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_BLENDFACTORALPHA);
1586  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
1587  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
1588 
1589 
1590  // Lightning below first because it is more distant
1591  if (!playerships[0].simulator && lightningbelow.inuse && !g_bAboveClouds)
1592  {
1594  const float height = D3DXVec3Length(&result);
1595  const float width = height * 0.5f;
1596 
1597  D3DXMatrixRotationZ(&matrixTemp, -D3DX_PI); // 1.5
1598  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixLookAtHorizon);
1599  D3DXMatrixScaling(&matrixTemp, width, width, width);
1600  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
1601  D3DXMatrixRotationY(&matrixTemp, D3DX_HALFPI); // rotate 90° left
1602  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld); // matrixWorld is scaled lookat matrix
1603 
1604  const D3DXVECTOR3 lightningCg = (lightningbelow.groundpos + lightningbelow.cloudpos) * 0.5f;
1605  result = lightningCg - playerships[0].position;
1606  matrixWorld._41 = -result.x;
1607  matrixWorld._42 = -result.y;
1608  matrixWorld._43 = -result.z;
1609 
1610  float alphafog;
1611  if (f_MSL < 63.0f)
1612  {
1613  const float dist = D3DXVec3Length(&result);
1615  if (alphafog < 0)
1616  alphafog = 0;
1617  else if (alphafog > 1)
1618  alphafog = 1;
1619  }
1620  else
1621  alphafog = 1;
1622  r = static_cast<short>(alphafog * 255.0f);
1623  if (r > 0)
1624  {
1625  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, r << 24);
1626 
1627 
1628 
1629  //pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
1630 
1631 
1632  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
1633  pd3dDevice->SetTexture(0, m_pddsLightningBelow[lightningbelow.texture]);
1634  pd3dDevice->SetStreamSource(0, m_avSunVertices, 0, sizeof(D3DNONORMAL));
1635  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
1636 
1637  //pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1638  }
1639  }
1640 
1641 
1642  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1643  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
1644  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1645  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
1646  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
1647  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TFACTOR);
1648  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1649  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1650 
1651 
1652 
1653 #ifdef treetestC
1654  // inserted for trees
1655  if (f_ACL < 0.0f)
1656  {
1657  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
1658  pd3dDevice->SetRenderState(D3DRS_AMBIENT, (D3DXCOLOR)sunlight.Diffuse); // for continuing ground render
1659  pd3dDevice->SetStreamSource(0, m_avTree, 0, sizeof(D3DNONORMAL));
1660  float width = 0.030f;
1661 
1662  D3DXMatrixRotationZ(&matrixTemp, -D3DX_PI); // 1.5
1663  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixLookAtHorizon);
1664  D3DXMatrixScaling(&matrixTemp, width, width, width);
1665  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
1666  D3DXMatrixRotationY(&matrixTemp, D3DX_HALFPI); // rotate 90° left
1667  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld); // matrixWorld is scaled lookat matrix
1668 
1669  for (t = 0; t < treesC; t++)
1670  {
1671  matrixWorld._41 = -treepos[t].x;
1672  matrixWorld._42 = -treepos[t].y;
1673  matrixWorld._43 = -treepos[t].z;
1674 
1675  //sprintf_s(msg, sizeof(msg), "t%i s%i x%f y%f z%f", t, s, result.x, result.y, result.z );
1676  //_write(logfile, msg, strlen(msg));
1677 
1678  if (f_MSL < 63.0f)
1679  {
1680  f_temp = (4.0f - treedist[t]) / (4.0f - 1.0f);
1681  if (f_temp > 1.0f)
1682  f_temp = 1.0f;
1683  else if (f_temp < 0.0f)
1684  f_temp = 0.0f;
1685  r = (int)(255.0f * f_temp * (fFogEndHorizon - treedist[t]) / (fFogEndHorizon));
1686  if (r < 0)
1687  r = 0;
1688  else if (r > 255)
1689  r = 255;
1690  }
1691  else
1692  r = 255;
1693 
1694  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, r << 24);
1695 
1696 
1697  // may not be necessary now
1698 // pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
1699 
1700 // pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS );
1701 
1702  pd3dDevice->SetTransform(D3DTS_WORLD, &matrixWorld);
1703  pd3dDevice->SetTexture(0, m_pddsTree);
1704  // pd3dDevice->SetTexture( 0, m_pddsLightningBelow[0] );
1705  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
1706 
1707  // pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_LESS );
1708 
1709  // may not be necessary now
1710  // pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_CW ); // normal
1711  }
1712  pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
1713  }
1714 
1715 #endif
1716 
1717 
1718 
1719 
1720 
1721  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
1722  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
1723 
1724  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
1725  // pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
1726  pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1727  pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1728  pd3dDevice->SetRenderState(D3DRS_ZWRITEENABLE, true);
1729 
1730  // pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, false );
1731  // pd3dDevice->SetFVF( D3DFVF_VERTEX );
1732  // Weapons ----------------------------------------------------------------------------------
1733 
1734 
1735  // pd3dDevice->SetRenderState( D3DRS_LIGHTING, false ); // should still be false from lights.coo
1736 
1737 
1738 
1739 
1740 
1741 
1742  // sprintf_s(msg, sizeof(msg), "Narrow down 5" );
1743  // _write(logfile, msg, strlen(msg));
1744 
1745 
1746  // this takes care of the case when we are in the clouds
1747  // normally we use the windshield glass for this but in the simulator that won't work
1748  /*
1749  if (outside || playerships[0].simulator)
1750  {
1751  // need to impede visibility like we do with the windshield
1753  if (alphascreen.a > 0.0f)
1754  {
1755  pd3dDevice->SetFVF(D3DFVF_SCREEN);
1756 
1757  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
1758  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TFACTOR);
1759  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
1760  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TFACTOR);
1761 
1762  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, alphascreen);
1763 
1764  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1765  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1766  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1767 
1768  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
1769  //pd3dDevice->SetRenderState( D3DRS_STENCILREF, 4); // 0 is default
1770  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); // was always before cockpit
1771  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // with 2
1772 
1774  D3DSCREEN* vtxs;
1775  // tempcolor=D3DCOLOR_ARGB( (int)(betascreen.a*255.0f), (int)(betascreen.r*255.0f), (int)(betascreen.g*255.0f), (int)(betascreen.b*255.0f) );
1776  // Lock the vertex buffer
1777  V(m_avScreen->Lock(0, 0, reinterpret_cast<void**>(&vtxs), D3DLOCK_DISCARD));
1778 
1779  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = 0.0f; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
1780  (*vtxs).diffuse = 0;
1781  vtxs++;
1782  (*vtxs).x = 0.0f; (*vtxs).y = 0.0f; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
1783  (*vtxs).diffuse = 0;
1784  vtxs++;
1785  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
1786  (*vtxs).diffuse = 0;
1787  vtxs++;
1788  (*vtxs).x = 0.0f; (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
1789  (*vtxs).diffuse = 0;
1790 
1791  V(m_avScreen->Unlock());
1792 
1793 
1794  pd3dDevice->SetStreamSource(0, m_avScreen, 0, sizeof D3DSCREEN);
1795  pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
1796 
1797 
1798  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
1799  pd3dDevice->SetFVF(D3DFVF_VERTEX);
1800  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
1801  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
1802 
1803  // pd3dDevice->SetRenderState( D3DRS_ZFUNC, D3DCMP_ALWAYS ); // corrected after 2nd half of condition
1804  // pd3dDevice->SetRenderState( D3DRS_STENCILFUNC, D3DCMP_ALWAYS ); // this is how we want it after 2nd
1805 
1806  }
1807  }
1808  */
1809 #pragma endregion
1810  }
1811 
1812  // so outside view is done at this point
1813 
1814  // Switch rendertarget
1815  if (playerships[0].simulator)
1816  {
1817  logger->AddToCallStack("Viewscreen::OnFrameRender SIM");
1818 
1819  if (gameclass->bus->FlightFreeze)
1820  {
1821  RECT readloc;
1822  readloc.top = readloc.left = 0;
1823  readloc.right = 1135;
1824  readloc.bottom = 388;
1825  m_spriteVector->Begin(D3DXSPRITE_ALPHABLEND);
1826  m_pFont->DrawTextW(m_spriteVector, L"FLIGHT FREEZE", -1, &readloc, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);
1827  m_spriteVector->End();
1828  }
1829 
1830  // swap rendertargets
1831  V(m_pRenderToSurfaceNextGen->EndScene(0)); // projection screen
1832  gameclass->beginScene = 0;
1833 
1834  V(pd3dDevice->BeginScene());
1835  gameclass->beginScene = 1; // prim is 1
1836 
1837  V(pd3dDevice->Clear(0, NULL, D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL | D3DCLEAR_TARGET, 0L, 1.0f, 0));
1838  pd3dDevice->SetFVF(D3DFVF_VERTEX);
1839  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
1840  pd3dDevice->SetTransform(D3DTS_VIEW, &matrixLook);
1841  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
1842 
1843  ptrCockpit->Render(pd3dDevice);
1844  }
1845 
1846  if (!dead || playerships[0].simulator) // need to keep drawing the windshield and freaking HUD!
1847  {
1848  logger->AddToCallStack("Viewscreen::OnFrameRender ALPHA");
1849 
1850  pd3dDevice->SetFVF(D3DFVF_VERTEX);
1851  pd3dDevice->SetStreamSource(0, polyobjects[5].VB, 0, sizeof(D3DVERTEX));
1852  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
1853  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
1854  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
1855 
1856  if (!playerships[0].simulator)
1857  {
1858  pd3dDevice->SetRenderState(D3DRS_STENCILREF, 4); // 0 is default
1859  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // with 2
1860  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER); // 0-2
1861  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
1862  }
1863  else
1864  {
1865  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
1866  }
1867 
1868 
1869  if (!outside && !playerships[0].simulator)
1870  {
1871  // Cockpit ------------------------------------------------------------------------------------
1872  // what this actually does is hazing of the window when in clouds, st. elmo's fire, reentry
1873 #pragma region Windshield1
1874  logger->AddToCallStack("Viewscreen::OnFrameRender WS1");
1875 
1876 
1877  D3DXVECTOR4 clouduv = D3DXVECTOR4(0, 0, 0, 0);
1878  D3DXVECTOR4 feature = D3DXVECTOR4(0, 0, 0, 0);
1879  if (alphascreen.a > 0.0f) // has to stay on for st. elmo's fire
1880  {
1881  clouduv.x = 1.0f; // mode 1 is clouds
1882  //clouduv.y = alphascreen.a; // unused
1883  D3DXVECTOR4 ambient = D3DXVECTOR4(alphascreen.r, alphascreen.g, alphascreen.b, ptrWeather->fFogEndHorizon);
1884  V(gameclass->graphics->g_pEffect->SetVector("ambient", &ambient));
1885  }
1886  else if (gammascreen.w > 0.0f)
1887  {
1888  clouduv.x = 2.0f; // mode 2 is reentry
1889  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsReentry));
1890  clouduv.y = gammascreen.w; // opacity
1891  clouduv.z = static_cast<float>(gammascreen.x) / 63.0f; // depth layer of volumetric file
1892  }
1893 
1894  if (clouduv.x > 0.0f) // has a mode
1895  {
1896  if ((ptrPropulsion->staticBuildup > 1.0f || ptrWeather->elmoOverride) && clouduv.x == 1.0f)
1897  {
1898  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsElmo[rand() % 4]));
1899 
1900  if (ourcockpit.texturelib == E10 || ourcockpit.texturelib == E11) // E-10 or E-11 are same
1901  {
1902  if (rand() % 2 == 0)
1903  {
1904  clouduv.w = 1.0f; // St. Elmo's Fire to right
1905  feature.x = 1066.0f / 2048.0f; feature.y = 491.0f / 1024.0f;
1906  feature.z = 1326.0f / 2048.0f; feature.w = 746.0f / 1024.0f;
1907  }
1908  else
1909  {
1910  clouduv.w = -1.0f; // St. Elmo's Fire to left
1911  feature.x = 716.0f / 2048.0f; feature.y = 491.0f / 1024.0f;
1912  feature.z = 982.0f / 2048.0f; feature.w = 746.0f / 1024.0f;
1913  }
1914  }
1915  else if (ourcockpit.texturelib == A4)
1916  {
1917  if (rand() % 2 == 0)
1918  {
1919  clouduv.w = 1.0f; // St. Elmo's Fire to right
1920  feature.x = 48.0f / 1024.0f; feature.y = 311.0f / 1024.0f;
1921  feature.z = 208.0f / 1024.0f; feature.w = 471.0f / 1024.0f;
1922  }
1923  else
1924  {
1925  clouduv.w = -1.0f; // St. Elmo's Fire to left
1926  feature.x = 411.0f / 1024.0f; feature.y = 311.0f / 1024.0f;
1927  feature.z = 571.0f / 1024.0f; feature.w = 471.0f / 1024.0f;
1928  }
1929  }
1930  else if (ourcockpit.texturelib == P13)
1931  {
1932  if (rand() % 2 == 0)
1933  {
1934  clouduv.w = 1.0f; // St. Elmo's Fire to right
1935  feature.x = 1348.0f / 2048.0f; feature.y = 423.0f / 1024.0f;
1936  feature.z = 1568.0f / 2048.0f; feature.w = 642.0f / 1024.0f;
1937  }
1938  else
1939  {
1940  clouduv.w = -1.0f; // St. Elmo's Fire to left
1941  feature.x = 504.0f / 2048.0f; feature.y = 423.0f / 1024.0f;
1942  feature.z = 723.0f / 2048.0f; feature.w = 642.0f / 1024.0f;
1943  }
1944  }
1945  else if (ourcockpit.texturelib == W6Manx)
1946  {
1947  if (rand() % 2 == 0)
1948  {
1949  clouduv.w = 1.0f; // St. Elmo's Fire to right
1950  feature.x = 1048.0f / 2048.0f; feature.y = 434.5f / 1024.0f;
1951  feature.z = 1303.0f / 2048.0f; feature.w = 689.5f / 1024.0f;
1952  }
1953  else
1954  {
1955  clouduv.w = -1.0f; // St. Elmo's Fire to left
1956  feature.x = 745.0f / 2048.0f; feature.y = 434.5f / 1024.0f;
1957  feature.z = 1000.0f / 2048.0f; feature.w = 689.5f / 1024.0f;
1958  }
1959  }
1960  else if (ourcockpit.texturelib == T19)
1961  {
1962  if (rand() % 2 == 0)
1963  {
1964  clouduv.w = 1.0f; // St. Elmo's Fire to right
1965  feature.x = 1066.0f / 2048.0f; feature.y = 491.0f / 1024.0f;
1966  feature.z = 1326.0f / 2048.0f; feature.w = 746.0f / 1024.0f;
1967  }
1968  else
1969  {
1970  clouduv.w = -1.0f; // St. Elmo's Fire to left
1971  feature.x = 746.0f / 2048.0f; feature.y = 491.0f / 1024.0f;
1972  feature.z = 1012.0f / 2048.0f; feature.w = 746.0f / 1024.0f;
1973  }
1974  }
1975 
1976  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
1977  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCCOLOR);
1978 
1979 
1980  // Features are currently only used by pass 9 for st. elmo
1981  V(gameclass->graphics->g_pEffect->SetVector("Features", &feature));
1982  }
1983 
1984  V(gameclass->graphics->g_pEffect->SetVector("clouduv", &clouduv));
1985  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
1986  V(gameclass->graphics->g_pEffect->BeginPass(9)); // windshield
1987 
1988  for (s = 0; s < ourcockpit.components; s++)
1989  {
1990  if (ourcockpit.componentarray[s].type == 5) // windshield
1991  {
1992  D3DXMATRIX mWorldViewProj = ourcockpit.componentarray[s].matWorld * matrixLook * matrixProjCock;
1993  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
1994  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &ourcockpit.componentarray[s].matWorld));
1995 
1996  V(gameclass->graphics->g_pEffect->CommitChanges());
1997 
1998  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, ourcockpit.componentarray[s].startvertex, ourcockpit.componentarray[s].primitives));
1999  }
2000  }
2001 
2002  V(gameclass->graphics->g_pEffect->EndPass());
2003  V(gameclass->graphics->g_pEffect->End());
2004 
2006  {
2007  ptrPropulsion->staticBuildup = 0.0f;
2008 
2009  // restore
2010  if (clouduv.x == 1.0f)
2011  {
2012  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2013  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
2014  }
2015  }
2016  }
2017 
2018 #pragma endregion
2019  }
2020 
2021 
2022  pd3dDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
2023  pd3dDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
2024 
2025  pd3dDevice->SetRenderState(D3DRS_LIGHTING, true);
2026 
2027 
2028  if (!outside)
2029  {
2030 #pragma region Windshield2
2031  logger->AddToCallStack("Viewscreen::OnFrameRender WS2");
2032 
2033  D3DXVECTOR4 radiosity = D3DXVECTOR4(0, 0, 0, 0);
2034  D3DXVECTOR4 Sunlight = D3DXVECTOR4(0, 0, 0, 0);
2035  D3DXVECTOR4 ambient = D3DXVECTOR4(0, 0, 0, 0);
2036  if (g_bAboveClouds)
2037  {
2038  // Block light from sun by Vieneo
2039  if (ptrWeather->shadow > 0.0f)
2040  {
2041  // radiosity
2042  D3DXVec3Scale(&vieneohit, &Xsunlight, radiusC); // Where it hits Vieneo
2043  D3DXVec3Subtract(&result, &playerships[0].position, &vieneohit); // Vector from surface point to this object
2044  D3DXVec3Normalize(&result, &result);
2045  radiosity.x = result.x; radiosity.y = result.y; radiosity.z = result.z;
2046  radiosity.w = fabsf(D3DXVec3Dot(&result, &Xsunlight)); // cos of angle between the two
2047  radiosity.w = 1.0f - radiosity.w; // Compliment, not comparing to surface normal ya know
2048  radiosity.w /= powf(D3DXVec3Length(&playerships[0].position) / radiusC, 2.0f);
2049  }
2050 
2051  // Adjust diffuse by shadow
2052  Sunlight.x = -sunlight.Direction.x; Sunlight.y = -sunlight.Direction.y; Sunlight.z = -sunlight.Direction.z;
2053  Sunlight.w = ptrWeather->shadow * (1.0f - alphascreen.a); // only ambient can get through clouds and objects
2054 
2055 
2056  if (f_ACL <= 0.150f) // in or below clouds
2057  {
2058  // I think Ambient is 0 prior to this point
2059  ambient.x = sunlight.Diffuse.r * alphascreen.a;
2060  ambient.y = sunlight.Diffuse.g * alphascreen.a;
2061  ambient.z = sunlight.Diffuse.b * alphascreen.a;
2062  }
2063 
2064  if (playerships[0].domelight || gameclass->GUI->player[ourcockpit.ourplyrC].frame > 0)
2065  {
2066  float mod = 1.0f;
2067  if (ourcockpit.power < 1.0f && gameclass->GUI->player[ourcockpit.ourplyrC].frame == 0)
2068  mod = ourcockpit.power;
2069 
2070  ambient.x += 191.0f / 255.0f * mod * (1.0f - ambient.x);
2071  ambient.y += 181.0f / 255.0f * mod * (1.0f - ambient.y);
2072  ambient.z += 168.0f / 255.0f * mod * (1.0f - ambient.z);
2073  }
2074  }
2075  else // BCL
2076  {
2077  // Adjust diffuse
2078  ambient.x = sunlight.Diffuse.r;
2079  ambient.y = sunlight.Diffuse.g;
2080  ambient.z = sunlight.Diffuse.b;
2081 
2082  if (playerships[0].domelight || gameclass->GUI->player[ourcockpit.ourplyrC].frame > 0)
2083  {
2084  float mod = 1.0f;
2085  if (ourcockpit.power < 1.0f && gameclass->GUI->player[ourcockpit.ourplyrC].frame == 0)
2086  mod = ourcockpit.power;
2087 
2088  ambient.x += 191.0f / 255.0f * mod * (1.0f - ambient.x);
2089  ambient.y += 181.0f / 255.0f * mod * (1.0f - ambient.y);
2090  ambient.z += 168.0f / 255.0f * mod * (1.0f - ambient.z);
2091  }
2092  }
2093 
2094  if (ourcockpit.vdat.holiday > 0)
2095  {
2096  ambient.w = static_cast<float>(ourcockpit.vdat.holiday) / 127.0f;
2097  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap2", m_pddsHolidayTexture));
2098  }
2099 
2100  V(gameclass->graphics->g_pEffect->SetVector("Radiosity", &radiosity));
2101  V(gameclass->graphics->g_pEffect->SetVector("Sunlight", &Sunlight));
2102  V(gameclass->graphics->g_pEffect->SetVector("ambient", &ambient));
2103 
2104 
2105  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
2106  V(gameclass->graphics->g_pEffect->BeginPass(8)); // windshield
2107 
2108 
2109  // Do the actual glass and dirt now, alpha blended ------------------------------
2110  for (s = 0; s < ourcockpit.components; s++)
2111  {
2112  if (ourcockpit.componentarray[s].type == 5) // windshield
2113  {
2114  //pd3dDevice->SetTransform(D3DTS_WORLD, &ourcockpit.componentarray[s].matWorld);
2115  D3DXMATRIX mWorldViewProj = ourcockpit.componentarray[s].matWorld * matrixLook * matrixProjCock;
2116  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
2117  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &ourcockpit.componentarray[s].matWorld));
2118 
2119  //pd3dDevice->SetTexture(1, m_pddsCockpitTexture[ourcockpit.componentarray[s].texture]);
2121 
2122  V(gameclass->graphics->g_pEffect->CommitChanges());
2123 
2124  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, ourcockpit.componentarray[s].startvertex, ourcockpit.componentarray[s].primitives));
2125  }
2126  }
2127 
2128  V(gameclass->graphics->g_pEffect->EndPass());
2129  V(gameclass->graphics->g_pEffect->End());
2130 
2131 #pragma endregion
2132 
2133  V(pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS));
2134 
2135 
2136 #pragma region HUD
2137  logger->AddToCallStack("Viewscreen::OnFrameRender HUD");
2138 
2139 
2140  // gray background mostly transparent in dark, mostly opaque in light
2141  V(gameclass->graphics->g_pEffect->SetVector("Radiosity", &radiosity));
2142  V(gameclass->graphics->g_pEffect->SetVector("Sunlight", &Sunlight));
2143  V(gameclass->graphics->g_pEffect->SetVector("ambient", &ambient));
2144 
2145  V(gameclass->graphics->g_pEffect->Begin(NULL, 0));
2146  V(gameclass->graphics->g_pEffect->BeginPass(13)); // windshield
2147 
2148  for (s = 0; s < ourcockpit.components; s++)
2149  {
2150  if (ourcockpit.componentarray[s].type == 51 || ourcockpit.componentarray[s].type == 251) // HUDs
2151  {
2152  // If it is attached... rotate to correct orientation
2153  D3DXMatrixRotationYawPitchRoll(&matrixWorld, ourcockpit.componentarray[s].nominalypr.x, ourcockpit.componentarray[s].nominalypr.y, ourcockpit.componentarray[s].nominalypr.z);
2154 
2155  if (ourcockpit.componentarray[s].type == 251) // HUD that moves with pitch
2156  {
2157  // Animated extensions...
2158  D3DXVec3Scale(&result, &ourcockpit.componentarray[s].extendby, 0.5f - gameclass->viewscreen->pitchInput * 0.5f);
2159  D3DXVec3Add(&result, &ourcockpit.componentarray[s].nominalxyz, &result);
2160  result -= ourcockpit.position;
2161  }
2162  else if (ourcockpit.componentarray[s].extendby.x != 0.0f ||
2163  ourcockpit.componentarray[s].extendby.y != 0.0f ||
2164  ourcockpit.componentarray[s].extendby.z != 0.0f ||
2166  {
2167  // If it is attached... move to correct location
2169 
2170  // Animated rotations...
2171  D3DXMatrixTranslation(&matrixTemp, -ourcockpit.componentarray[s].hingeCG.x, -ourcockpit.componentarray[s].hingeCG.y, -ourcockpit.componentarray[s].hingeCG.z);
2172  matrixWorld = matrixWorld * matrixTemp;
2173  D3DXMatrixRotationAxis(&matrixTemp, &ourcockpit.componentarray[s].hingeaxis, ourcockpit.componentarray[s].extended * ourcockpit.componentarray[s].hingeextent);
2174  matrixWorld = matrixWorld * matrixTemp;
2175 
2176  // Animated extensions...
2177  D3DXVec3Scale(&result, &ourcockpit.componentarray[s].extendby, ourcockpit.componentarray[s].extended);
2178  D3DXVec3Add(&result, &ourcockpit.componentarray[s].nominalxyz, &result);
2179  result += ourcockpit.componentarray[s].hingeCG;
2180 
2181  result -= ourcockpit.position;
2182  }
2183  else
2185  D3DXMatrixTranslation(&matrixTemp, result.x, result.y, result.z);
2186  matrixWorld = matrixWorld * matrixTemp;
2187 
2188  D3DXMatrixRotationX(&matrixTemp, D3DX_HALFPI); // pitch
2189  matrixWorld = matrixWorld * matrixTemp;
2190  D3DXMatrixRotationY(&matrixTemp, D3DX_PI); // pitch
2191  matrixWorld = matrixWorld * matrixTemp;
2192 
2193 
2194  D3DXMatrixInverse(&matrixTemp, nullptr, &matrixView);
2195  matrixWorld = matrixWorld * matrixTemp;
2196 
2197  if (ourcockpit.power >= 0.75f + 0.1f * RandomFloat() - 0.05f)
2198  {
2199  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", m_pddsDynamicTexture));
2200  }
2201  else
2202  {
2203  V(gameclass->graphics->g_pEffect->SetTexture("ColorMap", nullptr));
2204  }
2205 
2206  D3DXMATRIX mWorldViewProj = matrixWorld * matrixLook * matrixProjCock;
2207  V(gameclass->graphics->g_pEffect->SetMatrix("matWorldViewProj", &mWorldViewProj));
2208  V(gameclass->graphics->g_pEffect->SetMatrix("matWorld", &matrixWorld));
2209 
2210  V(gameclass->graphics->g_pEffect->CommitChanges());
2211 
2212  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, ourcockpit.componentarray[s].startvertex, ourcockpit.componentarray[s].primitives));
2213  }
2214  }
2215 
2216  V(gameclass->graphics->g_pEffect->EndPass());
2217  V(gameclass->graphics->g_pEffect->End());
2218 
2219 #pragma endregion
2220 
2221 
2222  // restore
2223  pd3dDevice->SetLight(0, &sunlight);
2224  pd3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR, 0x80606060);
2225  if (g_bAboveClouds)
2226  {
2227  // Restore
2228  if (ptrWeather->shadow > 0.0f)
2229  pd3dDevice->LightEnable(2, false);
2230  }
2231 
2232  pd3dDevice->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
2233  pd3dDevice->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_POINT);
2234  // --- End of Cockpit --------------------------------------
2235  }
2236 
2237  if (playerships[0].simulator)
2238  pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrixProjSim);
2239  else
2240  pd3dDevice->SetTransform(D3DTS_PROJECTION, &matrixProj);
2241  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS);
2242 
2243 #pragma region Binoculars or Sunglasses Overlay
2244  if (ourcockpit.inventoryItemInUseType == KitType::Sunglasses)
2245  {
2246  logger->AddToCallStack("Viewscreen::OnFrameRender SHADES");
2247 
2249  D3DINSTRUMENT* vtxs;
2250  V(m_avInstrument->Lock(0, 0, reinterpret_cast<void**>(&vtxs), D3DLOCK_DISCARD));
2251 
2252  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = 0.0f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2253  (*vtxs).tu = 1.0f; (*vtxs).tv = 0.0f;
2254  vtxs++;
2255  (*vtxs).x = 0.0f; (*vtxs).y = 0.0f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2256  (*vtxs).tu = 0.0f; (*vtxs).tv = 0.0f;
2257  vtxs++;
2258  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2259  (*vtxs).tu = 1.0f; (*vtxs).tv = 1.0f;
2260  vtxs++;
2261  (*vtxs).x = 0.0f; (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2262  (*vtxs).tu = 0.0f; (*vtxs).tv = 1.0f;
2263 
2264  V(m_avInstrument->Unlock());
2265 
2266  V(pd3dDevice->SetFVF(D3DFVF_INSTRUMENT));
2267  V(pd3dDevice->SetStreamSource(0, m_avInstrument, 0, sizeof(D3DINSTRUMENT)));
2268 
2269  V(pd3dDevice->SetTexture(0, m_pddsSunglasses));
2270 
2271  V(pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
2272  V(pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
2273  V(pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
2274 
2275  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1));
2276  V(pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS));
2277 
2278  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2));
2279 
2280  V(pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS));
2281  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE));
2282  }
2283  else if (ourcockpit.inventoryItemInUseType == KitType::Binoculars && !outside)
2284  {
2285  logger->AddToCallStack("Viewscreen::OnFrameRender BINOC");
2286 
2288  D3DINSTRUMENT* vtxs;
2289  V(m_avInstrument->Lock(0, 0, reinterpret_cast<void**>(&vtxs), D3DLOCK_DISCARD));
2290 
2291  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = 0.0f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2292  (*vtxs).tu = 1.0f; (*vtxs).tv = 0.0f;
2293  vtxs++;
2294  (*vtxs).x = -1.0f; (*vtxs).y = 0.0f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2295  (*vtxs).tu = 0.0f; (*vtxs).tv = 0.0f;
2296  vtxs++;
2297  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2298  (*vtxs).tu = 1.0f; (*vtxs).tv = 1.0f;
2299  vtxs++;
2300  (*vtxs).x = -1.0f; (*vtxs).y = static_cast<float>(pp->Height); (*vtxs).z = 0.0f; (*vtxs).w = 1.0f;
2301  (*vtxs).tu = 0.0f; (*vtxs).tv = 1.0f;
2302  vtxs++;
2303 
2304  const float stripOffset = lookhdg / 360.0f + 0.05f;
2305  (*vtxs).x = static_cast<float>(pp->Width) * 0.7f; (*vtxs).y = static_cast<float>(pp->Height) * 0.021f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // top right
2306  (*vtxs).tu = 0.78f + stripOffset; (*vtxs).tv = 0.0f;
2307  vtxs++;
2308  (*vtxs).x = static_cast<float>(pp->Width) * 0.3f; (*vtxs).y = static_cast<float>(pp->Height) * 0.021f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // top left
2309  (*vtxs).tu = 0.0f + stripOffset; (*vtxs).tv = 0.0f;
2310  vtxs++;
2311  (*vtxs).x = static_cast<float>(pp->Width) * 0.7f; (*vtxs).y = static_cast<float>(pp->Height) * 0.061f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // lower right
2312  (*vtxs).tu = 0.78f + stripOffset; (*vtxs).tv = 1.0f;
2313  vtxs++;
2314  (*vtxs).x = static_cast<float>(pp->Width) * 0.3f; (*vtxs).y = static_cast<float>(pp->Height) * 0.061f; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // lower left
2315  (*vtxs).tu = 0.0f + stripOffset; (*vtxs).tv = 1.0f;
2316  vtxs++;
2317 
2318  const float arrowOffset = (lookAzimuthDegrees / 90.0f * 244.0f + 511.0f) * static_cast<float>(pp->Height) / 1024.0f;
2319  const float arrowHeight = static_cast<float>(pp->Height) / 1024.0f * 32.0f;
2320  (*vtxs).x = static_cast<float>(pp->Width) * 0.029f; (*vtxs).y = arrowOffset; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // top right
2321  (*vtxs).tu = 0.9f; (*vtxs).tv = 0.0f;
2322  vtxs++;
2323  (*vtxs).x = static_cast<float>(pp->Width) * 0.019f; (*vtxs).y = arrowOffset; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // top left
2324  (*vtxs).tu = 0.0f; (*vtxs).tv = 0.0f;
2325  vtxs++;
2326  (*vtxs).x = static_cast<float>(pp->Width) * 0.029f; (*vtxs).y = arrowOffset + arrowHeight; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // lower right
2327  (*vtxs).tu = 0.9f; (*vtxs).tv = 1.0f;
2328  vtxs++;
2329  (*vtxs).x = static_cast<float>(pp->Width) * 0.019f; (*vtxs).y = arrowOffset + arrowHeight; (*vtxs).z = 0.0f; (*vtxs).w = 1.0f; // lower left
2330  (*vtxs).tu = 0.0f; (*vtxs).tv = 1.0f;
2331  vtxs++;
2332 
2333  V(m_avInstrument->Unlock());
2334 
2335  V(pd3dDevice->SetFVF(D3DFVF_INSTRUMENT));
2336  V(pd3dDevice->SetStreamSource(0, m_avInstrument, 0, sizeof(D3DINSTRUMENT)));
2337 
2338  V(pd3dDevice->SetTexture(0, m_pddsBinoculars));
2339 
2340  V(pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true));
2341  V(pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA));
2342  V(pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA));
2343 
2344  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1));
2345  V(pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE));
2346  V(pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1));
2347  V(pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE));
2348  V(pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS));
2349 
2350  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2));
2351 
2352  V(pd3dDevice->SetTexture(0, m_pddsBinocularsCompass));
2353  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4, 2));
2354 
2355  V(pd3dDevice->SetTexture(0, m_pddsBinocularsArrow));
2356  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 2));
2357 
2358  // MAG LEVEL
2359  //RECT readloc;
2360  //readloc.top = (int)(748.0f * static_cast<float>(pp->Height) / 1024.0f);
2361  //readloc.left = (int)(1044.0f * static_cast<float>(pp->Width) / 2048.0f);
2362  //readloc.bottom = readloc.right = -1;
2363  //m_spriteVector->Begin(0);
2364  //m_pFontHull->DrawTextA(m_spriteVector, "4.0", -1, &readloc, DT_NOCLIP, 0xFFFFFFFF);
2365  //m_spriteVector->End();
2366 
2367  V(pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS));
2368  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE));
2369  }
2370 
2371 #pragma endregion
2372 
2373  if (ptrWeather->betascreen > 0.0f && ourcockpit.inventoryItemInUseType != KitType::Sunglasses) // for sun flare effects that come into the cockpit
2374  {
2375  logger->AddToCallStack("Viewscreen::OnFrameRender BETA");
2376 
2377  // Screen
2378  pd3dDevice->SetFVF(D3DFVF_SCREEN);
2379 
2380  pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
2381  pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_DIFFUSE);
2382  pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
2383  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);
2384  pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
2385  pd3dDevice->SetTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
2386  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2387  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
2388  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2389  pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
2390  pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS); // was always before cockpit
2391  pd3dDevice->SetRenderState(D3DRS_STENCILPASS, D3DSTENCILOP_KEEP); // with 2
2392 
2393 
2394  D3DSCREEN* vtxs;
2396  // Lock the vertex buffer
2397  V(m_avScreen->Lock(0, 0, reinterpret_cast<void**>(&vtxs), D3DLOCK_DISCARD));
2398 
2399  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = 0.0f; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
2400  (*vtxs).diffuse = ptrWeather->betascreen;
2401  vtxs++;
2402  (*vtxs).x = 0.0f; (*vtxs).y = 0.0f; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
2403  (*vtxs).diffuse = ptrWeather->betascreen;
2404  vtxs++;
2405  (*vtxs).x = static_cast<float>(pp->Width); (*vtxs).y = (float)pp->Height; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
2406  (*vtxs).diffuse = ptrWeather->betascreen;
2407  vtxs++;
2408  (*vtxs).x = 0.0f; (*vtxs).y = (float)pp->Height; (*vtxs).z = 1.0f; (*vtxs).w = 2.0f;
2409  (*vtxs).diffuse = ptrWeather->betascreen;
2410 
2411  V(m_avScreen->Unlock());
2412 
2413 
2414  V(pd3dDevice->SetStreamSource(0, m_avScreen, 0, sizeof(D3DSCREEN)));
2415  V(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2));
2416 
2417  V(pd3dDevice->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_GREATER)); // 1 or 0
2418  V(pd3dDevice->SetRenderState(D3DRS_ZFUNC, D3DCMP_LESS));
2419  V(pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false));
2420  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE));
2421  V(pd3dDevice->SetFVF(D3DFVF_VERTEX));
2422  V(pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE));
2423  // Screen
2424  }
2425 
2426  logger->AddToCallStack("Viewscreen::OnFrameRender OCC");
2428  {
2429  while (m_pLightSunVizQuery->GetData(&m_dwSunViz, sizeof(DWORD), D3DGETDATA_FLUSH) == S_FALSE)
2430  {
2431  }
2432  }
2433 
2434 #ifdef treetestC
2435  sprintf_s(msg, sizeof(msg), "Trees: %i/%i", treesC, raindrops);
2436  m_pChat->DrawText(37, 93, D3DCOLOR_ARGB(255, 0, 0, 255), msg);
2437 #endif
2438  } // !dead or isSimulator
2439 
2440  //V( pd3dDevice->EndScene() ); do not end scene here
2441 
2442  logger->AddToCallStack("Viewscreen::OnFrameRender END");
2443 }
2444 
2445 void Viewscreen::OnFrameRender2(IDirect3DDevice9* pd3dDevice, float fElapsedTime)
2446 {
2447  logger->AddToCallStack("Viewscreen::OnFrameRender2");
2448 
2449  if (!dead || playerships[0].simulator)
2450  {
2451 #pragma region Instrumentation
2452  // sprintf_s(msg, sizeof(msg), "Narrow down 7" );
2453  // _write(logfile, msg, strlen(msg));
2454  if (advanceframe)
2455  {
2456  pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, false); // was always before cockpit
2457  pd3dDevice->SetRenderState(D3DRS_ZENABLE, false); // was always before cockpit
2458 
2459  HRESULT hr;
2460  if (ourcockpit.nextgen)
2461  {
2462  V(m_pRenderToSurfaceNextGen->BeginScene(m_pddsDynamicSurface, NULL));
2463  gameclass->beginScene = 3; // nextgen is 3
2464  }
2465  else
2466  {
2467  V(m_pRenderToSurface->BeginScene(m_pddsDynamicSurface, NULL));
2468  gameclass->beginScene = 4; // monitor is 4
2469  }
2470 
2471  V(pd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET, 0L, 1.0f, 0));
2472 
2474 
2476  if (gameclass->GUI->player[ourcockpit.ourplyrC].frame == 0) // in a vehicle
2477  ptrInstruments->Draw(fElapsedTime, pd3dDevice);
2478 
2479  if (ourcockpit.nextgen)
2480  {
2481  V(m_pRenderToSurfaceNextGen->EndScene(0));
2482  }
2483  else
2484  {
2485  V(m_pRenderToSurface->EndScene(0));
2486  }
2487  gameclass->beginScene = 0;
2488 
2489  pd3dDevice->SetRenderState(D3DRS_ZENABLE, true); // was always before cockpit
2490  pd3dDevice->SetRenderState(D3DRS_STENCILENABLE, true); // was always before cockpit
2491  }
2492 #pragma endregion
2493 
2494 #pragma region Dynamic Hull Registries/License Plates
2495 
2496  for (short t = 1; t < MAX_SCAN; t++)
2497  {
2498  if (playerships[t].active && playerships[t].visible &&
2499  (playerships[t].type == VehicleType::E10 || playerships[t].type == VehicleType::E11 ||
2500  playerships[t].type == VehicleType::W6Manx || playerships[t].type == VehicleType::T19 ||
2501  playerships[t].type == VehicleType::DIHV ||
2502  playerships[t].type == VehicleType::PODS_CARGOAFT || playerships[t].type == VehicleType::PODS_CARGOTOP ||
2503  playerships[t].type == VehicleType::PODS_FUEL || playerships[t].type == VehicleType::PODS_PAX ||
2504  playerships[t].type == VehicleType::PODS_CNST ||
2505  playerships[t].type == VehicleType::C98 || playerships[t].type == VehicleType::C2 || playerships[t].type == VehicleType::C2A ||
2506  playerships[t].type == VehicleType::T27 || playerships[t].type == VehicleType::T120 || playerships[t].type == VehicleType::T121))
2507  {
2508  if (!m_pddsHullDynamicTexture[t])
2509  {
2510  HRESULT hr;
2511  D3DDISPLAYMODE mode;
2512  pd3dDevice->GetDisplayMode(0, &mode);
2513 
2514  if (FAILED(hr = D3DXCreateTexture(pd3dDevice, 256, 128, 1, D3DUSAGE_RENDERTARGET,
2515  mode.Format, D3DPOOL_DEFAULT, &m_pddsHullDynamicTexture[t])))
2516  {
2517  sprintf_s(msg, 160, "Render::OnFrameRender2 failed to create m_pddsHullDynamicTexture: %X", hr);
2518  logger->Log(msg, Logger::Level::Warn);
2519  }
2520  else
2521  {
2522  sprintf_s(msg, 160, "m_pddsHullDynamicTexture[%i]", t);
2523  gameclass->AddTrackedResource(msg, D3DPOOL_DEFAULT);
2524  }
2525 
2526  LPDIRECT3DSURFACE9 m_pddsHullDynamicSurface = nullptr;
2527  if (FAILED(hr = m_pddsHullDynamicTexture[t]->GetSurfaceLevel(0, &m_pddsHullDynamicSurface)))
2528  {
2529  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 failed to get m_pddsHullDynamicSurface: %X", hr);
2530  logger->Log(msg, Logger::Level::Warn);
2531  }
2532  else
2533  gameclass->AddTrackedResource("m_pddsHullDynamicSurface", D3DPOOL_DEFAULT);
2534 
2535  // and dynamic texture
2536  if (FAILED(hr = m_pHullRender2Surface->BeginScene(m_pddsHullDynamicSurface, NULL)))
2537  {
2538  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 could not begin scene for nameplate: %X", hr);
2539  logger->Log(msg, Logger::Level::Warn);
2540  }
2541  else
2542  gameclass->beginScene = 5; // hull is 5
2543  pd3dDevice->Clear(0, nullptr, D3DCLEAR_TARGET, 0xFF000000, 1.0f, 0);
2544 
2545  char hulltext[99];
2546  float arcpos;
2547  D3DXVECTOR3 letterpos;
2548  RECT readloc;
2549  D3DXMATRIX matrixWorld, matrixTemp;
2550 
2551  if (playerships[t].type == VehicleType::E10 || playerships[t].type == VehicleType::E11)
2552  {
2553  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].hullname);
2554  logger->Log(msg);
2555 
2556  // For if the letters overlap
2557  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2558  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
2559  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2560 
2561  m_spriteVector->Begin(0);
2562 
2563  float arcwidth;
2564  if (playerships[t].hullname[0] != 0)
2565  {
2566  sprintf_s(hulltext, sizeof(hulltext), "USV");
2567  arcwidth = static_cast<float>(strlen(hulltext)) * 6.4f;
2568  arcpos = -arcwidth * 0.5f;
2569  for (short s = 0; s < static_cast<short>(strlen(hulltext)); s++)
2570  {
2571  letterpos.x = sinf(D3DXToRadian(arcpos)) * 122.0f + 74.0f;
2572  letterpos.y = cosf(D3DXToRadian(arcpos)) * 122.0f - 52.0f;
2573  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2574  D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2575  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2576  D3DXMatrixScaling(&matrixTemp, 0.5f, 0.5f, 1.0f);
2577  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2578  m_spriteVector->SetTransform(&matrixWorld);
2579  readloc.left = FontOffset(hulltext[s]);
2580  readloc.right = readloc.left + 23;
2581  readloc.top = 0;
2582  readloc.bottom = 12;
2583 
2584  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, 0xFFFFFFFF);
2585 
2586  arcpos += 6.4f;
2587  }
2588 
2589  // single line
2590  if (strlen(playerships[t].hullname) <= 10)
2591  {
2592  strcpy_s(hulltext, sizeof(hulltext), playerships[t].hullname);
2593  arcwidth = static_cast<float>(strlen(hulltext)) * 6.4f;
2594  arcpos = -arcwidth * 0.5f;
2595  for (short s = 0; s < static_cast<short>(strlen(hulltext)); s++)
2596  {
2597  letterpos.x = sinf(D3DXToRadian(arcpos)) * 122.0f + 70.0f;
2598  letterpos.y = cosf(D3DXToRadian(arcpos)) * 122.0f - 38.5f;
2599  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2600  D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2601  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2602  m_spriteVector->SetTransform(&matrixWorld);
2603  readloc.left = FontOffset(hulltext[s]);
2604  readloc.right = readloc.left + 23;
2605  readloc.top = 0;
2606  readloc.bottom = 12;
2607 
2608  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, 0xFFFFFFFF);
2609 
2610  arcpos += 6.4f;
2611  }
2612  }
2613  short lastspace = -1;
2614  if (strlen(playerships[t].hullname) > 10)
2615  {
2616  for (short s = 0; s < static_cast<short>(strlen(playerships[t].hullname)); s++)
2617  {
2618  if (playerships[t].hullname[s] == 32)
2619  lastspace = s;
2620  }
2621  }
2622  if (lastspace != -1)
2623  {
2624  // double line
2625  strcpy_s(hulltext, sizeof(hulltext), playerships[t].hullname);
2626  hulltext[lastspace] = 0;
2627 
2628  arcwidth = static_cast<float>(strlen(hulltext)) * 6.4f;
2629  arcpos = -arcwidth * 0.5f;
2630  for (short s = 0; s < static_cast<short>(strlen(hulltext)); s++)
2631  {
2632  letterpos.x = sinf(D3DXToRadian(arcpos)) * 122.0f + 70.0f;
2633  letterpos.y = cosf(D3DXToRadian(arcpos)) * 122.0f - 45.0f;
2634  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2635  D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2636  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2637  m_spriteVector->SetTransform(&matrixWorld);
2638  readloc.left = FontOffset(hulltext[s]);
2639  readloc.right = readloc.left + 23;
2640  readloc.top = 0;
2641  readloc.bottom = 12;
2642 
2643  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, 0xFFFFFFFF);
2644 
2645  arcpos += 6.4f;
2646  }
2647 
2648  lastspace++;
2649  {
2650  short s;
2651  for (s = lastspace; s < static_cast<short>(strlen(playerships[t].hullname)); s++)
2652  hulltext[s - lastspace] = playerships[t].hullname[s];
2653  hulltext[s - lastspace] = 0;
2654  }
2655  arcwidth = static_cast<float>(strlen(hulltext)) * 6.4f;
2656  arcpos = -arcwidth * 0.5f;
2657  for (short s = 0; s < static_cast<short>(strlen(hulltext)); s++)
2658  {
2659  letterpos.x = sinf(D3DXToRadian(arcpos)) * 122.0f + 70.0f;
2660  letterpos.y = cosf(D3DXToRadian(arcpos)) * 122.0f - 32.0f;
2661  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2662  D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2663  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2664  m_spriteVector->SetTransform(&matrixWorld);
2665  readloc.left = FontOffset(hulltext[s]);
2666  readloc.right = readloc.left + 23;
2667  readloc.top = 0;
2668  readloc.bottom = 12;
2669 
2670  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, 0xFFFFFFFF);
2671 
2672  arcpos += 6.4f;
2673  }
2674  }
2675  }
2676 
2677  sprintf_s(hulltext, sizeof(hulltext), "IVR-%s", playerships[t].IVR);
2678  arcwidth = static_cast<float>(strlen(hulltext)) * 3.2f;
2679  arcpos = -arcwidth * 0.5f;
2680  for (short s = 0; s < static_cast<short>(strlen(hulltext)); s++)
2681  {
2682  letterpos.x = sinf(D3DXToRadian(arcpos)) * 122.0f + 74.0f;
2683  letterpos.y = cosf(D3DXToRadian(arcpos)) * 122.0f - 17.0f;
2684  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2685  D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2686  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2687  D3DXMatrixScaling(&matrixTemp, 0.5f, 0.5f, 1.0f);
2688  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2689  m_spriteVector->SetTransform(&matrixWorld);
2690  readloc.left = FontOffset(hulltext[s]);
2691  readloc.right = readloc.left + 23;
2692  readloc.top = 0;
2693  readloc.bottom = 12;
2694 
2695  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, 0xFFFFFFFF);
2696 
2697  arcpos += 3.2f;
2698  }
2699 
2700  }
2701  else if (playerships[t].type == VehicleType::C98 || playerships[t].type == VehicleType::C2 ||
2702  playerships[t].type == VehicleType::C2A || playerships[t].type == VehicleType::T120 || playerships[t].type == VehicleType::T121)
2703  {
2704  // For if the letters overlap
2705  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2706  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2707  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2708 
2709  m_spriteVector->Begin(0);
2710 
2711  readloc.left = 3;
2712  readloc.right = 74;
2713  readloc.bottom = 35;
2714  readloc.top = 14;
2715  if (playerships[t].hullname[0])
2716  {
2717  m_pFontLicense->DrawTextA(m_spriteVector, playerships[t].hullname, -1, &readloc, DT_CENTER, 0xFFFFFFFF);
2718  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].hullname);
2719  }
2720  else
2721  {
2722  m_pFontLicense->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_CENTER, 0xFFFFFFFF);
2723  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2724  }
2725  logger->Log(msg);
2726  }
2727  else if (playerships[t].type == VehicleType::W6Manx)
2728  {
2729  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].hullname);
2730  logger->Log(msg);
2731 
2732  m_pFontLicense->DrawTextA(m_spriteVector, playerships[t].hullname, -1, &readloc, DT_CENTER, 0xFFFFFFFF);
2733 
2734  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2735  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2736  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2737 
2738  m_spriteVector->Begin(0);
2739 
2740  if (playerships[t].hullname[0] != 0)
2741  {
2742  sprintf_s(hulltext, sizeof(hulltext), "USV %s", playerships[t].hullname);
2743  _strlwr_s(hulltext, sizeof(hulltext)); // Bill's GIMPy font requires lower case letters
2744  readloc.left = 11;
2745  readloc.right = 165;
2746  readloc.top = 15;
2747  readloc.bottom = 127;
2748  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_LEFT, 0xFFFFFFFF);
2749  readloc.left = 11;
2750  readloc.right = 165;
2751  readloc.top = 85;
2752  readloc.bottom = 127;
2753  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_RIGHT, 0xFFFFFFFF);
2754  }
2755 
2756  sprintf_s(hulltext, sizeof(hulltext), "IVR-%s", playerships[t].IVR);
2757  _strlwr_s(hulltext, sizeof(hulltext)); // Bill's GIMPy font requires lower case letters
2758  readloc.left = 11;
2759  readloc.right = 165;
2760  readloc.top = 35;
2761  readloc.bottom = 127;
2762  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_LEFT, 0xFFFFFFFF);
2763  readloc.left = 11;
2764  readloc.right = 165;
2765  readloc.top = 105;
2766  readloc.bottom = 127;
2767  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_RIGHT, 0xFFFFFFFF);
2768  }
2769  else if (playerships[t].type == VehicleType::DIHV)
2770  {
2771  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].hullname);
2772  logger->Log(msg);
2773 
2774  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2775  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2776  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2777 
2778  m_spriteVector->Begin(0);
2779 
2780  if (playerships[t].hullname[0] != 0)
2781  {
2782  sprintf_s(hulltext, sizeof(hulltext), "%s", playerships[t].hullname);
2783  _strlwr_s(hulltext, sizeof(hulltext));
2784  readloc.left = 0;
2785  readloc.right = 156;
2786  readloc.top = 7;
2787  readloc.bottom = 30;
2788  m_pFontHull->DrawText(m_spriteVector, L"usv", -1, &readloc, DT_CENTER, 0xFF000000);
2789  readloc.left = 0;
2790  readloc.right = 156;
2791  readloc.top = 16;
2792  readloc.bottom = 100;
2793  m_pFontLicense->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_CENTER, 0xFF000000);
2794  }
2795 
2796  sprintf_s(hulltext, sizeof(hulltext), "IVR %s", playerships[t].IVR);
2797  _strlwr_s(hulltext, sizeof(hulltext));
2798  readloc.left = 0;
2799  readloc.right = 156;
2800  readloc.top = 44;
2801  readloc.bottom = 54;
2802  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_CENTER, 0xFF000000);
2803  }
2804  else if (playerships[t].type == VehicleType::PODS_FUEL)
2805  {
2806  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2807  logger->Log(msg);
2808 
2809  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2810  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2811  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2812 
2813  m_spriteVector->Begin(0);
2814 
2815  readloc.left = 3;
2816  readloc.right = 64;
2817  readloc.top = 3;
2818  readloc.bottom = 14;
2819  m_pFontHull->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_LEFT, 0xFFFFFFFF);
2820  }
2821  else if (playerships[t].type == VehicleType::PODS_PAX)
2822  {
2823  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2824  logger->Log(msg);
2825 
2826  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2827  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2828  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2829 
2830  m_spriteVector->Begin(0);
2831 
2832  readloc.left = 57;
2833  readloc.right = 160;
2834  readloc.top = 0;
2835  readloc.bottom = 28;
2836  m_pFontLicense->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);
2837  }
2838  else if (playerships[t].type == VehicleType::PODS_CNST)
2839  {
2840  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2841  logger->Log(msg);
2842 
2843  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2844  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2845  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2846 
2847  m_spriteVector->Begin(0);
2848 
2849  // this gets applied for type 11
2850  readloc.left = 156;
2851  readloc.right = 251;
2852  readloc.top = 55;
2853  readloc.bottom = 70;
2854  m_pFontHull->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);
2855  }
2856  else if (playerships[t].type == VehicleType::PODS_CARGOAFT || playerships[t].type == VehicleType::PODS_CARGOTOP)
2857  {
2858  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2859  logger->Log(msg);
2860 
2861  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2862  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2863  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2864 
2865  m_spriteVector->Begin(0);
2866 
2867  readloc.left = 72;
2868  readloc.right = 133;
2869  readloc.top = 107;
2870  readloc.bottom = 118;
2871  m_pFontHull->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_LEFT, 0xFFFFFFFF);
2872  }
2873  else if (playerships[t].type == VehicleType::PODS_MUNITIONS)
2874  {
2875  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2876  logger->Log(msg);
2877 
2878  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2879  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2880  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2881 
2882  m_spriteVector->Begin(0);
2883 
2884  // this gets applied for type 15
2885  readloc.left = 152;
2886  readloc.right = 255;
2887  readloc.top = 1;
2888  readloc.bottom = 53;
2889  m_pFontLicense->DrawTextA(m_spriteVector, playerships[t].IVR, -1, &readloc, DT_CENTER | DT_VCENTER, 0xFFFFFFFF);
2890  }
2891  else if (playerships[t].type == VehicleType::T19)
2892  {
2893  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].IVR);
2894  logger->Log(msg);
2895 
2896  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2897  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
2898  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2899 
2900  m_spriteVector->Begin(0);
2901 
2902  sprintf_s(hulltext, sizeof(hulltext), "IVR %s", playerships[t].IVR);
2903  _strlwr_s(hulltext, sizeof(hulltext));
2904  readloc.left = 147;
2905  readloc.right = 255;
2906  readloc.top = 115;
2907  readloc.bottom = 127;
2908  m_pFontHull->DrawTextA(m_spriteVector, hulltext, -1, &readloc, DT_CENTER, 0xFFFFFFFF);
2909  }
2910  else if (playerships[t].type == VehicleType::T27)
2911  {
2912  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 creating m_pddsHullDynamicTexture slot %i (IVR-%s): %s", t, playerships[t].IVR, playerships[t].hullname);
2913  logger->Log(msg);
2914 
2915  // For if the letters overlap
2916  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
2917  pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCCOLOR);
2918  pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);
2919 
2920  m_spriteVector->Begin(0);
2921 
2922  char topline[99], botline[99];
2923  strcpy_s(topline, 99, playerships[t].hullname);
2924  for (short s = 0; s < static_cast<short>(strlen(topline)); s++)
2925  {
2926  if (topline[s] == ' ')
2927  {
2928  strcpy_s(botline, 99, &topline[s + 1]);
2929  topline[s] = 0;
2930  break;
2931  }
2932  if (topline[s] == 0)
2933  {
2934  botline[0] = 0;
2935  break;
2936  }
2937  }
2938 
2939  D3DXVECTOR3 center;
2940  center.x = 23.0f * 0.5f;
2941  center.y = 12.0f * 0.5f;
2942  center.z = 0.0f;
2943  for (short s = 0; s < static_cast<short>(strlen(topline)); s++)
2944  {
2945  readloc.left = FontOffset(topline[s]);
2946  readloc.right = readloc.left + 23;
2947  readloc.top = 0;
2948  readloc.bottom = 12;
2949 
2950  letterpos.x = 128.0f - 10.0f - strlen(topline) * 11.0f + s * 11.0f; // right justified
2951  letterpos.y = 5.5f;
2952  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2953  D3DXMatrixScaling(&matrixTemp, 0.8f, 1.6f, 1.0f);
2954  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2955  m_spriteVector->SetTransform(&matrixWorld);
2956 
2957  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, playerships[t].trimcolor);
2958 
2959  letterpos.x = 61.0f + s * 11.0f; // left justified
2960  letterpos.y = 45.5f;
2961  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2962  D3DXMatrixScaling(&matrixTemp, 0.8f, 1.6f, 1.0f);
2963  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2964  m_spriteVector->SetTransform(&matrixWorld);
2965 
2966  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, playerships[t].trimcolor);
2967  }
2968 
2969  for (short s = 0; s < (short)strlen(botline); s++)
2970  {
2971  readloc.left = FontOffset(botline[s]);
2972  readloc.right = readloc.left + 23;
2973  readloc.top = 0;
2974  readloc.bottom = 12;
2975 
2976  letterpos.x = 128.0f - 7.0f - strlen(botline) * 4.2f + s * 4.2f; // right justified
2977  letterpos.y = 26.5f;
2978  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2979  //D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2980  //D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2981  D3DXMatrixScaling(&matrixTemp, 0.3f, 0.6f, 1.0f);
2982  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2983  m_spriteVector->SetTransform(&matrixWorld);
2984 
2985  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, playerships[t].trimcolor);
2986 
2987  letterpos.x = 63.0f + s * 4.2f; // left justified
2988  letterpos.y = 66.5f;
2989  D3DXMatrixTranslation(&matrixWorld, letterpos.x, letterpos.y, 0.0f);
2990  //D3DXMatrixRotationZ(&matrixTemp, -D3DXToRadian(arcpos + 3.25f));
2991  //D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2992  D3DXMatrixScaling(&matrixTemp, 0.3f, 0.6f, 1.0f);
2993  D3DXMatrixMultiply(&matrixWorld, &matrixTemp, &matrixWorld);
2994  m_spriteVector->SetTransform(&matrixWorld);
2995 
2996  m_spriteVector->Draw(m_pddsLetters, &readloc, nullptr, nullptr, playerships[t].trimcolor);
2997  }
2998  }
2999 
3000  m_spriteVector->End();
3001 
3002  pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
3003 
3004  D3DXMatrixIdentity(&matrixWorld);
3005  m_spriteVector->SetTransform(&matrixWorld);
3006  m_pHullRender2Surface->EndScene(0);
3007  gameclass->beginScene = 0;
3008 
3009  //sprintf_s(msg, sizeof(msg), "hull-%s.bmp", playerships[t].IVR);
3010  //D3DXSaveSurfaceToFileA(msg, D3DXIFF_BMP, m_pddsHullDynamicSurface, NULL, NULL);
3011 
3012  SAFE_RELEASE(m_pddsHullDynamicSurface);
3013  gameclass->UpdateTrackedResource("m_pddsHullDynamicSurface", 3);
3014 
3015  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 m_pddsHullDynamicTexture finished!");
3016  logger->Log(msg);
3017  } // NULL texture
3018  }
3019  else if (m_pddsHullDynamicTexture[t] != nullptr) // ineligible ship with a texture assigned
3020  {
3021  sprintf_s(msg, sizeof(msg), "Render::OnFrameRender2 released m_pddsHullDynamicTexture slot %i!", t);
3022  logger->Log(msg);
3023  SAFE_RELEASE(m_pddsHullDynamicTexture[t]);
3024  sprintf_s(msg, sizeof(msg), "m_pddsHullDynamicTexture[%i]", t);
3026  }
3027  }
3028 #pragma endregion
3029  }
3030 
3031  logger->AddToCallStack("Viewscreen::OnFrameRender2 END");
3032 }
unsigned char v
Definition: globals.h:334
bool elmoOverride
Definition: weather.h:86
#define radiusC
Definition: globals.h:88
LPDIRECT3DVERTEXBUFFER9 m_avCloudGrid
Definition: Viewscreen.h:109
float GetCloudCeilingMslKm() const
Definition: weather.cpp:945
D3DXMATRIX matWorld
Definition: globals.h:428
Ssorter sortme[buildingVBC]
Definition: globals.cpp:166
Scockpit ourcockpit
Definition: globals.cpp:176
D3DXVECTOR3 position
Definition: globals.h:753
D3DLIGHT9 sunlight
Definition: Viewscreen.h:217
bool powered
Definition: globals.h:297
s_mesh_component * rtscomponentarray
Definition: globals.h:458
VECTOR2SHORT tcp
Definition: grid.h:34
D3DXVECTOR3 cloudpos
Definition: globals.h:741
int inventoryItemInUseType
Definition: globals.h:687
#define MAX_ENGINES
Definition: Bus.h:14
ID3DXEffect * g_pEffect
Definition: Graphics.h:30
#define D3DFVF_LOCALGRID2
Definition: globals.h:113
LPDIRECT3DTEXTURE9 m_pddsTransition[transitiontextureC]
Definition: Viewscreen.h:192
LPD3DXFONT m_pFont
Definition: Viewscreen.h:46
float power
Definition: globals.h:608
double cloudprecisiony
Definition: Viewscreen.h:236
void Render()
Definition: Displays.cpp:419
LPD3DXRENDERTOSURFACE m_pRenderToSurfaceNextGen
Definition: Viewscreen.h:206
D3DXVECTOR3 posnorml
Definition: Viewscreen.h:248
bool g_bAboveClouds
Definition: globals.cpp:22
D3DXVECTOR3 position
Definition: Viewscreen.h:247
#define D3DFVF_LOCALGRID
Definition: globals.h:112
D3DXVECTOR3 position
Definition: globals.h:549
LPDIRECT3DTEXTURE9 m_pddsFirework1[firework1C]
Definition: Viewscreen.h:141
D3DXCOLOR colorhorizon
Definition: weather.h:68
#define cloudTopsMslC
Definition: globals.h:92
void RenderShips(IDirect3DDevice9 *pd3dDevice, const D3DXVECTOR3 *Xsunlight)
Definition: renderer.cpp:3375
unsigned short rtscomponents
Definition: globals.h:456
LPDIRECT3DTEXTURE9 m_pddsCockpitTexture[cockpittextureC]
Definition: Viewscreen.h:162
GameClass * gameclass
Definition: Viewscreen.h:292
unsigned char type
Definition: globals.h:406
unsigned char beginScene
Definition: GameClass.h:126
LPDIRECT3DTEXTURE9 m_pddsWorld2a1
Definition: Viewscreen.h:124
unsigned short startindex
Definition: globals.h:333
D3DXMATRIX matrixLook
Definition: Viewscreen.h:220
LPDIRECT3DTEXTURE9 m_pddsIntersection
Definition: Viewscreen.h:198
unsigned char BCLobjC
Definition: globals.cpp:28
void RenderDocks(IDirect3DDevice9 *pd3dDevice, const D3DXVECTOR3 *Xsunlight)
Definition: renderer.cpp:2890
LPDIRECT3DTEXTURE9 m_pddsCloudBaseMap
Definition: Viewscreen.h:125
D3DXVECTOR3 terpos
Definition: globals.h:449
renderer * ptrRenderer
Definition: Viewscreen.h:286
LPDIRECT3DTEXTURE9 m_pddsHolidayTexture
Definition: Viewscreen.h:134
LPD3DXFONT m_pFontHull
Definition: Viewscreen.h:49
float x
Definition: globals.h:243
#define D3DFVF_RAINDROP
Definition: globals.h:104
instruments * ptrInstruments
Definition: Viewscreen.h:289
float radperseg
Definition: Viewscreen.h:318
double precisiony
Definition: globals.h:550
FIREWORKS fireworks[fireworksC]
Definition: globals.cpp:181
D3DXVECTOR3 position
Definition: globals.h:280
short v
Definition: globals.h:451
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
LPD3DXRENDERTOSURFACE m_pHullRender2Surface
Definition: Viewscreen.h:207
LPDIRECT3DVERTEXBUFFER9 m_avLocalGrid
Definition: Viewscreen.h:111
short texturelib
Definition: globals.h:612
unsigned char ourmoonC
Definition: globals.cpp:27
long FontOffset(char letter) const
LPDIRECT3DTEXTURE9 m_pddsWaterNormal
Definition: Viewscreen.h:193
unsigned char ter_landform
Definition: globals.h:338
#define D3DFVF_VERTEX2
Definition: globals.h:102
weapon * ptrWeapon
Definition: Viewscreen.h:280
#define starsC
Definition: globals.h:66
D3DXCOLOR alphascreen
Definition: Viewscreen.h:231
LPDIRECT3DTEXTURE9 m_pddsSunglasses
Definition: Viewscreen.h:131
void OnFrameRender(IDirect3DDevice9 *pd3dDevice, double fTime) const
Definition: render.cpp:8
float H2Ooffsetu
Definition: Viewscreen.h:267
float extended
Definition: globals.h:427
D3DVERTEX * vertexbackup
Definition: globals.h:345
short u
Definition: renderer.h:32
bool m_bDeviceSupportsVizQuery
Definition: Viewscreen.h:224
LPD3DXSPRITE m_spriteVector
Definition: Viewscreen.h:214
LPDIRECT3DTEXTURE9 m_pddsMarston1
Definition: Viewscreen.h:195
float cloudHorizonDistance
Definition: weather.h:66
D3DXMATRIX matrixProj
Definition: Viewscreen.h:219
float f_ACL
Definition: globals.cpp:16
s_mesh_component * componentarray
Definition: globals.h:678
weather * ptrWeather
Definition: Viewscreen.h:287
void SendEvent(EventType eventType, float extent=0.0f) const
Definition: Networking.cpp:111
unsigned char u
Definition: globals.h:334
LPDIRECT3DVERTEXBUFFER9 m_avStaticStars
Definition: Viewscreen.h:101
LPDIRECT3DVOLUMETEXTURE9 m_pddsReentry
Definition: Viewscreen.h:150
float lookhdg
Definition: Viewscreen.h:234
LPDIRECT3DTEXTURE9 m_pddsRunwayEdgeLight1
Definition: Viewscreen.h:196
LPDIRECT3DTEXTURE9 m_pddsFirework2[firework2C]
Definition: Viewscreen.h:142
double terprecisionx
Definition: Viewscreen.h:235
D3DXVECTOR3 groundpos
Definition: globals.h:741
LPDIRECT3DTEXTURE9 m_pddsElmo[elmoAnimateC]
Definition: Viewscreen.h:144
bool advanceframe
Definition: Viewscreen.h:240
#define drawlistC
Definition: globals.h:55
D3DXVECTOR3 nominalypr
Definition: globals.h:417
float lookAzimuthDegrees
Definition: Viewscreen.h:234
D3DXMATRIX matrixLookAdj
Definition: Viewscreen.h:220
float fFogEndHorizon
Definition: weather.h:74
unsigned char primitives
Definition: globals.h:337
void Draw(float fElapsedTime, IDirect3DDevice9 *pd3dDevice) const
CDXUTDialog g_HUD
Definition: gui.h:710
double terprecisionz
Definition: Viewscreen.h:235
#define fireworksC
Definition: globals.h:746
propulsion * ptrPropulsion
Definition: Viewscreen.h:285
LPDIRECT3DSURFACE9 m_pddsProjectionSurface
Definition: Viewscreen.h:204
float startupextend
Definition: globals.h:608
#define cutplaneC
Definition: globals.h:19
LPDIRECT3DTEXTURE9 m_pddsLandform[landformtextureC]
Definition: Viewscreen.h:191
#define D3DFVF_NONORMAL
Definition: globals.h:108
LPDIRECT3DTEXTURE9 m_pddsCloudDetailBelow
Definition: Viewscreen.h:127
s_universe_object allobjects[maxstarC]
Definition: globals.cpp:170
short v
Definition: renderer.h:32
D3DXMATRIX matrixWorld
Definition: globals.h:491
Viewscreen * viewscreen
Definition: GameClass.h:111
bool gridvisible[63][63]
Definition: Viewscreen.h:262
void RenderLights(IDirect3DDevice9 *pd3dDevice, const double *fTime)
Definition: renderer.cpp:3552
Networking * networking
Definition: GameClass.h:107
#define D3DFVF_INSTRUMENT
Definition: globals.h:110
LIGHTNINGBELOW lightningbelow
Definition: globals.cpp:179
double terprecisiony
Definition: Viewscreen.h:235
float f_MSL
Definition: globals.cpp:36
bool outside
Definition: Viewscreen.h:272
SPlayerData player[MAX_ONLINEPLAYERS]
Definition: gui.h:765
void Render(IDirect3DDevice9 *pd3dDevice, D3DXMATRIX *matrixLookAtLocal)
Definition: weapon.cpp:799
#define D3DFVF_SKYDOME
Definition: globals.h:103
DWORD m_dwSunViz
Definition: globals.cpp:68
D3DXVECTOR3 nominalxyz
Definition: globals.h:416
bool FlightFreeze
Definition: Bus.h:374
BATCHINDEX2 drawlist[drawlistC]
Definition: globals.cpp:156
LPDIRECT3DVERTEXBUFFER9 m_avScreen
Definition: Viewscreen.h:117
LPDIRECT3DTEXTURE9 m_pddsLetters
Definition: Viewscreen.h:174
unsigned char sec_landform
Definition: globals.h:338
D3DXVECTOR2 temp
Definition: renderer.h:34
void OnFrameRender2(IDirect3DDevice9 *pd3dDevice, float fElapsedTime)
Definition: render.cpp:2445
float pitchInput
Definition: Viewscreen.h:237
LPDIRECT3DVERTEXBUFFER9 m_avRainDrops
Definition: Viewscreen.h:114
char msg[199]
Definition: Viewscreen.h:33
D3DXMATRIX matrixProjCock
Definition: Viewscreen.h:219
D3DXMATRIX matrixProjSim
Definition: Viewscreen.h:219
BUILDZONE buildzone[buildingVBC]
Definition: globals.cpp:165
unsigned char sec_transition
Definition: globals.h:338
LPDIRECT3DTEXTURE9 m_pddsSunTexture
Definition: Viewscreen.h:132
void Render(IDirect3DDevice9 *pd3dDevice) const
Definition: cockpit.cpp:313
unsigned short components
Definition: globals.h:624
Graphics * graphics
Definition: GameClass.h:109
const D3DXVECTOR3 centerC
LPDIRECT3DTEXTURE9 m_pddsDynamicTexture
Definition: Viewscreen.h:201
void RenderBuildings(IDirect3DDevice9 *pd3dDevice, double *fTime, bool drawTransparancy)
Definition: renderer.cpp:3145
#define skydomeC
Definition: globals.h:77
short buildzone
Definition: globals.h:467
D3DXMATRIX matrixWorld
Definition: globals.h:555
D3DXVECTOR3 headlightvec
Definition: Viewscreen.h:230
D3DXVECTOR3 extendby
Definition: globals.h:422
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
grid * ptrGrid
Definition: Viewscreen.h:279
s_polygon_object polyobjects[maxpolyC]
Definition: globals.cpp:160
#define D3DFVF_SCREEN
Definition: globals.h:109
float cloudHorizonAngle
Definition: weather.h:66
#define aftersdC
Definition: globals.h:95
#define D3DFVF_STATICSTARS
Definition: globals.h:106
LPDIRECT3DTEXTURE9 m_pddsBinoculars
Definition: Viewscreen.h:128
D3DXCOLOR betascreen
Definition: weather.h:69
float staticBuildup
Definition: propulsion.h:75
LPDIRECT3DVERTEXBUFFER9 m_avInstrument
Definition: Viewscreen.h:118
LPDIRECT3DVERTEXBUFFER9 m_avSkyRing
Definition: Viewscreen.h:116
#define D3DFVF_SKYRING
Definition: globals.h:105
#define maxstarC
Definition: globals.h:24
LPDIRECT3DTEXTURE9 m_pddsBinocularsCompass
Definition: Viewscreen.h:129
LPD3DXRENDERTOSURFACE m_pRenderToSurface
Definition: Viewscreen.h:205
bool m_bPsize
Definition: Viewscreen.h:224
float deathinhibit
Definition: globals.cpp:51
#define buildingVBC
Definition: globals.h:54
D3DXCOLOR dwFogColorHorizon
Definition: weather.h:65
D3DXVECTOR3 position
Definition: globals.h:619
float emissive
Definition: globals.h:453
unsigned char pri_landform
Definition: globals.h:338
s_polygon_extras2 polyextras2
Definition: Viewscreen.h:255
D3DXCOLOR dwFogColorZenith
Definition: weather.h:63
D3DXMATRIX matrixView
Definition: Viewscreen.h:220
LPDIRECT3DTEXTURE9 m_pddsAtmosphere
Definition: Viewscreen.h:178
LPDIRECT3DTEXTURE9 m_pddsRoad
Definition: Viewscreen.h:197
float hingeextent
Definition: globals.h:424
double cloudprecisionz
Definition: Viewscreen.h:236
float x
Definition: globals.h:218
HMI * GUI
Definition: GameClass.h:110
D3DLIGHT9 headlight
Definition: Viewscreen.h:217
short ourplyrC
Definition: globals.h:659
UINT startvertex
Definition: globals.h:408
LPDIRECT3DSURFACE9 m_pddsDynamicSurface
Definition: Viewscreen.h:202
float intensity
Definition: globals.h:738
LPDIRECT3DQUERY9 m_pLightSunVizQuery
Definition: Viewscreen.h:225
char dead
Definition: globals.cpp:49
void AddTrackedResource(const char *name, _D3DPOOL pool=D3DPOOL_MANAGED)
Definition: GameClass.cpp:2702
short BCLoffsetu
Definition: Viewscreen.h:266
LOCALGRID2 gridarray[64][64]
Definition: globals.cpp:153
LPDIRECT3DTEXTURE9 m_pddsCloudDetailAbove
Definition: Viewscreen.h:126
cockpit * ptrCockpit
Definition: Viewscreen.h:288
LPDIRECT3DTEXTURE9 m_pddsRTSTexture[RTStextureC]
Definition: Viewscreen.h:186
LPDIRECT3DTEXTURE9 m_pddsLightningBelow[3]
Definition: Viewscreen.h:176
unsigned char pri_transition
Definition: globals.h:338
LPDIRECT3DVERTEXBUFFER9 RTSVB
Definition: globals.h:445
float shadow
Definition: weather.h:80
#define D3DFVF_VERTEX
Definition: globals.h:101
short BCLoffsetv
Definition: Viewscreen.h:266
D3DXMATRIX matGridRot
Definition: Viewscreen.h:221
std::wstring strings[L_ENUMERATION]
Definition: gui.h:749
unsigned char ourstarC
Definition: globals.cpp:30
short texture
Definition: globals.h:740
D3DXVECTOR4 gammascreen
Definition: Viewscreen.h:232
bool gndvehicle
Definition: globals.h:604
void UpdateTrackedResource(const char *name, int status)
Definition: GameClass.cpp:2725
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
Bus * bus
Definition: GameClass.h:112
bool nextgen
Definition: globals.h:680
LPDIRECT3DINDEXBUFFER9 m_aiCloudGrid
Definition: Viewscreen.h:108
LPD3DXFONT m_pFontLicense
Definition: Viewscreen.h:47
D3DXVECTOR3 hingeCG
Definition: globals.h:423
LPDIRECT3DTEXTURE9 m_pddsRTSLights[RTStextureC]
Definition: Viewscreen.h:187
char gearshift
Definition: globals.h:652
D3DXVECTOR3 hingeaxis
Definition: globals.h:423
float RandomFloat()
Definition: MathUtilities.h:98
Logger * logger
Definition: Viewscreen.h:293
double precisionz
Definition: globals.h:550
Displays * displays
Definition: GameClass.h:114
D3DXCOLOR dwFogFactorZenith
Definition: weather.h:64
unsigned char ourplanetC
Definition: globals.cpp:31
LPDIRECT3DVERTEXBUFFER9 m_avSkyDome
Definition: Viewscreen.h:115
LPDIRECT3DTEXTURE9 m_pddsBinocularsArrow
Definition: Viewscreen.h:130
LPDIRECT3DTEXTURE9 m_pddsHullDynamicTexture[MAX_SCAN]
Definition: Viewscreen.h:209
LPDIRECT3DTEXTURE9 m_pddsFirework3[firework3C]
Definition: Viewscreen.h:143
float x
Definition: globals.h:228
short u
Definition: globals.h:451
float EngineThrustLever[MAX_ENGINES]
Definition: Bus.h:264
short raindrops
Definition: Viewscreen.h:260
LPDIRECT3DVERTEXBUFFER9 m_avSunVertices
Definition: Viewscreen.h:103
SVesselDC vdat
Definition: globals.h:669
LPDIRECT3DTEXTURE9 m_pddsStarTexture
Definition: Viewscreen.h:133
unsigned char roads
Definition: globals.h:335
double cloudprecisionx
Definition: Viewscreen.h:236