diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/Frontend.cpp | 25 | ||||
-rw-r--r-- | src/core/Frontend.h | 10 | ||||
-rw-r--r-- | src/core/config.h | 1 | ||||
-rw-r--r-- | src/fakerw/fake.cpp | 5 | ||||
-rw-r--r-- | src/skel/glfw/glfw.cpp | 186 | ||||
-rw-r--r-- | src/skel/win/win.cpp | 113 |
6 files changed, 292 insertions, 48 deletions
diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 64332cb4..97cb21fd 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -3045,7 +3045,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); @@ -3127,7 +3144,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 a1769c70..0d57f55d 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/fakerw/fake.cpp b/src/fakerw/fake.cpp index ccc7635f..113c4519 100644 --- a/src/fakerw/fake.cpp +++ b/src/fakerw/fake.cpp @@ -490,12 +490,11 @@ RwBool RwRenderStateSet(RwRenderState state, void *value) RwBool RwEngineInit(RwMemoryFunctions *memFuncs, RwUInt32 initFlags, RwUInt32 resArenaSize) { Engine::init(); return true; } // TODO: this is platform dependent RwBool RwEngineOpen(RwEngineOpenParams *initParams) { -#if defined RW_D3D9 || defined RWLIBS static EngineOpenParams openParams; +#ifdef RW_D3D9 openParams.window = (HWND)initParams->displayID; #else - extern EngineOpenParams openParams; - openParams.window = (GLFWwindow**)initParams->displayID; + openParams = *(EngineOpenParams*)initParams->displayID; #endif return Engine::open(&openParams); } diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index 6359d22f..2813c823 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -421,7 +421,11 @@ RwChar **_psGetVideoModeList() _VMList[i] = nil; } else +#ifdef IMPROVED_VIDEOMODE + _VMList[i] = strdup("WINDOW"); +#else _VMList[i] = nil; +#endif } return _VMList; @@ -529,6 +533,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 */ @@ -536,8 +544,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 ) @@ -581,9 +593,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 @@ -616,10 +686,73 @@ psSelectDevice() PSGLOBAL(fullScreen) = TRUE; } +#ifdef IMPROVED_VIDEOMODE + else{ + RsGlobal.maximumWidth = FrontEndMenuManager.m_nPrefsWidth; + RsGlobal.maximumHeight = FrontEndMenuManager.m_nPrefsHeight; + RsGlobal.width = FrontEndMenuManager.m_nPrefsWidth; + RsGlobal.height = FrontEndMenuManager.m_nPrefsHeight; + + PSGLOBAL(fullScreen) = FALSE; + } +#endif return TRUE; } +void keypressCB(GLFWwindow* window, int key, int scancode, int action, int mods); +void resizeCB(GLFWwindow* window, int width, int height); +void scrollCB(GLFWwindow* window, double xoffset, double yoffset); +void cursorCB(GLFWwindow* window, double xpos, double ypos); +void joysChangeCB(int jid, int event); + +void _InputInitialiseJoys() +{ + for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) { + if (glfwJoystickPresent(i)) { + if (PSGLOBAL(joy1id) == -1) + PSGLOBAL(joy1id) = i; + else if (PSGLOBAL(joy2id) == -1) + PSGLOBAL(joy2id) = i; + else + break; + } + } + + if (PSGLOBAL(joy1id) != -1) { + int count; + glfwGetJoystickButtons(PSGLOBAL(joy1id), &count); + ControlsManager.InitDefaultControlConfigJoyPad(count); + } +} + +void _InputInitialiseMouse() +{ + glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); +} + +void psPostRWinit(void) +{ + RwVideoMode vm; + RwEngineGetVideoModeInfo(&vm, GcurSelVM); + + glfwSetKeyCallback(PSGLOBAL(window), keypressCB); + glfwSetWindowSizeCallback(PSGLOBAL(window), resizeCB); + glfwSetScrollCallback(PSGLOBAL(window), scrollCB); + glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); + glfwSetJoystickCallback(joysChangeCB); + + _InputInitialiseJoys(); + _InputInitialiseMouse(); + + if(!(vm.flags & rwVIDEOMODEEXCLUSIVE)) + glfwSetWindowSize(PSGLOBAL(window), RsGlobal.maximumWidth, RsGlobal.maximumHeight); + + // Make sure all keys are released + CPad::GetPad(0)->Clear(true); + CPad::GetPad(1)->Clear(true); +} + /* ***************************************************************************** */ @@ -634,9 +767,9 @@ RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode) useDefault = TRUE; - if ( RsEventHandler(rsRWINITIALISE, &PSGLOBAL(window)) == rsEVENTERROR ) + if ( RsEventHandler(rsRWINITIALISE, &openParams) == rsEVENTERROR ) return FALSE; - + RwInitialised = TRUE; useDefault = FALSE; @@ -649,6 +782,8 @@ RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode) RsEventHandler(rsCAMERASIZE, &r); + psPostRWinit(); + return TRUE; } @@ -895,7 +1030,7 @@ void resizeCB(GLFWwindow* window, int width, int height) { RsEventHandler(rsCAMERASIZE, &r); } - glfwSetWindowPos(window, 0, 0); +// glfwSetWindowPos(window, 0, 0); } void scrollCB(GLFWwindow* window, double xoffset, double yoffset) { @@ -1067,31 +1202,6 @@ cursorCB(GLFWwindow* window, double xpos, double ypos) { FrontEndMenuManager.m_nMouseTempPosY = ypos; } -void _InputInitialiseJoys() -{ - for (int i = 0; i <= GLFW_JOYSTICK_LAST; i++) { - if (glfwJoystickPresent(i)) { - if (PSGLOBAL(joy1id) == -1) - PSGLOBAL(joy1id) = i; - else if (PSGLOBAL(joy2id) == -1) - PSGLOBAL(joy2id) = i; - else - break; - } - } - - if (PSGLOBAL(joy1id) != -1) { - int count; - glfwGetJoystickButtons(PSGLOBAL(joy1id), &count); - ControlsManager.InitDefaultControlConfigJoyPad(count); - } -} - -void _InputInitialiseMouse() -{ - glfwSetInputMode(PSGLOBAL(window), GLFW_CURSOR, GLFW_CURSOR_HIDDEN); -} - /* ***************************************************************************** */ @@ -1145,6 +1255,7 @@ WinMain(HINSTANCE instance, openParams.width = RsGlobal.maximumWidth; openParams.height = RsGlobal.maximumHeight; openParams.windowtitle = RsGlobal.appName; + openParams.window = &PSGLOBAL(window); ControlsManager.MakeControllerActionsBlank(); ControlsManager.InitDefaultControlConfiguration(); @@ -1152,18 +1263,18 @@ WinMain(HINSTANCE instance, /* * Initialize the 3D (RenderWare) components of the app... */ - if( rsEVENTERROR == RsEventHandler(rsRWINITIALISE, &PSGLOBAL(window)) ) + if( rsEVENTERROR == RsEventHandler(rsRWINITIALISE, &openParams) ) { RsEventHandler(rsTERMINATE, nil); return 0; } - _InputInitialiseJoys(); - _InputInitialiseMouse(); + psPostRWinit(); + ControlsManager.InitDefaultControlConfigMouse(MousePointerStateHelper.GetMouseSetUp()); - glfwSetWindowPos(PSGLOBAL(window), 0, 0); +// glfwSetWindowPos(PSGLOBAL(window), 0, 0); /* * Parse command line parameters (except program name) one at @@ -1231,11 +1342,6 @@ WinMain(HINSTANCE instance, #endif initkeymap(); - glfwSetKeyCallback(PSGLOBAL(window), keypressCB); - glfwSetWindowSizeCallback(PSGLOBAL(window), resizeCB); - glfwSetScrollCallback(PSGLOBAL(window), scrollCB); - glfwSetCursorPosCallback(PSGLOBAL(window), cursorCB); - glfwSetJoystickCallback(joysChangeCB); while ( TRUE ) { 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... |