Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Core/GameEngine/Include/Common/Radar.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,11 @@ class Radar : public Snapshot,
/// empty the entire shroud
virtual void clearShroud() = 0;

/// set the shroud level at shroud cell x,y
virtual void setShroudLevel( Int x, Int y, CellShroudStatus setting ) = 0;
/// TheSuperHackers @performance xezon 20/12/2025 Provides beginSetShroudLevel and endSetShroudLevel to improve performance.
/// Calling setShroudLevel many times is very expensive because it will lock a render resource on every call.
virtual void setShroudLevel( Int x, Int y, CellShroudStatus setting ) = 0; ///< set the shroud level at shroud cell x,y
virtual void beginSetShroudLevel() {} ///< call this once before multiple calls to setShroudLevel for better performance
virtual void endSetShroudLevel() {} ///< call this once after beginSetShroudLevel and setShroudLevel

protected:

Expand Down
9 changes: 8 additions & 1 deletion Core/GameEngineDevice/Include/W3DDevice/Common/W3DRadar.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

// FORWARD REFERENCES /////////////////////////////////////////////////////////////////////////////
class TextureClass;
class SurfaceClass;
class TerrainLogic;

// PROTOTYPES /////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -63,7 +64,9 @@ class W3DRadar : public Radar
virtual void draw( Int pixelX, Int pixelY, Int width, Int height ); ///< draw the radar

virtual void clearShroud();
virtual void setShroudLevel(Int x, Int y, CellShroudStatus setting);
virtual void setShroudLevel(Int x, Int y, CellShroudStatus setting); ///< set the shroud level at shroud cell x,y
virtual void beginSetShroudLevel(); ///< call this once before multiple calls to setShroudLevel for better performance
virtual void endSetShroudLevel(); ///< call this once after beginSetShroudLevel and setShroudLevel

virtual void refreshTerrain( TerrainLogic *terrain );
virtual void refreshObjects();
Expand Down Expand Up @@ -104,6 +107,10 @@ class W3DRadar : public Radar
WW3DFormat m_shroudTextureFormat; ///< format to use for shroud texture
Image *m_shroudImage; ///< shroud image abstraction for drawing
TextureClass *m_shroudTexture; ///< shroud texture
SurfaceClass *m_shroudSurface; ///< surface to shroud texture
void *m_shroudSurfaceBits; ///< shroud surface bits
int m_shroudSurfacePitch; ///< shroud surface pitch
UnsignedInt m_shroudSurfacePixelSize; ///< shroud surface pixel size

Int m_textureWidth; ///< width for all radar textures
Int m_textureHeight; ///< height for all radar textures
Expand Down
93 changes: 75 additions & 18 deletions Core/GameEngineDevice/Source/W3DDevice/Common/System/W3DRadar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
#include "W3DDevice/GameClient/W3DShroud.h"
#include "WW3D2/texture.h"
#include "WW3D2/dx8caps.h"
#include "WWMath/vector2i.h"



Expand Down Expand Up @@ -132,7 +133,7 @@ void W3DRadar::initializeTextureFormats( void )
}

//-------------------------------------------------------------------------------------------------
/** Delete resources used specifically in this W3D radar implemetation */
/** Delete resources used specifically in this W3D radar implementation */
//-------------------------------------------------------------------------------------------------
void W3DRadar::deleteResources( void )
{
Expand Down Expand Up @@ -167,6 +168,9 @@ void W3DRadar::deleteResources( void )
deleteInstance(m_shroudImage);
m_shroudImage = nullptr;

DEBUG_ASSERTCRASH(m_shroudSurface == NULL, ("W3DRadar::deleteResources: m_shroudSurface is expected NULL"));
DEBUG_ASSERTCRASH(m_shroudSurfaceBits == NULL, ("W3DRadar::deleteResources: m_shroudSurfaceBits is expected NULL"));

}

//-------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -844,6 +848,10 @@ W3DRadar::W3DRadar( void )
m_shroudTextureFormat = WW3D_FORMAT_UNKNOWN;
m_shroudImage = nullptr;
m_shroudTexture = nullptr;
m_shroudSurface = nullptr;
m_shroudSurfaceBits = nullptr;
m_shroudSurfacePitch = 0;
m_shroudSurfacePixelSize = 0;

m_textureWidth = RADAR_CELL_WIDTH;
m_textureHeight = RADAR_CELL_HEIGHT;
Expand Down Expand Up @@ -1301,9 +1309,6 @@ void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting
if (!shroud)
return;

SurfaceClass* surface = m_shroudTexture->Get_Surface_Level();
DEBUG_ASSERTCRASH( surface, ("W3DRadar: Can't get surface for Shroud texture") );

Int mapMinX = shroudX * shroud->getCellWidth();
Int mapMinY = shroudY * shroud->getCellHeight();
Int mapMaxX = (shroudX+1) * shroud->getCellWidth();
Expand All @@ -1315,21 +1320,19 @@ void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting
worldPoint.x = mapMinX;
worldPoint.y = mapMinY;
worldToRadar( &worldPoint, &radarPoint );
Int radarMinX = radarPoint.x;
Int radarMinY = radarPoint.y;
const Int radarMinX = radarPoint.x;
const Int radarMinY = radarPoint.y;

worldPoint.x = mapMaxX;
worldPoint.y = mapMaxY;
worldToRadar( &worldPoint, &radarPoint );
Int radarMaxX = radarPoint.x;
Int radarMaxY = radarPoint.y;
const Int radarMaxX = radarPoint.x;
const Int radarMaxY = radarPoint.y;

/*
Int radarMinX = REAL_TO_INT_FLOOR(mapMinX / getXSample());
Int radarMinY = REAL_TO_INT_FLOOR(mapMinY / getYSample());
Int radarMaxX = REAL_TO_INT_CEIL(mapMaxX / getXSample());
Int radarMaxY = REAL_TO_INT_CEIL(mapMaxY / getYSample());
*/
// Int radarMinX = REAL_TO_INT_FLOOR(mapMinX / getXSample());
// Int radarMinY = REAL_TO_INT_FLOOR(mapMinY / getYSample());
// Int radarMaxX = REAL_TO_INT_CEIL(mapMaxX / getXSample());
// Int radarMaxY = REAL_TO_INT_CEIL(mapMaxY / getYSample());

/// @todo srj -- this really needs to smooth the display!

Expand All @@ -1343,15 +1346,69 @@ void W3DRadar::setShroudLevel(Int shroudX, Int shroudY, CellShroudStatus setting
else
alpha = 0;

for( Int y = radarMinY; y <= radarMaxY; y++ )
if (m_shroudSurface == NULL)
{
for( Int x = radarMinX; x <= radarMaxX; x++ )
// This is expensive.
SurfaceClass* surface = m_shroudTexture->Get_Surface_Level();
DEBUG_ASSERTCRASH( surface, ("W3DRadar: Can't get surface for Shroud texture") );

for( Int y = radarMinY; y <= radarMaxY; y++ )
{
if( legalRadarPoint( x, y ) )
for( Int x = radarMinX; x <= radarMaxX; x++ )
{
surface->DrawPixel( x, y, GameMakeColor( 0, 0, 0, alpha ) );
}
}
REF_PTR_RELEASE(surface);
}
REF_PTR_RELEASE(surface);
else
{
// This is cheap.
DEBUG_ASSERTCRASH(m_shroudSurfaceBits != NULL, ("W3DRadar::setShroudLevel: m_shroudSurfaceBits is not expected NULL"));
DEBUG_ASSERTCRASH(m_shroudSurfacePixelSize != 0, ("W3DRadar::setShroudLevel: m_shroudSurfacePixelSize is not expected 0"));
const Color color = GameMakeColor( 0, 0, 0, alpha );

for( Int y = radarMinY; y <= radarMaxY; ++y )
{
UnsignedByte* row = static_cast<UnsignedByte*>(m_shroudSurfaceBits) + y * m_shroudSurfacePitch;
for( Int x = radarMinX; x <= radarMaxX; ++x )
{
UnsignedByte* column = row + x * m_shroudSurfacePixelSize;

switch (m_shroudSurfacePixelSize)
{
case 1: *column = (UnsignedByte)(color & 0xFF); break;
case 2: *reinterpret_cast<UnsignedShort*>(column) = (UnsignedShort)(color & 0xFFFF); break;
case 4: *reinterpret_cast<UnsignedInt*>(column) = (UnsignedInt)color; break;
}
}
}
}
}

void W3DRadar::beginSetShroudLevel()
{
DEBUG_ASSERTCRASH( m_shroudSurface == NULL, ("W3DRadar::beginSetShroudLevel: m_shroudSurface is expected NULL") );
m_shroudSurface = m_shroudTexture->Get_Surface_Level();
DEBUG_ASSERTCRASH( m_shroudSurface != NULL, ("W3DRadar::beginSetShroudLevel: Can't get surface for Shroud texture") );

SurfaceClass::SurfaceDescription sd;
m_shroudSurface->Get_Description(sd);
m_shroudSurfaceBits = m_shroudSurface->Lock(&m_shroudSurfacePitch);
m_shroudSurfacePixelSize = Get_Bytes_Per_Pixel(sd.Format);
}

void W3DRadar::endSetShroudLevel()
{
DEBUG_ASSERTCRASH( m_shroudSurface != NULL, ("W3DRadar::endSetShroudLevel: m_shroudSurface is not expected NULL") );
if (m_shroudSurfaceBits != NULL)
{
m_shroudSurface->Unlock();
m_shroudSurfaceBits = NULL;
m_shroudSurfacePitch = 0;
m_shroudSurfacePixelSize = 0;
}
REF_PTR_RELEASE(m_shroudSurface);
}

//-------------------------------------------------------------------------------------------------
Expand Down
92 changes: 28 additions & 64 deletions Core/Libraries/Source/WWVegas/WW3D2/surfaceclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
* SurfaceClass::Clear -- Clears a surface to 0 *
* SurfaceClass::Copy -- Copies a region from one surface to another of the same format *
* SurfaceClass::FindBBAlpha -- Finds the bounding box of non zero pixels in the region (x0, *
* PixelSize -- Helper Function to find the size in bytes of a pixel *
* SurfaceClass::Is_Transparent_Column -- Tests to see if the column is transparent or not *
* SurfaceClass::Copy -- Copies from a byte array to the surface *
* SurfaceClass::CreateCopy -- Creates a byte array copy of the surface *
Expand All @@ -56,57 +55,6 @@
#include "bound.h"
#include <d3dx8.h>

/***********************************************************************************************
* PixelSize -- Helper Function to find the size in bytes of a pixel *
* *
* *
* *
* *
* INPUT: *
* *
* OUTPUT: *
* *
* WARNINGS: *
* *
* HISTORY: *
* 2/13/2001 hy : Created. *
*=============================================================================================*/

unsigned int PixelSize(const SurfaceClass::SurfaceDescription &sd)
{
unsigned int size=0;

switch (sd.Format)
{
case WW3D_FORMAT_A8R8G8B8:
case WW3D_FORMAT_X8R8G8B8:
size=4;
break;
case WW3D_FORMAT_R8G8B8:
size=3;
break;
case WW3D_FORMAT_R5G6B5:
case WW3D_FORMAT_X1R5G5B5:
case WW3D_FORMAT_A1R5G5B5:
case WW3D_FORMAT_A4R4G4B4:
case WW3D_FORMAT_A8R3G3B2:
case WW3D_FORMAT_X4R4G4B4:
case WW3D_FORMAT_A8P8:
case WW3D_FORMAT_A8L8:
size=2;
break;
case WW3D_FORMAT_R3G3B2:
case WW3D_FORMAT_A8:
case WW3D_FORMAT_P8:
case WW3D_FORMAT_L8:
case WW3D_FORMAT_A4L4:
size=1;
break;
}

return size;
}

void Convert_Pixel(Vector3 &rgb, const SurfaceClass::SurfaceDescription &sd, const unsigned char * pixel)
{
const float scale=1/255.0f;
Expand Down Expand Up @@ -257,7 +205,7 @@ void SurfaceClass::Get_Description(SurfaceDescription &surface_desc)
surface_desc.Width = d3d_desc.Width;
}

void * SurfaceClass::Lock(int * pitch)
void *SurfaceClass::Lock(int *pitch)
{
D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand All @@ -266,6 +214,22 @@ void * SurfaceClass::Lock(int * pitch)
return (void *)lock_rect.pBits;
}

void *SurfaceClass::Lock(int *pitch, const Vector2i &min, const Vector2i &max)
{
D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));

RECT rect;
rect.left = min.I;
rect.top = min.J;
rect.right = max.I;
rect.bottom = max.J;
DX8_ErrorCode(D3DSurface->LockRect(&lock_rect, &rect, 0));

*pitch = lock_rect.Pitch;
return (void *)lock_rect.pBits;
}

void SurfaceClass::Unlock(void)
{
DX8_ErrorCode(D3DSurface->UnlockRect());
Expand All @@ -292,7 +256,7 @@ void SurfaceClass::Clear()
Get_Description(sd);

// size of each pixel in bytes
unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -331,7 +295,7 @@ void SurfaceClass::Copy(const unsigned char *other)
Get_Description(sd);

// size of each pixel in bytes
unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -364,13 +328,13 @@ void SurfaceClass::Copy(const unsigned char *other)
* HISTORY: *
* 5/2/2001 hy : Created. *
*=============================================================================================*/
void SurfaceClass::Copy(Vector2i &min,Vector2i &max, const unsigned char *other)
void SurfaceClass::Copy(const Vector2i &min, const Vector2i &max, const unsigned char *other)
{
SurfaceDescription sd;
Get_Description(sd);

// size of each pixel in bytes
unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -415,7 +379,7 @@ unsigned char *SurfaceClass::CreateCopy(int *width,int *height,int*size,bool fli
Get_Description(sd);

// size of each pixel in bytes
unsigned int mysize=PixelSize(sd);
unsigned int mysize=Get_Bytes_Per_Pixel(sd.Format);

*width=sd.Width;
*height=sd.Height;
Expand Down Expand Up @@ -595,7 +559,7 @@ void SurfaceClass::FindBB(Vector2i *min,Vector2i*max)
DX8_ErrorCode(D3DSurface->LockRect(&lock_rect,&rect,D3DLOCK_READONLY));

int x,y;
unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);
Vector2i realmin=*max;
Vector2i realmax=*min;

Expand Down Expand Up @@ -658,7 +622,7 @@ bool SurfaceClass::Is_Transparent_Column(unsigned int column)
break;
}

unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -808,7 +772,7 @@ void SurfaceClass::DrawPixel(const unsigned int x,const unsigned int y, unsigned
SurfaceDescription sd;
Get_Description(sd);

unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -862,7 +826,7 @@ void SurfaceClass::DrawHLine(const unsigned int y,const unsigned int x1, const u
SurfaceDescription sd;
Get_Description(sd);

unsigned int size=PixelSize(sd);
unsigned int size=Get_Bytes_Per_Pixel(sd.Format);

D3DLOCKED_RECT lock_rect;
::ZeroMemory(&lock_rect, sizeof(D3DLOCKED_RECT));
Expand Down Expand Up @@ -963,7 +927,7 @@ bool SurfaceClass::Is_Monochrome(void)

int pitch,size;

size=PixelSize(sd);
size=Get_Bytes_Per_Pixel(sd.Format);
unsigned char *bits=(unsigned char*) Lock(&pitch);

Vector3 rgb;
Expand Down Expand Up @@ -1013,7 +977,7 @@ void SurfaceClass::Hue_Shift(const Vector3 &hsv_shift)
Get_Description(sd);
int pitch,size;

size=PixelSize(sd);
size=Get_Bytes_Per_Pixel(sd.Format);
unsigned char *bits=(unsigned char*) Lock(&pitch);

Vector3 rgb;
Expand Down
Loading
Loading