Rise
The Vieneo Province
Displays.cpp
Go to the documentation of this file.
1 #include "Displays.h"
2 
3 
4 #include <clocale>
5 #include <io.h>
6 #include <sys/stat.h>
7 #include <fcntl.h>
8 
9 void Displays::ConfigureScreens(rapidxml::xml_node<>* xml_node)
10 {
11  logger->AddToCallStack("Displays::ConfigureScreens");
12  //xml_attribute<> *exclusiveMode = viewportNode->first_attribute("exclusiveMode");
13  //viewport->exclusiveMode = atoi(exclusiveMode->value()) == 1;
14 
15  for (rapidxml::xml_node<>* screenNode = xml_node->first_node(); screenNode; screenNode = screenNode->next_sibling())
16  {
18  Screen screen = Screen(bus);
19  rapidxml::xml_attribute<>* screenName = screenNode->first_attribute("name");
20  if (screenName) screen.name = screenName->value();
21  rapidxml::xml_attribute<>* xAtt = screenNode->first_attribute("x");
22  screen.x = atoi(xAtt->value());
23  rapidxml::xml_attribute<>* yAtt = screenNode->first_attribute("y");
24  screen.y = atoi(yAtt->value());
25  rapidxml::xml_attribute<>* widthAtt = screenNode->first_attribute("width");
26  screen.width = atoi(widthAtt->value());
27  rapidxml::xml_attribute<>* heightAtt = screenNode->first_attribute("height");
28  screen.height = atoi(heightAtt->value());
29  screen.rect.top = screen.y;
30  screen.rect.left = screen.x;
31  screen.rect.right = screen.x + screen.width;
32  screen.rect.bottom = screen.y + screen.height;
33 
34  for (rapidxml::xml_node<>* pageNode = screenNode->first_node(); pageNode; pageNode = pageNode->next_sibling())
35  {
36  Page page = Page();
37  rapidxml::xml_attribute<>* pageName = pageNode->first_attribute("name");
38  page.name = pageName->value();
39 
40  for (rapidxml::xml_node<>* instrumentOrElementNode = pageNode->first_node(); instrumentOrElementNode;
41  instrumentOrElementNode = instrumentOrElementNode->next_sibling())
42  {
43  if (_strcmpi(instrumentOrElementNode->name(), "Instrument") == 0)
44  {
45  rapidxml::xml_attribute<>* xAtt = instrumentOrElementNode->first_attribute("x");
46  int x = atoi(xAtt->value()) + screen.x;
47  rapidxml::xml_attribute<>* yAtt = instrumentOrElementNode->first_attribute("y");
48  int y = atoi(yAtt->value()) + screen.y;
49  rapidxml::xml_attribute<>* xScaleAtt = instrumentOrElementNode->first_attribute("xScale");
50  float xScale = xScaleAtt ? static_cast<float>(atof(xScaleAtt->value())) : 1.0f;
51  rapidxml::xml_attribute<>* yScaleAtt = instrumentOrElementNode->first_attribute("yScale");
52  float yScale = yScaleAtt ? static_cast<float>(atof(yScaleAtt->value())) : 1.0f;
53  /*
54  xml_attribute<> *widthAtt = instrumentOrElementNode->first_attribute("width");
55  int width = widthAtt ? atoi(widthAtt->value()) : 0;
56  xml_attribute<> *heightAtt = instrumentOrElementNode->first_attribute("height");
57  int height = heightAtt ? atoi(heightAtt->value()) : 0;
58 
59  */
60  rapidxml::xml_attribute<>* typeAtt = instrumentOrElementNode->first_attribute("type");
61  std::string type = typeAtt->value();
62  /*
63  xml_attribute<> *textureAtt = instrumentOrElementNode->first_attribute("texture");
64  std::string texfile = textureAtt ? textureAtt->value() : "";
65  xml_attribute<> *modulateKmAtt = instrumentOrElementNode->first_attribute("modulateKm");
66  float modulateKm = modulateKmAtt ? static_cast<float>(atof(modulateKmAtt->value())) : 1.0f;
67 
68  xml_attribute<> *guid1element = instrumentOrElementNode->first_attribute("guid1");
69  std::string guid1 = guid1element ? guid1element->value() : "";
70  xml_attribute<> *guid2element = instrumentOrElementNode->first_attribute("guid2");
71  std::string guid2 = guid2element ? guid2element->value() : "";
72  */
73  rapidxml::xml_attribute<> *ordinalElement = instrumentOrElementNode->first_attribute("ordinal");
74  const int ordinal = ordinalElement ? atoi(ordinalElement->value()) : -1;
75 
76  if (type == "CargoManagement") page.instruments.emplace_back(new CargoManagement(x, y, xScale, yScale, bus, logger, pDevice, fonts));
77  if (type == "Intermedia") page.instruments.emplace_back(new Intermedia(x, y, xScale, yScale, bus, logger, pDevice, fonts));
78  if (type == "LineInput") page.instruments.emplace_back(new LineInput(x, y, xScale, yScale, bus, logger, pDevice, fonts, page.name));
79  if (type == "Diagnostics") page.instruments.emplace_back(new Diagnostics(x, y, xScale, yScale, bus, logger, pDevice, fonts));
80  if (type == "Scanner") page.instruments.emplace_back(new Scanner(x, y, xScale, yScale, bus, logger, pDevice, fonts));
81  if (type == "LandingStrut") page.instruments.emplace_back(new LandingStrut(x, y, xScale, yScale, bus, logger, pDevice, fonts));
82  if (type == "LandingGear") page.instruments.emplace_back(new LandingGear(x, y, xScale, yScale, bus, logger, pDevice, fonts));
83  if (type == "EngineBox") page.instruments.emplace_back(new EngineBox(x, y, xScale, yScale, bus, logger, pDevice, fonts, ordinal));
84  if (type == "EngineBar") page.instruments.emplace_back(new EngineBar(x, y, xScale, yScale, bus, logger, pDevice, fonts, ordinal));
85  if (type == "HeadlightBox") page.instruments.emplace_back(new HeadlightBox(x, y, xScale, yScale, bus, logger, pDevice, fonts));
86  if (type == "HeadlightIcon") page.instruments.emplace_back(new HeadlightIcon(x, y, xScale, yScale, bus, logger, pDevice, fonts));
87  if (type == "ElevatorTrim") page.instruments.emplace_back(new ElevatorTrim(x, y, xScale, yScale, bus, logger, pDevice, fonts));
88  if (type == "Flaps") page.instruments.emplace_back(new Flaps(x, y, xScale, yScale, bus, logger, pDevice, fonts));
89  if (type == "AlertMessageStack") page.instruments.emplace_back(new AlertMessageStack(x, y, xScale, yScale, bus, logger, pDevice, fonts));
90  if (type == "MovingMap") page.instruments.emplace_back(new MovingMap(x, y, xScale, yScale, bus, logger, pDevice, fonts));
91  if (type == "TCAS") page.instruments.emplace_back(new TCASOverlay(x, y, xScale, yScale, bus, logger, pDevice, fonts));
92  if (type == "Wind") page.instruments.emplace_back(new Wind(x, y, xScale, yScale, bus, logger, pDevice, fonts));
93  if (type == "FMA") page.instruments.emplace_back(new FMA(x, y, xScale, yScale, bus, logger, pDevice, fonts));
94  if (type == "Orbit") page.instruments.emplace_back(new Orbit(x, y, xScale, yScale, bus, logger, pDevice, fonts));
95  if (type == "CarRadio") page.instruments.emplace_back(new CarRadio(x, y, xScale, yScale, bus, logger, pDevice, fonts));
96  if (type == "AttitudeIndicator") page.instruments.emplace_back(new AttitudeIndicator(x, y, xScale, yScale, bus, logger, pDevice, fonts));
97  if (type == "StreetView") page.instruments.emplace_back(new StreetView(x, y, xScale, yScale, bus, logger, pDevice, fonts));
98  if (type == "IndicatedAirSpeed") page.instruments.emplace_back(new IndicatedAirSpeed(x, y, xScale, yScale, bus, logger, pDevice, fonts));
99  if (type == "RadioAltimeter") page.instruments.emplace_back(new RadioAltimeter(x, y, xScale, yScale, bus, logger, pDevice, fonts));
100  if (type == "Altimeter") page.instruments.emplace_back(new Altimeter(x, y, xScale, yScale, bus, logger, pDevice, fonts));
101  if (type == "Compass") page.instruments.emplace_back(new Compass(x, y, xScale, yScale, bus, logger, pDevice, fonts));
102  /*
103  if (type == "N1Indicator") page.instruments.emplace_back(new N1Indicator(x, y, xScale, yScale, guid1, guid2, ordinal));
104  if (type == "ITTIndicator") page.instruments.emplace_back(new ITTIndicator(x, y, xScale, yScale, guid1, guid2, ordinal));
105  */
106  }
107  else if (_strcmpi(instrumentOrElementNode->name(), "Element") == 0)
108  {
109  Element element;
110  rapidxml::xml_attribute<>* x = instrumentOrElementNode->first_attribute("x");
111  element.x = atoi(x->value()) + screen.x;
112  rapidxml::xml_attribute<>* y = instrumentOrElementNode->first_attribute("y");
113  element.y = atoi(y->value()) + screen.y;
114 
115  for (rapidxml::xml_node<>* componentNode = instrumentOrElementNode->first_node(); componentNode; componentNode =
116  componentNode->next_sibling())
117  {
118  Component component = Component(bus, logger, pDevice);
119  rapidxml::xml_attribute<>* busval = componentNode->first_attribute("busval");
120  if (busval)
121  {
122  const std::string type = busval->value();
123  // THESE ARE ONLY FLOATING POINT VALUES SINGLE PRECISION
124  if (type == "DesiredClosingSpeed") component.ptrValue = &bus->AFCS.DesiredClosingSpeed;
125  if (type == "TvmCurrentClosingSpeed") component.ptrValue = &bus->AFCS.TvmCurrentClosingSpeed;
126  if (type == "StaticAirTemperatureCelsius") component.ptrValue = &bus->StaticAirTemperatureCelsius;
127  if (type == "OutsideAirTemperatureKelvin") component.ptrValue = &bus->OutsideAirTemperatureKelvin;
128  if (type == "TotalAirTemperatureCelsius") component.ptrValue = &bus->TotalAirTemperatureCelsius;
129  if (type == "AirframeTemperatureCelsius") component.ptrValue = &bus->AirframeTemperatureCelsius;
130  if (type == "AngleOfAttack") component.ptrValue = &bus->AngleOfAttackRadians;
131  if (type == "GroundSpeed") component.ptrValue = &bus->GroundSpeedKms;
132  if (type == "Latitude") component.ptrValue = &bus->LatitudeDeg;
133  if (type == "Longitude") component.ptrValue = &bus->LongitudeDeg;
134  if (type == "VerticalSpeed") component.ptrValue = &bus->VerticalSpeedKms;
135  if (type == "FlightPathAngle") component.ptrValue = &bus->FlightPathAngleRadians;
136  if (type == "AirDensityScalar") component.ptrValue = &bus->AirDensityScalar;
137  if (type == "DynamicPressure") component.ptrValue = &bus->DynamicPressure;
138  if (type == "LinearVelocity") component.ptrValue = &bus->LinearVelocityKms;
139  if (type == "Mach") component.ptrValue = &bus->Mach;
140  if (type == "SpeedOfSoundKms") component.ptrValue = &bus->SpeedOfSoundKms;
141  if (type == "EmptyWeight") component.ptrValue = &bus->EmptyWeightLbs;
142  if (type == "FuelWeight") component.ptrValue = &bus->FuelWeightLbs;
143  if (type == "FuelFlow") component.ptrValue = &bus->FuelFlowKgh;
144  if (type == "PayloadWeight") component.ptrValue = &bus->PayloadWeightLbs;
145  if (type == "PitchTrim") component.ptrValue = &bus->PitchTrimScalar;
146  if (type == "NormalAcceleration.x") component.ptrValue = &bus->NormalAcceleration.x;
147  if (type == "NormalAcceleration.y") component.ptrValue = &bus->NormalAcceleration.y;
148  if (type == "NormalAcceleration.z") component.ptrValue = &bus->NormalAcceleration.z;
149  if (type == "PressureAltitude") component.ptrValue = &bus->PressureAltitudeKm;
150  if (type == "RadioAltitude") component.ptrValue = &bus->RadioAltitudeKm;
151  if (type == "HeadingTrue") component.ptrValue = &bus->HeadingTrueDegrees;
152  if (type == "HeadingTrack") component.ptrValue = &bus->HeadingTrackDegrees;
153  if (type == "TrueAirspeedKms") component.ptrValue = &bus->TrueAirspeedKms;
154  if (type == "IndicatedAirspeedKms") component.ptrValue = &bus->IndicatedAirspeedKms;
155  if (type == "MapScale") component.ptrValue = &bus->MapScaleInnerRingKm;
156  if (type == "WindSpeedMs") component.ptrValue = &bus->WindSpeedMs;
157  if (type == "WindDirectionDegrees") component.ptrValue = &bus->WindDirectionDegrees;
158  if (type == "GlideslopeDeviation") component.ptrValue = &bus->GlideslopeDeviationRadians;
159  if (type == "LocalTimeHours") component.ptrValue = &bus->LocalTimeHours;
160  if (type == "LocalTimeMinutes") component.ptrValue = &bus->LocalTimeMinutes;
161  if (type == "IVR") component.chrValue = &playerships[0].IVR[0];
162  if (type == "TimeToNextFix") component.chrValue = &bus->TimeToNextFix[0];
163  }
164 
165  rapidxml::xml_attribute<>* modulate = componentNode->first_attribute("modulate");
166  if (modulate) component.modulate = static_cast<float>(atof(modulate->value()));
167  rapidxml::xml_attribute<>* bias = componentNode->first_attribute("bias");
168  if (bias) component.bias = static_cast<float>(atof(bias->value()));
169  rapidxml::xml_attribute<>* abs = componentNode->first_attribute("abs");
170  if (abs) component.abs = atoi(abs->value());
171 
172  for (rapidxml::xml_node<>* conditionNode = componentNode->first_node(); conditionNode; conditionNode =
173  conditionNode->next_sibling())
174  {
175  Condition condition;
176  rapidxml::xml_attribute<>* min = conditionNode->first_attribute("min");
177  if (min) condition.min = static_cast<float>(atof(min->value()));
178  rapidxml::xml_attribute<>* max = conditionNode->first_attribute("max");
179  if (max) condition.max = static_cast<float>(atof(max->value()));
180 
181  for (rapidxml::xml_node<>* spriteOrTextNode = conditionNode->first_node(); spriteOrTextNode; spriteOrTextNode =
182  spriteOrTextNode->next_sibling())
183  {
184  if (_strcmpi(spriteOrTextNode->name(), "Sprite") == 0)
185  {
186  std::string pathAndFilename = spriteOrTextNode->value();
187  rapidxml::xml_attribute<>* spriteX = spriteOrTextNode->first_attribute("x");
188  int x = atoi(spriteX->value()) + element.x;
189  rapidxml::xml_attribute<>* spriteY = spriteOrTextNode->first_attribute("y");
190  int y = atoi(spriteY->value()) + element.y;
191  rapidxml::xml_attribute<>* zAttr = spriteOrTextNode->first_attribute("z");
192  float z = 0.0f; // bottom of render order
193  if (zAttr) z = static_cast<float>(atof(zAttr->value()));
194 
195  rapidxml::xml_attribute<>* spriteTop = spriteOrTextNode->first_attribute("top");
196  int top = 0;
197  if (spriteTop) top = atoi(spriteTop->value());
198  rapidxml::xml_attribute<>* spriteLeft = spriteOrTextNode->first_attribute("left");
199  int left = 0;
200  if (spriteLeft) left = atoi(spriteLeft->value());
201  rapidxml::xml_attribute<>* widthAttr = spriteOrTextNode->first_attribute("width");
202  int width = atoi(widthAttr->value());
203  rapidxml::xml_attribute<>* heightAttr = spriteOrTextNode->first_attribute("height");
204  int height = atoi(heightAttr->value());
205 
206  rapidxml::xml_attribute<>* colorAttr = spriteOrTextNode->first_attribute("color");
207  DWORD color = 0xFFFFFFFF;
208  if (colorAttr) color = strtoul(colorAttr->value(), nullptr, 16);
209 
210  float scaleX = 1.0f;
211  rapidxml::xml_attribute<>* scaleXAttr = spriteOrTextNode->first_attribute("xScale");
212  if (scaleXAttr) scaleX = static_cast<float>(atof(scaleXAttr->value()));
213  float scaleY = 1.0f;
214  rapidxml::xml_attribute<>* scaleYAttr = spriteOrTextNode->first_attribute("yScale");
215  if (scaleYAttr) scaleY = static_cast<float>(atof(scaleYAttr->value()));
216 
217  //rapidxml::xml_attribute<> *name = spriteOrTextNode->first_attribute("name");
218  //if (name) sprite.elementName = name->value();
219  //rapidxml::xml_attribute<> *hidden = spriteOrTextNode->first_attribute("hidden");
220  //if (hidden) sprite.normallyHidden = atoi(hidden->value()) == 1;
221 
222  const Sprite sprite = Sprite(logger, pDevice, pathAndFilename, x, y, z, top, left, width, height, color, scaleX, scaleY);
223 
224  condition.sprites.emplace_back(sprite);
225  }
226  else if (_strcmpi(spriteOrTextNode->name(), "Text") == 0)
227  {
228  rapidxml::xml_attribute<>* textX = spriteOrTextNode->first_attribute("x");
229  int x = atoi(textX->value()) + element.x;
230  rapidxml::xml_attribute<>* textY = spriteOrTextNode->first_attribute("y");
231  int y = atoi(textY->value()) + element.y;
232  rapidxml::xml_attribute<>* font = spriteOrTextNode->first_attribute("font");
233 
234  rapidxml::xml_attribute<>* widthAttr = spriteOrTextNode->first_attribute("width");
235  int width = 0;
236  if (widthAttr) width = atoi(widthAttr->value());
237  rapidxml::xml_attribute<>* heightAttr = spriteOrTextNode->first_attribute("height");
238  int height = 0;
239  if (heightAttr) height = atoi(heightAttr->value());
240 
241  int fontInt = 0;
242  if (font) fontInt = atoi(font->value());
243  if (fontInt >= (int)fonts.size() || fontInt < 0)
244  {
245  throw std::exception("Font requested is not in available fonts list!");
246  }
247 
248  Text text = Text(logger, bus, pDevice, fonts.at(fontInt)->pFont, x, y, width, height);
249  std::string temptext = spriteOrTextNode->value();
250  std::size_t found;
251  do
252  {
253  // we tried changing the encoding from utf-8 to iso-8559-1 but nothing worked to delete the &nbsp; hatted weird "A"
254  found = temptext.find(-62);
255  if (found != std::string::npos)
256  temptext.erase(found, 1);
257  } while (found != std::string::npos);
258 
259  text.formattedText = temptext;
260 
261  rapidxml::xml_attribute<>* align = spriteOrTextNode->first_attribute("align");
262  if (align)
263  {
264  if (_strcmpi(align->value(), "left") == 0) text.flags |= DT_LEFT;
265  if (_strcmpi(align->value(), "center") == 0) text.flags |= DT_CENTER;
266  if (_strcmpi(align->value(), "right") == 0) text.flags |= DT_RIGHT;
267  }
268 
269  rapidxml::xml_attribute<>* valign = spriteOrTextNode->first_attribute("valign");
270  if (valign)
271  {
272  if (_strcmpi(valign->value(), "top") == 0) text.flags |= DT_TOP;
273  if (_strcmpi(valign->value(), "center") == 0) text.flags |= DT_VCENTER;
274  if (_strcmpi(valign->value(), "bottom") == 0) text.flags |= DT_BOTTOM;
275  }
276 
277  rapidxml::xml_attribute<>* color = spriteOrTextNode->first_attribute("color");
278  text.color = strtoul(color->value(), nullptr, 16);
279 
280  condition.text.emplace_back(text);
281  }
282  }
283 
284  component.conditions.emplace_back(condition);
285  }
286 
287  element.components.emplace_back(component);
288  }
289 
290  page.elements.emplace_back(element);
291  }
292  }
293  screen.pages.emplace_back(page);
294  }
295 
296  screens.emplace_back(screen);
297  }
298 }
299 
300 void Displays::ConfigureFonts(rapidxml::xml_node<>* xml_node)
301 {
302  logger->AddToCallStack("Displays::ConfigureFonts");
303  for (rapidxml::xml_node<>* fontNode = xml_node->first_node(); fontNode; fontNode = fontNode->next_sibling())
304  {
305  rapidxml::xml_attribute<>* width = fontNode->first_attribute("width");
306  int iwidth = atoi(width->value());
307  rapidxml::xml_attribute<>* height = fontNode->first_attribute("height");
308  int iheight = atoi(height->value());
309  rapidxml::xml_attribute<>* name = fontNode->first_attribute("name");
310  std::string iname = name->value();
311  std::string ipathAndFilename = fontNode->value();
312 
313  // fonts.emplace_back(Font(logger, DXUTGetD3D10Device(), iwidth, iheight, iname, ipathAndFilename));
314  fonts.emplace_back(new Font(logger, DXUTGetD3D9Device(), iwidth, iheight, iname, ipathAndFilename));
315  }
316 }
317 
319 {
320  logger->AddToCallStack("Displays::ChangeCockpit");
321 
322  OnDestroyDevice();
323 
324  //pDevice = new DeviceObject(logger, DXUTGetD3D10Device());
325  pDevice = new DeviceObject(DXUTGetD3D9Device(), logger);
326 
327  screens.clear();
328 
329  setlocale(LC_ALL, "English");
330 
331  WCHAR configFilePath[MAX_PATH];
332  switch (ourcockpit.texturelib)
333  {
334  case C98:
335  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\C-98.xml");
336  break;
337  case E10:
338  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\E-10.xml");
339  break;
340  case P13:
341  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\P-13.xml");
342  break;
343  case A4:
344  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\A-4.xml");
345  break;
346  case C2:
347  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\C-2.xml");
348  break;
349  case T120:
350  case T121:
351  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\T-120.xml");
352  break;
353  case E11:
354  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\E-11.xml");
355  break;
356  case C2A:
357  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\C-2A.xml");
358  break;
359  case W6Manx:
360  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\W-6.xml");
361  break;
362  case T19:
363  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\T-19.xml");
364  break;
365  case T27:
366  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\T-27.xml");
367  break;
368  case Apartment:
369  wcscpy_s(configFilePath, MAX_PATH, L"Displays\\Apartment.xml");
370  break;
371  default:
372  return;
373  }
374 
375  int configFile;
376  _wsopen_s(&configFile, configFilePath, _O_RDONLY | _O_BINARY | _O_SEQUENTIAL, SH_DENYWR, S_IREAD);
377  if (configFile == -1)
378  {
379  char msg[99];
380  sprintf_s(msg, 99, "Config::Initialize could not open file: %S", configFilePath);
381  logger->Log(msg, Logger::Error, errno);
382  return;
383  }
384 
385  // had to do as dynamic char array because it wouldn't take a std::string
386  const int fileLength = _filelength(configFile);
387  char* buffer = new char[fileLength + 1]; // null terminator
388  _read(configFile, buffer, fileLength);
389  _close(configFile);
390  buffer[fileLength] = 0; // null terminate
391 
392  rapidxml::xml_document<> doc; // character type defaults to char
393  try
394  {
395  doc.parse<0>(buffer); // 0 means default parse flags
396  }
397  catch (...)
398  {
399  SAFE_DELETE_ARRAY(buffer);
400  char msg[99];
401  sprintf_s(msg, 99, "Config::Initialize exception parsing file: %S", configFilePath);
402  logger->Log(msg, Logger::Error, errno);
403  return;
404  }
405 
406  rapidxml::xml_node<>* rootNode = doc.first_node("Displays");
407 
408  rapidxml::xml_node<>* fontsNode = rootNode->first_node("Fonts");
409  ConfigureFonts(fontsNode);
410 
411  rapidxml::xml_node<>* screensNode = rootNode->first_node("Screens");
412  ConfigureScreens(screensNode);
413 
414  SAFE_DELETE_ARRAY(buffer);
415 
416  gui->SetLocale();
417 }
418 
420 {
421  logger->AddToCallStack("Displays::Render");
422  HRESULT hr;
423  V(pDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true));
424 
425  V(pDevice->pSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE | D3DXSPRITE_SORT_DEPTH_BACKTOFRONT));
426 
427  for (UINT i = 0; i < screens.size(); i++)
428  {
429  V(pDevice->SetScissorRect(&screens.at(i).rect));
430  screens.at(i).Render();
431  V(pDevice->pSprite->Flush());
432  }
433 
434  V(pDevice->pSprite->End());
435 
436  V(pDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, false));
437 }
438 
439 void Displays::FrameMove(float fElapsed)
440 {
441  logger->AddToCallStack("Displays::FrameMove");
442  for (UINT i = 0; i < bus->commandStream.size(); i++)
443  {
444  const Command command = bus->commandStream.at(i);
445 
446  if (command.name == "ChangeMfdPage")
447  {
448  ChangePage("MFD", command.sValue);
449  bus->commandStream.erase(bus->commandStream.begin() + i);
450  }
451  else if (command.name == "RestorePage")
452  {
453  RestorePage(command.sValue);
454  bus->commandStream.erase(bus->commandStream.begin() + i);
455  }
456  }
457 
458  for (UINT i = 0; i < screens.size(); i++)
459  screens.at(i).FrameMove(fElapsed);
460 }
461 
462 bool Displays::HandleKeyPress(short key, bool shift)
463 {
464  logger->AddToCallStack("Displays::HandleKeyPress");
465  for (UINT i = 0; i < screens.size(); i++)
466  {
467  if (screens.at(i).HandleKeyPress(key, shift))
468  return true;
469  }
470  return false;
471 }
472 
474 {
475  logger->AddToCallStack("Displays::OnLostDevice");
476  if (pDevice)
478  for (UINT i = 0; i < fonts.size(); i++)
479  fonts.at(i)->pFont->OnLostDevice();
480 }
481 
483 {
484  logger->AddToCallStack("Displays::OnResetDevice");
485  if (pDevice)
487  for (UINT i = 0; i < fonts.size(); i++)
488  fonts.at(i)->pFont->OnResetDevice();
489 }
490 
491 void Displays::ChangePage(std::string screenName, std::string pageName)
492 {
493  logger->AddToCallStack("Displays::ChangePage");
494  char msg[99];
495 
496  for (UINT i = 0; i < screens.size(); i++)
497  {
498  if (screens.at(i).name == screenName)
499  {
500  if (screens.at(i).ChangePage(pageName))
501  return;
502 
503  sprintf_s(msg, 99, "Displays::ChangePage found screen %s but couldn't find page: %s", screenName.c_str(),
504  pageName.c_str());
505  logger->Log(msg, Logger::Warn);
506  }
507  }
508 
509  sprintf_s(msg, 99, "Displays::ChangePage could not find screen named: %s", screenName.c_str());
510  logger->Log(msg, Logger::Warn);
511 }
512 
513 // If you call this you are responsible for updating the server (except if it is coming FROM the server)
514 void Displays::ChangePage(std::string screenName, int pageNumber)
515 {
516  logger->AddToCallStack("Displays::ChangePage");
517  char msg[99];
518 
519  for (UINT i = 0; i < screens.size(); i++)
520  {
521  if (screens.at(i).name == screenName)
522  {
523  screens.at(i).ChangePage(pageNumber);
524  return;
525  }
526  }
527 
528  sprintf_s(msg, 99, "Displays::ChangePage could not find screen named: %s", screenName.c_str());
529  logger->Log(msg, Logger::Warn);
530 }
531 
532 std::string Displays::TogglePage(std::string screenName)
533 {
534  logger->AddToCallStack("Displays::TogglePage");
535  for (UINT i = 0; i < screens.size(); i++)
536  {
537  if (screens.at(i).name == screenName)
538  {
539  if (screens.at(i).pages.size() == 0)
540  return "";
541  screens.at(i).currentPage++;
542  if (screens.at(i).currentPage >= screens.at(i).pages.size())
543  screens.at(i).currentPage = 0;
544  screens.at(i).OnPageChange();
545  return screens.at(i).pages.at(screens.at(i).currentPage).name;
546  }
547  }
548 
549  char msg[99];
550  sprintf_s(msg, 99, "Displays::ChangePage could not find screen named: %s", screenName.c_str());
551  logger->Log(msg, Logger::Warn);
552  return "";
553 }
554 
555 std::string Displays::TogglePageReverse(std::string screenName)
556 {
557  logger->AddToCallStack("Displays::TogglePageReverse");
558  for (UINT i = 0; i < screens.size(); i++)
559  {
560  if (screens.at(i).name == screenName)
561  {
562  if (screens.at(i).pages.size() == 0)
563  return "";
564  if (screens.at(i).currentPage == 0)
565  screens.at(i).currentPage = screens.at(i).pages.size() - 1;
566  else
567  screens.at(i).currentPage--;
568  screens.at(i).OnPageChange();
569  return screens.at(i).pages.at(screens.at(i).currentPage).name;
570  }
571  }
572 
573  char msg[99];
574  sprintf_s(msg, 99, "Displays::ChangePage could not find screen named: %s", screenName.c_str());
575  logger->Log(msg, Logger::Warn);
576  return "";
577 }
578 
579 Displays::Displays(Logger* prmLogger, Bus* prmBus, HMI* prmGui)
580 {
581  logger = prmLogger;
582  logger->AddToCallStack("Displays::ctor");
583  bus = prmBus;
584  gui = prmGui;
585 }
586 
588 {
589  logger->AddToCallStack("Displays::OnDestroyDevice");
590 
591  SAFE_DELETE(pDevice);
592 
593  logger->AddToCallStack("Displays::OnDestroyDevice FONTS");
594 
595  for (UINT i = 0; i < fonts.size(); i++)
596  fonts.at(i)->OnDestroyDevice();
597  fonts.clear();
598 
599  logger->AddToCallStack("Displays::OnDestroyDevice DONE");
600 }
601 
602 void Displays::RestorePage(std::string screenName)
603 {
604  logger->AddToCallStack("Displays::RestorePage");
605  char msg[99];
606 
607  for (UINT i = 0; i < screens.size(); i++)
608  {
609  if (screens.at(i).name == screenName)
610  {
611  screens.at(i).RestorePage();
612  return;
613  }
614  }
615 
616  sprintf_s(msg, 99, "Displays::RestorePage could not find screen named: %s", screenName.c_str());
617  logger->Log(msg, Logger::Warn);
618 }
float Mach
Definition: Bus.h:356
Definition: Text.h:50
std::vector< Element > elements
Definition: Page.h:11
DeviceObject * pDevice
Definition: Displays.h:17
Scockpit ourcockpit
Definition: globals.cpp:176
float PitchTrimScalar
Definition: Bus.h:316
char * chrValue
Definition: Component.h:17
Definition: Element.h:5
D3DXCOLOR color
Definition: Text.h:64
std::vector< Text > text
Definition: Condition.h:14
float LocalTimeMinutes
Definition: Bus.h:359
struct Bus::Afcs AFCS
void Render()
Definition: Displays.cpp:419
float HeadingTrueDegrees
Definition: Bus.h:30
float SpeedOfSoundKms
Definition: Bus.h:357
std::vector< Command > commandStream
Definition: Bus.h:342
float TvmCurrentClosingSpeed
Definition: Bus.h:128
float * ptrValue
Definition: Component.h:16
Definition: Font.h:6
float FuelWeightLbs
Definition: Bus.h:362
int y
Definition: Screen.h:30
float DynamicPressure
Definition: Bus.h:354
Definition: Logger.h:9
void SetLocale() const
Definition: gui.cpp:1449
int x
Definition: Screen.h:29
void FrameMove(float fElapsed)
Definition: Displays.cpp:439
s_network_objects playerships[MAX_SCAN]
Definition: globals.cpp:174
Definition: Screen.h:5
short texturelib
Definition: globals.h:612
float RadioAltitudeKm
Definition: Bus.h:134
float WindDirectionDegrees
Definition: Bus.h:229
void OnDestroyDevice()
Definition: Displays.cpp:587
float VerticalSpeedKms
Definition: Bus.h:351
float EmptyWeightLbs
Definition: Bus.h:361
void ConfigureScreens(rapidxml::xml_node<> *xml_node)
Definition: Displays.cpp:9
float PayloadWeightLbs
Definition: Bus.h:364
void ChangePage(std::string screenName, std::string pageName)
Definition: Displays.cpp:491
float AngleOfAttackRadians
Definition: Bus.h:152
float GlideslopeDeviationRadians
Definition: Bus.h:136
float PressureAltitudeKm
Definition: Bus.h:25
std::string name
Definition: Page.h:9
void OnResetDevice()
Definition: Displays.cpp:482
Definition: Bus.h:16
std::string name
Definition: Command.h:11
D3DXVECTOR3 NormalAcceleration
Definition: Bus.h:34
float DesiredClosingSpeed
Definition: Bus.h:127
std::vector< Sprite > sprites
Definition: Condition.h:13
Definition: Sprite.h:7
void OnLostDevice() const
Definition: Page.h:6
HRESULT SetRenderState(_D3DRENDERSTATETYPE renderStateType, int value) const
Displays(Logger *prmLogger, Bus *prmBus, HMI *prmGui)
Definition: Displays.cpp:579
std::string formattedText
Definition: Text.h:67
float HeadingTrackDegrees
Definition: Bus.h:226
std::string TogglePage(std::string screenName)
Definition: Displays.cpp:532
HMI * gui
Definition: Displays.h:15
float IndicatedAirspeedKms
Definition: Bus.h:27
int x
Definition: Element.h:8
bool HandleKeyPress(short key, bool shift)
Definition: Displays.cpp:462
float AirDensityScalar
Definition: Bus.h:353
float WindSpeedMs
Definition: Bus.h:230
void ChangeCockpit()
Definition: Displays.cpp:318
int y
Definition: Element.h:8
void OnLostDevice()
Definition: Displays.cpp:473
float LinearVelocityKms
Definition: Bus.h:355
float MapScaleInnerRingKm
Definition: Bus.h:381
std::vector< Page > pages
Definition: Screen.h:25
float AirframeTemperatureCelsius
Definition: Bus.h:69
float modulate
Definition: Component.h:22
Definition: Command.h:5
float LongitudeDeg
Definition: Bus.h:234
std::string sValue
Definition: Command.h:20
std::vector< Component > components
Definition: Element.h:9
std::string TogglePageReverse(std::string screenName)
Definition: Displays.cpp:555
float LatitudeDeg
Definition: Bus.h:234
void OnResetDevice() const
HRESULT SetScissorRect(RECT *rect) const
std::vector< Condition > conditions
Definition: Component.h:24
std::vector< Font * > fonts
Definition: Displays.h:20
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition: Logger.cpp:11
Definition: gui.h:696
std::string name
Definition: Screen.h:24
int height
Definition: Screen.h:28
void RestorePage(std::string screenName)
Definition: Displays.cpp:602
float LocalTimeHours
Definition: Bus.h:358
float OutsideAirTemperatureKelvin
Definition: Bus.h:67
char TimeToNextFix[6]
Definition: Bus.h:394
int width
Definition: Screen.h:27
float GroundSpeedKms
Definition: Bus.h:156
float TotalAirTemperatureCelsius
Definition: Bus.h:68
void ConfigureFonts(rapidxml::xml_node<> *xml_node)
Definition: Displays.cpp:300
void AddToCallStack(const char *msg)
Definition: Logger.cpp:86
std::vector< Screen > screens
Definition: Displays.h:19
Nullable< float > max
Definition: Condition.h:11
LPD3DXSPRITE pSprite
Definition: DeviceObject.h:21
Bus * bus
Definition: Displays.h:14
bool abs
Definition: Component.h:23
RECT rect
Definition: Screen.h:31
int flags
Definition: Text.h:66
float StaticAirTemperatureCelsius
Definition: Bus.h:66
float FlightPathAngleRadians
Definition: Bus.h:352
float bias
Definition: Component.h:21
float FuelFlowKgh
Definition: Bus.h:363
Logger * logger
Definition: Displays.h:13
Nullable< float > min
Definition: Condition.h:10
float TrueAirspeedKms
Definition: Bus.h:348
std::vector< Instrument * > instruments
Definition: Page.h:10