From 297ca08e81181af9e28cec8ebac8b88aa4a489b5 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 17 Mar 2019 21:19:24 +0700 Subject: [PATCH] ref: replace model (un)loading by Mod_ProcessRenderData --- engine/client/cl_frame.c | 4 +--- engine/client/cl_game.c | 18 ++++++--------- engine/client/cl_parse.c | 6 ----- engine/common/mod_sprite.c | 8 ++----- engine/common/model.c | 43 +++++++++++++---------------------- engine/ref_api.h | 4 ++-- ref_gl/gl_context.c | 46 ++++++++++++++++++++++++++++++++++++-- ref_gl/gl_rmain.c | 5 +++++ ref_gl/gl_rmisc.c | 4 ++++ 9 files changed, 81 insertions(+), 57 deletions(-) diff --git a/engine/client/cl_frame.c b/engine/client/cl_frame.c index 5e145c3f..3678d57a 100644 --- a/engine/client/cl_frame.c +++ b/engine/client/cl_frame.c @@ -1310,9 +1310,7 @@ void CL_EmitEntities( void ) // set client ideal pitch when mlook is disabled CL_SetIdealPitch (); - // clear the scene befor start new frame - if( clgame.drawFuncs.R_ClearScene != NULL ) - clgame.drawFuncs.R_ClearScene(); + ref.dllFuncs.R_ClearScene (); // link all the visible clients first CL_LinkPlayers ( &cl.frames[cl.parsecountmod] ); diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 448247ba..277715bc 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1135,20 +1135,12 @@ void CL_InitEdicts( void ) clgame.remap_info = (remap_info_t **)Mem_Calloc( clgame.mempool, sizeof( remap_info_t* ) * clgame.maxRemapInfos ); } - if( clgame.drawFuncs.R_ProcessEntData != NULL ) - { - // let the client.dll free custom data - clgame.drawFuncs.R_ProcessEntData( true ); - } + ref.dllFuncs.R_ProcessEntData( true ); } void CL_FreeEdicts( void ) { - if( clgame.drawFuncs.R_ProcessEntData != NULL ) - { - // let the client.dll free custom data - clgame.drawFuncs.R_ProcessEntData( false ); - } + ref.dllFuncs.R_ProcessEntData( false ); if( clgame.entities ) Mem_Free( clgame.entities ); @@ -1236,7 +1228,11 @@ static qboolean CL_LoadHudSprite( const char *szSpriteName, model_t *m_pSprite, if( type == SPR_MAPSPRITE ) ref.dllFuncs.Mod_LoadMapSprite( m_pSprite, buf, size, &loaded ); - else Mod_LoadSpriteModel( m_pSprite, buf, &loaded, texFlags ); + else + { + Mod_LoadSpriteModel( m_pSprite, buf, &loaded, texFlags ); + ref.dllFuncs.Mod_ProcessRenderData( m_pSprite, true, buf ); + } Mem_Free( buf ); diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index f4ecabaf..44cfa8c9 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -1554,9 +1554,6 @@ void CL_RegisterResources( sizebuf_t *msg ) CL_SetupOverviewParams(); - if( clgame.drawFuncs.R_NewMap != NULL ) - clgame.drawFuncs.R_NewMap(); - // release unused SpriteTextures for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ ) { @@ -3138,9 +3135,6 @@ void CL_LegacyPrecache_f( void ) CL_SetupOverviewParams(); - if( clgame.drawFuncs.R_NewMap != NULL ) - clgame.drawFuncs.R_NewMap(); - // release unused SpriteTextures for( i = 1, mod = clgame.sprites; i < MAX_CLIENT_SPRITES; i++, mod++ ) { diff --git a/engine/common/mod_sprite.c b/engine/common/mod_sprite.c index 396ecfd8..952660eb 100644 --- a/engine/common/mod_sprite.c +++ b/engine/common/mod_sprite.c @@ -99,17 +99,13 @@ void Mod_LoadSpriteModel( model_t *mod, const void *buffer, qboolean *loaded, ui mod->mins[2] = -pinhl->bounds[1] * 0.5f; mod->maxs[2] = pinhl->bounds[1] * 0.5f; } + if( loaded ) *loaded = true; // done if( Host_IsDedicated() ) { // skip frames loading - if( loaded ) *loaded = true; // done + psprite->numframes = 0; return; } - - // continue loading frames -#ifndef XASH_DEDICATED - ref.dllFuncs.Mod_LoadModel( mod_sprite, mod, buffer, loaded, texFlags ); -#endif } diff --git a/engine/common/model.c b/engine/common/model.c index 761e04bb..b87cd09c 100644 --- a/engine/common/model.c +++ b/engine/common/model.c @@ -88,11 +88,7 @@ static void Mod_FreeUserData( model_t *mod ) #ifndef XASH_DEDICATED else { - if( clgame.drawFuncs.Mod_ProcessUserData != NULL ) - { - // let the client.dll free custom data - clgame.drawFuncs.Mod_ProcessUserData( mod, false, NULL ); - } + ref.dllFuncs.Mod_ProcessRenderData( mod, false, NULL ); } #endif } @@ -111,9 +107,6 @@ void Mod_FreeModel( model_t *mod ) if( mod->type != mod_brush || mod->name[0] != '*' ) { Mod_FreeUserData( mod ); -#ifndef XASH_DEDICATED - ref.dllFuncs.Mod_UnloadTextures( mod ); -#endif Mem_FreePool( &mod->mempool ); } @@ -295,8 +288,8 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash ) Mod_LoadSpriteModel( mod, buf, &loaded, 0 ); break; case IDALIASHEADER: - // REFTODO: move alias loader to engine - ref.dllFuncs.Mod_LoadModel( mod_alias, mod, buf, &loaded, 0 ); + // REFTODO: move server-related code here + loaded = true; break; case Q1BSP_VERSION: case HLBSP_VERSION: @@ -310,18 +303,7 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash ) else Con_Printf( S_ERROR "%s has unknown format\n", tempname ); return NULL; } - - if( !loaded ) - { - Mod_FreeModel( mod ); - Mem_Free( buf ); - - if( crash ) Host_Error( "Could not load model %s\n", tempname ); - else Con_Printf( S_ERROR "Could not load model %s\n", tempname ); - - return NULL; - } - else + if( loaded ) { if( world.loading ) SetBits( mod->flags, MODEL_WORLD ); // mark worldmodel @@ -337,15 +319,22 @@ model_t *Mod_LoadModel( model_t *mod, qboolean crash ) #ifndef XASH_DEDICATED else { - if( clgame.drawFuncs.Mod_ProcessUserData != NULL ) - { - // let the client.dll load custom data - clgame.drawFuncs.Mod_ProcessUserData( mod, true, buf ); - } + loaded = ref.dllFuncs.Mod_ProcessRenderData( mod, true, buf ); } #endif } + if( !loaded ) + { + Mod_FreeModel( mod ); + Mem_Free( buf ); + + if( crash ) Host_Error( "Could not load model %s\n", tempname ); + else Con_Printf( S_ERROR "Could not load model %s\n", tempname ); + + return NULL; + } + p = &mod_crcinfo[mod - mod_known]; mod->needload = NL_PRESENT; diff --git a/engine/ref_api.h b/engine/ref_api.h index e0f72807..5fca874c 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -460,6 +460,7 @@ typedef struct ref_interface_s qboolean (*R_AddEntity)( struct cl_entity_s *clent, int type ); void (*CL_AddCustomBeam)( cl_entity_t *pEnvBeam ); + void (*R_ProcessEntData)( qboolean allocate ); // view info qboolean (*IsNormalPass)( void ); @@ -518,9 +519,8 @@ typedef struct ref_interface_s // model management // flags ignored for everything except spritemodels - void (*Mod_LoadModel)( modtype_t desiredType, model_t *mod, const byte *buf, qboolean *loaded, int flags ); void (*Mod_LoadMapSprite)( struct model_s *mod, const void *buffer, size_t size, qboolean *loaded ); - void (*Mod_UnloadTextures)( model_t *mod ); + qboolean (*Mod_ProcessRenderData)( model_t *mod, qboolean create, const byte *buffer ); void (*Mod_StudioLoadTextures)( model_t *mod, void *data ); // efx implementation diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index f722d2c5..56cdd124 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -164,6 +164,42 @@ static void Mod_LoadModel( modtype_t desiredType, model_t *mod, const byte *buf, } } +qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte *buf ) +{ + qboolean loaded = true; + + if( create ) + { + + + switch( mod->type ) + { + case mod_studio: + // Mod_LoadStudioModel( mod, buf, loaded ); + break; + case mod_sprite: + Mod_LoadSpriteModel( mod, buf, &loaded, mod->numtexinfo ); + break; + case mod_alias: + Mod_LoadAliasModel( mod, buf, &loaded ); + break; + case mod_brush: + // Mod_LoadBrushModel( mod, buf, loaded ); + break; + + default: gEngfuncs.Host_Error( "Mod_LoadModel: unsupported type %d\n", mod->type ); + } + } + + if( loaded && gEngfuncs.drawFuncs->Mod_ProcessUserData ) + gEngfuncs.drawFuncs->Mod_ProcessUserData( mod, create, buf ); + + if( !create ) + Mod_UnloadTextures( mod ); + + return loaded; +} + static int GL_RenderGetParm( int parm, int arg ) { gl_texture_t *glt; @@ -339,6 +375,12 @@ void Mod_UnloadTextures( model_t *mod ) } } +void R_ProcessEntData( qboolean allocate ) +{ + if( gEngfuncs.drawFuncs->R_ProcessEntData ) + gEngfuncs.drawFuncs->R_ProcessEntData( allocate ); +} + ref_interface_t gReffuncs = { R_Init, @@ -363,6 +405,7 @@ ref_interface_t gReffuncs = R_AddEntity, CL_AddCustomBeam, + R_ProcessEntData, IsNormalPass, @@ -407,9 +450,8 @@ ref_interface_t gReffuncs = R_GetSpriteParms, - Mod_LoadModel, Mod_LoadMapSprite, - Mod_UnloadTextures, + Mod_ProcessRenderData, Mod_StudioLoadTextures, CL_DrawParticles, diff --git a/ref_gl/gl_rmain.c b/ref_gl/gl_rmain.c index a1d96e51..bc25629b 100644 --- a/ref_gl/gl_rmain.c +++ b/ref_gl/gl_rmain.c @@ -223,6 +223,11 @@ void R_ClearScene( void ) tr.draw_list->num_solid_entities = 0; tr.draw_list->num_trans_entities = 0; tr.draw_list->num_beam_entities = 0; + + // clear the scene befor start new frame + if( gEngfuncs.drawFuncs->R_ClearScene != NULL ) + gEngfuncs.drawFuncs->R_ClearScene(); + } /* diff --git a/ref_gl/gl_rmisc.c b/ref_gl/gl_rmisc.c index 487c542a..11712949 100644 --- a/ref_gl/gl_rmisc.c +++ b/ref_gl/gl_rmisc.c @@ -178,4 +178,8 @@ void R_NewMap( void ) GL_BuildLightmaps (); R_GenerateVBO(); + + if( gEngfuncs.drawFuncs->R_NewMap != NULL ) + gEngfuncs.drawFuncs->R_NewMap(); + }