Skip to content

Commit

Permalink
Merged ZDoom/gzdoom#1927 (Host/Join CCMDs)
Browse files Browse the repository at this point in the history
  • Loading branch information
MajorCooke committed Jan 21, 2023
1 parent 050f982 commit 3d7e8bf
Show file tree
Hide file tree
Showing 10 changed files with 373 additions and 23 deletions.
4 changes: 2 additions & 2 deletions src/common/platform/win32/base_sysfb.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ class SystemBaseFrameBuffer : public DFrameBuffer
void ToggleFullscreen(bool yes) override;
void SetWindowSize(int client_w, int client_h);

void PositionWindow(bool fullscreen, bool initialcall = false); // RicardoLuis0: this needs to be public for proper fullscreen handling in netgame restarts

protected:

void GetCenteredPos(int in_w, int in_h, int &winx, int &winy, int &winw, int &winh, int &scrwidth, int &scrheight);
void KeepWindowOnScreen(int &winx, int &winy, int winw, int winh, int scrwidth, int scrheight);

void PositionWindow(bool fullscreen, bool initialcall = false);

float m_Gamma, m_Brightness, m_Contrast;
uint16_t m_origGamma[768];
bool m_Fullscreen = false;
Expand Down
12 changes: 12 additions & 0 deletions src/common/platform/win32/i_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
#include "printf.h"

#include "i_mainwindow.h"
#include "base_sysfb.h"

// MACROS ------------------------------------------------------------------

Expand Down Expand Up @@ -314,6 +315,17 @@ void I_ShowFatalError(const char *msg)
}
}

void I_NetRestartShowConsole()
{
if(vid_fullscreen)
{
static_cast<SystemBaseFrameBuffer*>(screen)->PositionWindow(false, true);
screen->Update();
vid_fullscreen = true; // vid_fullscreen is forced to false by PositionWindow
}
mainwindow.RestoreConView(true);
}

// Here is how the error logging system works.
//
// To catch exceptions that occur in secondary threads, CatchAllExceptions is
Expand Down
59 changes: 49 additions & 10 deletions src/common/platform/win32/i_mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,22 @@ int MainWindow::GetGameTitleWindowHeight()
// Sets the main WndProc, hides all the child windows, and starts up in-game input.
void MainWindow::ShowGameView()
{
if (GetWindowLongPtr(Window, GWLP_USERDATA) == 0)
if (GetWindowLongPtr(Window, GWLP_USERDATA) != 1)
{
SetWindowLongPtr(Window, GWLP_USERDATA, 1);
SetWindowLongPtr(Window, GWLP_WNDPROC, (LONG_PTR)WndProc);
ShowWindow(ConWindow, SW_HIDE);
ShowWindow(ProgressBar, SW_HIDE);
ConWindowHidden = true;
ShowWindow(GameTitleWindow, SW_HIDE);
I_InitInput(Window);

if (GetWindowLongPtr(Window, GWLP_USERDATA) != 2) I_InitInput(Window);

SetWindowLongPtr(Window, GWLP_USERDATA, 1);
}
}

// Returns the main window to its startup state.
void MainWindow::RestoreConView()
void MainWindow::RestoreConView(bool netgame_restart)
{
HDC screenDC = GetDC(0);
int dpi = GetDeviceCaps(screenDC, LOGPIXELSX);
Expand All @@ -118,25 +120,62 @@ void MainWindow::RestoreConView()

// Make sure the window has a frame in case it was fullscreened.
SetWindowLongPtr(Window, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW);
if (GetWindowLong(Window, GWL_EXSTYLE) & WS_EX_TOPMOST)
{
SetWindowPos(Window, HWND_BOTTOM, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE);
SetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
if(netgame_restart)
{
DEVMODE displaysettings;
// Many Windows structures that specify their size do so with the first
// element. DEVMODE is not one of those structures.
memset (&displaysettings, 0, sizeof(displaysettings));
displaysettings.dmSize = sizeof(displaysettings);
EnumDisplaySettings (NULL, ENUM_CURRENT_SETTINGS, &displaysettings);
int x = (displaysettings.dmPelsWidth - width) / 2;
int y = (displaysettings.dmPelsHeight - height) / 2;

// Make sure the window has a frame in case it was fullscreened.
SetWindowLongPtr(Window, GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW);
if (GetWindowLong(Window, GWL_EXSTYLE) & WS_EX_TOPMOST)
{
SetWindowPos(Window, HWND_BOTTOM, x, y, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS);
SetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
}
else
{
SetWindowPos(Window, NULL, x, y, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOZORDER);
}
}
else
{
SetWindowPos(Window, NULL, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
if (GetWindowLong(Window, GWL_EXSTYLE) & WS_EX_TOPMOST)
{
SetWindowPos(Window, HWND_BOTTOM, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE);
SetWindowPos(Window, HWND_TOP, 0, 0, 0, 0, SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOSIZE);
}
else
{
SetWindowPos(Window, NULL, 0, 0, width, height, SWP_DRAWFRAME | SWP_NOCOPYBITS | SWP_NOMOVE | SWP_NOZORDER);
}
}

SetWindowLongPtr(Window, GWLP_WNDPROC, (LONG_PTR)LConProc);
ShowWindow(ConWindow, SW_SHOW);
ConWindowHidden = false;
ShowWindow(GameTitleWindow, SW_SHOW);
I_ShutdownInput(); // Make sure the mouse pointer is available.

if(netgame_restart)
{ // Make sure the input system isn't reset
I_CheckNativeMouse(true, false);
}
else
{ // Make sure the mouse pointer is available.
I_ShutdownInput();
}
// Make sure the progress bar isn't visible.
DeleteStartupScreen();

FlushBufferedConsoleStuff();

// Make sure the input system isn't reset
SetWindowLongPtr(Window, GWLP_USERDATA, 2);
}

// Shows an error message, preferably in the main window, but it can use a normal message box too.
Expand Down
2 changes: 1 addition & 1 deletion src/common/platform/win32/i_mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class MainWindow
void Create(const FString& title, int x, int y, int width, int height);

void ShowGameView();
void RestoreConView();
void RestoreConView(bool netgame_restart = false);

void ShowErrorPane(const char* text);
void CheckForRestart();
Expand Down
2 changes: 1 addition & 1 deletion src/common/rendering/vulkan/shaders/vk_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ FString VkShaderManager::LoadPrivateShaderLump(const char *lumpname)

VkPPShader* VkShaderManager::GetVkShader(PPShader* shader)
{
if (!shader->Backend)
if (!shader->Backend || !static_cast<VkPPShader*>(shader->Backend.get())->VertexShader)
shader->Backend = std::make_unique<VkPPShader>(fb, shader);
return static_cast<VkPPShader*>(shader->Backend.get());
}
Expand Down
2 changes: 1 addition & 1 deletion src/common/rendering/vulkan/textures/vk_texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ VkFormat VkTextureManager::GetTextureFormat(PPTexture* texture)

VkPPTexture* VkTextureManager::GetVkTexture(PPTexture* texture)
{
if (!texture->Backend)
if (!texture->Backend || !static_cast<VkPPTexture*>(texture->Backend.get())->TexImage.View)
texture->Backend = std::make_unique<VkPPTexture>(fb, texture);
return static_cast<VkPPTexture*>(texture->Backend.get());
}
Expand Down
Loading

0 comments on commit 3d7e8bf

Please sign in to comment.