diff options
author | Aki <please@ignore.pl> | 2022-02-28 22:49:18 +0100 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-02-28 22:49:18 +0100 |
commit | c376af320ebd9d9e435ef3003dd35136dbd71ae8 (patch) | |
tree | 224ef8cdd3390260ed97d8278d1223d0494016c8 /Stars45/Game.cpp | |
parent | 724c36ea74dc6f2dfc097c45825c06df7756e058 (diff) | |
download | starshatter-c376af320ebd9d9e435ef3003dd35136dbd71ae8.zip starshatter-c376af320ebd9d9e435ef3003dd35136dbd71ae8.tar.gz starshatter-c376af320ebd9d9e435ef3003dd35136dbd71ae8.tar.bz2 |
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.
Diffstat (limited to 'Stars45/Game.cpp')
-rw-r--r-- | Stars45/Game.cpp | 57 |
1 files changed, 20 insertions, 37 deletions
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."); } } |