mirror of
https://github.com/nillerusr/source-engine.git
synced 2026-08-08 01:39:36 +00:00
vphysics: fix saverestore
This commit is contained in:
+54
-23
@@ -1,24 +1,23 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//===========================================================================//
|
||||
|
||||
#include "mempool.h"
|
||||
#include "tier1/mempool.h"
|
||||
#include <stdio.h>
|
||||
#ifdef OSX
|
||||
#include <malloc/malloc.h>
|
||||
#else
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
#include <memory.h>
|
||||
#include "tier0/dbg.h"
|
||||
#include <ctype.h>
|
||||
#include "tier1/strtools.h"
|
||||
|
||||
#ifndef _PS3
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
// Should be last include
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
MemoryPoolReportFunc_t CUtlMemoryPool::g_ReportFunc = 0;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -36,7 +35,7 @@ void CUtlMemoryPool::SetErrorReportFunc( MemoryPoolReportFunc_t func )
|
||||
CUtlMemoryPool::CUtlMemoryPool( int blockSize, int numElements, int growMode, const char *pszAllocOwner, int nAlignment )
|
||||
{
|
||||
#ifdef _X360
|
||||
if( numElements > 0 && growMode != UTLMEMORYPOOL_GROW_NONE )
|
||||
if( numElements > 0 && growMode != GROW_NONE )
|
||||
{
|
||||
numElements = 1;
|
||||
}
|
||||
@@ -100,18 +99,40 @@ void CUtlMemoryPool::Clear()
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Is an allocation within the pool?
|
||||
//-----------------------------------------------------------------------------
|
||||
bool CUtlMemoryPool::IsAllocationWithinPool( void *pMem ) const
|
||||
{
|
||||
for( CBlob *pCur = m_BlobHead.m_pNext; pCur != &m_BlobHead; pCur = pCur->m_pNext )
|
||||
{
|
||||
// Is the allocation within the blob?
|
||||
if ( ( pMem < pCur->m_Data ) || ( pMem >= pCur->m_Data + pCur->m_NumBytes ) )
|
||||
continue;
|
||||
|
||||
// Make sure the allocation is on a block boundary
|
||||
intp pFirstAllocation = AlignValue( ( intp ) pCur->m_Data, m_nAlignment );
|
||||
|
||||
intp nOffset = (intp)pMem - pFirstAllocation;
|
||||
return ( nOffset % m_BlockSize ) == 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Reports memory leaks
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void CUtlMemoryPool::ReportLeaks()
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
if (!g_ReportFunc)
|
||||
return;
|
||||
|
||||
g_ReportFunc("Memory leak: mempool blocks left in memory: %d\n", m_BlocksAllocated);
|
||||
|
||||
#ifdef _DEBUG
|
||||
// walk and destroy the free list so it doesn't intefere in the scan
|
||||
while (m_pHeadOfFreeList != NULL)
|
||||
{
|
||||
@@ -132,7 +153,7 @@ void CUtlMemoryPool::ReportLeaks()
|
||||
while (scanPoint < scanEnd)
|
||||
{
|
||||
// search for and dump any strings
|
||||
if ((unsigned)(*scanPoint + 1) <= 256 && isprint(*scanPoint))
|
||||
if ((unsigned)(*scanPoint + 1) <= 256 && V_isprint(*scanPoint))
|
||||
{
|
||||
g_ReportFunc("%c", *scanPoint);
|
||||
needSpace = true;
|
||||
@@ -161,18 +182,18 @@ void CUtlMemoryPool::AddNewBlob()
|
||||
|
||||
int sizeMultiplier;
|
||||
|
||||
if( m_GrowMode == UTLMEMORYPOOL_GROW_SLOW )
|
||||
if( m_GrowMode == GROW_SLOW )
|
||||
{
|
||||
sizeMultiplier = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( m_GrowMode == UTLMEMORYPOOL_GROW_NONE )
|
||||
if ( m_GrowMode == GROW_NONE )
|
||||
{
|
||||
// Can only have one allocation when we're in this mode
|
||||
if( m_NumBlobs != 0 )
|
||||
{
|
||||
Assert( !"CUtlMemoryPool::AddNewBlob: mode == UTLMEMORYPOOL_GROW_NONE" );
|
||||
Assert( !"CUtlMemoryPool::AddNewBlob: mode == GROW_NONE" );
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -230,15 +251,15 @@ void *CUtlMemoryPool::Alloc( size_t amount )
|
||||
{
|
||||
void *returnBlock;
|
||||
|
||||
if ( amount > (unsigned int)m_BlockSize )
|
||||
if ( amount > (size_t)m_BlockSize )
|
||||
return NULL;
|
||||
|
||||
if( !m_pHeadOfFreeList )
|
||||
if ( !m_pHeadOfFreeList )
|
||||
{
|
||||
// returning NULL is fine in UTLMEMORYPOOL_GROW_NONE
|
||||
if( m_GrowMode == UTLMEMORYPOOL_GROW_NONE )
|
||||
// returning NULL is fine in GROW_NONE
|
||||
if ( m_GrowMode == GROW_NONE && m_NumBlobs > 0 )
|
||||
{
|
||||
//Assert( !"CUtlMemoryPool::Alloc: tried to make new blob with UTLMEMORYPOOL_GROW_NONE" );
|
||||
//Assert( !"CUtlMemoryPool::Alloc: tried to make new blob with GROW_NONE" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -246,14 +267,14 @@ void *CUtlMemoryPool::Alloc( size_t amount )
|
||||
AddNewBlob();
|
||||
|
||||
// still failure, error out
|
||||
if( !m_pHeadOfFreeList )
|
||||
if ( !m_pHeadOfFreeList )
|
||||
{
|
||||
Assert( !"CUtlMemoryPool::Alloc: ran out of memory" );
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
m_BlocksAllocated++;
|
||||
m_PeakAlloc = max(m_PeakAlloc, m_BlocksAllocated);
|
||||
m_PeakAlloc = MAX(m_PeakAlloc, m_BlocksAllocated);
|
||||
|
||||
returnBlock = m_pHeadOfFreeList;
|
||||
|
||||
@@ -272,7 +293,7 @@ void *CUtlMemoryPool::AllocZero( size_t amount )
|
||||
void *mem = Alloc( amount );
|
||||
if ( mem )
|
||||
{
|
||||
V_memset( mem, 0x00, amount );
|
||||
V_memset( mem, 0x00, ( int )amount );
|
||||
}
|
||||
return mem;
|
||||
}
|
||||
@@ -313,4 +334,14 @@ void CUtlMemoryPool::Free( void *memBlock )
|
||||
m_pHeadOfFreeList = memBlock;
|
||||
}
|
||||
|
||||
int CUtlMemoryPool::Size() const
|
||||
{
|
||||
uint32 size = 0;
|
||||
|
||||
for( CBlob *pCur=m_BlobHead.m_pNext; pCur != &m_BlobHead; pCur=pCur->m_pNext )
|
||||
{
|
||||
size += pCur->m_NumBytes;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user