Use std::vector for HVSURFACE->RegionList

Replaces the use of old custom list implementation in container.cpp
This commit is contained in:
Asdow
2023-10-09 23:01:33 +03:00
parent 56a55f1bc4
commit 8525d3f869
2 changed files with 26 additions and 55 deletions
+23 -52
View File
@@ -110,6 +110,7 @@ HVSURFACE ghFrameBuffer = NULL;
HVSURFACE ghMouseBuffer = NULL;
#include <map>
#include <vector>
extern std::map<UINT32,ClipRectangle> g_SurfaceRectangle;
@@ -1161,11 +1162,7 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc )
//
// Allocate memory for Video Surface data and initialize
//
hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) );
memset( hVSurface, 0, sizeof( SGPVSurface ) );
CHECKF( hVSurface != NULL );
hVSurface = new SGPVSurface{};
hVSurface->usHeight = usHeight;
hVSurface->usWidth = usWidth;
// BF : since we use a 16bpp framebuffer and images are converted to that format,
@@ -1178,7 +1175,6 @@ HVSURFACE CreateVideoSurface( VSURFACE_DESC *VSurfaceDesc )
hVSurface->pPalette = NULL;
hVSurface->p16BPPPalette = NULL;
hVSurface->TransparentColor = FROMRGB( 0, 0, 0 );
hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) );
hVSurface->fFlags = 0;
hVSurface->pClipper = NULL;
@@ -1647,12 +1643,6 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
hVSurface->pPalette = NULL;
}
//if ( hVSurface->pClipper != NULL )
//{
// Release Clipper
// DDReleaseClipper( (LPDIRECTDRAWCLIPPER)hVSurface->pClipper );
//}
// Get surface pointer
lpDDSurface = (LPDIRECTDRAWSURFACE2)hVSurface->pSurfaceData;
@@ -1670,7 +1660,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
}
// Release region data
DeleteList( hVSurface->RegionList );
hVSurface->RegionList.clear();
//If there is a 16bpp palette, free it
if( hVSurface->p16BPPPalette != NULL )
@@ -1682,8 +1672,7 @@ BOOLEAN DeleteVideoSurface( HVSURFACE hVSurface )
giMemUsedInSurfaces -= ( hVSurface->usHeight * hVSurface->usWidth * ( hVSurface->ubBitDepth / 8 ) );
// Release object
MemFree( hVSurface );
delete hVSurface;
return( TRUE );
}
@@ -1768,7 +1757,7 @@ BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions )
{
Assert( hVSurface );
*puiNumRegions = ListSize( hVSurface->RegionList );
*puiNumRegions = hVSurface->RegionList.size();
return( TRUE );
@@ -1780,7 +1769,7 @@ BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion )
Assert( pNewRegion != NULL );
// Add new region to list
hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, ListSize( hVSurface->RegionList ) );
hVSurface->RegionList.push_back(*pNewRegion);
return( TRUE );
}
@@ -1801,29 +1790,10 @@ BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions,
return( TRUE );
}
BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex )
{
VSURFACE_REGION aRegion;
Assert( hVSurface != NULL );
return( RemfromList( hVSurface->RegionList, &aRegion, usIndex ) );
}
BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface )
{
UINT32 uiListSize;
Assert( hVSurface != NULL );
uiListSize = ListSize( hVSurface->RegionList );
for ( INT32 cnt = uiListSize - 1; cnt >= 0; cnt-- )
{
RemoveVSurfaceRegion( hVSurface, (UINT16)cnt );
}
hVSurface->RegionList.clear();
return( TRUE );
}
@@ -1831,12 +1801,13 @@ BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION
{
Assert( hVSurface != NULL );
if ( !PeekList( hVSurface->RegionList, aRegion, usIndex ) )
if (usIndex < hVSurface->RegionList.size())
{
return( FALSE );
*aRegion = hVSurface->RegionList[usIndex];
return( TRUE );
}
return( TRUE );
return( FALSE );
}
BOOLEAN GetVSurfaceRect( HVSURFACE hVSurface, RECT *pRect)
@@ -1858,16 +1829,13 @@ BOOLEAN ReplaceVSurfaceRegion( HVSURFACE hVSurface , UINT16 usIndex, VSURFACE_RE
Assert( hVSurface != NULL );
// Validate index given
if ( !PeekList( hVSurface->RegionList, &OldRegion, usIndex ) )
if (usIndex < hVSurface->RegionList.size())
{
return( FALSE );
hVSurface->RegionList[usIndex] = *aRegion;
return( TRUE );
}
// Replace information
hVSurface->RegionList = AddtoList( hVSurface->RegionList, aRegion, usIndex );
return( TRUE );
return( FALSE );
}
BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion )
@@ -1876,10 +1844,14 @@ BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_
Assert( pNewRegion != NULL );
// Add new region to list
hVSurface->RegionList = AddtoList( hVSurface->RegionList, pNewRegion, usIndex );
return( TRUE );
if (usIndex < hVSurface->RegionList.size())
{
auto pos = hVSurface->RegionList.begin() + usIndex;
hVSurface->RegionList.insert(pos, *pNewRegion);
return(TRUE);
}
return(FALSE);
}
// *******************************************************************
@@ -2161,7 +2133,7 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface )
// Allocate Video Surface struct
hVSurface = (HVSURFACE) MemAlloc( sizeof( SGPVSurface ) );
hVSurface = new SGPVSurface{};
// Set values based on DD Surface given
DDGetSurfaceDescription ( lpDDSurface, &DDSurfaceDesc );
@@ -2173,7 +2145,6 @@ HVSURFACE CreateVideoSurfaceFromDDSurface( LPDIRECTDRAWSURFACE2 lpDDSurface )
hVSurface->pSurfaceData = (PTR)lpDDSurface;
hVSurface->pSurfaceData1 = NULL;
hVSurface->pSavedSurfaceData = NULL;
hVSurface->RegionList = CreateList( DEFAULT_NUM_REGIONS, sizeof( VSURFACE_REGION ) );
hVSurface->fFlags = 0;
// Get and Set palette, if attached, allow to fail
+3 -3
View File
@@ -5,6 +5,7 @@
#include "container.h"
#include "himage.h"
#include "vobject.h"
#include <vector>
///////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -105,7 +106,7 @@ typedef struct
UINT16 *p16BPPPalette; // A 16BPP palette used for 8->16 blits
COLORVAL TransparentColor; // Defaults to 0,0,0
PTR pClipper; // A void pointer encapsolated as a clipper Surface
HLIST RegionList; // A List of regions within the video Surface
std::vector<VSURFACE_REGION> RegionList; // A List of regions within the video Surface
} SGPVSurface, *HVSURFACE;
@@ -240,7 +241,6 @@ BOOLEAN DeleteVideoSurfaceFromIndex( UINT32 uiIndex );
BOOLEAN AddVSurfaceRegion( HVSURFACE hVSurface, VSURFACE_REGION *pNewRegion );
BOOLEAN AddVSurfaceRegionAtIndex( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *pNewRegion );
BOOLEAN AddVSurfaceRegions( HVSURFACE hVSurface, VSURFACE_REGION **ppNewRegions, UINT16 uiNumRegions );
BOOLEAN RemoveVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex );
BOOLEAN ClearAllVSurfaceRegions( HVSURFACE hVSurface );
BOOLEAN GetVSurfaceRegion( HVSURFACE hVSurface, UINT16 usIndex, VSURFACE_REGION *aRegion );
BOOLEAN GetNumRegions( HVSURFACE hVSurface , UINT32 *puiNumRegions );
@@ -286,4 +286,4 @@ BOOLEAN ShadowVideoSurfaceRectUsingLowPercentTable( UINT32 uiDestVSurface, INT32
#endif
*/
#endif
#endif