From c376af320ebd9d9e435ef3003dd35136dbd71ae8 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 28 Feb 2022 22:49:18 +0100 Subject: Replaced old panic mechanism uses with the new one This will allow to split the functionality even further. I predict that at some point they I will start joining them up together once again, but for now I need them to be isolated. --- Stars45/AwardDlg.cpp | 3 ++- Stars45/DebriefDlg.cpp | 3 ++- Stars45/Game.cpp | 57 ++++++++++++++++++-------------------------------- Stars45/Game.h | 6 +----- Stars45/Main.cpp | 5 +++-- Stars45/MsnDlg.cpp | 5 +++-- Stars45/Ship.cpp | 3 ++- 7 files changed, 33 insertions(+), 49 deletions(-) diff --git a/Stars45/AwardDlg.cpp b/Stars45/AwardDlg.cpp index 631531f..46daf2a 100644 --- a/Stars45/AwardDlg.cpp +++ b/Stars45/AwardDlg.cpp @@ -30,6 +30,7 @@ #include "Keyboard.h" #include "Mouse.h" #include "Sound.h" +#include "Panic.h" // +--------------------------------------------------------------------+ // DECLARE MAPPING FUNCTIONS: @@ -147,5 +148,5 @@ AwardDlg::OnClose(AWEvent* event) } else - Game::Panic("AwardDlg::OnClose() - Game instance not found"); + Panic::Panic("AwardDlg::OnClose() - Game instance not found"); } diff --git a/Stars45/DebriefDlg.cpp b/Stars45/DebriefDlg.cpp index cf9882c..7765ca1 100644 --- a/Stars45/DebriefDlg.cpp +++ b/Stars45/DebriefDlg.cpp @@ -39,6 +39,7 @@ #include "ListBox.h" #include "Slider.h" #include "ParseUtil.h" +#include "Panic.h" // +--------------------------------------------------------------------+ // DECLARE MAPPING FUNCTIONS: @@ -367,7 +368,7 @@ DebriefDlg::OnClose(AWEvent* event) } else { - Game::Panic("DebriefDlg::OnClose() - Game instance not found"); + Panic::Panic("DebriefDlg::OnClose() - Game instance not found"); } } } diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp index 5ec6c0c..39c502e 100644 --- a/Stars45/Game.cpp +++ b/Stars45/Game.cpp @@ -17,6 +17,7 @@ #include "Color.h" #include "DataLoader.h" #include "Keyboard.h" +#include "Panic.h" #include "Pcx.h" #include "Bitmap.h" #include "MachineInfo.h" @@ -29,8 +30,6 @@ Game* game = 0; -char Game::panicbuf[256]; - const int VIDEO_FPS = 30; const double MAX_FRAME_TIME_VIDEO = 1.0 / (double) VIDEO_FPS; const double MAX_FRAME_TIME_NORMAL = 1.0 / 5.0; @@ -65,8 +64,6 @@ Game::Game() max_frame_length = MAX_FRAME_TIME_NORMAL; min_frame_length = MIN_FRAME_TIME_NORMAL; - panicbuf[0] = 0; - video_settings = new(__FILE__,__LINE__) VideoSettings; is_windowed = false; @@ -227,12 +224,12 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) stats.Clear(); if (!InitApplication(hInst)) { // Initialize shared things - Panic("Could not initialize the application."); + Panic::Panic("Could not initialize the application."); status = INIT_FAILED; } if (status == OK && !video_settings) { - Panic("No video settings specified"); + Panic::Panic("No video settings specified"); status = INIT_FAILED; } @@ -240,13 +237,13 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) static int os_version = MachineInfo::GetPlatform(); if (os_version == MachineInfo::OS_WIN95 || os_version == MachineInfo::OS_WIN98) { - Panic(" Windows 95 and 98 are no longer supported. Please update to Windows XP or higher."); + Panic::Panic(" Windows 95 and 98 are no longer supported. Please update to Windows XP or higher."); status = INIT_FAILED; } else if (os_version == MachineInfo::OS_WINNT) { - Panic(" D3D not available under WinNT 4"); + Panic::Panic(" D3D not available under WinNT 4"); status = INIT_FAILED; } else if (MachineInfo::GetDirectXVersion() < MachineInfo::DX_9) { - Panic(" Insufficient DirectX detected (Dx9 IS REQUIRED)"); + Panic::Panic(" Insufficient DirectX detected (Dx9 IS REQUIRED)"); status = INIT_FAILED; } @@ -257,7 +254,7 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) Print("\n Initializing instance...\n"); // Perform initializations that apply to a specific instance if (!InitInstance(hInst, nCmdShow)) { - Panic("Could not initialize the instance."); + Panic::Panic("Could not initialize the instance."); status = INIT_FAILED; } } @@ -268,8 +265,8 @@ Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) Print(" Initializing game...\n"); if (!InitGame()) { - if (!panicbuf[0]) - Panic("Could not initialize the game."); + if (Panic::Panicked()) + Panic::Panic("Could not initialize the game."); status = INIT_FAILED; } } @@ -383,7 +380,7 @@ Game::InitInstance(HINSTANCE hInstance, int nCmdShow) // If window could not be created, return "failure" if (!hwnd) { - Panic("Could not create window\n"); + Panic::Panic("Could not create window\n"); return false; } @@ -427,7 +424,7 @@ Game::InitVideo() video_factory->DestroyVideo(video); video = 0; - Panic("3D Hardware Not Found"); + Panic::Panic("3D Hardware Not Found"); } // save a copy of the device-specific video settings: @@ -462,7 +459,7 @@ Game::ResetVideo() } if (!video || video->Status() != Video::VIDEO_OK) { - Panic("Could not re-create Video Interface."); + Panic::Panic("Could not re-create Video Interface."); return false; } @@ -478,7 +475,7 @@ Game::ResetVideo() screen = new(__FILE__,__LINE__) Screen(video); if (!screen) { - Panic("Could not re-create Screen object."); + Panic::Panic("Could not re-create Screen object."); return false; } @@ -663,15 +660,15 @@ Game::InitGame() else { if (!SetupPalette()) { - Panic("Could not set up the palette."); + Panic::Panic("Could not set up the palette."); return false; } Print(" Palette loaded.\n"); if (!InitVideo() || !video || video->Status() != Video::VIDEO_OK) { - if (!panicbuf[0]) - Panic("Could not create the Video Interface."); + if (Panic::Panicked()) + Panic::Panic("Could not create the Video Interface."); return false; } @@ -681,8 +678,8 @@ Game::InitGame() screen = new(__FILE__,__LINE__) Screen(video); if (!screen) { - if (!panicbuf[0]) - Panic("Could not create the Screen object."); + if (Panic::Panicked()) + Panic::Panic("Could not create the Screen object."); return false; } @@ -772,7 +769,7 @@ Game::Run() Print("+====================================================================+\n"); // Polling messages from event queue until quit - while (status < EXIT) { + while (status < EXIT || Panic::Panicked()) { if (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; @@ -798,20 +795,6 @@ Game::Exit() status = EXIT; } -void -Game::Panic(const char* msg) -{ - if (msg) Print("*** PANIC: %s\n", msg); - else Print("*** PANIC! ***\n"); - - if (!msg) msg = "Unspecified fatal error."; - sprintf_s(panicbuf, "%s\nThis game will now terminate.", msg); - - if (game) { - game->status = PANIC; - } -} - // +--------------------------------------------------------------------+ void @@ -936,7 +919,7 @@ Game::UpdateScreen() video->Present(); } else { - Panic("Screen refresh failed."); + Panic::Panic("Screen refresh failed."); } } diff --git a/Stars45/Game.h b/Stars45/Game.h index 1be7170..4e691de 100644 --- a/Stars45/Game.h +++ b/Stars45/Game.h @@ -41,7 +41,7 @@ class Game : public ApplicationDX9 { public: static const char* TYPENAME() { return "Game"; } - enum STATUS { OK, RUN, EXIT, PANIC, INIT_FAILED, TOO_MANY }; + enum STATUS { OK, RUN, EXIT, INIT_FAILED, TOO_MANY }; Game(); virtual ~Game(); @@ -67,8 +67,6 @@ public: // static Game* GetInstance(); - static void Panic(const char* msg=0); - static const char* GetPanicMessage() { return panicbuf; } bool DisplayModeSupported(int w, int h, int bpp); int MaxTexSize(); @@ -192,8 +190,6 @@ protected: double max_frame_length; double min_frame_length; - - static char panicbuf[256]; }; // +--------------------------------------------------------------------+ diff --git a/Stars45/Main.cpp b/Stars45/Main.cpp index bd79886..dbb3a45 100644 --- a/Stars45/Main.cpp +++ b/Stars45/Main.cpp @@ -26,6 +26,7 @@ #include "MachineInfo.h" #include "Encrypt.h" #include "FormatUtil.h" +#include "Panic.h" #include "ParseUtil.h" #include "Random.h" #include "VersionInfo.h" @@ -132,8 +133,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, Token::close(); - if (*Game::GetPanicMessage()) - MessageBox(0, Game::GetPanicMessage(), "Starshatter - Error", MB_OK); + if (Panic::Panicked()) + MessageBox(0, Panic::Message(), "Starshatter - Error", MB_OK); } catch (const char* msg) { diff --git a/Stars45/MsnDlg.cpp b/Stars45/MsnDlg.cpp index fe2a878..65a3b00 100644 --- a/Stars45/MsnDlg.cpp +++ b/Stars45/MsnDlg.cpp @@ -33,6 +33,7 @@ #include "Button.h" #include "ListBox.h" #include "Slider.h" +#include "Panic.h" #include "ParseUtil.h" // +--------------------------------------------------------------------+ @@ -281,7 +282,7 @@ MsnDlg::OnCommit(AWEvent* event) } else - Game::Panic("MsnDlg::OnCommit() - Game instance not found"); + Panic::Panic("MsnDlg::OnCommit() - Game instance not found"); } void @@ -299,5 +300,5 @@ MsnDlg::OnCancel(AWEvent* event) } else - Game::Panic("MsnDlg::OnCancel() - Game instance not found"); + Panic::Panic("MsnDlg::OnCancel() - Game instance not found"); } diff --git a/Stars45/Ship.cpp b/Stars45/Ship.cpp index 61765fd..45c4c92 100644 --- a/Stars45/Ship.cpp +++ b/Stars45/Ship.cpp @@ -83,6 +83,7 @@ #include "Button.h" #include "Sound.h" #include "DataLoader.h" +#include "Panic.h" #include "Parser.h" #include "Reader.h" @@ -133,7 +134,7 @@ Ship::Ship(const char* ship_name, const char* reg_num, ShipDesign* ship_dsn, int if (!design) { char msg[256]; sprintf_s(msg, "No ship design found for '%s'\n", ship_name); - Game::Panic(msg); + Panic::Panic(msg); } obj_type = SimObject::SIM_SHIP; -- cgit v1.1