Skip to content

Commit

Permalink
[SP] Match AddPolyToScene with MP
Browse files Browse the repository at this point in the history
  • Loading branch information
SomaZ committed Oct 25, 2023
1 parent b23b3f1 commit 63249af
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 67 deletions.
2 changes: 1 addition & 1 deletion code/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1006,7 +1006,7 @@ intptr_t CL_CgameSystemCalls( intptr_t *args ) {
case CG_R_GETLIGHTING:
return re.GetLighting( (const float * ) VMA(1), (float *) VMA(2), (float *) VMA(3), (float *) VMA(4) );
case CG_R_ADDPOLYTOSCENE:
re.AddPolyToScene( args[1], args[2], (const polyVert_t *) VMA(3) );
re.AddPolyToScene( args[1], args[2], (const polyVert_t *) VMA(3), 1 );
return 0;
case CG_R_ADDLIGHTTOSCENE:
re.AddLightToScene( (const float *) VMA(1), VMF(2), VMF(3), VMF(4), VMF(5) );
Expand Down
2 changes: 1 addition & 1 deletion code/client/cl_cin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ static void CIN_AddTextCrawl()

// render it out
re.ClearScene();
re.AddPolyToScene( cinTable[CL_handle].hCRAWLTEXT, 4, verts );
re.AddPolyToScene( cinTable[CL_handle].hCRAWLTEXT, 4, verts, 1 );
re.RenderScene( &refdef );

//time's up
Expand Down
2 changes: 1 addition & 1 deletion code/client/cl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void CL_InitUI( void ) {
#endif
uii.R_ClearScene = re.ClearScene;
uii.R_AddRefEntityToScene = re.AddRefEntityToScene;
uii.R_AddPolyToScene = re.AddPolyToScene;
uii.R_AddPolyToScene = re.AddPolyToScene;
uii.R_AddLightToScene = re.AddLightToScene;
uii.R_RenderScene = re.RenderScene;

Expand Down
2 changes: 1 addition & 1 deletion code/rd-common/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ typedef struct {
// Nothing is drawn until R_RenderScene is called.
void (*ClearScene)( void );
void (*AddRefEntityToScene)( const refEntity_t *re );
void (*AddPolyToScene)( qhandle_t hShader , int numVerts, const polyVert_t *verts );
void (*AddPolyToScene)( qhandle_t hShader , int numVerts, const polyVert_t *verts, int numPolys );
void (*AddLightToScene)( const vec3_t org, float intensity, float r, float g, float b );
void (*RenderScene)( const refdef_t *fd );
qboolean(*GetLighting)( const vec3_t org, vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir);
Expand Down
2 changes: 1 addition & 1 deletion code/rd-vanilla/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ void R_InitNextFrame( void );

void RE_ClearScene( void );
void RE_AddRefEntityToScene( const refEntity_t *ent );
void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts );
void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int numPolys );
void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b );
void RE_RenderScene( const refdef_t *fd );

Expand Down
109 changes: 56 additions & 53 deletions code/rd-vanilla/tr_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ RE_AddPolyToScene
=====================
*/
void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts ) {
void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *verts, int numPolys ) {
srfPoly_t *poly;
int i;
int i, j;
int fogIndex = 0;
fog_t *fog;
vec3_t bounds[2];
Expand All @@ -134,67 +134,70 @@ void RE_AddPolyToScene( qhandle_t hShader , int numVerts, const polyVert_t *vert
return;
}

if ( r_numpolyverts + numVerts >= MAX_POLYVERTS || r_numpolys >= MAX_POLYS ) {
/*
NOTE TTimo this was initially a PRINT_WARNING
but it happens a lot with high fighting scenes and particles
since we don't plan on changing the const and making for room for those effects
simply cut this message to developer only
*/
ri.Printf( PRINT_DEVELOPER, S_COLOR_YELLOW "WARNING: RE_AddPolyToScene: r_max_polys or r_max_polyverts reached\n");
return;
}
for (j = 0; j < numPolys; j++) {
if (r_numpolyverts + numVerts >= MAX_POLYVERTS || r_numpolys >= MAX_POLYS) {
/*
NOTE TTimo this was initially a PRINT_WARNING
but it happens a lot with high fighting scenes and particles
since we don't plan on changing the const and making for room for those effects
simply cut this message to developer only
*/
ri.Printf(PRINT_DEVELOPER, S_COLOR_YELLOW "WARNING: RE_AddPolyToScene: r_max_polys or r_max_polyverts reached\n");
return;
}

poly = &backEndData->polys[r_numpolys];
poly->surfaceType = SF_POLY;
poly->hShader = hShader;
poly->numVerts = numVerts;
poly->verts = &backEndData->polyVerts[r_numpolyverts];

memcpy( poly->verts, verts, numVerts * sizeof( *verts ) );
r_numpolys++;
r_numpolyverts += numVerts;

// see if it is in a fog volume
if ( !tr.world || tr.world->numfogs == 1) {
fogIndex = 0;
} else {
// find which fog volume the poly is in
VectorCopy( poly->verts[0].xyz, bounds[0] );
VectorCopy( poly->verts[0].xyz, bounds[1] );
for ( i = 1 ; i < poly->numVerts ; i++ ) {
AddPointToBounds( poly->verts[i].xyz, bounds[0], bounds[1] );
poly = &backEndData->polys[r_numpolys];
poly->surfaceType = SF_POLY;
poly->hShader = hShader;
poly->numVerts = numVerts;
poly->verts = &backEndData->polyVerts[r_numpolyverts];

memcpy( poly->verts, &verts[numVerts*j], numVerts * sizeof( *verts ) );
r_numpolys++;
r_numpolyverts += numVerts;

// see if it is in a fog volume
if (!tr.world || tr.world->numfogs == 1) {
fogIndex = 0;
}
for ( int fI = 1 ; fI < tr.world->numfogs ; fI++ ) {
fog = &tr.world->fogs[fI];
if ( bounds[0][0] >= fog->bounds[0][0]
&& bounds[0][1] >= fog->bounds[0][1]
&& bounds[0][2] >= fog->bounds[0][2]
&& bounds[1][0] <= fog->bounds[1][0]
&& bounds[1][1] <= fog->bounds[1][1]
&& bounds[1][2] <= fog->bounds[1][2] )
{//completely in this one
fogIndex = fI;
break;
else {
// find which fog volume the poly is in
VectorCopy(poly->verts[0].xyz, bounds[0]);
VectorCopy(poly->verts[0].xyz, bounds[1]);
for (i = 1; i < poly->numVerts; i++) {
AddPointToBounds(poly->verts[i].xyz, bounds[0], bounds[1]);
}
else if ( ( bounds[0][0] >= fog->bounds[0][0] && bounds[0][1] >= fog->bounds[0][1] && bounds[0][2] >= fog->bounds[0][2] &&
bounds[0][0] <= fog->bounds[1][0] && bounds[0][1] <= fog->bounds[1][1] && bounds[0][2] <= fog->bounds[1][2]) ||
( bounds[1][0] >= fog->bounds[0][0] && bounds[1][1] >= fog->bounds[0][1] && bounds[1][2] >= fog->bounds[0][2] &&
bounds[1][0] <= fog->bounds[1][0] && bounds[1][1] <= fog->bounds[1][1] && bounds[1][2] <= fog->bounds[1][2] ) )
{//partially in this one
if ( tr.refdef.fogIndex == fI || R_FogParmsMatch( tr.refdef.fogIndex, fI ) )
{//take new one only if it's the same one that the viewpoint is in
for (int fI = 1; fI < tr.world->numfogs; fI++) {
fog = &tr.world->fogs[fI];
if (bounds[0][0] >= fog->bounds[0][0]
&& bounds[0][1] >= fog->bounds[0][1]
&& bounds[0][2] >= fog->bounds[0][2]
&& bounds[1][0] <= fog->bounds[1][0]
&& bounds[1][1] <= fog->bounds[1][1]
&& bounds[1][2] <= fog->bounds[1][2])
{//completely in this one
fogIndex = fI;
break;
}
else if ( !fogIndex )
{//didn't find one yet, so use this one
fogIndex = fI;
else if ((bounds[0][0] >= fog->bounds[0][0] && bounds[0][1] >= fog->bounds[0][1] && bounds[0][2] >= fog->bounds[0][2] &&
bounds[0][0] <= fog->bounds[1][0] && bounds[0][1] <= fog->bounds[1][1] && bounds[0][2] <= fog->bounds[1][2]) ||
(bounds[1][0] >= fog->bounds[0][0] && bounds[1][1] >= fog->bounds[0][1] && bounds[1][2] >= fog->bounds[0][2] &&
bounds[1][0] <= fog->bounds[1][0] && bounds[1][1] <= fog->bounds[1][1] && bounds[1][2] <= fog->bounds[1][2]))
{//partially in this one
if (tr.refdef.fogIndex == fI || R_FogParmsMatch(tr.refdef.fogIndex, fI))
{//take new one only if it's the same one that the viewpoint is in
fogIndex = fI;
break;
}
else if (!fogIndex)
{//didn't find one yet, so use this one
fogIndex = fI;
}
}
}
}
poly->fogIndex = fogIndex;
}
poly->fogIndex = fogIndex;
}


Expand Down
2 changes: 1 addition & 1 deletion code/ui/ui_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ typedef struct {
// Nothing is drawn until R_RenderScene is called.
void (*R_ClearScene)( void );
void (*R_AddRefEntityToScene)( const refEntity_t *re );
void (*R_AddPolyToScene)( qhandle_t hShader , int numVerts, const polyVert_t *verts );
void (*R_AddPolyToScene)( qhandle_t hShader , int numVerts, const polyVert_t *verts, int numPolys );
void (*R_AddLightToScene)( const vec3_t org, float intensity, float r, float g, float b );
void (*R_RenderScene)( const refdef_t *fd );

Expand Down
4 changes: 1 addition & 3 deletions shared/rd-rend2/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -3330,10 +3330,8 @@ void RE_ClearScene( void );
void RE_AddRefEntityToScene( const refEntity_t *ent );
#ifndef REND2_SP
void RE_AddMiniRefEntityToScene( const miniRefEntity_t *miniRefEnt );
void RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t *verts, int num = 1);
#else
void RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t *verts);
#endif
void RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t *verts, int num = 1);
void RE_AddLightToScene( const vec3_t org, float intensity, float r, float g, float b );
void RE_AddAdditiveLightToScene( const vec3_t org, float intensity, float r, float g, float b );
void RE_BeginScene( const refdef_t *fd );
Expand Down
6 changes: 1 addition & 5 deletions shared/rd-rend2/tr_scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,8 @@ RE_AddPolyToScene
=====================
*/
#ifndef REND2_SP

void RE_AddPolyToScene( qhandle_t hShader, int numVerts, const polyVert_t *verts, int numPolys ) {
#else
void RE_AddPolyToScene(qhandle_t hShader, int numVerts, const polyVert_t *verts) {
int numPolys = 1;
#endif
srfPoly_t *poly;
int i, j;
int fogIndex;
Expand Down

0 comments on commit 63249af

Please sign in to comment.