From 8f353abd0bfe18baddd8a8250ab7c4f2d1c83a6e Mon Sep 17 00:00:00 2001 From: Aki Date: Thu, 31 Mar 2022 23:41:46 +0200 Subject: Moved HINST and HWND from Game to GameWinDX9 --- Stars45/Game.cpp | 42 ++---------------------------------------- Stars45/Game.h | 5 ----- Stars45/GameWinDX9.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ Stars45/GameWinDX9.h | 8 ++++++++ Stars45/Joystick.cpp | 6 +++--- Stars45/MCIWave.cpp | 4 ++-- Stars45/StarServer.cpp | 2 -- Stars45/TrackIR.cpp | 4 ++-- 8 files changed, 57 insertions(+), 54 deletions(-) (limited to 'Stars45') diff --git a/Stars45/Game.cpp b/Stars45/Game.cpp index bd6484e..3b480cc 100644 --- a/Stars45/Game.cpp +++ b/Stars45/Game.cpp @@ -34,7 +34,6 @@ const double MAX_FRAME_TIME_NORMAL = 1.0 / 5.0; Game::Game() : world(0), video_factory(0), video(0), video_settings(0), soundcard(0), screen(0), totaltime(0), - hInst(0), hwnd(0), status(Game::OK), exit_code(0), window_style(0) { Clock::Init(); @@ -75,24 +74,6 @@ Game::~Game() // +--------------------------------------------------------------------+ -HINSTANCE Game::GetHINST() -{ - if (game) - return game->hInst; - - return 0; -} - -HWND Game::GetHWND() -{ - if (game) - return game->hwnd; - - return 0; -} - -// +--------------------------------------------------------------------+ - bool Game::Init(HINSTANCE hi, HINSTANCE hpi, LPSTR cmdline, int nCmdShow) { @@ -129,31 +110,12 @@ Game::InitGame() int Game::Run() { - MSG msg; - status = RUN; - Print("\n"); - Print("+====================================================================+\n"); - Print("| RUN |\n"); - Print("+====================================================================+\n"); - - // Polling messages from event queue until quit Clock::GetInstance()->Set(); while (status < EXIT && !Panic::Panicked()) { - if (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) { - if (msg.message == WM_QUIT) - break; - - TranslateMessage(&msg); - DispatchMessage(&msg); - } - else { - if (GameLoop()) - WaitMessage(); - } + GameLoop(); } - - return exit_code ? exit_code : msg.wParam; + return exit_code; } // +--------------------------------------------------------------------+ diff --git a/Stars45/Game.h b/Stars45/Game.h index 518789c..0a59197 100644 --- a/Stars45/Game.h +++ b/Stars45/Game.h @@ -67,9 +67,6 @@ public: bool Server() { return server; } bool ShowMouse() { return show_mouse; } - HINSTANCE GetHINST(); - HWND GetHWND(); - virtual bool GameLoop(); virtual void UpdateWorld(); virtual void GameState(); @@ -91,8 +88,6 @@ protected: RenderStats stats; DWORD totaltime; - HINSTANCE hInst; - HWND hwnd; HMENU hmenu; DWORD winstyle; diff --git a/Stars45/GameWinDX9.cpp b/Stars45/GameWinDX9.cpp index 5414027..5d04c97 100644 --- a/Stars45/GameWinDX9.cpp +++ b/Stars45/GameWinDX9.cpp @@ -10,6 +10,7 @@ #include #include "Bitmap.h" +#include "Clock.h" #include "Color.h" #include "DataLoader.h" #include "Game.h" @@ -35,6 +36,8 @@ GameWinDX9::GetInstance() GameWinDX9::GameWinDX9() : max_tex_size {2048}, screen_color {Color::Black}, + hInst{nullptr}, + hwnd{nullptr}, is_windowed {false}, is_active {false}, is_device_lost {false}, @@ -554,6 +557,29 @@ GameWinDX9::LoadPalette(PALETTEENTRY* pal, BYTE* inv) int +GameWinDX9::Run() +{ + MSG msg; + status = RUN; + Clock::GetInstance()->Set(); + while (status < EXIT && !Panic::Panicked()) { + if (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) { + if (msg.message == WM_QUIT) + break; + + TranslateMessage(&msg); + DispatchMessage(&msg); + } + else { + if (GameLoop()) + WaitMessage(); + } + } + return exit_code ? exit_code : msg.wParam; +} + + +int GameWinDX9::MaxTexSize() const { if (video) { @@ -605,6 +631,20 @@ GameWinDX9::GetScreenHeight() const } +HINSTANCE +GameWinDX9::GetHINST() +{ + return hInst; +} + + +HWND +GameWinDX9::GetHWND() +{ + return hwnd; +} + + void GameWinDX9::SetMaxTexSize(int n) { diff --git a/Stars45/GameWinDX9.h b/Stars45/GameWinDX9.h index 9f31ce1..43fc71d 100644 --- a/Stars45/GameWinDX9.h +++ b/Stars45/GameWinDX9.h @@ -35,12 +35,17 @@ public: virtual bool SetupPalette(); virtual bool LoadPalette(PALETTEENTRY* pal, BYTE* inv); + virtual int Run() override; + int MaxTexSize() const; int MaxTexAspect() const; Color GetScreenColor() const; int GetScreenWidth() const; int GetScreenHeight() const; + HINSTANCE GetHINST(); + HWND GetHWND(); + void SetMaxTexSize(int n); void SetScreenColor(Color c); @@ -54,6 +59,9 @@ protected: int max_tex_size; Color screen_color; + HINSTANCE hInst; + HWND hwnd; + bool is_windowed; bool is_active; bool is_device_lost; diff --git a/Stars45/Joystick.cpp b/Stars45/Joystick.cpp index 48ec842..8b1a2ee 100644 --- a/Stars45/Joystick.cpp +++ b/Stars45/Joystick.cpp @@ -11,7 +11,7 @@ Joystick Input class */ -#include "Game.h" +#include "GameWinDX9.h" #include "Joystick.h" #include "MachineInfo.h" #include "Types.h" @@ -86,7 +86,7 @@ Joystick::Joystick() } else if (!pdi) { - HRESULT hr = DirectInput8Create(Game::GetInstance()->GetHINST(), + HRESULT hr = DirectInput8Create(GameWinDX9::GetInstance()->GetHINST(), DIRECTINPUT_VERSION, IID_IDirectInput7, (void**)&pdi, @@ -269,7 +269,7 @@ bool CreateDevice(int select) } // Set the coop level: - hr = pdev->SetCooperativeLevel(Game::GetInstance()->GetHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); + hr = pdev->SetCooperativeLevel(GameWinDX9::GetInstance()->GetHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND); if (hr != DI_OK) { DirectInputError("Set Cooperative Level failed", hr); diff --git a/Stars45/MCIWave.cpp b/Stars45/MCIWave.cpp index 4840eb6..a8c0a0b 100644 --- a/Stars45/MCIWave.cpp +++ b/Stars45/MCIWave.cpp @@ -12,7 +12,7 @@ */ #include "Types.h" -#include "Game.h" +#include "GameWinDX9.h" #include "Utils.h" // +----------------------------------------------------------------------+ @@ -25,7 +25,7 @@ static MMRESULT wav_err; static int mci_send_string(const char* cmd_str) { - mci_err = mciSendString(cmd_str, ret_str, sizeof(ret_str), Game::GetInstance()->GetHWND()); + mci_err = mciSendString(cmd_str, ret_str, sizeof(ret_str), GameWinDX9::GetInstance()->GetHWND()); if (mci_err) { if (mciGetErrorString(mci_err, err_str, sizeof(err_str))) Print("Error (%s): '%s'\n", cmd_str, err_str); diff --git a/Stars45/StarServer.cpp b/Stars45/StarServer.cpp index ceaa5ca..a03bd15 100644 --- a/Stars45/StarServer.cpp +++ b/Stars45/StarServer.cpp @@ -88,7 +88,6 @@ admin_server(0), lobby_server(0) "The file 'shatter.dat' appears to have been damaged. Please re-install Starshatter." : "Starshatter cannot open the file 'shatter.dat'. Please re-install Starshatter."; - ::MessageBox(hwnd, err_msg, "Starshatter - Error", MB_OK); ::Print(err_msg); ::Print("\n\nFATAL ERROR: EXIT."); exit(-1); @@ -342,7 +341,6 @@ StarServer::UpdateWorld() static DWORD refresh_time = 0; if (Clock::GetInstance()->RealTime() - refresh_time > 1000) { refresh_time = Clock::GetInstance()->RealTime(); - RedrawWindow(hwnd, 0, 0, RDW_ERASE|RDW_INVALIDATE); } } diff --git a/Stars45/TrackIR.cpp b/Stars45/TrackIR.cpp index fbe8108..87dd937 100644 --- a/Stars45/TrackIR.cpp +++ b/Stars45/TrackIR.cpp @@ -15,7 +15,7 @@ #include "NPClient.h" #include "NPClientWraps.h" -#include "Game.h" +#include "GameWinDX9.h" #include "Text.h" // +--------------------------------------------------------------------+ @@ -101,7 +101,7 @@ az(0), el(0), x(0), y(0), z(0) } // Register the app's window handle - result = NP_RegisterWindowHandle(Game::GetInstance()->GetHWND()); + result = NP_RegisterWindowHandle(GameWinDX9::GetInstance()->GetHWND()); if (result == NP_OK) { Print("NPClient - Window handle registration successful.\n"); -- cgit v1.1