diff --git a/engine/client/cl_game.c b/engine/client/cl_game.c index 76c71f27..3c29efe4 100644 --- a/engine/client/cl_game.c +++ b/engine/client/cl_game.c @@ -1109,12 +1109,12 @@ void CL_InitEdicts( int maxclients ) clgame.remap_info = (remap_info_t **)Mem_Calloc( clgame.mempool, sizeof( remap_info_t* ) * clgame.maxRemapInfos ); } - ref.dllFuncs.R_ProcessEntData( true ); + ref.dllFuncs.R_ProcessEntData( true, clgame.entities, clgame.maxEntities ); } void CL_FreeEdicts( void ) { - ref.dllFuncs.R_ProcessEntData( false ); + ref.dllFuncs.R_ProcessEntData( false, NULL, 0 ); if( clgame.entities ) Mem_Free( clgame.entities ); diff --git a/engine/client/ref_common.c b/engine/client/ref_common.c index 9c690071..71badbc0 100644 --- a/engine/client/ref_common.c +++ b/engine/client/ref_common.c @@ -212,6 +212,11 @@ static qboolean R_Init_Video_( const int type ) return R_Init_Video( type ); } +static model_t **pfnGetModels( void ) +{ + return cl.models; +} + static ref_api_t gEngfuncs = { pfnEngineGetParm, @@ -248,7 +253,6 @@ static ref_api_t gEngfuncs = CL_GetLocalPlayer, CL_GetViewModel, - CL_GetEntityByIndex, R_BeamGetEntity, CL_GetWaterEntity, CL_AddVisibleEntity, @@ -272,7 +276,7 @@ static ref_api_t gEngfuncs = Mod_ForName, pfnMod_Extradata, - CL_ModelHandle, + pfnGetModels, CL_GetRemapInfoForEntity, CL_AllocRemapInfo, diff --git a/engine/ref_api.h b/engine/ref_api.h index a1cda649..7c586ad1 100644 --- a/engine/ref_api.h +++ b/engine/ref_api.h @@ -301,7 +301,6 @@ typedef struct ref_api_s // entity management struct cl_entity_s *(*GetLocalPlayer)( void ); struct cl_entity_s *(*GetViewModel)( void ); - struct cl_entity_s *(*GetEntityByIndex)( int idx ); struct cl_entity_s *(*R_BeamGetEntity)( int index ); struct cl_entity_s *(*CL_GetWaterEntity)( const vec3_t p ); qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType ); @@ -329,7 +328,7 @@ typedef struct ref_api_s // model management model_t *(*Mod_ForName)( const char *name, qboolean crash, qboolean trackCRC ); void *(*Mod_Extradata)( int type, model_t *model ); - struct model_s *(*pfnGetModelByIndex)( int index ); // CL_ModelHandle + struct model_s **(*pfnGetModels)( void ); // remap struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e ); @@ -463,7 +462,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 ); + void (*R_ProcessEntData)( qboolean allocate, cl_entity_t *entities, unsigned int max_entities ); // debug void (*R_ShowTextures)( void ); diff --git a/ref/gl/gl_beams.c b/ref/gl/gl_beams.c index 7886297f..1a78d3fa 100644 --- a/ref/gl/gl_beams.c +++ b/ref/gl/gl_beams.c @@ -943,7 +943,7 @@ void R_BeamDraw( BEAM *pbeam, float frametime ) model_t *model; vec3_t delta; - model = gEngfuncs.pfnGetModelByIndex( pbeam->modelIndex ); + model = CL_ModelHandle( pbeam->modelIndex ); SetBits( pbeam->flags, FBEAM_ISACTIVE ); if( !model || model->type != mod_sprite ) @@ -1146,7 +1146,7 @@ passed through this */ static void R_BeamSetup( BEAM *pbeam, vec3_t start, vec3_t end, int modelIndex, float life, float width, float amplitude, float brightness, float speed ) { - model_t *sprite = gEngfuncs.pfnGetModelByIndex( modelIndex ); + model_t *sprite = CL_ModelHandle( modelIndex ); if( !sprite ) return; diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index 5e35659c..b9f468aa 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -295,13 +295,21 @@ const byte *GL_TextureData( unsigned int texnum ) return NULL; } -void R_ProcessEntData( qboolean allocate ) +void R_ProcessEntData( qboolean allocate, cl_entity_t *entities, unsigned int max_entities ) { if( !allocate ) { tr.draw_list->num_solid_entities = 0; tr.draw_list->num_trans_entities = 0; tr.draw_list->num_beam_entities = 0; + + tr.max_entities = 0; + tr.entities = NULL; + } + else + { + tr.max_entities = max_entities; + tr.entities = entities; } if( gEngfuncs.drawFuncs->R_ProcessEntData ) diff --git a/ref/gl/gl_cull.c b/ref/gl/gl_cull.c index 704e755d..bd0714bf 100644 --- a/ref/gl/gl_cull.c +++ b/ref/gl/gl_cull.c @@ -77,7 +77,7 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ) return CULL_VISIBLE; // world surfaces can be culled by vis frame too - if( RI.currententity == gEngfuncs.GetEntityByIndex( 0 ) && surf->visframe != tr.framecount ) + if( RI.currententity == CL_GetEntityByIndex( 0 ) && surf->visframe != tr.framecount ) return CULL_VISFRAME; // only static ents can be culled by frustum @@ -92,7 +92,7 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags ) { vec3_t orthonormal; - if( e == gEngfuncs.GetEntityByIndex( 0 ) ) orthonormal[2] = surf->plane->normal[2]; + if( e == CL_GetEntityByIndex( 0 )) orthonormal[2] = surf->plane->normal[2]; else Matrix4x4_VectorRotate( RI.objectMatrix, surf->plane->normal, orthonormal ); dist = orthonormal[2]; } diff --git a/ref/gl/gl_dbghulls.c b/ref/gl/gl_dbghulls.c index d25251be..a159729b 100644 --- a/ref/gl/gl_dbghulls.c +++ b/ref/gl/gl_dbghulls.c @@ -28,7 +28,7 @@ GNU General Public License for more details. // REFTODO: rewrite in triapi void R_DrawWorldHull( void ) { - hull_model_t *hull = &WORLD->hull_models[0]; + hull_model_t *hull = &tr.world->hull_models[0]; winding_t *poly; int i; @@ -69,10 +69,10 @@ void R_DrawModelHull( void ) return; i = atoi( RI.currentmodel->name + 1 ); - if( i < 1 || i >= WORLD->num_hull_models ) + if( i < 1 || i >= tr.world->num_hull_models ) return; - hull = &WORLD->hull_models[i]; + hull = &tr.world->hull_models[i]; pglPolygonOffset( 1.0f, 2.0 ); pglEnable( GL_POLYGON_OFFSET_FILL ); diff --git a/ref/gl/gl_decals.c b/ref/gl/gl_decals.c index 833b207c..4497b205 100644 --- a/ref/gl/gl_decals.c +++ b/ref/gl/gl_decals.c @@ -750,15 +750,15 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos if( entityIndex > 0 ) { - ent = gEngfuncs.GetEntityByIndex( entityIndex ); + ent = CL_GetEntityByIndex( entityIndex ); - if( modelIndex > 0 ) model = gEngfuncs.pfnGetModelByIndex( modelIndex ); - else if( ent != NULL ) model = gEngfuncs.pfnGetModelByIndex( ent->curstate.modelindex ); + if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex ); + else if( ent != NULL ) model = CL_ModelHandle( ent->curstate.modelindex ); else return; } else if( modelIndex > 0 ) - model = gEngfuncs.pfnGetModelByIndex( modelIndex ); - else model = WORLDMODEL; + model = CL_ModelHandle( modelIndex ); + else model = CL_ModelHandle( 1 ); if( !model ) return; diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index acf7ec4b..baace5c2 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -57,10 +57,6 @@ void VGL_ShimEndFrame( void ); #include -#define WORLD (gEngfuncs.GetWorld()) -#define WORLDMODEL (gEngfuncs.pfnGetModelByIndex( 1 )) -#define MOVEVARS (gEngfuncs.pfnGetMoveVars()) - // make mod_ref.h? #define LM_SAMPLE_SIZE 16 @@ -257,6 +253,14 @@ typedef struct vec3_t modelorg; // relative to viewpoint qboolean fCustomSkybox; + + // get from engine + struct world_static_s *world; + cl_entity_t *entities; + movevars_t *movevars; + model_t **models; + + uint max_entities; } gl_globals_t; typedef struct @@ -707,7 +711,6 @@ typedef struct qboolean in2DMode; } glstate_t; - typedef struct { qboolean initialized; // OpenGL subsystem started @@ -724,6 +727,21 @@ extern ref_globals_t *gpGlobals; #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( ( parm ), 0 ) +// +// helper funcs +// +static inline cl_entity_t *CL_GetEntityByIndex( int index ) +{ + return &tr.entities[index]; +} + +static inline model_t *CL_ModelHandle( int index ) +{ + return tr.models[index]; +} + +#define WORLDMODEL (tr.models[1]) + // // renderer cvars // diff --git a/ref/gl/gl_opengl.c b/ref/gl/gl_opengl.c index ec192ea0..d4966ec0 100644 --- a/ref/gl/gl_opengl.c +++ b/ref/gl/gl_opengl.c @@ -1284,6 +1284,11 @@ qboolean R_Init( void ) return false; } + // see R_ProcessEntData for tr.entities initialization + tr.world = gEngfuncs.GetWorld(); + tr.models = gEngfuncs.pfnGetModels(); + tr.movevars = gEngfuncs.pfnGetMoveVars(); + GL_SetDefaults(); R_CheckVBO(); R_InitImages(); diff --git a/ref/gl/gl_rlight.c b/ref/gl/gl_rlight.c index 87036181..745f249f 100644 --- a/ref/gl/gl_rlight.c +++ b/ref/gl/gl_rlight.c @@ -152,7 +152,7 @@ void R_PushDlights( void ) tr.dlightframecount = tr.framecount; - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); if( RI.currententity ) RI.currentmodel = RI.currententity->model; diff --git a/ref/gl/gl_rmain.c b/ref/gl/gl_rmain.c index 9a5a3702..9adb068b 100644 --- a/ref/gl/gl_rmain.c +++ b/ref/gl/gl_rmain.c @@ -324,7 +324,7 @@ R_GetFarClip static float R_GetFarClip( void ) { if( WORLDMODEL && RI.drawWorld ) - return MOVEVARS->zmax * 1.73f; + return tr.movevars->zmax * 1.73f; return 2048.0f; } @@ -429,7 +429,7 @@ void R_RotateForEntity( cl_entity_t *e ) { float scale = 1.0f; - if( e == gEngfuncs.GetEntityByIndex( 0 ) ) + if( e == CL_GetEntityByIndex( 0 )) { R_LoadIdentity(); return; @@ -455,7 +455,7 @@ void R_TranslateForEntity( cl_entity_t *e ) { float scale = 1.0f; - if( e == gEngfuncs.GetEntityByIndex( 0 ) ) + if( e == CL_GetEntityByIndex( 0 )) { R_LoadIdentity(); return; @@ -669,7 +669,7 @@ static void R_CheckFog( void ) // quake global fog if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) { - if( !MOVEVARS->fog_settings ) + if( !tr.movevars->fog_settings ) { if( pglIsEnabled( GL_FOG )) pglDisable( GL_FOG ); @@ -678,10 +678,10 @@ static void R_CheckFog( void ) } // quake-style global fog - RI.fogColor[0] = ((MOVEVARS->fog_settings & 0xFF000000) >> 24) / 255.0f; - RI.fogColor[1] = ((MOVEVARS->fog_settings & 0xFF0000) >> 16) / 255.0f; - RI.fogColor[2] = ((MOVEVARS->fog_settings & 0xFF00) >> 8) / 255.0f; - RI.fogDensity = ((MOVEVARS->fog_settings & 0xFF) / 255.0f) * 0.01f; + RI.fogColor[0] = ((tr.movevars->fog_settings & 0xFF000000) >> 24) / 255.0f; + RI.fogColor[1] = ((tr.movevars->fog_settings & 0xFF0000) >> 16) / 255.0f; + RI.fogColor[2] = ((tr.movevars->fog_settings & 0xFF00) >> 8) / 255.0f; + RI.fogDensity = ((tr.movevars->fog_settings & 0xFF) / 255.0f) * 0.01f; RI.fogStart = RI.fogEnd = 0.0f; RI.fogColor[3] = 1.0f; RI.fogCustom = false; diff --git a/ref/gl/gl_rmisc.c b/ref/gl/gl_rmisc.c index 9395b008..0ce9a8a1 100644 --- a/ref/gl/gl_rmisc.c +++ b/ref/gl/gl_rmisc.c @@ -146,7 +146,7 @@ void R_NewMap( void ) tx->texturechain = NULL; } - R_SetupSky( MOVEVARS->skyName ); + R_SetupSky( tr.movevars->skyName ); GL_BuildLightmaps (); R_GenerateVBO(); diff --git a/ref/gl/gl_rpart.c b/ref/gl/gl_rpart.c index 086fd0ae..1efc9c80 100644 --- a/ref/gl/gl_rpart.c +++ b/ref/gl/gl_rpart.c @@ -188,7 +188,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) pglDisable( GL_ALPHA_TEST ); pglDepthMask( GL_FALSE ); - gravity = frametime * MOVEVARS->gravity; + gravity = frametime * tr.movevars->gravity; scale = 1.0 - (frametime * 0.9); if( scale < 0.0f ) scale = 0.0f; diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index a2305085..fe9caebc 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -758,7 +758,7 @@ void DrawGLPoly( glpoly_t *p, float xScale, float yScale ) float flRate, flAngle; gl_texture_t *texture; - if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) && RI.currententity == gEngfuncs.GetEntityByIndex( 0 ) ) + if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) && RI.currententity == CL_GetEntityByIndex( 0 )) { // same as doom speed flConveyorSpeed = -35.0f; @@ -1235,7 +1235,7 @@ void R_DrawTextureChains( void ) GL_SetupFogColorForSurfaces(); // restore worldmodel - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); RI.currentmodel = RI.currententity->model; if( ENGINE_GET_PARM( PARM_SKY_SPHERE ) ) @@ -1266,7 +1266,7 @@ void R_DrawTextureChains( void ) if( !s || ( i == tr.skytexturenum )) continue; - if(( s->flags & SURF_DRAWTURB ) && MOVEVARS->wateralpha < 1.0f ) + if(( s->flags & SURF_DRAWTURB ) && tr.movevars->wateralpha < 1.0f ) continue; // draw translucent water later if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) && FBitSet( s->flags, SURF_TRANSPARENT )) @@ -1309,7 +1309,7 @@ void R_DrawAlphaTextureChains( void ) GL_SetupFogColorForSurfaces(); // restore worldmodel - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); RI.currentmodel = RI.currententity->model; RI.currententity->curstate.rendermode = kRenderTransAlpha; draw_alpha_surfaces = false; @@ -1350,11 +1350,11 @@ void R_DrawWaterSurfaces( void ) return; // non-transparent water is already drawed - if( MOVEVARS->wateralpha >= 1.0f ) + if( tr.movevars->wateralpha >= 1.0f ) return; // restore worldmodel - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); RI.currentmodel = RI.currententity->model; // go back to the world matrix @@ -1365,7 +1365,7 @@ void R_DrawWaterSurfaces( void ) pglDisable( GL_ALPHA_TEST ); pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - pglColor4f( 1.0f, 1.0f, 1.0f, MOVEVARS->wateralpha ); + pglColor4f( 1.0f, 1.0f, 1.0f, tr.movevars->wateralpha ); for( i = 0; i < WORLDMODEL->numtextures; i++ ) { @@ -3280,7 +3280,7 @@ void R_DrawWorld( void ) // paranoia issues: when gl_renderer is "0" we need have something valid for currententity // to prevent crashing until HeadShield drawing. - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); if( !RI.currententity ) return; @@ -3490,7 +3490,7 @@ void GL_RebuildLightmaps( void ) for( i = 0; i < ENGINE_GET_PARM( PARM_NUMMODELS ); i++ ) { - if(( m = gEngfuncs.pfnGetModelByIndex( i + 1 )) == NULL ) + if(( m = CL_ModelHandle( i + 1 )) == NULL ) continue; if( m->name[0] == '*' || m->type != mod_brush ) @@ -3554,7 +3554,7 @@ void GL_BuildLightmaps( void ) for( i = 0; i < ENGINE_GET_PARM( PARM_NUMMODELS ); i++ ) { - if(( m = gEngfuncs.pfnGetModelByIndex( i + 1 )) == NULL ) + if(( m = CL_ModelHandle( i + 1 )) == NULL ) continue; if( m->name[0] == '*' || m->type != mod_brush ) diff --git a/ref/gl/gl_sprite.c b/ref/gl/gl_sprite.c index 8240f2d3..6703a781 100644 --- a/ref/gl/gl_sprite.c +++ b/ref/gl/gl_sprite.c @@ -826,7 +826,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) { cl_entity_t *parent; - parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); + parent = CL_GetEntityByIndex( e->curstate.aiment ); if( parent && parent->model ) { diff --git a/ref/gl/gl_studio.c b/ref/gl/gl_studio.c index 83796e92..8a34fc28 100644 --- a/ref/gl/gl_studio.c +++ b/ref/gl/gl_studio.c @@ -1851,7 +1851,7 @@ void R_StudioRenderShadow( int iSprite, float *p1, float *p2, float *p3, float * if( !p1 || !p2 || !p3 || !p4 ) return; - if( TriSpriteTexture( gEngfuncs.pfnGetModelByIndex( iSprite ), 0 )) + if( TriSpriteTexture( CL_ModelHandle( iSprite ), 0 )) { TriRenderMode( kRenderTransAlpha ); TriColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); @@ -3371,7 +3371,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) // copy attachments into global entity array if( RI.currententity->index > 0 ) { - cl_entity_t *ent = gEngfuncs.GetEntityByIndex( RI.currententity->index ); + cl_entity_t *ent = CL_GetEntityByIndex( RI.currententity->index ); memcpy( ent->attachment, RI.currententity->attachment, sizeof( vec3_t ) * 4 ); } } @@ -3414,7 +3414,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) if( pplayer->weaponmodel ) { cl_entity_t saveent = *RI.currententity; - model_t *pweaponmodel = gEngfuncs.pfnGetModelByIndex( pplayer->weaponmodel ); + model_t *pweaponmodel = CL_ModelHandle( pplayer->weaponmodel ); m_pStudioHeader = (studiohdr_t *)gEngfuncs.Mod_Extradata( mod_studio, pweaponmodel ); @@ -3500,7 +3500,7 @@ static int R_StudioDrawModel( int flags ) // copy attachments into global entity array if( RI.currententity->index > 0 ) { - cl_entity_t *ent = gEngfuncs.GetEntityByIndex( RI.currententity->index ); + cl_entity_t *ent = CL_GetEntityByIndex( RI.currententity->index ); memcpy( ent->attachment, RI.currententity->attachment, sizeof( vec3_t ) * 4 ); } } @@ -3569,7 +3569,7 @@ void R_DrawStudioModel( cl_entity_t *e ) { if( e->curstate.movetype == MOVETYPE_FOLLOW && e->curstate.aiment > 0 ) { - cl_entity_t *parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); + cl_entity_t *parent = CL_GetEntityByIndex( e->curstate.aiment ); if( parent && parent->model && parent->model->type == mod_studio ) { @@ -3828,7 +3828,9 @@ void Mod_StudioUnloadTextures( void *data ) static model_t *pfnModelHandle( int modelindex ) { - return gEngfuncs.pfnGetModelByIndex( modelindex ); + if( modelindex < 0 || modelindex >= MAX_MODELS ) + return NULL; + return CL_ModelHandle( modelindex ); } static void *pfnMod_CacheCheck( struct cache_user_s *c ) diff --git a/ref/soft/r_beams.c b/ref/soft/r_beams.c index 49142cb2..2e77c841 100644 --- a/ref/soft/r_beams.c +++ b/ref/soft/r_beams.c @@ -956,7 +956,7 @@ void R_BeamDraw( BEAM *pbeam, float frametime ) model_t *model; vec3_t delta; - model = gEngfuncs.pfnGetModelByIndex( pbeam->modelIndex ); + model = CL_ModelHandle( pbeam->modelIndex ); SetBits( pbeam->flags, FBEAM_ISACTIVE ); if( !model || model->type != mod_sprite ) @@ -1159,7 +1159,7 @@ passed through this */ static void R_BeamSetup( BEAM *pbeam, vec3_t start, vec3_t end, int modelIndex, float life, float width, float amplitude, float brightness, float speed ) { - model_t *sprite = gEngfuncs.pfnGetModelByIndex( modelIndex ); + model_t *sprite = CL_ModelHandle( modelIndex ); if( !sprite ) return; diff --git a/ref/soft/r_bsp.c b/ref/soft/r_bsp.c index 6f5cede0..f12b70d8 100644 --- a/ref/soft/r_bsp.c +++ b/ref/soft/r_bsp.c @@ -949,7 +949,7 @@ void R_RenderWorld (void) c_drawnode=0; // auto cycle the world frame for texture animation - RI.currententity = gEngfuncs.GetEntityByIndex(0); + RI.currententity = CL_GetEntityByIndex(0); //RI.currententity->frame = (int)(gpGlobals->time*2); VectorCopy (RI.vieworg, tr.modelorg); diff --git a/ref/soft/r_context.c b/ref/soft/r_context.c index 703e04b9..016b5285 100644 --- a/ref/soft/r_context.c +++ b/ref/soft/r_context.c @@ -273,9 +273,10 @@ void Mod_UnloadTextures( model_t *mod ) } } -void GAME_EXPORT R_ProcessEntData( qboolean allocate ) +void GAME_EXPORT R_ProcessEntData( qboolean allocate, cl_entity_t *entities, unsigned int max_entities ) { - + tr.entities = entities; + tr.max_entities = max_entities; } // stubs diff --git a/ref/soft/r_decals.c b/ref/soft/r_decals.c index ac2b1501..57653be9 100644 --- a/ref/soft/r_decals.c +++ b/ref/soft/r_decals.c @@ -774,14 +774,14 @@ void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex if( entityIndex > 0 ) { - ent = gEngfuncs.GetEntityByIndex( entityIndex ); + ent = CL_GetEntityByIndex( entityIndex ); - if( modelIndex > 0 ) model = gEngfuncs.pfnGetModelByIndex( modelIndex ); - else if( ent != NULL ) model = gEngfuncs.pfnGetModelByIndex( ent->curstate.modelindex ); + if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex ); + else if( ent != NULL ) model = CL_ModelHandle( ent->curstate.modelindex ); else return; } else if( modelIndex > 0 ) - model = gEngfuncs.pfnGetModelByIndex( modelIndex ); + model = CL_ModelHandle( modelIndex ); else model = WORLDMODEL; if( !model ) return; diff --git a/ref/soft/r_edge.c b/ref/soft/r_edge.c index eead8ca8..d83dd1e2 100644 --- a/ref/soft/r_edge.c +++ b/ref/soft/r_edge.c @@ -1118,7 +1118,7 @@ void D_SolidSurf (surf_t *s) { if( alphaspans ) return; - RI.currententity = gEngfuncs.GetEntityByIndex(0); //r_worldentity; + RI.currententity = CL_GetEntityByIndex(0); //r_worldentity; tr.modelviewIdentity = true; } diff --git a/ref/soft/r_light.c b/ref/soft/r_light.c index aa341aff..41e8f740 100644 --- a/ref/soft/r_light.c +++ b/ref/soft/r_light.c @@ -155,7 +155,7 @@ void R_PushDlights( void ) tr.dlightframecount = tr.framecount; - RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); + RI.currententity = CL_GetEntityByIndex( 0 ); if( RI.currententity ) RI.currentmodel = RI.currententity->model; diff --git a/ref/soft/r_local.h b/ref/soft/r_local.h index 31f9fd4a..9ecb3f6d 100644 --- a/ref/soft/r_local.h +++ b/ref/soft/r_local.h @@ -41,14 +41,9 @@ typedef int fixed16_t; #include -#define WORLD (gEngfuncs.GetWorld()) -#define WORLDMODEL (gEngfuncs.pfnGetModelByIndex( 1 )) -#define MOVEVARS (gEngfuncs.pfnGetMoveVars()) - // make mod_ref.h? #define LM_SAMPLE_SIZE 16 - extern poolhandle_t r_temppool; #define BLOCK_SIZE tr.block_size // lightmap blocksize @@ -298,6 +293,13 @@ typedef struct int sample_size; uint sample_bits; qboolean map_unload; + + // get from engine + cl_entity_t *entities; + movevars_t *movevars; + model_t **models; + + uint max_entities; } gl_globals_t; typedef struct @@ -672,6 +674,21 @@ void TriBrightness( float brightness ); #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( (parm), 0 ) +// +// helper funcs +// +static inline cl_entity_t *CL_GetEntityByIndex( int index ) +{ + return &tr.entities[index]; +} + +static inline model_t *CL_ModelHandle( int index ) +{ + return tr.models[index]; +} + +#define WORLDMODEL (tr.models[1]) + extern ref_api_t gEngfuncs; extern ref_globals_t *gpGlobals; diff --git a/ref/soft/r_main.c b/ref/soft/r_main.c index 89bf9f2e..7f2c54a6 100644 --- a/ref/soft/r_main.c +++ b/ref/soft/r_main.c @@ -425,7 +425,7 @@ R_GetFarClip static float R_GetFarClip( void ) { if( WORLDMODEL && RI.drawWorld ) - return MOVEVARS->zmax * 1.73f; + return tr.movevars->zmax * 1.73f; return 2048.0f; } @@ -539,7 +539,7 @@ void R_RotateForEntity( cl_entity_t *e ) #if 0 float scale = 1.0f; - if( e == gEngfuncs.GetEntityByIndex( 0 ) ) + if( e == CL_GetEntityByIndex( 0 ) ) { R_LoadIdentity(); return; @@ -567,7 +567,7 @@ void R_TranslateForEntity( cl_entity_t *e ) #if 0 float scale = 1.0f; - if( e == gEngfuncs.GetEntityByIndex( 0 ) ) + if( e == CL_GetEntityByIndex( 0 ) ) { R_LoadIdentity(); return; @@ -784,7 +784,7 @@ void R_DrawEntitiesOnList( void ) //d_aflatcolor = 0; tr.blend = 1.0f; // GL_CheckForErrors(); - //RI.currententity = gEngfuncs.GetEntityByIndex(0); + //RI.currententity = CL_GetEntityByIndex(0); d_pdrawspans = R_PolysetFillSpans8; GL_SetRenderMode(kRenderNormal); // first draw solid entities @@ -815,7 +815,7 @@ void R_DrawEntitiesOnList( void ) extern void (*d_pdrawspans)(void *); extern void R_PolysetFillSpans8 ( void * ); d_pdrawspans = R_PolysetFillSpans8; - //RI.currententity = gEngfuncs.GetEntityByIndex(0); + //RI.currententity = CL_GetEntityByIndex(0); R_AliasSetUpTransform(); image_t *image = R_GetTexture(GL_LoadTexture("gfx/env/desertbk", NULL, 0, 0)); r_affinetridesc.pskin = image->pixels[0]; @@ -1938,6 +1938,10 @@ qboolean GAME_EXPORT R_Init( void ) return false; } + // see R_ProcessEntData for tr.entities initialization + tr.models = gEngfuncs.pfnGetModels(); + tr.movevars = gEngfuncs.pfnGetMoveVars(); + R_InitBlit( glblit ); R_InitImages(); diff --git a/ref/soft/r_part.c b/ref/soft/r_part.c index 0839255a..13ff4c3e 100644 --- a/ref/soft/r_part.c +++ b/ref/soft/r_part.c @@ -194,7 +194,7 @@ void GAME_EXPORT CL_DrawTracers( double frametime, particle_t *cl_active_tracers //pglDisable( GL_ALPHA_TEST ); //pglDepthMask( GL_FALSE ); - gravity = frametime * MOVEVARS->gravity; + gravity = frametime * tr.movevars->gravity; scale = 1.0 - (frametime * 0.9); if( scale < 0.0f ) scale = 0.0f; diff --git a/ref/soft/r_sprite.c b/ref/soft/r_sprite.c index 6e9ce0a1..e00205f0 100644 --- a/ref/soft/r_sprite.c +++ b/ref/soft/r_sprite.c @@ -895,7 +895,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) { cl_entity_t *parent; - parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); + parent = CL_GetEntityByIndex( e->curstate.aiment ); if( parent && parent->model ) { diff --git a/ref/soft/r_studio.c b/ref/soft/r_studio.c index 1da13e1f..3ce9d847 100644 --- a/ref/soft/r_studio.c +++ b/ref/soft/r_studio.c @@ -1846,7 +1846,7 @@ void R_StudioRenderShadow( int iSprite, float *p1, float *p2, float *p3, float * if( !p1 || !p2 || !p3 || !p4 ) return; - if( TriSpriteTexture( gEngfuncs.pfnGetModelByIndex( iSprite ), 0 )) + if( TriSpriteTexture( CL_ModelHandle( iSprite ), 0 )) { TriRenderMode( kRenderTransAlpha ); _TriColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); @@ -3137,7 +3137,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) // copy attachments into global entity array if( RI.currententity->index > 0 ) { - cl_entity_t *ent = gEngfuncs.GetEntityByIndex( RI.currententity->index ); + cl_entity_t *ent = CL_GetEntityByIndex( RI.currententity->index ); memcpy( ent->attachment, RI.currententity->attachment, sizeof( vec3_t ) * 4 ); } } @@ -3180,7 +3180,7 @@ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) if( pplayer->weaponmodel ) { cl_entity_t saveent = *RI.currententity; - model_t *pweaponmodel = gEngfuncs.pfnGetModelByIndex( pplayer->weaponmodel ); + model_t *pweaponmodel = CL_ModelHandle( pplayer->weaponmodel ); m_pStudioHeader = (studiohdr_t *)gEngfuncs.Mod_Extradata( mod_studio, pweaponmodel ); @@ -3266,7 +3266,7 @@ static int R_StudioDrawModel( int flags ) // copy attachments into global entity array if( RI.currententity->index > 0 ) { - cl_entity_t *ent = gEngfuncs.GetEntityByIndex( RI.currententity->index ); + cl_entity_t *ent = CL_GetEntityByIndex( RI.currententity->index ); memcpy( ent->attachment, RI.currententity->attachment, sizeof( vec3_t ) * 4 ); } } @@ -3335,7 +3335,7 @@ void R_DrawStudioModel( cl_entity_t *e ) { if( e->curstate.movetype == MOVETYPE_FOLLOW && e->curstate.aiment > 0 ) { - cl_entity_t *parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); + cl_entity_t *parent = CL_GetEntityByIndex( e->curstate.aiment ); if( parent && parent->model && parent->model->type == mod_studio ) { @@ -3610,7 +3610,7 @@ void Mod_StudioUnloadTextures( void *data ) static model_t *pfnModelHandle( int modelindex ) { - return gEngfuncs.pfnGetModelByIndex( modelindex ); + return CL_ModelHandle( modelindex ); } static void *pfnMod_CacheCheck( struct cache_user_s *c )