WIP: fix some memaccess-class warnings

This commit is contained in:
nillerusr 2022-11-16 13:28:39 +03:00
parent 8fbc002a37
commit db3062c60b
12 changed files with 78 additions and 35 deletions

View File

@ -11,6 +11,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "tier1/utlvector.h" #include "tier1/utlvector.h"
#include "tier1/memhelpers.h"
#ifdef COMPILER_MSVC #ifdef COMPILER_MSVC
#include <new> #include <new>
#endif #endif
@ -318,10 +319,10 @@ CPolyhedron *ClipPolyhedron( const CPolyhedron *pExistingPolyhedron, const float
pExistingPolyhedron->iPolygonCount ); pExistingPolyhedron->iPolygonCount );
} }
memcpy( pReturn->pVertices, pExistingPolyhedron->pVertices, sizeof( Vector ) * pReturn->iVertexCount ); memutils::copy( pReturn->pVertices, pExistingPolyhedron->pVertices, pReturn->iVertexCount );
memcpy( pReturn->pLines, pExistingPolyhedron->pLines, sizeof( Polyhedron_IndexedLine_t ) * pReturn->iLineCount ); memutils::copy( pReturn->pLines, pExistingPolyhedron->pLines, pReturn->iLineCount );
memcpy( pReturn->pIndices, pExistingPolyhedron->pIndices, sizeof( Polyhedron_IndexedLineReference_t ) * pReturn->iIndexCount ); memutils::copy( pReturn->pIndices, pExistingPolyhedron->pIndices, pReturn->iIndexCount );
memcpy( pReturn->pPolygons, pExistingPolyhedron->pPolygons, sizeof( Polyhedron_IndexedPolygon_t ) * pReturn->iPolygonCount ); memutils::copy( pReturn->pPolygons, pExistingPolyhedron->pPolygons, pReturn->iPolygonCount );
return pReturn; return pReturn;
} }

View File

@ -30,7 +30,7 @@
#include "materialsystem/deformations.h" #include "materialsystem/deformations.h"
#include "materialsystem/imaterialsystemhardwareconfig.h" #include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/IColorCorrection.h" #include "materialsystem/IColorCorrection.h"
#include "tier1/memhelpers.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// forward declarations // forward declarations
@ -1563,12 +1563,9 @@ public:
template< class E > inline E* IMatRenderContext::LockRenderDataTyped( int nCount, const E* pSrcData ) template< class E > inline E* IMatRenderContext::LockRenderDataTyped( int nCount, const E* pSrcData )
{ {
int nSizeInBytes = nCount * sizeof(E); E *pDstData = (E*)LockRenderData( nCount*sizeof(E) );
E *pDstData = (E*)LockRenderData( nSizeInBytes );
if ( pSrcData && pDstData ) if ( pSrcData && pDstData )
{ memutils::copy( pDstData, pSrcData, nCount );
memcpy( pDstData, pSrcData, nSizeInBytes );
}
return pDstData; return pDstData;
} }

View File

@ -20,6 +20,7 @@
#include "tier0/dbg.h" #include "tier0/dbg.h"
#include "tier1/utlsoacontainer.h" #include "tier1/utlsoacontainer.h"
#include "mathlib/ssemath.h" #include "mathlib/ssemath.h"
#include "tier1/memhelpers.h"
class CSIMDVectorMatrix class CSIMDVectorMatrix
{ {
@ -61,19 +62,19 @@ public:
// set up storage and fields for m x n matrix. destroys old data // set up storage and fields for m x n matrix. destroys old data
void SetSize( int width, int height ) void SetSize( int width, int height )
{ {
if ( ( ! m_pData ) || ( width != m_nWidth ) || ( height != m_nHeight ) ) if ( ( ! m_pData ) || ( width > m_nWidth ) || ( height > m_nHeight ) )
{ {
if ( m_pData ) if ( m_pData )
delete[] m_pData; delete[] m_pData;
m_nWidth = width;
m_nHeight = height;
m_nPaddedWidth = ( m_nWidth + 3) >> 2; m_nPaddedWidth = ( m_nWidth + 3) >> 2;
m_pData = NULL; m_pData = NULL;
if ( width && height ) if ( width && height )
m_pData = new FourVectors[ m_nPaddedWidth * m_nHeight ]; m_pData = new FourVectors[ m_nPaddedWidth * m_nHeight ];
} }
m_nWidth = width;
m_nHeight = height;
} }
CSIMDVectorMatrix( int width, int height ) CSIMDVectorMatrix( int width, int height )
@ -86,7 +87,8 @@ public:
{ {
SetSize( src.m_nWidth, src.m_nHeight ); SetSize( src.m_nWidth, src.m_nHeight );
if ( m_pData ) if ( m_pData )
memcpy( m_pData, src.m_pData, m_nHeight*m_nPaddedWidth*sizeof(m_pData[0]) ); memutils::copy( m_pData, src.m_pData, m_nHeight*m_nPaddedWidth );
return *this; return *this;
} }
@ -131,7 +133,9 @@ public:
void Clear( void ) void Clear( void )
{ {
Assert( m_pData ); Assert( m_pData );
memset( m_pData, 0, m_nHeight*m_nPaddedWidth*sizeof(m_pData[0]) );
static FourVectors value{Four_Zeros, Four_Zeros, Four_Zeros};
memutils::set( m_pData, value, m_nHeight*m_nPaddedWidth );
} }
void RaiseToPower( float power ); void RaiseToPower( float power );

View File

@ -2613,6 +2613,13 @@ public:
z=src.z; z=src.z;
} }
FourVectors( fltx4 x, fltx4 y, fltx4 z )
{
this->x=x;
this->y=y;
this->z=z;
}
FORCEINLINE void operator=( FourVectors const &src ) FORCEINLINE void operator=( FourVectors const &src )
{ {
x=src.x; x=src.x;

View File

@ -3298,17 +3298,19 @@ inline int Studio_LoadVertexes( const vertexFileHeader_t *pTempVvdHdr, vertexFil
} }
// copy vertexes // copy vertexes
// TODO(nillerusr): That sucks and needs to be fixed
memcpy( memcpy(
(mstudiovertex_t *)((byte *)pNewVvdHdr+pNewVvdHdr->vertexDataStart) + target, (byte*)((mstudiovertex_t *)((byte *)pNewVvdHdr+pNewVvdHdr->vertexDataStart) + target),
(mstudiovertex_t *)((byte *)pTempVvdHdr+pTempVvdHdr->vertexDataStart) + pFixupTable[i].sourceVertexID, (byte*)((mstudiovertex_t *)((byte *)pTempVvdHdr+pTempVvdHdr->vertexDataStart) + pFixupTable[i].sourceVertexID),
pFixupTable[i].numVertexes*sizeof(mstudiovertex_t) ); pFixupTable[i].numVertexes*sizeof(mstudiovertex_t) );
if (bNeedsTangentS) if (bNeedsTangentS)
{ {
// copy tangents // copy tangents
memcpy( memcpy(
(Vector4D *)((byte *)pNewVvdHdr+pNewVvdHdr->tangentDataStart) + target, (byte*)((Vector4D *)((byte *)pNewVvdHdr+pNewVvdHdr->tangentDataStart) + target),
(Vector4D *)((byte *)pTempVvdHdr+pTempVvdHdr->tangentDataStart) + pFixupTable[i].sourceVertexID, (byte*)((Vector4D *)((byte *)pTempVvdHdr+pTempVvdHdr->tangentDataStart) + pFixupTable[i].sourceVertexID),
pFixupTable[i].numVertexes*sizeof(Vector4D) ); pFixupTable[i].numVertexes*sizeof(Vector4D) );
} }

View File

@ -1266,12 +1266,12 @@ struct CPUInformation
uint8 m_nLogicalProcessors; // Number op logical processors. uint8 m_nLogicalProcessors; // Number op logical processors.
uint8 m_nPhysicalProcessors; // Number of physical processors uint8 m_nPhysicalProcessors; // Number of physical processors
bool m_bSSE3 : 1, bool m_bSSE3 : 1,
m_bSSSE3 : 1, m_bSSSE3 : 1,
m_bSSE4a : 1, m_bSSE4a : 1,
m_bSSE41 : 1, m_bSSE41 : 1,
m_bSSE42 : 1; m_bSSE42 : 1;
int64 m_Speed; // In cycles per second. int64 m_Speed; // In cycles per second.
@ -1280,7 +1280,7 @@ struct CPUInformation
uint32 m_nModel; uint32 m_nModel;
uint32 m_nFeatures[3]; uint32 m_nFeatures[3];
CPUInformation(): m_Size(0){} CPUInformation() = default;
}; };
// Have to return a pointer, not a reference, because references are not compatible with the // Have to return a pointer, not a reference, because references are not compatible with the

32
public/tier1/memhelpers.h Normal file
View File

@ -0,0 +1,32 @@
// ======= Copyright nillerusr, 2022 =======
// Helper аunctions for setting/сopying memory ( specially for non-POD types )
// FUCK STL
#ifndef MEMHELPERS_H
#define MEMHELPERS_H
namespace memutils
{
template<typename T>
inline void copy( T *dest, const T *src, size_t n )
{
do
{
--n;
*(dest+n) = *(src+n);
} while( n );
}
template<typename T>
inline void set( T *dest, T value, size_t n )
{
do
{
--n;
*(dest+n) = value;
} while( n );
}
}
#endif //MEMHELPERS_H

View File

@ -1039,10 +1039,6 @@ struct fluidparams_t
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
struct springparams_t struct springparams_t
{ {
springparams_t()
{
memset( this, 0, sizeof(*this) );
}
float constant; // spring constant float constant; // spring constant
float naturalLength;// relaxed length float naturalLength;// relaxed length
float damping; // damping factor float damping; // damping factor

View File

@ -36,7 +36,7 @@ int CopyLocalLightingState( int nMaxLights, LightDesc_t *pDest, int nLightCount,
for( int i = 0; i < nLightCount; i++ ) for( int i = 0; i < nLightCount; i++ )
{ {
LightDesc_t *pLight = &pDest[i]; LightDesc_t *pLight = &pDest[i];
memcpy( pLight, &pSrc[i], sizeof( LightDesc_t ) ); *pLight = pSrc[i];
pLight->m_Flags = 0; pLight->m_Flags = 0;
if( pLight->m_Attenuation0 != 0.0f ) if( pLight->m_Attenuation0 != 0.0f )
{ {
@ -539,4 +539,4 @@ void CStudioRenderContext::ComputeLightingConstDirectional( const Vector* pAmbie
// color from the ambient cube calculated in ComputeLightingCommon // color from the ambient cube calculated in ComputeLightingCommon
int index = ComputeLightingCommon( pAmbient, lightCount, pLights, pt, normal, m_pLightPos, lighting ); int index = ComputeLightingCommon( pAmbient, lightCount, pLights, pt, normal, m_pLightPos, lighting );
R_LightEffectsWorldFunctionTableConstDirectional::functions[index]( pLights, m_pLightPos, normal, lighting, flDirectionalAmount ); R_LightEffectsWorldFunctionTableConstDirectional::functions[index]( pLights, m_pLightPos, normal, lighting, flDirectionalAmount );
} }

View File

@ -19,6 +19,7 @@
#include "tier1/callqueue.h" #include "tier1/callqueue.h"
#include "cmodel.h" #include "cmodel.h"
#include "tier0/vprof.h" #include "tier0/vprof.h"
#include "tier1/memhelpers.h"
// memdbgon must be the last include file in a .cpp file!!! // memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h" #include "tier0/memdbgon.h"
@ -1994,7 +1995,7 @@ void CStudioRenderContext::SetAmbientLightColors( const Vector *pColors )
void CStudioRenderContext::SetAmbientLightColors( const Vector4D *pColors ) void CStudioRenderContext::SetAmbientLightColors( const Vector4D *pColors )
{ {
memcpy( m_RC.m_LightBoxColors, pColors, 6 * sizeof(Vector4D) ); memutils::copy( &m_RC.m_LightBoxColors[0], pColors, 6 );
// FIXME: Would like to get this into the render thread, but there's systemic confusion // FIXME: Would like to get this into the render thread, but there's systemic confusion
// about whether to set lighting state here or in the material system // about whether to set lighting state here or in the material system

View File

@ -498,9 +498,6 @@ const CPUInformation* GetCPUInformation()
if ( pi.m_Size == sizeof(pi) ) if ( pi.m_Size == sizeof(pi) )
return &pi; return &pi;
// Redundant, but just in case the user somehow messes with the size.
memset(&pi, 0x0, sizeof(pi));
// Fill out the structure, and return it: // Fill out the structure, and return it:
pi.m_Size = sizeof(pi); pi.m_Size = sizeof(pi);

View File

@ -69,7 +69,13 @@ void ComputeProjectionMatrix( VMatrix *pCameraToProjection, const Camera_t &came
float halfHeight = tan( flFOV * M_PI / 360.0 ); float halfHeight = tan( flFOV * M_PI / 360.0 );
float halfWidth = flApsectRatio * halfHeight; float halfWidth = flApsectRatio * halfHeight;
#endif #endif
memset( pCameraToProjection, 0, sizeof( VMatrix ) ); pCameraToProjection->Init(
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f,
0.f, 0.f, 0.f, 0.f
);
pCameraToProjection->m[0][0] = 1.0f / halfWidth; pCameraToProjection->m[0][0] = 1.0f / halfWidth;
pCameraToProjection->m[1][1] = 1.0f / halfHeight; pCameraToProjection->m[1][1] = 1.0f / halfHeight;
pCameraToProjection->m[2][2] = flZFar / ( flZNear - flZFar ); pCameraToProjection->m[2][2] = flZFar / ( flZNear - flZFar );