From ef73b55413a6ba49b90d9fb75f8bbe23274da833 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 12 Apr 2026 16:10:48 +0500 Subject: [PATCH] ref: common: move malloc and GL_InitRandomTable --- ref/common/ref_common.h | 17 +++++++++++++++++ ref/common/ref_context.c | 31 +++++++++++++++++++++++++++++++ ref/gl/gl_context.c | 9 --------- ref/gl/gl_local.h | 11 ----------- ref/gl/gl_rsurf.c | 15 --------------- ref/soft/r_context.c | 9 --------- ref/soft/r_local.h | 11 ----------- ref/soft/r_surf.c | 15 --------------- 8 files changed, 48 insertions(+), 70 deletions(-) diff --git a/ref/common/ref_common.h b/ref/common/ref_common.h index 8e7b70ec..c80c7fc1 100644 --- a/ref/common/ref_common.h +++ b/ref/common/ref_common.h @@ -31,6 +31,23 @@ extern const ref_interface_t gReffuncs; #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( (parm), 0 ) +extern uint16_t rtable[MOD_FRAMES][MOD_FRAMES]; +void GL_InitRandomTable( void ); + +void _Mem_Free( void *data, const char *filename, int fileline ); +void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) + ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; +void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) + ALLOC_CHECK( 3 ) WARN_UNUSED_RESULT; + +#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) +#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) +#define Mem_Realloc( pool, ptr, size ) _Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ ) +#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ ) +#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ ) +#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ ) +#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ ) + // // ref_math.c // diff --git a/ref/common/ref_context.c b/ref/common/ref_context.c index 8ad3e3f3..2ee72052 100644 --- a/ref/common/ref_context.c +++ b/ref/common/ref_context.c @@ -19,6 +19,37 @@ ref_api_t gEngfuncs; ref_globals_t *gpGlobals; ref_client_t *gp_cl; ref_host_t *gp_host; +uint16_t rtable[MOD_FRAMES][MOD_FRAMES]; + +void _Mem_Free( void *data, const char *filename, int fileline ) +{ + gEngfuncs._Mem_Free( data, filename, fileline ); +} + +void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) +{ + return gEngfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline ); +} + +void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean clear, const char *filename, int fileline ) +{ + return gEngfuncs._Mem_Realloc( poolptr, memptr, size, clear, filename, fileline ); +} + +void GL_InitRandomTable( void ) +{ + int tu, tv; + + for( tu = 0; tu < MOD_FRAMES; tu++ ) + { + for( tv = 0; tv < MOD_FRAMES; tv++ ) + { + rtable[tu][tv] = gEngfuncs.COM_RandomLong( 0, 0x7FFF ); + } + } + + gEngfuncs.COM_SetRandomSeed( 0 ); +} int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals ); int EXPORT GetRefAPI( int version, ref_interface_t *funcs, ref_api_t *engfuncs, ref_globals_t *globals ) diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index c8ba60df..6dbba16b 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -23,15 +23,6 @@ GNU General Public License for more details. #endif -void _Mem_Free( void *data, const char *filename, int fileline ) -{ - gEngfuncs._Mem_Free( data, filename, fileline ); -} - -void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) -{ - return gEngfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline ); -} static void R_ClearScreen( void ) { diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index cc4b372f..6ad9abeb 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -418,7 +418,6 @@ void GL_SubdivideSurface( model_t *mod, msurface_t *fa ); void GL_SetupFogColorForSurfaces( void ); void R_DrawAlphaTextureChains( void ); void GL_RebuildLightmaps( void ); -void GL_InitRandomTable( void ); void GL_BuildLightmaps( void ); void GL_ResetFogColor( void ); void R_GenerateVBO( void ); @@ -802,16 +801,6 @@ DECLARE_ENGINE_SHARED_CVAR_LIST() // #include "crtlib.h" -void _Mem_Free( void *data, const char *filename, int fileline ); -void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) - ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; -#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) -#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) -#define Mem_Realloc( pool, ptr, size ) gEngfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ ) -#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ ) -#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ ) -#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ ) -#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ ) #endif // GL_LOCAL_H diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index e93e2fcb..03f69d0e 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -40,7 +40,6 @@ static vec2_t world_orthohalf; static uint r_blocklights[BLOCK_SIZE_MAX*BLOCK_SIZE_MAX*3]; static mextrasurf_t *fullbright_surfaces[MAX_TEXTURES]; static mextrasurf_t *detail_surfaces[MAX_TEXTURES]; -static int rtable[MOD_FRAMES][MOD_FRAMES]; typedef struct { @@ -4008,17 +4007,3 @@ void GL_BuildLightmaps( void ) } } -void GL_InitRandomTable( void ) -{ - int tu, tv; - - for( tu = 0; tu < MOD_FRAMES; tu++ ) - { - for( tv = 0; tv < MOD_FRAMES; tv++ ) - { - rtable[tu][tv] = gEngfuncs.COM_RandomLong( 0, 0x7FFF ); - } - } - - gEngfuncs.COM_SetRandomSeed( 0 ); -} diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index 9a3febd4..e4f77e36 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -20,15 +20,6 @@ ref_speeds_t r_stats; poolhandle_t r_temppool; viddef_t vid; -void _Mem_Free( void *data, const char *filename, int fileline ) -{ - gEngfuncs._Mem_Free( data, filename, fileline ); -} - -void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) -{ - return gEngfuncs._Mem_Alloc( poolptr, size, clear, filename, fileline ); -} static void GAME_EXPORT R_ClearScreen( void ) { diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 870af6b4..4b3983c7 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -1074,7 +1074,6 @@ void R_ScanEdges( void ); // // r_surf.c // -void GL_InitRandomTable( void ); void D_FlushCaches( void ); // @@ -1122,16 +1121,6 @@ void R_SetUpWorldTransform( void ); // #include "crtlib.h" #include "crclib.h" -void _Mem_Free( void *data, const char *filename, int fileline ); -void *_Mem_Alloc( poolhandle_t poolptr, size_t size, qboolean clear, const char *filename, int fileline ) -ALLOC_CHECK( 2 ) MALLOC_LIKE( _Mem_Free, 1 ) WARN_UNUSED_RESULT; -#define Mem_Malloc( pool, size ) _Mem_Alloc( pool, size, false, __FILE__, __LINE__ ) -#define Mem_Calloc( pool, size ) _Mem_Alloc( pool, size, true, __FILE__, __LINE__ ) -#define Mem_Realloc( pool, ptr, size ) gEngfuncs._Mem_Realloc( pool, ptr, size, true, __FILE__, __LINE__ ) -#define Mem_Free( mem ) _Mem_Free( mem, __FILE__, __LINE__ ) -#define Mem_AllocPool( name ) gEngfuncs._Mem_AllocPool( name, __FILE__, __LINE__ ) -#define Mem_FreePool( pool ) gEngfuncs._Mem_FreePool( pool, __FILE__, __LINE__ ) -#define Mem_EmptyPool( pool ) gEngfuncs._Mem_EmptyPool( pool, __FILE__, __LINE__ ) #endif // GL_LOCAL_H diff --git a/ref/soft/r_surf.c b/ref/soft/r_surf.c index 2692f5e2..746ffe73 100644 --- a/ref/soft/r_surf.c +++ b/ref/soft/r_surf.c @@ -62,7 +62,6 @@ static int sc_size; surfcache_t *sc_rover; static surfcache_t *sc_base; -static int rtable[MOD_FRAMES][MOD_FRAMES]; static void R_BuildLightMap( void ); /* @@ -238,20 +237,6 @@ static void R_BuildLightMap( void ) } } -void GL_InitRandomTable( void ) -{ - int tu, tv; - - for( tu = 0; tu < MOD_FRAMES; tu++ ) - { - for( tv = 0; tv < MOD_FRAMES; tv++ ) - { - rtable[tu][tv] = gEngfuncs.COM_RandomLong( 0, 0x7FFF ); - } - } - - gEngfuncs.COM_SetRandomSeed( 0 ); -} /* ===============