From 804b022e671f11f2cf680862f2822444d6b66a5c Mon Sep 17 00:00:00 2001 From: aap Date: Wed, 29 Apr 2020 18:08:54 +0200 Subject: implemented improved video modes for win.cpp --- src/core/Frontend.cpp | 25 +++++++++++ src/core/Frontend.h | 10 +++++ src/core/config.h | 1 + src/skel/win/win.cpp | 113 +++++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 144 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index a83bffce..e9ca1755 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -3038,7 +3038,24 @@ CMenuManager::LoadSettings() if (strncmp(Ver, TopLineEmptyFile, sizeof(TopLineEmptyFile) - 1)) { CFileMgr::Seek(fileHandle, 0, 0); ControlsManager.LoadSettings(fileHandle); +#ifdef IMPROVED_VIDEOMODE + CFileMgr::Read(fileHandle, (char*)&m_nPrefsWidth, sizeof(m_nPrefsWidth)); + CFileMgr::Read(fileHandle, (char*)&m_nPrefsHeight, sizeof(m_nPrefsHeight)); + CFileMgr::Read(fileHandle, (char*)&m_nPrefsDepth, sizeof(m_nPrefsDepth)); + CFileMgr::Read(fileHandle, (char*)&m_nPrefsWindowed, sizeof(m_nPrefsWindowed)); + CFileMgr::Read(fileHandle, (char*)&m_nPrefsSubsystem, sizeof(m_nPrefsSubsystem)); + if(m_nPrefsWindowed != 0 && m_nPrefsWindowed != 1){ + // garbage data from vanilla settings file + // let skeleton find something + m_nPrefsWidth = 0; + m_nPrefsHeight = 0; + m_nPrefsDepth = 0; + m_nPrefsWindowed = 0; + m_nPrefsSubsystem = 0; + } +#else CFileMgr::Read(fileHandle, gString, 20); +#endif CFileMgr::Read(fileHandle, gString, 20); CFileMgr::Read(fileHandle, gString, 4); CFileMgr::Read(fileHandle, gString, 4); @@ -3120,7 +3137,15 @@ CMenuManager::SaveSettings() int fileHandle = CFileMgr::OpenFile("gta3.set", "w+"); if (fileHandle) { ControlsManager.SaveSettings(fileHandle); +#ifdef IMPROVED_VIDEOMODE + CFileMgr::Write(fileHandle, (char*)&m_nPrefsWidth, sizeof(m_nPrefsWidth)); + CFileMgr::Write(fileHandle, (char*)&m_nPrefsHeight, sizeof(m_nPrefsHeight)); + CFileMgr::Write(fileHandle, (char*)&m_nPrefsDepth, sizeof(m_nPrefsDepth)); + CFileMgr::Write(fileHandle, (char*)&m_nPrefsWindowed, sizeof(m_nPrefsWindowed)); + CFileMgr::Write(fileHandle, (char*)&m_nPrefsSubsystem, sizeof(m_nPrefsSubsystem)); +#else CFileMgr::Write(fileHandle, RubbishString, 20); +#endif CFileMgr::Write(fileHandle, RubbishString, 20); CFileMgr::Write(fileHandle, RubbishString, 4); CFileMgr::Write(fileHandle, RubbishString, 4); diff --git a/src/core/Frontend.h b/src/core/Frontend.h index c1284101..fc2c5235 100644 --- a/src/core/Frontend.h +++ b/src/core/Frontend.h @@ -533,6 +533,14 @@ public: int32 m_nCurrSaveSlot; int32 m_nScreenChangeDelayTimer; +#ifdef IMPROVED_VIDEOMODE + int32 m_nPrefsWidth; + int32 m_nPrefsHeight; + int32 m_nPrefsDepth; + int32 m_nPrefsWindowed; + int32 m_nPrefsSubsystem; +#endif + public: bool GetIsMenuActive() {return !!m_bMenuActive;} @@ -645,7 +653,9 @@ public: // uint8 GetNumberOfMenuOptions(); }; +#ifndef IMPROVED_VIDEOMODE static_assert(sizeof(CMenuManager) == 0x564, "CMenuManager: error"); +#endif extern CMenuManager FrontEndMenuManager; extern unsigned long _dwOperatingSystemVersion; \ No newline at end of file diff --git a/src/core/config.h b/src/core/config.h index 163af701..01684afd 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -192,6 +192,7 @@ enum Config { #define MORE_LANGUAGES // Add more translations to the game #define DEFAULT_NATIVE_RESOLUTION // Set default video mode to your native resolution (fixes Windows 10 launch) #define USE_TXD_CDIMAGE // generate and load textures from txd.img +#define IMPROVED_VIDEOMODE // save and load videomode parameters instead of a magic number //#define USE_TEXTURE_POOL //#define OPENAL diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index 288788c0..531b9d31 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -791,7 +791,11 @@ RwChar **_psGetVideoModeList() _VMList[i] = nil; } else +#ifdef IMPROVED_VIDEOMODE + _VMList[i] = strdup("WINDOW"); +#else _VMList[i] = nil; +#endif } return _VMList; @@ -1310,6 +1314,10 @@ psSelectDevice() /* Get the default selection */ GcurSel = RwEngineGetCurrentSubSystem(); +#ifdef IMPROVED_VIDEOMODE + if(FrontEndMenuManager.m_nPrefsSubsystem < GnumSubSystems) + GcurSel = FrontEndMenuManager.m_nPrefsSubsystem; +#endif } /* Set the driver to use the correct sub system */ @@ -1317,8 +1325,12 @@ psSelectDevice() { return FALSE; } - - + +#ifdef IMPROVED_VIDEOMODE + FrontEndMenuManager.m_nPrefsSubsystem = GcurSel; +#endif + +#ifndef IMPROVED_VIDEOMODE if ( !useDefault ) { if ( _psGetVideoModeList()[FrontEndMenuManager.m_nDisplayVideoMode] && FrontEndMenuManager.m_nDisplayVideoMode ) @@ -1362,9 +1374,67 @@ psSelectDevice() } } } +#else + if ( !useDefault ) + { + if(FrontEndMenuManager.m_nPrefsWidth == 0 || + FrontEndMenuManager.m_nPrefsHeight == 0 || + FrontEndMenuManager.m_nPrefsDepth == 0){ + // Defaults if nothing specified + FrontEndMenuManager.m_nPrefsWidth = GetSystemMetrics(SM_CXSCREEN); + FrontEndMenuManager.m_nPrefsHeight = GetSystemMetrics(SM_CYSCREEN); + FrontEndMenuManager.m_nPrefsDepth = 32; + FrontEndMenuManager.m_nPrefsWindowed = 0; + } + + // Find the videomode that best fits what we got from the settings file + RwInt32 bestMode = -1; + RwInt32 bestWidth = -1; + RwInt32 bestHeight = -1; + RwInt32 bestDepth = -1; + for(GcurSelVM = 0; GcurSelVM < RwEngineGetNumVideoModes(); GcurSelVM++){ + RwEngineGetVideoModeInfo(&vm, GcurSelVM); + if(!(vm.flags & rwVIDEOMODEEXCLUSIVE) != FrontEndMenuManager.m_nPrefsWindowed) + continue; + + if(FrontEndMenuManager.m_nPrefsWindowed){ + bestMode = GcurSelVM; + }else{ + // try the largest one that isn't larger than what we wanted + if(vm.width >= bestWidth && vm.width <= FrontEndMenuManager.m_nPrefsWidth && + vm.height >= bestHeight && vm.height <= FrontEndMenuManager.m_nPrefsHeight && + vm.depth >= bestDepth && vm.depth <= FrontEndMenuManager.m_nPrefsDepth){ + bestWidth = vm.width; + bestHeight = vm.height; + bestDepth = vm.depth; + bestMode = GcurSelVM; + } + } + } + + if(bestMode < 0){ + MessageBox(nil, "Cannot find desired video mode", "GTA3", MB_OK); + return FALSE; + } + GcurSelVM = bestMode; + + FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM; + FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode; + GcurSelVM = FrontEndMenuManager.m_nDisplayVideoMode; + } +#endif RwEngineGetVideoModeInfo(&vm, GcurSelVM); - + +#ifdef IMPROVED_VIDEOMODE + if(vm.flags & rwVIDEOMODEEXCLUSIVE){ + FrontEndMenuManager.m_nPrefsWidth = vm.width; + FrontEndMenuManager.m_nPrefsHeight = vm.height; + FrontEndMenuManager.m_nPrefsDepth = vm.depth; + } + FrontEndMenuManager.m_nPrefsWindowed = !(vm.flags & rwVIDEOMODEEXCLUSIVE); +#endif + FrontEndMenuManager.m_nCurrOption = 0; /* Set up the video mode and set the apps window @@ -1395,8 +1465,39 @@ psSelectDevice() RsGlobal.height = vm.height; PSGLOBAL(fullScreen) = TRUE; + +#ifdef IMPROVED_VIDEOMODE + SetWindowLong(PSGLOBAL(window), GWL_STYLE, WS_POPUP); + SetWindowPos(PSGLOBAL(window), nil, 0, 0, 0, 0, + SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER| + SWP_FRAMECHANGED); + }else{ + RECT rect; + rect.left = rect.top = 0; + rect.right = FrontEndMenuManager.m_nPrefsWidth; + rect.bottom = FrontEndMenuManager.m_nPrefsHeight; + AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); + + // center it + int spaceX = GetSystemMetrics(SM_CXSCREEN) - (rect.right-rect.left); + int spaceY = GetSystemMetrics(SM_CYSCREEN) - (rect.bottom-rect.top); + + SetWindowLong(PSGLOBAL(window), GWL_STYLE, WS_VISIBLE | WS_OVERLAPPEDWINDOW); + SetWindowPos(PSGLOBAL(window), HWND_NOTOPMOST, spaceX/2, spaceY/2, + (rect.right - rect.left), + (rect.bottom - rect.top), 0); + + // Have to get actual size because the window perhaps didn't fit + GetClientRect(PSGLOBAL(window), &rect); + RsGlobal.maximumWidth = rect.right; + RsGlobal.maximumHeight = rect.bottom; + RsGlobal.width = rect.right; + RsGlobal.height = rect.bottom; + + PSGLOBAL(fullScreen) = FALSE; +#endif } - + return TRUE; } @@ -1840,11 +1941,13 @@ WinMain(HINSTANCE instance, } ControlsManager.InitDefaultControlConfigMouse(MousePointerStateHelper.GetMouseSetUp()); - + +#ifndef IMPROVED_VIDEOMODE SetWindowLong(PSGLOBAL(window), GWL_STYLE, WS_POPUP); SetWindowPos(PSGLOBAL(window), nil, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER| SWP_FRAMECHANGED); +#endif /* * Initialize the 3D (RenderWare) components of the app... -- cgit v1.2.3