Skip to content

Commit

Permalink
Merge pull request #1269 from colincornaby/backing-scale-changes
Browse files Browse the repository at this point in the history
Introducing backing scale
  • Loading branch information
dpogue authored Jun 26, 2023
2 parents fd591cb + 8c02a4b commit 45f3fa2
Show file tree
Hide file tree
Showing 27 changed files with 900 additions and 274 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ find_package(CURL REQUIRED)
find_package(DirectX)
find_package(epoxy)
find_package(expat REQUIRED)
find_package(freetype)
find_package(freetype REQUIRED)
find_package(JPEG REQUIRED)
find_package(libwebm)
find_package(Ogg REQUIRED)
Expand Down
70 changes: 60 additions & 10 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ You can contact Cyan Worlds, Inc. by email [email protected]

#include "plClient.h"

#ifdef HS_BUILD_FOR_WIN32
# include "plWinDpi/plWinDpi.h"
#endif

#include "pnDispatch/plDispatch.h"
#include "pnDispatch/plDispatchLogBase.h"
#include "pnKeyedObject/plFixedKey.h"
Expand Down Expand Up @@ -92,6 +96,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plInputCore/plInputManager.h"
#include "plMessage/plAgeLoadedMsg.h"
#include "plMessage/plAnimCmdMsg.h"
#include "plMessage/plDisplayScaleChangedMsg.h"
#include "plMessage/plInputEventMsg.h"
#include "plMessage/plLinkToAgeMsg.h"
#include "plMessage/plMovieMsg.h"
Expand Down Expand Up @@ -382,6 +387,7 @@ void plClient::InitInputs()
plgDispatch::Dispatch()->RegisterForExactType(plIMouseYEventMsg::Index(), fInputManager->GetKey());
plgDispatch::Dispatch()->RegisterForExactType(plIMouseBEventMsg::Index(), fInputManager->GetKey());
plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), fInputManager->GetKey());
plgDispatch::Dispatch()->RegisterForExactType(plDisplayScaleChangedMsg::Index(), fInputManager->GetKey());
plInputDevice* pKeyboard = new plKeyboardDevice();
fInputManager->AddInputDevice(pKeyboard);

Expand Down Expand Up @@ -710,6 +716,44 @@ bool plClient::MsgReceive(plMessage* msg)
}
return true;
}

plDisplayScaleChangedMsg* pDSChangedMsg = plDisplayScaleChangedMsg::ConvertNoRef(msg);
if (pDSChangedMsg) {
fPipeline->SetBackingScale(pDSChangedMsg->GetScale());
if (pDSChangedMsg->GetSuggestedLocation().has_value()) {
int width = pDSChangedMsg->GetSuggestedLocation()->fRight - pDSChangedMsg->GetSuggestedLocation()->fLeft;
int height = pDSChangedMsg->GetSuggestedLocation()->fBottom - pDSChangedMsg->GetSuggestedLocation()->fTop;
IResizeWindow(width, height);
if (fPipeline) {
// NOTE: Trying to resize the pipeline while it spans multiple
// monitors seems to crash on D3D9.
fPipeline->ResetDisplayDevice(
width,
height,
fPipeline->ColorDepth(),
!fPipeline->IsFullScreen(),
// FIXME... There doesn't seem to be a way to get the current AA value?
fPipeline->GetMaxAntiAlias(width, height, fPipeline->ColorDepth()),
fPipeline->GetMaxAnisotropicSamples(),
// FIXME... There doesn't seem to be a way to get the current VSync value?
true
);
}
#ifdef HS_BUILD_FOR_WIN32
SetWindowPos(
fWindowHndl,
nullptr,
pDSChangedMsg->GetSuggestedLocation()->fLeft,
pDSChangedMsg->GetSuggestedLocation()->fTop,
width,
height,
SWP_NOZORDER | SWP_NOACTIVATE
);
#endif
}
return true;
}

plRenderRequestMsg* rendReq = plRenderRequestMsg::ConvertNoRef(msg);
if( rendReq )
{
Expand Down Expand Up @@ -1414,6 +1458,8 @@ bool plClient::StartInit()
plgDispatch::Dispatch()->RegisterForExactType(plEvalMsg::Index(), pLMod->GetKey());
plgDispatch::Dispatch()->RegisterForExactType(plAudioSysMsg::Index(), pLMod->GetKey());

plgDispatch::Dispatch()->RegisterForExactType(plDisplayScaleChangedMsg::Index(), GetKey());

plSynchedObject::PushSynchDisabled(false); // enable dirty tracking
return true;
}
Expand All @@ -1422,7 +1468,7 @@ bool plClient::StartInit()
bool plClient::BeginGame()
{
plNetClientMgr::GetInstance()->Init();
IPlayIntroMovie("avi/CyanWorlds.webm", 0.f, 0.f, 0.f, 1.f, 1.f, 0.75);
IPlayIntroMovie("avi/CyanWorlds.webm", 0.f, 0.f, 0.f, fPipeline->fBackingScale, fPipeline->fBackingScale, 0.75);
if (GetDone()) return false;
if (NetCommGetStartupAge()->ageDatasetName.compare_i("StartUp") == 0) {
// This is needed because there is no auth step in this case
Expand Down Expand Up @@ -1870,6 +1916,16 @@ void plClient::IAddRenderRequest(plRenderRequest* req)
}
}

void plClient::IResizeWindow(int Width, int Height)
{
if (plMouseDevice::Instance())
plMouseDevice::Instance()->SetDisplayResolution((float)Width, (float)Height);

float aspectratio = (float)Width / (float)Height;
if (pfGameGUIMgr::GetInstance())
pfGameGUIMgr::GetInstance()->SetAspectRatio(aspectratio);
}

void plClient::ResetDisplayDevice(int Width, int Height, int ColorDepth, bool Windowed, int NumAASamples, int MaxAnisotropicSamples, bool VSync)
{
if(!fPipeline) return;
Expand All @@ -1885,13 +1941,7 @@ void plClient::ResetDisplayDevice(int Width, int Height, int ColorDepth, bool Wi

void plClient::ResizeDisplayDevice(int Width, int Height, bool Windowed)
{

if (plMouseDevice::Instance())
plMouseDevice::Instance()->SetDisplayResolution((float)Width, (float)Height);

float aspectratio = (float)Width / (float)Height;
if (pfGameGUIMgr::GetInstance())
pfGameGUIMgr::GetInstance()->SetAspectRatio( aspectratio );
IResizeWindow(Width, Height);

// Direct3D no longer uses exclusive fullscreen mode, ergo, we must resize the display
if (!Windowed)
Expand Down Expand Up @@ -1949,8 +1999,8 @@ void plClient::IDetectAudioVideoSettings()
#ifdef HS_BUILD_FOR_WIN32
if(!plPipeline::fDefaultPipeParams.Windowed)
{
plPipeline::fDefaultPipeParams.Width = GetSystemMetrics(SM_CXSCREEN);
plPipeline::fDefaultPipeParams.Height = GetSystemMetrics(SM_CYSCREEN);
plPipeline::fDefaultPipeParams.Width = plWinDpi::Instance().GetSystemMetrics(SM_CXSCREEN, fWindowHndl);
plPipeline::fDefaultPipeParams.Height = plWinDpi::Instance().GetSystemMetrics(SM_CYSCREEN, fWindowHndl);
}
else
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/Plasma/Apps/plClient/plClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class plClient : public hsKeyedObject
void IChangeResolution(int width, int height);
void IUpdateProgressIndicator(plOperationProgress* progress);

void IResizeWindow(int width, int height);

public:

plClient();
Expand Down
25 changes: 16 additions & 9 deletions Sources/Plasma/Apps/plClient/win32/plClient_Win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include <shellapi.h>

#include "plClient.h"
#include "plWinDpi/plWinDpi.h"

#include "pnFactory/plFactory.h"
#include "pnNetCommon/plNetApp.h"
Expand All @@ -72,17 +73,23 @@ void plClient::IResizeNativeDisplayDevice(int width, int height, bool windowed)
SetWindowLongPtr(fWindowHndl, GWL_EXSTYLE, winExStyle);

uint32_t flags = SWP_NOCOPYBITS | SWP_SHOWWINDOW | SWP_FRAMECHANGED;
uint32_t outsideWidth, outsideHeight;

// The window rect will be (left, top, width, height)
RECT winRect{ 0, 0, width, height };
if (windowed) {
RECT winRect = { 0, 0, width, height };
AdjustWindowRectEx(&winRect, winStyle, false, winExStyle);
outsideWidth = winRect.right - winRect.left;
outsideHeight = winRect.bottom - winRect.top;
} else {
outsideWidth = width;
outsideHeight = height;
if (GetClientRect(fWindowHndl, &winRect) != FALSE) {
MapWindowPoints(fWindowHndl, nullptr, reinterpret_cast<LPPOINT>(&winRect), 2);
winRect.right = winRect.left + width;
winRect.bottom = winRect.top + height;
}

UINT dpi = plWinDpi::Instance().GetDpi(fWindowHndl);
plWinDpi::Instance().AdjustWindowRectEx(&winRect, winStyle, false, winExStyle, dpi);

winRect.right = winRect.right - winRect.left;
winRect.bottom = winRect.bottom - winRect.top;
}
SetWindowPos(fWindowHndl, HWND_NOTOPMOST, 0, 0, outsideWidth, outsideHeight, flags);
SetWindowPos(fWindowHndl, HWND_NOTOPMOST, winRect.left, winRect.top, winRect.right, winRect.bottom, flags);
}

void plClient::IChangeResolution(int width, int height)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plClient/win32/res/plClient.rc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "Login",IDOK,87,225,50,14
PUSHBUTTON "Quit",IDCANCEL,163,225,50,14
CONTROL 151,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZEIMAGE | WS_BORDER,7,7,289,36
CONTROL 151,IDC_STATIC,"Static",SS_BITMAP | SS_REALSIZECONTROL | WS_BORDER,7,7,289,36
LTEXT "Account name:",IDC_STATIC,69,119,49,10
LTEXT "Password:",IDC_STATIC,69,135,49,10
EDITTEXT IDC_URULOGIN_USERNAME,123,119,108,12,ES_AUTOHSCROLL
Expand Down
38 changes: 30 additions & 8 deletions Sources/Plasma/Apps/plClient/win32/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,14 @@ You can contact Cyan Worlds, Inc. by email [email protected]
#include "plInputCore/plInputManager.h"
#include "plNetClient/plNetClientMgr.h"
#include "plNetGameLib/plNetGameLib.h"
#include "plMessage/plDisplayScaleChangedMsg.h"
#include "plPhysX/plPXSimulation.h"
#include "plPipeline/hsG3DDeviceSelector.h"
#include "plResMgr/plLocalization.h"
#include "plResMgr/plResManager.h"
#include "plResMgr/plVersion.h"
#include "plStatusLog/plStatusLog.h"
#include "plWinDpi/plWinDpi.h"

#include "pfConsoleCore/pfConsoleEngine.h"
#include "pfCrashHandler/plCrashCli.h"
Expand Down Expand Up @@ -122,12 +124,6 @@ static const plCmdArgDef s_cmdLineArgs[] = {
{ kCmdArgFlagged | kCmdTypeString, "Renderer", kArgRenderer },
};

/// Made globals now, so we can set them to zero if we take the border and
/// caption styles out ala fullscreen (8.11.2000 mcn)
int gWinBorderDX = GetSystemMetrics( SM_CXSIZEFRAME );
int gWinBorderDY = GetSystemMetrics( SM_CYSIZEFRAME );
int gWinMenuDY = GetSystemMetrics( SM_CYCAPTION );

plClientLoader gClient;
bool gPendingActivate = false;
bool gPendingActivateFlag = false;
Expand Down Expand Up @@ -177,12 +173,24 @@ static void AuthFailedStrings (ENetError authError,

void DebugMsgF(const char* format, ...);

static void HandleDpiChange(HWND hWnd, UINT dpi, float scale, const RECT& rect)
{
// Inform the engine about the new DPI.
auto* msg = new plDisplayScaleChangedMsg(scale, plDisplayScaleChangedMsg::ConvertRect(rect));
msg->Send();
}

// Handles all the windows messages we might receive
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static bool gDragging = false;
static uint8_t mouse_down = 0;

// DPI Helper can eat messages.
auto result = plWinDpi::Instance().WndProc(hWnd, message, wParam, lParam, HandleDpiChange);
if (result.has_value())
return result.value();

// Messages we registered for manually (no const value)
if (message == s_WmTaskbarList)
{
Expand Down Expand Up @@ -347,6 +355,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
RECT r;
::GetClientRect(hWnd, &r);
gClient->GetPipeline()->Resize(r.right - r.left, r.bottom - r.top);
gClient->GetPipeline()->SetBackingScale(plWinDpi::Instance().GetScale(hWnd));
}
break;

Expand Down Expand Up @@ -1019,6 +1028,9 @@ 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;
Expand All @@ -1037,13 +1049,17 @@ bool WinInit(HINSTANCE hInst)
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 + gWinBorderDX * 2,
600 + gWinBorderDY * 2 + gWinMenuDY,
800 + winBorderDX * 2,
600 + winBorderDY * 2 + winMenuDY,
nullptr, nullptr, hInst, nullptr
);
HDC hDC = GetDC(hWnd);
Expand Down Expand Up @@ -1268,6 +1284,12 @@ int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nC
::DestroyWindow(splashDialog);
}

// Tell everybody about the current display scaling
{
plDisplayScaleChangedMsg* msg = new plDisplayScaleChangedMsg(plWinDpi::Instance().GetScale());
msg->Send();
}

// Main loop
if (gClient && !gClient->GetDone()) {
// Must be done here due to the plClient* dereference.
Expand Down
1 change: 1 addition & 0 deletions Sources/Plasma/Apps/plUruLauncher/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ target_link_libraries(
pnNetBase
plNetGameLib
plStatusLog
plWinDpi
pfConsoleCore
pfPatcher
CURL::libcurl
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/Apps/plUruLauncher/plUruLauncher.rc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS |
EXSTYLE WS_EX_APPWINDOW
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL 109,IDB_BITMAP,"Static",SS_BITMAP | SS_SUNKEN,7,7,288,36
CONTROL 109,IDB_BITMAP,"Static",SS_BITMAP | SS_SUNKEN | SS_REALSIZECONTROL,7,7,288,36
CONTROL "",IDC_PROGRESS,"msctls_progress32",WS_BORDER | 0x1,7,
111,234,11
CONTROL "", IDC_MARQUEE, "msctls_progress32", WS_BORDER | 0x8, 7,
Expand Down
10 changes: 10 additions & 0 deletions Sources/Plasma/Apps/plUruLauncher/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Mead, WA 99021
#include "pfPatcher/plManifests.h"
#include "pfPatcher/pfPatcher.h"

#include "plWinDpi/plWinDpi.h"

#include "plClientLauncher.h"

#include "hsWindows.h"
Expand All @@ -55,6 +57,7 @@ Mead, WA 99021
#include <commctrl.h>
#include <shellapi.h>
#include <shlobj.h>
#include <ShellScalingApi.h>

// ===================================================

Expand Down Expand Up @@ -124,6 +127,11 @@ static inline void IShowMarquee(bool marquee=true)

INT_PTR CALLBACK PatcherDialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
// DPI Helper can eat messages.
auto result = plWinDpi::Instance().WndProc(hwndDlg, uMsg, wParam, lParam, nullptr);
if (result.has_value())
return result.value();

// NT6 Taskbar Majick
if (uMsg == s_taskbarCreated) {
hsRequireCOM();
Expand Down Expand Up @@ -380,6 +388,8 @@ static pfPatcher* IPatcherFactory()

int __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLink, int nCmdShow)
{
plWinDpi::Instance();

plClientLauncher launcher;
s_launcher = &launcher;

Expand Down
Loading

0 comments on commit 45f3fa2

Please sign in to comment.