Browse Source

engine, ref: eliminate calls to global arrays, instead store array pointers at renderer side

pull/2/head
Alibek Omarov 1 year ago
parent
commit
7e9f87de2d
  1. 4
      engine/client/cl_game.c
  2. 8
      engine/client/ref_common.c
  3. 5
      engine/ref_api.h
  4. 4
      ref/gl/gl_beams.c
  5. 10
      ref/gl/gl_context.c
  6. 4
      ref/gl/gl_cull.c
  7. 6
      ref/gl/gl_dbghulls.c
  8. 10
      ref/gl/gl_decals.c
  9. 28
      ref/gl/gl_local.h
  10. 5
      ref/gl/gl_opengl.c
  11. 2
      ref/gl/gl_rlight.c
  12. 16
      ref/gl/gl_rmain.c
  13. 2
      ref/gl/gl_rmisc.c
  14. 2
      ref/gl/gl_rpart.c
  15. 20
      ref/gl/gl_rsurf.c
  16. 2
      ref/gl/gl_sprite.c
  17. 14
      ref/gl/gl_studio.c
  18. 4
      ref/soft/r_beams.c
  19. 2
      ref/soft/r_bsp.c
  20. 5
      ref/soft/r_context.c
  21. 8
      ref/soft/r_decals.c
  22. 2
      ref/soft/r_edge.c
  23. 2
      ref/soft/r_light.c
  24. 27
      ref/soft/r_local.h
  25. 14
      ref/soft/r_main.c
  26. 2
      ref/soft/r_part.c
  27. 2
      ref/soft/r_sprite.c
  28. 12
      ref/soft/r_studio.c

4
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 ); 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 ) void CL_FreeEdicts( void )
{ {
ref.dllFuncs.R_ProcessEntData( false ); ref.dllFuncs.R_ProcessEntData( false, NULL, 0 );
if( clgame.entities ) if( clgame.entities )
Mem_Free( clgame.entities ); Mem_Free( clgame.entities );

8
engine/client/ref_common.c

@ -212,6 +212,11 @@ static qboolean R_Init_Video_( const int type )
return R_Init_Video( type ); return R_Init_Video( type );
} }
static model_t **pfnGetModels( void )
{
return cl.models;
}
static ref_api_t gEngfuncs = static ref_api_t gEngfuncs =
{ {
pfnEngineGetParm, pfnEngineGetParm,
@ -248,7 +253,6 @@ static ref_api_t gEngfuncs =
CL_GetLocalPlayer, CL_GetLocalPlayer,
CL_GetViewModel, CL_GetViewModel,
CL_GetEntityByIndex,
R_BeamGetEntity, R_BeamGetEntity,
CL_GetWaterEntity, CL_GetWaterEntity,
CL_AddVisibleEntity, CL_AddVisibleEntity,
@ -272,7 +276,7 @@ static ref_api_t gEngfuncs =
Mod_ForName, Mod_ForName,
pfnMod_Extradata, pfnMod_Extradata,
CL_ModelHandle, pfnGetModels,
CL_GetRemapInfoForEntity, CL_GetRemapInfoForEntity,
CL_AllocRemapInfo, CL_AllocRemapInfo,

5
engine/ref_api.h

@ -301,7 +301,6 @@ typedef struct ref_api_s
// entity management // entity management
struct cl_entity_s *(*GetLocalPlayer)( void ); struct cl_entity_s *(*GetLocalPlayer)( void );
struct cl_entity_s *(*GetViewModel)( 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 *(*R_BeamGetEntity)( int index );
struct cl_entity_s *(*CL_GetWaterEntity)( const vec3_t p ); struct cl_entity_s *(*CL_GetWaterEntity)( const vec3_t p );
qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType ); qboolean (*CL_AddVisibleEntity)( cl_entity_t *ent, int entityType );
@ -329,7 +328,7 @@ typedef struct ref_api_s
// model management // model management
model_t *(*Mod_ForName)( const char *name, qboolean crash, qboolean trackCRC ); model_t *(*Mod_ForName)( const char *name, qboolean crash, qboolean trackCRC );
void *(*Mod_Extradata)( int type, model_t *model ); void *(*Mod_Extradata)( int type, model_t *model );
struct model_s *(*pfnGetModelByIndex)( int index ); // CL_ModelHandle struct model_s **(*pfnGetModels)( void );
// remap // remap
struct remap_info_s *(*CL_GetRemapInfoForEntity)( cl_entity_t *e ); 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 ); qboolean (*R_AddEntity)( struct cl_entity_s *clent, int type );
void (*CL_AddCustomBeam)( cl_entity_t *pEnvBeam ); 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 // debug
void (*R_ShowTextures)( void ); void (*R_ShowTextures)( void );

4
ref/gl/gl_beams.c

@ -943,7 +943,7 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
model_t *model; model_t *model;
vec3_t delta; vec3_t delta;
model = gEngfuncs.pfnGetModelByIndex( pbeam->modelIndex ); model = CL_ModelHandle( pbeam->modelIndex );
SetBits( pbeam->flags, FBEAM_ISACTIVE ); SetBits( pbeam->flags, FBEAM_ISACTIVE );
if( !model || model->type != mod_sprite ) 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 ) 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; if( !sprite ) return;

10
ref/gl/gl_context.c

@ -295,13 +295,21 @@ const byte *GL_TextureData( unsigned int texnum )
return NULL; return NULL;
} }
void R_ProcessEntData( qboolean allocate ) void R_ProcessEntData( qboolean allocate, cl_entity_t *entities, unsigned int max_entities )
{ {
if( !allocate ) if( !allocate )
{ {
tr.draw_list->num_solid_entities = 0; tr.draw_list->num_solid_entities = 0;
tr.draw_list->num_trans_entities = 0; tr.draw_list->num_trans_entities = 0;
tr.draw_list->num_beam_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 ) if( gEngfuncs.drawFuncs->R_ProcessEntData )

4
ref/gl/gl_cull.c

@ -77,7 +77,7 @@ int R_CullSurface( msurface_t *surf, gl_frustum_t *frustum, uint clipflags )
return CULL_VISIBLE; return CULL_VISIBLE;
// world surfaces can be culled by vis frame too // 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; return CULL_VISFRAME;
// only static ents can be culled by frustum // 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; 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 ); else Matrix4x4_VectorRotate( RI.objectMatrix, surf->plane->normal, orthonormal );
dist = orthonormal[2]; dist = orthonormal[2];
} }

6
ref/gl/gl_dbghulls.c

@ -28,7 +28,7 @@ GNU General Public License for more details.
// REFTODO: rewrite in triapi // REFTODO: rewrite in triapi
void R_DrawWorldHull( void ) void R_DrawWorldHull( void )
{ {
hull_model_t *hull = &WORLD->hull_models[0]; hull_model_t *hull = &tr.world->hull_models[0];
winding_t *poly; winding_t *poly;
int i; int i;
@ -69,10 +69,10 @@ void R_DrawModelHull( void )
return; return;
i = atoi( RI.currentmodel->name + 1 ); i = atoi( RI.currentmodel->name + 1 );
if( i < 1 || i >= WORLD->num_hull_models ) if( i < 1 || i >= tr.world->num_hull_models )
return; return;
hull = &WORLD->hull_models[i]; hull = &tr.world->hull_models[i];
pglPolygonOffset( 1.0f, 2.0 ); pglPolygonOffset( 1.0f, 2.0 );
pglEnable( GL_POLYGON_OFFSET_FILL ); pglEnable( GL_POLYGON_OFFSET_FILL );

10
ref/gl/gl_decals.c

@ -750,15 +750,15 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos
if( entityIndex > 0 ) if( entityIndex > 0 )
{ {
ent = gEngfuncs.GetEntityByIndex( entityIndex ); ent = CL_GetEntityByIndex( entityIndex );
if( modelIndex > 0 ) model = gEngfuncs.pfnGetModelByIndex( modelIndex ); if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex );
else if( ent != NULL ) model = gEngfuncs.pfnGetModelByIndex( ent->curstate.modelindex ); else if( ent != NULL ) model = CL_ModelHandle( ent->curstate.modelindex );
else return; else return;
} }
else if( modelIndex > 0 ) else if( modelIndex > 0 )
model = gEngfuncs.pfnGetModelByIndex( modelIndex ); model = CL_ModelHandle( modelIndex );
else model = WORLDMODEL; else model = CL_ModelHandle( 1 );
if( !model ) return; if( !model ) return;

28
ref/gl/gl_local.h

@ -57,10 +57,6 @@ void VGL_ShimEndFrame( void );
#include <stdio.h> #include <stdio.h>
#define WORLD (gEngfuncs.GetWorld())
#define WORLDMODEL (gEngfuncs.pfnGetModelByIndex( 1 ))
#define MOVEVARS (gEngfuncs.pfnGetMoveVars())
// make mod_ref.h? // make mod_ref.h?
#define LM_SAMPLE_SIZE 16 #define LM_SAMPLE_SIZE 16
@ -257,6 +253,14 @@ typedef struct
vec3_t modelorg; // relative to viewpoint vec3_t modelorg; // relative to viewpoint
qboolean fCustomSkybox; 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; } gl_globals_t;
typedef struct typedef struct
@ -707,7 +711,6 @@ typedef struct
qboolean in2DMode; qboolean in2DMode;
} glstate_t; } glstate_t;
typedef struct typedef struct
{ {
qboolean initialized; // OpenGL subsystem started qboolean initialized; // OpenGL subsystem started
@ -724,6 +727,21 @@ extern ref_globals_t *gpGlobals;
#define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm)
#define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( ( parm ), 0 ) #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 // renderer cvars
// //

5
ref/gl/gl_opengl.c

@ -1284,6 +1284,11 @@ qboolean R_Init( void )
return false; return false;
} }
// see R_ProcessEntData for tr.entities initialization
tr.world = gEngfuncs.GetWorld();
tr.models = gEngfuncs.pfnGetModels();
tr.movevars = gEngfuncs.pfnGetMoveVars();
GL_SetDefaults(); GL_SetDefaults();
R_CheckVBO(); R_CheckVBO();
R_InitImages(); R_InitImages();

2
ref/gl/gl_rlight.c

@ -152,7 +152,7 @@ void R_PushDlights( void )
tr.dlightframecount = tr.framecount; tr.dlightframecount = tr.framecount;
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
if( RI.currententity ) if( RI.currententity )
RI.currentmodel = RI.currententity->model; RI.currentmodel = RI.currententity->model;

16
ref/gl/gl_rmain.c

@ -324,7 +324,7 @@ R_GetFarClip
static float R_GetFarClip( void ) static float R_GetFarClip( void )
{ {
if( WORLDMODEL && RI.drawWorld ) if( WORLDMODEL && RI.drawWorld )
return MOVEVARS->zmax * 1.73f; return tr.movevars->zmax * 1.73f;
return 2048.0f; return 2048.0f;
} }
@ -429,7 +429,7 @@ void R_RotateForEntity( cl_entity_t *e )
{ {
float scale = 1.0f; float scale = 1.0f;
if( e == gEngfuncs.GetEntityByIndex( 0 ) ) if( e == CL_GetEntityByIndex( 0 ))
{ {
R_LoadIdentity(); R_LoadIdentity();
return; return;
@ -455,7 +455,7 @@ void R_TranslateForEntity( cl_entity_t *e )
{ {
float scale = 1.0f; float scale = 1.0f;
if( e == gEngfuncs.GetEntityByIndex( 0 ) ) if( e == CL_GetEntityByIndex( 0 ))
{ {
R_LoadIdentity(); R_LoadIdentity();
return; return;
@ -669,7 +669,7 @@ static void R_CheckFog( void )
// quake global fog // quake global fog
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE )) if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ))
{ {
if( !MOVEVARS->fog_settings ) if( !tr.movevars->fog_settings )
{ {
if( pglIsEnabled( GL_FOG )) if( pglIsEnabled( GL_FOG ))
pglDisable( GL_FOG ); pglDisable( GL_FOG );
@ -678,10 +678,10 @@ static void R_CheckFog( void )
} }
// quake-style global fog // quake-style global fog
RI.fogColor[0] = ((MOVEVARS->fog_settings & 0xFF000000) >> 24) / 255.0f; RI.fogColor[0] = ((tr.movevars->fog_settings & 0xFF000000) >> 24) / 255.0f;
RI.fogColor[1] = ((MOVEVARS->fog_settings & 0xFF0000) >> 16) / 255.0f; RI.fogColor[1] = ((tr.movevars->fog_settings & 0xFF0000) >> 16) / 255.0f;
RI.fogColor[2] = ((MOVEVARS->fog_settings & 0xFF00) >> 8) / 255.0f; RI.fogColor[2] = ((tr.movevars->fog_settings & 0xFF00) >> 8) / 255.0f;
RI.fogDensity = ((MOVEVARS->fog_settings & 0xFF) / 255.0f) * 0.01f; RI.fogDensity = ((tr.movevars->fog_settings & 0xFF) / 255.0f) * 0.01f;
RI.fogStart = RI.fogEnd = 0.0f; RI.fogStart = RI.fogEnd = 0.0f;
RI.fogColor[3] = 1.0f; RI.fogColor[3] = 1.0f;
RI.fogCustom = false; RI.fogCustom = false;

2
ref/gl/gl_rmisc.c

@ -146,7 +146,7 @@ void R_NewMap( void )
tx->texturechain = NULL; tx->texturechain = NULL;
} }
R_SetupSky( MOVEVARS->skyName ); R_SetupSky( tr.movevars->skyName );
GL_BuildLightmaps (); GL_BuildLightmaps ();
R_GenerateVBO(); R_GenerateVBO();

2
ref/gl/gl_rpart.c

@ -188,7 +188,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers )
pglDisable( GL_ALPHA_TEST ); pglDisable( GL_ALPHA_TEST );
pglDepthMask( GL_FALSE ); pglDepthMask( GL_FALSE );
gravity = frametime * MOVEVARS->gravity; gravity = frametime * tr.movevars->gravity;
scale = 1.0 - (frametime * 0.9); scale = 1.0 - (frametime * 0.9);
if( scale < 0.0f ) scale = 0.0f; if( scale < 0.0f ) scale = 0.0f;

20
ref/gl/gl_rsurf.c

@ -758,7 +758,7 @@ void DrawGLPoly( glpoly_t *p, float xScale, float yScale )
float flRate, flAngle; float flRate, flAngle;
gl_texture_t *texture; 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 // same as doom speed
flConveyorSpeed = -35.0f; flConveyorSpeed = -35.0f;
@ -1235,7 +1235,7 @@ void R_DrawTextureChains( void )
GL_SetupFogColorForSurfaces(); GL_SetupFogColorForSurfaces();
// restore worldmodel // restore worldmodel
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
RI.currentmodel = RI.currententity->model; RI.currentmodel = RI.currententity->model;
if( ENGINE_GET_PARM( PARM_SKY_SPHERE ) ) if( ENGINE_GET_PARM( PARM_SKY_SPHERE ) )
@ -1266,7 +1266,7 @@ void R_DrawTextureChains( void )
if( !s || ( i == tr.skytexturenum )) if( !s || ( i == tr.skytexturenum ))
continue; 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 continue; // draw translucent water later
if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) && FBitSet( s->flags, SURF_TRANSPARENT )) if( ENGINE_GET_PARM( PARM_QUAKE_COMPATIBLE ) && FBitSet( s->flags, SURF_TRANSPARENT ))
@ -1309,7 +1309,7 @@ void R_DrawAlphaTextureChains( void )
GL_SetupFogColorForSurfaces(); GL_SetupFogColorForSurfaces();
// restore worldmodel // restore worldmodel
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
RI.currentmodel = RI.currententity->model; RI.currentmodel = RI.currententity->model;
RI.currententity->curstate.rendermode = kRenderTransAlpha; RI.currententity->curstate.rendermode = kRenderTransAlpha;
draw_alpha_surfaces = false; draw_alpha_surfaces = false;
@ -1350,11 +1350,11 @@ void R_DrawWaterSurfaces( void )
return; return;
// non-transparent water is already drawed // non-transparent water is already drawed
if( MOVEVARS->wateralpha >= 1.0f ) if( tr.movevars->wateralpha >= 1.0f )
return; return;
// restore worldmodel // restore worldmodel
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
RI.currentmodel = RI.currententity->model; RI.currentmodel = RI.currententity->model;
// go back to the world matrix // go back to the world matrix
@ -1365,7 +1365,7 @@ void R_DrawWaterSurfaces( void )
pglDisable( GL_ALPHA_TEST ); pglDisable( GL_ALPHA_TEST );
pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); pglBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); 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++ ) 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 // paranoia issues: when gl_renderer is "0" we need have something valid for currententity
// to prevent crashing until HeadShield drawing. // to prevent crashing until HeadShield drawing.
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
if( !RI.currententity ) if( !RI.currententity )
return; return;
@ -3490,7 +3490,7 @@ void GL_RebuildLightmaps( void )
for( i = 0; i < ENGINE_GET_PARM( PARM_NUMMODELS ); i++ ) 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; continue;
if( m->name[0] == '*' || m->type != mod_brush ) 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++ ) 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; continue;
if( m->name[0] == '*' || m->type != mod_brush ) if( m->name[0] == '*' || m->type != mod_brush )

2
ref/gl/gl_sprite.c

@ -826,7 +826,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
{ {
cl_entity_t *parent; cl_entity_t *parent;
parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); parent = CL_GetEntityByIndex( e->curstate.aiment );
if( parent && parent->model ) if( parent && parent->model )
{ {

14
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 ) if( !p1 || !p2 || !p3 || !p4 )
return; return;
if( TriSpriteTexture( gEngfuncs.pfnGetModelByIndex( iSprite ), 0 )) if( TriSpriteTexture( CL_ModelHandle( iSprite ), 0 ))
{ {
TriRenderMode( kRenderTransAlpha ); TriRenderMode( kRenderTransAlpha );
TriColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); 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 // copy attachments into global entity array
if( RI.currententity->index > 0 ) 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 ); 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 ) if( pplayer->weaponmodel )
{ {
cl_entity_t saveent = *RI.currententity; 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 ); 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 // copy attachments into global entity array
if( RI.currententity->index > 0 ) 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 ); 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 ) 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 ) if( parent && parent->model && parent->model->type == mod_studio )
{ {
@ -3828,7 +3828,9 @@ void Mod_StudioUnloadTextures( void *data )
static model_t *pfnModelHandle( int modelindex ) 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 ) static void *pfnMod_CacheCheck( struct cache_user_s *c )

4
ref/soft/r_beams.c

@ -956,7 +956,7 @@ void R_BeamDraw( BEAM *pbeam, float frametime )
model_t *model; model_t *model;
vec3_t delta; vec3_t delta;
model = gEngfuncs.pfnGetModelByIndex( pbeam->modelIndex ); model = CL_ModelHandle( pbeam->modelIndex );
SetBits( pbeam->flags, FBEAM_ISACTIVE ); SetBits( pbeam->flags, FBEAM_ISACTIVE );
if( !model || model->type != mod_sprite ) 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 ) 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; if( !sprite ) return;

2
ref/soft/r_bsp.c

@ -949,7 +949,7 @@ void R_RenderWorld (void)
c_drawnode=0; c_drawnode=0;
// auto cycle the world frame for texture animation // 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); //RI.currententity->frame = (int)(gpGlobals->time*2);
VectorCopy (RI.vieworg, tr.modelorg); VectorCopy (RI.vieworg, tr.modelorg);

5
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 // stubs

8
ref/soft/r_decals.c

@ -774,14 +774,14 @@ void GAME_EXPORT R_DecalShoot( int textureIndex, int entityIndex, int modelIndex
if( entityIndex > 0 ) if( entityIndex > 0 )
{ {
ent = gEngfuncs.GetEntityByIndex( entityIndex ); ent = CL_GetEntityByIndex( entityIndex );
if( modelIndex > 0 ) model = gEngfuncs.pfnGetModelByIndex( modelIndex ); if( modelIndex > 0 ) model = CL_ModelHandle( modelIndex );
else if( ent != NULL ) model = gEngfuncs.pfnGetModelByIndex( ent->curstate.modelindex ); else if( ent != NULL ) model = CL_ModelHandle( ent->curstate.modelindex );
else return; else return;
} }
else if( modelIndex > 0 ) else if( modelIndex > 0 )
model = gEngfuncs.pfnGetModelByIndex( modelIndex ); model = CL_ModelHandle( modelIndex );
else model = WORLDMODEL; else model = WORLDMODEL;
if( !model ) return; if( !model ) return;

2
ref/soft/r_edge.c

@ -1118,7 +1118,7 @@ void D_SolidSurf (surf_t *s)
{ {
if( alphaspans ) if( alphaspans )
return; return;
RI.currententity = gEngfuncs.GetEntityByIndex(0); //r_worldentity; RI.currententity = CL_GetEntityByIndex(0); //r_worldentity;
tr.modelviewIdentity = true; tr.modelviewIdentity = true;
} }

2
ref/soft/r_light.c

@ -155,7 +155,7 @@ void R_PushDlights( void )
tr.dlightframecount = tr.framecount; tr.dlightframecount = tr.framecount;
RI.currententity = gEngfuncs.GetEntityByIndex( 0 ); RI.currententity = CL_GetEntityByIndex( 0 );
if( RI.currententity ) if( RI.currententity )
RI.currentmodel = RI.currententity->model; RI.currentmodel = RI.currententity->model;

27
ref/soft/r_local.h

@ -41,14 +41,9 @@ typedef int fixed16_t;
#include <stdio.h> #include <stdio.h>
#define WORLD (gEngfuncs.GetWorld())
#define WORLDMODEL (gEngfuncs.pfnGetModelByIndex( 1 ))
#define MOVEVARS (gEngfuncs.pfnGetMoveVars())
// make mod_ref.h? // make mod_ref.h?
#define LM_SAMPLE_SIZE 16 #define LM_SAMPLE_SIZE 16
extern poolhandle_t r_temppool; extern poolhandle_t r_temppool;
#define BLOCK_SIZE tr.block_size // lightmap blocksize #define BLOCK_SIZE tr.block_size // lightmap blocksize
@ -298,6 +293,13 @@ typedef struct
int sample_size; int sample_size;
uint sample_bits; uint sample_bits;
qboolean map_unload; qboolean map_unload;
// get from engine
cl_entity_t *entities;
movevars_t *movevars;
model_t **models;
uint max_entities;
} gl_globals_t; } gl_globals_t;
typedef struct typedef struct
@ -672,6 +674,21 @@ void TriBrightness( float brightness );
#define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm) #define ENGINE_GET_PARM_ (*gEngfuncs.EngineGetParm)
#define ENGINE_GET_PARM( parm ) ENGINE_GET_PARM_( (parm), 0 ) #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_api_t gEngfuncs;
extern ref_globals_t *gpGlobals; extern ref_globals_t *gpGlobals;

14
ref/soft/r_main.c

@ -425,7 +425,7 @@ R_GetFarClip
static float R_GetFarClip( void ) static float R_GetFarClip( void )
{ {
if( WORLDMODEL && RI.drawWorld ) if( WORLDMODEL && RI.drawWorld )
return MOVEVARS->zmax * 1.73f; return tr.movevars->zmax * 1.73f;
return 2048.0f; return 2048.0f;
} }
@ -539,7 +539,7 @@ void R_RotateForEntity( cl_entity_t *e )
#if 0 #if 0
float scale = 1.0f; float scale = 1.0f;
if( e == gEngfuncs.GetEntityByIndex( 0 ) ) if( e == CL_GetEntityByIndex( 0 ) )
{ {
R_LoadIdentity(); R_LoadIdentity();
return; return;
@ -567,7 +567,7 @@ void R_TranslateForEntity( cl_entity_t *e )
#if 0 #if 0
float scale = 1.0f; float scale = 1.0f;
if( e == gEngfuncs.GetEntityByIndex( 0 ) ) if( e == CL_GetEntityByIndex( 0 ) )
{ {
R_LoadIdentity(); R_LoadIdentity();
return; return;
@ -784,7 +784,7 @@ void R_DrawEntitiesOnList( void )
//d_aflatcolor = 0; //d_aflatcolor = 0;
tr.blend = 1.0f; tr.blend = 1.0f;
// GL_CheckForErrors(); // GL_CheckForErrors();
//RI.currententity = gEngfuncs.GetEntityByIndex(0); //RI.currententity = CL_GetEntityByIndex(0);
d_pdrawspans = R_PolysetFillSpans8; d_pdrawspans = R_PolysetFillSpans8;
GL_SetRenderMode(kRenderNormal); GL_SetRenderMode(kRenderNormal);
// first draw solid entities // first draw solid entities
@ -815,7 +815,7 @@ void R_DrawEntitiesOnList( void )
extern void (*d_pdrawspans)(void *); extern void (*d_pdrawspans)(void *);
extern void R_PolysetFillSpans8 ( void * ); extern void R_PolysetFillSpans8 ( void * );
d_pdrawspans = R_PolysetFillSpans8; d_pdrawspans = R_PolysetFillSpans8;
//RI.currententity = gEngfuncs.GetEntityByIndex(0); //RI.currententity = CL_GetEntityByIndex(0);
R_AliasSetUpTransform(); R_AliasSetUpTransform();
image_t *image = R_GetTexture(GL_LoadTexture("gfx/env/desertbk", NULL, 0, 0)); image_t *image = R_GetTexture(GL_LoadTexture("gfx/env/desertbk", NULL, 0, 0));
r_affinetridesc.pskin = image->pixels[0]; r_affinetridesc.pskin = image->pixels[0];
@ -1938,6 +1938,10 @@ qboolean GAME_EXPORT R_Init( void )
return false; return false;
} }
// see R_ProcessEntData for tr.entities initialization
tr.models = gEngfuncs.pfnGetModels();
tr.movevars = gEngfuncs.pfnGetMoveVars();
R_InitBlit( glblit ); R_InitBlit( glblit );
R_InitImages(); R_InitImages();

2
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 ); //pglDisable( GL_ALPHA_TEST );
//pglDepthMask( GL_FALSE ); //pglDepthMask( GL_FALSE );
gravity = frametime * MOVEVARS->gravity; gravity = frametime * tr.movevars->gravity;
scale = 1.0 - (frametime * 0.9); scale = 1.0 - (frametime * 0.9);
if( scale < 0.0f ) scale = 0.0f; if( scale < 0.0f ) scale = 0.0f;

2
ref/soft/r_sprite.c

@ -895,7 +895,7 @@ void R_DrawSpriteModel( cl_entity_t *e )
{ {
cl_entity_t *parent; cl_entity_t *parent;
parent = gEngfuncs.GetEntityByIndex( e->curstate.aiment ); parent = CL_GetEntityByIndex( e->curstate.aiment );
if( parent && parent->model ) if( parent && parent->model )
{ {

12
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 ) if( !p1 || !p2 || !p3 || !p4 )
return; return;
if( TriSpriteTexture( gEngfuncs.pfnGetModelByIndex( iSprite ), 0 )) if( TriSpriteTexture( CL_ModelHandle( iSprite ), 0 ))
{ {
TriRenderMode( kRenderTransAlpha ); TriRenderMode( kRenderTransAlpha );
_TriColor4f( 0.0f, 0.0f, 0.0f, 1.0f ); _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 // copy attachments into global entity array
if( RI.currententity->index > 0 ) 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 ); 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 ) if( pplayer->weaponmodel )
{ {
cl_entity_t saveent = *RI.currententity; 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 ); 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 // copy attachments into global entity array
if( RI.currententity->index > 0 ) 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 ); 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 ) 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 ) if( parent && parent->model && parent->model->type == mod_studio )
{ {
@ -3610,7 +3610,7 @@ void Mod_StudioUnloadTextures( void *data )
static model_t *pfnModelHandle( int modelindex ) static model_t *pfnModelHandle( int modelindex )
{ {
return gEngfuncs.pfnGetModelByIndex( modelindex ); return CL_ModelHandle( modelindex );
} }
static void *pfnMod_CacheCheck( struct cache_user_s *c ) static void *pfnMod_CacheCheck( struct cache_user_s *c )

Loading…
Cancel
Save