From 035e6d5caa6513d7dcdec0dbb8b7174a42a1371f Mon Sep 17 00:00:00 2001 From: Sergeant_Kolja Date: Fri, 23 Feb 2007 21:13:20 +0000 Subject: [PATCH] Added new, optional JA2.INI parameter to select windowed mode instead of Fullscreen ([Ja2 Setting] SCREEN_MODE_WINDOWED=1). To keep Fullscreen, simply omit this swith or set it to 0. Also, added a cmdline switch for the same effect, but with higher prio. /FULLSCREEN overwrites INI/SCREEN_MODE_WINDOWED=1 while /WINDOW overrides INI/SCREEN_MODE_WINDOWED=0. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@734 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- SCREENS.cpp | 15 +- Standard Gaming Platform/sgp.cpp | 41 +++-- Standard Gaming Platform/video.cpp | 232 +++++++++++++---------------- Utils/Music Control.cpp | 30 ++-- 4 files changed, 162 insertions(+), 156 deletions(-) diff --git a/SCREENS.cpp b/SCREENS.cpp index 915c59a2..c32b5b7a 100644 --- a/SCREENS.cpp +++ b/SCREENS.cpp @@ -6,8 +6,19 @@ #endif int iResolution; // INI file -// WANNE -int iScreenMode; // INI file (Windowed or Fullscreen) // REPLACE all defines WINDOWED_MODE with this variable +/* WANNE, Sgt.Kolja + * INI file (Windowed or Fullscreen) + * REPLACE all defines WINDOWED_MODE with this variable + * this is the LAST occurence of WINDOWED_MODE ! + * If (and only if) optionally set, we got a preset of + * Windowed Screen. But this can be overloaded by INI or CmdLine + */ +#ifdef WINDOWED_MODE +int iScreenMode = 1; /* 1 for Windowed, 0 for Fullscreen */ +#else +int iScreenMode = 0; /* 0 for Fullscreen */ +#endif +BOOL bScreenModeCmdLine = FALSE; int SCREEN_WIDTH; int SCREEN_HEIGHT; diff --git a/Standard Gaming Platform/sgp.cpp b/Standard Gaming Platform/sgp.cpp index a15780a5..7ca4a88c 100644 --- a/Standard Gaming Platform/sgp.cpp +++ b/Standard Gaming Platform/sgp.cpp @@ -54,6 +54,8 @@ extern UINT32 MemDebugCounter; #ifdef JA2 extern BOOLEAN gfPauseDueToPlayerGamePause; +extern int iScreenMode; +extern BOOL bScreenModeCmdLine; #endif extern BOOLEAN CheckIfGameCdromIsInCDromDrive(); @@ -89,9 +91,7 @@ HINSTANCE ghInstance; #endif // Global Variable Declarations -#ifdef WINDOWED_MODE RECT rcWindow; -#endif // moved from header file: 24mar98:HJH UINT32 giStartMem; @@ -139,14 +139,14 @@ INT32 FAR PASCAL WindowProcedure(HWND hWindow, UINT16 Message, WPARAM wParam, LP } #ifdef JA2 -#ifdef WINDOWED_MODE case WM_MOVE: - - GetClientRect(hWindow, &rcWindow); - ClientToScreen(hWindow, (LPPOINT)&rcWindow); - ClientToScreen(hWindow, (LPPOINT)&rcWindow+1); + if( 1==iScreenMode ) + { + GetClientRect(hWindow, &rcWindow); + ClientToScreen(hWindow, (LPPOINT)&rcWindow); + ClientToScreen(hWindow, (LPPOINT)&rcWindow+1); + } break; -#endif #else case WM_MOUSEMOVE: break; @@ -788,7 +788,7 @@ int PASCAL HandledWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR p GameLoop(); // After this frame, reset input given flag - gfSGPInputReceived = FALSE; + gfSGPInputReceived = FALSE; } } } @@ -905,6 +905,11 @@ void GetRuntimeSettings( ) iScreenWidthOffset = (SCREEN_WIDTH - 640) / 2; iScreenHeightOffset = (SCREEN_HEIGHT - 480) / 2; + + /* Sergeant_Kolja. 2007-02-20: runtime Windowed mode instead of compile-time */ + /* 1 for Windowed, 0 for Fullscreen */ + if( !bScreenModeCmdLine ) + iScreenMode = (int) GetPrivateProfileInt( "Ja2 Settings","SCREEN_MODE_WINDOWED", iScreenMode, INIFile ); } void ShutdownWithErrorBox(CHAR8 *pcMessage) @@ -1014,10 +1019,24 @@ void ProcessJa2CommandLineBeforeInitialization(CHAR8 *pCommandLine) //disable the sound SoundEnableSound(FALSE); } + else if(!_strnicmp(pToken, "/FULLSCREEN", 11)) + { + //overwrite Graphic setting from JA2_settings.ini + iScreenMode=0; /* 1 for Windowed, 0 for Fullscreen */ + bScreenModeCmdLine = TRUE; /* if set TRUE, INI is no longer evaluated */ + /* no resolution read from Args. Still from INI, but could be added here, too...*/ + } + else if(!_strnicmp(pToken, "/WINDOW", 7)) + { + //overwrite Graphic setting from JA2_settings.ini + iScreenMode=1; /* 1 for Windowed, 0 for Fullscreen */ + bScreenModeCmdLine = TRUE; /* if set TRUE, INI is no longer evaluated */ + /* no resolution read from Args. Still from INI, but could be added here, too...*/ + } - //get the next token + //get the next token pToken=strtok(NULL, cSeparators); } MemFree(pCopy); -} \ No newline at end of file +} diff --git a/Standard Gaming Platform/video.cpp b/Standard Gaming Platform/video.cpp index e166e6ff..059d83ae 100644 --- a/Standard Gaming Platform/video.cpp +++ b/Standard Gaming Platform/video.cpp @@ -22,6 +22,8 @@ #define _MT #endif +extern int iScreenMode; + /////////////////////////////////////////////////////////////////////////////////////////////////// // // Local Defines @@ -101,15 +103,9 @@ static LPDIRECTDRAWSURFACE2 gpBackBuffer = NULL; static LPDIRECTDRAWSURFACE _gpFrameBuffer = NULL; static LPDIRECTDRAWSURFACE2 gpFrameBuffer = NULL; - -#ifdef WINDOWED_MODE - static LPDIRECTDRAWSURFACE _gpBackBuffer = NULL; +extern RECT rcWindow; -extern RECT rcWindow; - - -#endif // @@ -217,11 +213,7 @@ BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void * DDSURFACEDESC SurfaceDescription; DDCOLORKEY ColorKey; PTR pTmpPointer; - -#ifndef WINDOWED_MODE DDSCAPS SurfaceCaps; -#endif - // // Register debug topics @@ -255,11 +247,11 @@ BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void * // Get a window handle for our application (gotta have on of those) // Don't change this // -#ifdef WINDOWED_MODE - hWindow = CreateWindowEx(0, (LPCSTR) ClassName, "Windowed JA2 !!", WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); -#else - hWindow = CreateWindowEx(WS_EX_TOPMOST, (LPCSTR) ClassName, (LPCSTR)ClassName, WS_POPUP | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); -#endif + if( 1==iScreenMode ) + hWindow = CreateWindowEx(0, (LPCSTR) ClassName, "Windowed JA2 !!", WS_POPUP, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); + else + hWindow = CreateWindowEx(WS_EX_TOPMOST, (LPCSTR) ClassName, (LPCSTR)ClassName, WS_POPUP | WS_VISIBLE, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL); + if (hWindow == NULL) { DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create window frame for Direct Draw"); @@ -311,11 +303,11 @@ BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void * // // Set the exclusive mode // -#ifdef WINDOWED_MODE - ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); -#else - ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); -#endif + if( 1==iScreenMode ) /* Windowed mode */ + ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); + else + ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); + if (ReturnCode != DD_OK) { DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); @@ -325,14 +317,15 @@ BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void * // // Set the display mode // -#ifndef WINDOWED_MODE - ReturnCode = IDirectDraw2_SetDisplayMode( gpDirectDrawObject, SCREEN_WIDTH, SCREEN_HEIGHT, gbPixelDepth, 0, 0 ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } -#endif + if( 0==iScreenMode ) /* Fullscreen mode */ + { + ReturnCode = IDirectDraw2_SetDisplayMode( gpDirectDrawObject, SCREEN_WIDTH, SCREEN_HEIGHT, gbPixelDepth, 0, 0 ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + } gusScreenWidth = SCREEN_WIDTH; gusScreenHeight = SCREEN_HEIGHT; @@ -349,81 +342,80 @@ BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void * // ZEROMEM(SurfaceDescription); -#ifdef WINDOWED_MODE + if( 1==iScreenMode ) /* Windowed mode */ + { + // Create a primary surface and a backbuffer in system memory + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - // Create a primary surface and a backbuffer in system memory - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpPrimarySurface, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpPrimarySurface, NULL ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - ReturnCode = IDirectDrawSurface_QueryInterface(_gpPrimarySurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpPrimarySurface); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ReturnCode = IDirectDrawSurface_QueryInterface(_gpPrimarySurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpPrimarySurface); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - // Backbuffer - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - SurfaceDescription.dwWidth = SCREEN_WIDTH; - SurfaceDescription.dwHeight = SCREEN_HEIGHT; - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpBackBuffer, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + // Backbuffer + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + SurfaceDescription.dwWidth = SCREEN_WIDTH; + SurfaceDescription.dwHeight = SCREEN_HEIGHT; + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpBackBuffer, NULL ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - ReturnCode = IDirectDrawSurface_QueryInterface(_gpBackBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpBackBuffer); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ReturnCode = IDirectDrawSurface_QueryInterface(_gpBackBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpBackBuffer); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + } + else /* iScreenMode = FULLSCREEN */ + { + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; + SurfaceDescription.dwBackBufferCount = 1; + + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpPrimarySurface, NULL ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } -#else - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; - SurfaceDescription.dwBackBufferCount = 1; + ReturnCode = IDirectDrawSurface_QueryInterface(_gpPrimarySurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *) &gpPrimarySurface); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpPrimarySurface, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - - ReturnCode = IDirectDrawSurface_QueryInterface(_gpPrimarySurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *) &gpPrimarySurface); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - SurfaceCaps.dwCaps = DDSCAPS_BACKBUFFER; - ReturnCode = IDirectDrawSurface2_GetAttachedSurface( gpPrimarySurface, &SurfaceCaps, &gpBackBuffer ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - -#endif + SurfaceCaps.dwCaps = DDSCAPS_BACKBUFFER; + ReturnCode = IDirectDrawSurface2_GetAttachedSurface( gpPrimarySurface, &SurfaceCaps, &gpBackBuffer ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + } /* endif iScreenMode */ // // Initialize the frame buffer @@ -2153,20 +2145,28 @@ void RefreshScreen(void *DummyVariable) // // Step (1) - Flip pages // -#ifdef WINDOWED_MODE - do { + if( 1==iScreenMode ) /* Windowed mode */ + { + ReturnCode = IDirectDrawSurface_Blt( + gpPrimarySurface, // dest surface + &rcWindow, // dest rect + gpBackBuffer, // src surface + NULL, // src rect (all of it) + DDBLT_WAIT, + NULL); + } + else + { + ReturnCode = IDirectDrawSurface_Flip( + _gpPrimarySurface, + NULL, + gGameExternalOptions.gfVSync ? DDFLIP_WAIT : 0x00000008l + ); + } - ReturnCode = IDirectDrawSurface_Blt( - gpPrimarySurface, // dest surface - &rcWindow, // dest rect - gpBackBuffer, // src surface - NULL, // src rect (all of it) - DDBLT_WAIT, - NULL); - - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); @@ -2179,26 +2179,6 @@ void RefreshScreen(void *DummyVariable) } while (ReturnCode != DD_OK); -#else - - do - { - ReturnCode = IDirectDrawSurface_Flip(_gpPrimarySurface, NULL, gGameExternalOptions.gfVSync ? DDFLIP_WAIT : 0x00000008l );//DDFLIP_WAIT ); -// if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - } - - } while (ReturnCode != DD_OK); - -#endif - // // Step (2) - Copy Primary Surface to the Back Buffer // diff --git a/Utils/Music Control.cpp b/Utils/Music Control.cpp index e3db439c..c0c572da 100644 --- a/Utils/Music Control.cpp +++ b/Utils/Music Control.cpp @@ -15,6 +15,7 @@ #include "fade screen.h" #endif +extern int iScreenMode; UINT32 uiMusicHandle=NO_SAMPLE; UINT32 uiMusicVolume=50; @@ -99,9 +100,10 @@ void MusicStopCallback( void *pData ); //******************************************************************************** BOOLEAN MusicPlay(UINT32 uiNum) { -#ifndef WINDOWED_MODE + if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ + return FALSE; -SOUNDPARMS spParms; + SOUNDPARMS spParms; if(fMusicPlaying) MusicStop(); @@ -128,10 +130,6 @@ SOUNDPARMS spParms; } //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music PLay %d %d", uiMusicHandle, gubMusicMode ) ); - - -#endif - return(FALSE); } @@ -147,9 +145,11 @@ BOOLEAN MusicSetVolume(UINT32 uiVolume) { INT32 uiOldMusicVolume = uiMusicVolume; -#ifndef WINDOWED_MODE + if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ + return FALSE; - uiMusicVolume=__min(uiVolume, 127); + + uiMusicVolume=__min(uiVolume, 127); if(uiMusicHandle!=NO_SAMPLE) { @@ -173,8 +173,6 @@ BOOLEAN MusicSetVolume(UINT32 uiVolume) StartMusicBasedOnMode( ); } -#endif - return(FALSE); } @@ -201,8 +199,8 @@ UINT32 MusicGetVolume(void) //******************************************************************************** BOOLEAN MusicStop(void) { - -#ifndef WINDOWED_MODE + if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ + return(FALSE); if(uiMusicHandle!=NO_SAMPLE) @@ -216,9 +214,6 @@ BOOLEAN MusicStop(void) } //DebugMsg( TOPIC_JA2, DBG_LEVEL_3, String( "Music Stop %d %d", uiMusicHandle, gubMusicMode ) ); - -#endif - return(FALSE); } @@ -271,7 +266,9 @@ BOOLEAN MusicPoll( BOOLEAN fForce ) { //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll"); -#ifndef WINDOWED_MODE + if( 1==iScreenMode ) /* on Windowed mode, skip the music? was coded for WINDOWED_MODE that way...*/ + return(TRUE); + INT32 iVol; //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll: SoundServiceStreams "); @@ -356,7 +353,6 @@ BOOLEAN MusicPoll( BOOLEAN fForce ) gfDontRestartSong = FALSE; } } -#endif //DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"MusicPoll done"); return(TRUE);