From c55b7dcda7f362cbf72713ab783647879a7050b3 Mon Sep 17 00:00:00 2001 From: mittorn Date: Sun, 17 Mar 2019 23:14:53 +0700 Subject: [PATCH] ref: simplify efx api, move efrags to engine --- .../gl_refrag.c => engine/client/cl_efrag.c | 20 +++++++------ engine/client/cl_efx.c | 30 ------------------- engine/client/cl_game.c | 2 +- engine/client/cl_parse.c | 8 ++--- engine/client/cl_qparse.c | 6 ++-- engine/client/cl_render.c | 2 +- engine/client/cl_tent.h | 1 - engine/client/client.h | 6 ++++ engine/client/ref_common.c | 4 +-- engine/ref_api.h | 12 +------- ref_gl/gl_context.c | 4 --- ref_gl/gl_local.h | 5 ---- ref_gl/gl_rpart.c | 25 ++++++++++++++-- ref_gl/gl_rsurf.c | 6 ++-- 14 files changed, 54 insertions(+), 77 deletions(-) rename ref_gl/gl_refrag.c => engine/client/cl_efrag.c (90%) diff --git a/ref_gl/gl_refrag.c b/engine/client/cl_efrag.c similarity index 90% rename from ref_gl/gl_refrag.c rename to engine/client/cl_efrag.c index f26b0aad..d8ce446c 100644 --- a/ref_gl/gl_refrag.c +++ b/engine/client/cl_efrag.c @@ -13,10 +13,12 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. */ -#include "gl_local.h" +#include "common.h" #include "entity_types.h" #include "studio.h" #include "world.h" // BOX_ON_PLANE_SIDE +#include "client.h" +#include "mathlib.h" /* =============================================================================== @@ -65,8 +67,8 @@ void R_RemoveEfrags( cl_entity_t *ent ) ef = ef->entnext; // put it on the free list - old->entnext = gEngfuncs.GetEfragsFreeList(); - gEngfuncs.SetEfragsFreeList( old ); + old->entnext = clgame.free_efrags; + clgame.free_efrags = old; } ent->efrag = NULL; } @@ -94,14 +96,14 @@ static void R_SplitEntityOnNode( mnode_t *node ) leaf = (mleaf_t *)node; // grab an efrag off the free list - ef = gEngfuncs.GetEfragsFreeList(); + ef = clgame.free_efrags; if( !ef ) { - gEngfuncs.Con_Printf( S_ERROR "too many efrags!\n" ); + Con_Printf( S_ERROR "too many efrags!\n" ); return; // no free fragments... } - gEngfuncs.SetEfragsFreeList( ef->entnext ); + clgame.free_efrags = ef->entnext; ef->entity = r_addent; // add the entity link @@ -159,7 +161,7 @@ void R_AddEfrags( cl_entity_t *ent ) r_emaxs[i] = ent->origin[i] + outmaxs[i]; } - R_SplitEntityOnNode( WORLDMODEL->nodes ); + R_SplitEntityOnNode( cl.worldmodel->nodes ); ent->topnode = r_pefragtopnode; } @@ -190,10 +192,10 @@ void R_StoreEfrags( efrag_t **ppefrag, int framecount ) if( pent->visframe != framecount ) { - if( gEngfuncs.CL_AddVisibleEntity( pent, ET_FRAGMENTED )) + if( CL_AddVisibleEntity( pent, ET_FRAGMENTED )) { // mark that we've recorded this entity for this frame - pent->curstate.messagenum = gpGlobals->parsecount; + pent->curstate.messagenum = cl.parsecount; pent->visframe = framecount; } } diff --git a/engine/client/cl_efx.c b/engine/client/cl_efx.c index 3446d01b..4d0c4c4e 100644 --- a/engine/client/cl_efx.c +++ b/engine/client/cl_efx.c @@ -21,22 +21,6 @@ static int ramp2[8] = { 0x6f, 0x6e, 0x6d, 0x6c, 0x6b, 0x6a, 0x68, 0x66 }; static int ramp3[6] = { 0x6d, 0x6b, 6, 5, 4, 3 }; static int gSparkRamp[9] = { 0xfe, 0xfd, 0xfc, 0x6f, 0x6e, 0x6d, 0x6c, 0x67, 0x60 }; -static color24 gTracerColors[] = -{ -{ 255, 255, 255 }, // White -{ 255, 0, 0 }, // Red -{ 0, 255, 0 }, // Green -{ 0, 0, 255 }, // Blue -{ 0, 0, 0 }, // Tracer default, filled in from cvars, etc. -{ 255, 167, 17 }, // Yellow-orange sparks -{ 255, 130, 90 }, // Yellowish streaks (garg) -{ 55, 60, 144 }, // Blue egon streak -{ 255, 130, 90 }, // More Yellowish streaks (garg) -{ 255, 140, 90 }, // More Yellowish streaks (garg) -{ 200, 130, 90 }, // More red streaks (garg) -{ 255, 120, 70 }, // Darker red streaks (garg) -}; - convar_t *tracerspeed; convar_t *tracerlength; convar_t *traceroffset; @@ -83,14 +67,6 @@ short R_LookupColor( byte r, byte g, byte b ) return best; } -color24 *R_GetTracerColor( uint idx ) -{ - if( idx > ARRAYSIZE( gTracerColors )) - return NULL; - - return &gTracerColors[idx]; -} - /* ================ R_GetPackedColor @@ -1879,12 +1855,6 @@ void R_UserTracerParticle( float *org, float *vel, float life, int colorIndex, f if( colorIndex < 0 ) return; - if( colorIndex > ARRAYSIZE( gTracerColors )) - { - Con_Printf( S_ERROR "UserTracer with color > %d\n", ARRAYSIZE( gTracerColors )); - return; - } - if(( p = R_AllocTracer( org, vel, life )) != NULL ) { p->context = deathcontext; diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 277715bc..cbfd3cc9 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1096,7 +1096,7 @@ void CL_LinkUserMessage( char *pszName, const int svc_num, int iSize ) void CL_FreeEntity( cl_entity_t *pEdict ) { Assert( pEdict != NULL ); - ref.dllFuncs.R_RemoveEfrags( pEdict ); + R_RemoveEfrags( pEdict ); CL_KillDeadBeams( pEdict ); } diff --git a/engine/client/cl_parse.c b/engine/client/cl_parse.c index 44cfa8c9..5673cb8c 100644 --- a/engine/client/cl_parse.c +++ b/engine/client/cl_parse.c @@ -352,7 +352,7 @@ void CL_ParseStaticEntity( sizebuf_t *msg ) } } - ref.dllFuncs.R_AddEfrags( ent ); // add link + R_AddEfrags( ent ); // add link } @@ -1023,8 +1023,8 @@ void CL_ParseClientData( sizebuf_t *msg ) } } - refState.parsecount = cl.parsecount = i; // ack'd incoming messages. - refState.parsecountmod = cl.parsecountmod = cl.parsecount & CL_UPDATE_MASK; // index into window. + cl.parsecount = i; // ack'd incoming messages. + cl.parsecountmod = cl.parsecount & CL_UPDATE_MASK; // index into window. frame = &cl.frames[cl.parsecountmod]; // frame at index. frame->time = cl.mtime[0]; // mark network received time @@ -2559,7 +2559,7 @@ void CL_LegacyParseStaticEntity( sizebuf_t *msg ) } } - ref.dllFuncs.R_AddEfrags( ent ); // add link + R_AddEfrags( ent ); // add link } diff --git a/engine/client/cl_qparse.c b/engine/client/cl_qparse.c index 7755ddfb..32331c65 100644 --- a/engine/client/cl_qparse.c +++ b/engine/client/cl_qparse.c @@ -349,8 +349,8 @@ static void CL_ParseQuakeClientData( sizebuf_t *msg ) // this is the frame update that this message corresponds to i = cls.netchan.incoming_sequence; - refState.parsecount = cl.parsecount = i; // ack'd incoming messages. - refState.parsecountmod = cl.parsecountmod = cl.parsecount & CL_UPDATE_MASK; // index into window. + cl.parsecount = i; // ack'd incoming messages. + cl.parsecountmod = cl.parsecount & CL_UPDATE_MASK; // index into window. frame = &cl.frames[cl.parsecountmod]; // frame at index. frame->time = cl.mtime[0]; // mark network received time frame->receivedtime = host.realtime; // time now that we are parsing. @@ -683,7 +683,7 @@ static void CL_ParseQuakeStaticEntity( sizebuf_t *msg ) } } - ref.dllFuncs.R_AddEfrags( ent ); // add link + R_AddEfrags( ent ); // add link } /* diff --git a/engine/client/cl_render.c b/engine/client/cl_render.c index e72bf3ce..6a4a4cc6 100644 --- a/engine/client/cl_render.c +++ b/engine/client/cl_render.c @@ -260,7 +260,7 @@ qboolean R_InitRenderAPI( void ) gRenderAPI.GetFrameTime = ref.dllFuncs.GetFrameTime; gRenderAPI.R_SetCurrentEntity = ref.dllFuncs.R_SetCurrentEntity; gRenderAPI.R_SetCurrentModel = ref.dllFuncs.R_SetCurrentModel; - gRenderAPI.R_StoreEfrags = ref.dllFuncs.R_StoreEfrags; + gRenderAPI.R_StoreEfrags = R_StoreEfrags; gRenderAPI.GL_FindTexture = ref.dllFuncs.GL_FindTexture; gRenderAPI.GL_TextureName = ref.dllFuncs.GL_TextureName; gRenderAPI.GL_TextureData = ref.dllFuncs.GL_TextureData; diff --git a/engine/client/cl_tent.h b/engine/client/cl_tent.h index 80ee9eb7..fb3accd7 100644 --- a/engine/client/cl_tent.h +++ b/engine/client/cl_tent.h @@ -91,7 +91,6 @@ int CL_DecalIndex( int id ); // RefAPI struct particle_s *CL_AllocParticleFast( void ); -color24 *R_GetTracerColor( uint idx ); // Beams struct beam_s *R_BeamLightning( vec3_t start, vec3_t end, int modelIndex, float life, float width, float amplitude, float brightness, float speed ); diff --git a/engine/client/client.h b/engine/client/client.h index f98950ed..2e578244 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -963,6 +963,12 @@ lightstyle_t *CL_GetLightStyle( int number ); int R_FatPVS( const vec3_t org, float radius, byte *visbuffer, qboolean merge, qboolean fullvis ); const ref_overview_t *GL_GetOverviewParms( void ); +// +// cl_efrag.c +// +void R_StoreEfrags( efrag_t **ppefrag, int framecount ); +void R_AddEfrags( cl_entity_t *ent ); +void R_RemoveEfrags( cl_entity_t *ent ); // // cl_tent.c // diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 2f991b97..501fab9a 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -292,11 +292,9 @@ static ref_api_t gEngfuncs = CL_ThinkParticle, R_FreeDeadParticles, CL_AllocParticleFast, - pfnGetEfragsFreeList, - pfnSetEfragsFreeList, - R_GetTracerColor, CL_AllocElight, pfnGetDefaultSprite, + R_StoreEfrags, Mod_ForName, pfnMod_Extradata, diff --git a/engine/ref_api.h b/engine/ref_api.h index 5fca874c..d2f978aa 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -80,16 +80,12 @@ typedef struct typedef struct ref_globals_s { qboolean developer; - qboolean video_prepped; float time; // cl.time float oldtime; // cl.oldtime double realtime; // host.realtime double frametime; // host.frametime - int parsecount; // cl.parsecount - int parsecountmod; // cl.parsecountmod - // viewport width and height int width; int height; @@ -313,11 +309,9 @@ typedef struct ref_api_s void (*CL_ThinkParticle)( double frametime, particle_t *p ); void (*R_FreeDeadParticles)( particle_t **ppparticles ); particle_t *(*CL_AllocParticleFast)( void ); // unconditionally give new particle pointer from cl_free_particles - efrag_t* (*GetEfragsFreeList)( void ); // clgame.free_efrags - void (*SetEfragsFreeList)( efrag_t* ); // clgame.free_efrags - color24 *(*GetTracerColors)( uint num ); struct dlight_s *(*CL_AllocElight)( int key ); struct model_s *(*GetDefaultSprite)( enum ref_defaultsprite_e spr ); + void (*R_StoreEfrags)( struct efrag_s **ppefrag, int framecount );// store efrags for static entities // model management model_t *(*Mod_ForName)( const char *name, qboolean crash, qboolean trackCRC ); @@ -494,9 +488,6 @@ typedef struct ref_interface_s // light colorVec (*R_LightPoint)( const float *p ); - void (*R_AddEfrags)( struct cl_entity_s *ent ); - void (*R_RemoveEfrags)( struct cl_entity_s *ent ); - // decals // Shoots a decal onto the surface of the BSP. position is the center of the decal in world coords void (*R_DecalShoot)( int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale ); @@ -539,7 +530,6 @@ typedef struct ref_interface_s // Set renderer info (tell engine about changes) void (*R_SetCurrentEntity)( struct cl_entity_s *ent ); // tell engine about both currententity and currentmodel void (*R_SetCurrentModel)( struct model_s *mod ); // change currentmodel but leave currententity unchanged - void (*R_StoreEfrags)( struct efrag_s **ppefrag, int framecount );// store efrags for static entities // Texture tools int (*GL_FindTexture)( const char *name ); diff --git a/ref_gl/gl_context.c b/ref_gl/gl_context.c index 56cdd124..09a168a6 100644 --- a/ref_gl/gl_context.c +++ b/ref_gl/gl_context.c @@ -432,9 +432,6 @@ ref_interface_t gReffuncs = R_LightPoint, - R_AddEfrags, - R_RemoveEfrags, - R_DecalShoot, R_DecalRemoveAll, R_CreateDecalList, @@ -466,7 +463,6 @@ ref_interface_t gReffuncs = R_SetCurrentEntity, R_SetCurrentModel, - R_StoreEfrags, GL_FindTexture, GL_TextureName, diff --git a/ref_gl/gl_local.h b/ref_gl/gl_local.h index 3f7ff709..f6a7972d 100644 --- a/ref_gl/gl_local.h +++ b/ref_gl/gl_local.h @@ -359,11 +359,6 @@ void R_TextureList_f( void ); void R_InitImages( void ); void R_ShutdownImages( void ); -// -// gl_refrag.c -// -void R_StoreEfrags( efrag_t **ppefrag, int framecount ); - // // gl_rlight.c // diff --git a/ref_gl/gl_rpart.c b/ref_gl/gl_rpart.c index e1460a47..3d65eedc 100644 --- a/ref_gl/gl_rpart.c +++ b/ref_gl/gl_rpart.c @@ -23,6 +23,21 @@ GNU General Public License for more details. #include "studio.h" static float gTracerSize[11] = { 1.5f, 0.5f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f }; +static color24 gTracerColors[] = +{ +{ 255, 255, 255 }, // White +{ 255, 0, 0 }, // Red +{ 0, 255, 0 }, // Green +{ 0, 0, 255 }, // Blue +{ 0, 0, 0 }, // Tracer default, filled in from cvars, etc. +{ 255, 167, 17 }, // Yellow-orange sparks +{ 255, 130, 90 }, // Yellowish streaks (garg) +{ 55, 60, 144 }, // Blue egon streak +{ 255, 130, 90 }, // More Yellowish streaks (garg) +{ 255, 140, 90 }, // More Yellowish streaks (garg) +{ 200, 130, 90 }, // More red streaks (garg) +{ 255, 120, 70 }, // Darker red streaks (garg) +}; /* ================ @@ -153,7 +168,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) // update tracer color if this is changed if( FBitSet( tracerred->flags|tracergreen->flags|tracerblue->flags|traceralpha->flags, FCVAR_CHANGED )) { - color24 *customColors = gEngfuncs.GetTracerColors( 4 ); + color24 *customColors = &gTracerColors[4]; customColors->r = (byte)(tracerred->value * traceralpha->value * 255); customColors->g = (byte)(tracergreen->value * traceralpha->value * 255); customColors->b = (byte)(tracerblue->value * traceralpha->value * 255); @@ -215,7 +230,13 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) VectorAdd( verts[0], delta, verts[2] ); VectorAdd( verts[1], delta, verts[3] ); - pColor = gEngfuncs.GetTracerColors( p->color ); + if( p->color > sizeof( gTracerColors ) / sizeof( color24 ) ) + { + gEngfuncs.Con_Printf( S_ERROR "UserTracer with color > %d\n", sizeof( gTracerColors ) / sizeof( color24 )); + p->color = 0; + } + + pColor = &gTracerColors[p->color]; pglColor4ub( pColor->r, pColor->g, pColor->b, p->packedColor ); pglBegin( GL_QUADS ); diff --git a/ref_gl/gl_rsurf.c b/ref_gl/gl_rsurf.c index bc1777c0..569fde9a 100644 --- a/ref_gl/gl_rsurf.c +++ b/ref_gl/gl_rsurf.c @@ -3069,7 +3069,7 @@ loc0: // deal with model fragments in this leaf if( pleaf->efrags ) - R_StoreEfrags( &pleaf->efrags, tr.realframecount ); + gEngfuncs.R_StoreEfrags( &pleaf->efrags, tr.realframecount ); r_stats.c_world_leafs++; return; @@ -3163,7 +3163,7 @@ static void R_DrawTopViewLeaf( mleaf_t *pleaf, uint clipflags ) // deal with model fragments in this leaf if( pleaf->efrags ) - R_StoreEfrags( &pleaf->efrags, tr.realframecount ); + gEngfuncs.R_StoreEfrags( &pleaf->efrags, tr.realframecount ); r_stats.c_world_leafs++; } @@ -3492,7 +3492,7 @@ void GL_RebuildLightmaps( void ) int i, j; model_t *m; - if( !gpGlobals->video_prepped ) + if( !gEngfuncs.CL_GetRenderParm( PARM_CLIENT_ACTIVE, 0 ) ) return; // wait for worldmodel ClearBits( vid_brightness->flags, FCVAR_CHANGED );