ref: remove Mod_LoadMapSprite from RefAPI

This commit is contained in:
Alibek Omarov 2024-11-03 02:59:44 +03:00
parent 4cb11861e4
commit 4d003bc13f
8 changed files with 1 additions and 263 deletions

View file

@ -55,7 +55,7 @@ GNU General Public License for more details.
// Move hulls rendering back to engine
// Removed lightstyle, dynamic and entity light functions. Renderer is supposed to get them through PARM_GET_*_PTR.
// CL_RunLightStyles now accepts lightstyles array.
// Removed R_DrawTileClear.
// Removed R_DrawTileClear and Mod_LoadMapSprite, as they're implemented on engine side
// Removed FillRGBABlend. Now FillRGBA accepts rendermode parameter.
#define REF_API_VERSION 9
@ -550,7 +550,6 @@ typedef struct ref_interface_s
// model management
// flags ignored for everything except spritemodels
void (*Mod_LoadMapSprite)( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded );
qboolean (*Mod_ProcessRenderData)( model_t *mod, qboolean create, const byte *buffer );
void (*Mod_StudioLoadTextures)( model_t *mod, void *data );

View file

@ -471,7 +471,6 @@ static const ref_interface_t gReffuncs =
R_GetSpriteParms,
R_GetSpriteTexture,
Mod_LoadMapSprite,
Mod_ProcessRenderData,
Mod_StudioLoadTextures,

View file

@ -537,7 +537,6 @@ qboolean R_CullBox( const vec3_t mins, const vec3_t maxs );
int R_WorldToScreen( const vec3_t point, vec3_t screen );
void R_ScreenToWorld( const vec3_t screen, vec3_t point );
qboolean R_AddEntity( struct cl_entity_s *pRefEntity, int entityType );
void Mod_LoadMapSprite( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded );
void Mod_SpriteUnloadTextures( void *data );
void Mod_UnloadAliasModel( struct model_s *mod );
void Mod_AliasUnloadTextures( void *data );

View file

@ -19,8 +19,6 @@ GNU General Public License for more details.
#include "studio.h"
#include "entity_types.h"
// it's a Valve default value for LoadMapSprite (probably must be power of two)
#define MAPSPRITE_SIZE 128
#define GLARE_FALLOFF 19000.0f
char sprite_name[MAX_QPATH];
@ -242,129 +240,6 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui
if( loaded ) *loaded = true; // done
}
/*
====================
Mod_LoadMapSprite
Loading a bitmap image as sprite with multiple frames
as pieces of input image
====================
*/
void Mod_LoadMapSprite( model_t *mod, const void *buffer, size_t size, qboolean *loaded )
{
byte *src, *dst;
rgbdata_t *pix, temp;
char texname[128];
int i, j, x, y, w, h;
int xl, yl, xh, yh;
int linedelta, numframes;
mspriteframe_t *pspriteframe;
msprite_t *psprite;
char poolname[MAX_VA_STRING];
if( loaded ) *loaded = false;
Q_snprintf( texname, sizeof( texname ), "#%s", mod->name );
gEngfuncs.Image_SetForceFlags( IL_OVERVIEW );
pix = gEngfuncs.FS_LoadImage( texname, buffer, size );
gEngfuncs.Image_ClearForceFlags();
if( !pix ) return; // bad image or something else
mod->type = mod_sprite;
r_texFlags = 0; // no custom flags for map sprites
if( pix->width % MAPSPRITE_SIZE )
w = pix->width - ( pix->width % MAPSPRITE_SIZE );
else w = pix->width;
if( pix->height % MAPSPRITE_SIZE )
h = pix->height - ( pix->height % MAPSPRITE_SIZE );
else h = pix->height;
if( w < MAPSPRITE_SIZE ) w = MAPSPRITE_SIZE;
if( h < MAPSPRITE_SIZE ) h = MAPSPRITE_SIZE;
// resample image if needed
gEngfuncs.Image_Process( &pix, w, h, IMAGE_FORCE_RGBA|IMAGE_RESAMPLE, 0.0f );
w = h = MAPSPRITE_SIZE;
// check range
if( w > pix->width ) w = pix->width;
if( h > pix->height ) h = pix->height;
// determine how many frames we needs
numframes = (pix->width * pix->height) / (w * h);
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
mod->mempool = Mem_AllocPool( poolname );
psprite = Mem_Calloc( mod->mempool, sizeof( msprite_t ) + ( numframes - 1 ) * sizeof( psprite->frames ));
mod->cache.data = psprite; // make link to extradata
psprite->type = SPR_FWD_PARALLEL_ORIENTED;
psprite->texFormat = SPR_ALPHTEST;
psprite->numframes = mod->numframes = numframes;
psprite->radius = sqrt(((w >> 1) * (w >> 1)) + ((h >> 1) * (h >> 1)));
mod->mins[0] = mod->mins[1] = -w / 2;
mod->maxs[0] = mod->maxs[1] = w / 2;
mod->mins[2] = -h / 2;
mod->maxs[2] = h / 2;
// create a temporary pic
memset( &temp, 0, sizeof( temp ));
temp.width = w;
temp.height = h;
temp.type = pix->type;
temp.flags = pix->flags;
temp.size = w * h * gEngfuncs.Image_GetPFDesc(temp.type)->bpp;
temp.buffer = Mem_Malloc( r_temppool, temp.size );
temp.palette = NULL;
// chop the image and upload into video memory
for( i = xl = yl = 0; i < numframes; i++ )
{
xh = xl + w;
yh = yl + h;
src = pix->buffer + ( yl * pix->width + xl ) * 4;
linedelta = ( pix->width - w ) * 4;
dst = temp.buffer;
// cut block from source
for( y = yl; y < yh; y++ )
{
for( x = xl; x < xh; x++ )
for( j = 0; j < 4; j++ )
*dst++ = *src++;
src += linedelta;
}
// build uinque frame name
Q_snprintf( texname, sizeof( texname ), "#MAP/%s_%i%i.spr", mod->name, i / 10, i % 10 );
psprite->frames[i].frameptr = Mem_Calloc( mod->mempool, sizeof( mspriteframe_t ));
pspriteframe = psprite->frames[i].frameptr;
pspriteframe->width = w;
pspriteframe->height = h;
pspriteframe->up = ( h >> 1 );
pspriteframe->left = -( w >> 1 );
pspriteframe->down = ( h >> 1 ) - h;
pspriteframe->right = w + -( w >> 1 );
pspriteframe->gl_texturenum = GL_LoadTextureInternal( texname, &temp, TF_IMAGE );
xl += w;
if( xl >= pix->width )
{
xl = 0;
yl += h;
}
}
gEngfuncs.FS_FreeImage( pix );
Mem_Free( temp.buffer );
if( loaded ) *loaded = true;
}
/*
====================
Mod_UnloadSpriteModel

View file

@ -194,12 +194,6 @@ static int R_GetSpriteTexture( const model_t *m_pSpriteModel, int frame )
return 0;
}
static void Mod_LoadMapSprite( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded )
{
*loaded = false;
return;
}
static qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buffer )
{
return true;
@ -504,7 +498,6 @@ static const ref_interface_t gReffuncs =
.R_GetSpriteParms = R_GetSpriteParms,
.R_GetSpriteTexture = R_GetSpriteTexture,
.Mod_LoadMapSprite = Mod_LoadMapSprite,
.Mod_ProcessRenderData = Mod_ProcessRenderData,
.Mod_StudioLoadTextures = Mod_StudioLoadTextures,

View file

@ -478,7 +478,6 @@ static const ref_interface_t gReffuncs =
R_GetSpriteParms,
R_GetSpriteTexture,
Mod_LoadMapSprite,
Mod_ProcessRenderData,
Mod_StudioLoadTextures,

View file

@ -618,7 +618,6 @@ qboolean R_CullBox( const vec3_t mins, const vec3_t maxs );
int R_WorldToScreen( const vec3_t point, vec3_t screen );
void R_ScreenToWorld( const vec3_t screen, vec3_t point );
qboolean R_AddEntity( struct cl_entity_s *pRefEntity, int entityType );
void Mod_LoadMapSprite( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded );
void Mod_SpriteUnloadTextures( void *data );
void Mod_UnloadAliasModel( struct model_s *mod );
void Mod_AliasUnloadTextures( void *data );

View file

@ -19,8 +19,6 @@ GNU General Public License for more details.
#include "studio.h"
#include "entity_types.h"
// it's a Valve default value for LoadMapSprite (probably must be power of two)
#define MAPSPRITE_SIZE 128
#define GLARE_FALLOFF 19000.0f
char sprite_name[MAX_QPATH];
@ -228,129 +226,6 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui
if( loaded ) *loaded = true; // done
}
/*
====================
Mod_LoadMapSprite
Loading a bitmap image as sprite with multiple frames
as pieces of input image
====================
*/
void Mod_LoadMapSprite( model_t *mod, const void *buffer, size_t size, qboolean *loaded )
{
byte *src, *dst;
rgbdata_t *pix, temp;
char texname[128];
int i, j, x, y, w, h;
int xl, yl, xh, yh;
int linedelta, numframes;
mspriteframe_t *pspriteframe;
msprite_t *psprite;
char poolname[MAX_VA_STRING];
if( loaded ) *loaded = false;
Q_snprintf( texname, sizeof( texname ), "#%s", mod->name );
gEngfuncs.Image_SetForceFlags( IL_OVERVIEW );
pix = gEngfuncs.FS_LoadImage( texname, buffer, size );
gEngfuncs.Image_ClearForceFlags();
if( !pix ) return; // bad image or something else
mod->type = mod_sprite;
r_texFlags = 0; // no custom flags for map sprites
if( pix->width % MAPSPRITE_SIZE )
w = pix->width - ( pix->width % MAPSPRITE_SIZE );
else w = pix->width;
if( pix->height % MAPSPRITE_SIZE )
h = pix->height - ( pix->height % MAPSPRITE_SIZE );
else h = pix->height;
if( w < MAPSPRITE_SIZE ) w = MAPSPRITE_SIZE;
if( h < MAPSPRITE_SIZE ) h = MAPSPRITE_SIZE;
// resample image if needed
gEngfuncs.Image_Process( &pix, w, h, IMAGE_FORCE_RGBA|IMAGE_RESAMPLE, 0.0f );
w = h = MAPSPRITE_SIZE;
// check range
if( w > pix->width ) w = pix->width;
if( h > pix->height ) h = pix->height;
// determine how many frames we needs
numframes = (pix->width * pix->height) / (w * h);
Q_snprintf( poolname, sizeof( poolname ), "^2%s^7", mod->name );
mod->mempool = Mem_AllocPool( poolname );
psprite = Mem_Calloc( mod->mempool, sizeof( msprite_t ) + ( numframes - 1 ) * sizeof( psprite->frames ));
mod->cache.data = psprite; // make link to extradata
psprite->type = SPR_FWD_PARALLEL_ORIENTED;
psprite->texFormat = SPR_ALPHTEST;
psprite->numframes = mod->numframes = numframes;
psprite->radius = sqrt(((w >> 1) * (w >> 1)) + ((h >> 1) * (h >> 1)));
mod->mins[0] = mod->mins[1] = -w / 2;
mod->maxs[0] = mod->maxs[1] = w / 2;
mod->mins[2] = -h / 2;
mod->maxs[2] = h / 2;
// create a temporary pic
memset( &temp, 0, sizeof( temp ));
temp.width = w;
temp.height = h;
temp.type = pix->type;
temp.flags = pix->flags;
temp.size = w * h * gEngfuncs.Image_GetPFDesc(temp.type)->bpp;
temp.buffer = Mem_Malloc( r_temppool, temp.size );
temp.palette = NULL;
// chop the image and upload into video memory
for( i = xl = yl = 0; i < numframes; i++ )
{
xh = xl + w;
yh = yl + h;
src = pix->buffer + ( yl * pix->width + xl ) * 4;
linedelta = ( pix->width - w ) * 4;
dst = temp.buffer;
// cut block from source
for( y = yl; y < yh; y++ )
{
for( x = xl; x < xh; x++ )
for( j = 0; j < 4; j++ )
*dst++ = *src++;
src += linedelta;
}
// build uinque frame name
Q_snprintf( texname, sizeof( texname ), "#MAP/%s_%i%i.spr", mod->name, i / 10, i % 10 );
psprite->frames[i].frameptr = Mem_Calloc( mod->mempool, sizeof( mspriteframe_t ));
pspriteframe = psprite->frames[i].frameptr;
pspriteframe->width = w;
pspriteframe->height = h;
pspriteframe->up = ( h >> 1 );
pspriteframe->left = -( w >> 1 );
pspriteframe->down = ( h >> 1 ) - h;
pspriteframe->right = w + -( w >> 1 );
pspriteframe->gl_texturenum = GL_LoadTextureInternal( texname, &temp, TF_IMAGE );
xl += w;
if( xl >= pix->width )
{
xl = 0;
yl += h;
}
}
gEngfuncs.FS_FreeImage( pix );
Mem_Free( temp.buffer );
if( loaded ) *loaded = true;
}
/*
====================
Mod_UnloadSpriteModel