From 9481718b673a8e1366a5c37d98cc563441f60f9f Mon Sep 17 00:00:00 2001 From: Darryl Pogue Date: Mon, 13 Nov 2023 21:53:28 -0800 Subject: [PATCH] First pass of plClientWindow work --- Sources/Plasma/Apps/plClient/CMakeLists.txt | 10 ++ .../Plasma/Apps/plClient/Mac-Cocoa/main.mm | 5 +- Sources/Plasma/Apps/plClient/linux/main.cpp | 46 +++++-- .../Apps/plClient/linux/plX11ClientWindow.cpp | 113 ++++++++++++++++++ .../Apps/plClient/linux/plX11ClientWindow.h | 65 ++++++++++ .../Plasma/Apps/plClient/plClientLoader.cpp | 10 +- Sources/Plasma/Apps/plClient/plClientLoader.h | 17 ++- Sources/Plasma/Apps/plClient/plClientWindow.h | 84 +++++++++++++ .../Apps/plClient/win32/plClient_Win.cpp | 6 +- .../plClient/win32/plWin32ClientWindow.cpp | 99 +++++++++++++++ .../Apps/plClient/win32/plWin32ClientWindow.h | 68 +++++++++++ .../Plasma/Apps/plClient/win32/winmain.cpp | 57 ++------- 12 files changed, 503 insertions(+), 77 deletions(-) create mode 100644 Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.cpp create mode 100644 Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.h create mode 100644 Sources/Plasma/Apps/plClient/plClientWindow.h create mode 100644 Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.cpp create mode 100644 Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.h diff --git a/Sources/Plasma/Apps/plClient/CMakeLists.txt b/Sources/Plasma/Apps/plClient/CMakeLists.txt index fb2d6557cc..8235405867 100644 --- a/Sources/Plasma/Apps/plClient/CMakeLists.txt +++ b/Sources/Plasma/Apps/plClient/CMakeLists.txt @@ -58,6 +58,7 @@ set(plClient_HEADERS plClientCreatable.h plClientLoader.h plClientUpdateFormat.h + plClientWindow.h ) set(plClient_SOURCES @@ -76,8 +77,12 @@ set(plClient_TEXT ) if(WIN32) + list(APPEND plClient_HEADERS + win32/plWin32ClientWindow.h + ) list(APPEND plClient_SOURCES win32/plClient_Win.cpp + win32/plWin32ClientWindow.cpp win32/winmain.cpp ) list(APPEND plClient_RESOURCES @@ -122,7 +127,12 @@ elseif(APPLE) win32/res/Dirt.ICO ) elseif(UNIX AND NOT APPLE) + list(APPEND plClient_HEADERS + linux/plX11ClientWindow.h + ) + list(APPEND plClient_SOURCES + linux/plX11ClientWindow.cpp linux/main.cpp ) else() diff --git a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm index 300a4195de..eb0130443e 100644 --- a/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm +++ b/Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm @@ -60,6 +60,7 @@ // Plasma engine #include "plClient/plClient.h" #include "plClient/plClientLoader.h" +#include "plClient/plClientWindow.h" #include "plCmdParser.h" #include "pfConsoleCore/pfConsoleEngine.h" #include "pfGameGUIMgr/pfGameGUIMgr.h" @@ -451,8 +452,8 @@ - (void)startClient [self.window makeKeyAndOrderFront:self]; self.renderLayer = self.window.contentView.layer; - gClient.SetClientWindow((hsWindowHndl)(__bridge void*)self.window); - gClient.SetClientDisplay((hsWindowHndl)NULL); + plClientWindow* cwnd = new plStubClientWindow((hsWindowHndl)(__bridge void*)self.window, (hsWindowHndl)nullptr); + gClient.SetClientWindow(cwnd); if (!gClient) { exit(0); diff --git a/Sources/Plasma/Apps/plClient/linux/main.cpp b/Sources/Plasma/Apps/plClient/linux/main.cpp index 0bf2501724..e0ddcc8ac3 100644 --- a/Sources/Plasma/Apps/plClient/linux/main.cpp +++ b/Sources/Plasma/Apps/plClient/linux/main.cpp @@ -66,6 +66,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plClient.h" #include "plClientLoader.h" +#include "plX11ClientWindow.h" #include "pnEncryption/plChallengeHash.h" @@ -88,10 +89,11 @@ extern bool gPythonLocal; extern bool gSDLLocal; static plClientLoader gClient; -static xcb_connection_t* gXConn; -static xcb_key_symbols_t* keysyms; -static pcSmallRect gWindowSize; -static bool gHasXFixes = false; +static plClientWindow* gWindow = nullptr; +//static xcb_connection_t* gXConn; +//static xcb_key_symbols_t* keysyms; +//static pcSmallRect gWindowSize; +//static bool gHasXFixes = false; static hsSemaphore statusFlag; enum @@ -165,6 +167,7 @@ void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed) { hsStatusMessage(ST::format("Setting window size to {}×{}", width, height).c_str()); +#if 0 const uint32_t values[] = { uint32_t(width), uint32_t(height) }; xcb_configure_window(gXConn, (xcb_window_t)(uintptr_t)fWindowHndl, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, @@ -172,15 +175,18 @@ void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed) gWindowSize.fWidth = width; gWindowSize.fHeight = height; +#endif } void plClient::IChangeResolution(int width, int height) {} void plClient::IUpdateProgressIndicator(plOperationProgress* progress) {} void plClient::ShowClientWindow() { +#if 0 /* Map the window on the screen */ xcb_map_window(gXConn, (xcb_window_t)(uintptr_t)fWindowHndl); xcb_flush(gXConn); +#endif } void plClient::FlashWindow() {} @@ -372,6 +378,7 @@ static uint32_t ParseRendererArgument(const ST::string& requested) return hsG3DDeviceSelector::kDevTypeUnknown; } +#if 0 static bool XInit(xcb_connection_t* connection) { gWindowSize.Set(0, 0, 800, 600); @@ -442,6 +449,7 @@ static bool XInit(xcb_connection_t* connection) gClient.Init(); return true; } +#endif static void PumpMessageQueueProc() { @@ -457,6 +465,7 @@ static void PumpMessageQueueProc() 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }; +#if 0 xcb_generic_event_t* event; while ((event = xcb_poll_for_event(gXConn))) { switch (event->response_type & ~0x80) @@ -643,9 +652,9 @@ static void PumpMessageQueueProc() free(event); } +#endif } -// Stub main function so it compiles on non-Windows int main(int argc, const char** argv) { PF_CONSOLE_INIT_ALL(); @@ -689,6 +698,12 @@ int main(int argc, const char** argv) if (cmdParser.IsSpecified(kArgServerIni)) serverIni = cmdParser.GetString(kArgServerIni); + gWindow = new plX11ClientWindow(); + if (!gWindow->PreInit()) { + hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal); + return 1; + } + // Load an optional general.ini plFileName gipath = plFileName::Join(plFileSystem::GetInitPath(), "general.ini"); FILE *generalini = plFileSystem::Open(gipath, "rb"); @@ -712,15 +727,11 @@ int main(int argc, const char** argv) } else { - hsMessageBox("No server.ini file found. Please check your URU installation.", "Error", hsMessageBoxNormal); - return 1; - } - - if (!XInitThreads()) { - hsMessageBox("Failed to initialize plClient", "Error", hsMessageBoxNormal); + hsMessageBox(ST_LITERAL("No server.ini file found. Please check your URU installation."), ST_LITERAL("Error"), hsMessageBoxNormal); return 1; } +#if 0 /* Open the connection to the X server */ gXConn = xcb_connect(nullptr, nullptr); @@ -728,6 +739,15 @@ int main(int argc, const char** argv) hsMessageBox("Failed to initialize plClient", "Error", hsMessageBoxNormal); return 1; } +#endif + + if (!gWindow->CreateClientWindow()) { + hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal); + return 1; + } + + gClient.SetClientWindow(gWindow); + gClient.Init(); NetCliAuthAutoReconnectEnable(false); NetCommStartup(); @@ -740,7 +760,7 @@ int main(int argc, const char** argv) gClient.ShutdownEnd(); NetCommShutdown(); - xcb_disconnect(gXConn); + //xcb_disconnect(gXConn); return 0; } @@ -780,7 +800,7 @@ int main(int argc, const char** argv) gClient.ShutdownEnd(); NetCommShutdown(); - xcb_disconnect(gXConn); + //xcb_disconnect(gXConn); return 0; } diff --git a/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.cpp b/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.cpp new file mode 100644 index 0000000000..2ec1b3b2e5 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.cpp @@ -0,0 +1,113 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "plX11ClientWindow.h" +#include "hsOptionalCall.h" +#include "plProduct.h" + +#include +#include + +hsOptionalCallDecl("libX11.so", XCloseDisplay); +hsOptionalCallDecl("libX11.so", XCreateWindow); +hsOptionalCallDecl("libX11.so", XDestroyWindow); +hsOptionalCallDecl("libX11.so", XFlush); +hsOptionalCallDecl("libX11.so", XInitThreads); +hsOptionalCallDecl("libX11.so", XMapWindow); +hsOptionalCallDecl("libX11.so", XOpenDisplay); +hsOptionalCallDecl("libX11.so", XStoreName); + +bool plX11ClientWindow::PreInit() +{ + // First: Check that we were able to dynamically load the X11 functions + if (!(bool)__XOpenDisplay) + return false; + + if (!*__XInitThreads()) + return false; + + return true; +} + +bool plX11ClientWindow::CreateClientWindow() +{ + fXDisplay = *__XOpenDisplay(nullptr); + if (!fXDisplay) { + hsDebugMessage("Could not connect to X server", -1); + return false; + } + + Window root = DefaultRootWindow(fXDisplay); + + XSetWindowAttributes win_attrs; + win_attrs.background_pixmap = None; + win_attrs.event_mask = ExposureMask + | EnterWindowMask + | LeaveWindowMask + | PointerMotionMask + | ButtonPressMask + | ButtonReleaseMask + | KeyPressMask + | KeyReleaseMask + | StructureNotifyMask; + + fXWindow = *__XCreateWindow(fXDisplay, root, fWindowSize.fX, fWindowSize.fY, fWindowSize.fWidth, fWindowSize.fHeight, 0, CopyFromParent, InputOutput, CopyFromParent, CWEventMask | CWBackPixmap, &win_attrs); + + const char* title = ST::format("{}", plProduct::LongName()).c_str(); + __XStoreName(fXDisplay, fXWindow, title); + + return true; +} + +void plX11ClientWindow::ShowClientWindow() +{ + __XMapWindow(fXDisplay, fXWindow); + __XFlush(fXDisplay); +} + +void plX11ClientWindow::DeInit() +{ + if (fXWindow) + __XDestroyWindow(fXDisplay, fXWindow); + if (fXDisplay) + __XCloseDisplay(fXDisplay); +} diff --git a/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.h b/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.h new file mode 100644 index 0000000000..63335f4ac7 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.h @@ -0,0 +1,65 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "plClientWindow.h" + +class plX11ClientWindow : public plClientWindow +{ +private: + struct _XDisplay* fXDisplay; + uint32_t fXWindow; + +public: + plX11ClientWindow() : plClientWindow(), fXDisplay(), fXWindow() { } + + bool PreInit() override; + bool CreateClientWindow() override; + void ShowClientWindow() override; + void DeInit() override; + + hsWindowHndl GetWindowHandle() const override { + return (hsWindowHndl)(uintptr_t)fXWindow; + } + hsWindowHndl GetDisplayHandle() const override { + return (hsWindowHndl)fXDisplay; + } +}; diff --git a/Sources/Plasma/Apps/plClient/plClientLoader.cpp b/Sources/Plasma/Apps/plClient/plClientLoader.cpp index a57a6b42bd..2854fda8e2 100644 --- a/Sources/Plasma/Apps/plClient/plClientLoader.cpp +++ b/Sources/Plasma/Apps/plClient/plClientLoader.cpp @@ -42,6 +42,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plClientLoader.h" #include "plClient.h" +#include "plClientWindow.h" #include "plFileSystem.h" #include "plPipeline.h" @@ -66,7 +67,7 @@ void plClientLoader::Run() plClientResMgr::Instance().ILoadResources("resource.dat"); fClient = new plClient; - fClient->SetWindowHandle(fWindow); + fClient->SetWindowHandle(fWindow->GetWindowHandle()); plSimulationMgr::Init(); if (plSimulationMgr::GetInstance()) { @@ -76,7 +77,7 @@ void plClientLoader::Run() return; } - if (fClient->InitPipeline(fDisplay, fDevType) || !fClient->StartInit()) { + if (fClient->InitPipeline(fWindow->GetDisplayHandle(), fDevType) || !fClient->StartInit()) { fClient->SetDone(true); } } @@ -84,6 +85,7 @@ void plClientLoader::Run() void plClientLoader::Start() { fClient->ResizeDisplayDevice(fClient->GetPipeline()->Width(), fClient->GetPipeline()->Height(), !fClient->GetPipeline()->IsFullScreen()); + fWindow->ShowClientWindow(); fClient->ShowClientWindow(); // Now, show the intro video, patch the global ages, etc... @@ -106,6 +108,10 @@ void plClientLoader::ShutdownEnd() { if (fClient) fClient->Shutdown(); + + if (fWindow) + fWindow->DeInit(); + hsAssert(hsgResMgr::ResMgr()->RefCnt() == 1, "resMgr has too many refs, expect mem leaks"); hsgResMgr::Shutdown(); } diff --git a/Sources/Plasma/Apps/plClient/plClientLoader.h b/Sources/Plasma/Apps/plClient/plClientLoader.h index c73cf27909..ca9040d2f1 100644 --- a/Sources/Plasma/Apps/plClient/plClientLoader.h +++ b/Sources/Plasma/Apps/plClient/plClientLoader.h @@ -44,11 +44,13 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "hsThread.h" #include "hsWindows.h" +class plClient; +class plClientWindow; + class plClientLoader : private hsThread { - class plClient* fClient; - hsWindowHndl fWindow; - hsWindowHndl fDisplay; + plClient* fClient; + plClientWindow* fWindow; uint32_t fDevType; void OnQuit() override @@ -60,7 +62,7 @@ class plClientLoader : private hsThread void Run() override; public: - plClientLoader() : fClient(), fWindow(), fDisplay(), fDevType() { } + plClientLoader() : fClient(), fWindow(), fDevType() { } /** * Initializes the client asyncrhonouslynn including: loading the localization, @@ -80,12 +82,7 @@ class plClientLoader : private hsThread /** * Sets the client window handle. */ - void SetClientWindow(hsWindowHndl hWnd) { fWindow = hWnd; } - - /** - * Sets the client display handle. - */ - void SetClientDisplay(hsWindowHndl hDC) { fDisplay = hDC; } + void SetClientWindow(plClientWindow* wnd) { fWindow = wnd; } /** * Sets the preferred rendering backend for the client pipeline. diff --git a/Sources/Plasma/Apps/plClient/plClientWindow.h b/Sources/Plasma/Apps/plClient/plClientWindow.h new file mode 100644 index 0000000000..b2926520f9 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/plClientWindow.h @@ -0,0 +1,84 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "HeadSpin.h" +#include "pcSmallRect.h" + +class plClientWindow +{ +protected: + pcSmallRect fWindowSize; + +public: + plClientWindow() : fWindowSize(0, 0, 800, 600) { } + + virtual bool PreInit() = 0; + virtual bool CreateClientWindow() = 0; + virtual void ShowClientWindow() = 0; + virtual void DeInit() = 0; + + virtual hsWindowHndl GetWindowHandle() const = 0; + virtual hsWindowHndl GetDisplayHandle() const = 0; +}; + + +class plStubClientWindow : public plClientWindow +{ +private: + hsWindowHndl fWindow; + hsWindowHndl fDisplay; + +public: + plStubClientWindow(hsWindowHndl w, hsWindowHndl d) : plClientWindow(), fWindow(w), fDisplay(d) { } + + bool PreInit() override { return true; } + bool CreateClientWindow() override { return true; } + void ShowClientWindow() override { } + void DeInit() override { } + + hsWindowHndl GetWindowHandle() const override { + return fWindow; + } + hsWindowHndl GetDisplayHandle() const override { + return fDisplay; + } +}; diff --git a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp index b8aaa4215a..97c75bae6b 100644 --- a/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp +++ b/Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp @@ -145,11 +145,7 @@ void plClient::IUpdateProgressIndicator(plOperationProgress* progress) } // Show the client window -void plClient::ShowClientWindow() -{ - ShowWindow(fWindowHndl, SW_SHOW); - BringWindowToTop(fWindowHndl); -} +void plClient::ShowClientWindow() { } void plClient::FlashWindow() { diff --git a/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.cpp b/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.cpp new file mode 100644 index 0000000000..729e215d12 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.cpp @@ -0,0 +1,99 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "plWin32ClientWindow.h" +#include "res/resource.h" +#include "plProduct.h" +#include "plWinDpi/plWinDpi.h" + +#define CLASSNAME "Plasma" + +bool plWin32ClientWindow::PreInit() +{ + // Initialize the DPI helpers + plWinDpi::Instance(); + + return true; +} + +bool plWin32ClientWindow::CreateClientWindow() +{ + // Fill out WNDCLASS info + WNDCLASS wndClass; + wndClass.style = CS_DBLCLKS; // CS_HREDRAW | CS_VREDRAW; + wndClass.lpfnWndProc = fProc; + wndClass.cbClsExtra = 0; + wndClass.cbWndExtra = 0; + wndClass.hInstance = fInst; + wndClass.hIcon = LoadIcon(fInst, MAKEINTRESOURCE(IDI_ICON_DIRT)); + wndClass.hCursor = LoadCursor(nullptr, IDC_ARROW); + wndClass.hbrBackground = (struct HBRUSH__*) (GetStockObject(BLACK_BRUSH)); + wndClass.lpszMenuName = CLASSNAME; + wndClass.lpszClassName = CLASSNAME; + + // can only run one at a time anyway, so just quit if another is running + if (!RegisterClass(&wndClass)) + return false; + + int winBorderDX = plWinDpi::Instance().GetSystemMetrics(SM_CXSIZEFRAME); + int winBorderDY = plWinDpi::Instance().GetSystemMetrics(SM_CYSIZEFRAME); + int winMenuDY = plWinDpi::Instance().GetSystemMetrics(SM_CYCAPTION); + + // Create a window + fWnd = CreateWindow( + CLASSNAME, plProduct::LongName().c_str(), + WS_OVERLAPPEDWINDOW, + 0, 0, + 800 + winBorderDX * 2, + 600 + winBorderDY * 2 + winMenuDY, + nullptr, nullptr, fInst, nullptr + ); + fDC = GetDC(fWnd); + + return true; +} + +void plWin32ClientWindow::ShowClientWindow() +{ + ShowWindow(fWnd, SW_SHOW); + BringWindowToTop(fWnd); +} diff --git a/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.h b/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.h new file mode 100644 index 0000000000..fbe69e1e15 --- /dev/null +++ b/Sources/Plasma/Apps/plClient/win32/plWin32ClientWindow.h @@ -0,0 +1,68 @@ +/*==LICENSE==* + +CyanWorlds.com Engine - MMOG client, server and tools +Copyright (C) 2011 Cyan Worlds, Inc. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . + +Additional permissions under GNU GPL version 3 section 7 + +If you modify this Program, or any covered work, by linking or +combining it with any of RAD Game Tools Bink SDK, Autodesk 3ds Max SDK, +NVIDIA PhysX SDK, Microsoft DirectX SDK, OpenSSL library, Independent +JPEG Group JPEG library, Microsoft Windows Media SDK, or Apple QuickTime SDK +(or a modified version of those libraries), +containing parts covered by the terms of the Bink SDK EULA, 3ds Max EULA, +PhysX SDK EULA, DirectX SDK EULA, OpenSSL and SSLeay licenses, IJG +JPEG Library README, Windows Media SDK EULA, or QuickTime SDK EULA, the +licensors of this Program grant you additional +permission to convey the resulting work. Corresponding Source for a +non-source form of such a combination shall include the source code for +the parts of OpenSSL and IJG JPEG Library used as well as that of the covered +work. + +You can contact Cyan Worlds, Inc. by email legal@cyan.com + or by snail mail at: + Cyan Worlds, Inc. + 14617 N Newport Hwy + Mead, WA 99021 + +*==LICENSE==*/ + +#include "plClientWindow.h" +#include "hsWindows.h" + +class plWin32ClientWindow : public plClientWindow +{ +private: + HINSTANCE fInst; + WNDPROC fProc; + HWND fWnd; + HDC fDC; + +public: + plWin32ClientWindow(HINSTANCE inst, WNDPROC proc) : plClientWindow(), fInst(inst), fProc(proc), fWnd(), fDC() { } + + bool PreInit() override; + bool CreateClientWindow() override; + void ShowClientWindow() override; + void DeInit() override { } + + hsWindowHndl GetWindowHandle() const override { + return (hsWindowHndl)fWnd; + } + hsWindowHndl GetDisplayHandle() const override { + return (hsWindowHndl)fDC; + } +}; diff --git a/Sources/Plasma/Apps/plClient/win32/winmain.cpp b/Sources/Plasma/Apps/plClient/win32/winmain.cpp index 58ccae7fa9..01f9b30e02 100644 --- a/Sources/Plasma/Apps/plClient/win32/winmain.cpp +++ b/Sources/Plasma/Apps/plClient/win32/winmain.cpp @@ -58,6 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #include "plClient.h" #include "plClientLoader.h" +#include "plWin32ClientWindow.h" #include "res/resource.h" #include "pnEncryption/plChallengeHash.h" @@ -143,6 +144,7 @@ static UINT s_WmTaskbarList = RegisterWindowMessage("TaskbarButtonCr FILE *errFP = nullptr; HINSTANCE gHInst = nullptr; // Instance of this app +static plClientWindow* gWindow = nullptr; static const unsigned AUTH_LOGIN_TIMER = 1; static const unsigned AUTH_FAILED_TIMER = 2; @@ -1021,50 +1023,6 @@ uint32_t ParseRendererArgument(const ST::string& requested) PF_CONSOLE_LINK_ALL() -bool WinInit(HINSTANCE hInst) -{ - // Initialize the DPI helpers - plWinDpi::Instance(); - - // Fill out WNDCLASS info - WNDCLASS wndClass; - wndClass.style = CS_DBLCLKS; // CS_HREDRAW | CS_VREDRAW; - wndClass.lpfnWndProc = WndProc; - wndClass.cbClsExtra = 0; - wndClass.cbWndExtra = 0; - wndClass.hInstance = hInst; - wndClass.hIcon = LoadIcon(hInst, MAKEINTRESOURCE(IDI_ICON_DIRT)); - - wndClass.hCursor = LoadCursor(nullptr, IDC_ARROW); - wndClass.hbrBackground = (struct HBRUSH__*) (GetStockObject(BLACK_BRUSH)); - wndClass.lpszMenuName = CLASSNAME; - wndClass.lpszClassName = CLASSNAME; - - // can only run one at a time anyway, so just quit if another is running - if (!RegisterClass(&wndClass)) - return false; - - int winBorderDX = plWinDpi::Instance().GetSystemMetrics(SM_CXSIZEFRAME); - int winBorderDY = plWinDpi::Instance().GetSystemMetrics(SM_CYSIZEFRAME); - int winMenuDY = plWinDpi::Instance().GetSystemMetrics(SM_CYCAPTION); - - // Create a window - HWND hWnd = CreateWindow( - CLASSNAME, plProduct::LongName().c_str(), - WS_OVERLAPPEDWINDOW, - 0, 0, - 800 + winBorderDX * 2, - 600 + winBorderDY * 2 + winMenuDY, - nullptr, nullptr, hInst, nullptr - ); - HDC hDC = GetDC(hWnd); - - gClient.SetClientWindow((hsWindowHndl)hWnd); - gClient.SetClientDisplay((hsWindowHndl)hDC); - gClient.Init(); - return true; -} - int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nCmdShow) { PF_CONSOLE_INIT_ALL() @@ -1107,6 +1065,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC if (cmdParser.IsSpecified(kArgServerIni)) serverIni = cmdParser.GetString(kArgServerIni); + gWindow = new plWin32ClientWindow(hInst, WndProc); + if (!gWindow->PreInit()) { + hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal); + return PARABLE_NORMAL_EXIT; + } + // check to see if we were launched from the patcher bool eventExists = false; // we check to see if the event exists that the patcher should have created @@ -1211,11 +1175,14 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC } // Begin initializing the client in the background - if (!WinInit(hInst)) { + if (!gWindow->CreateClientWindow()) { hsMessageBox(ST_LITERAL("Failed to initialize plClient"), ST_LITERAL("Error"), hsMessageBoxNormal); return PARABLE_NORMAL_EXIT; } + gClient.SetClientWindow(gWindow); + gClient.Init(); + NetCliAuthAutoReconnectEnable(false); InitNetClientComm();