Skip to content

Commit

Permalink
First pass of plClientWindow work
Browse files Browse the repository at this point in the history
  • Loading branch information
dpogue committed Nov 14, 2023
1 parent db8c702 commit 9481718
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 77 deletions.
10 changes: 10 additions & 0 deletions Sources/Plasma/Apps/plClient/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ set(plClient_HEADERS
plClientCreatable.h
plClientLoader.h
plClientUpdateFormat.h
plClientWindow.h
)

set(plClient_SOURCES
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions Sources/Plasma/Apps/plClient/Mac-Cocoa/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
46 changes: 33 additions & 13 deletions Sources/Plasma/Apps/plClient/linux/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "plClient.h"
#include "plClientLoader.h"
#include "plX11ClientWindow.h"

#include "pnEncryption/plChallengeHash.h"

Expand All @@ -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
Expand Down Expand Up @@ -165,22 +167,26 @@ 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,
values);

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() {}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -442,6 +449,7 @@ static bool XInit(xcb_connection_t* connection)
gClient.Init();
return true;
}
#endif

static void PumpMessageQueueProc()
{
Expand All @@ -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)
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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");
Expand All @@ -712,22 +727,27 @@ 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);

if (!XInit(gXConn)) {
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();
Expand All @@ -740,7 +760,7 @@ int main(int argc, const char** argv)
gClient.ShutdownEnd();
NetCommShutdown();

xcb_disconnect(gXConn);
//xcb_disconnect(gXConn);

return 0;
}
Expand Down Expand Up @@ -780,7 +800,7 @@ int main(int argc, const char** argv)
gClient.ShutdownEnd();
NetCommShutdown();

xcb_disconnect(gXConn);
//xcb_disconnect(gXConn);

return 0;
}
113 changes: 113 additions & 0 deletions Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.cpp
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 [email protected]
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 <string_theory/format>
#include <X11/Xlib.h>

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);
}
65 changes: 65 additions & 0 deletions Sources/Plasma/Apps/plClient/linux/plX11ClientWindow.h
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
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 [email protected]
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;
}
};
Loading

0 comments on commit 9481718

Please sign in to comment.