Rise
The Vieneo Province
Loading...
Searching...
No Matches
GameClass.cpp
Go to the documentation of this file.
1#include "GameClass.h"
2#include "CpuInformation.h"
4
5#include <Dbt.h>
6#include <ctime>
7#include <VersionHelpers.h>
8
9#include "MathUtilities.h"
11#include "Modules/Orbit.h"
12#include "WaypointProtocol.h"
13
14
18
19#define GUID_DEVINTERFACE_USB_DEVICE {0x4d1e55b2, 0xf16f, 0x11cf,{ 0x88, 0xcb, 0x00, 0x11, 0x11, 0x00, 0x00, 0x30}}
20/* A5DCBF10-6530-11D2-901F-00C04FB951ED */
21
23{
24 logger = std::make_unique<Logger>();
25 logger->AddToCallStack("GameClass::ctor");
26
27 RtlZeroMemory(vphelp, vphelpC);
28
29 networking = std::make_unique<Networking>(this);
31
32 sound = std::make_unique<Sound>(this);
33
34 GUI = std::make_unique<HMI>(this, networking.get(), sound.get());
36
37 graphics = std::make_unique<Graphics>(GUI.get());
38 bus = std::make_unique<Bus>(logger.get());
39 viewscreen = std::make_unique<Viewscreen>(this);
40 displays = std::make_unique<Displays>(logger.get(), bus.get(), GUI.get());
41 discord = std::make_unique<DiscordIntegration>(networking.get(), bus.get(), logger.get(), GUI->isSteam);
42
43 // Back in the Dropship days these were sourced from XML configuration
44 modules.emplace_back(std::make_unique<Cas>(bus.get(), logger.get(), sound.get()));
45 modules.emplace_back(std::make_unique<IceDetector>(bus.get(), logger.get()));
46 modules.emplace_back(std::make_unique<Gpws>(bus.get(), logger.get(), viewscreen.get()));
47 modules.emplace_back(std::make_unique<WeatherRadar>(bus.get(), viewscreen.get()));
48 modules.emplace_back(std::make_unique<Avionics::Orbit>(bus.get(), [this] { TurnOffDOR(true); }, [this] { return GUI && GUI->IsAdmin; }, [this](int index) {
49 if(index<0||index>=int(bus->waypoint.size())) return;
50 bus->WPtargetC=index;bus->targetC=-1;bus->ClearTurnByTurn();
51 auto packet=WaypointProtocol::Select(bus->waypoint[index].id,false);
52 networking->SendToServer(&packet,sizeof(packet),true);
53 }));
54 modules.emplace_back(std::make_unique<TCAS>(bus.get(), logger.get(), &viewscreen->matrixView));
55 modules.emplace_back(std::make_unique<Vmu>(bus.get(), logger.get(), sound.get()));
56 modules.emplace_back(std::make_unique<MarkerBeacons>(bus.get(), logger.get(), sound.get()));
57
59}
60
62{
63 logger->AddToCallStack("GameClass::dtor");
64
65 // make sure we have no unreleased resources
66
67 logger->AddToCallStack("GameClass::dtor modules");
68 modules.clear();
69 discord.reset();
70 // displays has untracked resources that he manages... this is what got us in trouble with OnLostDevice failing to Reset
71 displays.reset();
72 logger->AddToCallStack("GameClass::dtor viewscreen");
73 viewscreen.reset();
74 logger->AddToCallStack("GameClass::dtor viewscreen released");
75 graphics.reset();
76 logger->AddToCallStack("GameClass::dtor graphics released");
77 GUI.reset();
78 sound.reset();
79 bus.reset();
81 networking.reset();
82 logger->AddToCallStack("GameClass::dtor resources released");
83 // The callbacks were stopped before entering this destructor. Finish D3D
84 // after game resources, while the crash recorder can still report a fault.
85 logger->AddToCallStack("GameClass::dtor graphics device");
86 if (auto* renderer = Rendering::ClientRenderer()) renderer->Reset();
87 if (auto* host = Rendering::ClientHost()) host->Destroy();
88 logger->AddToCallStack("GameClass::dtor graphics device released");
89 logger.reset();
90}
91
93{
94 // Close and WM_DESTROY can both reach cleanup, including partial startup.
95 const HDEVNOTIFY notification = dev_notify;
96 dev_notify = nullptr;
97 if (notification && !UnregisterDeviceNotification(notification))
98 logger->Log("UnregisterDeviceNotification failed!", Logger::Error, HRESULT_FROM_WIN32(GetLastError()));
99}
100
101// ReSharper disable once CppMemberFunctionMayBeConst
103{
104 logger->AddToCallStack("GameClass::Close");
105
107
108
109 if (displaystage == GameState::STATUS_GAME) // keep from saving before initialized, does its own logging
111
112 networking->Close();
113 sound->Close();
114}
115
117{
118 bus->Scanner.Reset();
119 for (int i = 0; i < MAX_SCAN; i++)
120 playerships[i].align = 1;
121}
122
124{
125 SClientPacket outpacket; // NOLINT
126 outpacket.type = 36; // new scanner
127 outpacket.f_x = 1.0f; // request all data
128 outpacket.f_y = 0.0f; // NULL
129 outpacket.f_z = 0.0f; // NULL
130 outpacket.f_w = 0.0f; // vehicle ID unused for request all data
131 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
132}
133
134void GameClass::TouchFile(const WCHAR* str)
135{
136#if defined(_DEBUG) && defined(_TOUCHFILES)
137 // touch file so we know what the hell is real!
138 SYSTEMTIME st;
139 GetSystemTime(&st);
140 FILETIME ft;
141 if (!SystemTimeToFileTime(&st, &ft))
142 {
143 logger->Log("Bailing out in LoadSound trying to CreateFile @1", Logger::Level::Error);
144 return;
145 }
146
147 HANDLE handle;
148 handle = CreateFile(str, GENERIC_WRITE, FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
149 if (handle == INVALID_HANDLE_VALUE)
150 {
151 logger->Log("Bailing out in LoadSound trying to CreateFile: INVALID_HANDLE_VALUE @1", Logger::Level::Error);
152 }
153 else if (!SetFileTime(handle, nullptr, nullptr, &ft))
154 {
155 logger->Log("Bailing out in LoadSound trying to SetFileTime @1", Logger::Level::Error);
156 }
157 CloseHandle(handle);
158#endif
159}
160
162{
164#pragma region Mirrored on the Server
165
166 if (ourcockpit.vdat.clengine > -1)
168 if (ourcockpit.vdat.elevator > -1)
170 if (ourcockpit.vdat.hulllight > -1)
172 if (ourcockpit.vdat.windshield > -1)
176 if (ourcockpit.vdat.landing[0] > -1)
177 ourcockpit.vdat.landing[0] = 127;
178 if (ourcockpit.vdat.landing[1] > -1)
179 ourcockpit.vdat.landing[1] = 127;
180 if (ourcockpit.vdat.leftaileron > -1)
182 if (ourcockpit.vdat.leftengine > -1)
184 if (ourcockpit.vdat.leftwing > -1)
186 if (ourcockpit.vdat.monitor[0] > -1)
187 ourcockpit.vdat.monitor[0] = 127;
188 if (ourcockpit.vdat.monitor[1] > -1)
189 ourcockpit.vdat.monitor[1] = 127;
190 if (ourcockpit.vdat.monitor[2] > -1)
191 ourcockpit.vdat.monitor[2] = 127;
192 if (ourcockpit.vdat.monitor[3] > -1)
193 ourcockpit.vdat.monitor[3] = 127;
194 if (ourcockpit.vdat.monitor[4] > -1)
195 ourcockpit.vdat.monitor[4] = 127;
196 if (ourcockpit.vdat.monitor[5] > -1)
197 ourcockpit.vdat.monitor[5] = 127;
198 if (ourcockpit.vdat.monitor[6] > -1)
199 ourcockpit.vdat.monitor[6] = 127;
200 if (ourcockpit.vdat.overhead > -1)
202 if (ourcockpit.vdat.rcs > -1)
203 ourcockpit.vdat.rcs = 127;
206 if (ourcockpit.vdat.rightengine > -1)
208 if (ourcockpit.vdat.rightwing > -1)
210 if (ourcockpit.vdat.rudder > -1)
211 ourcockpit.vdat.rudder = 127;
212 if (ourcockpit.vdat.leftStrut > -1)
214 if (ourcockpit.vdat.rightStrut > -1)
216 if (ourcockpit.vdat.noseStrut > -1)
218 if (ourcockpit.vdat.vtail > -1)
219 ourcockpit.vdat.vtail = 127;
220 if (ourcockpit.vdat.htail > -1)
221 ourcockpit.vdat.htail = 127;
222 if (ourcockpit.vdat.thrustaug > -1)
224 if (ourcockpit.vdat.yawdamper > -1)
226 if (ourcockpit.vdat.baydoor > -1)
227 ourcockpit.vdat.baydoor = 127;
228 if (ourcockpit.vdat.flapsLE > -1)
229 ourcockpit.vdat.flapsLE = 127;
230 if (ourcockpit.vdat.flapsTE > -1)
231 ourcockpit.vdat.flapsTE = 127;
234 if (ourcockpit.vdat.leftBrake > -1)
236 if (ourcockpit.vdat.rightBrake > -1)
238 if (ourcockpit.vdat.antiIce > -1)
239 ourcockpit.vdat.antiIce = 127;
240 if (ourcockpit.vdat.biolock > -1)
241 ourcockpit.vdat.biolock = 127;
242 if (ourcockpit.vdat.steering > -1)
244 if (ourcockpit.vdat.vpt > -1)
245 ourcockpit.vdat.vpt = 127;
248 if (ourcockpit.vdat.autoflyte > -1)
250#pragma endregion
251
252 ourcockpit.vdatChanged = true;
253
254 bus->ComponentRcsRollFail = false;
255 bus->ComponentFcsRollFail = false;
256
257 bus->messages.clear();
258 bus->commandStream.clear();
259}
260
262{
265 else
266 PostQuitMessage(0);
267}
268
269void GameClass::ToggleFullScreen(bool goFullScreen)
270{
271 // want full screen (true) is windowed (true)
272 // want windowed (false) is windowed (true)
273 // want windowed (false) is full-screen (false)
274 if (goFullScreen && Rendering::ClientWindowed())
275 {
276 logger->Log("Rendering::ClientToggleFullscreen(true)");
278 maximized = false;
279 }
280 else if (!goFullScreen && !Rendering::ClientWindowed())
281 {
282 logger->Log("Rendering::ClientToggleFullscreen(false)");
284 }
285 if (GUI)
286 {
287 SetCursor(LoadCursor(nullptr, GUI->currentCursor));
288 SetCursor(LoadCursor(Rendering::ClientInstance(), GUI->currentCursor));
289 }
290 ShowCursor(true);
291}
292
294{
295 logger->AddToCallStack("GameClass::InitializeGame");
296
297 // Set starting gamestate
298 loadstage = 0;
300
301 // Set the randomization seed based on time so it is always different
302 time_t ltime;
303 time(&ltime);
304 srand(static_cast<unsigned int>(ltime));
305
306
308}
309
311{
312 logger->AddToCallStack("GameClass::InitDirectInput");
313 HRESULT hr;
314
315 logger->Log("InitDirectInput() called...");
316
317 try
318 {
319#pragma region DirectInput
320 logger->Log("Calling DirectInput8Create...");
321 if (!viewscreen->g_pDI && FAILED(hr = DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
322 IID_IDirectInput8, reinterpret_cast<void**>(&viewscreen->g_pDI), NULL)))
323 {
324 logger->Log("DirectInput8Create() failed!", Logger::Level::Warn);
325 return hr;
326 }
327 logger->Log("Done with DirectInput8Create!");
328#pragma endregion
329
330#pragma region Keyboard
331 logger->Log("Calling ptrKeyboard->Initialize...");
332 if (FAILED(hr = viewscreen->ptrKeyboard->Initialize(hDlg)))
333 return hr;
334 logger->Log("Done with ptrKeyboard->Initialize!");
335#pragma endregion
336
337#pragma region Joystick
338 logger->Log("Calling ptrJoystick->Initialize...");
340 logger->Log("Done with ptrJoystick->Initialize!");
341#pragma endregion
342 }
343 catch (const std::exception& e)
344 {
345 logger->Log(const_cast<char*>(e.what()), Logger::Level::Error);
346 }
347
348 logger->Log("InitDirectInput() exited successfully!");
349
350 return S_OK;
351}
352
353//--------------------------------------------------------------------------------------
354// Returns true if a particular depth-stencil format can be created and used with
355// an adapter format and backbuffer format combination.
356HRESULT CALLBACK GameClass::OnCreateDevice(Rendering::RenderDevice* pd3dDevice, const Rendering::SurfaceDescription* pBackBufferSurfaceDesc, void* pUserContext)
357{
358 GameClass* game = static_cast<GameClass*>(pUserContext);
359 game->logger->AddToCallStack("GameClass::OnCreateDevice");
360 game->logger->Log("Calling OnCreateDevice()...");
361
362 HRESULT hr;
363
364 V_RETURN(game->GUI->OnCreateDevice(pd3dDevice)); // 6 references (4 we track)
365
367 V_RETURN(game->graphics->g_pEffect->SetTechnique("TShader")); // now have 37 (5 we track) so apparently 21 for the different samplers, etc?
368
369 V_RETURN(game->viewscreen->OnCreateDevice(pd3dDevice)); // now have 78 ... added 41 (48 we track, added 43)
370
371
372 // Recreate display resources before switching to loading because that switch prevents the
373 // subsequent OnResetDevice callback from taking its STATUS_GAME branch.
376 {
377 game->logger->Log("Device replacement: restarting asset loading with the current vehicle state", Logger::Level::Debug);
378 game->displays->OnCreateDevice();
379
380 game->GUI->furtherdelay = 0.5f;
381 game->GUI->fade = 0.0f;
382 game->GUI->cloudmotion = 0.0f; // for zoom
383 game->GUI->eyemotion = 0.0f;
384 game->GUI->eyeReveal.Reset();
385
387 game->UpdateTrackedResource("m_pddsGUIActions", 3);
388
389 game->loadstage = game->stage = game->instage = 0;
391 game->logger->Log("Advanced to STATUS_LOADING");
392 game->discord->UpdatePresence("Loading Screen", "Loading game assets...", "loading");
393 }
394
395 game->logger->Log("OnCreateDevice() done!");
396 return S_OK;
397}
398
400{
404 gameWindowShown = true;
405 logger->Log("First game frame presented; applying game window placement");
406 SetWindowLong(Rendering::ClientWindow(), GWL_STYLE, WS_CAPTION | WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX | WS_MAXIMIZE);
408 {
409 const HRESULT hr = Rendering::ClientHost()->SetFullscreen(true);
410 if (FAILED(hr)) return hr;
411 maximized = false;
412 SetCursor(LoadCursor(nullptr, GUI->currentCursor));
413 }
414 else
415 {
416 maximized = true;
417 ShowWindow(Rendering::ClientWindow(), SW_MAXIMIZE);
418 }
419 SetFocus(Rendering::ClientWindow());
420 return S_OK;
421}
422
424{
425 logger->Log("game->GUI->g_HUD Initializing...");
426 logger->AddToCallStack("game->GUI->g_HUD Initializing...");
427
431
432 HRESULT hr;
433 V_RETURN(GUI->g_HUD.SetFont(0, L"DejaVu Sans Mono", static_cast<LONG>(12.0f * displayscale), FW_NORMAL));
434 V_RETURN(GUI->g_HUD.SetFont(1, L"Comic Sans MS", static_cast<LONG>(24.0f * displayscale), FW_NORMAL));
435 GUI->g_HUD.SetLocation(0, 0);
436
437 V_RETURN(GUI->g_HUD.AddStatic(IDC_REJOINTEXT, L"", static_cast<int>((designedWidthC * 0.5f - 200.0f) * displayscale), static_cast<int>((designedHeightC * 0.5f - 135.0f) * displayscale), static_cast<int>(400.0f * displayscale), static_cast<int>(235.0f * displayscale)));
439 return E_FAIL;
442
443 V_RETURN(GUI->g_HUD.AddButton(IDC_REJOINBTN, GUI->strings[L_DEAD_BUTTON].c_str(), static_cast<int>((designedWidthC * 0.5f - 40.0f) * displayscale), static_cast<int>((designedHeightC * 0.5f + 25.0f) * displayscale), static_cast<int>(80.0f * displayscale), static_cast<int>(35.0f * displayscale), 0, true));
445 return E_FAIL;
447
448 return S_OK;
449}
450
451//--------------------------------------------------------------------------------------
452// This callback function will be called immediately after the Direct3D device has been
453// reset, which will happen after a lost device scenario. This is the best location to
454// create Rendering::ResourcePool::Device resources since these resources need to be reloaded whenever
455// the device is lost. Resources created here should be released in the OnLostDevice
456// callback.
457//--------------------------------------------------------------------------------------
458HRESULT CALLBACK GameClass::OnResetDevice(Rendering::RenderDevice* pd3dDevice, const Rendering::SurfaceDescription* pBackBufferSurfaceDesc, void* pUserContext)
459{
460 GameClass* game = static_cast<GameClass*>(pUserContext);
461 game->logger->AddToCallStack("GameClass::OnResetDevice");
462
463 HRESULT hr;
464 //hr = game->graphics->g_pEffect->OnResetDevice();
465 //if (!SUCCEEDED(hr))
466 // game->logger->Log("game->graphics->g_pEffect->OnResetDevice()", Logger::Level::Fatal, hr);
467 //game->UpdateTrackedResource("g_pEffect", 2);
468
469 char msg[99];
470 sprintf_s(msg, sizeof msg, "GameClass::OnResetDevice() DS %i", game->displaystage);
471 game->logger->Log(msg);
472
473 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
474 switch (game->displaystage)
475 {
476 case GameState::STATUS_SPLASH: // used B4
477 case GameState::STATUS_LOGIN: // used B4
478 case GameState::STATUS_CREATE: // used B4
479
480 V(game->graphics->OnResetDevice()); // g_pEffect only
481
482 game->GUI->OnResetDevice(); // g_pSprite and dialogmanager only
483 break;
484
485 case GameState::STATUS_LOADING: // used B4
486 V(game->graphics->OnResetDevice()); // g_pEffect only
487
488 game->GUI->OnResetDevice(); // g_pSprite and dialogmanager only
489
490 V_RETURN(game->viewscreen->OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc));
491 game->gameGraphicsReady = true;
492 game->displays->OnResetDevice();
493 break;
494
495 case GameState::STATUS_GAME: // STATUS_GAME
496 V(game->graphics->OnResetDevice()); // g_pEffect only
497 V_RETURN(game->viewscreen->OnResetDevice(pd3dDevice, pBackBufferSurfaceDesc));
498 game->gameGraphicsReady = true;
499
500 game->GUI->OnResetDevice();
501
503
504 game->displays->OnResetDevice();
505
506 break;
507 }
508
509 game->logger->Log("OnResetDevice() done!");
510 game->logger->AddToCallStack("GameClass::OnResetDevice DONE");
511
512 return S_OK;
513}
514
515void GameClass::UseOrDisuseInventoryItemType(int itemtype, int itemsubtype, int itemId, int vehicleId) const
516{
517 logger->AddToCallStack("GameClass::UseOrDisuseInventoryItemType");
518
519 // disuse or switching
521 itemtype = 0; // removed
522
524 {
525 g_fFOV = RiseMath::ToRadian(115.0f);
527 }
528
529 // using an item or new item
530 if (itemtype == 1 && itemsubtype == KitType::Binoculars && viewscreen->InventoryItemEffectsEnabled())
531 {
532 g_fFOV = RiseMath::ToRadian(12.0f);
534 }
535
536 ourcockpit.inventoryItemInUseType = itemtype; // 0 is none
537 ourcockpit.inventoryItemInUseSubType = itemsubtype; // 0 is none
539 ourcockpit.inventoryItemInUseVehicleId = vehicleId; // 0 is personal inventory
540}
541
542//--------------------------------------------------------------------------------------
543// This callback function will be called once at the beginning of every frame. This is the
544// best location for your application to handle updates to the scene, but is not
545// intended to contain actual rendering calls, which should instead be placed in the
546// OnFrameRender callback.
547//--------------------------------------------------------------------------------------
548void CALLBACK GameClass::OnFrameMove(double fTime, float fElapsedTime, void* pUserContext)
549{
550 GameClass* game = static_cast<GameClass*>(pUserContext);
551
552 char msg[99];
553 sprintf_s(msg, sizeof msg, "GameClass::OnFrameMove %i", game->displaystage);
554 game->logger->AddToCallStack(msg);
555
556 game->FrameElapsedTime = fElapsedTime;
557 game->discord->FrameMove();
558
559 if (game->lastDeviceChange < 2.0f)
560 {
561 game->lastDeviceChange += fElapsedTime;
562 if (game->lastDeviceChange >= 2.0f)
563 {
564 if (game->lastDeviceChangedSound)
565 {
566 game->sound->Reset();
567 game->lastDeviceChangedSound = false;
568 }
569
570 if (game->lastDeviceChangedInput)
571 {
574 game->lastDeviceChangedInput = false;
575 }
576
577 // update after everything is done because new BASS_Init system will have new device enumeration
580 }
581 }
582
583
584 game->logger->AddToCallStack("GameClass::lastDeviceChange");
585
586
587 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
588 switch (game->displaystage)
589 {
591 {
592 if (game->loadstage < SOUND_APTRIMCLACKER)
593 {
594 game->sound->LoadSounds(game->loadstage);
596 game->loadstage++;
597 }
598 else
599 {
600 game->GUI->FadeIn(0.6f, fElapsedTime);
601 }
602
604 game->sound->loopintro = false;
605
607 (game->sound->musicstage == GameState::STATUS_LOGIN || (!game->sound->loopintro && !game->sound->g_pSoundIntro)))
608 game->logger->Log("Oops, this is where we were skipping ahead in STATUS_SPLASH before all resources were loaded!", Logger::Level::Debug);
609
611 (game->sound->musicstage == GameState::STATUS_LOGIN || (!game->sound->loopintro && !game->sound->g_pSoundIntro)))
612 {
613 game->GUI->furtherdelay += fElapsedTime;
614 if (game->GUI->furtherdelay > 0.5f) // wait until the part of the song
615 {
616 if (!game->GUI->m_pddsGUIParts)
617 {
618 game->logger->Log("Somehow we are advancing to STATUS_LOGIN with a null MOTD GLASS!", Logger::Level::Error);
619 game->LoadTexture(&game->GUI->m_pddsGUIParts, "m_pddsGUIParts", L"Textures\\Glass.png");
620 }
621
622 if (!game->GUI->m_pddsGUIScroll)
623 {
624 sprintf_s(msg, sizeof msg, "Somehow we are advancing to STATUS_LOGIN with a null m_pddsGUIScroll %i!", game->loadstage);
625 game->logger->Log(msg, Logger::Level::Error);
626 game->LoadTexture(&game->GUI->m_pddsGUIScroll, "m_pddsGUIScroll", L"Textures\\Logo.png");
627 }
628
629 game->GUI->furtherdelay = 0.5f;
630 game->GUI->fade = 0.0f;
631
632 game->loadstage = 0;
634 game->discord->UpdatePresence("Login Screen", "Waiting for credentials...", "login");
635
636 if (game->GUI->tm_time.tm_mon == 11 && game->GUI->tm_time.tm_mday >= 11 && game->GUI->tm_time.tm_mday <= 25) // December 11-25
637 {
638 // bells
639 game->sound->LoadCustomSound(SOUND_HOLIDAY, "Sounds\\Holidays\\christmas1.wav");
640 game->sound->Play(SOUND_HOLIDAY);
641 }
642 else if (game->GUI->tm_time.tm_mon == 9 && game->GUI->tm_time.tm_mday >= 17) // October 17-31
643 {
644 // howl
645 game->sound->LoadCustomSound(SOUND_HOLIDAY, "Sounds\\Holidays\\halloween3.mp3");
646 game->sound->Play(SOUND_HOLIDAY);
647 }
648
649 game->logger->Log("Advanced to STATUS_LOGIN");
650
651 game->GUI->CreateDialogs();
652 game->GUI->InitApp();
653 game->GUI->LoadConfiguration(); // user-defined
654 }
655 }
656
657 game->GUI->LightningCalculations(fElapsedTime);
658
659 game->networking->FrameMove(game->displaystage);
660 }
661 break;
662
664 {
665 if (game->loadstage < SOUND_ENUMERATION)
666 {
667 //game->GUI->fade = game->GUI->furtherdelay = 0.0f;
669 if (game->loadstage >= SOUND_APTRIMCLACKER)
670 game->sound->LoadSounds(game->loadstage);
671 game->loadstage++;
672 }
673
674 game->GUI->FadeIn(0.4f, fElapsedTime);
675
677 {
678 game->GUI->furtherdelay += fElapsedTime;
679 if (game->GUI->furtherdelay > 0.5f) // wait until the part of the song
680 {
681 if (!game->GUI->m_pddsGUIScroll)
682 {
683 sprintf_s(msg, sizeof msg, "Somehow we are advancing to STATUS_LOADING with a null m_pddsGUIScroll %i!", game->loadstage);
684 game->logger->Log(msg, Logger::Level::Error);
685 game->LoadTexture(&game->GUI->m_pddsGUIScroll, "m_pddsGUIScroll", L"Textures\\Logo.png");
686 }
687
688 // don't keep these
690 game->UpdateTrackedResource("m_pddsCloudBaseMapAndNetwork", 3);
692 game->UpdateTrackedResource("m_pddsLightningAndBackground[0]", 3);
694 game->UpdateTrackedResource("m_pddsLightningAndBackground[1]", 3);
696 game->UpdateTrackedResource("m_pddsLightningAndBackground[2]", 3);
697
698 game->GUI->furtherdelay = 0.5f;
699 game->GUI->fade = 0.0f;
700
701 game->loadstage = game->stage = game->instage = 0;
703 game->logger->Log("Advanced to STATUS_LOADING");
704 game->discord->UpdatePresence("Loading Screen", "Loading game assets...", "loading");
705 }
706 }
707
708 game->networking->FrameMove(game->displaystage);
709
710 game->GUI->LightningCalculations(fElapsedTime);
711 }
712 break;
713
715 {
716 if (game->GUI->rxbuffer > 0)
717 {
718 game->GUI->rxhold += fElapsedTime;
719 if (game->GUI->rxhold > 0.05f)
720 {
721 game->GUI->rxlight = !game->GUI->rxlight;
722 game->GUI->rxbuffer -= 3;
723 game->GUI->rxhold = 0.0f;
724 }
725 }
726 else
727 game->GUI->rxlight = false;
728 if (game->GUI->txbuffer > 0)
729 {
730 game->GUI->txhold += fElapsedTime;
731 if (game->GUI->txhold > 0.05f)
732 {
733 game->GUI->txlight = !game->GUI->txlight;
734 game->GUI->txbuffer -= 3;
735 game->GUI->txhold = 0.0f;
736 }
737 }
738 else
739 game->GUI->txlight = false;
740
741 if (game->loadstage < 4)
742 {
744 //game->sound->LoadSounds(GameState::STATUS_CREATE, game->loadstage);
745 game->loadstage++;
746 game->GUI->furtherdelay = 0.0f;
747 }
748
749 if (game->loadstage >= 4 && (game->sound->musicstage == GameState::STATUS_LOADING || (!game->sound->loopintro && !game->sound->g_pSoundIntro && game->GUI->immigrationPassed)))
750 {
751 game->GUI->furtherdelay += fElapsedTime;
752 if (game->GUI->furtherdelay > 0.5f) // wait until the part of the song
753 {
754 game->GUI->furtherdelay = 0.5f;
755 game->GUI->fade = 0.0f;
756
757 game->loadstage = game->stage = game->instage = 0;
759 game->logger->Log("Advanced to STATUS_LOADING");
760 game->discord->UpdatePresence("Loading Screen", "Loading game assets...", "loading");
761
762 // this fixes the window size after we leave immigration
763 RECT rect;
764 if (!GetWindowRect(Rendering::ClientWindow(), &rect))
765 {
766 sprintf_s(msg, sizeof msg, "Error in GetWindowRect: %d", GetLastError());
767 game->logger->Log(msg, Logger::Fatal);
768 return;
769 }
770
771 const int loadingHeight = static_cast<int>(500.0f * game->displayscale);
772 const int loadingY = (rect.top + rect.bottom - loadingHeight) / 2;
773 if (!MoveWindow(Rendering::ClientWindow(), rect.left, loadingY, static_cast<int>(700.0f * game->displayscale), loadingHeight, true))
774 {
775 sprintf_s(msg, sizeof msg, "Error in MoveWindow: %d", GetLastError());
776 game->logger->Log(msg, Logger::Fatal);
777 return;
778 }
780
781 game->GUI->g_HUD.RemoveAllControls();
782 return;
783 }
784 }
785
786 game->networking->FrameMove(game->displaystage);
787
788 game->GUI->OnFrameMove(fElapsedTime);
789
791 }
792 break;
793
795 {
797 if (game->GUI->eyemotion >= 1.0f)
798 {
799 game->GUI->eyemotion = 1.0f;
800 game->sound->loopintro = false;
801 }
802
803 if (game->loadstage == 0)
804 game->GUI->furtherdelay = 0.0f;
805
806 // good idea but wrong implementation, results in confirmation packets sent like 10 times
807 // and isn't actually throttling the texture loading because it is done in framerender because of the
808 // output text
809 if (game->loadstage < 78)// && game->loadstage < (short)(game->GUI->eyemotion*78.0f)) // one per second
810 {
811 game->GUI->LoadTextures(GameState::STATUS_LOADING, game->loadstage); // 1 get eyezoom, 8 gets new msgs
812 }
813
814 if (game->loadstage == 78)
815 {
816 }
817 if (game->loadstage == 79)
818 {
819 }
820 if (game->loadstage == 80)
821 {
822 // Schedule the session download; the network pump waits for server login
823 // completion. Resource reloads must not clear waypoints already received.
825 }
826 if (game->loadstage == 81)
827 {
828 }
829
830 game->networking->FrameMove(GameState::STATUS_LOADING); // 5 send confirmation packet, raknetmsghandler process too though
831
832 game->GUI->fade += fElapsedTime / 5.8f; // fade in over six seconds (with music)
833 if (game->GUI->fade > 1.0f)
834 game->GUI->fade = 1.0f;
835
836 if (game->loadstage < 82)
837 game->loadstage++;
838
839 if (game->stage > 32 && !game->gameGraphicsReady)
840 {
841 game->logger->Log("Preparing game graphics in the loading window");
842 const double start = Rendering::ClientAbsoluteTime();
843 OnLostDevice(game);
845 if (FAILED(ready))
846 {
847 game->logger->Log("Loading-window graphics preparation failed", Logger::Level::Error, ready);
849 return;
850 }
851 sprintf_s(msg, sizeof msg, "Loading-window graphics ready in %.1f ms", (Rendering::ClientAbsoluteTime() - start) * 1000.0);
852 game->logger->Log(msg);
853 }
854
855 HRESULT cloudPrograms = S_OK;
857 {
858 // Spread first-use driver preparation over loading frames, including
859 // the base/inside/above-deck programs used by the subsequent ascent.
860 auto& clouds = *game->viewscreen->cloudVolume.Effect();
861 cloudPrograms = clouds.Pass().PrepareLoadingStep(Rendering::ClientRenderer()->Context(),
862 Rendering::ClientBackBufferDescription()->MultiSampleType, clouds.OrganicReady());
863 if (FAILED(cloudPrograms))
864 {
865 game->logger->Log("Loading cloud program preparation failed", Logger::Level::Error, cloudPrograms);
867 return;
868 }
869 }
870
871 game->loadingReadyToContinue = cloudPrograms == S_OK && game->loadstage >= 82 &&
872 game->stage > 32 && game->gameGraphicsReady && game->loadingLabelsReady;
873 if (game->loadingReadyToContinue && (game->sound->musicstage == GameState::STATUS_GAME || (!game->sound->loopintro && !game->sound->g_pSoundIntro)))
874 {
875 game->GUI->furtherdelay += fElapsedTime;
876 if (game->GUI->furtherdelay > 0.5f) // wait until the part of the song
877 {
878 game->GUI->furtherdelay = 0.5f;
879
881 game->UpdateTrackedResource("m_pddsGUIRanks", 3);
882 SAFE_RELEASE(game->GUI->m_pddsGUIParts); // because we are going to load Textures\\GUI\\gui.png in place of Textures\\Glass.png
883 game->UpdateTrackedResource("m_pddsGUIParts", 3);
885 game->UpdateTrackedResource("m_pddsGUIInterlace", 3);
887 game->UpdateTrackedResource("m_pddsGUIScroll", 3);
889 game->UpdateTrackedResource("m_pddsGUIScrollButton", 3);
891 game->UpdateTrackedResource("m_pddsGUIActions", 3);
892
893 game->GUI->OnFrameMove(fElapsedTime); // just calling once
894
895 game->loadstage = 0;
897 game->logger->Log("Advanced to STATUS_GAME");
898 game->discord->UpdateTelemetry();
899 const HRESULT hudResult = game->InitializeGameHud();
900 if (FAILED(hudResult))
901 {
902 game->logger->Log("Could not initialize the in-game HUD", Logger::Level::Fatal, hudResult);
903 return;
904 }
905
906 game->viewscreen->OnFrameMove(fTime, fElapsedTime);
907
908 // Keep the loading window size for the first real game frame.
909 game->GUI->LoadTextures(STATUS_GAME, 0);
910
911 break; // so we don't execute FrameMove below on the new displaystage
912 }
913 }
914 }
915 break;
916
918 {
919#if !defined(DIALOGHARNESS) | !defined(_DEBUG)
920
921 Rendering::ProfileScope11 networkSoundTiming("Network and sound update", false);
923 game->sound->FrameMove(fElapsedTime);
924 networkSoundTiming.Stop();
925
926 Rendering::ProfileScope11 viewscreenUpdateTiming("Viewscreen update", false);
927 game->viewscreen->OnFrameMove(fTime, fElapsedTime);
928 viewscreenUpdateTiming.Stop();
929
930#endif
931 Rendering::ProfileScope11 uiUpdateTiming("UI update", false);
932 game->GUI->OnFrameMove(fElapsedTime);
933 uiUpdateTiming.Stop();
934
935 game->bus->FrameMove(fElapsedTime);
936
937 for (size_t i = 0; i < game->bus->commandStream.size(); i++)
938 {
939 const Command command = game->bus->commandStream.at(i);
940
941 if (command.name == "UseInventoryItem")
942 {
943 if (!playerships[0].isSimulator)
944 {
945 const int itemIndex = command.ivalues[0];
946 int vehicleId;
947 InventoryHelper item;
948 if (command.bValue)
949 {
950 item = ourcockpit.personalInventory.at(itemIndex);
951 vehicleId = 0;
952 }
953 else
954 {
955 item = ourcockpit.vehicleInventory.at(itemIndex);
956 vehicleId = playerships[0].vehicleId;
957 }
958
959 if (item.type == 1) // General
960 {
961 switch (item.subtype)
962 {
964 if (game->bus->targetC >= 0)
965 {
966 SClientPacket outpacket = SClientPacket();
967 // 21=useinventory x=itemtype, y=itemsubtype, z=(0==personal 1==vehicle), w=serverarray
968 outpacket.type = 21; // use inventory on target
969 outpacket.f_x = static_cast<float>(item.type);
970 outpacket.f_y = static_cast<float>(item.subtype);
971 outpacket.f_z = command.bValue ? 0.0f : 1.0f;
972 outpacket.f_w = static_cast<float>(playerships[game->bus->scanslot[game->bus->targetC]].vehicleId);
973 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
974 }
975 else
976 {
978 }
979 break;
983 // client-side only
984 game->UseOrDisuseInventoryItemType(item.type, item.subtype, itemIndex, vehicleId);
985 break;
986 case KitType::ATM:
989 case KitType::RVR:
990 case KitType::ILS: // GLS
991 case KitType::NexRad:
992 {
993 SClientPacket outpacket = SClientPacket();
994 // 28=installinventory x=itemtype, y=itemsubtype, z=(0==personal 1==vehicle), w=serverarray
995 outpacket.type = 28; // install on target
996 outpacket.f_x = static_cast<float>(item.type);
997 outpacket.f_y = static_cast<float>(item.subtype);
998 outpacket.f_z = command.bValue ? 0.0f : 1.0f;
999 outpacket.f_w = 0.0f; // N/A
1000 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1001 break;
1002 }
1003 case KitType::Fireworks:
1004 case KitType::EVA_KIT:
1005 {
1006 SClientPacket outpacket = SClientPacket();
1007 // 21=useinventory x=itemtype, y=itemsubtype, z=(0==personal 1==vehicle), w=serverarray
1008 outpacket.type = 21; // use inventory on target
1009 outpacket.f_x = static_cast<float>(item.type);
1010 outpacket.f_y = static_cast<float>(item.subtype);
1011 outpacket.f_z = command.bValue ? 0.0f : 1.0f;
1012 outpacket.f_w = 0.0f; // N/A
1013 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1014 break;
1015 }
1016 case KitType::FirstAid:
1017 case KitType::CandyCane:
1018 {
1020
1021 unsigned char hitpoints = 255 - ourcockpit.hitpoints;
1022
1023 if (hitpoints > 0)
1024 {
1025 // clamp to what is left in the hypospray @TODO can't do this yet since we don't have the hitpoints for the item over the wire
1026 //hitpoints = RiseMath::Min(hitpoints, item.quantity);
1027 //ourcockpit.hitpoints += hitpoints;
1028 //ourcockpit.vdatChanged = true;
1029
1030 game->sound->Play(HYPOSPRAY_START);
1031 float delay = 0.173f + 0.081f * hitpoints / 10.0f;
1032 game->sound->AddDelayedSound(HYPOSPRAY_END, delay);
1033
1034 SClientPacket outpacket = SClientPacket();
1035 // 21=useinventory x=itemtype, y=itemsubtype, z=(0==personal 1==vehicle), w=serverarray
1036 outpacket.type = 21; // use inventory on target
1037 outpacket.f_x = static_cast<float>(item.type);
1038 outpacket.f_y = static_cast<float>(item.subtype);
1039 outpacket.f_z = command.bValue ? 0.0f : 1.0f;
1040 outpacket.f_w = hitpoints; // amount we want to use
1041 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1042 break;
1043 }
1044
1045 break;
1046 }
1047 default:
1048 game->logger->Log("Received request to UseInventoryItem but unhandled General subtype!", Logger::Level::Error);
1049 break;
1050 }
1051 }
1052 else
1053 {
1054 game->logger->Log("Received request to UseInventoryItem but unhandled type!", Logger::Level::Error);
1055 }
1056 }
1057 else
1058 {
1060 }
1061 game->bus->commandStream.erase(game->bus->commandStream.begin() + static_cast<int>(i));
1062 }
1063 else if (command.name == "TransferInventoryItem")
1064 {
1065 if (!playerships[0].isSimulator)
1066 {
1067 const int itemIndex = command.ivalues[0];
1068 int itemType, itemSubType;
1069 if (command.bValue)
1070 {
1071 itemType = ourcockpit.personalInventory.at(itemIndex).type;
1072 itemSubType = ourcockpit.personalInventory.at(itemIndex).subtype;
1073 }
1074 else
1075 {
1076 itemType = ourcockpit.vehicleInventory.at(itemIndex).type;
1077 itemSubType = ourcockpit.vehicleInventory.at(itemIndex).subtype;
1078 }
1079
1082 game->UseOrDisuseInventoryItemType(0, 0, 0, 0);
1083
1084 SClientPacket outpacket = SClientPacket();
1085 // 26=transferinventory x=itemtype, y=itemsubtype, z=(0==personal 1==vehicle), w=
1086 outpacket.type = 26; // transfer inventory to target
1087 outpacket.f_x = static_cast<float>(itemType);
1088 outpacket.f_y = static_cast<float>(itemSubType);
1089 outpacket.f_z = static_cast<float>(command.ivalues[1]); // 0 is personal, 1 is vehicle
1090 outpacket.f_w = 0.0f; // unused
1091 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1092 }
1093 else
1094 {
1096 }
1097 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1098 }
1099 else if (command.name == "SwapInventoryItem")
1100 {
1101 if (!playerships[0].isSimulator)
1102 {
1103 const int itemIndex = command.ivalues[0];
1104 int itemType, itemSubType, vehicleId;
1105 if (command.bValue) // WAS on person is true
1106 {
1107 itemType = ourcockpit.personalInventory.at(itemIndex).type;
1108 itemSubType = ourcockpit.personalInventory.at(itemIndex).subtype;
1109 vehicleId = playerships[0].vehicleId; // was on person, now in vehicle
1110 }
1111 else
1112 {
1113 itemType = ourcockpit.vehicleInventory.at(itemIndex).type;
1114 itemSubType = ourcockpit.vehicleInventory.at(itemIndex).subtype;
1115 vehicleId = 0; // was in vehicle (cabin), now on person (baggage)
1116 }
1117
1119 ourcockpit.inventoryItemInUseVehicleId = vehicleId; // update vehicleId
1120
1121 SClientPacket outpacket = SClientPacket();
1122 // 27=swapinventory x=itemtype, y=itemsubtype, z=(0==from personal 1==from vehicle), w=serverarray
1123 outpacket.type = 27; // swap inventory
1124 outpacket.f_x = static_cast<float>(itemType);
1125 outpacket.f_y = static_cast<float>(itemSubType);
1126 outpacket.f_z = static_cast<float>(command.ivalues[1]); // 0 is personal2vehicle, 1 is vehicle2personal
1127 outpacket.f_w = 0.0f; // no vehicle needed
1128 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1129 }
1130 else
1131 {
1133 }
1134 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1135 }
1136 else if (command.name == "TransferWeapon")
1137 {
1138 if (!playerships[0].isSimulator)
1139 {
1140 SClientPacket outpacket = SClientPacket();
1141 outpacket.type = 19; // cash/fuel/weapon transfer
1142 outpacket.f_x = 0.0f; // cash
1143 outpacket.f_y = 0.0f; // fuel
1144 outpacket.f_z = 1.0f; // weapon
1145 outpacket.f_w = static_cast<float>(command.ivalues[0]);
1146 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1147 }
1148 else
1149 {
1151 }
1152 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1153 }
1154 else if (command.name == "ToggleAvionics")
1155 {
1156 if (command.ivalues[0] == 3)
1157 {
1159 game->networking->SendEvent(EventType::EVENT_RADIO, ourcockpit.radioPower ? static_cast<float>(game->bus->station) : 0.0f);
1160 if (game->sound->g_pSoundIntro)
1161 BASS_ChannelStop(game->sound->g_pSoundIntro);
1163 }
1164 else if (command.ivalues[0] == 4)
1165 {
1168 RtlZeroMemory(&game->bus->assayGrid, sizeof SAssayGrid);
1169 game->bus->assayGrid.tcp = game->bus->tcp;
1170 }
1171 else if (command.ivalues[0] == 5)
1172 {
1175 }
1176 else if (command.ivalues[0] == 6)
1177 {
1178 if (!playerships[0].transponder && ourcockpit.vdat.vpt > 0)
1179 {
1180 playerships[0].transponder = true;
1182 }
1183 else if (playerships[0].transponder)
1184 {
1185 playerships[0].transponder = false;
1187 }
1188 }
1189 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1190 }
1191 else if (command.name == "RadioStation")
1192 {
1193 game->networking->SendEvent(EventType::EVENT_RADIO, ourcockpit.radioPower ? static_cast<float>(game->bus->station) : 0.0f);
1194 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1195 }
1196 else if (command.name == "SoundMidwayTarget")
1197 {
1201 game->bus->commandStream.erase(game->bus->commandStream.begin() + i);
1202 }
1203 }
1204
1206 {
1207 SClientPacket outpacket; // NOLINT
1208 outpacket.type = 11; // Menu type
1209 outpacket.f_x = static_cast<float>(interactive.outboundMenuSelect); // selection
1210 outpacket.f_y = 0.0f; // NULL
1211 outpacket.f_z = 0.0f; // NULL
1212 outpacket.f_w = 0.0f; // NULL
1213 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1215 }
1216 }
1217 break;
1218 }
1219
1220
1221 // Runs in every stage so death, loading and logout clear the hearing effect.
1222 game->sound->FrameMoveEarPressure(fElapsedTime);
1223 game->sound->FrameMoveHorns();
1224 game->sound->FrameMoveWipers(fElapsedTime);
1225 game->viewscreen->ptrCockpit->FrameMovePropSounds(fElapsedTime);
1226 // Refresh attached loops and one-shots after the current camera pose is known.
1228
1229 game->logger->AddToCallStack("GameClass::OnFrameMove END");
1230}
1231
1232//--------------------------------------------------------------------------------------
1233// This callback function will be called at the end of every frame to perform all the
1234// rendering calls for the scene, and it will also be called if the window needs to be
1235// repainted. After this function has returned, DXUT will call
1236// Rendering::RenderDevice::Present to display the contents of the next buffer in the swap chain
1237//--------------------------------------------------------------------------------------
1238void CALLBACK GameClass::OnFrameRender(Rendering::RenderDevice* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext)
1239{
1240 GameClass* game = static_cast<GameClass*>(pUserContext);
1241
1242 char msg[99];
1243 sprintf_s(msg, sizeof msg, "GameClass::OnFrameRender (%i)", game->displaystage);
1244 game->logger->AddToCallStack(msg);
1245
1246 // ReSharper disable once CppEntityAssignedButNoRead
1247 HRESULT hr;
1248
1249 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
1250 switch (game->displaystage)
1251 {
1254 if (SUCCEEDED(pd3dDevice->BeginScene()))
1255 {
1256 V(pd3dDevice->Clear(0, NULL, Rendering::ClearFlags::TARGET | Rendering::ClearFlags::ZBUFFER, 0L, 1.0f, 0));
1257
1263
1264 game->GUI->OnRender(fElapsedTime, pd3dDevice);
1265
1266 //If succeeded beginscene, and we get here, end it
1267 V(pd3dDevice->EndScene());
1268 }
1269 break;
1270
1271 case GameState::STATUS_CREATE: // he used his own OnFrameRenderCreate
1272 if (SUCCEEDED(pd3dDevice->BeginScene()))
1273 {
1274 V(pd3dDevice->Clear(0, NULL, Rendering::ClearFlags::TARGET | Rendering::ClearFlags::ZBUFFER, 0L, 1.0f, 0));
1275
1281
1282 game->graphics->DrawImmigration(pd3dDevice, fElapsedTime);
1283
1284 //If succeeded beginscene, and we get here, end it
1285 V(pd3dDevice->EndScene());
1286 }
1287 break;
1288
1290 if (SUCCEEDED(pd3dDevice->BeginScene()))
1291 {
1292 V(pd3dDevice->Clear(0, NULL, Rendering::ClearFlags::TARGET | Rendering::ClearFlags::ZBUFFER, game->GUI->fade == 1.0f ? Rendering::ColorRGB(static_cast<short>(255.0f * game->GUI->furtherdelay / 0.5f), static_cast<short>(255.0f * game->GUI->furtherdelay / 0.5f), static_cast<short>(255.0f * game->GUI->furtherdelay / 0.5f)) : Rendering::ColorRGB(static_cast<short>(game->GUI->fade * 255.0f), static_cast<short>(game->GUI->fade * 255.0f), static_cast<short>(game->GUI->fade * 255.0f)), 1.0f, 0));
1293 //V(pd3dDevice->Clear(0, NULL, Rendering::ClearFlags::TARGET | Rendering::ClearFlags::ZBUFFER, 0xFFFFFFFF, 1.0f, 0));
1294
1300
1301 game->GUI->OnRender(fElapsedTime, pd3dDevice);
1302
1303 if (game->stage == 0)
1304 {
1305 game->logger->Log("#include TEXTURES called!");
1306 game->instage = -1;
1307 }
1308
1309 game->viewscreen->ptrRenderer->LoadTextures(pd3dDevice, &game->stage, &game->instage);
1310
1311 if (game->stage == 31)
1312 {
1313 game->logger->Log("#include TEXTURES exited successfully!");
1314 game->instage = -1;
1315 }
1316
1317 // load remaining sounds
1318 if (game->stage == 32)
1319 {
1320 game->instage = -1;
1321 deathinhibit = 5.0f; // proceeding to game, don't hiccup and die right away
1322 }
1323
1324 if (game->instage == -1)
1325 {
1326 game->stage++;
1327 game->instage = 0;
1328 }
1329
1330 //If succeeded beginscene, and we get here, end it
1331 V(pd3dDevice->EndScene());
1332 }
1333 if (game->stage > 32 && game->gameGraphicsReady && !game->loadingLabelsReady)
1334 game->loadingLabelsReady = game->viewscreen->PrepareHullTextures(pd3dDevice);
1335 break;
1336
1338 {
1339 // Outside view (may include dynamic texture for simulator screen)
1340
1341
1342 // He leaves a BeginScene() unclosed for us
1343 game->viewscreen->OnFrameRender(pd3dDevice, fTime);
1344
1345
1347
1351
1352
1353 if (!game->timeLapse)
1354 {
1355
1356 Rendering::ProfileScope11 timing("Dialogs and UI");
1357 game->GUI->OnRender(fElapsedTime, pd3dDevice);
1358
1359 game->logger->AddToCallStack("GameClass g_HUD.OnRender");
1360 V(game->GUI->g_HUD.OnRender(fElapsedTime));
1361
1362 }
1363
1364 if (game->viewscreen->adDiagnostics.Enabled())
1365 {
1366 const auto* screen=Rendering::ClientBackBufferDescription();
1367 std::vector<RECT> bounds;
1368 std::vector<DirectX::XMFLOAT4> masks;
1369 if (game->viewscreen->adDiagnostics.Collecting())
1370 {
1371 game->GUI->g_HUD.AppendVisibleBounds(bounds);
1372 for (const auto* dialog:DialogBase::dialogs)if (dialog && dialog->active)
1373 {
1374 const float scale=game->displayscale;
1375 bounds.push_back({LONG(dialog->windowlocation.x*scale),LONG(dialog->windowlocation.y*scale),
1376 LONG((dialog->windowlocation.x+dialog->width)*scale),LONG((dialog->windowlocation.y+dialog->height+96)*scale)});
1377 dialog->HUD.AppendVisibleBounds(bounds);
1378 }
1379 // The GUI bottom bar spans the entire display, including its slide animation.
1380 bounds.push_back({0,LONG(screen->Height)-LONG(64*game->displayscale),LONG(screen->Width),LONG(screen->Height)});
1381 }
1382 // Draw and mask the same readout. Its layout rectangle is not an
1383 // opaque full-width panel; empty space beside/below the text is clear.
1384 game->viewscreen->adDiagnostics.DrawOverlay(game->GUI->g_pFont,game->GUI->g_pTextSprite,screen->Width,screen->Height,
1385 game->viewscreen->adDiagnostics.Collecting() ? &bounds : nullptr);
1386 for (const auto& rect:bounds)masks.push_back({float(rect.left)/screen->Width,float(rect.top)/screen->Height,
1387 float(rect.right)/screen->Width,float(rect.bottom)/screen->Height});
1388 game->viewscreen->adDiagnostics.FinishScene(*pd3dDevice,
1390 }
1391
1392 // Need to close this finally now that everything is drawn
1393 // We will have switched to the device endscene even if we were in a simulator by this point
1394 if (game->beginScene == 1)
1395 {
1396 V(pd3dDevice->EndScene());
1397 game->beginScene = 0;
1398 }
1399 else
1400 {
1401 sprintf_s(msg, sizeof msg, "Found a %i when trying to EndScene", game->beginScene);
1402 game->logger->Log(msg, Logger::Level::Fatal);
1403 }
1404
1407
1408 // Dynamic textures for license plates and instrumentation
1409 // He has his own BeginScene() and EndScene() so it is not left open
1410 game->viewscreen->OnFrameRender2(pd3dDevice, fElapsedTime);
1411
1412#if defined(TIMELAPSE) && defined(_DEBUG)
1413 static float timelapseTimer = 0.0f;
1414 static int timelapseFrame = 0;
1415 static float oldElevation = game->viewscreen->ptrWeather->elevation;
1416 static bool active = false;
1417
1418 if (game->timeLapse && oldElevation < -0.104528463f && game->viewscreen->ptrWeather->elevation >= -0.104528463f)
1419 active = true;
1420 if (active && game->viewscreen->ptrWeather->elevation < -0.104528463f)
1421 exit(0);
1422
1423 if (active)
1424 {
1425 timelapseTimer += fElapsedTime;
1426 if (timelapseTimer >= 2.356f)
1427 {
1428 timelapseTimer -= 2.356f;
1429
1430 Rendering::RenderSurface* pBackBuffer = nullptr;
1431 V(pd3dDevice->GetBackBuffer(0, 0, 0, &pBackBuffer));
1432
1433 WCHAR szFileName[99];
1434 swprintf_s(szFileName, 99, L"Screenshots\\Screenshot_%06d.png", timelapseFrame);
1435 Rendering::SaveSurfaceToFile(szFileName, Rendering::ImageFile::PNG, pBackBuffer, nullptr, nullptr);
1436 SAFE_RELEASE(pBackBuffer);
1437
1438 timelapseFrame++;
1439 }
1440 }
1441 oldElevation = game->viewscreen->ptrWeather->elevation;
1442#endif
1443
1444 }
1445 break;
1446 }
1447
1448 game->logger->AddToCallStack("GameClass::OnFrameRender DONE");
1449}
1450
1452{
1453 if (!playerships[0].groundvehicle) // can't turn on FD without AFCS
1454 {
1455 // ReSharper disable once CppExpressionWithoutSideEffects
1456 TurnOffDOR();
1457 // ReSharper disable once CppExpressionWithoutSideEffects
1458 TurnOffTVM();
1459
1461 {
1462 if (playerships[0].reference == REF_ONGROUND)
1464 else
1465 {
1467 if (fabsf(bus->RollAttitudeRadians) < 0.087266462599716478846184538424431f) // 5°
1468 bus->AFCS.DesiredRollRadians = 0.0f;
1469 else if (fabsf(bus->RollAttitudeRadians) >= RiseMath::Pi)
1470 bus->AFCS.DesiredRollRadians = 0.0f;
1471 else
1473 }
1474 }
1476 {
1477 if (playerships[0].reference == REF_ONGROUND)
1479 else
1480 {
1483 }
1484 }
1485
1487 }
1488}
1489
1490//--------------------------------------------------------------------------------------
1491// Before handling window messages, DXUT passes incoming windows
1492// messages to the application through this callback function. If the application sets
1493// *pbNoFurtherProcessing to TRUE, then DXUT will not process this message.
1494//--------------------------------------------------------------------------------------
1495LRESULT CALLBACK GameClass::MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool* pbNoFurtherProcessing, void* pUserContext)
1496{
1497 GameClass* game = static_cast<GameClass*>(pUserContext);
1498 game->logger->AddToCallStack("GameClass::MsgProc");
1499#ifdef ChatEnter
1500 const bool traceEnter = HudDiagnostics::IsEnterMessage(uMsg, wParam);
1501 if (traceEnter && game->GUI)
1502 {
1503 char event[160];
1504 sprintf_s(event, sizeof event,
1505 "window message=0x%04X flags=0x%08lX repeat=%d numpad=%d alt=%d ctrl=%d shift=%d",
1506 uMsg, static_cast<unsigned long>(lParam), (lParam & (1L << 30)) != 0,
1507 (lParam & (1L << 24)) != 0, (GetKeyState(VK_MENU) & 0x8000) != 0,
1508 (GetKeyState(VK_CONTROL) & 0x8000) != 0, (GetKeyState(VK_SHIFT) & 0x8000) != 0);
1509 HudDiagnostics::LogChatInput(*game->GUI, event);
1510 }
1511#endif
1512
1513 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
1514 switch (uMsg)
1515 {
1517 *pbNoFurtherProcessing = true;
1519 return 0;
1520
1521 case WM_SYSCOMMAND:
1522 if (wParam == SC_RESTORE)
1523 return 0;
1524 break;
1525
1526 case WM_CREATE:
1527 {
1528 game->logger->Log("GameClass::MsgProc WM_CREATE");
1529
1530 DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
1531 ZeroMemory(&NotificationFilter, sizeof DEV_BROADCAST_DEVICEINTERFACE);
1532 NotificationFilter.dbcc_size = sizeof DEV_BROADCAST_DEVICEINTERFACE;
1533 NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
1534 NotificationFilter.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
1535 game->dev_notify = RegisterDeviceNotification(hWnd, &NotificationFilter, DEVICE_NOTIFY_WINDOW_HANDLE);
1536 if (game->dev_notify == nullptr)
1537 {
1538 game->logger->Log("Could not register for device notifications!", Logger::Fatal, HRESULT_FROM_WIN32(GetLastError()));
1539 }
1540 // The native HWND exists, but the HUD and GPU resources do not yet.
1541 *pbNoFurtherProcessing = true;
1542 return 0;
1543 }
1544
1545 case WM_CLOSE:
1546 {
1547 game->RequestClose();
1548 *pbNoFurtherProcessing = true;
1549 return 0;
1550 }
1551
1552 case WM_DEVICECHANGE:
1553 {
1554 game->logger->Log("GameClass::MsgProc WM_DEVICECHANGE");
1555
1556 if (lParam)
1557 {
1558 const auto lpdb = PDEV_BROADCAST_HDR(lParam);
1559 if (lpdb->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)
1560 {
1561 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
1562 switch (wParam)
1563 {
1564 case DBT_DEVICEARRIVAL:
1565 case DBT_DEVICEREMOVECOMPLETE:
1566 {
1567 const size_t oldDeviceCount = game->viewscreen->ptrJoystick->deviceList.size();
1569 if (oldDeviceCount != game->viewscreen->ptrJoystick->deviceList.size())
1570 {
1571 game->lastDeviceChangedInput = true;
1572 game->lastDeviceChange = 0.0f;
1573 }
1574 }
1575 break;
1576 }
1577 }
1578 }
1579
1580 const size_t oldDeviceCount = game->sound->deviceGuids.size();
1581 game->sound->EnumDevices();
1582 if (oldDeviceCount != game->sound->deviceGuids.size())
1583 {
1584 game->lastDeviceChangedSound = true;
1585 game->lastDeviceChange = 0.0f;
1586 }
1587 }
1588 break;
1589
1590 case WM_ACTIVATE:
1591 game->logger->Log("GameClass::MsgProc WM_ACTIVATE");
1592 break;
1593 case WM_NULL:
1594 game->logger->Log("GameClass::MsgProc WM_NULL");
1595 break;
1596 case WM_DESTROY:
1597 game->logger->Log("GameClass::MsgProc WM_DESTROY");
1599 break;
1600 case WM_ENABLE:
1601 game->logger->Log("GameClass::MsgProc WM_ENABLE");
1602 break;
1603 case WM_SETFOCUS:
1604 game->logger->Log("GameClass::MsgProc WM_SETFOCUS");
1605 break;
1606 case WM_KILLFOCUS:
1607 if (game->viewscreen) game->viewscreen->SetHornPressed(false);
1608 game->logger->Log("GameClass::MsgProc WM_KILLFOCUS");
1609 break;
1610 case WM_QUIT:
1611 game->logger->Log("GameClass::MsgProc WM_QUIT");
1612 break;
1613 case WM_SHOWWINDOW:
1614 game->logger->Log("GameClass::MsgProc WM_SHOWWINDOW");
1615 break;
1616
1617 case WM_MOVE:
1618 game->logger->Log("GameClass::MsgProc WM_MOVE");
1619 break;
1620
1621 case WM_SIZE:
1622 game->logger->Log("GameClass::MsgProc WM_SIZE");
1623 if (game->displaystage == GameState::STATUS_GAME && !IsIconic(hWnd))
1624 {
1626 {
1627 /*if (wParam == SIZE_RESTORED)
1628 {
1629 if (game->maximized)
1630 game->logger->Log("SIZE_RESTORED, calling ShowWindow SW_MINIMIZE");
1631 else
1632 game->logger->Log("SIZE_RESTORED, calling ShowWindow SW_MAXIMIZE");
1633 ShowWindow(hWnd, game->maximized ? SW_SHOWMINNOACTIVE : SW_MAXIMIZE);
1634 game->maximized = !game->maximized;
1635 }*/
1636
1637 RECT client;
1638 if (GetClientRect(hWnd, &client)) // && game->maximized)
1639 {
1640 char msg[999];
1641 sprintf_s(msg, sizeof msg, "old window resolution width%.0f height%.0f", game->displayWidth, game->displayHeight);
1642 game->logger->Log(msg);
1643 game->displayWidth = static_cast<float>(client.right - client.left);
1644 game->displayHeight = static_cast<float>(client.bottom - client.top);
1645 game->displayscale = game->config.scale;
1646 sprintf_s(msg, sizeof msg, "new window resolution width%.0f height%.0f", game->displayWidth, game->displayHeight);
1647 game->logger->Log(msg);
1648 }
1649 }
1650 else
1651 {
1652 char msg[999];
1653 sprintf_s(msg, sizeof msg, "old exclusive resolution width%.0f height%.0f", game->displayWidth, game->displayHeight);
1654 game->logger->Log(msg);
1655 game->displayWidth = static_cast<float>(Rendering::ClientBackBufferDescription()->Width);
1656 game->displayHeight = static_cast<float>(Rendering::ClientBackBufferDescription()->Height);
1657 game->displayscale = game->config.scale;
1658 sprintf_s(msg, sizeof msg, "new exclusive resolution width%.0f height%.0f", game->displayWidth, game->displayHeight);
1659 game->logger->Log(msg);
1660 }
1661 }
1662 break;
1663 }
1664
1665
1666 game->logger->AddToCallStack("GameClass::MsgProc (Before g_HUD.MsgProc)");
1667
1668 game->GUI->Edited = false;
1669 //if (!g_bTextInput)
1670 {
1671 // Give the dialogs a chance to handle the message first
1672 *pbNoFurtherProcessing = game->GUI->MsgProc(hWnd, uMsg, wParam, lParam);
1673 if (*pbNoFurtherProcessing)
1674 {
1675 game->GUI->Edited = true;
1676#ifdef ChatEnter
1677 if (traceEnter)
1678 HudDiagnostics::LogChatInput(*game->GUI, "handled by HMI");
1679#endif
1680 return 0;
1681 }
1682
1683 game->logger->AddToCallStack("RiseDialog::MsgProc");
1684 *pbNoFurtherProcessing = game->GUI->g_HUD.MsgProc(hWnd, uMsg, wParam, lParam);
1685 if (*pbNoFurtherProcessing)
1686 {
1687 game->GUI->Edited = true;
1688#ifdef ChatEnter
1689 if (traceEnter)
1690 HudDiagnostics::LogChatInput(*game->GUI, "handled by main HUD");
1691#endif
1692 return 0;
1693 }
1694 }
1695
1696 game->logger->AddToCallStack("GameClass::MsgProc (After g_HUD.MsgProc)");
1697
1698 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
1699 switch (uMsg)
1700 {
1701 case WM_RBUTTONDOWN:
1702 game->logger->Log("GameClass::MsgProc WM_RBUTTONDOWN");
1703 game->logger->AddToCallStack("GameClass::MsgProc WM_RBUTTONDOWN");
1704 // reset timeout
1705 game->GUI->g_bRightDown = true;
1706 break;
1707
1708 case WM_RBUTTONUP:
1709 game->logger->Log("GameClass::MsgProc WM_RBUTTONUP");
1710 game->logger->AddToCallStack("GameClass::MsgProc WM_RBUTTONUP");
1711 // reset timeout
1712 game->GUI->g_bRightDown = false;
1713 break;
1714
1715 case WM_RBUTTONDBLCLK:
1716 game->logger->Log("GameClass::MsgProc WM_RBUTTONDBLCLK");
1717 game->logger->AddToCallStack("GameClass::MsgProc WM_RBUTTONDBLCLK");
1718 // center up
1719 if (game->viewscreen && game->viewscreen->camera)
1720 {
1723 game->viewscreen->rolltilt = 0.0f;
1724 game->viewscreen->targetZoom = 1.0f;
1725
1726 if (game->GUI->informationDialog) // unavailable until STATUS_GAME
1728 }
1729 break;
1730
1731 case WM_CHAR:
1732 game->logger->Log("GameClass::MsgProc WM_CHAR");
1733 game->logger->AddToCallStack("GameClass::MsgProc WM_CHAR");
1734 if (g_bTextInput)
1735 {
1736 if (LOWORD(wParam) > 13) // valid ascii
1737 {
1738 if (strlen(outgoing) < 77)
1739 sprintf_s(outgoing, sizeof(outgoing), "%s%c", outgoing, LOWORD(wParam));
1740 }
1741 else if (LOWORD(wParam) == 13) // enter
1742 {
1743#ifdef ChatEnter
1744 HudDiagnostics::LogChatInput(*game->GUI, "Enter reached MFD/text-mode handler");
1745#endif
1746 if (g_bTextInput == 2) // server menu line input
1747 {
1748 // Send it
1749 SPacketBig outpacket = SPacketBig();
1750 strcpy_s(outpacket.msg, sizeof outpacket.msg, outgoing);
1751 outpacket.type = 6; // Requested line input
1752 outpacket.array = 0;
1753 game->networking->SendToServer(&outpacket, sizeof(SPacketBig), true);
1754 g_bTextInput = 0;
1755
1756 if (!interactive.avail)
1757 game->displays->RestorePage("MFD");
1758 }
1759 else if (g_bTextInput == 5) // cash transfer
1760 {
1761 int amount;
1762 if (sscanf_s(outgoing, "%d", &amount) == 1 && amount > 0.0f)
1763 {
1764 if (!playerships[0].isSimulator)
1765 {
1766 SClientPacket outpacket; // NOLINT
1767 outpacket.type = 19; // cash/fuel/weapon transfer
1768 outpacket.f_x = static_cast<float>(amount); // cash
1769 outpacket.f_y = 0.0f; // fuel
1770 outpacket.f_z = 0.0f; // weapon
1771 outpacket.f_w = static_cast<float>(temptarget);
1772 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1773 }
1774 }
1775 else
1776 {
1778 }
1779 g_bTextInput = 0;
1780 }
1781 else if (g_bTextInput == 6) // fuel transfer
1782 {
1783 int amount;
1784 if (sscanf_s(outgoing, "%d", &amount) == 1)
1785 {
1786 if (!playerships[0].isSimulator)
1787 {
1788 SClientPacket outpacket; // NOLINT
1789 outpacket.type = 19; // cash/fuel/weapon transfer
1790 outpacket.f_x = 0.0f; // cash
1791 outpacket.f_y = static_cast<float>(amount); // fuel
1792 outpacket.f_z = 0.0f; // weapon
1793 outpacket.f_w = static_cast<float>(temptarget);
1794 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1795 }
1796 }
1797 else
1798 {
1800 }
1801 g_bTextInput = 0;
1802 }
1803 else if (g_bTextInput == 8) // fuel jettison
1804 {
1805 int amount;
1806 if (sscanf_s(outgoing, "%d", &amount) == 1 && amount < 0)
1807 {
1808 if (-amount > fuel / Kg2Lbs)
1809 {
1811 }
1812 else
1813 {
1814 fuel += amount * Kg2Lbs;
1815
1816 SClientPacket outpacket; // NOLINT
1817 outpacket.type = 4; // jettison fuel
1818 outpacket.f_x = -static_cast<float>(amount); // fuel lbs
1819 outpacket.f_y = 0.0f; // unused
1820 outpacket.f_z = 0.0f; // unused
1821 outpacket.f_w = 0.0f; // unused
1822 game->networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1823 }
1824 }
1825 else
1826 {
1828 }
1829 g_bTextInput = 0;
1830 }
1831
1832 }
1833 else if (LOWORD(wParam) == 8) // backspace
1834 {
1835 const size_t len = strlen(outgoing);
1836 if (len > 0)
1837 outgoing[len - 1] = 0;
1838 }
1839 }
1840 break;
1841 }
1842
1843 game->logger->AddToCallStack("GameClass::MsgProc END");
1844#ifdef ChatEnter
1845 if (traceEnter)
1846 HudDiagnostics::LogChatInput(*game->GUI, "window message finished; returned to DXUT");
1847#endif
1848
1849 return 0;
1850}
1851
1852void GameClass::LoadTexture(Rendering::RenderTexture** resource, const std::string& pointerName, const WCHAR* file, Rendering::ImageFormat format)
1853{
1854 logger->AddToCallStack("GameClass::LoadTexture");
1855
1856 // release
1857 if (*resource)
1858 {
1859 SAFE_RELEASE(*resource);
1860 UpdateTrackedResource(pointerName.c_str(), 3);
1861 char msg[199];
1862 sprintf_s(msg, sizeof msg, "Resource was not previously released: %s", pointerName.c_str());
1864 }
1865
1866 if (!file[0])
1867 {
1868 char msg[199];
1869 sprintf_s(msg, sizeof msg, "Filename was blank for: %s", pointerName.c_str());
1871 return;
1872 }
1873
1874 HRESULT hr;
1875 if (FAILED(hr = Rendering::LoadTexture(Rendering::ClientRenderer(), file, resource, 1)))
1876 {
1877 char msg[199];
1878 sprintf_s(msg, sizeof msg, "Cannot load texture: %S (%S)", file, Rendering::ErrorString(hr));
1879 logger->Log(msg, Logger::Fatal);
1880 return;
1881 }
1882
1883 AddTrackedResource(pointerName.c_str()); // managed
1884
1885 TouchFile(file);
1886
1887 logger->AddToCallStack("GameClass::LoadTexture DONE");
1888}
1889
1890void GameClass::ChangeGear(const char newGear, bool isInit) const
1891{
1892 if (ourcockpit.gearshift == newGear)
1893 return;
1894
1895 switch (newGear)
1896 {
1897 case -2: bus->gearShift[0] = 'P'; break;
1898 case -1: bus->gearShift[0] = 'R'; break;
1899 case 0: bus->gearShift[0] = 'N'; break;
1900 default:
1901 if (ourcockpit.fwdgears > 1)
1902 sprintf_s(bus->gearShift, 2, "%i", newGear);
1903 else
1904 sprintf_s(bus->gearShift, 2, "D");
1905 break;
1906 }
1907
1908 if (isInit)
1909 {
1910 ourcockpit.gearshift = newGear;
1911 return;
1912 }
1913
1915
1916 if (ourcockpit.gearshift == -2) // was park
1917 {
1919 {
1920 SClientPacket outpacket; // NOLINT
1921 outpacket.type = 23; // Universe sound
1922 outpacket.f_x = 0.0f; // car noise
1923 outpacket.f_y = 2.0f; // brakes off
1924 outpacket.f_z = 0.0f; // NULL
1925 outpacket.f_w = 0.0f; // NULL
1926 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1927
1929 }
1930 }
1931 else if (ourcockpit.gearshift == -1) // was in reverse
1932 {
1934 {
1935 SClientPacket outpacket; // NOLINT
1936 outpacket.type = 23; // Universe sound
1937 outpacket.f_x = 0.0f; // car noise
1938 outpacket.f_y = 4.0f; // reverse off
1939 outpacket.f_z = 0.0f; // NULL
1940 outpacket.f_w = 0.0f; // NULL
1941 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1942
1944 }
1945 }
1946
1947 if (newGear == -2) // now park
1948 {
1949 if (viewscreen->UniverseRelativeSpeedKms >= 0.002f)
1950 {
1954 if (ourcockpit.vdat.transmission < 64)
1956 ourcockpit.vdatChanged = true;
1957 }
1959 {
1960 SClientPacket outpacket; // NOLINT
1961 outpacket.type = 23; // Universe sound
1962 outpacket.f_x = 0.0f; // car noise
1963 outpacket.f_y = 1.0f; // brakes on
1964 outpacket.f_z = 0.0f; // NULL
1965 outpacket.f_w = 0.0f; // NULL
1966 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1968
1969 outpacket.type = 23; // Universe sound
1970 outpacket.f_x = 0.0f; // car noise
1971 outpacket.f_y = 4.0f; // reverse off
1972 outpacket.f_z = 0.0f; // NULL
1973 outpacket.f_w = 0.0f; // NULL
1974 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1976 }
1977 }
1978 else if (newGear == -1) // now reverse
1979 {
1981 {
1982 SClientPacket outpacket; // NOLINT
1983 outpacket.type = 23; // Universe sound
1984 outpacket.f_x = 0.0f; // car noise
1985 outpacket.f_y = 3.0f; // reverse on
1986 outpacket.f_z = 0.0f; // NULL
1987 outpacket.f_w = 0.0f; // NULL
1988 networking->SendToServer(&outpacket, sizeof(SClientPacket), true);
1990 }
1991 if (ourcockpit.tach > 0.5f)
1992 {
1996 if (ourcockpit.vdat.transmission < 64)
1998 ourcockpit.vdatChanged = true;
1999 }
2000 }
2001 else if (ourcockpit.gearshift == 0 && newGear == 1) // was neutral, now 1
2002 {
2003 if (viewscreen->UniverseRelativeSpeedKms >= 0.002f || ourcockpit.tach > 0.5f)
2004 {
2008 if (ourcockpit.vdat.transmission < 64)
2010 ourcockpit.vdatChanged = true;
2011 }
2013 }
2014
2015 ourcockpit.gearshift = newGear;
2016
2019}
2020
2021void GameClass::LostScannerTarget(const char* msg) const
2022{
2023 logger->AddToCallStack("GameClass::LostScannerTarget");
2024
2025 if (bus->targetC == -1)
2026 {
2027 char bug[199];
2028 sprintf_s(bug, 199, "That's weird, tried to lose scanner target but already -1: %s", msg);
2030 return;
2031 }
2032
2033 bus->targetC = -1;
2035
2036 if (playerships[0].groundvehicle)
2037 {
2039 return;
2040 }
2041
2043 {
2046 }
2047
2048 // ReSharper disable once CppExpressionWithoutSideEffects
2049 TurnOffTVM();
2050}
2051
2064
2066{
2067 logger->AddToCallStack("GameClass::AutopilotDisconnect");
2069 return;
2070
2071 if(bus->AFCS.DorAircraft) { TurnOffDOR();return; }
2072 bus->AFCS.AutopilotEngaged = false;
2075 for(int i=0;i<MAX_ENGINES;++i) {bus->EngineThrustLever[i]=0;bus->ThrustReverserCommand[i]=false;}
2076 }
2077 if (!playerships[0].groundvehicle && ourcockpit.power > 0.5f)
2079
2081}
2082
2084{
2085 logger->AddToCallStack("GameClass::TurnOffTVM");
2086
2087 if (bus->AFCS.TvmOn)
2088 {
2089 bus->AFCS.TvmOn = false;
2090 if (!playerships[0].groundvehicle && ourcockpit.power > 0.5f)
2092 bus->AFCS.DesiredClosingSpeed = 0.0f; // reset
2093 for (int i = 0; i < MAX_ENGINES; i++)
2094 {
2095 bus->EngineThrustLever[i] = 0.0f;
2096 bus->ThrustReverserCommand[i] = false;
2097 }
2098 return true; // NOLINT(readability-simplify-boolean-expr)
2099 }
2100 return false;
2101}
2102
2103bool GameClass::TurnOffDOR(bool preserveGuidance) const
2104{
2105 logger->AddToCallStack("GameClass::TurnOffDOR");
2108 bus->orbit.guidance.status=L"ENTRY SPEED HOLD OFF";
2110 for(int i=0;i<MAX_ENGINES;++i) {bus->EngineThrustLever[i]=0;bus->ThrustReverserCommand[i]=false;}
2111 return true;
2112 }
2113
2114 if (bus->AFCS.DorOn)
2115 {
2116 bus->AFCS.DorOn = false;
2117 if(bus->AFCS.DorAircraft) {
2120 }
2121 // Automatic completion/abort retains its reason on the instrument.
2122 if (!preserveGuidance)
2123 bus->orbit.guidance = {};
2124 // DOR disengagement is audible even when loss of cockpit power caused it.
2126 bus->AFCS.DesiredClosingSpeed = 0.0f; // reset
2127 for (int i = 0; i < MAX_ENGINES; i++)
2128 {
2129 bus->EngineThrustLever[i] = 0.0f;
2130 bus->ThrustReverserCommand[i] = false;
2131 }
2132 return true; // NOLINT(readability-simplify-boolean-expr)
2133 }
2134 return false;
2135}
2136
2137//--------------------------------------------------------------------------------------
2138// As a convenience, DXUT inspects the incoming windows messages for
2139// keystroke messages and decodes the message parameters to pass relevant keyboard
2140// messages to the application. The framework does not remove the underlying keystroke
2141// messages, which are still passed to the application's MsgProc callback.
2142//--------------------------------------------------------------------------------------
2143void CALLBACK GameClass::KeyboardProc(UINT nChar, bool bKeyDown, bool bAltDown, void* pUserContext)
2144{
2145 GameClass* game = static_cast<GameClass*>(pUserContext);
2146
2147 char msg[99];
2148 sprintf_s(msg, sizeof msg, "KeyboardProc START %i %i %i", game->displaystage, nChar, bKeyDown ? 1 : 0);
2149 game->logger->AddToCallStack(msg);
2150#ifdef ChatEnter
2151 if (nChar == VK_RETURN && game->GUI)
2152 {
2153 sprintf_s(msg, sizeof msg, "DXUT Enter callback keyDown=%d alt=%d", bKeyDown, bAltDown);
2154 HudDiagnostics::LogChatInput(*game->GUI, msg);
2155 }
2156#endif
2157
2158 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2159 switch (game->displaystage)
2160 {
2162 if (bKeyDown)
2163 {
2164 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2165 switch (nChar)
2166 {
2167#ifdef _DEBUG
2168 case VK_SPACE:
2169 game->sound->loopintro = false;
2170 Sound::AdvanceStage(NULL, NULL, NULL, game->sound.get());
2171 game->sound->loopintro = false;
2172 break;
2173#endif
2174
2175 case VK_ESCAPE:
2176 PostQuitMessage(0);
2177 break;
2178 }
2179 }
2180 break;
2181
2183 if (bKeyDown)
2184 {
2185 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2186 switch (nChar)
2187 {
2188 case VK_RETURN:
2190 {
2192 {
2195 }
2196 else if (game->GUI->g_HUD.GetEditBox(IDC_PASSWORD)->m_bHasFocus)
2197 {
2199 HMI::OnGUIEvent(0, IDC_LOGIN, nullptr, game->GUI.get());
2200 }
2201 }
2202 break;
2203
2204 case VK_ESCAPE:
2205 PostQuitMessage(0);
2206 break;
2207 }
2208 }
2209 break;
2210
2212 if (bKeyDown)
2213 {
2214 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2215 switch (nChar)
2216 {
2217 case VK_ESCAPE:
2218 PostQuitMessage(0);
2219 break;
2220
2221#ifdef _DEBUG
2222 case VK_F5:
2223 game->LoadTexture(&game->GUI->m_pddsGUIInterlace, "m_pddsGUIInterlace", L"Textures\\Immigration.png");
2224 game->LoadTexture(&game->graphics->m_pddsCloudBaseMapAndNetwork, "m_pddsCloudBaseMapAndNetwork", L"Textures\\Network.png");
2225 break;
2226#endif
2227 }
2228 }
2229 break;
2230
2232 if (bKeyDown)
2233 {
2234 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2235 switch (nChar)
2236 {
2237 case VK_SPACE:
2238 if (!game->loadingReadyToContinue) break;
2239 game->sound->loopintro = false;
2240 Sound::AdvanceStage(NULL, NULL, NULL, game->sound.get());
2241 game->sound->loopintro = false;
2242 break;
2243
2244 case VK_ESCAPE:
2245 PostQuitMessage(0);
2246 break;
2247
2248#ifdef _DEBUG
2249 case VK_F5:
2250 game->LoadTexture(&game->GUI->m_pddsGUIActions, "m_pddsGUIActions", L"Textures\\eyezoomtest.png", Rendering::ImageFormat::RGB8);
2251 break;
2252#endif
2253 }
2254 }
2255 break;
2256
2258 if (bKeyDown)
2259 {
2260 sprintf_s(msg, sizeof msg, "KeyboardProc key %x", nChar);
2261 game->logger->AddToCallStack(msg);
2262
2263 //Switching on the values passed to KeyboardProc, see http://www.tweakvb.com/cheat2000.pdf
2264 //things that require the key to be held down CAN'T go in this section
2265 //only things that can take a single key or key repeats can go here (that we want to slow down)
2266 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
2267 switch (nChar)
2268 {
2269 case VK_ESCAPE:
2270 {
2271 for (int i = 0; i < D_ENUMERATION; i++)
2272 DialogBase::dialogs[i]->ClearEdit();
2273 }
2274 break;
2275
2276 case VK_RETURN:
2277 {
2278 if (bAltDown)
2279 {
2283 }
2284 }
2285 break;
2286
2287 case VK_F2:
2288 {
2289 if (game->viewscreen->ptrKeyboard->g_bShift && game->GUI->IsAdmin)
2290 {
2291 game->timeLapse = true;
2292 }
2293#ifdef _DEBUG
2294 else
2295#else
2296 else if (game->GUI->IsAdmin)
2297#endif
2298 {
2299 HRESULT hr=game->graphics->LoadShaderFile();
2300 if(FAILED(hr))game->logger->Log("Native material reload failed",Logger::Level::Error,hr);
2301 else game->logger->Log("Native materials reloaded; shader source changes require rebuilding the embedded SM5 package");
2302 }
2303 }
2304 break;
2305 }
2306 }
2307 break;
2308 }
2309
2310 game->logger->AddToCallStack("GameClass::KeyboardProc END");
2311}
2312
2313//--------------------------------------------------------------------------------------
2314// This callback function will be called immediately after the Direct3D device has
2315// entered a lost state and before Rendering::RenderDevice::Reset is called. Resources created
2316// in the OnResetDevice callback should be released here, which generally includes all
2317// Rendering::ResourcePool::Device resources. See the "Lost Devices" section of the documentation for
2318// information about lost devices.
2319//--------------------------------------------------------------------------------------
2320void CALLBACK GameClass::OnLostDevice(void* pUserContext)
2321{
2322 GameClass* game = static_cast<GameClass*>(pUserContext);
2323
2324 game->logger->AddToCallStack("GameClass::OnLostDevice");
2325 game->logger->Log("Calling OnLostDevice()...");
2326
2327 // ReSharper disable once CppEntityAssignedButNoRead
2328 HRESULT hr;
2329
2330 V(game->graphics->g_pEffect->OnLostDevice());
2331 game->UpdateTrackedResource("g_pEffect", 1);
2332
2334 game->UpdateTrackedResource("g_DialogResourceManager", 1);
2336 game->UpdateTrackedResource("externalCameraOverlay.labelFont", 1);
2337 game->UpdateTrackedResource("externalCameraOverlay.valueFont", 1);
2339 game->UpdateTrackedResource("keyboardChart.font", 1);
2340
2341 if (game->GUI->g_pFont)
2342 {
2343 V(game->GUI->g_pFont->OnLostDevice());
2344 game->UpdateTrackedResource("g_pFont", 1);
2345 }
2346 if (game->GUI->g_pChatFont)
2347 {
2348 V(game->GUI->g_pChatFont->OnLostDevice());
2349 game->UpdateTrackedResource("g_pChatFont", 1);
2350 }
2351 if (game->GUI->g_pSubtitleFont)
2352 {
2353 V(game->GUI->g_pSubtitleFont->OnLostDevice());
2354 game->UpdateTrackedResource("g_pSubtitleFont", 1);
2355 }
2356
2357 if (game->GUI->g_pTextSprite)
2358 {
2359 V(game->GUI->g_pTextSprite->OnLostDevice());
2360 game->UpdateTrackedResource("g_pTextSprite", 1);
2361 }
2362
2363 if (game->viewscreen)
2364 game->viewscreen->OnLostDevice();
2365
2367 game->displays->OnLostDevice();
2368
2369 game->gameGraphicsReady = game->loadingLabelsReady = game->loadingReadyToContinue = false;
2370 game->logger->Log("OnLostDevice() done!");
2371
2372 for (size_t t = 0; t < game->trackedResources.size(); t++)
2373 {
2374 if (game->trackedResources.at(t).pool != Rendering::ResourcePool::Managed &&
2375 game->trackedResources.at(t).status != 1 && game->trackedResources.at(t).status != 3)
2376 {
2377 char msg[199];
2378 sprintf_s(msg, sizeof msg, "Resource not set to lost: %s", game->trackedResources.at(t).name);
2379 game->logger->Log(msg, Logger::Level::Error);
2380 }
2381 }
2382}
2383
2384//--------------------------------------------------------------------------------------
2385// This callback function will be called immediately after the Direct3D device has
2386// been destroyed, which generally happens as a result of application termination or
2387// windowed/full screen toggles. Resources created in the OnCreateDevice callback
2388// should be released here, which generally includes all Rendering::ResourcePool::Managed resources.
2389//--------------------------------------------------------------------------------------
2390void CALLBACK GameClass::OnDestroyDevice(void* pUserContext)
2391{
2392 GameClass* game = static_cast<GameClass*>(pUserContext);
2393 game->logger->AddToCallStack("GameClass::OnDestroyDevice");
2394 game->logger->Log("Calling OnDestroyDevice()...");
2395
2396 game->GUI->OnDestroyDevice();
2397 game->graphics->OnDestroyDevice();
2398
2399 //if (game->displaystage >= GameState::STATUS_LOADING)
2400 const bool preservingModels = Rendering::ClientHost() && Rendering::ClientHost()->Recovering();
2401 game->viewscreen->OnDestroyDevice(preservingModels);
2402
2404 game->displays->OnDestroyDevice("native device destroyed");
2405
2406 game->logger->AddToCallStack("TrackedResourcesCheck");
2407
2408 bool found = false;
2409 char msg[199];
2410 for (UINT i = 0; i < game->trackedResources.size(); i++)
2411 {
2412 const char* name = game->trackedResources.at(i).name;
2413 if (preservingModels && (!strcmp(name, "ourcockpit.componentarray") ||
2414 !strcmp(name, "polyobjects[5].VB") ||
2415 (!strncmp(name, "playerships[", 12) && strstr(name, "].componentarray")))) continue;
2416 if (game->trackedResources.at(i).status != 3) // not released
2417 {
2418 if (!found)
2419 {
2420 game->logger->Log("Resources that haven't been freed:", Logger::Level::Warn);
2421 found = true;
2422 }
2423 sprintf_s(msg, sizeof msg, " --> %s", game->trackedResources.at(i).name);
2424 game->logger->Log(msg, Logger::Level::Warn);
2425 }
2426 }
2427 if (!found)
2428 game->logger->Log(preservingModels ? "All tracked GPU resources freed; CPU vehicle models retained for recovery" : "All tracked resources have been freed!");
2429
2430 game->logger->Log("OnDestroyDevice() done!");
2431}
2432
2433void GameClass::GetProgramVersion(int& major, int& minor, int& build, int& revision) const
2434{
2435 WCHAR filename[MAX_PATH];
2436 GetModuleFileName(nullptr, filename, MAX_PATH);
2437
2438 char msg[MAX_PATH];
2439 sprintf_s(msg, MAX_PATH, "Executable: %S", filename);
2440 logger->Log(msg);
2441
2442 const DWORD dwSize = GetFileVersionInfoSize(filename, nullptr);
2443 if (dwSize == 0)
2444 {
2445 sprintf_s(msg, MAX_PATH, "Error in GetFileVersionInfoSize: %d", GetLastError());
2446 logger->Log(msg, Logger::Fatal);
2447 return;
2448 }
2449
2450 BYTE* pbVersionInfo = new BYTE[dwSize];
2451
2452 if (!GetFileVersionInfo(filename, 0, dwSize, pbVersionInfo))
2453 {
2454 sprintf_s(msg, MAX_PATH, "Error in GetFileVersionInfo: %d", GetLastError());
2455 logger->Log(msg, Logger::Fatal);
2456 SAFE_DELETE_ARRAY(pbVersionInfo);
2457 return;
2458 }
2459
2460 LPBYTE p = nullptr;
2461 UINT querySize;
2462 if (!VerQueryValue(pbVersionInfo, TEXT("\\"), reinterpret_cast<VOID FAR * FAR*>(&p), &querySize))
2463 {
2464 sprintf_s(msg, MAX_PATH, "Error in VerQueryValue: %d", GetLastError());
2465 logger->Log(msg, Logger::Fatal);
2466 SAFE_DELETE_ARRAY(pbVersionInfo);
2467 return;
2468 }
2469
2470 // pFileInfo->dwFileVersionMS is usually zero. However, you should check
2471 // this if your version numbers seem to be wrong
2472 VS_FIXEDFILEINFO* verInfo = reinterpret_cast<VS_FIXEDFILEINFO*>(p);
2473 major = HIWORD(verInfo->dwFileVersionMS);
2474 minor = LOWORD(verInfo->dwFileVersionMS);
2475 build = HIWORD(verInfo->dwFileVersionLS);
2476 revision = LOWORD(verInfo->dwFileVersionLS);
2477
2478 SAFE_DELETE_ARRAY(pbVersionInfo);
2479}
2480
2482{
2483 return static_cast<float>(CpuInformation::MaximumSpecifiedMhz());
2484}
2485
2487{
2488 assert(strlen(name) < 32);
2489 for (UINT i = 0; i < trackedResources.size(); i++)
2490 {
2491 if (_strcmpi(trackedResources.at(i).name, name) == 0)
2492 {
2493 if (trackedResources.at(i).status != 1 && trackedResources.at(i).status != 3)
2494 {
2495 char msg[199];
2496 sprintf_s(msg, sizeof msg, "GameClass::AddTrackedResource Already Tracking: %s (%i)", name, trackedResources.at(i).status);
2498 }
2499 else
2500 {
2501 trackedResources.at(i).status = 0;
2502 }
2503 return;
2504 }
2505 }
2506 trackedResources.emplace_back(Resource(name, pool));
2507}
2508
2509void GameClass::UpdateTrackedResource(const char* name, int status)
2510{
2511 assert(status != 0);
2512 assert(strlen(name) < 32);
2513 for (UINT i = 0; i < trackedResources.size(); i++)
2514 {
2515 if (_strcmpi(trackedResources.at(i).name, name) == 0)
2516 {
2517 if (status == trackedResources.at(i).status)
2518 {
2519 char msg[199];
2520 sprintf_s(msg, sizeof msg, "GameClass::UpdateTrackedResource %s already status %i", name, status);
2522 }
2523 else if (status == 2 && trackedResources.at(i).status == 3) // can't go to "reset" from anything but "lost" or "created"
2524 {
2525 char msg[199];
2526 sprintf_s(msg, sizeof msg, "GameClass::UpdateTrackedResource %s status transition %i", name, status);
2528 }
2529 else
2530 {
2531 trackedResources.at(i).status = status;
2532 }
2533 return;
2534 }
2535 }
2536#ifdef _DEBUG
2537 char msg[199];
2538 sprintf_s(msg, sizeof msg, "GameClass::UpdateTrackedResource Wasn't Tracking: %s", name);
2540#endif
2541}
@ SimulatorCannotTransferItem
Definition ActiveHelp.h:20
@ HowToUseJVCAudio
Definition ActiveHelp.h:435
@ CenterUp
Definition ActiveHelp.h:385
@ ScannerLostContact
Definition ActiveHelp.h:27
@ SimulatorCannotUseItem
Definition ActiveHelp.h:19
@ Heal
Definition ActiveHelp.h:445
@ InsufficientFuelUs
Definition ActiveHelp.h:26
@ FirstSelectVehicleOrContainer
Definition ActiveHelp.h:10
@ InvalidNegativeKilogramAmount
Definition ActiveHelp.h:25
@ SimulatorCannotTransferWeapons
Definition ActiveHelp.h:22
@ InvalidPositiveKilogramAmount
Definition ActiveHelp.h:24
@ FuelReminder
Definition ActiveHelp.h:362
@ InvalidPositiveMonetaryAmount
Definition ActiveHelp.h:23
@ GetItInGear
Definition ActiveHelp.h:388
@ SimulatorCannotSwapItem
Definition ActiveHelp.h:21
@ TorqueConverter
Definition ActiveHelp.h:436
#define SAFE_DELETE_ARRAY(value)
#define V_RETURN(expression)
#define SAFE_RELEASE(value)
#define V(expression)
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
@ D_CONFIGURATION
Definition DialogBase.h:11
@ D_ENUMERATION
Definition DialogBase.h:15
#define GUID_DEVINTERFACE_USB_DEVICE
Definition GameClass.cpp:19
#define DIRECTINPUT_VERSION
Definition GameClass.h:3
#define designedHeightC
Definition GameClass.h:24
#define designedWidthC
Definition GameClass.h:23
@ STATUS_LOADING
Definition GameState.h:8
@ STATUS_GAME
Definition GameState.h:9
@ STATUS_CREATE
Definition GameState.h:7
@ STATUS_LOGIN
Definition GameState.h:6
@ STATUS_SPLASH
Definition GameState.h:5
float RandomFloat()
@ EVENT_SELECT_TARGET
Definition Networking.h:59
@ EVENT_REMOTEASSAY
Definition Networking.h:39
@ EVENT_CURRENT_GEAR
Definition Networking.h:61
@ EVENT_RADIO
Definition Networking.h:38
@ EVENT_TRANSPONDER
Definition Networking.h:66
@ EVENT_WXRADAR
Definition Networking.h:56
@ CONNECT_PATCHED
Definition Networking.h:31
@ T120
Definition ServerTypes.h:67
@ T27
Definition ServerTypes.h:82
@ T121
Definition ServerTypes.h:89
#define MAX_ENGINES
#define MAX_SCAN
@ NexRad
@ Fireworks
@ LockPick
@ FirstAid
@ Binoculars
@ TemporaryRunwayLights
@ EVA_KIT
@ NightVision
@ ColonyUpLink
@ RVR
@ ATM
@ Sunglasses
@ ILS
@ CandyCane
@ REF_INANOTHER
Definition ServerTypes.h:45
@ REF_ONGROUND
Definition ServerTypes.h:43
@ SOUND_BACKUP
Definition Sound.h:261
@ SOUND_APTRIMCLACKER
Definition Sound.h:169
@ SOUND_GEARSHIFT
Definition Sound.h:251
@ SOUND_APCAVALRY
Definition Sound.h:171
@ SOUND_AIRBRAKEONMAMMOTH
Definition Sound.h:265
@ SOUND_HOLIDAY
Definition Sound.h:167
@ SOUND_MIDWAYTARGET
Definition Sound.h:174
@ SOUND_BACKUPMAMMOTH
Definition Sound.h:264
@ SOUND_AIRBRAKEOFFMAMMOTH
Definition Sound.h:266
@ HYPOSPRAY_END
Definition Sound.h:288
@ SOUND_AIRBRAKEOFF
Definition Sound.h:263
@ SOUND_ENUMERATION
Definition Sound.h:344
@ HYPOSPRAY_START
Definition Sound.h:287
@ SOUND_GEARGRIND
Definition Sound.h:252
@ SOUND_AIRBRAKEON
Definition Sound.h:262
scanDb Scanner
Definition Bus.h:484
VECTOR2SHORT tcp
Definition Bus.h:314
float RollAttitudeRadians
Definition Bus.h:48
char gearShift[2]
Definition Bus.h:528
float PitchAttitudeRadians
Definition Bus.h:47
void FrameMove(float fElapsed)
Definition Bus.cpp:21
short targetC
Definition Bus.h:480
float EngineThrustLever[MAX_ENGINES]
Definition Bus.h:357
struct Bus::Afcs AFCS
short station
Definition Bus.h:506
SAssayGrid assayGrid
Definition Bus.h:494
bool ComponentFcsRollFail
Definition Bus.h:492
short scanslot[MAX_SCAN]
Definition Bus.h:485
Orbital::BusState orbit
Definition Bus.h:481
std::vector< Message > messages
Definition Bus.h:445
bool ComponentRcsRollFail
Definition Bus.h:491
bool ThrustReverserCommand[MAX_ENGINES]
Definition Bus.h:72
std::vector< Command > commandStream
Definition Bus.h:442
Rendering::CloudRenderer11 * Effect()
float scale
Definition config.h:29
bool g_bStartFullscreen
Definition config.h:26
static DialogBase * dialogs[D_ENUMERATION]
Definition DialogBase.h:41
virtual void UpdateMenu(short tab)
Definition DialogBase.h:114
virtual void ActiveTab()
void UpdatePresence(const char *prmDetails, const char *prmState, const char *prmLargeImageKey)
void OnCreateDevice()
Definition Displays.cpp:846
void OnResetDevice()
Definition Displays.cpp:733
void OnDestroyDevice(const char *reason="unspecified")
Definition Displays.cpp:854
void OnLostDevice()
Definition Displays.cpp:722
void RestorePage(std::string screenName)
Definition Displays.cpp:882
unsigned char beginScene
Definition GameClass.h:128
float lastDeviceChange
Definition GameClass.h:52
float FrameElapsedTime
Definition GameClass.h:116
HRESULT InitializeGameHud()
short instage
Definition GameClass.h:121
GameState displaystage
Definition GameClass.h:118
void LoadTexture(Rendering::RenderTexture **resource, const std::string &pointerName, const WCHAR *file, Rendering::ImageFormat format=Rendering::ImageFormat::BGRA8)
std::unique_ptr< Bus > bus
Definition GameClass.h:108
static HRESULT CALLBACK OnResetDevice(Rendering::RenderDevice *pd3dDevice, const Rendering::SurfaceDescription *pBackBufferSurfaceDesc, void *pUserContext)
bool lastDeviceChangedSound
Definition GameClass.h:53
Config config
Definition GameClass.h:100
void LostScannerTarget(const char *msg) const
void RequestScannerData() const
static void CALLBACK OnDestroyDevice(void *pUserContext)
void UnregisterDeviceNotifications()
Definition GameClass.cpp:92
void GetProgramVersion(int &major, int &minor, int &build, int &revision) const
std::unique_ptr< HMI > GUI
Definition GameClass.h:106
HRESULT InitDirectInput(HWND hDlg) const
void UseOrDisuseInventoryItemType(int itemtype, int itemsubtype, int itemId, int vehicleId) const
bool loadingLabelsReady
Definition GameClass.h:125
std::unique_ptr< Sound > sound
Definition GameClass.h:104
static void CALLBACK KeyboardProc(UINT nChar, bool bKeyDown, bool bAltDown, void *pUserContext)
void LostVerticalTarget(const char *msg) const
bool TurnOffTVM() const
std::unique_ptr< Networking > networking
Definition GameClass.h:103
void AddTrackedResource(const char *name, Rendering::ResourcePool pool=Rendering::ResourcePool::Managed)
short stage
Definition GameClass.h:121
bool vphelp[vphelpC]
Definition GameClass.h:101
void UpdateTrackedResource(const char *name, int status)
void Close()
void RequestClose() const
static void CALLBACK OnLostDevice(void *pUserContext)
bool gameWindowShown
Definition GameClass.h:125
std::vector< Resource > trackedResources
Definition GameClass.h:50
void FlightDirectorOn() const
std::unique_ptr< Displays > displays
Definition GameClass.h:110
static void CALLBACK OnFrameMove(double fTime, float fElapsedTime, void *pUserContext)
static float GetCpuSpeedMhz()
HDEVNOTIFY dev_notify
Definition GameClass.h:55
static void CALLBACK OnFrameRender(Rendering::RenderDevice *pd3dDevice, double fTime, float fElapsedTime, void *pUserContext)
bool loadingReadyToContinue
Definition GameClass.h:126
bool timeLapse
Definition GameClass.h:134
std::vector< std::unique_ptr< Module > > modules
Definition GameClass.h:113
void RepairVehicle() const
static void TouchFile(const WCHAR *str)
HRESULT OnFramePresented()
std::unique_ptr< DiscordIntegration > discord
Definition GameClass.h:111
void InitializeGame()
void KillScannerData() const
short loadstage
Definition GameClass.h:119
static LRESULT CALLBACK MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, bool *pbNoFurtherProcessing, void *pUserContext)
bool lastDeviceChangedInput
Definition GameClass.h:54
std::unique_ptr< Viewscreen > viewscreen
Definition GameClass.h:107
bool TurnOffDOR(bool preserveGuidance=false) const
float displayscale
Definition GameClass.h:130
void ChangeGear(char newGear, bool isInit=false) const
bool gameGraphicsReady
Definition GameClass.h:125
std::unique_ptr< Graphics > graphics
Definition GameClass.h:105
float displayWidth
Definition GameClass.h:131
std::unique_ptr< Logger > logger
Definition GameClass.h:109
static HRESULT CALLBACK OnCreateDevice(Rendering::RenderDevice *pd3dDevice, const Rendering::SurfaceDescription *pBackBufferSurfaceDesc, void *pUserContext)
float displayHeight
Definition GameClass.h:131
void ToggleFullScreen(bool goFullScreen)
void AutopilotDisconnect() const
bool maximized
Definition GameClass.h:56
Rendering::RenderTexture * m_pddsCloudBaseMapAndNetwork
Definition Graphics.h:31
HRESULT OnResetDevice(void) const
Definition Graphics.cpp:137
HRESULT LoadShaderFile(void)
Definition Graphics.cpp:366
void OnDestroyDevice(void)
Definition Graphics.cpp:148
void DrawImmigration(Rendering::RenderDevice *pd3dDevice, float fElapsedTime)
Definition Graphics.cpp:180
Rendering::RenderMaterial * g_pEffect
Definition Graphics.h:30
Rendering::RenderTexture * m_pddsLightningAndBackground[3]
Definition Graphics.h:32
void OnResetDevice()
Definition gui.cpp:1047
const char * AdUnmeasuredUiReason() const
Definition gui.h:1033
bool immigrationPassed
Definition gui.h:1107
Rendering::RenderFont * g_pSubtitleFont
Definition gui.h:1054
float txhold
Definition gui.h:1122
HRESULT OnCreateDevice(Rendering::RenderDevice *pd3dDevice)
Definition gui.cpp:1231
SPlayerData player[MAX_ONLINEPLAYERS]
Definition gui.h:1093
Rendering::RenderTexture * m_pddsGUIRanks
Definition gui.h:1066
short txbuffer
Definition gui.h:1100
Rendering::RenderFont * g_pChatFont
Definition gui.h:1053
LPWSTR currentCursor
Definition gui.h:1110
Rendering::RenderTexture * m_pddsGUIInterlace
Definition gui.h:1061
float furtherdelay
Definition gui.h:1085
Rendering::RenderTexture * m_pddsGUIActions
Definition gui.h:1065
bool isSteam
Definition gui.h:1114
bool MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition gui.cpp:1105
void LightningCalculations(float fElapsedTime)
Definition gui.cpp:5297
ExternalCameraOverlay externalCameraOverlay
Definition gui.h:1056
RiseDialog g_HUD
Definition gui.h:1031
std::wstring strings[L_ENUMERATION]
Definition gui.h:1076
void OnFrameMove(float fElapsedTime)
Definition gui.cpp:326
void LoadLanguage()
Definition gui.cpp:1877
InformationDialog * informationDialog
Definition gui.h:1120
bool rxlight
Definition gui.h:1098
float rxhold
Definition gui.h:1122
Rendering::RenderTexture * m_pddsGUIScrollButton
Definition gui.h:1064
void SaveConfiguration() const
Definition gui.cpp:2180
float eyemotion
Definition gui.h:1083
tm tm_time
Definition gui.h:1029
void LoadConfiguration() const
Definition gui.cpp:2102
static void CALLBACK OnGUIEvent(UINT nEvent, int nControlID, RiseControl *pControl, void *pUserContext)
Definition gui.cpp:3276
void FadeIn(float f, float fElapsedTime)
Definition gui.cpp:5285
void CreateDialogs()
Definition gui.cpp:3067
Rendering::RenderTexture * m_pddsGUIScroll
Definition gui.h:1063
float fade
Definition gui.h:1086
void InitApp()
Definition gui.cpp:2079
KeyboardChart keyboardChart
Definition gui.h:1055
bool txlight
Definition gui.h:1098
LoadingEyeReveal eyeReveal
Definition gui.h:1084
float cloudmotion
Definition gui.h:1088
void OnRender(float fElapsedTime, Rendering::RenderDevice *pd3dDevice)
Definition gui.cpp:2356
Rendering::RenderFont * g_pFont
Definition gui.h:1052
void OnDestroyDevice()
Definition gui.cpp:3929
bool Edited
Definition gui.h:1109
RiseDialogResourceManager g_DialogResourceManager
Definition gui.h:1079
short rxbuffer
Definition gui.h:1100
Rendering::RenderTexture * m_pddsGUIParts
Definition gui.h:1059
bool g_bRightDown
Definition gui.h:1045
void LoadTextures(GameState displaystage, short loadstage)
Definition gui.cpp:3810
bool IsAdmin
Definition gui.h:1108
Rendering::RenderSprite * g_pTextSprite
Definition gui.h:1051
bool DismissHelp(int helpId, int nControlID=GUI_UNDERSTOOD)
bool PopUpHelp(short helpId, bool allowDismiss=true, bool isLearnMore=false)
float Progress(double now)
void Log(const char *msg, Level level=Info, int errorCode=0)
Definition Logger.cpp:283
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
void SetNetworkingPointer(Networking *prmNetworking)
Definition Logger.cpp:362
@ Debug
Definition Logger.h:27
@ Warn
Definition Logger.h:26
@ Fatal
Definition Logger.h:29
@ Error
Definition Logger.h:28
void FrameMove(GameState displaystage)
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
void RequestVerbiage(int helpId) const
char connectstatus
Definition Networking.h:111
void SendEvent(EventType eventType, float extent=0.0f) const
void DrawOverlay(RenderFont *font, RenderSprite *sprite, unsigned width, unsigned height, std::vector< RECT > *drawnBounds=nullptr)
void FinishScene(RenderDevice &device, bool weatherMeasured, const std::vector< DirectX::XMFLOAT4 > &uiRects, const char *uiBlocker=nullptr)
HRESULT PrepareLoadingStep(ID3D11DeviceContext *context, UINT samples, bool organic)
HRESULT SetRenderState(DWORD state, DWORD value)
HRESULT Clear(DWORD count, const RECT *rectangles, DWORD flags, PackedColor color, float depth, DWORD stencil)
HRESULT GetBackBuffer(UINT chain, UINT buffer, UINT type, RenderSurface **result)
HRESULT SetSamplerState(DWORD sampler, DWORD state, DWORD value)
HRESULT SetTechnique(const char *name)
bool Recovering() const
Definition Window11.h:54
HRESULT SetFullscreen(bool value)
Definition Window11.cpp:120
HRESULT RecreateDevice()
Definition Window11.cpp:105
void Close(int result=0)
Definition Window11.cpp:216
Resource(const char *prmName, Rendering::ResourcePool prmPool)
Definition GameClass.h:36
RiseElement * GetElement(UINT iElement)
Definition Controls.h:636
bool m_bHasFocus
Definition Controls.h:645
virtual void SetEnabled(bool bEnabled)
Definition Controls.h:575
virtual void SetTextColor(Rendering::PackedColor Color)
RiseEditBox * GetEditBox(int ID)
Definition Controls.h:196
void Init(RiseDialogResourceManager *pManager, bool bRegisterDialog=true)
Definition Controls.cpp:176
void RemoveAllControls()
Definition Controls.cpp:254
bool MsgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition Controls.cpp:888
void AppendVisibleBounds(std::vector< RECT > &rectangles) const
Definition Controls.cpp:510
RiseControl * GetControl(int ID)
HRESULT AddStatic(int ID, LPCWSTR strText, int x, int y, int width, int height, bool bIsDefault=false, RiseStatic **ppCreated=NULL, bool bShadow=true)
static void WINAPI ClearFocus()
void SetLocation(int x, int y)
Definition Controls.h:281
RiseStatic * GetStatic(int ID)
Definition Controls.h:172
HRESULT OnRender(float fElapsedTime)
Definition Controls.cpp:526
void RequestFocus(RiseControl *pControl)
RiseButton * GetButton(int ID)
Definition Controls.h:176
HRESULT SetFont(UINT index, LPCWSTR strFaceName, LONG height, LONG weight)
Definition Controls.cpp:709
void SetCallback(UICallback pCallback, void *pUserContext=NULL)
Definition Controls.cpp:212
HRESULT AddButton(int ID, LPCWSTR strText, int x, int y, int width, int height, UINT nHotkey=0, bool bIsDefault=false, RiseButton **ppCreated=NULL)
float originalPan
Definition Camera.h:14
float originalTilt
Definition Camera.h:15
void FrameMoveHorns()
Definition Sound.cpp:1781
void AddDelayedSound(SOUNDS soundEnum, float delay, float volume=1.0f, float freq=1.0f, bool fromOutside=false)
Definition Sound.cpp:3376
void Stop(SOUNDS soundEnum) const
Definition Sound.cpp:3397
void LoadSounds(short instage)
Definition Sound.cpp:2159
void FrameMoveEarPressure(float elapsedTime)
Definition Sound.cpp:1717
void FrameMoveVehicleSounds()
Definition Sound.cpp:766
void EnumDevices()
Definition Sound.cpp:91
static void CALLBACK AdvanceStage(HSYNC handle, DWORD channel, DWORD data, void *user)
Definition Sound.cpp:1246
void FrameMove(float elapsedTime)
Definition Sound.cpp:1901
GameState musicstage
Definition Sound.h:701
void FrameMoveWipers(float elapsedTime)
Definition Sound.cpp:1849
float Play(SOUNDS soundEnum, float volume=1.0f)
Definition Sound.cpp:802
void FrameMoveImmigration()
Definition Sound.cpp:1773
void Close()
Definition Sound.cpp:391
void PlayEx(SOUNDS soundEnum, bool loop, float volume=1.0f, float frequencyMod=1.0f, float pan=0.0f, bool restart=true, bool fromOutside=false, bool partOfHull=false)
Definition Sound.cpp:1006
void Reset()
Definition Sound.cpp:808
bool loopintro
Definition Sound.h:700
void LoadCustomSound(SOUNDS sound_enum, const char *path, SoundConfig *device=nullptr)
Definition Sound.cpp:5277
HSTREAM g_pSoundIntro
Definition Sound.h:698
std::vector< GUID > deviceGuids
Definition Sound.h:706
float lateraltime
Definition Viewscreen.h:378
void ShowCloudFallbackWarning(HWND owner) const
std::unique_ptr< renderer > ptrRenderer
Definition Viewscreen.h:433
std::unique_ptr< keyboard > ptrKeyboard
Definition Viewscreen.h:429
void OnFrameRender(Rendering::RenderDevice *pd3dDevice, double fTime) const
Definition render.cpp:16
float yawInput
Definition Viewscreen.h:372
static constexpr UINT CloudFallbackWarningMessage
Definition Viewscreen.h:405
CloudVolumeRenderer cloudVolume
Definition Viewscreen.h:396
float targetZoom
Definition Viewscreen.h:446
bool adWeatherMeasured
Definition Viewscreen.h:402
float pitchInput
Definition Viewscreen.h:372
void OnDestroyDevice(bool preserveModels=false)
void Initialize()
void SetHornPressed(bool pressed)
std::unique_ptr< waypoints > ptrWaypoints
Definition Viewscreen.h:437
bool VolumeCloudsEnabled() const
Definition Viewscreen.h:404
bool InventoryItemEffectsEnabled() const
Definition Viewscreen.h:169
float rolltilt
Definition Viewscreen.h:447
RiseMath::Matrix matrixView
Definition Viewscreen.h:346
HRESULT OnCreateDevice(Rendering::RenderDevice *pd3dDevice)
std::unique_ptr< weather > ptrWeather
Definition Viewscreen.h:434
void SetCrashHornFault(bool enabled)
void SetProjectionMatrices()
void OnFrameRender2(Rendering::RenderDevice *pd3dDevice, float fElapsedTime)
Definition render.cpp:2734
Rendering::AdDiagnostics11 adDiagnostics
Definition Viewscreen.h:401
float rollInput
Definition Viewscreen.h:372
float UniverseRelativeSpeedKms
Definition Viewscreen.h:126
float verticaltime
Definition Viewscreen.h:378
LPDIRECTINPUT8 g_pDI
Definition Viewscreen.h:210
void OnFrameMove(double fTime, float fElapsedTime)
float targetUpdown
Definition Viewscreen.h:445
std::unique_ptr< cockpit > ptrCockpit
Definition Viewscreen.h:435
std::unique_ptr< joystick > ptrJoystick
Definition Viewscreen.h:430
HRESULT OnResetDevice(Rendering::RenderDevice *pd3dDevice, const Rendering::SurfaceDescription *pBackBufferSurfaceDesc)
float targetLeftright
Definition Viewscreen.h:444
void OnLostDevice()
SCamera * camera
Definition Viewscreen.h:137
bool PrepareHullTextures(Rendering::RenderDevice *pd3dDevice, unsigned budget=2)
Definition render.cpp:2793
void FrameMovePropSounds(float elapsedTime) const
Definition cockpit.cpp:36
std::vector< DIDEVICEINSTANCE > deviceList
Definition joystick.h:29
HRESULT EnumDevices()
Definition joystick.cpp:554
void Initialize(HWND prmHWND)
Definition joystick.cpp:529
bool g_bShift
Definition keyboard.h:31
HRESULT Initialize(HWND hDlg)
Definition keyboard.cpp:19
void LoadTextures(Rendering::RenderDevice *pd3dDevice, short *stage, short *instage)
Definition renderer.cpp:27
void Reset()
Definition scanDb.cpp:9
void RequestWaypointData()
Definition waypoints.cpp:31
float elevation
Definition weather.h:197
float fuel
Definition globals.cpp:90
Sinteractive interactive
Definition globals.cpp:120
DeathType dead
Definition globals.cpp:37
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
unsigned short temptarget
Definition globals.cpp:72
float deathinhibit
Definition globals.cpp:39
Scockpit ourcockpit
Definition globals.cpp:114
bool g_bGotConclusion
Definition globals.cpp:97
float g_fFOV
Definition globals.cpp:80
char g_bTextInput
Definition globals.cpp:61
char outgoing[80]
Definition globals.cpp:60
#define Kg2Lbs
Definition globals.h:40
#define vphelpC
Definition globals.h:74
@ L_DEAD_BUTTON
Definition gui.h:405
@ IDC_PASSWORD
Definition gui.h:672
@ IDC_CALLSIGN
Definition gui.h:671
@ IDC_REJOINTEXT
Definition gui.h:979
@ IDC_REJOINBTN
Definition gui.h:980
@ IDC_LOGIN
Definition gui.h:670
ULONG MaximumSpecifiedMhz()
void ReleaseAircraft(Afcs &a)
constexpr uint32_t WRAP
constexpr uint32_t INVSRCALPHA
constexpr uint32_t SRCALPHA
constexpr uint32_t TARGET
constexpr uint32_t ZBUFFER
constexpr uint32_t LESS
constexpr uint32_t ALWAYS
constexpr uint32_t SRCBLEND
constexpr uint32_t ALPHABLENDENABLE
constexpr uint32_t DESTBLEND
constexpr uint32_t ZFUNC
constexpr uint32_t ADDRESSV
HWND ClientWindow()
HRESULT SaveSurfaceToFile(const wchar_t *path, ImageFile format, RenderSurface *surface, const void *, const RECT *crop)
constexpr PackedColor ColorRGB(unsigned r, unsigned g, unsigned b)
Window11 * ClientHost()
double ClientAbsoluteTime()
const wchar_t * ErrorString(HRESULT code)
RenderDevice * ClientRenderer()
HRESULT LoadTexture(RenderDevice *owner, const wchar_t *path, RenderTexture **result, UINT levels=0, UINT width=0, UINT height=0)
const SurfaceDescription * ClientBackBufferDescription()
HINSTANCE ClientInstance()
HRESULT ClientToggleFullscreen()
bool ClientWindowed()
auto ToRadian(T value)
Definition ClientMath.h:13
constexpr float Pi
Definition ClientMath.h:12
constexpr auto Min(A first, B second)
Definition ClientMath.h:15
float DesiredPitchRadians
Definition Bus.h:141
float DesiredRollRadians
Definition Bus.h:140
@ Navigation
Definition Bus.h:115
@ LateralMode_TakeOff
Definition Bus.h:111
@ Roll
Definition Bus.h:113
@ Glideslope
Definition Bus.h:104
@ Pitch
Definition Bus.h:98
@ VerticalMode_TakeOff
Definition Bus.h:96
@ AltitudeAgl
Definition Bus.h:103
bool DorOn
Definition Bus.h:148
bool AutothrottleEngaged
Definition Bus.h:88
bool TvmOn
Definition Bus.h:151
enum Bus::Afcs::LateralModes CurrentLateralMode
bool AutopilotEngaged
Definition Bus.h:87
bool DorAircraft
Definition Bus.h:149
float DesiredClosingSpeed
Definition Bus.h:152
enum Bus::Afcs::VerticalModes CurrentVerticalMode
bool bValue
Definition Command.h:22
int ivalues[2]
Definition Command.h:21
std::string name
Definition Command.h:11
unsigned char type
Definition globals.h:576
unsigned char subtype
Definition globals.h:576
std::wstring status
Definition OrbitState.h:315
VECTOR2SHORT tcp
unsigned char type
unsigned char array
unsigned char type
char leftaileron
char leftengine
char rightaileron
char autoflyte
char parkingBrake
char rightBrake
char hullintegrity
char monitor[7]
char windshield
char rightStrut
char overhead
char leftwing
char transmission
char landing[2]
char noseStrut
char elevator
char rightwing
char rightengine
char yawdamper
char steering
char thrustaug
char leftStrut
char hulllight
char leftBrake
char clengine
bool remoteAssayPower
Definition globals.h:597
int inventoryItemInUseSubType
Definition globals.h:700
short texturelib
Definition globals.h:602
char fwdgears
Definition globals.h:677
int inventoryItemInUseVehicleId
Definition globals.h:701
short ourplyrC
Definition globals.h:682
std::vector< InventoryHelper > vehicleInventory
Definition globals.h:698
float power
Definition globals.h:599
std::vector< InventoryHelper > personalInventory
Definition globals.h:697
SVesselDC vdat
Definition globals.h:664
bool radioPower
Definition globals.h:597
char gearshift
Definition globals.h:677
float tach
Definition globals.h:676
float clutchtime
Definition globals.h:676
bool vdatChanged
Definition globals.h:665
unsigned char hitpoints
Definition globals.h:686
float clutchhold
Definition globals.h:676
int inventoryItemInUseType
Definition globals.h:699
int inventoryItemInUseId
Definition globals.h:702
bool weatherRadarPower
Definition globals.h:597
short outboundMenuSelect
Definition globals.h:785
unsigned short vehicleId
Definition globals.h:537