From 9d71fc89f0804a125214a01447ecfaad2a23469b Mon Sep 17 00:00:00 2001 From: Overhaul Date: Thu, 19 Jul 2007 08:33:17 +0000 Subject: [PATCH] Massive effort to reign in militia problem. Still has issues :( Fix: If only some of mercs go to a lower level (mine, basement, etc) but do not choose to "GO TO SECTOR", sector is still inaccessible from strategic map. However, watch for triggers that might happen on first visit to a sector, that fail. git-svn-id: https://ja2svn.mooo.com/source/ja2/trunk/GameSource/ja2_v1.13/Build@1076 3b4a5df2-a311-0410-b5c6-a8a6f20db521 --- Res/resource.h | 2 +- Standard Gaming Platform/video.cpp | 3660 ++++++++++++------------ Strategic/Auto Resolve.cpp | 8 + Strategic/Game Clock.cpp | 2 +- Strategic/Map Screen Interface Map.cpp | 14 +- Strategic/MilitiaSquads.cpp | 27 +- Strategic/PreBattle Interface.cpp | 2 + Strategic/Queen Command.cpp | 10 +- Strategic/Reinforcement.cpp | 3 + Strategic/Strategic Movement.cpp | 12 +- Strategic/Town Militia.cpp | 51 +- Strategic/strategicmap.cpp | 15 +- Tactical/Militia Control.cpp | 84 +- Tactical/Overhead.cpp | 2 + Tactical/Soldier Create.cpp | 1 + resource.h | 28 - 16 files changed, 2017 insertions(+), 1904 deletions(-) delete mode 100644 resource.h diff --git a/Res/resource.h b/Res/resource.h index f0f6ca6f..31646037 100644 --- a/Res/resource.h +++ b/Res/resource.h @@ -1,6 +1,6 @@ //{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. -// Used by ja2.rc +// Used by ja2.rc and console.rc // #define IDI_ICON1 113 #define IDI_ICON2 115 diff --git a/Standard Gaming Platform/video.cpp b/Standard Gaming Platform/video.cpp index 786015e2..8a2f4b75 100644 --- a/Standard Gaming Platform/video.cpp +++ b/Standard Gaming Platform/video.cpp @@ -1,29 +1,29 @@ #ifdef JA2_PRECOMPILED_HEADERS - #include "JA2 SGP ALL.H" +#include "JA2 SGP ALL.H" #elif defined( WIZ8_PRECOMPILED_HEADERS ) - #include "WIZ8 SGP ALL.H" +#include "WIZ8 SGP ALL.H" #else - #include "types.h" - #include "Video.h" - #include "vobject_blitters.h" - #include "sgp.h" - #include - #include - #include "renderworld.h" - #include "Render Dirty.h" - #include "Isometric utils.h" - #include "fade screen.h" - #include "impTGA.h" - #include "timer control.h" - #include "Fileman.h" - #include "Input.h" - #include "GameSettings.h" +#include "types.h" +#include "Video.h" +#include "vobject_blitters.h" +#include "sgp.h" +#include +#include +#include "renderworld.h" +#include "Render Dirty.h" +#include "Isometric utils.h" +#include "fade screen.h" +#include "impTGA.h" +#include "timer control.h" +#include "Fileman.h" +#include "Input.h" +#include "GameSettings.h" #endif #include "resource.h" #ifndef _MT - #define _MT +#define _MT #endif extern int iScreenMode; @@ -57,12 +57,12 @@ extern int iScreenMode; typedef struct { - BOOLEAN fRestore; - INT16 usMouseXPos, usMouseYPos; - INT16 usLeft, usTop, usRight, usBottom; + BOOLEAN fRestore; + INT16 usMouseXPos, usMouseYPos; + INT16 usLeft, usTop, usRight, usBottom; RECT Region; - LPDIRECTDRAWSURFACE _pSurface; - LPDIRECTDRAWSURFACE2 pSurface; + LPDIRECTDRAWSURFACE _pSurface; + LPDIRECTDRAWSURFACE2 pSurface; } MouseCursorBackground; @@ -209,494 +209,494 @@ void RefreshMovieCache( ); BOOLEAN InitializeVideoManager(HINSTANCE hInstance, UINT16 usCommandShow, void *WindowProc) { - UINT32 uiIndex, uiPitch; - HRESULT ReturnCode; - HWND hWindow; - WNDCLASS WindowClass; - UINT8 ClassName[] = APPLICATION_NAME; - DDSURFACEDESC SurfaceDescription; - DDCOLORKEY ColorKey; - PTR pTmpPointer; - DDSCAPS SurfaceCaps; + UINT32 uiIndex, uiPitch; + HRESULT ReturnCode; + HWND hWindow; + WNDCLASS WindowClass; + UINT8 ClassName[] = APPLICATION_NAME; + DDSURFACEDESC SurfaceDescription; + DDCOLORKEY ColorKey; + PTR pTmpPointer; + DDSCAPS SurfaceCaps; - // - // Register debug topics - // + // + // Register debug topics + // - RegisterDebugTopic(TOPIC_VIDEO, "Video"); - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Initializing the video manager"); + RegisterDebugTopic(TOPIC_VIDEO, "Video"); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Initializing the video manager"); - ///////////////////////////////////////////////////////////////////////////////////////////////// - // - // Register and Realize our display window. The DirectX surface will eventually overlay on top - // of this surface. - // - // <<<<<<<<< Don't change this >>>>>>>> - // - ///////////////////////////////////////////////////////////////////////////////////////////////// - - WindowClass.style = CS_HREDRAW | CS_VREDRAW; - WindowClass.lpfnWndProc = (WNDPROC) WindowProc; - WindowClass.cbClsExtra = 0; - WindowClass.cbWndExtra = 0; - WindowClass.hInstance = hInstance; - WindowClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE( IDI_ICON1 ) ); - WindowClass.hCursor = NULL; - WindowClass.hbrBackground = NULL; - WindowClass.lpszMenuName = NULL; - WindowClass.lpszClassName = (LPCSTR) ClassName; - RegisterClass(&WindowClass); + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // Register and Realize our display window. The DirectX surface will eventually overlay on top + // of this surface. + // + // <<<<<<<<< Don't change this >>>>>>>> + // + ///////////////////////////////////////////////////////////////////////////////////////////////// - // - // Get a window handle for our application (gotta have on of those) - // Don't change this - // - if( 1==iScreenMode ) - { - RECT window; - DWORD style; - DWORD exstyle; + WindowClass.style = CS_HREDRAW | CS_VREDRAW; + WindowClass.lpfnWndProc = (WNDPROC) WindowProc; + WindowClass.cbClsExtra = 0; + WindowClass.cbWndExtra = 0; + WindowClass.hInstance = hInstance; + WindowClass.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE( IDI_ICON1 ) ); + WindowClass.hCursor = NULL; + WindowClass.hbrBackground = NULL; + WindowClass.lpszMenuName = NULL; + WindowClass.lpszClassName = (LPCSTR) ClassName; + RegisterClass(&WindowClass); - window.top = 0; - window.left = 0; - window.right = SCREEN_WIDTH; - window.bottom = SCREEN_HEIGHT; + // + // Get a window handle for our application (gotta have on of those) + // Don't change this + // + if( 1==iScreenMode ) + { + RECT window; + DWORD style; + DWORD exstyle; - exstyle = WS_EX_APPWINDOW; - style = WS_OVERLAPPEDWINDOW & (~(WS_MAXIMIZEBOX | WS_SYSMENU)); + window.top = 0; + window.left = 0; + window.right = SCREEN_WIDTH; + window.bottom = SCREEN_HEIGHT; - AdjustWindowRectEx( &window, style, FALSE, exstyle); - OffsetRect( &window, -window.left, -window.top); + exstyle = WS_EX_APPWINDOW; + style = WS_OVERLAPPEDWINDOW & (~(WS_MAXIMIZEBOX | WS_SYSMENU)); - ptWindowSize.x = window.right; - ptWindowSize.y = window.bottom; + AdjustWindowRectEx( &window, style, FALSE, exstyle); + OffsetRect( &window, -window.left, -window.top); - hWindow = CreateWindowEx(exstyle, (LPCSTR) ClassName, "Jagged Alliance 2 v1.13", style, window.left, window.top, window.right, window.bottom, NULL, NULL, hInstance, NULL); - GetClientRect( hWindow, &window); - window.top = window.top; - } - else - hWindow = CreateWindowEx(WS_EX_TOPMOST, (LPCSTR) ClassName, (LPCSTR)ClassName, WS_POPUP | WS_VISIBLE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); + ptWindowSize.x = window.right; + ptWindowSize.y = window.bottom; - if (hWindow == NULL) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create window frame for Direct Draw"); - return FALSE; - } + hWindow = CreateWindowEx(exstyle, (LPCSTR) ClassName, "Jagged Alliance 2 v1.13", style, window.left, window.top, window.right, window.bottom, NULL, NULL, hInstance, NULL); + GetClientRect( hWindow, &window); + window.top = window.top; + } + else + hWindow = CreateWindowEx(WS_EX_TOPMOST, (LPCSTR) ClassName, (LPCSTR)ClassName, WS_POPUP | WS_VISIBLE, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, NULL, NULL, hInstance, NULL); - // - // Okay, now hide the cursor for the window. - // - SetCursor( NULL); + if (hWindow == NULL) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create window frame for Direct Draw"); + return FALSE; + } - // - // Excellent. Now we record the hWindow variable for posterity (not) - // + // + // Okay, now hide the cursor for the window. + // + SetCursor( NULL); + + // + // Excellent. Now we record the hWindow variable for posterity (not) + // memset( gpFrameData, 0, sizeof( gpFrameData ) ); - ghWindow = hWindow; + ghWindow = hWindow; - // - // Display our full screen window - // + // + // Display our full screen window + // -// ShowCursor(FALSE); - ShowWindow(hWindow, usCommandShow); - UpdateWindow(hWindow); - SetFocus(hWindow); - - ///////////////////////////////////////////////////////////////////////////////////////////////// - // - // Start up Direct Draw - // - ///////////////////////////////////////////////////////////////////////////////////////////////// + // ShowCursor(FALSE); + ShowWindow(hWindow, usCommandShow); + UpdateWindow(hWindow); + SetFocus(hWindow); - // - // Create the Direct Draw Object - // + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // Start up Direct Draw + // + ///////////////////////////////////////////////////////////////////////////////////////////////// - ReturnCode = DirectDrawCreate(NULL, &_gpDirectDrawObject, NULL); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - ReturnCode = IDirectDraw_QueryInterface( _gpDirectDrawObject, /*&*/IID_IDirectDraw2, (LPVOID *) &gpDirectDrawObject ); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; + // + // Create the Direct Draw Object + // + + ReturnCode = DirectDrawCreate(NULL, &_gpDirectDrawObject, NULL); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; } - // - // Set the exclusive mode - // - if( 1==iScreenMode ) /* Windowed mode */ - ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); - else - ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); + ReturnCode = IDirectDraw_QueryInterface( _gpDirectDrawObject, /*&*/IID_IDirectDraw2, (LPVOID *) &gpDirectDrawObject ); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - // - // Set the display mode - // - 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; - } - } + // + // Set the exclusive mode + // + if( 1==iScreenMode ) /* Windowed mode */ + ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); + else + ReturnCode = IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN ); - gusScreenWidth = SCREEN_WIDTH; - gusScreenHeight = SCREEN_HEIGHT; - gubScreenPixelDepth = gbPixelDepth; - - ///////////////////////////////////////////////////////////////////////////////////////////////// - // - // Setup all the surfaces - // - ///////////////////////////////////////////////////////////////////////////////////////////////// + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - // - // Initialize Primary Surface along with BackBuffer - // + // + // Set the display mode + // + 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; + } + } - ZEROMEM(SurfaceDescription); - if( 1==iScreenMode ) /* Windowed mode */ - { - LPDIRECTDRAWCLIPPER clip; + gusScreenWidth = SCREEN_WIDTH; + gusScreenHeight = SCREEN_HEIGHT; + gubScreenPixelDepth = gbPixelDepth; - // Create a primary surface and a backbuffer in system memory - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; + ///////////////////////////////////////////////////////////////////////////////////////////////// + // + // Setup all the surfaces + // + ///////////////////////////////////////////////////////////////////////////////////////////////// - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpPrimarySurface, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + // + // Initialize Primary Surface along with BackBuffer + // - ReturnCode = DirectDrawCreateClipper ( 0, &clip, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ZEROMEM(SurfaceDescription); + if( 1==iScreenMode ) /* Windowed mode */ + { + LPDIRECTDRAWCLIPPER clip; - ReturnCode = IDirectDrawClipper_SetHWnd( clip, 0, ghWindow); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + // Create a primary surface and a backbuffer in system memory + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - ReturnCode = IDirectDrawSurface_SetClipper( _gpPrimarySurface, clip); - 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 = DirectDrawCreateClipper ( 0, &clip, 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 = IDirectDrawClipper_SetHWnd( clip, 0, ghWindow); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + ReturnCode = IDirectDrawSurface_SetClipper( _gpPrimarySurface, clip); + 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 = IDirectDrawSurface_QueryInterface(_gpPrimarySurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpPrimarySurface); // (jonathanl) + 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 iScreenMode */ - - // - // Initialize the frame buffer - // - - 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, &_gpFrameBuffer, NULL ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - ReturnCode = IDirectDrawSurface_QueryInterface(_gpFrameBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpFrameBuffer); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - // - // Blank out the frame buffer - // - - pTmpPointer = LockFrameBuffer(&uiPitch); - memset(pTmpPointer, 0, SCREEN_HEIGHT * uiPitch); - UnlockFrameBuffer(); - - // - // Initialize the main mouse surfaces - // - - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - // SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; - SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpMouseCursor, NULL ); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to create MouseCursor witd %ld", ReturnCode & 0x0f)); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - ReturnCode = IDirectDrawSurface_QueryInterface(_gpMouseCursor, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpMouseCursor); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - ColorKey.dwColorSpaceLowValue = 0; - ColorKey.dwColorSpaceHighValue = 0; - ReturnCode = IDirectDrawSurface2_SetColorKey(gpMouseCursor, DDCKEY_SRCBLT, &ColorKey); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - // - // Initialize the main mouse original surface - // - - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; - SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpMouseCursorOriginal, NULL ); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create MouseCursorOriginal"); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - ReturnCode = IDirectDrawSurface_QueryInterface(_gpMouseCursorOriginal, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpMouseCursorOriginal); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - // - // Initialize the main mouse background surfaces. There are two of them (one for each of the Primary - // and Backbuffer surfaces - // - - for (uiIndex = 0; uiIndex < 1; uiIndex++) - { - // - // Initialize various mouse background variables - // - - gMouseCursorBackground[uiIndex].fRestore = FALSE; - - // - // Initialize the direct draw surfaces for the mouse background - // - - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - //SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + // Backbuffer + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; - SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; - SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; - ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &(gMouseCursorBackground[uiIndex]._pSurface), NULL ); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create MouseCursorBackground"); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + 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(gMouseCursorBackground[uiIndex]._pSurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&(gMouseCursorBackground[uiIndex].pSurface)); // (jonathanl) - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - } - // - // Initialize the mutex sections - // + 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; + } + + + 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 iScreenMode */ + + // + // Initialize the frame buffer + // + + 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, &_gpFrameBuffer, NULL ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ReturnCode = IDirectDrawSurface_QueryInterface(_gpFrameBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpFrameBuffer); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + // + // Blank out the frame buffer + // + + pTmpPointer = LockFrameBuffer(&uiPitch); + memset(pTmpPointer, 0, SCREEN_HEIGHT * uiPitch); + UnlockFrameBuffer(); + + // + // Initialize the main mouse surfaces + // + + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + // SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; + SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpMouseCursor, NULL ); + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to create MouseCursor witd %ld", ReturnCode & 0x0f)); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ReturnCode = IDirectDrawSurface_QueryInterface(_gpMouseCursor, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpMouseCursor); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ColorKey.dwColorSpaceLowValue = 0; + ColorKey.dwColorSpaceHighValue = 0; + ReturnCode = IDirectDrawSurface2_SetColorKey(gpMouseCursor, DDCKEY_SRCBLT, &ColorKey); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + // + // Initialize the main mouse original surface + // + + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; + SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &_gpMouseCursorOriginal, NULL ); + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create MouseCursorOriginal"); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ReturnCode = IDirectDrawSurface_QueryInterface(_gpMouseCursorOriginal, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&gpMouseCursorOriginal); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + // + // Initialize the main mouse background surfaces. There are two of them (one for each of the Primary + // and Backbuffer surfaces + // + + for (uiIndex = 0; uiIndex < 1; uiIndex++) + { + // + // Initialize various mouse background variables + // + + gMouseCursorBackground[uiIndex].fRestore = FALSE; + + // + // Initialize the direct draw surfaces for the mouse background + // + + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; + //SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; + SurfaceDescription.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; + SurfaceDescription.dwWidth = MAX_CURSOR_WIDTH; + SurfaceDescription.dwHeight = MAX_CURSOR_HEIGHT; + ReturnCode = IDirectDraw2_CreateSurface ( gpDirectDrawObject, &SurfaceDescription, &(gMouseCursorBackground[uiIndex]._pSurface), NULL ); + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to create MouseCursorBackground"); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ReturnCode = IDirectDrawSurface_QueryInterface(gMouseCursorBackground[uiIndex]._pSurface, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&(gMouseCursorBackground[uiIndex].pSurface)); // (jonathanl) + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + } + + // + // Initialize the mutex sections + // // ATE: Keep these mutexes for now! - if (InitializeMutex(REFRESH_THREAD_MUTEX, (UINT8 *)"RefreshThreadMutex") == FALSE) - { - return FALSE; - } - if (InitializeMutex(FRAME_BUFFER_MUTEX, (UINT8 *)"FrameBufferMutex") == FALSE) - { - return FALSE; - } - if (InitializeMutex(MOUSE_BUFFER_MUTEX, (UINT8 *)"MouseBufferMutex") == FALSE) - { - return FALSE; - } + if (InitializeMutex(REFRESH_THREAD_MUTEX, (UINT8 *)"RefreshThreadMutex") == FALSE) + { + return FALSE; + } + if (InitializeMutex(FRAME_BUFFER_MUTEX, (UINT8 *)"FrameBufferMutex") == FALSE) + { + return FALSE; + } + if (InitializeMutex(MOUSE_BUFFER_MUTEX, (UINT8 *)"MouseBufferMutex") == FALSE) + { + return FALSE; + } - // - // Initialize state variables - // + // + // Initialize state variables + // - guiFrameBufferState = BUFFER_DIRTY; - guiMouseBufferState = BUFFER_DISABLED; - guiVideoManagerState = VIDEO_ON; - guiRefreshThreadState = THREAD_OFF; - guiDirtyRegionCount = 0; - gfForceFullScreenRefresh = TRUE; - gpFrameBufferRefreshOverride = NULL; - gpCursorStore = NULL; - gfPrintFrameBuffer = FALSE; - guiPrintFrameBufferIndex = 0; + guiFrameBufferState = BUFFER_DIRTY; + guiMouseBufferState = BUFFER_DISABLED; + guiVideoManagerState = VIDEO_ON; + guiRefreshThreadState = THREAD_OFF; + guiDirtyRegionCount = 0; + gfForceFullScreenRefresh = TRUE; + gpFrameBufferRefreshOverride = NULL; + gpCursorStore = NULL; + gfPrintFrameBuffer = FALSE; + guiPrintFrameBufferIndex = 0; - // - // This function must be called to setup RGB information - // + // + // This function must be called to setup RGB information + // - GetRGBDistribution(); + GetRGBDistribution(); - return TRUE; + return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////// void ShutdownVideoManager(void) { - //UINT32 uiRefreshThreadState; + //UINT32 uiRefreshThreadState; DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Shutting down the video manager"); - // - // Toggle the state of the video manager to indicate to the refresh thread that it needs to shut itself - // down - // + // + // Toggle the state of the video manager to indicate to the refresh thread that it needs to shut itself + // down + // - IDirectDrawSurface2_Release(gpMouseCursorOriginal); - IDirectDrawSurface2_Release(gpMouseCursor); - IDirectDrawSurface2_Release(gMouseCursorBackground[0].pSurface); - IDirectDrawSurface2_Release(gpBackBuffer); - IDirectDrawSurface2_Release(gpPrimarySurface); + IDirectDrawSurface2_Release(gpMouseCursorOriginal); + IDirectDrawSurface2_Release(gpMouseCursor); + IDirectDrawSurface2_Release(gMouseCursorBackground[0].pSurface); + IDirectDrawSurface2_Release(gpBackBuffer); + IDirectDrawSurface2_Release(gpPrimarySurface); - IDirectDraw2_RestoreDisplayMode( gpDirectDrawObject ); - IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); - IDirectDraw2_Release( gpDirectDrawObject ); + IDirectDraw2_RestoreDisplayMode( gpDirectDrawObject ); + IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); + IDirectDraw2_Release( gpDirectDrawObject ); - // destroy the window - // DestroyWindow( ghWindow ); + // destroy the window + // DestroyWindow( ghWindow ); - guiVideoManagerState = VIDEO_OFF; + guiVideoManagerState = VIDEO_OFF; - if (gpCursorStore != NULL) - { - DeleteVideoObject(gpCursorStore); - gpCursorStore = NULL; - } + if (gpCursorStore != NULL) + { + DeleteVideoObject(gpCursorStore); + gpCursorStore = NULL; + } - // ATE: Release mouse cursor! - FreeMouseCursor( ); + // ATE: Release mouse cursor! + FreeMouseCursor( ); - UnRegisterDebugTopic(TOPIC_VIDEO, "Video"); + UnRegisterDebugTopic(TOPIC_VIDEO, "Video"); } /////////////////////////////////////////////////////////////////////////////////////////////////// void SuspendVideoManager(void) { - guiVideoManagerState = VIDEO_SUSPENDED; + guiVideoManagerState = VIDEO_SUSPENDED; } void DoTester( ) { - IDirectDraw2_RestoreDisplayMode( gpDirectDrawObject ); - IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); -// ShowCursor(TRUE); + IDirectDraw2_RestoreDisplayMode( gpDirectDrawObject ); + IDirectDraw2_SetCooperativeLevel(gpDirectDrawObject, ghWindow, DDSCL_NORMAL ); + // ShowCursor(TRUE); } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -704,66 +704,66 @@ void DoTester( ) BOOLEAN RestoreVideoManager(void) { HRESULT ReturnCode; - - // - // Make sure the video manager is indeed suspended before moving on - // - if (guiVideoManagerState == VIDEO_SUSPENDED) - { - // - // Restore the Primary and Backbuffer - // + // + // Make sure the video manager is indeed suspended before moving on + // - ReturnCode = IDirectDrawSurface2_Restore( gpPrimarySurface ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + if (guiVideoManagerState == VIDEO_SUSPENDED) + { + // + // Restore the Primary and Backbuffer + // - ReturnCode = IDirectDrawSurface2_Restore( gpBackBuffer ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ReturnCode = IDirectDrawSurface2_Restore( gpPrimarySurface ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - // - // Restore the mouse surfaces and make sure to initialize the gpMouseCursor surface - // - - ReturnCode = IDirectDrawSurface2_Restore( gMouseCursorBackground[0].pSurface ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } + ReturnCode = IDirectDrawSurface2_Restore( gpBackBuffer ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } - ReturnCode = IDirectDrawSurface2_Restore( gpMouseCursor ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } else - { - guiMouseBufferState = BUFFER_DIRTY; - } + // + // Restore the mouse surfaces and make sure to initialize the gpMouseCursor surface + // - // - // Set the video state to VIDEO_ON - // - - guiFrameBufferState = BUFFER_DIRTY; - guiMouseBufferState = BUFFER_DIRTY; - gfForceFullScreenRefresh = TRUE; - guiVideoManagerState = VIDEO_ON; - return TRUE; + ReturnCode = IDirectDrawSurface2_Restore( gMouseCursorBackground[0].pSurface ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + ReturnCode = IDirectDrawSurface2_Restore( gpMouseCursor ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } else + { + guiMouseBufferState = BUFFER_DIRTY; + } + + // + // Set the video state to VIDEO_ON + // + + guiFrameBufferState = BUFFER_DIRTY; + guiMouseBufferState = BUFFER_DIRTY; + gfForceFullScreenRefresh = TRUE; + guiVideoManagerState = VIDEO_ON; + return TRUE; } - else - { - return FALSE; - } + else + { + return FALSE; + } } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -779,98 +779,98 @@ void GetCurrentVideoSettings( UINT16 *usWidth, UINT16 *usHeight, UINT8 *ubBitDep BOOLEAN CanBlitToFrameBuffer(void) { - BOOLEAN fCanBlit; + BOOLEAN fCanBlit; - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - fCanBlit = (guiFrameBufferState == BUFFER_READY); + fCanBlit = (guiFrameBufferState == BUFFER_READY); - return fCanBlit; + return fCanBlit; } /////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN CanBlitToMouseBuffer(void) { - BOOLEAN fCanBlit; + BOOLEAN fCanBlit; - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // MOUSE_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // MOUSE_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - fCanBlit = (guiMouseBufferState == BUFFER_READY); + fCanBlit = (guiMouseBufferState == BUFFER_READY); - return fCanBlit; + return fCanBlit; } /////////////////////////////////////////////////////////////////////////////////////////////////// void InvalidateRegion(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom) { - if (gfForceFullScreenRefresh == TRUE) - { - // - // There's no point in going on since we are forcing a full screen refresh - // + if (gfForceFullScreenRefresh == TRUE) + { + // + // There's no point in going on since we are forcing a full screen refresh + // - return; - } + return; + } - if (guiDirtyRegionCount < MAX_DIRTY_REGIONS) - { - // - // Well we haven't broken the MAX_DIRTY_REGIONS limit yet, so we register the new region - // + if (guiDirtyRegionCount < MAX_DIRTY_REGIONS) + { + // + // Well we haven't broken the MAX_DIRTY_REGIONS limit yet, so we register the new region + // // DO SOME PREMIMARY CHECKS FOR VALID RECTS if ( iLeft < 0 ) - iLeft = 0; + iLeft = 0; if ( iTop < 0 ) - iTop = 0; + iTop = 0; if ( iRight > SCREEN_WIDTH ) - iRight = SCREEN_WIDTH; + iRight = SCREEN_WIDTH; if ( iBottom > SCREEN_HEIGHT ) - iBottom = SCREEN_HEIGHT; + iBottom = SCREEN_HEIGHT; if ( ( iRight - iLeft ) <= 0 ) - return; + return; if ( ( iBottom - iTop ) <= 0 ) - return; + return; - gListOfDirtyRegions[guiDirtyRegionCount].iLeft = iLeft; - gListOfDirtyRegions[guiDirtyRegionCount].iTop = iTop; - gListOfDirtyRegions[guiDirtyRegionCount].iRight = iRight; - gListOfDirtyRegions[guiDirtyRegionCount].iBottom = iBottom; + gListOfDirtyRegions[guiDirtyRegionCount].iLeft = iLeft; + gListOfDirtyRegions[guiDirtyRegionCount].iTop = iTop; + gListOfDirtyRegions[guiDirtyRegionCount].iRight = iRight; + gListOfDirtyRegions[guiDirtyRegionCount].iBottom = iBottom; -// gDirtyRegionFlags[ guiDirtyRegionCount ] = TRUE; + // gDirtyRegionFlags[ guiDirtyRegionCount ] = TRUE; - guiDirtyRegionCount++; + guiDirtyRegionCount++; - } - else - { - // - // The MAX_DIRTY_REGIONS limit has been exceeded. Therefore we arbitrarely invalidate the entire - // screen and force a full screen refresh - // - guiDirtyRegionExCount = 0; - guiDirtyRegionCount = 0; - gfForceFullScreenRefresh = TRUE; - } + } + else + { + // + // The MAX_DIRTY_REGIONS limit has been exceeded. Therefore we arbitrarely invalidate the entire + // screen and force a full screen refresh + // + guiDirtyRegionExCount = 0; + guiDirtyRegionCount = 0; + gfForceFullScreenRefresh = TRUE; + } } @@ -883,19 +883,19 @@ void InvalidateRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UI // Check if we are spanning the rectangle - if so slit it up! if ( iTop <= gsVIEWPORT_WINDOW_END_Y && iBottom > gsVIEWPORT_WINDOW_END_Y ) { - // Add new top region - iBottom = gsVIEWPORT_WINDOW_END_Y; - AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); - - // Add new bottom region - iTop = gsVIEWPORT_WINDOW_END_Y; - iBottom = iOldBottom; - AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); - + // Add new top region + iBottom = gsVIEWPORT_WINDOW_END_Y; + AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); + + // Add new bottom region + iTop = gsVIEWPORT_WINDOW_END_Y; + iBottom = iOldBottom; + AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); + } else { - AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); + AddRegionEx( iLeft, iTop, iRight, iBottom, uiFlags ); } } @@ -903,45 +903,45 @@ void InvalidateRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UI void AddRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UINT32 uiFlags ) { - if (guiDirtyRegionExCount < MAX_DIRTY_REGIONS) - { + if (guiDirtyRegionExCount < MAX_DIRTY_REGIONS) + { // DO SOME PREMIMARY CHECKS FOR VALID RECTS if ( iLeft < 0 ) - iLeft = 0; + iLeft = 0; if ( iTop < 0 ) - iTop = 0; + iTop = 0; if ( iRight > SCREEN_WIDTH ) - iRight = SCREEN_WIDTH; + iRight = SCREEN_WIDTH; if ( iBottom > SCREEN_HEIGHT ) - iBottom = SCREEN_HEIGHT; + iBottom = SCREEN_HEIGHT; if ( ( iRight - iLeft ) <= 0 ) - return; + return; if ( ( iBottom - iTop ) <= 0 ) - return; + return; - gDirtyRegionsEx[ guiDirtyRegionExCount ].iLeft = iLeft; - gDirtyRegionsEx[ guiDirtyRegionExCount ].iTop = iTop; - gDirtyRegionsEx[ guiDirtyRegionExCount ].iRight = iRight; - gDirtyRegionsEx[ guiDirtyRegionExCount ].iBottom = iBottom; + gDirtyRegionsEx[ guiDirtyRegionExCount ].iLeft = iLeft; + gDirtyRegionsEx[ guiDirtyRegionExCount ].iTop = iTop; + gDirtyRegionsEx[ guiDirtyRegionExCount ].iRight = iRight; + gDirtyRegionsEx[ guiDirtyRegionExCount ].iBottom = iBottom; gDirtyRegionsFlagsEx[ guiDirtyRegionExCount ] = uiFlags; - guiDirtyRegionExCount++; + guiDirtyRegionExCount++; - } + } else { - guiDirtyRegionExCount = 0; - guiDirtyRegionCount = 0; - gfForceFullScreenRefresh = TRUE; + guiDirtyRegionExCount = 0; + guiDirtyRegionCount = 0; + gfForceFullScreenRefresh = TRUE; } } @@ -951,71 +951,71 @@ void AddRegionEx(INT32 iLeft, INT32 iTop, INT32 iRight, INT32 iBottom, UINT32 ui void InvalidateRegions(SGPRect *pArrayOfRegions, UINT32 uiRegionCount) { - if (gfForceFullScreenRefresh == TRUE) - { - // - // There's no point in going on since we are forcing a full screen refresh - // + if (gfForceFullScreenRefresh == TRUE) + { + // + // There's no point in going on since we are forcing a full screen refresh + // - return; - } + return; + } - if ((guiDirtyRegionCount + uiRegionCount) < MAX_DIRTY_REGIONS) - { - UINT32 uiIndex; + if ((guiDirtyRegionCount + uiRegionCount) < MAX_DIRTY_REGIONS) + { + UINT32 uiIndex; - for (uiIndex = 0; uiIndex < uiRegionCount; uiIndex++) - { - // - // Well we haven't broken the MAX_DIRTY_REGIONS limit yet, so we register the new region - // + for (uiIndex = 0; uiIndex < uiRegionCount; uiIndex++) + { + // + // Well we haven't broken the MAX_DIRTY_REGIONS limit yet, so we register the new region + // - gListOfDirtyRegions[guiDirtyRegionCount].iLeft = pArrayOfRegions[uiIndex].iLeft; - gListOfDirtyRegions[guiDirtyRegionCount].iTop = pArrayOfRegions[uiIndex].iTop; - gListOfDirtyRegions[guiDirtyRegionCount].iRight = pArrayOfRegions[uiIndex].iRight; - gListOfDirtyRegions[guiDirtyRegionCount].iBottom = pArrayOfRegions[uiIndex].iBottom; + gListOfDirtyRegions[guiDirtyRegionCount].iLeft = pArrayOfRegions[uiIndex].iLeft; + gListOfDirtyRegions[guiDirtyRegionCount].iTop = pArrayOfRegions[uiIndex].iTop; + gListOfDirtyRegions[guiDirtyRegionCount].iRight = pArrayOfRegions[uiIndex].iRight; + gListOfDirtyRegions[guiDirtyRegionCount].iBottom = pArrayOfRegions[uiIndex].iBottom; - guiDirtyRegionCount++; - } - } - else - { - guiDirtyRegionCount = 0; - gfForceFullScreenRefresh = TRUE; - } + guiDirtyRegionCount++; + } + } + else + { + guiDirtyRegionCount = 0; + gfForceFullScreenRefresh = TRUE; + } } /////////////////////////////////////////////////////////////////////////////////////////////////// void InvalidateScreen(void) { - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - guiDirtyRegionCount = 0; - guiDirtyRegionExCount = 0; - gfForceFullScreenRefresh = TRUE; - guiFrameBufferState = BUFFER_DIRTY; + guiDirtyRegionCount = 0; + guiDirtyRegionExCount = 0; + gfForceFullScreenRefresh = TRUE; + guiFrameBufferState = BUFFER_DIRTY; } /////////////////////////////////////////////////////////////////////////////////////////////////// void InvalidateFrameBuffer(void) { - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - guiFrameBufferState = BUFFER_DIRTY; + guiFrameBufferState = BUFFER_DIRTY; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -1023,7 +1023,7 @@ void InvalidateFrameBuffer(void) void SetFrameBufferRefreshOverride(PTR pFrameBufferRefreshOverride) { - gpFrameBufferRefreshOverride = (void (__cdecl *)(void))pFrameBufferRefreshOverride; + gpFrameBufferRefreshOverride = (void (__cdecl *)(void))pFrameBufferRefreshOverride; } //#define SCROLL_TEST @@ -1033,8 +1033,8 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr { UINT16 usWidth, usHeight; UINT8 ubBitDepth; - HRESULT ReturnCode; - static RECT Region; + HRESULT ReturnCode; + static RECT Region; static UINT16 usMouseXPos, usMouseYPos; static RECT StripRegions[ 2 ], MouseRegion; UINT16 usNumStrips = 0; @@ -1043,13 +1043,13 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr INT32 uiCountY; - GetCurrentVideoSettings( &usWidth, &usHeight, &ubBitDepth ); + GetCurrentVideoSettings( &usWidth, &usHeight, &ubBitDepth ); usHeight=(gsVIEWPORT_WINDOW_END_Y - gsVIEWPORT_WINDOW_START_Y ); -// pSource = gpFrameBuffer; -// pDest = gpFrameBuffer; + // pSource = gpFrameBuffer; + // pDest = gpFrameBuffer; -///zmiany + ///zmiany StripRegions[ 0 ].left = gsVIEWPORT_START_X ; StripRegions[ 0 ].right = gsVIEWPORT_END_X ; StripRegions[ 0 ].top = gsVIEWPORT_WINDOW_START_Y ; @@ -1069,351 +1069,351 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr switch (uiDirection) { - case SCROLL_LEFT: + case SCROLL_LEFT: - Region.left = 0; - Region.top = gsVIEWPORT_WINDOW_START_Y; - Region.right = usWidth-(sScrollXIncrement); - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; + Region.left = 0; + Region.top = gsVIEWPORT_WINDOW_START_Y; + Region.right = usWidth-(sScrollXIncrement); + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - do + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } + break; } - } while (ReturnCode != DD_OK); - - // memset z-buffer - for(uiCountY = gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - sScrollXIncrement*2); - - } - - StripRegions[ 0 ].right =(INT16)(gsVIEWPORT_START_X+sScrollXIncrement); - usMouseXPos += sScrollXIncrement; - - usNumStrips = 1; - break; - - case SCROLL_RIGHT: - - - Region.left = sScrollXIncrement ; - Region.top = gsVIEWPORT_WINDOW_START_Y; - Region.right = usWidth; - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - - if (Region.left >= Region.right) - { - break; } + } while (ReturnCode != DD_OK); - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + // memset z-buffer + for(uiCountY = gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + sScrollXIncrement*2); - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } - } - } while (ReturnCode != DD_OK); + } - // memset z-buffer - for(uiCountY= gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, - sScrollXIncrement*2); - } + StripRegions[ 0 ].right =(INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + usMouseXPos += sScrollXIncrement; + + usNumStrips = 1; + break; + + case SCROLL_RIGHT: - //for(uiCountY=0; uiCountY < usHeight; uiCountY++) - //{ - // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), - // pSrcBuf+(uiCountY*uiDestPitchBYTES)+sScrollXIncrement*uiBPP, - // uiDestPitchBYTES-sScrollXIncrement*uiBPP); - //} + Region.left = sScrollXIncrement ; + Region.top = gsVIEWPORT_WINDOW_START_Y; + Region.right = usWidth; + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - StripRegions[ 0 ].left =(INT16)(gsVIEWPORT_END_X-sScrollXIncrement); - usMouseXPos -= sScrollXIncrement; - - usNumStrips = 1; + if (Region.left >= Region.right) + { break; + } - case SCROLL_UP: - - Region.left = 0; - Region.top = gsVIEWPORT_WINDOW_START_Y; - Region.right = usWidth; - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; - - do + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } + break; } - } while (ReturnCode != DD_OK); - - - for(uiCountY=sScrollYIncrement-1+gsVIEWPORT_WINDOW_START_Y; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); - } - - //for(uiCountY=usHeight-1; uiCountY >= sScrollYIncrement; uiCountY--) - //{ - // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), - // pSrcBuf+((uiCountY-sScrollYIncrement)*uiDestPitchBYTES), - // uiDestPitchBYTES); - //} - StripRegions[ 0 ].bottom =(INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); - usNumStrips = 1; - - usMouseYPos += sScrollYIncrement; - - break; - - case SCROLL_DOWN: - - Region.left = 0; - Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; - Region.right = usWidth; - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } - } - } while (ReturnCode != DD_OK); - - // Zero out z - for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement ); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); } + } while (ReturnCode != DD_OK); - //for(uiCountY=0; uiCountY < (usHeight-sScrollYIncrement); uiCountY++) - //{ - // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), - // pSrcBuf+((uiCountY+sScrollYIncrement)*uiDestPitchBYTES), - // uiDestPitchBYTES); - //} + // memset z-buffer + for(uiCountY= gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, + sScrollXIncrement*2); + } - StripRegions[ 0 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); - usNumStrips = 1; - usMouseYPos -= sScrollYIncrement; + //for(uiCountY=0; uiCountY < usHeight; uiCountY++) + //{ + // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), + // pSrcBuf+(uiCountY*uiDestPitchBYTES)+sScrollXIncrement*uiBPP, + // uiDestPitchBYTES-sScrollXIncrement*uiBPP); + //} - break; + StripRegions[ 0 ].left =(INT16)(gsVIEWPORT_END_X-sScrollXIncrement); + usMouseXPos -= sScrollXIncrement; - case SCROLL_UPLEFT: + usNumStrips = 1; + break; - Region.left = 0; - Region.top = gsVIEWPORT_WINDOW_START_Y; - Region.right = usWidth-(sScrollXIncrement); - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; + case SCROLL_UP: - do + Region.left = 0; + Region.top = gsVIEWPORT_WINDOW_START_Y; + Region.right = usWidth; + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } + break; } - } while (ReturnCode != DD_OK); - - // memset z-buffer - for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - sScrollXIncrement*2); - - } - for(uiCountY=gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement-1; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); - } - - - StripRegions[ 0 ].right = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); - StripRegions[ 1 ].bottom = (INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); - StripRegions[ 1 ].left = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); - usNumStrips = 2; - - usMouseYPos += sScrollYIncrement; - usMouseXPos += sScrollXIncrement; - - break; - - case SCROLL_UPRIGHT: - - Region.left = sScrollXIncrement; - Region.top = gsVIEWPORT_WINDOW_START_Y; - Region.right = usWidth; - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } - } - } while (ReturnCode != DD_OK); - - // memset z-buffer - for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, - sScrollXIncrement*2); - } - for(uiCountY=gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement-1; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); - } - - - StripRegions[ 0 ].left = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); - StripRegions[ 1 ].bottom = (INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); - StripRegions[ 1 ].right = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); - usNumStrips = 2; - - usMouseYPos += sScrollYIncrement; - usMouseXPos -= sScrollXIncrement; - - break; - - case SCROLL_DOWNLEFT: - - Region.left = 0; - Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; - Region.right = usWidth-(sScrollXIncrement); - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } - } - } while (ReturnCode != DD_OK); - - // memset z-buffer - for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - sScrollXIncrement*2); - - } - for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); } + } while (ReturnCode != DD_OK); - StripRegions[ 0 ].right =(INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + for(uiCountY=sScrollYIncrement-1+gsVIEWPORT_WINDOW_START_Y; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } + //for(uiCountY=usHeight-1; uiCountY >= sScrollYIncrement; uiCountY--) + //{ + // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), + // pSrcBuf+((uiCountY-sScrollYIncrement)*uiDestPitchBYTES), + // uiDestPitchBYTES); + //} + StripRegions[ 0 ].bottom =(INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); + usNumStrips = 1; - StripRegions[ 1 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); - StripRegions[ 1 ].left = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); - usNumStrips = 2; + usMouseYPos += sScrollYIncrement; - usMouseYPos -= sScrollYIncrement; - usMouseXPos += sScrollXIncrement; + break; - break; + case SCROLL_DOWN: - case SCROLL_DOWNRIGHT: + Region.left = 0; + Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; + Region.right = usWidth; + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - Region.left = sScrollXIncrement; - Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; - Region.right = usWidth; - Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; - - do + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - break; - } - } - } while (ReturnCode != DD_OK); - - // memset z-buffer - for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, - sScrollXIncrement*2); - } - for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) - { - memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, - 2280); + break; + } } + } while (ReturnCode != DD_OK); + + // Zero out z + for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement ); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } + + //for(uiCountY=0; uiCountY < (usHeight-sScrollYIncrement); uiCountY++) + //{ + // memcpy(pDestBuf+(uiCountY*uiDestPitchBYTES), + // pSrcBuf+((uiCountY+sScrollYIncrement)*uiDestPitchBYTES), + // uiDestPitchBYTES); + //} + + StripRegions[ 0 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); + usNumStrips = 1; + + usMouseYPos -= sScrollYIncrement; + + break; + + case SCROLL_UPLEFT: + + Region.left = 0; + Region.top = gsVIEWPORT_WINDOW_START_Y; + Region.right = usWidth-(sScrollXIncrement); + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + break; + } + } + } while (ReturnCode != DD_OK); + + // memset z-buffer + for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + sScrollXIncrement*2); + + } + for(uiCountY=gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement-1; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } - StripRegions[ 0 ].left =(INT16)(gsVIEWPORT_END_X-sScrollXIncrement); - StripRegions[ 1 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); - StripRegions[ 1 ].right = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); - usNumStrips = 2; + StripRegions[ 0 ].right = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + StripRegions[ 1 ].bottom = (INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); + StripRegions[ 1 ].left = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + usNumStrips = 2; - usMouseYPos -= sScrollYIncrement; - usMouseXPos -= sScrollXIncrement; + usMouseYPos += sScrollYIncrement; + usMouseXPos += sScrollXIncrement; - break; + break; + + case SCROLL_UPRIGHT: + + Region.left = sScrollXIncrement; + Region.top = gsVIEWPORT_WINDOW_START_Y; + Region.right = usWidth; + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight - sScrollYIncrement; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + break; + } + } + } while (ReturnCode != DD_OK); + + // memset z-buffer + for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, + sScrollXIncrement*2); + } + for(uiCountY=gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement-1; uiCountY >= gsVIEWPORT_WINDOW_START_Y; uiCountY--) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } + + + StripRegions[ 0 ].left = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); + StripRegions[ 1 ].bottom = (INT16)(gsVIEWPORT_WINDOW_START_Y+sScrollYIncrement); + StripRegions[ 1 ].right = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); + usNumStrips = 2; + + usMouseYPos += sScrollYIncrement; + usMouseXPos -= sScrollXIncrement; + + break; + + case SCROLL_DOWNLEFT: + + Region.left = 0; + Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; + Region.right = usWidth-(sScrollXIncrement); + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, sScrollXIncrement, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + break; + } + } + } while (ReturnCode != DD_OK); + + // memset z-buffer + for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + sScrollXIncrement*2); + + } + for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } + + + StripRegions[ 0 ].right =(INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + + + StripRegions[ 1 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); + StripRegions[ 1 ].left = (INT16)(gsVIEWPORT_START_X+sScrollXIncrement); + usNumStrips = 2; + + usMouseYPos -= sScrollYIncrement; + usMouseXPos += sScrollXIncrement; + + break; + + case SCROLL_DOWNRIGHT: + + Region.left = sScrollXIncrement; + Region.top = gsVIEWPORT_WINDOW_START_Y + sScrollYIncrement; + Region.right = usWidth; + Region.bottom = gsVIEWPORT_WINDOW_START_Y + usHeight; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pDest, 0, gsVIEWPORT_WINDOW_START_Y, pSource, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + break; + } + } + } while (ReturnCode != DD_OK); + + // memset z-buffer + for(uiCountY=gsVIEWPORT_WINDOW_START_Y; uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280) + ( ( gsVIEWPORT_END_X - sScrollXIncrement ) * 2 ), 0, + sScrollXIncrement*2); + } + for(uiCountY=(gsVIEWPORT_WINDOW_END_Y - sScrollYIncrement); uiCountY < gsVIEWPORT_WINDOW_END_Y; uiCountY++) + { + memset((UINT8 *)gpZBuffer+(uiCountY*2280), 0, + 2280); + } + + + StripRegions[ 0 ].left =(INT16)(gsVIEWPORT_END_X-sScrollXIncrement); + StripRegions[ 1 ].top = (INT16)(gsVIEWPORT_WINDOW_END_Y-sScrollYIncrement); + StripRegions[ 1 ].right = (INT16)(gsVIEWPORT_END_X-sScrollXIncrement); + usNumStrips = 2; + + usMouseYPos -= sScrollYIncrement; + usMouseXPos -= sScrollXIncrement; + + break; } @@ -1424,7 +1424,7 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr #ifdef SCROLL_TEST { DDBLTFX BlitterFX; - + BlitterFX.dwSize = sizeof( DDBLTFX ); BlitterFX.dwFillColor = 0; @@ -1434,11 +1434,11 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr #if 0 - StripRegions[ 0 ].left = gsVIEWPORT_START_X ; - StripRegions[ 0 ].right = gsVIEWPORT_END_X ; - StripRegions[ 0 ].top = gsVIEWPORT_WINDOW_START_Y ; - StripRegions[ 0 ].bottom = gsVIEWPORT_WINDOW_END_Y ; - usNumStrips = 1; + StripRegions[ 0 ].left = gsVIEWPORT_START_X ; + StripRegions[ 0 ].right = gsVIEWPORT_END_X ; + StripRegions[ 0 ].top = gsVIEWPORT_WINDOW_START_Y ; + StripRegions[ 0 ].bottom = gsVIEWPORT_WINDOW_END_Y ; + usNumStrips = 1; #endif for ( cnt = 0; cnt < usNumStrips; cnt++ ) @@ -1469,53 +1469,53 @@ void ScrollJA2Background(UINT32 uiDirection, INT16 sScrollXIncrement, INT16 sScr switch (uiDirection) { - case SCROLL_LEFT: + case SCROLL_LEFT: - sShiftX = sScrollXIncrement; - sShiftY = 0; - break; + sShiftX = sScrollXIncrement; + sShiftY = 0; + break; - case SCROLL_RIGHT: + case SCROLL_RIGHT: - sShiftX = -sScrollXIncrement; - sShiftY = 0; - break; + sShiftX = -sScrollXIncrement; + sShiftY = 0; + break; - case SCROLL_UP: + case SCROLL_UP: - sShiftX = 0; - sShiftY = sScrollYIncrement; - break; + sShiftX = 0; + sShiftY = sScrollYIncrement; + break; - case SCROLL_DOWN: + case SCROLL_DOWN: - sShiftX = 0; - sShiftY = -sScrollYIncrement; - break; + sShiftX = 0; + sShiftY = -sScrollYIncrement; + break; - case SCROLL_UPLEFT: + case SCROLL_UPLEFT: - sShiftX = sScrollXIncrement; - sShiftY = sScrollYIncrement; - break; + sShiftX = sScrollXIncrement; + sShiftY = sScrollYIncrement; + break; - case SCROLL_UPRIGHT: + case SCROLL_UPRIGHT: - sShiftX = -sScrollXIncrement; - sShiftY = sScrollYIncrement; - break; + sShiftX = -sScrollXIncrement; + sShiftY = sScrollYIncrement; + break; - case SCROLL_DOWNLEFT: + case SCROLL_DOWNLEFT: - sShiftX = sScrollXIncrement; - sShiftY = -sScrollYIncrement; - break; + sShiftX = sScrollXIncrement; + sShiftY = -sScrollYIncrement; + break; - case SCROLL_DOWNRIGHT: + case SCROLL_DOWNRIGHT: - sShiftX = -sScrollXIncrement; - sShiftY = -sScrollYIncrement; - break; + sShiftX = -sScrollXIncrement; + sShiftY = -sScrollYIncrement; + break; } @@ -1574,13 +1574,13 @@ BOOLEAN gfNextRefreshFullScreen = FALSE; void RefreshScreen(void *DummyVariable) { - static UINT32 uiRefreshThreadState, uiIndex; - UINT16 usScreenWidth, usScreenHeight; - static BOOLEAN fShowMouse; - HRESULT ReturnCode; - static RECT Region; - static INT16 sx, sy; - static POINT MousePos; + static UINT32 uiRefreshThreadState, uiIndex; + UINT16 usScreenWidth, usScreenHeight; + static BOOLEAN fShowMouse; + HRESULT ReturnCode; + static RECT Region; + static INT16 sx, sy; + static POINT MousePos; static BOOLEAN fFirstTime = TRUE; UINT32 uiTime; @@ -1603,60 +1603,60 @@ void RefreshScreen(void *DummyVariable) gfNextRefreshFullScreen = FALSE; } - //DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Looping in refresh"); + //DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Looping in refresh"); - /////////////////////////////////////////////////////////////////////////////////////////////// - // - // REFRESH_THREAD_MUTEX - // - /////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////// + // + // REFRESH_THREAD_MUTEX + // + /////////////////////////////////////////////////////////////////////////////////////////////// - switch (guiVideoManagerState) - { - case VIDEO_ON - : // - // Excellent, everything is cosher, we continue on - // - uiRefreshThreadState = guiRefreshThreadState = THREAD_ON; - usScreenWidth = gusScreenWidth; - usScreenHeight = gusScreenHeight; - break; - case VIDEO_OFF - : // - // Hot damn, the video manager is suddenly off. We have to bugger out of here. Don't forget to - // leave the critical section - // - guiRefreshThreadState = THREAD_OFF; - return; - case VIDEO_SUSPENDED - : // - // This are suspended. Make sure the refresh function does try to access any of the direct - // draw surfaces - // - uiRefreshThreadState = guiRefreshThreadState = THREAD_SUSPENDED; - break; - case VIDEO_SHUTTING_DOWN - : // - // Well things are shutting down. So we need to bugger out of there. Don't forget to leave the - // critical section before returning - // - guiRefreshThreadState = THREAD_OFF; - return; - } + switch (guiVideoManagerState) + { + case VIDEO_ON + : // + // Excellent, everything is cosher, we continue on + // + uiRefreshThreadState = guiRefreshThreadState = THREAD_ON; + usScreenWidth = gusScreenWidth; + usScreenHeight = gusScreenHeight; + break; + case VIDEO_OFF + : // + // Hot damn, the video manager is suddenly off. We have to bugger out of here. Don't forget to + // leave the critical section + // + guiRefreshThreadState = THREAD_OFF; + return; + case VIDEO_SUSPENDED + : // + // This are suspended. Make sure the refresh function does try to access any of the direct + // draw surfaces + // + uiRefreshThreadState = guiRefreshThreadState = THREAD_SUSPENDED; + break; + case VIDEO_SHUTTING_DOWN + : // + // Well things are shutting down. So we need to bugger out of there. Don't forget to leave the + // critical section before returning + // + guiRefreshThreadState = THREAD_OFF; + return; + } - // - // Get the current mouse position - // + // + // Get the current mouse position + // - GetCursorPos(&MousePos); - ScreenToClient(ghWindow, &MousePos); // In window coords! + GetCursorPos(&MousePos); + ScreenToClient(ghWindow, &MousePos); // In window coords! - ///////////////////////////////////////////////////////////////////////////////////////////// - // - // FRAME_BUFFER_MUTEX - // - ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + // + // FRAME_BUFFER_MUTEX + // + ///////////////////////////////////////////////////////////////////////////////////////////// // RESTORE OLD POSITION OF MOUSE @@ -1687,13 +1687,13 @@ void RefreshScreen(void *DummyVariable) } - // - // Ok we were able to get a hold of the frame buffer stuff. Check to see if it needs updating - // if not, release the frame buffer stuff right away - // + // + // Ok we were able to get a hold of the frame buffer stuff. Check to see if it needs updating + // if not, release the frame buffer stuff right away + // if (guiFrameBufferState == BUFFER_DIRTY) { - + // Well the frame buffer is dirty. // @@ -1703,7 +1703,7 @@ void RefreshScreen(void *DummyVariable) // Method (3) - We are using a function override to refresh the frame buffer. First we // call the override function then we must set the override pointer to NULL // - + (*gpFrameBufferRefreshOverride)(); gpFrameBufferRefreshOverride = NULL; @@ -1715,15 +1715,15 @@ void RefreshScreen(void *DummyVariable) gFadeFunction( ); } else - // - // Either Method (1) or (2) - // + // + // Either Method (1) or (2) + // { #if 0 if ( gfRenderScroll ) { ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpPrimarySurface, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); -// ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpBackBuffer, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); + // ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpBackBuffer, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); gfForceFullScreenRefresh = TRUE; } #endif @@ -1813,17 +1813,17 @@ void RefreshScreen(void *DummyVariable) } while (ReturnCode != DD_OK); } } - + } if ( gfRenderScroll ) { -// ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpPrimarySurface, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); + // ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpPrimarySurface, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); ScrollJA2Background( guiScrollDirection, gsScrollXIncrement, gsScrollYIncrement, gpBackBuffer, gpBackBuffer, TRUE, PREVIOUS_MOUSE_DATA ); } gfIgnoreScrollDueToCenterAdjust = FALSE; - - + + // @@ -1833,9 +1833,9 @@ void RefreshScreen(void *DummyVariable) guiFrameBufferState = BUFFER_READY; } - // - // Do we want to print the frame stuff ?? - // + // + // Do we want to print the frame stuff ?? + // if( gfVideoCapture ) { @@ -1848,276 +1848,276 @@ void RefreshScreen(void *DummyVariable) } - if (gfPrintFrameBuffer == TRUE) - { - LPDIRECTDRAWSURFACE _pTmpBuffer; - LPDIRECTDRAWSURFACE2 pTmpBuffer; - DDSURFACEDESC SurfaceDescription; - FILE *OutputFile; - CHAR8 FileName[64]; - INT32 iIndex; + if (gfPrintFrameBuffer == TRUE) + { + LPDIRECTDRAWSURFACE _pTmpBuffer; + LPDIRECTDRAWSURFACE2 pTmpBuffer; + DDSURFACEDESC SurfaceDescription; + FILE *OutputFile; + CHAR8 FileName[64]; + INT32 iIndex; STRING512 DataDir; STRING512 ExecDir; - UINT16 *p16BPPData; + UINT16 *p16BPPData; // Snap: save current directory GetFileManCurrentDirectory( DataDir ); GetExecutableDirectory( ExecDir ); SetFileManCurrentDirectory( ExecDir ); - // - // Create temporary system memory surface. This is used to correct problems with the backbuffer - // surface which can be interlaced or have a funky pitch - // + // + // Create temporary system memory surface. This is used to correct problems with the backbuffer + // surface which can be interlaced or have a funky pitch + // - 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, &_pTmpBuffer, NULL ); + 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, &_pTmpBuffer, NULL ); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } - ReturnCode = IDirectDrawSurface_QueryInterface(_pTmpBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&pTmpBuffer); // (jonathanl) + ReturnCode = IDirectDrawSurface_QueryInterface(_pTmpBuffer, /*&*/IID_IDirectDrawSurface2, (LPVOID *)&pTmpBuffer); // (jonathanl) if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } - - // - // Copy the primary surface to the temporary surface - // + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } - Region.left = 0; - Region.top = 0; - Region.right = SCREEN_WIDTH; - Region.bottom = SCREEN_HEIGHT; + // + // Copy the primary surface to the temporary surface + // - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(pTmpBuffer, 0, 0, gpPrimarySurface, &rcWindow, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } - } while (ReturnCode != DD_OK); + Region.left = 0; + Region.top = 0; + Region.right = SCREEN_WIDTH; + Region.bottom = SCREEN_HEIGHT; - // - // Ok now that temp surface has contents of backbuffer, copy temp surface to disk - // - - do - { - sprintf( FileName, "SCREEN%03d.TGA", guiPrintFrameBufferIndex++); - } - while( (_access( FileName, 0 )) != -1 ); - - if ((OutputFile = fopen( FileName, "wb")) != NULL) - { - fprintf(OutputFile, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, LOBYTE(SCREEN_WIDTH), HIBYTE(SCREEN_WIDTH), LOBYTE(SCREEN_HEIGHT), HIBYTE(SCREEN_HEIGHT), 0x10, 0); - - - // - // Lock temp surface - // - - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Lock(pTmpBuffer, NULL, &SurfaceDescription, 0, NULL); + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(pTmpBuffer, 0, 0, gpPrimarySurface, &rcWindow, DDBLTFAST_NOCOLORKEY); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + } while (ReturnCode != DD_OK); - // - // Copy 16 bit buffer to file - // + // + // Ok now that temp surface has contents of backbuffer, copy temp surface to disk + // - // 5/6/5.. create buffer... + do + { + sprintf( FileName, "SCREEN%03d.TGA", guiPrintFrameBufferIndex++); + } + while( (_access( FileName, 0 )) != -1 ); + + if ((OutputFile = fopen( FileName, "wb")) != NULL) + { + fprintf(OutputFile, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, LOBYTE(SCREEN_WIDTH), HIBYTE(SCREEN_WIDTH), LOBYTE(SCREEN_HEIGHT), HIBYTE(SCREEN_HEIGHT), 0x10, 0); + + + // + // Lock temp surface + // + + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Lock(pTmpBuffer, NULL, &SurfaceDescription, 0, NULL); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + + // + // Copy 16 bit buffer to file + // + + // 5/6/5.. create buffer... if (gusRedMask == 0xF800 && gusGreenMask == 0x07E0 && gusBlueMask == 0x001F) - { - p16BPPData = (UINT16 *)MemAlloc( SCREEN_WIDTH * 2 ); - } + { + p16BPPData = (UINT16 *)MemAlloc( SCREEN_WIDTH * 2 ); + } - for (iIndex = SCREEN_HEIGHT - 1; iIndex >= 0; iIndex--) - { - // ATE: OK, fix this such that it converts pixel format to 5/5/5 - // if current settings are 5/6/5.... + for (iIndex = SCREEN_HEIGHT - 1; iIndex >= 0; iIndex--) + { + // ATE: OK, fix this such that it converts pixel format to 5/5/5 + // if current settings are 5/6/5.... if (gusRedMask == 0xF800 && gusGreenMask == 0x07E0 && gusBlueMask == 0x001F) - { - // Read into a buffer... - memcpy( p16BPPData, ( ((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2) ), SCREEN_WIDTH * 2 ); + { + // Read into a buffer... + memcpy( p16BPPData, ( ((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2) ), SCREEN_WIDTH * 2 ); - // Convert.... - ConvertRGBDistribution565To555( p16BPPData, SCREEN_WIDTH ); + // Convert.... + ConvertRGBDistribution565To555( p16BPPData, SCREEN_WIDTH ); - // Write - fwrite( p16BPPData, SCREEN_WIDTH * 2, 1, OutputFile); - } - else - { - fwrite((void *)(((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2)), SCREEN_WIDTH * 2, 1, OutputFile); - } - } + // Write + fwrite( p16BPPData, SCREEN_WIDTH * 2, 1, OutputFile); + } + else + { + fwrite((void *)(((UINT8 *)SurfaceDescription.lpSurface) + (iIndex * SCREEN_WIDTH * 2)), SCREEN_WIDTH * 2, 1, OutputFile); + } + } - // 5/6/5.. Delete buffer... + // 5/6/5.. Delete buffer... if (gusRedMask == 0xF800 && gusGreenMask == 0x07E0 && gusBlueMask == 0x001F) - { - MemFree( p16BPPData ); - } - - fclose(OutputFile); + { + MemFree( p16BPPData ); + } - // - // Unlock temp surface - // + fclose(OutputFile); - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(pTmpBuffer, &SurfaceDescription); + // + // Unlock temp surface + // + + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(pTmpBuffer, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + } - // - // Release temp surface - // + // + // Release temp surface + // - gfPrintFrameBuffer = FALSE; - IDirectDrawSurface2_Release(pTmpBuffer); + gfPrintFrameBuffer = FALSE; + IDirectDrawSurface2_Release(pTmpBuffer); // Snap: Restore the data directory once we are finished. SetFileManCurrentDirectory( DataDir ); //strcat( ExecDir, "\\Data" ); //SetFileManCurrentDirectory( ExecDir ); - } + } - // - // Ok we were able to get a hold of the frame buffer stuff. Check to see if it needs updating - // if not, release the frame buffer stuff right away - // + // + // Ok we were able to get a hold of the frame buffer stuff. Check to see if it needs updating + // if not, release the frame buffer stuff right away + // - if (guiMouseBufferState == BUFFER_DIRTY) - { - // - // Well the mouse buffer is dirty. Upload the whole thing - // + if (guiMouseBufferState == BUFFER_DIRTY) + { + // + // Well the mouse buffer is dirty. Upload the whole thing + // - Region.left = 0; - Region.top = 0; - Region.right = gusMouseCursorWidth; - Region.bottom = gusMouseCursorHeight; + Region.left = 0; + Region.top = 0; + Region.right = gusMouseCursorWidth; + Region.bottom = gusMouseCursorHeight; - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpMouseCursor, 0, 0, gpMouseCursorOriginal, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } - } while (ReturnCode != DD_OK); + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpMouseCursor, 0, 0, gpMouseCursorOriginal, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + } while (ReturnCode != DD_OK); - guiMouseBufferState = BUFFER_READY; - } - - // - // Check current state of the mouse cursor - // + guiMouseBufferState = BUFFER_READY; + } - if (fShowMouse == FALSE) - { - if (guiMouseBufferState == BUFFER_READY) - { - fShowMouse = TRUE; - } - else - { - fShowMouse = FALSE; - } - } - else - { - if (guiMouseBufferState == BUFFER_DISABLED) - { - fShowMouse = FALSE; - } - } + // + // Check current state of the mouse cursor + // - /////////////////////////////////////////////////////////////////////////////////////////////// - // - // End of MOUSE_BUFFER_MUTEX - // - /////////////////////////////////////////////////////////////////////////////////////////////// + if (fShowMouse == FALSE) + { + if (guiMouseBufferState == BUFFER_READY) + { + fShowMouse = TRUE; + } + else + { + fShowMouse = FALSE; + } + } + else + { + if (guiMouseBufferState == BUFFER_DISABLED) + { + fShowMouse = FALSE; + } + } + + /////////////////////////////////////////////////////////////////////////////////////////////// + // + // End of MOUSE_BUFFER_MUTEX + // + /////////////////////////////////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////////////////////////////////// - // - // If fMouseState == TRUE - // - // (1) Save mouse background from gpBackBuffer to gpMouseCursorBackground - // (2) If step (1) is successfull blit mouse cursor onto gpBackBuffer - // - /////////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////////// + // + // If fMouseState == TRUE + // + // (1) Save mouse background from gpBackBuffer to gpMouseCursorBackground + // (2) If step (1) is successfull blit mouse cursor onto gpBackBuffer + // + /////////////////////////////////////////////////////////////////////////////////////////////// - if (fShowMouse == TRUE ) - { - // - // Step (1) - Save mouse background - // + if (fShowMouse == TRUE ) + { + // + // Step (1) - Save mouse background + // - Region.left = MousePos.x - gsMouseCursorXOffset; - Region.top = MousePos.y - gsMouseCursorYOffset; - Region.right = Region.left + gusMouseCursorWidth; - Region.bottom = Region.top + gusMouseCursorHeight; + Region.left = MousePos.x - gsMouseCursorXOffset; + Region.top = MousePos.y - gsMouseCursorYOffset; + Region.right = Region.left + gusMouseCursorWidth; + Region.bottom = Region.top + gusMouseCursorHeight; - if (Region.right > usScreenWidth) - { - Region.right = usScreenWidth; - } + if (Region.right > usScreenWidth) + { + Region.right = usScreenWidth; + } - if (Region.bottom > usScreenHeight) - { - Region.bottom = usScreenHeight; - } + if (Region.bottom > usScreenHeight) + { + Region.bottom = usScreenHeight; + } - if ((Region.right > Region.left)&&(Region.bottom > Region.top)) - { - // - // Make sure the mouse background is marked for restore and coordinates are saved for the - // future restore - // + if ((Region.right > Region.left)&&(Region.bottom > Region.top)) + { + // + // Make sure the mouse background is marked for restore and coordinates are saved for the + // future restore + // - gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = TRUE; - gMouseCursorBackground[CURRENT_MOUSE_DATA].usRight = (INT16)Region.right - (INT16) Region.left; - gMouseCursorBackground[CURRENT_MOUSE_DATA].usBottom = (INT16)Region.bottom - (INT16) Region.top; - if (Region.left < 0) - { - gMouseCursorBackground[CURRENT_MOUSE_DATA].usLeft = (INT16) (0 - Region.left); - gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos = 0; - Region.left = 0; - } - else - { - gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos = (UINT16) MousePos.x - gsMouseCursorXOffset; - gMouseCursorBackground[CURRENT_MOUSE_DATA].usLeft = 0; - } - if (Region.top < 0) - { - gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos = 0; - gMouseCursorBackground[CURRENT_MOUSE_DATA].usTop = (UINT16) (0 - Region.top); - Region.top = 0; - } - else - { - gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos = (UINT16) MousePos.y - gsMouseCursorYOffset; - gMouseCursorBackground[CURRENT_MOUSE_DATA].usTop = 0; - } + gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = TRUE; + gMouseCursorBackground[CURRENT_MOUSE_DATA].usRight = (INT16)Region.right - (INT16) Region.left; + gMouseCursorBackground[CURRENT_MOUSE_DATA].usBottom = (INT16)Region.bottom - (INT16) Region.top; + if (Region.left < 0) + { + gMouseCursorBackground[CURRENT_MOUSE_DATA].usLeft = (INT16) (0 - Region.left); + gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos = 0; + Region.left = 0; + } + else + { + gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos = (UINT16) MousePos.x - gsMouseCursorXOffset; + gMouseCursorBackground[CURRENT_MOUSE_DATA].usLeft = 0; + } + if (Region.top < 0) + { + gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos = 0; + gMouseCursorBackground[CURRENT_MOUSE_DATA].usTop = (UINT16) (0 - Region.top); + Region.top = 0; + } + else + { + gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos = (UINT16) MousePos.y - gsMouseCursorYOffset; + gMouseCursorBackground[CURRENT_MOUSE_DATA].usTop = 0; + } if ((Region.right > Region.left)&&(Region.bottom > Region.top)) { @@ -2158,7 +2158,7 @@ void RefreshScreen(void *DummyVariable) { DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); } - + if (ReturnCode == DDERR_SURFACELOST) { goto ENDOFLOOP; @@ -2167,286 +2167,286 @@ void RefreshScreen(void *DummyVariable) } else { - // + // // Hum, the mouse was not blitted this round. Henceforth we will flag fRestore as FALSE // gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = FALSE; } - } - else - { - // - // Hum, the mouse was not blitted this round. Henceforth we will flag fRestore as FALSE - // - - gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = FALSE; - - } - } - else - { - // - // Well since there was no mouse handling this round, we disable the mouse restore - // - - gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = FALSE; - - } - - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // Rain // - /////////////////////////////////////////////////////////////////////////////////////////////// - - if( IsItAllowedToRenderRain() && gfProgramIsRunning ) - { - BltVideoSurface( BACKBUFFER, guiRainRenderSurface, 0, 0, 0, VS_BLT_FAST | VS_BLT_USECOLORKEY, NULL ); - gfNextRefreshFullScreen = TRUE; - } - - - - /////////////////////////////////////////////////////////////////////////////////////////////// - // - // (1) Flip Pages - // (2) If the page flipping worked, then we copy the contents of the primary surface back - // to the backbuffer - // (3) If step (2) was successfull we then restore the mouse background onto the backbuffer - // if fShowMouse is TRUE - // - /////////////////////////////////////////////////////////////////////////////////////////////// - - // - // Step (1) - Flip pages - // - Region.top = 0; - Region.left = 0; - Region.right = rcWindow.right - rcWindow.left; - Region.bottom = rcWindow.bottom - rcWindow.top; - if( 1==iScreenMode ) /* Windowed mode */ - { - do - { - 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)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - } - } while (ReturnCode != DD_OK); - - gfRenderScroll = FALSE; - gfScrollStart = FALSE; - guiDirtyRegionCount = 0; - guiDirtyRegionExCount = 0; - gfForceFullScreenRefresh = FALSE; - } - else - { - do - { - ReturnCode = IDirectDrawSurface_Flip( - _gpPrimarySurface, - NULL, - gGameExternalOptions.gfVSync ? DDFLIP_WAIT : 0x00000008l - ); - - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - } - } while (ReturnCode != DD_OK); - - // - // Step (2) - Copy Primary Surface to the Back Buffer - // - - if ( gfRenderScroll ) - { - Region.left = 0; - Region.top = 0; - Region.right = gsVIEWPORT_END_X; //ods1 640; - Region.bottom = gsVIEWPORT_END_Y; - - do + } + else { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, 0, 0, gpPrimarySurface, &Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + // + // Hum, the mouse was not blitted this round. Henceforth we will flag fRestore as FALSE + // - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - - } - } while (ReturnCode != DD_OK); - - //Get new background for mouse - // - // Ok, do the actual data save to the mouse background - - // - - - gfRenderScroll = FALSE; - gfScrollStart = FALSE; - - } - - - // COPY MOUSE AREAS FROM PRIMARY BACK! - - // FIRST OLD ERASED POSITION - if (gMouseCursorBackground[PREVIOUS_MOUSE_DATA].fRestore == TRUE ) - { - Region = gMouseCursorBackground[PREVIOUS_MOUSE_DATA].Region; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gMouseCursorBackground[PREVIOUS_MOUSE_DATA].usMouseXPos, gMouseCursorBackground[PREVIOUS_MOUSE_DATA].usMouseYPos, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if (ReturnCode != DD_OK && ReturnCode != DDERR_WASSTILLDRAWING ) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - } - } while (ReturnCode != DD_OK); - } - - // NOW NEW MOUSE AREA - if (gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore == TRUE ) - { - Region = gMouseCursorBackground[CURRENT_MOUSE_DATA].Region; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos, gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } - } - } while (ReturnCode != DD_OK); - } - - if (gfForceFullScreenRefresh == TRUE) - { - // - // Method (1) - We will be refreshing the entire screen - // - Region.left = 0; - Region.top = 0; - Region.right = SCREEN_WIDTH; - Region.bottom = SCREEN_HEIGHT; - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, 0, 0, gpPrimarySurface, &Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } + gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = FALSE; } - } while (ReturnCode != DD_OK); - - guiDirtyRegionCount = 0; - guiDirtyRegionExCount = 0; - gfForceFullScreenRefresh = FALSE; } else { - for (uiIndex = 0; uiIndex < guiDirtyRegionCount; uiIndex++) - { - Region.left = gListOfDirtyRegions[uiIndex].iLeft; - Region.top = gListOfDirtyRegions[uiIndex].iTop; - Region.right = gListOfDirtyRegions[uiIndex].iRight; - Region.bottom = gListOfDirtyRegions[uiIndex].iBottom; + // + // Well since there was no mouse handling this round, we disable the mouse restore + // + gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore = FALSE; + + } + + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // Rain // + /////////////////////////////////////////////////////////////////////////////////////////////// + + if( IsItAllowedToRenderRain() && gfProgramIsRunning ) + { + BltVideoSurface( BACKBUFFER, guiRainRenderSurface, 0, 0, 0, VS_BLT_FAST | VS_BLT_USECOLORKEY, NULL ); + gfNextRefreshFullScreen = TRUE; + } + + + + /////////////////////////////////////////////////////////////////////////////////////////////// + // + // (1) Flip Pages + // (2) If the page flipping worked, then we copy the contents of the primary surface back + // to the backbuffer + // (3) If step (2) was successfull we then restore the mouse background onto the backbuffer + // if fShowMouse is TRUE + // + /////////////////////////////////////////////////////////////////////////////////////////////// + + // + // Step (1) - Flip pages + // + Region.top = 0; + Region.left = 0; + Region.right = rcWindow.right - rcWindow.left; + Region.bottom = rcWindow.bottom - rcWindow.top; + if( 1==iScreenMode ) /* Windowed mode */ + { do { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gListOfDirtyRegions[uiIndex].iLeft, gListOfDirtyRegions[uiIndex].iTop, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + 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)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - if (ReturnCode == DDERR_SURFACELOST) - { - goto ENDOFLOOP; - } + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } } while (ReturnCode != DD_OK); - } - - guiDirtyRegionCount = 0; - gfForceFullScreenRefresh = FALSE; + gfRenderScroll = FALSE; + gfScrollStart = FALSE; + guiDirtyRegionCount = 0; + guiDirtyRegionExCount = 0; + gfForceFullScreenRefresh = FALSE; } - - // Do extended dirty regions! - for (uiIndex = 0; uiIndex < guiDirtyRegionExCount; uiIndex++) + else { - Region.left = gDirtyRegionsEx[uiIndex].iLeft; - Region.top = gDirtyRegionsEx[uiIndex].iTop; - Region.right = gDirtyRegionsEx[uiIndex].iRight; - Region.bottom = gDirtyRegionsEx[uiIndex].iBottom; - - if ( ( Region.top < gsVIEWPORT_WINDOW_END_Y ) && gfRenderScroll ) - { - continue; - } - - do - { - ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gDirtyRegionsEx[uiIndex].iLeft, gDirtyRegionsEx[uiIndex].iTop, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + do { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + ReturnCode = IDirectDrawSurface_Flip( + _gpPrimarySurface, + NULL, + gGameExternalOptions.gfVSync ? DDFLIP_WAIT : 0x00000008l + ); + + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } + } while (ReturnCode != DD_OK); + + // + // Step (2) - Copy Primary Surface to the Back Buffer + // + + if ( gfRenderScroll ) + { + Region.left = 0; + Region.top = 0; + Region.right = gsVIEWPORT_END_X; //ods1 640; + Region.bottom = gsVIEWPORT_END_Y; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, 0, 0, gpPrimarySurface, &Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + + } + } while (ReturnCode != DD_OK); + + //Get new background for mouse + // + // Ok, do the actual data save to the mouse background + + // + + + gfRenderScroll = FALSE; + gfScrollStart = FALSE; + } - if (ReturnCode == DDERR_SURFACELOST) + + // COPY MOUSE AREAS FROM PRIMARY BACK! + + // FIRST OLD ERASED POSITION + if (gMouseCursorBackground[PREVIOUS_MOUSE_DATA].fRestore == TRUE ) { - goto ENDOFLOOP; + Region = gMouseCursorBackground[PREVIOUS_MOUSE_DATA].Region; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gMouseCursorBackground[PREVIOUS_MOUSE_DATA].usMouseXPos, gMouseCursorBackground[PREVIOUS_MOUSE_DATA].usMouseYPos, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if (ReturnCode != DD_OK && ReturnCode != DDERR_WASSTILLDRAWING ) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } + } while (ReturnCode != DD_OK); + } + + // NOW NEW MOUSE AREA + if (gMouseCursorBackground[CURRENT_MOUSE_DATA].fRestore == TRUE ) + { + Region = gMouseCursorBackground[CURRENT_MOUSE_DATA].Region; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseXPos, gMouseCursorBackground[CURRENT_MOUSE_DATA].usMouseYPos, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } + } while (ReturnCode != DD_OK); + } + + if (gfForceFullScreenRefresh == TRUE) + { + // + // Method (1) - We will be refreshing the entire screen + // + Region.left = 0; + Region.top = 0; + Region.right = SCREEN_WIDTH; + Region.bottom = SCREEN_HEIGHT; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, 0, 0, gpPrimarySurface, &Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + + } + } while (ReturnCode != DD_OK); + + guiDirtyRegionCount = 0; + guiDirtyRegionExCount = 0; + gfForceFullScreenRefresh = FALSE; + } + else + { + for (uiIndex = 0; uiIndex < guiDirtyRegionCount; uiIndex++) + { + Region.left = gListOfDirtyRegions[uiIndex].iLeft; + Region.top = gListOfDirtyRegions[uiIndex].iTop; + Region.right = gListOfDirtyRegions[uiIndex].iRight; + Region.bottom = gListOfDirtyRegions[uiIndex].iBottom; + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gListOfDirtyRegions[uiIndex].iLeft, gListOfDirtyRegions[uiIndex].iTop, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } while (ReturnCode != DD_OK); + } + + guiDirtyRegionCount = 0; + gfForceFullScreenRefresh = FALSE; + + } + + // Do extended dirty regions! + for (uiIndex = 0; uiIndex < guiDirtyRegionExCount; uiIndex++) + { + Region.left = gDirtyRegionsEx[uiIndex].iLeft; + Region.top = gDirtyRegionsEx[uiIndex].iTop; + Region.right = gDirtyRegionsEx[uiIndex].iRight; + Region.bottom = gDirtyRegionsEx[uiIndex].iBottom; + + if ( ( Region.top < gsVIEWPORT_WINDOW_END_Y ) && gfRenderScroll ) + { + continue; + } + + do + { + ReturnCode = IDirectDrawSurface2_SGPBltFast(gpBackBuffer, gDirtyRegionsEx[uiIndex].iLeft, gDirtyRegionsEx[uiIndex].iTop, gpPrimarySurface, (LPRECT)&Region, DDBLTFAST_NOCOLORKEY); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } + + if (ReturnCode == DDERR_SURFACELOST) + { + goto ENDOFLOOP; + } + } while (ReturnCode != DD_OK); } - } while (ReturnCode != DD_OK); } - } - guiDirtyRegionExCount = 0; + guiDirtyRegionExCount = 0; ENDOFLOOP: - + fFirstTime = FALSE; @@ -2466,7 +2466,7 @@ LPDIRECTDRAW2 GetDirectDraw2Object(void) } /////////////////////////////////////////////////////////////////////////////////////////////////// - + LPDIRECTDRAWSURFACE2 GetPrimarySurfaceObject(void) { Assert( gpPrimarySurface != NULL ); @@ -2510,185 +2510,185 @@ LPDIRECTDRAWSURFACE2 GetMouseBufferObject(void) PTR LockPrimarySurface(UINT32 *uiPitch) { - HRESULT ReturnCode; - DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; - ZEROMEM(SurfaceDescription); + ZEROMEM(SurfaceDescription); SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - do - { - ReturnCode = IDirectDrawSurface2_Lock(gpPrimarySurface, NULL, &SurfaceDescription, 0, NULL); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return NULL; - } + do + { + ReturnCode = IDirectDrawSurface2_Lock(gpPrimarySurface, NULL, &SurfaceDescription, 0, NULL); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return NULL; + } - } while (ReturnCode != DD_OK); + } while (ReturnCode != DD_OK); - *uiPitch = SurfaceDescription.lPitch; - return SurfaceDescription.lpSurface; + *uiPitch = SurfaceDescription.lPitch; + return SurfaceDescription.lpSurface; } /////////////////////////////////////////////////////////////////////////////////////////////////// void UnlockPrimarySurface(void) { - DDSURFACEDESC SurfaceDescription; - HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(gpPrimarySurface, &SurfaceDescription); + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(gpPrimarySurface, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// PTR LockBackBuffer(UINT32 *uiPitch) { - HRESULT ReturnCode; - DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - ZEROMEM(SurfaceDescription); + ZEROMEM(SurfaceDescription); SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - do - { - ReturnCode = IDirectDrawSurface2_Lock(gpBackBuffer, NULL, &SurfaceDescription, 0, NULL); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return NULL; - } + do + { + ReturnCode = IDirectDrawSurface2_Lock(gpBackBuffer, NULL, &SurfaceDescription, 0, NULL); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return NULL; + } - } while (ReturnCode != DD_OK); + } while (ReturnCode != DD_OK); - *uiPitch = SurfaceDescription.lPitch; - return SurfaceDescription.lpSurface; + *uiPitch = SurfaceDescription.lPitch; + return SurfaceDescription.lpSurface; } /////////////////////////////////////////////////////////////////////////////////////////////////// void UnlockBackBuffer(void) { - DDSURFACEDESC SurfaceDescription; - HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; - // - // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- - // - // This function is intended to be called by a thread which has already locked the - // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to - // yack - // + // + // W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- W A R N I N G ---- + // + // This function is intended to be called by a thread which has already locked the + // FRAME_BUFFER_MUTEX mutual exclusion section. Anything else will cause the application to + // yack + // - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(gpBackBuffer, &SurfaceDescription); + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(gpBackBuffer, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// PTR LockFrameBuffer(UINT32 *uiPitch) { - HRESULT ReturnCode; - DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; - ZEROMEM(SurfaceDescription); + ZEROMEM(SurfaceDescription); SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - do - { - ReturnCode = IDirectDrawSurface2_Lock(gpFrameBuffer, NULL, &SurfaceDescription, 0, NULL); - if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return NULL; - } + do + { + ReturnCode = IDirectDrawSurface2_Lock(gpFrameBuffer, NULL, &SurfaceDescription, 0, NULL); + if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to lock backbuffer"); + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return NULL; + } - } while (ReturnCode != DD_OK); + } while (ReturnCode != DD_OK); - *uiPitch = SurfaceDescription.lPitch; + *uiPitch = SurfaceDescription.lPitch; - return SurfaceDescription.lpSurface; + return SurfaceDescription.lpSurface; } /////////////////////////////////////////////////////////////////////////////////////////////////// void UnlockFrameBuffer(void) { - DDSURFACEDESC SurfaceDescription; - HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(gpFrameBuffer, &SurfaceDescription); + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(gpFrameBuffer, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// PTR LockMouseBuffer(UINT32 *uiPitch) { - HRESULT ReturnCode; - DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; - ZEROMEM(SurfaceDescription); + ZEROMEM(SurfaceDescription); SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Lock(gpMouseCursorOriginal, NULL, &SurfaceDescription, 0, NULL); + ReturnCode = IDirectDrawSurface2_Lock(gpMouseCursorOriginal, NULL, &SurfaceDescription, 0, NULL); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return NULL; - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return NULL; + } - *uiPitch = SurfaceDescription.lPitch; - - return SurfaceDescription.lpSurface; + *uiPitch = SurfaceDescription.lPitch; + + return SurfaceDescription.lpSurface; } /////////////////////////////////////////////////////////////////////////////////////////////////// void UnlockMouseBuffer(void) { - DDSURFACEDESC SurfaceDescription; - HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; + HRESULT ReturnCode; - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(gpMouseCursorOriginal, &SurfaceDescription); + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(gpMouseCursorOriginal, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2699,11 +2699,11 @@ void UnlockMouseBuffer(void) BOOLEAN GetRGBDistribution(void) { -DDSURFACEDESC SurfaceDescription; -UINT16 usBit; -HRESULT ReturnCode; + DDSURFACEDESC SurfaceDescription; + UINT16 usBit; + HRESULT ReturnCode; - Assert ( gpPrimarySurface != NULL ); + Assert ( gpPrimarySurface != NULL ); // ONLY DO IF WE ARE IN 16BIT MODE if ( gbPixelDepth == 8 ) @@ -2711,19 +2711,19 @@ HRESULT ReturnCode; return( TRUE ); } - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof (DDSURFACEDESC); - SurfaceDescription.dwFlags = DDSD_PIXELFORMAT; - ReturnCode = IDirectDrawSurface2_GetSurfaceDesc ( gpPrimarySurface, &SurfaceDescription ); - if (ReturnCode != DD_OK) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - return FALSE; - } - - // - // Ok we now have the surface description, we now can get the information that we need - // + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof (DDSURFACEDESC); + SurfaceDescription.dwFlags = DDSD_PIXELFORMAT; + ReturnCode = IDirectDrawSurface2_GetSurfaceDesc ( gpPrimarySurface, &SurfaceDescription ); + if (ReturnCode != DD_OK) + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + return FALSE; + } + + // + // Ok we now have the surface description, we now can get the information that we need + // gusRedMask = (UINT16) SurfaceDescription.ddpfPixelFormat.dwRBitMask; gusGreenMask = (UINT16) SurfaceDescription.ddpfPixelFormat.dwGBitMask; @@ -2744,31 +2744,31 @@ HRESULT ReturnCode; guiTranslucentMask=0x7bef; - usBit = 0x8000; - gusRedShift = 8; + usBit = 0x8000; + gusRedShift = 8; while(!(gusRedMask & usBit)) { usBit >>= 1; gusRedShift--; } - usBit = 0x8000; - gusGreenShift = 8; + usBit = 0x8000; + gusGreenShift = 8; while(!(gusGreenMask & usBit)) { usBit >>= 1; gusGreenShift--; } - usBit = 0x8000; - gusBlueShift = 8; + usBit = 0x8000; + gusBlueShift = 8; while(!(gusBlueMask & usBit)) { usBit >>= 1; gusBlueShift--; } - return TRUE; + return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2786,58 +2786,58 @@ BOOLEAN GetPrimaryRGBDistributionMasks(UINT32 *RedBitMask, UINT32 *GreenBitMask, BOOLEAN SetMouseCursorFromObject(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY ) { - BOOLEAN ReturnValue; - PTR pTmpPointer; - UINT32 uiPitch; - ETRLEObject pETRLEPointer; + BOOLEAN ReturnValue; + PTR pTmpPointer; + UINT32 uiPitch; + ETRLEObject pETRLEPointer; - // - // Erase cursor background - // + // + // Erase cursor background + // - pTmpPointer = LockMouseBuffer(&uiPitch); - memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); - UnlockMouseBuffer(); + pTmpPointer = LockMouseBuffer(&uiPitch); + memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); + UnlockMouseBuffer(); - // - // Get new cursor data - // + // + // Get new cursor data + // - ReturnValue = BltVideoObjectFromIndex(MOUSE_BUFFER, uiVideoObjectHandle, usVideoObjectSubIndex, 0, 0, VO_BLT_SRCTRANSPARENCY, NULL); - guiMouseBufferState = BUFFER_DIRTY; + ReturnValue = BltVideoObjectFromIndex(MOUSE_BUFFER, uiVideoObjectHandle, usVideoObjectSubIndex, 0, 0, VO_BLT_SRCTRANSPARENCY, NULL); + guiMouseBufferState = BUFFER_DIRTY; - if (GetVideoObjectETRLEPropertiesFromIndex(uiVideoObjectHandle, &pETRLEPointer, usVideoObjectSubIndex)) - { - gsMouseCursorXOffset = usOffsetX; - gsMouseCursorYOffset = usOffsetY; - gusMouseCursorWidth = pETRLEPointer.usWidth + pETRLEPointer.sOffsetX; - gusMouseCursorHeight = pETRLEPointer.usHeight + pETRLEPointer.sOffsetY; + if (GetVideoObjectETRLEPropertiesFromIndex(uiVideoObjectHandle, &pETRLEPointer, usVideoObjectSubIndex)) + { + gsMouseCursorXOffset = usOffsetX; + gsMouseCursorYOffset = usOffsetY; + gusMouseCursorWidth = pETRLEPointer.usWidth + pETRLEPointer.sOffsetX; + gusMouseCursorHeight = pETRLEPointer.usHeight + pETRLEPointer.sOffsetY; - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Mouse Create with [ %d. %d ] [ %d, %d]", pETRLEPointer.sOffsetX, pETRLEPointer.sOffsetY, pETRLEPointer.usWidth, pETRLEPointer.usHeight)); - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Mouse Create with [ %d. %d ] [ %d, %d]", pETRLEPointer.sOffsetX, pETRLEPointer.sOffsetY, pETRLEPointer.usWidth, pETRLEPointer.usHeight)); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); - } - else - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to get mouse info"); - } + } + else + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to get mouse info"); + } - return ReturnValue; + return ReturnValue; } BOOLEAN EraseMouseCursor( ) { - PTR pTmpPointer; - UINT32 uiPitch; + PTR pTmpPointer; + UINT32 uiPitch; - // - // Erase cursor background - // + // + // Erase cursor background + // - pTmpPointer = LockMouseBuffer(&uiPitch); - memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); - UnlockMouseBuffer(); + pTmpPointer = LockMouseBuffer(&uiPitch); + memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); + UnlockMouseBuffer(); // Don't set dirty return( TRUE ); @@ -2845,25 +2845,25 @@ BOOLEAN EraseMouseCursor( ) BOOLEAN SetMouseCursorProperties( INT16 sOffsetX, INT16 sOffsetY, UINT16 usCursorHeight, UINT16 usCursorWidth ) { - gsMouseCursorXOffset = sOffsetX; - gsMouseCursorYOffset = sOffsetY; - gusMouseCursorWidth = usCursorWidth; - gusMouseCursorHeight = usCursorHeight; + gsMouseCursorXOffset = sOffsetX; + gsMouseCursorYOffset = sOffsetY; + gusMouseCursorWidth = usCursorWidth; + gusMouseCursorHeight = usCursorHeight; return( TRUE ); } BOOLEAN BltToMouseCursor(UINT32 uiVideoObjectHandle, UINT16 usVideoObjectSubIndex, UINT16 usXPos, UINT16 usYPos ) { - BOOLEAN ReturnValue; + BOOLEAN ReturnValue; - ReturnValue = BltVideoObjectFromIndex(MOUSE_BUFFER, uiVideoObjectHandle, usVideoObjectSubIndex, usXPos, usYPos, VO_BLT_SRCTRANSPARENCY, NULL); + ReturnValue = BltVideoObjectFromIndex(MOUSE_BUFFER, uiVideoObjectHandle, usVideoObjectSubIndex, usXPos, usYPos, VO_BLT_SRCTRANSPARENCY, NULL); - return ReturnValue; + return ReturnValue; } void DirtyCursor( ) { - guiMouseBufferState = BUFFER_DIRTY; + guiMouseBufferState = BUFFER_DIRTY; } void EnableCursor( BOOLEAN fEnable ) @@ -2882,101 +2882,101 @@ void EnableCursor( BOOLEAN fEnable ) BOOLEAN HideMouseCursor(void) { - guiMouseBufferState = BUFFER_DISABLED; + guiMouseBufferState = BUFFER_DISABLED; - return TRUE; + return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN LoadCursorFile(STR8 pFilename) { - VOBJECT_DESC VideoObjectDescription; + VOBJECT_DESC VideoObjectDescription; - // - // Make sure the old cursor store is destroyed - // + // + // Make sure the old cursor store is destroyed + // - if (gpCursorStore != NULL) - { - DeleteVideoObject(gpCursorStore); - gpCursorStore = NULL; - } + if (gpCursorStore != NULL) + { + DeleteVideoObject(gpCursorStore); + gpCursorStore = NULL; + } - // - // Get the source file with all the cursors inside - // + // + // Get the source file with all the cursors inside + // - VideoObjectDescription.fCreateFlags = VOBJECT_CREATE_FROMFILE; + VideoObjectDescription.fCreateFlags = VOBJECT_CREATE_FROMFILE; strcpy(VideoObjectDescription.ImageFile, pFilename); - gpCursorStore = CreateVideoObject(&VideoObjectDescription); + gpCursorStore = CreateVideoObject(&VideoObjectDescription); - // - // Were we successful in creating the cursor store ? - // + // + // Were we successful in creating the cursor store ? + // - if (gpCursorStore == NULL) - { - return FALSE; - } + if (gpCursorStore == NULL) + { + return FALSE; + } - return TRUE; + return TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN SetCurrentCursor(UINT16 usVideoObjectSubIndex, UINT16 usOffsetX, UINT16 usOffsetY ) { - BOOLEAN ReturnValue; - PTR pTmpPointer; - UINT32 uiPitch; - ETRLEObject pETRLEPointer; + BOOLEAN ReturnValue; + PTR pTmpPointer; + UINT32 uiPitch; + ETRLEObject pETRLEPointer; - // - // Make sure we have a cursor store - // + // + // Make sure we have a cursor store + // - if (gpCursorStore == NULL) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "ERROR : Cursor store is not loaded"); - return FALSE; - } + if (gpCursorStore == NULL) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "ERROR : Cursor store is not loaded"); + return FALSE; + } - // - // Ok, then blit the mouse cursor to the MOUSE_BUFFER (which is really gpMouseBufferOriginal) - // - // - // Erase cursor background - // + // + // Ok, then blit the mouse cursor to the MOUSE_BUFFER (which is really gpMouseBufferOriginal) + // + // + // Erase cursor background + // - pTmpPointer = LockMouseBuffer(&uiPitch); - memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); - UnlockMouseBuffer(); + pTmpPointer = LockMouseBuffer(&uiPitch); + memset(pTmpPointer, 0, MAX_CURSOR_HEIGHT * uiPitch); + UnlockMouseBuffer(); - // - // Get new cursor data - // + // + // Get new cursor data + // - ReturnValue = BltVideoObject(MOUSE_BUFFER, gpCursorStore, usVideoObjectSubIndex, 0, 0, VO_BLT_SRCTRANSPARENCY, NULL); - guiMouseBufferState = BUFFER_DIRTY; + ReturnValue = BltVideoObject(MOUSE_BUFFER, gpCursorStore, usVideoObjectSubIndex, 0, 0, VO_BLT_SRCTRANSPARENCY, NULL); + guiMouseBufferState = BUFFER_DIRTY; - if (GetVideoObjectETRLEProperties(gpCursorStore, &pETRLEPointer, usVideoObjectSubIndex)) - { - gsMouseCursorXOffset = usOffsetX; - gsMouseCursorYOffset = usOffsetY; - gusMouseCursorWidth = pETRLEPointer.usWidth + pETRLEPointer.sOffsetX; - gusMouseCursorHeight = pETRLEPointer.usHeight + pETRLEPointer.sOffsetY; + if (GetVideoObjectETRLEProperties(gpCursorStore, &pETRLEPointer, usVideoObjectSubIndex)) + { + gsMouseCursorXOffset = usOffsetX; + gsMouseCursorYOffset = usOffsetY; + gusMouseCursorWidth = pETRLEPointer.usWidth + pETRLEPointer.sOffsetX; + gusMouseCursorHeight = pETRLEPointer.usHeight + pETRLEPointer.sOffsetY; - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Mouse Create with [ %d. %d ] [ %d, %d]", pETRLEPointer.sOffsetX, pETRLEPointer.sOffsetY, pETRLEPointer.usWidth, pETRLEPointer.usHeight)); - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); - } - else - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to get mouse info"); - } + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Mouse Create with [ %d. %d ] [ %d, %d]", pETRLEPointer.sOffsetX, pETRLEPointer.sOffsetY, pETRLEPointer.usWidth, pETRLEPointer.usHeight)); + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "================================================="); + } + else + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, "Failed to get mouse info"); + } - return ReturnValue; + return ReturnValue; } /////////////////////////////////////////////////////////////////////////////////////////////////// @@ -2991,7 +2991,7 @@ void StartFrameBufferRender(void) void EndFrameBufferRender(void) { - guiFrameBufferState = BUFFER_DIRTY; + guiFrameBufferState = BUFFER_DIRTY; return; @@ -3001,44 +3001,44 @@ void EndFrameBufferRender(void) void PrintScreen(void) { - gfPrintFrameBuffer = TRUE; + gfPrintFrameBuffer = TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////// BOOLEAN Set8BPPPalette(SGPPaletteEntry *pPalette) { -HRESULT ReturnCode; + HRESULT ReturnCode; - // If we are in 256 colors, then we have to initialize the palette system to 0 (faded out) - memcpy(gSgpPalette, pPalette, sizeof(SGPPaletteEntry)*256); + // If we are in 256 colors, then we have to initialize the palette system to 0 (faded out) + memcpy(gSgpPalette, pPalette, sizeof(SGPPaletteEntry)*256); + + ReturnCode = IDirectDraw_CreatePalette(gpDirectDrawObject, (DDPCAPS_8BIT | DDPCAPS_ALLOW256), (LPPALETTEENTRY)(&gSgpPalette[0]), &gpDirectDrawPalette, NULL); + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to create palette (Rc = %d)", ReturnCode)); + return(FALSE); + } + // Apply the palette to the surfaces + ReturnCode = IDirectDrawSurface_SetPalette(gpPrimarySurface, gpDirectDrawPalette); + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to primary surface")); + return(FALSE); + } - ReturnCode = IDirectDraw_CreatePalette(gpDirectDrawObject, (DDPCAPS_8BIT | DDPCAPS_ALLOW256), (LPPALETTEENTRY)(&gSgpPalette[0]), &gpDirectDrawPalette, NULL); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to create palette (Rc = %d)", ReturnCode)); - return(FALSE); - } - // Apply the palette to the surfaces - ReturnCode = IDirectDrawSurface_SetPalette(gpPrimarySurface, gpDirectDrawPalette); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to primary surface")); - return(FALSE); - } - ReturnCode = IDirectDrawSurface_SetPalette(gpBackBuffer, gpDirectDrawPalette); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to back buffer")); - return(FALSE); - } - + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to back buffer")); + return(FALSE); + } + ReturnCode = IDirectDrawSurface_SetPalette(gpFrameBuffer, gpDirectDrawPalette); - if (ReturnCode != DD_OK) - { - DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to frame buffer")); - return(FALSE); - } + if (ReturnCode != DD_OK) + { + DebugMsg(TOPIC_VIDEO, DBG_LEVEL_0, String("Failed to apply 8-bit palette to frame buffer")); + return(FALSE); + } return(TRUE); } @@ -3057,11 +3057,11 @@ void FatalError( const STR8 pError, ...) // Release DDraw IDirectDraw2_RestoreDisplayMode( gpDirectDrawObject ); - IDirectDraw2_Release( gpDirectDrawObject ); + IDirectDraw2_Release( gpDirectDrawObject ); ShowWindow( ghWindow, SW_HIDE ); - // destroy the window - // DestroyWindow( ghWindow ); + // destroy the window + // DestroyWindow( ghWindow ); gfProgramIsRunning = FALSE; @@ -3084,19 +3084,19 @@ void FatalError( const STR8 pError, ...) typedef struct { - UINT8 ubIDLength; - UINT8 ubColorMapType; - UINT8 ubTargaType; - UINT16 usColorMapOrigin; - UINT16 usColorMapLength; - UINT8 ubColorMapEntrySize; - UINT16 usOriginX; - UINT16 usOriginY; - UINT16 usImageWidth; - UINT16 usImageHeight; - UINT8 ubBitsPerPixel; - UINT8 ubImageDescriptor; - + UINT8 ubIDLength; + UINT8 ubColorMapType; + UINT8 ubTargaType; + UINT16 usColorMapOrigin; + UINT16 usColorMapLength; + UINT8 ubColorMapEntrySize; + UINT16 usOriginX; + UINT16 usOriginY; + UINT16 usImageWidth; + UINT16 usImageHeight; + UINT8 ubBitsPerPixel; + UINT8 ubImageDescriptor; + } TARGA_HEADER; #pragma pack (pop) @@ -3105,35 +3105,35 @@ typedef struct { void SnapshotSmall(void) { INT32 iCountX, iCountY; - DDSURFACEDESC SurfaceDescription; + DDSURFACEDESC SurfaceDescription; UINT16 *pVideo, *pDest; - HRESULT ReturnCode; + HRESULT ReturnCode; - ZEROMEM(SurfaceDescription); + ZEROMEM(SurfaceDescription); SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Lock( gpPrimarySurface, NULL, &SurfaceDescription, 0, NULL); + ReturnCode = IDirectDrawSurface2_Lock( gpPrimarySurface, NULL, &SurfaceDescription, 0, NULL); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { + { return; - } + } -// sprintf( cFilename, "JA%5.5d.TGA", uiPicNum++ ); - -// if( ( disk = fopen(cFilename, "wb"))==NULL ) -// return; + // sprintf( cFilename, "JA%5.5d.TGA", uiPicNum++ ); -// memset(&Header, 0, sizeof(TARGA_HEADER)); - -// Header.ubTargaType=2; // Uncompressed 16/24/32 bit -// Header.usImageWidth=320; -// Header.usImageHeight=240; -// Header.ubBitsPerPixel=16; + // if( ( disk = fopen(cFilename, "wb"))==NULL ) + // return; -// fwrite(&Header, sizeof(TARGA_HEADER), 1, disk); + // memset(&Header, 0, sizeof(TARGA_HEADER)); - // Get the write pointer + // Header.ubTargaType=2; // Uncompressed 16/24/32 bit + // Header.usImageWidth=320; + // Header.usImageHeight=240; + // Header.ubBitsPerPixel=16; + + // fwrite(&Header, sizeof(TARGA_HEADER), 1, disk); + + // Get the write pointer pVideo = (UINT16*)SurfaceDescription.lpSurface; pDest = gpFrameData[ giNumFrames ]; @@ -3142,23 +3142,23 @@ void SnapshotSmall(void) { for(iCountX=0; iCountX < SCREEN_WIDTH; iCountX+= 1) { - // uiData=(UINT16)*(pVideo+(iCountY*SCREEN_WIDTH*2)+ ( iCountX * 2 ) ); + // uiData=(UINT16)*(pVideo+(iCountY*SCREEN_WIDTH*2)+ ( iCountX * 2 ) ); -// 1111 1111 1100 0000 -// f f c - // usPixel555= (UINT16)(uiData&0xffff); -// usPixel555= ((usPixel555 & 0xffc0) >> 1) | (usPixel555 & 0x1f); + // 1111 1111 1100 0000 + // f f c + // usPixel555= (UINT16)(uiData&0xffff); + // usPixel555= ((usPixel555 & 0xffc0) >> 1) | (usPixel555 & 0x1f); - // usPixel555= (UINT16)(uiData); - - // fwrite( &usPixel555, sizeof(UINT16), 1, disk); - // fwrite( (void *)(((UINT8 *)SurfaceDescription.lpSurface) + ( iCountY * SCREEN_WIDTH * 2) + ( iCountX * 2 ) ), 2 * sizeof( BYTE ), 1, disk ); + // usPixel555= (UINT16)(uiData); - *( pDest + ( iCountY * SCREEN_WIDTH ) + ( iCountX ) ) = *( pVideo + ( iCountY * SCREEN_WIDTH ) + ( iCountX ) ); + // fwrite( &usPixel555, sizeof(UINT16), 1, disk); + // fwrite( (void *)(((UINT8 *)SurfaceDescription.lpSurface) + ( iCountY * SCREEN_WIDTH * 2) + ( iCountX * 2 ) ), 2 * sizeof( BYTE ), 1, disk ); + + *( pDest + ( iCountY * SCREEN_WIDTH ) + ( iCountX ) ) = *( pVideo + ( iCountY * SCREEN_WIDTH ) + ( iCountX ) ); } } - + giNumFrames++; if ( giNumFrames == MAX_NUM_FRAMES ) @@ -3167,15 +3167,15 @@ void SnapshotSmall(void) } - ZEROMEM(SurfaceDescription); - SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); - ReturnCode = IDirectDrawSurface2_Unlock(gpPrimarySurface, &SurfaceDescription); + ZEROMEM(SurfaceDescription); + SurfaceDescription.dwSize = sizeof(DDSURFACEDESC); + ReturnCode = IDirectDrawSurface2_Unlock(gpPrimarySurface, &SurfaceDescription); if ((ReturnCode != DD_OK)&&(ReturnCode != DDERR_WASSTILLDRAWING)) - { - DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); - } + { + DirectXAttempt ( ReturnCode, __LINE__, __FILE__ ); + } -// fclose(disk); + // fclose(disk); } @@ -3234,7 +3234,7 @@ void RefreshMovieCache( ) // Snap: save current directory GetFileManCurrentDirectory( DataDir ); - + GetExecutableDirectory( ExecDir ); SetFileManCurrentDirectory( ExecDir ); @@ -3260,7 +3260,7 @@ void RefreshMovieCache( ) { for(iCountX=0; iCountX < SCREEN_WIDTH; iCountX ++ ) { - fwrite( ( pDest + ( iCountY * SCREEN_WIDTH ) + iCountX ), sizeof(UINT16), 1, disk); + fwrite( ( pDest + ( iCountY * SCREEN_WIDTH ) + iCountX ), sizeof(UINT16), 1, disk); } } diff --git a/Strategic/Auto Resolve.cpp b/Strategic/Auto Resolve.cpp index c4d417df..a035609a 100644 --- a/Strategic/Auto Resolve.cpp +++ b/Strategic/Auto Resolve.cpp @@ -85,7 +85,9 @@ INT32 giMaxEnemiesToRender = 40; INT32 giMaxMilitiaToRender = 20;//Changes depending on merc amount extern UINT8 gubReinforcementMinEnemyStaticGroupSize; +extern BOOLEAN gfStrategicMilitiaChangesMade; +extern void ResetMilitia(); extern BOOLEAN AutoReload( SOLDIERTYPE *pSoldier ); extern HVSURFACE ghFrameBuffer; BOOLEAN gfTransferTacticalOppositionToAutoResolve = FALSE; @@ -2469,6 +2471,7 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Autoresolve2"); UnloadButtonImage( gpAR->iButtonImage[ i ] ); RemoveButton( gpAR->iButton[ i ] ); } + if( fDeleteForGood ) { //Warp the game time accordingly @@ -2501,6 +2504,11 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Autoresolve2"); gubSectorIDOfCreatureAttack = 0; } //VtPauseSampling(); + + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } void PauseButtonCallback( GUI_BUTTON *btn, INT32 reason ) diff --git a/Strategic/Game Clock.cpp b/Strategic/Game Clock.cpp index e07849ac..793554e7 100644 --- a/Strategic/Game Clock.cpp +++ b/Strategic/Game Clock.cpp @@ -702,7 +702,7 @@ void PauseTimeForInterupt() } //USING CLOCK RESOLUTION -//Note, that changing the clock resolution doesn't effect the amount of game time that passes per +//Note, that changing the clock resolution doesn't affect the amount of game time that passes per //real second, but how many times per second the clock is updated. This rate will break up the actual //time slices per second into smaller chunks. This is useful for animating strategic movement under //fast time compression, so objects don't warp around. diff --git a/Strategic/Map Screen Interface Map.cpp b/Strategic/Map Screen Interface Map.cpp index 7a95780e..c55b7dab 100644 --- a/Strategic/Map Screen Interface Map.cpp +++ b/Strategic/Map Screen Interface Map.cpp @@ -5046,9 +5046,6 @@ void DisplayLevelString( void ) // function to manipulate the number of towns people on the cursor BOOLEAN PickUpATownPersonFromSector( UINT8 ubType, INT16 sX, INT16 sY ) { - - - // see if there are any militia of this type in this sector if( !SectorInfo[ SECTOR( sX, sY ) ].ubNumberOfCivsAtLevel[ ubType ] ) { @@ -5067,7 +5064,7 @@ BOOLEAN PickUpATownPersonFromSector( UINT8 ubType, INT16 sX, INT16 sY ) return( FALSE ); } - if( SECTOR( sX, sY ) == SECTOR( gWorldSectorX, gWorldSectorY ) ) + if( sX == gWorldSectorX && sY == gWorldSectorY ) { gfStrategicMilitiaChangesMade = TRUE; } @@ -5115,11 +5112,12 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"Map Screen2"); return( FALSE ); } - if( SECTOR( sX, sY ) == SECTOR( gWorldSectorX, gWorldSectorY ) ) + if( sX == gWorldSectorX && sY == gWorldSectorY ) { gfStrategicMilitiaChangesMade = TRUE; } + // drop the guy into this sector switch( ubType ) { @@ -6119,6 +6117,12 @@ void MilitiaDoneButtonCallback(GUI_BUTTON *btn,INT32 reason) // reset fact we are in the box sSelectedMilitiaTown = 0; fMapPanelDirty = TRUE; + + // Go ahead and reset the militia in the selected sector (even if we didn't change it here) + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } } diff --git a/Strategic/MilitiaSquads.cpp b/Strategic/MilitiaSquads.cpp index 7687f1aa..2bde4fc6 100644 --- a/Strategic/MilitiaSquads.cpp +++ b/Strategic/MilitiaSquads.cpp @@ -152,6 +152,11 @@ void GenerateMilitiaSquad(INT16 sMapX, INT16 sMapY, INT16 sTMapX, INT16 sTMapY ) if(pSectorInfo->ubNumberOfCivsAtLevel[REGULAR_MILITIA])--pSectorInfo->ubNumberOfCivsAtLevel[REGULAR_MILITIA];else if(pSectorInfo->ubNumberOfCivsAtLevel[ELITE_MILITIA])--pSectorInfo->ubNumberOfCivsAtLevel[ELITE_MILITIA]; + // Update the militia if the current sector is affected + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } // Creates militia at destination sector and removes it from starting sector @@ -176,6 +181,11 @@ void MoveMilitiaSquad(INT16 sMapX, INT16 sMapY, INT16 sTMapX, INT16 sTMapY, BOOL {--pTSectorInfo->ubNumberOfCivsAtLevel[REGULAR_MILITIA];++pSectorInfo->ubNumberOfCivsAtLevel[REGULAR_MILITIA];}else if(pTSectorInfo->ubNumberOfCivsAtLevel[ELITE_MILITIA]) {--pTSectorInfo->ubNumberOfCivsAtLevel[ELITE_MILITIA];++pSectorInfo->ubNumberOfCivsAtLevel[ELITE_MILITIA];} + + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } BOOLEAN MoveOneBestMilitiaMan(INT16 sMapX, INT16 sMapY, INT16 sTMapX, INT16 sTMapY) @@ -481,6 +491,11 @@ void UpdateMilitiaSquads(INT16 sMapX, INT16 sMapY ) return; CreateMilitiaSquads( sMapX, sMapY ); + + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } @@ -530,12 +545,8 @@ void UpdateMilitiaSquads(INT16 sMapX, INT16 sMapY ) MoveMilitiaSquad( sMapX, sMapY, SECTORX( pMoveDir[ iRandomRes ][0] ), SECTORY( pMoveDir[ iRandomRes ][0] ), FALSE ); AddToBlockMoveList( SECTORX( pMoveDir[ iRandomRes ][0] ), SECTORY( pMoveDir[ iRandomRes ][0] ) ); - - if ( gWorldSectorX == SECTORX( pMoveDir[ iRandomRes ][0] ) && - gWorldSectorY == SECTORY( pMoveDir[ iRandomRes ][0] ) && - !gbWorldSectorZ ) + if ( gfStrategicMilitiaChangesMade) { - gfStrategicMilitiaChangesMade = TRUE; ResetMilitia(); } @@ -723,6 +734,12 @@ void DoMilitiaHelpFromAdjacentSectors( INT16 sMapX, INT16 sMapY ) } } + if (gfStrategicMilitiaChangesMade) + { + RemoveMilitiaFromTactical(); + PrepareMilitiaForTactical(); + gfStrategicMilitiaChangesMade = FALSE; + } } void MSCallBack( UINT8 ubResult ) diff --git a/Strategic/PreBattle Interface.cpp b/Strategic/PreBattle Interface.cpp index 949e12ce..10ba6e8b 100644 --- a/Strategic/PreBattle Interface.cpp +++ b/Strategic/PreBattle Interface.cpp @@ -911,6 +911,8 @@ void KillPreBattleInterface() { ShowButton( giCharInfoButton[ 1 ] ); } + + gfPersistantPBI = FALSE; // If killing the PBI, it must not be persistant anymore! } diff --git a/Strategic/Queen Command.cpp b/Strategic/Queen Command.cpp index d840f375..77967949 100644 --- a/Strategic/Queen Command.cpp +++ b/Strategic/Queen Command.cpp @@ -1132,8 +1132,9 @@ DebugMsg (TOPIC_JA2,DBG_LEVEL_3,"QueenCommand"); } } +//Well, not so rarely with mobile reinforcements! //Rarely, there will be more enemies than supported by the engine. In this case, these -//soldier's are waiting for a slot to be free so that they can enter the battle. This +//soldiers are waiting for a slot to be free so that they can enter the battle. This //essentially allows for an infinite number of troops, though only 32 at a time can fight. //This is also called whenever an enemy group's reinforcements arrive because the code is //identical, though it is highly likely that they will all be successfully added on the first call. @@ -1304,6 +1305,13 @@ void AddPossiblePendingEnemiesToBattle() AddEnemiesToBattle( pGroup, ubStrategicInsertionCode, ubNumAdmins, ubNumTroops, ubNumElites, FALSE ); gfPendingEnemies = TRUE; } + + // If there are still more to contribute, then move the remaining back to the sector they came from. + if (ubNumAvailable) + { + pGroup->ubSectorX = pGroup->ubPrevX; + pGroup->ubSectorY = pGroup->ubPrevY; + } } pGroup = pGroup->next; } diff --git a/Strategic/Reinforcement.cpp b/Strategic/Reinforcement.cpp index 2a6bd1ab..cc8ba14c 100644 --- a/Strategic/Reinforcement.cpp +++ b/Strategic/Reinforcement.cpp @@ -426,7 +426,10 @@ void AddPossiblePendingMilitiaToBattle() ubPredefinedInsertionCode = DoReinforcementAsPendingMilitia( gWorldSectorX, gWorldSectorY, &ubPredefinedRank ); if( ubPredefinedInsertionCode != 255 ) + { AddPossiblePendingMilitiaToBattle(); + gfStrategicMilitiaChangesMade = FALSE; // Handled them here + } } } \ No newline at end of file diff --git a/Strategic/Strategic Movement.cpp b/Strategic/Strategic Movement.cpp index c5137d5a..3e19c6d3 100644 --- a/Strategic/Strategic Movement.cpp +++ b/Strategic/Strategic Movement.cpp @@ -51,6 +51,8 @@ #include "MilitiaSquads.h" +extern UINT32 guiLastTacticalRealTime; + // the delay for a group about to arrive #define ABOUT_TO_ARRIVE_DELAY 5 @@ -1075,6 +1077,7 @@ BOOLEAN CheckConditionsForBattle( GROUP *pGroup ) if( NumEnemiesInSector( pGroup->ubSectorX, pGroup->ubSectorY ) ) { fBattlePending = TRUE; + StopTimeCompression(); } if( pGroup->uiFlags & GROUPFLAG_HIGH_POTENTIAL_FOR_AMBUSH && fBattlePending ) @@ -1089,6 +1092,7 @@ BOOLEAN CheckConditionsForBattle( GROUP *pGroup ) { fBloodCatAmbush = TRUE; fBattlePending = TRUE; + StopTimeCompression(); } if( fBattlePending && (!fBloodCatAmbush || gubEnemyEncounterCode == ENTERING_BLOODCAT_LAIR_CODE) ) @@ -1118,7 +1122,7 @@ BOOLEAN CheckConditionsForBattle( GROUP *pGroup ) } if( fBattlePending ) - { //A battle is pending, but the player's could be all unconcious or dead. + { //A battle is pending, but the players could be all unconcious or dead. //Go through every group until we find at least one concious merc. The looping will determine //if there are any live mercs and/or concious ones. If there are no concious mercs, but alive ones, //then we will go straight to autoresolve, where the enemy will likely annihilate them or capture them. @@ -1128,6 +1132,8 @@ BOOLEAN CheckConditionsForBattle( GROUP *pGroup ) ValidateGroups( pGroup ); #endif + StopTimeCompression(); + if( gubNumGroupsArrivedSimultaneously ) { //Because this is a battle case, clear all the group flags curr = gpGroupList; @@ -1970,7 +1976,7 @@ void GroupArrivedAtSector( UINT8 ubGroupID, BOOLEAN fCheckForBattle, BOOLEAN fNe if ( !fGroupDestroyed ) { //Determine if a battle should start. - //if a battle does start, or get's delayed, then we will keep the group in memory including + //if a battle does start, or gets delayed, then we will keep the group in memory including //all waypoints, until after the battle is resolved. At that point, we will continue the processing. if( fCheckForBattle && !CheckConditionsForBattle( pGroup ) && !gfWaitingForInput ) { @@ -2706,6 +2712,8 @@ void SetGroupSectorValue( INT16 sSectorX, INT16 sSectorY, INT16 sSectorZ, UINT8 } CheckAndHandleUnloadingOfCurrentWorld(); + + SetSectorFlag( sSectorX, sSectorY, (UINT8) sSectorZ, SF_ALREADY_VISITED); } void SetEnemyGroupSector( GROUP *pGroup, UINT8 ubSectorID ) diff --git a/Strategic/Town Militia.cpp b/Strategic/Town Militia.cpp index dfcefe8e..17812a23 100644 --- a/Strategic/Town Militia.cpp +++ b/Strategic/Town Militia.cpp @@ -119,7 +119,7 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa // force tactical to update militia status - gfStrategicMilitiaChangesMade = TRUE; + gfStrategicMilitiaChangesMade = FALSE; // ok, so what do we do with all this training? Well, in order of decreasing priority: // 1) If there's room in training sector, create new GREEN militia guys there @@ -148,6 +148,11 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa { // great! Create a new GREEN militia guy in the training sector StrategicAddMilitiaToSector(sMapX, sMapY, GREEN_MILITIA, 1); + + if (sMapX == gWorldSectorX && sMapY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } } else { @@ -166,6 +171,11 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa // great! Create a new GREEN militia guy in the neighbouring sector StrategicAddMilitiaToSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1); + if (sNeighbourX == gWorldSectorX && sNeighbourY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } + fFoundOne = TRUE; break; } @@ -183,6 +193,10 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa // great! Promote a GREEN militia guy in the training sector to a REGULAR StrategicPromoteMilitiaInSector(sMapX, sMapY, GREEN_MILITIA, 1); fFoundOne = TRUE; + if (sMapX == gWorldSectorX && sMapY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } } else { @@ -200,6 +214,11 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa // great! Promote a GREEN militia guy in the neighbouring sector to a REGULAR StrategicPromoteMilitiaInSector(sNeighbourX, sNeighbourY, GREEN_MILITIA, 1); + if (sNeighbourX == gWorldSectorX && sNeighbourY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } + fFoundOne = TRUE; break; } @@ -217,6 +236,12 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa { // great! Promote a REGULAR militia guy in the training sector to a VETERAN StrategicPromoteMilitiaInSector(sMapX, sMapY, REGULAR_MILITIA, 1); + + if (sMapX == gWorldSectorX && sMapY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } + fFoundOne = TRUE; } else @@ -235,6 +260,11 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa // great! Promote a Regular militia guy in the neighbouring sector to a Veteran StrategicPromoteMilitiaInSector(sNeighbourX, sNeighbourY, REGULAR_MILITIA, 1); + if (sNeighbourX == gWorldSectorX && sNeighbourY == gWorldSectorY) + { + gfStrategicMilitiaChangesMade = TRUE; + } + fFoundOne = TRUE; break; } @@ -258,6 +288,10 @@ void TownMilitiaTrainingCompleted( SOLDIERTYPE *pTrainer, INT16 sMapX, INT16 sMa ubMilitiaTrained++; } + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } // if anyone actually got trained if (ubMilitiaTrained > 0) @@ -333,6 +367,11 @@ void StrategicAddMilitiaToSector(INT16 sMapX, INT16 sMapY, UINT8 ubRank, UINT8 u pSectorInfo->ubNumberOfCivsAtLevel[ ubRank ] += ubHowMany; + if (ubHowMany && sMapX == gWorldSectorX && sMapY == gWorldSectorY ) + { + gfStrategicMilitiaChangesMade = TRUE; + } + // update the screen display fMapPanelDirty = TRUE; } @@ -354,6 +393,11 @@ void StrategicPromoteMilitiaInSector(INT16 sMapX, INT16 sMapY, UINT8 ubCurrentRa pSectorInfo->ubNumberOfCivsAtLevel[ ubCurrentRank ] -= ubHowMany; pSectorInfo->ubNumberOfCivsAtLevel[ ubCurrentRank + 1 ] += ubHowMany; + if (ubHowMany && sMapX == gWorldSectorX && sMapY == gWorldSectorY ) + { + gfStrategicMilitiaChangesMade = TRUE; + } + // update the screen display fMapPanelDirty = TRUE; } @@ -374,6 +418,11 @@ void StrategicRemoveMilitiaFromSector(INT16 sMapX, INT16 sMapY, UINT8 ubRank, UI pSectorInfo->ubNumberOfCivsAtLevel[ ubRank ] -= ubHowMany; + if (ubHowMany && sMapX == gWorldSectorX && sMapY == gWorldSectorY ) + { + gfStrategicMilitiaChangesMade = TRUE; + } + // update the screen display fMapPanelDirty = TRUE; } diff --git a/Strategic/strategicmap.cpp b/Strategic/strategicmap.cpp index 73fe9e56..850a3444 100644 --- a/Strategic/strategicmap.cpp +++ b/Strategic/strategicmap.cpp @@ -1753,7 +1753,16 @@ BOOLEAN SetCurrentWorldSector( INT16 sMapX, INT16 sMapY, INT8 bMapZ ) // Check for helicopter being on the ground in this sector... HandleHelicopterOnGroundGraphic( ); - ResetMilitia(); + // 0verhaul: Okay, it is apparent that the enemies are not reset incorrectly. So I will now try to add symmetry + // between enemy placement and militia placement. The enemies do have one advantage here, though: If a sector + // is in enemy hands, then their sector is not actually loaded. At least not normally. Perhaps it would be useful + // to lose a battle with one group of mercs, then bring in another group without changing to another sector to see + // if enemy integrity holds. But this would require the enemies to come up with reinforcements inbetween the battles + // to really test out. + // + // Anyway, for now I will remove this call from here. The objective is to add militia any time we could add enemies + // except for the case of training new militia. But that case can be handled each time militia training finishes. +// ResetMilitia(); AllTeamsLookForAll( TRUE ); return( TRUE ); } @@ -3367,7 +3376,7 @@ void AllMercsWalkedToExitGrid() pPlayer = pPlayer->next; } - SetGroupSectorValue( (UINT8)gsAdjacentSectorX, (UINT8)gsAdjacentSectorY, gbAdjacentSectorZ, gpAdjacentGroup->ubGroupID ); + SetGroupSectorValue( gsAdjacentSectorX, gsAdjacentSectorY, (INT16) gbAdjacentSectorZ, gpAdjacentGroup->ubGroupID ); AttemptToMergeSeparatedGroups( gpAdjacentGroup, FALSE ); SetDefaultSquadOnSectorEntry( TRUE ); @@ -3412,7 +3421,7 @@ void AllMercsWalkedToExitGrid() pPlayer = pPlayer->next; } - SetGroupSectorValue( gsAdjacentSectorX, gsAdjacentSectorY, gbAdjacentSectorZ, gpAdjacentGroup->ubGroupID ); + SetGroupSectorValue( gsAdjacentSectorX, gsAdjacentSectorY, (INT16) gbAdjacentSectorZ, gpAdjacentGroup->ubGroupID ); AttemptToMergeSeparatedGroups( gpAdjacentGroup, FALSE ); gFadeOutDoneCallback = DoneFadeOutExitGridSector; diff --git a/Tactical/Militia Control.cpp b/Tactical/Militia Control.cpp index 18811623..66cba3b2 100644 --- a/Tactical/Militia Control.cpp +++ b/Tactical/Militia Control.cpp @@ -126,47 +126,66 @@ void ResetMilitia() UINT8 ubNumVet = 0; UINT32 cnt; - if ( gWorldSectorX !=0 && gWorldSectorY != 0 && NumEnemiesInSector( gWorldSectorX, gWorldSectorY ) ) - fBattleInProgress = TRUE; +// if ( gWorldSectorX !=0 && gWorldSectorY != 0 && NumEnemiesInSector( gWorldSectorX, gWorldSectorY ) ) +// fBattleInProgress = TRUE; // 0verhaul: Instead of relying on the "changes made" flag, which isn't even saved in a saved game and therefore not // reliable, we'll just do this the hard way, by taking inventory. - gfStrategicMilitiaChangesMade = FALSE; - for (cnt = gTacticalStatus.Team[MILITIA_TEAM].bFirstID; cnt <= gTacticalStatus.Team[MILITIA_TEAM].bLastID; cnt++) +// gfStrategicMilitiaChangesMade = FALSE; +// for (cnt = gTacticalStatus.Team[MILITIA_TEAM].bFirstID; cnt <= gTacticalStatus.Team[MILITIA_TEAM].bLastID; cnt++) +// { +// if (!MercPtrs[cnt]->bActive) +// { +// continue; +// } +// +// switch (MercPtrs[cnt]->ubSoldierClass) +// { +// case SOLDIER_CLASS_GREEN_MILITIA: ubNumGreen++; break; +// case SOLDIER_CLASS_REG_MILITIA: ubNumReg++; break; +// case SOLDIER_CLASS_ELITE_MILITIA: ubNumVet++; break; +// default: ; +// } +// } +// if (MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, GREEN_MILITIA) != ubNumGreen || +// MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, REGULAR_MILITIA) != ubNumReg || +// MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, ELITE_MILITIA) != ubNumVet) +// { +// gfStrategicMilitiaChangesMade = TRUE; +// } +// + if (gfStrategicMilitiaChangesMade) { - if (!MercPtrs[cnt]->bActive) - { - continue; - } + // I truly hope that we remove such inane control methods from the soldier create code when we break the merc slot barrier + // Hacks like this really depress me. + UINT32 cs = guiCurrentScreen; + // Make sure we aren't on the AUTORESOLVE screen for this. Even if we are. We are removing and creating soldiers for + // tactical here, not autoresolve. In my opinion the CreateSoldierXXX and TacticalRemoveSoldierXXX functions should take + // a flag for autoresolve if different initialization or destruction is desired. + guiCurrentScreen = GAME_SCREEN; + - switch (MercPtrs[cnt]->ubSoldierClass) - { - case SOLDIER_CLASS_GREEN_MILITIA: ubNumGreen++; break; - case SOLDIER_CLASS_REG_MILITIA: ubNumReg++; break; - case SOLDIER_CLASS_ELITE_MILITIA: ubNumVet++; break; - default: ; - } - } - if (MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, GREEN_MILITIA) != ubNumGreen || - MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, REGULAR_MILITIA) != ubNumReg || - MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, ELITE_MILITIA) != ubNumVet) - { RemoveMilitiaFromTactical(); ubNumGreen = MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, GREEN_MILITIA); ubNumReg = MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, REGULAR_MILITIA); ubNumVet = MilitiaInSectorOfRank(gWorldSectorX, gWorldSectorY, ELITE_MILITIA); AddSoldierInitListMilitia( ubNumGreen, ubNumReg, ubNumVet ); + + // Now restore the original screen setting so the game doesn't go wacky. + guiCurrentScreen = cs; + + gfStrategicMilitiaChangesMade = FALSE; } // if( ( gfStrategicMilitiaChangesMade && !fBattleInProgress ) || gTacticalStatus.uiFlags & LOADING_SAVED_GAME || gfMSResetMilitia ) - if(gfMSResetMilitia ) - { +// if(gfMSResetMilitia ) +// { // if( !gfMSResetMilitia ) // RemoveMilitiaFromTactical(); - PrepareMilitiaForTactical(); - gfMSResetMilitia = FALSE; - } +// PrepareMilitiaForTactical(); +// gfMSResetMilitia = FALSE; +// } } void RemoveMilitiaFromTactical() @@ -212,17 +231,22 @@ void PrepareMilitiaForTactical() { for( x = 0 ; x < guiDirNumber ; ++x ) { +#if 0 // ScreenMsg( FONT_MCOLOR_LTYELLOW, MSG_INTERFACE, L"%ld,%ld,%ld,%ld", gpAttackDirs[ x ][ 0 ], gpAttackDirs[ x ][1], gpAttackDirs[ x ][2], gpAttackDirs[ x ][3] ); if( gfMSResetMilitia ) { if( gpAttackDirs[ x ][ 3 ] != INSERTION_CODE_CENTER ) { AddSoldierInitListMilitiaOnEdge( gpAttackDirs[ x ][ 3 ], gpAttackDirs[ x ][0], gpAttackDirs[ x ][1], gpAttackDirs[ x ][2] ); + ubGreen -= gpAttackDirs[ x ][0]; + ubRegs -= gpAttackDirs[ x ][1]; + ubElites -= gpAttackDirs[ x ][2]; } } else { - if( gpAttackDirs[ x ][ 3 ] == INSERTION_CODE_CENTER ) +#endif + if( gpAttackDirs[ x ][ 3 ] == INSERTION_CODE_CENTER ) { AddSoldierInitListMilitia( gpAttackDirs[ x ][0], gpAttackDirs[ x ][1], gpAttackDirs[ x ][2] ); } @@ -230,7 +254,7 @@ void PrepareMilitiaForTactical() { AddSoldierInitListMilitiaOnEdge( gpAttackDirs[ x ][ 3 ], gpAttackDirs[ x ][0], gpAttackDirs[ x ][1], gpAttackDirs[ x ][2] ); } - } +// } } } else @@ -247,6 +271,7 @@ void PrepareMilitiaForTactical() // } // } guiDirNumber = 0; + memset( gpAttackDirs, 0, sizeof( gpAttackDirs)); } void HandleMilitiaPromotions( void ) @@ -302,6 +327,11 @@ void HandleMilitiaPromotions( void ) // BuildMilitiaPromotionsString( str ); // DoScreenIndependantMessageBox( str, MSG_BOX_FLAG_OK, NULL ); } + + if (gfStrategicMilitiaChangesMade) + { + ResetMilitia(); + } } diff --git a/Tactical/Overhead.cpp b/Tactical/Overhead.cpp index 1e96e9f9..86e35083 100644 --- a/Tactical/Overhead.cpp +++ b/Tactical/Overhead.cpp @@ -3423,8 +3423,10 @@ void HandleNPCTeamMemberDeath( SOLDIERTYPE *pSoldierOld ) if (bMilitiaRank != -1) { + BOOLEAN NeedReset = gfStrategicMilitiaChangesMade; // remove this militia from the strategic records StrategicRemoveMilitiaFromSector( gWorldSectorX, gWorldSectorY, bMilitiaRank, 1 ); + gfStrategicMilitiaChangesMade = NeedReset; } // If the militia's killer is known diff --git a/Tactical/Soldier Create.cpp b/Tactical/Soldier Create.cpp index ef68f4ee..e56cba0e 100644 --- a/Tactical/Soldier Create.cpp +++ b/Tactical/Soldier Create.cpp @@ -1430,6 +1430,7 @@ BOOLEAN TacticalRemoveSoldierPointer( SOLDIERTYPE *pSoldier, BOOLEAN fRemoveVehi { DeleteSoldier( pSoldier ); } + MemFree( pSoldier ); } diff --git a/resource.h b/resource.h deleted file mode 100644 index f0f6ca6f..00000000 --- a/resource.h +++ /dev/null @@ -1,28 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by ja2.rc -// -#define IDI_ICON1 113 -#define IDI_ICON2 115 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 114 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif - - -#define ID_ABOUT 116 -#define IDD_ABOUT 117 -#define ID_COPY 118 -#define ID_PASTE 119 -#define ID_EXIT_CONSOLE 120 -#define IDR_POPUP_MENU 130 - - -