-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1269 from colincornaby/backing-scale-changes
Introducing backing scale
- Loading branch information
Showing
27 changed files
with
900 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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" | ||
|
@@ -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); | ||
|
||
|
@@ -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 ) | ||
{ | ||
|
@@ -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; | ||
} | ||
|
@@ -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 | ||
|
@@ -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; | ||
|
@@ -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) | ||
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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; | ||
|
@@ -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) | ||
{ | ||
|
@@ -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; | ||
|
||
|
@@ -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; | ||
|
@@ -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); | ||
|
@@ -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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.