Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion source/client/cl_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3063,7 +3063,7 @@ static void CL_CheckForUpdate( void )
*/
static void *CL_AsyncStream_Alloc( size_t size, const char *filename, int fileline )
{
return _Mem_Alloc( zoneMemPool, size, 0, 0, filename, fileline );
return _Mem_Alloc( Mem_DefaultZonePool(), size, 0, 0, filename, fileline );
}

/*
Expand Down
49 changes: 18 additions & 31 deletions source/client/cl_vid.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ static void *VID_RefModule_MemAllocExt( mempool_t *pool, size_t size, size_t ali
return _Mem_AllocExt( pool, size, align, z, MEMPOOL_REFMODULE, 0, filename, fileline );
}

static void *VID_RefModule_MemAlloc(mempool_t *pool, size_t size, const char *filename, int fileline ) {
return _Mem_Alloc( pool, size,MEMPOOL_REFMODULE, 0, filename, fileline );
}

static void VID_RefModule_MemFree( void *data, const char *filename, int fileline ) {
_Mem_Free( data, MEMPOOL_REFMODULE, 0, filename, fileline );
}
Expand All @@ -299,6 +303,18 @@ static void VID_RefModule_MemEmptyPool( mempool_t *pool, const char *filename, i
_Mem_EmptyPool( pool, MEMPOOL_REFMODULE, 0, filename, fileline );
}

static struct mem_import_s vid_mem_import = {
._Mod_Mem_AllocExt = VID_RefModule_MemAllocExt,
._Mod_Mem_Alloc = VID_RefModule_MemAlloc,
._Mod_Mem_FreePool = VID_RefModule_MemFreePool,
._Mod_Mem_EmptyPool = VID_RefModule_MemEmptyPool,
._Mod_AllocPool = VID_RefModule_MemAllocPool,
._Mod_Free = VID_RefModule_MemFree,
._Mem_CopyString = _Mem_CopyString,
._Mem_CheckSentinels = _Mem_CheckSentinels,
.Mem_PoolTotalSize = Mem_PoolTotalSize
};

static struct cinematics_s *VID_RefModule_CIN_Open( const char *name, unsigned int start_time, bool *yuv, float *framerate )
{
return CIN_Open( name, start_time, CIN_LOOP, yuv, framerate );
Expand All @@ -317,6 +333,8 @@ static bool VID_LoadRefresh( const char *name )

VID_UnloadRefresh();

import.fsImport = &default_fs_imports_s;
import.memImport = &vid_mem_import;
import.Com_Error = &Com_Error;
import.Com_Printf = &Com_Printf;
import.Com_DPrintf = &Com_DPrintf;
Expand Down Expand Up @@ -345,44 +363,13 @@ static bool VID_LoadRefresh( const char *name )
import.Cmd_ExecuteText = &Cbuf_ExecuteText;
import.Cmd_SetCompletionFunc = &Cmd_SetCompletionFunc;

import.FS_FOpenFile = &FS_FOpenFile;
import.FS_FOpenAbsoluteFile = &FS_FOpenAbsoluteFile;
import.FS_Read = &FS_Read;
import.FS_Write = &FS_Write;
import.FS_Printf = &FS_Printf;
import.FS_Tell = &FS_Tell;
import.FS_Seek = &FS_Seek;
import.FS_Eof = &FS_Eof;
import.FS_Flush = &FS_Flush;
import.FS_FCloseFile = &FS_FCloseFile;
import.FS_RemoveFile = &FS_RemoveFile;
import.FS_GetFileList = &FS_GetFileList;
import.FS_GetGameDirectoryList = &FS_GetGameDirectoryList;
import.FS_FirstExtension = &FS_FirstExtension;
import.FS_MoveFile = &FS_MoveFile;
import.FS_IsUrl = &FS_IsUrl;
import.FS_FileMTime = &FS_FileMTime;
import.FS_RemoveDirectory = &FS_RemoveDirectory;
import.FS_GameDirectory = &FS_GameDirectory;
import.FS_WriteDirectory = &FS_WriteDirectory;
import.FS_MediaDirectory = &FS_MediaDirectory;
import.FS_AddFileToMedia = &FS_AddFileToMedia;

import.CIN_Open = &VID_RefModule_CIN_Open;
import.CIN_NeedNextFrame = &CIN_NeedNextFrame;
import.CIN_ReadNextFrame = &CIN_ReadNextFrame;
import.CIN_ReadNextFrameYUV = &CIN_ReadNextFrameYUV;
import.CIN_Reset = &CIN_Reset;
import.CIN_Close = &CIN_Close;

import.Mem_AllocPool = &VID_RefModule_MemAllocPool;
import.Mem_FreePool = &VID_RefModule_MemFreePool;
import.Mem_EmptyPool = &VID_RefModule_MemEmptyPool;
import.Mem_AllocExt = &VID_RefModule_MemAllocExt;
import.Mem_Free = &VID_RefModule_MemFree;
import.Mem_Realloc = &_Mem_Realloc;
import.Mem_PoolTotalSize = &Mem_PoolTotalSize;

import.Thread_Create = QThread_Create;
import.Thread_Join = QThread_Join;
import.Thread_Yield = QThread_Yield;
Expand Down
3 changes: 2 additions & 1 deletion source/qcommon/autoupdate.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/

#include "mod_mem.h"
#include "qcommon.h"
#include "asyncstream.h"

Expand Down Expand Up @@ -55,7 +56,7 @@ static void (*au_newfiles_callback)( void );
* AU_MemAlloc
*/
static void *_AU_MemAlloc( size_t size, const char *filename, int fileline ) {
return _Mem_Alloc( zoneMemPool, size, 0, 0, filename, fileline );
return _Mem_Alloc( Mem_DefaultZonePool(), size, 0, 0, filename, fileline );
}

/*
Expand Down
9 changes: 6 additions & 3 deletions source/qcommon/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

*/
// common.c -- misc functions used in client and server
#include "mod_mem.h"
#include "qcommon.h"
#include "l10n.h"
#if defined(__GNUC__) && defined(i386)
Expand Down Expand Up @@ -229,6 +230,7 @@ void Com_Printf( const char *format, ... )
va_start( argptr, format );
Q_vsnprintfz( msg, sizeof( msg ), format, argptr );
va_end( argptr );
printf("%s", msg);

QMutex_Lock( com_print_mutex );

Expand Down Expand Up @@ -308,6 +310,7 @@ void Com_Error( com_error_code_t code, const char *format, ... )
Q_vsnprintfz( msg, sizeof_msg, format, argptr );
va_end( argptr );

printf("%s", msg);
if( code == ERR_DROP )
{
Com_Printf( "********************\nERROR: %s\n********************\n", msg );
Expand Down Expand Up @@ -513,12 +516,12 @@ int Com_GlobMatch( const char *pattern, const char *text, const bool casecmp )

char *_ZoneCopyString( const char *str, const char *filename, int fileline )
{
return _Mem_CopyString( zoneMemPool, str, filename, fileline );
return _Mem_CopyString( Mem_DefaultZonePool(), str, filename, fileline );
}

char *_TempCopyString( const char *str, const char *filename, int fileline )
{
return _Mem_CopyString( tempMemPool, str, filename, fileline );
return _Mem_CopyString( Mem_DefaultTempPool(), str, filename, fileline );
}

void Info_Print( char *s )
Expand Down Expand Up @@ -574,7 +577,7 @@ void Com_AddPakToPureList( purelist_t **purelist, const char *pakname, const uns
purelist_t *purefile;
const size_t len = strlen( pakname ) + 1;

purefile = ( purelist_t* )Mem_Alloc( mempool ? mempool : zoneMemPool, sizeof( purelist_t ) + len );
purefile = ( purelist_t* )Mem_Alloc( mempool ? mempool : Mem_DefaultZonePool(), sizeof( purelist_t ) + len );
purefile->filename = ( char * )(( uint8_t * )purefile + sizeof( *purefile ));
memcpy( purefile->filename, pakname, len );
purefile->checksum = checksum;
Expand Down
2 changes: 1 addition & 1 deletion source/qcommon/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ static int _FS_LoadFile( int fhandle, unsigned int len, void **buffer, void *sta
if( stack && ( stackSize > len ) )
buf = ( uint8_t* )stack;
else
buf = ( uint8_t* )_Mem_AllocExt( tempMemPool, len + 1, 0, 0, 0, 0, filename, fileline );
buf = ( uint8_t* )_Mem_AllocExt( Mem_DefaultTempPool(), len + 1, 0, 0, 0, 0, filename, fileline );
buf[len] = 0;
*buffer = buf;

Expand Down
14 changes: 12 additions & 2 deletions source/qcommon/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,10 @@ static mempool_t *poolChain = NULL;
// used for temporary memory allocations around the engine, not for longterm
// storage, if anything in this pool stays allocated during gameplay, it is
// considered a leak
mempool_t *tempMemPool;
static mempool_t *tempMemPool;

// only for zone
mempool_t *zoneMemPool;
static mempool_t *zoneMemPool;

static qmutex_t *memMutex;

Expand Down Expand Up @@ -670,6 +670,16 @@ void Memory_Init( void )
memory_initialized = true;
}

mempool_t *Mem_DefaultTempPool()
{
return tempMemPool;
}

mempool_t *Mem_DefaultZonePool()
{
return zoneMemPool;
}

/*
* Memory_InitCommands
*/
Expand Down
Loading