diff options
Diffstat (limited to 'src/skel/glfw/glfw.cpp')
-rw-r--r-- | src/skel/glfw/glfw.cpp | 278 |
1 files changed, 155 insertions, 123 deletions
diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index db6be3a2..63ebccee 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -49,7 +49,13 @@ static RwInt32 GcurSel = 0, GcurSelVM = 0; static RwBool useDefault; +// What is that for anyway? +#ifndef IMPROVED_VIDEOMODE static RwBool defaultFullscreenRes = TRUE; +#else +static RwBool defaultFullscreenRes = FALSE; +static RwInt32 bestWndMode = -1; +#endif static psGlobalType PsGlobal; @@ -248,83 +254,6 @@ psNativeTextureSupport(void) /* ***************************************************************************** */ -static char cpuvendor[16] = "UnknownVendr"; -__declspec(naked) const char * _psGetCpuVendr() -{ - __asm - { - push ebx - xor eax, eax - cpuid - mov dword ptr [cpuvendor+0], ebx - mov dword ptr [cpuvendor+4], edx - mov dword ptr [cpuvendor+8], ecx - mov eax, offset cpuvendor - pop ebx - retn - } -} - -/* - ***************************************************************************** - */ -__declspec(naked) RwUInt32 _psGetCpuFeatures() -{ - __asm - { - mov eax, 1 - cpuid - mov eax, edx - retn - } -} - -/* - ***************************************************************************** - */ -__declspec(naked) RwUInt32 _psGetCpuFeaturesEx() -{ - __asm - { - mov eax, 80000000h - cpuid - - cmp eax, 80000000h - jbe short _NOEX - - mov eax, 80000001h - cpuid - - mov eax, edx - jmp short _RETEX - -_NOEX: - xor eax, eax - mov eax, eax - -_RETEX: - retn - } -} - -void _psPrintCpuInfo() -{ - RwUInt32 features = _psGetCpuFeatures(); - RwUInt32 FeaturesEx = _psGetCpuFeaturesEx(); - - debug("Running on a %s", _psGetCpuVendr()); - - if ( features & 0x800000 ) - debug("with MMX"); - if ( features & 0x2000000 ) - debug("with SSE"); - if ( FeaturesEx & 0x80000000 ) - debug("with 3DNow"); -} - -/* - ***************************************************************************** - */ #ifdef UNDER_CE #define CMDSTR LPWSTR #else @@ -357,8 +286,6 @@ psInitialise(void) gGameState = GS_START_UP; TRACE("gGameState = GS_START_UP"); - _psPrintCpuInfo(); - OSVERSIONINFO verInfo; verInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); @@ -515,7 +442,7 @@ void _psSelectScreenVM(RwInt32 videoMode) FrontEndMenuManager.UnloadTextures(); - if ( !_psSetVideoMode(RwEngineGetCurrentSubSystem(), videoMode) ) + if (!_psSetVideoMode(RwEngineGetCurrentSubSystem(), videoMode)) { RsGlobal.quit = TRUE; } @@ -608,6 +535,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 */ @@ -615,8 +546,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 ) @@ -660,9 +595,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 bestFsMode = -1; + RwInt32 bestWidth = -1; + RwInt32 bestHeight = -1; + RwInt32 bestDepth = -1; + for(GcurSelVM = 0; GcurSelVM < RwEngineGetNumVideoModes(); GcurSelVM++){ + RwEngineGetVideoModeInfo(&vm, GcurSelVM); + + if (!(vm.flags & rwVIDEOMODEEXCLUSIVE)){ + bestWndMode = 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; + bestFsMode = GcurSelVM; + } + } + } + + if(bestFsMode < 0){ + MessageBox(nil, "Cannot find desired video mode", "GTA3", MB_OK); + return FALSE; + } + GcurSelVM = bestFsMode; + + FrontEndMenuManager.m_nDisplayVideoMode = GcurSelVM; + FrontEndMenuManager.m_nPrefsVideoMode = FrontEndMenuManager.m_nDisplayVideoMode; + + FrontEndMenuManager.m_nSelectedScreenMode = FrontEndMenuManager.m_nPrefsWindowed; + } +#endif + RwEngineGetVideoModeInfo(&vm, GcurSelVM); - + +#ifdef IMPROVED_VIDEOMODE + if (FrontEndMenuManager.m_nPrefsWindowed) + GcurSelVM = bestWndMode; + + // Now GcurSelVM is 0 but vm has sizes(and fullscreen flag) of the video mode we want, that's why we changed the rwVIDEOMODEEXCLUSIVE conditions below + FrontEndMenuManager.m_nPrefsWidth = vm.width; + FrontEndMenuManager.m_nPrefsHeight = vm.height; + FrontEndMenuManager.m_nPrefsDepth = vm.depth; +#endif + FrontEndMenuManager.m_nCurrOption = 0; /* Set up the video mode and set the apps window @@ -686,6 +679,7 @@ psSelectDevice() } } */ +#ifndef IMPROVED_VIDEOMODE if (vm.flags & rwVIDEOMODEEXCLUSIVE) { RsGlobal.maximumWidth = vm.width; @@ -695,10 +689,71 @@ psSelectDevice() PSGLOBAL(fullScreen) = TRUE; } +#else + RsGlobal.maximumWidth = FrontEndMenuManager.m_nPrefsWidth; + RsGlobal.maximumHeight = FrontEndMenuManager.m_nPrefsHeight; + RsGlobal.width = FrontEndMenuManager.m_nPrefsWidth; + RsGlobal.height = FrontEndMenuManager.m_nPrefsHeight; + + PSGLOBAL(fullScreen) = !FrontEndMenuManager.m_nPrefsWindowed; +#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); +} + /* ***************************************************************************** */ @@ -713,9 +768,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; @@ -728,6 +783,8 @@ RwBool _psSetVideoMode(RwInt32 subSystem, RwInt32 videoMode) RsEventHandler(rsCAMERASIZE, &r); + psPostRWinit(); + return TRUE; } @@ -967,14 +1024,18 @@ void resizeCB(GLFWwindow* window, int width, int height) { if (RwInitialised && height > 0 && width > 0) { RwRect r; + // TODO fix artifacts of resizing with mouse + RsGlobal.maximumHeight = height; + RsGlobal.maximumWidth = width; + r.x = 0; r.y = 0; - r.w = RsGlobal.maximumWidth; - r.h = RsGlobal.maximumHeight; + r.w = width; + r.h = height; RsEventHandler(rsCAMERASIZE, &r); } - glfwSetWindowPos(window, 0, 0); +// glfwSetWindowPos(window, 0, 0); } void scrollCB(GLFWwindow* window, double xoffset, double yoffset) { @@ -1146,31 +1207,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); -} - /* ***************************************************************************** */ @@ -1224,6 +1260,7 @@ WinMain(HINSTANCE instance, openParams.width = RsGlobal.maximumWidth; openParams.height = RsGlobal.maximumHeight; openParams.windowtitle = RsGlobal.appName; + openParams.window = &PSGLOBAL(window); ControlsManager.MakeControllerActionsBlank(); ControlsManager.InitDefaultControlConfiguration(); @@ -1231,18 +1268,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 @@ -1310,11 +1347,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 ) { |