Browse Source

engine: replace pool pointer by pool handle

pull/2/head
Alibek Omarov 4 years ago committed by Alibek Omarov #SupportRMS
parent
commit
9313f7e80e
  1. 2
      common/com_model.h
  2. 1
      common/xash3d_types.h
  3. 6
      engine/client/client.h
  4. 2
      engine/client/in_touch.c
  5. 2
      engine/client/ref_common.c
  6. 2
      engine/client/s_main.c
  7. 2
      engine/client/sound.h
  8. 4
      engine/common/common.c
  9. 22
      engine/common/common.h
  10. 4
      engine/common/filesystem.c
  11. 6
      engine/common/mod_bmodel.c
  12. 2
      engine/common/mod_local.h
  13. 2
      engine/common/model.c
  14. 2
      engine/common/net_chan.c
  15. 68
      engine/common/zone.c
  16. 10
      engine/ref_api.h
  17. 4
      engine/server/server.h
  18. 2
      ref_gl/gl_local.h
  19. 2
      ref_gl/gl_opengl.c
  20. 2
      ref_gl/gl_rsurf.c
  21. 2
      ref_soft/r_context.c
  22. 2
      ref_soft/r_local.h

2
common/com_model.h

@ -291,7 +291,7 @@ typedef struct model_s @@ -291,7 +291,7 @@ typedef struct model_s
// shared modelinfo
modtype_t type; // model type
int numframes; // sprite's framecount
byte *mempool; // private mempool (was synctype)
poolhandle_t mempool; // private mempool (was synctype)
int flags; // hl compatibility
//

1
common/xash3d_types.h

@ -20,6 +20,7 @@ typedef byte rgba_t[4]; // unsigned byte colorpack @@ -20,6 +20,7 @@ typedef byte rgba_t[4]; // unsigned byte colorpack
typedef byte rgb_t[3]; // unsigned byte colorpack
typedef vec_t matrix3x4[3][4];
typedef vec_t matrix4x4[4][4];
typedef uint32_t poolhandle_t;
#undef true
#undef false

6
engine/client/client.h

@ -437,7 +437,7 @@ typedef struct @@ -437,7 +437,7 @@ typedef struct
void *hInstance; // pointer to client.dll
cldll_func_t dllFuncs; // dll exported funcs
render_interface_t drawFuncs; // custom renderer support
byte *mempool; // client edicts pool
poolhandle_t mempool; // client edicts pool
string mapname; // map name
string maptitle; // display map title
string itemspath; // path to items description for auto-complete func
@ -496,7 +496,7 @@ typedef struct @@ -496,7 +496,7 @@ typedef struct
void *hInstance; // pointer to client.dll
UI_FUNCTIONS dllFuncs; // dll exported funcs
UI_EXTENDED_FUNCTIONS dllFuncs2; // fwgs extension
byte *mempool; // client edicts pool
poolhandle_t mempool; // client edicts pool
cl_entity_t playermodel; // uiPlayerSetup drawing model
player_info_t playerinfo; // local playerinfo
@ -534,7 +534,7 @@ typedef struct @@ -534,7 +534,7 @@ typedef struct
keydest_t key_dest;
byte *mempool; // client premamnent pool: edicts etc
poolhandle_t mempool; // client premamnent pool: edicts etc
netadr_t hltv_listen_address;

2
engine/client/in_touch.c

@ -95,7 +95,7 @@ struct touch_s @@ -95,7 +95,7 @@ struct touch_s
qboolean initialized;
qboolean config_loaded;
touchbuttonlist_t list_user, list_edit;
byte *mempool;
poolhandle_t mempool;
touchState state;
int look_finger;

2
engine/client/ref_common.c

@ -178,7 +178,7 @@ static int pfnGetStudioModelInterface( int version, struct r_studio_interface_s @@ -178,7 +178,7 @@ static int pfnGetStudioModelInterface( int version, struct r_studio_interface_s
0;
}
static byte *pfnImage_GetPool( void )
static poolhandle_t pfnImage_GetPool( void )
{
return host.imagepool;
}

2
engine/client/s_main.c

@ -23,7 +23,7 @@ GNU General Public License for more details. @@ -23,7 +23,7 @@ GNU General Public License for more details.
#define SND_CLIP_DISTANCE 1000.0f
dma_t dma;
byte *sndpool;
poolhandle_t sndpool;
static soundfade_t soundfade;
channel_t channels[MAX_CHANNELS];
sound_t ambient_sfx[NUM_AMBIENTS];

2
engine/client/sound.h

@ -16,7 +16,7 @@ GNU General Public License for more details. @@ -16,7 +16,7 @@ GNU General Public License for more details.
#ifndef SOUND_H
#define SOUND_H
extern byte *sndpool;
extern poolhandle_t sndpool;
#include "xash3d_mathlib.h"

4
engine/common/common.c

@ -842,7 +842,7 @@ Cache_Check @@ -842,7 +842,7 @@ Cache_Check
consistency check
====================
*/
void *Cache_Check( byte *mempool, cache_user_t *c )
void *Cache_Check( poolhandle_t mempool, cache_user_t *c )
{
if( !c->data )
return NULL;
@ -1177,7 +1177,7 @@ qboolean COM_IsSafeFileToDownload( const char *filename ) @@ -1177,7 +1177,7 @@ qboolean COM_IsSafeFileToDownload( const char *filename )
return true;
}
char *_copystring( byte *mempool, const char *s, const char *filename, int fileline )
char *_copystring( poolhandle_t mempool, const char *s, const char *filename, int fileline )
{
char *b;

22
engine/common/common.h

@ -392,7 +392,7 @@ typedef struct host_parm_s @@ -392,7 +392,7 @@ typedef struct host_parm_s
uint type; // running at
jmp_buf abortframe; // abort current frame
dword errorframe; // to prevent multiple host error
byte *mempool; // static mempool for misc allocations
poolhandle_t mempool; // static mempool for misc allocations
string finalmsg; // server shutdown final message
string downloadfile; // filename to be downloading
int downloadcount; // how many files remain to downloading
@ -446,8 +446,8 @@ typedef struct host_parm_s @@ -446,8 +446,8 @@ typedef struct host_parm_s
char rootdir[MAX_OSPATH]; // member root directory
char rodir[MAX_OSPATH]; // readonly root
char gamefolder[MAX_QPATH]; // it's a default gamefolder
byte *imagepool; // imagelib mempool
byte *soundpool; // soundlib mempool
poolhandle_t imagepool; // imagelib mempool
poolhandle_t soundpool; // soundlib mempool
uint features; // custom features that enables by mod-maker request
@ -505,14 +505,14 @@ void Cmd_ForwardToServer( void ); @@ -505,14 +505,14 @@ void Cmd_ForwardToServer( void );
// zone.c
//
void Memory_Init( void );
void *_Mem_Realloc( byte *poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void *_Mem_Alloc( byte *poolptr, size_t size, qboolean clear, const char *filename, int fileline );
byte *_Mem_AllocPool( const char *name, const char *filename, int fileline );
void _Mem_FreePool( byte **poolptr, const char *filename, int fileline );
void _Mem_EmptyPool( byte *poolptr, const char *filename, int fileline );
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline );
poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline );
void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline );
void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline );
void _Mem_Free( void *data, const char *filename, int fileline );
void _Mem_Check( const char *filename, int fileline );
qboolean Mem_IsAllocatedExt( byte *poolptr, void *data );
qboolean Mem_IsAllocatedExt( poolhandle_t poolptr, void *data );
void Mem_PrintList( size_t minallocationsize );
void Mem_PrintStats( void );
@ -746,7 +746,7 @@ cvar_t *pfnCVarGetPointer( const char *szVarName ); @@ -746,7 +746,7 @@ cvar_t *pfnCVarGetPointer( const char *szVarName );
int pfnDrawConsoleString( int x, int y, char *string );
void pfnDrawSetTextColor( float r, float g, float b );
void pfnDrawConsoleStringLen( const char *pText, int *length, int *height );
void *Cache_Check( byte *mempool, struct cache_user_s *c );
void *Cache_Check( poolhandle_t mempool, struct cache_user_s *c );
void COM_TrimSpace( const char *source, char *dest );
edict_t* pfnPEntityOfEntIndex( int iEntIndex );
void pfnGetModelBounds( model_t *mod, float *mins, float *maxs );
@ -765,7 +765,7 @@ float pfnTime( void ); @@ -765,7 +765,7 @@ float pfnTime( void );
#define copystring( s ) _copystring( host.mempool, s, __FILE__, __LINE__ )
#define SV_CopyString( s ) _copystring( svgame.stringspool, s, __FILE__, __LINE__ )
#define freestring( s ) if( s != NULL ) { Mem_Free( s ); s = NULL; }
char *_copystring( byte *mempool, const char *s, const char *filename, int fileline );
char *_copystring( poolhandle_t mempool, const char *s, const char *filename, int fileline );
// CS:CS engfuncs (stubs)
void *pfnSequenceGet( const char *fileName, const char *entryName );

4
engine/common/filesystem.c

@ -101,7 +101,7 @@ struct wfile_s @@ -101,7 +101,7 @@ struct wfile_s
string filename;
int infotableofs;
int numlumps;
byte *mempool; // W_ReadLump temp buffers
poolhandle_t mempool; // W_ReadLump temp buffers
file_t *handle;
dlumpinfo_t *lumps;
time_t filetime;
@ -144,7 +144,7 @@ typedef struct searchpath_s @@ -144,7 +144,7 @@ typedef struct searchpath_s
struct searchpath_s *next;
} searchpath_t;
static byte *fs_mempool;
static poolhandle_t fs_mempool;
static searchpath_t *fs_searchpaths = NULL; // chain
static searchpath_t fs_directpath; // static direct path
static char fs_basedir[MAX_SYSPATH]; // base game directory

6
engine/common/mod_bmodel.c

@ -1305,7 +1305,7 @@ static void Mod_MakeHull0( void ) @@ -1305,7 +1305,7 @@ static void Mod_MakeHull0( void )
Mod_SetupHull
=================
*/
static void Mod_SetupHull( dbspmodel_t *bmod, model_t *mod, byte *mempool, int headnode, int hullnum )
static void Mod_SetupHull( dbspmodel_t *bmod, model_t *mod, poolhandle_t mempool, int headnode, int hullnum )
{
hull_t *hull = &mod->hulls[hullnum];
int count;
@ -1469,7 +1469,7 @@ for embedded submodels @@ -1469,7 +1469,7 @@ for embedded submodels
static void Mod_SetupSubmodels( dbspmodel_t *bmod )
{
qboolean colored = false;
byte *mempool;
poolhandle_t mempool;
char *ents;
model_t *mod;
dmodel_t *bm;
@ -1550,7 +1550,7 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod ) @@ -1550,7 +1550,7 @@ static void Mod_SetupSubmodels( dbspmodel_t *bmod )
loadmodel = Mod_FindName( name, true );
*loadmodel = *mod;
Q_strncpy( loadmodel->name, name, sizeof( loadmodel->name ));
loadmodel->mempool = NULL;
loadmodel->mempool = 0;
mod = loadmodel;
}
}

2
engine/common/mod_local.h

@ -117,7 +117,7 @@ typedef struct world_static_s @@ -117,7 +117,7 @@ typedef struct world_static_s
#ifndef REF_DLL
extern world_static_t world;
extern byte *com_studiocache;
extern poolhandle_t com_studiocache;
extern model_t *loadmodel;
extern convar_t *mod_studiocache;
extern convar_t *r_wadtextures;

2
engine/common/model.c

@ -27,7 +27,7 @@ GNU General Public License for more details. @@ -27,7 +27,7 @@ GNU General Public License for more details.
static model_info_t mod_crcinfo[MAX_MODELS];
static model_t mod_known[MAX_MODELS];
static int mod_numknown = 0;
byte *com_studiocache; // cache for submodels
poolhandle_t com_studiocache; // cache for submodels
convar_t *mod_studiocache;
convar_t *r_wadtextures;
convar_t *r_showhull;

2
engine/common/net_chan.c

@ -92,7 +92,7 @@ convar_t *net_qport; @@ -92,7 +92,7 @@ convar_t *net_qport;
int net_drop;
netadr_t net_from;
sizebuf_t net_message;
byte *net_mempool;
static poolhandle_t net_mempool;
byte net_message_buffer[NET_MAX_MESSAGE];
const char *ns_strings[NS_COUNT] =

68
engine/common/zone.c

@ -50,19 +50,44 @@ typedef struct mempool_s @@ -50,19 +50,44 @@ typedef struct mempool_s
struct mempool_s *next; // linked into global mempool list
const char *filename; // file name and line where Mem_AllocPool was called
int fileline;
poolhandle_t idx;
char name[64]; // name of the pool
uint sentinel2; // should always be MEMHEADER_SENTINEL1
} mempool_t;
mempool_t *poolchain = NULL; // critical stuff
static mempool_t *poolchain = NULL; // critical stuff
void *_Mem_Alloc( byte *poolptr, size_t size, qboolean clear, const char *filename, int fileline )
// a1ba: due to mempool being passed with the model through reused 32-bit field
// which makes engine incompatible with 64-bit pointers I changed mempool type
// from pointer to 32-bit handle, thankfully mempool structure is private
// But! Mempools are handled through linked list so we can't index them safely
static uint lastidx = 0;
static mempool_t *Mem_FindPool( poolhandle_t poolptr )
{
mempool_t *pool;
for( pool = poolchain; pool; pool = pool->next )
{
if( pool->idx == poolptr )
return pool;
}
Sys_Error( "%s: not allocated or double freed pool %d", __FUNCTION__, poolptr );
return NULL;
}
void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline )
{
memheader_t *mem;
mempool_t *pool = (mempool_t *)poolptr;
mempool_t *pool;
if( size <= 0 ) return NULL;
if( poolptr == NULL ) Sys_Error( "Mem_Alloc: pool == NULL (alloc at %s:%i)\n", filename, fileline );
if( !poolptr ) Sys_Error( "Mem_Alloc: pool == NULL (alloc at %s:%i)\n", filename, fileline );
pool = Mem_FindPool( poolptr );
pool->totalsize += size;
// big allocations are not clumped
@ -147,7 +172,7 @@ void _Mem_Free( void *data, const char *filename, int fileline ) @@ -147,7 +172,7 @@ void _Mem_Free( void *data, const char *filename, int fileline )
Mem_FreeBlock((memheader_t *)((byte *)data - sizeof( memheader_t )), filename, fileline );
}
void *_Mem_Realloc( byte *poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline )
{
memheader_t *memhdr = NULL;
char *nb;
@ -172,12 +197,16 @@ void *_Mem_Realloc( byte *poolptr, void *memptr, size_t size, qboolean clear, co @@ -172,12 +197,16 @@ void *_Mem_Realloc( byte *poolptr, void *memptr, size_t size, qboolean clear, co
return (void *)nb;
}
byte *_Mem_AllocPool( const char *name, const char *filename, int fileline )
poolhandle_t _Mem_AllocPool( const char *name, const char *filename, int fileline )
{
mempool_t *pool;
pool = (mempool_t *)Q_malloc( sizeof( mempool_t ));
if( pool == NULL ) Sys_Error( "Mem_AllocPool: out of memory (allocpool at %s:%i)\n", filename, fileline );
if( pool == NULL )
{
Sys_Error( "Mem_AllocPool: out of memory (allocpool at %s:%i)\n", filename, fileline );
return 0;
}
memset( pool, 0, sizeof( mempool_t ));
// fill header
@ -190,17 +219,18 @@ byte *_Mem_AllocPool( const char *name, const char *filename, int fileline ) @@ -190,17 +219,18 @@ byte *_Mem_AllocPool( const char *name, const char *filename, int fileline )
pool->realsize = sizeof( mempool_t );
Q_strncpy( pool->name, name, sizeof( pool->name ));
pool->next = poolchain;
pool->idx = ++lastidx;
poolchain = pool;
return (byte *)pool;
return pool->idx;
}
void _Mem_FreePool( byte **poolptr, const char *filename, int fileline )
void _Mem_FreePool( poolhandle_t *poolptr, const char *filename, int fileline )
{
mempool_t *pool = (mempool_t *)*poolptr;
mempool_t *pool;
mempool_t **chainaddress;
if( pool )
if( *poolptr && ( pool = Mem_FindPool( *poolptr )))
{
// unlink pool from chain
for( chainaddress = &poolchain; *chainaddress && *chainaddress != pool; chainaddress = &((*chainaddress)->next));
@ -214,14 +244,14 @@ void _Mem_FreePool( byte **poolptr, const char *filename, int fileline ) @@ -214,14 +244,14 @@ void _Mem_FreePool( byte **poolptr, const char *filename, int fileline )
// free the pool itself
memset( pool, 0xBF, sizeof( mempool_t ));
Q_free( pool );
*poolptr = NULL;
*poolptr = 0;
}
}
void _Mem_EmptyPool( byte *poolptr, const char *filename, int fileline )
void _Mem_EmptyPool( poolhandle_t poolptr, const char *filename, int fileline )
{
mempool_t *pool = (mempool_t *)poolptr;
if( poolptr == NULL ) Sys_Error( "Mem_EmptyPool: pool == NULL (emptypool at %s:%i)\n", filename, fileline );
mempool_t *pool = Mem_FindPool( poolptr );
if( !poolptr ) Sys_Error( "Mem_EmptyPool: pool == NULL (emptypool at %s:%i)\n", filename, fileline );
if( pool->sentinel1 != MEMHEADER_SENTINEL1 ) Sys_Error( "Mem_EmptyPool: trashed pool sentinel 1 (allocpool at %s:%i, emptypool at %s:%i)\n", pool->filename, pool->fileline, filename, fileline );
if( pool->sentinel2 != MEMHEADER_SENTINEL1 ) Sys_Error( "Mem_EmptyPool: trashed pool sentinel 2 (allocpool at %s:%i, emptypool at %s:%i)\n", pool->filename, pool->fileline, filename, fileline );
@ -230,7 +260,7 @@ void _Mem_EmptyPool( byte *poolptr, const char *filename, int fileline ) @@ -230,7 +260,7 @@ void _Mem_EmptyPool( byte *poolptr, const char *filename, int fileline )
while( pool->chain ) Mem_FreeBlock( pool->chain, filename, fileline );
}
qboolean Mem_CheckAlloc( mempool_t *pool, void *data )
static qboolean Mem_CheckAlloc( mempool_t *pool, void *data )
{
memheader_t *header, *target;
@ -256,15 +286,15 @@ qboolean Mem_CheckAlloc( mempool_t *pool, void *data ) @@ -256,15 +286,15 @@ qboolean Mem_CheckAlloc( mempool_t *pool, void *data )
Check pointer for memory
========================
*/
qboolean Mem_IsAllocatedExt( byte *poolptr, void *data )
qboolean Mem_IsAllocatedExt( poolhandle_t poolptr, void *data )
{
mempool_t *pool = NULL;
if( poolptr ) pool = (mempool_t *)poolptr;
if( poolptr ) pool = Mem_FindPool( poolptr );
return Mem_CheckAlloc( pool, data );
}
void Mem_CheckHeaderSentinels( void *data, const char *filename, int fileline )
static void Mem_CheckHeaderSentinels( void *data, const char *filename, int fileline )
{
memheader_t *mem;

10
engine/ref_api.h

@ -356,10 +356,10 @@ typedef struct ref_api_s @@ -356,10 +356,10 @@ typedef struct ref_api_s
int (*pfnGetStudioModelInterface)( int version, struct r_studio_interface_s **ppinterface, struct engine_studio_api_s *pstudio );
// memory
byte *(*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
void (*_Mem_FreePool)( byte **poolptr, const char *filename, int fileline );
void *(*_Mem_Alloc)( byte *poolptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Realloc)( byte *poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
poolhandle_t (*_Mem_AllocPool)( const char *name, const char *filename, int fileline );
void (*_Mem_FreePool)( poolhandle_t *poolptr, const char *filename, int fileline );
void *(*_Mem_Alloc)( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline );
void *(*_Mem_Realloc)( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline );
void (*_Mem_Free)( void *data, const char *filename, int fileline );
// library management
@ -424,7 +424,7 @@ typedef struct ref_api_s @@ -424,7 +424,7 @@ typedef struct ref_api_s
rgbdata_t *(*FS_CopyImage)( rgbdata_t *in );
void (*FS_FreeImage)( rgbdata_t *pack );
void (*Image_SetMDLPointer)( byte *p );
byte *(*Image_GetPool)( void );
poolhandle_t (*Image_GetPool)( void );
const struct bpc_desc_s *(*Image_GetPFDesc)( int idx );
// client exports

4
engine/server/server.h

@ -345,8 +345,8 @@ typedef struct @@ -345,8 +345,8 @@ typedef struct
NEW_DLL_FUNCTIONS dllFuncs2; // new dll exported funcs (may be NULL)
physics_interface_t physFuncs; // physics interface functions (Xash3D extension)
byte *mempool; // server premamnent pool: edicts etc
byte *stringspool; // for engine strings
poolhandle_t mempool; // server premamnent pool: edicts etc
poolhandle_t stringspool; // for engine strings
} svgame_static_t;
typedef struct

2
ref_gl/gl_local.h

@ -56,7 +56,7 @@ GNU General Public License for more details. @@ -56,7 +56,7 @@ GNU General Public License for more details.
#define LM_SAMPLE_SIZE 16
extern byte *r_temppool;
extern poolhandle_t r_temppool;
#define BLOCK_SIZE tr.block_size // lightmap blocksize
#define BLOCK_SIZE_DEFAULT 128 // for keep backward compatibility

2
ref_gl/gl_opengl.c

@ -49,7 +49,7 @@ cvar_t *tracergreen; @@ -49,7 +49,7 @@ cvar_t *tracergreen;
cvar_t *tracerblue;
cvar_t *traceralpha;
byte *r_temppool;
poolhandle_t r_temppool;
gl_globals_t tr;
glconfig_t glConfig;

2
ref_gl/gl_rsurf.c

@ -1734,7 +1734,7 @@ extern decal_t gDecalPool[MAX_RENDER_DECALS]; @@ -1734,7 +1734,7 @@ extern decal_t gDecalPool[MAX_RENDER_DECALS];
struct vbo_static_s
{
// quickly free all allocations on map change
byte *mempool;
poolhandle_t mempool;
// arays
vbodecaldata_t *decaldata; // array

2
ref_soft/r_context.c

@ -19,7 +19,7 @@ ref_api_t gEngfuncs; @@ -19,7 +19,7 @@ ref_api_t gEngfuncs;
ref_globals_t *gpGlobals;
gl_globals_t tr;
ref_speeds_t r_stats;
byte *r_temppool;
poolhandle_t r_temppool;
cvar_t *gl_emboss_scale;
cvar_t *r_norefresh;
cvar_t *vid_brightness;

2
ref_soft/r_local.h

@ -57,7 +57,7 @@ typedef int fixed16_t; @@ -57,7 +57,7 @@ typedef int fixed16_t;
#define LM_SAMPLE_SIZE 16
extern byte *r_temppool;
extern poolhandle_t r_temppool;
#define BLOCK_SIZE tr.block_size // lightmap blocksize
#define BLOCK_SIZE_DEFAULT 128 // for keep backward compatibility

Loading…
Cancel
Save