Skip to content

Commit

Permalink
Patch stitching (#141)
Browse files Browse the repository at this point in the history
* A few small changes (cl_filterGames + MAX_PATCH_PLANES increase) (JACoders#1188)

* [MP] Add cl_filterGames cvar to discard servers that use an fs_game matching one listed in the cvar (separated by spaces).

* [MP] Use known MB2 (incompatible mod using the default serverlist) fs_game values as default for cl_filterGames to filter them out.

* [Shared] Increase MAX_PATCH_PLANES from 2048 to 4096.

Due to precision/rounding differences the vanilla engine on Windows, Linux and Mac effectively treated this limit different and the behavior for never consistent. For that reason jk2mv doubled the value back in 2015 and by now some maps require the limit to be increased.

* [MP] Improve cl_filterGames.

Skip cl_filterGames entry if it matches the current fs_game.
Add support for filtering servers without fs_game set (BASEGAME).

(cherry picked from commit 58ad339)

* replace PATCH_STITCHING preprocessor define with r_patchStitching cvar (JACoders#1199)

(cherry picked from commit 540edeb)

---------

Co-authored-by: Daggolin <daggolin@gmx.de>
Co-authored-by: razor <mrrazish@gmail.com>
  • Loading branch information
3 people authored Feb 10, 2024
1 parent 4d0a7ce commit ea04786
Show file tree
Hide file tree
Showing 15 changed files with 160 additions and 166 deletions.
17 changes: 17 additions & 0 deletions codemp/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3711,6 +3711,23 @@ void CL_ServerInfoPacket( netadr_t from, msg_t *msg ) {
}
}

if ( cl_filterGames && cl_filterGames->string && cl_filterGames->string[0] ) {
const char *gameFolder = Info_ValueForKey( infoString, "game" );

// If no game folder was specified the server is using base. Use the BASEGAME string so we can filter for it.
if ( !gameFolder[0] ) gameFolder = BASEGAME;

// NOTE: As the command tokenization doesn't support nested quotes we can't filter fs_game with spaces using
// this approach, but fs_game with spaces cause other issues as well, like downloads not working and at
// the time of writing this no public servers actually use an fs_game with spaces...
Cmd_TokenizeString( cl_filterGames->string );
for ( i = 0; i < Cmd_Argc(); i++ ) {
if ( !Q_stricmp(Cmd_Argv(i), gameFolder) && Q_stricmp(Cmd_Argv(i), FS_GetCurrentGameDir(false)) ) {
return;
}
}
}

// iterate servers waiting for ping response
for (i=0; i<MAX_PINGREQUESTS; i++)
{
Expand Down
5 changes: 5 additions & 0 deletions codemp/rd-dedicated/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ Ghoul2 Insert End
cvar_t *r_aviMotionJpegQuality;
cvar_t *r_screenshotJpegQuality;

cvar_t *r_patchStitching;

/*
** R_GetModeInfo
*/
Expand Down Expand Up @@ -453,6 +455,9 @@ Ghoul2 Insert Start
/*
Ghoul2 Insert End
*/

r_patchStitching = ri.Cvar_Get("r_patchStitching", "1", CVAR_ARCHIVE, "Enable stitching of neighbouring patch surfaces" );

r_modelpoolmegs = ri.Cvar_Get("r_modelpoolmegs", "20", CVAR_ARCHIVE, "" );
if (ri.Sys_LowPhysicalMemory() )
ri.Cvar_Set("r_modelpoolmegs", "0");
Expand Down
7 changes: 4 additions & 3 deletions codemp/rd-dedicated/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ typedef struct model_s {
char name[MAX_QPATH];
modtype_t type;
int index; // model = tr.models[model->mod_index]

int dataSize; // just for listing purposes
bmodel_t *bmodel; // only if type == MOD_BRUSH
md3Header_t *md3[MD3_MAX_LODS]; // only if type == MOD_MESH
Expand Down Expand Up @@ -1272,6 +1272,9 @@ extern cvar_t *r_noServerGhoul2;
/*
Ghoul2 Insert End
*/

extern cvar_t *r_patchStitching;

//====================================================================

float R_NoiseGet4f( float x, float y, float z, float t );
Expand Down Expand Up @@ -1579,8 +1582,6 @@ CURVE TESSELATION
============================================================
*/

#define PATCH_STITCHING

srfGridMesh_t *R_SubdividePatchToGrid( int width, int height,
drawVert_t points[MAX_PATCH_SIZE*MAX_PATCH_SIZE] );

Expand Down
88 changes: 46 additions & 42 deletions codemp/rd-rend2/tr_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,8 @@ cvar_t *r_debugWeather;
cvar_t *r_aspectCorrectFonts;
cvar_t *cl_ratioFix;

cvar_t *r_patchStitching;

extern void RB_SetGL2D (void);
static void R_Splash()
{
Expand Down Expand Up @@ -630,8 +632,8 @@ we use statics to store a count and start writing the first screenshot/screensho
(with FS_FileExists / FS_FOpenFileWrite calls)
FIXME: the statics don't get a reinit between fs_game changes
==============================================================================
*/
==============================================================================
*/

/*
==================
Expand Down Expand Up @@ -688,10 +690,10 @@ static void ConvertRGBtoBGR(
*dst++ = pixelRGB[2];
*dst++ = pixelRGB[1];
*dst++ = temp;

pixelRGB += 3;
}

row += stride;
}
}
Expand Down Expand Up @@ -724,11 +726,11 @@ static void R_SaveTGA(
ri.Hunk_FreeTempMemory(buffer);
}

/*
==================
/*
==================
R_SaveScreenshotTGA
==================
*/
==================
*/
static void R_SaveScreenshotTGA(
const screenshotReadback_t *screenshotReadback, byte *pixels)
{
Expand All @@ -741,9 +743,9 @@ static void R_SaveScreenshotTGA(
}

/*
==================
==================
R_SaveScreenshotPNG
==================
==================
*/
static void R_SaveScreenshotPNG(
const screenshotReadback_t *screenshotReadback, byte *pixels)
Expand Down Expand Up @@ -828,7 +830,7 @@ R_TakeScreenshotCmd
*/
const void *RB_TakeScreenshotCmd( const void *data ) {
const screenshotCommand_t *cmd;

cmd = (const screenshotCommand_t *)data;

// finish any 2D drawing if needed
Expand All @@ -838,13 +840,13 @@ const void *RB_TakeScreenshotCmd( const void *data ) {
const int frameNumber = backEndData->realFrameNumber;
gpuFrame_t *thisFrame = &backEndData->frames[frameNumber % MAX_FRAMES];
screenshotReadback_t *screenshot = &thisFrame->screenshotReadback;

GLint packAlign;
qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);

const int linelen = cmd->width * 3;
const int strideInBytes = PAD(linelen, packAlign);

qglGenBuffers(1, &screenshot->pbo);
qglBindBuffer(GL_PIXEL_PACK_BUFFER, screenshot->pbo);
qglBufferData(
Expand All @@ -862,8 +864,8 @@ const void *RB_TakeScreenshotCmd( const void *data ) {
screenshot->format = cmd->format;
Q_strncpyz(
screenshot->filename, cmd->fileName, sizeof(screenshot->filename));
return (const void *)(cmd + 1);

return (const void *)(cmd + 1);
}

/*
Expand All @@ -890,11 +892,11 @@ void R_TakeScreenshot( int x, int y, int width, int height, char *name, screensh
cmd->format = format;
}

/*
==================
/*
==================
R_ScreenshotFilename
==================
*/
==================
*/
void R_ScreenshotFilename( char *buf, int bufSize, const char *ext ) {
time_t rawtime;
char timeStr[32] = {0}; // should really only reach ~19 chars
Expand Down Expand Up @@ -974,8 +976,8 @@ static void R_LevelShot( void ) {
ri.Printf( PRINT_ALL, "Wrote %s\n", checkname );
}

/*
==================
/*
==================
R_ScreenShotTGA_f
screenshot
Expand All @@ -984,8 +986,8 @@ screenshot [levelshot]
screenshot [filename]
Doesn't print the pacifier message if there is a second arg
==================
*/
==================
*/
void R_ScreenShotTGA_f (void) {
char checkname[MAX_OSPATH] = {0};
qboolean silent = qfalse;
Expand All @@ -1007,7 +1009,7 @@ void R_ScreenShotTGA_f (void) {
R_ScreenshotFilename( checkname, sizeof( checkname ), ".tga" );

if ( ri.FS_FileExists( checkname ) ) {
Com_Printf( "ScreenShot: Couldn't create a file\n");
Com_Printf( "ScreenShot: Couldn't create a file\n");
return;
}
}
Expand Down Expand Up @@ -1039,7 +1041,7 @@ void R_ScreenShotPNG_f (void) {
R_ScreenshotFilename( checkname, sizeof( checkname ), ".png" );

if ( ri.FS_FileExists( checkname ) ) {
Com_Printf( "ScreenShot: Couldn't create a file\n");
Com_Printf( "ScreenShot: Couldn't create a file\n");
return;
}
}
Expand Down Expand Up @@ -1071,7 +1073,7 @@ void R_ScreenShotJPEG_f (void) {
R_ScreenshotFilename( checkname, sizeof( checkname ), ".jpg" );

if ( ri.FS_FileExists( checkname ) ) {
Com_Printf( "ScreenShot: Couldn't create a file\n");
Com_Printf( "ScreenShot: Couldn't create a file\n");
return;
}
}
Expand Down Expand Up @@ -1102,7 +1104,7 @@ const void *RB_TakeVideoFrameCmd( const void *data )
RB_EndSurface();

cmd = (const videoFrameCommand_t *)data;

qglGetIntegerv(GL_PACK_ALIGNMENT, &packAlign);

linelen = cmd->width * 3;
Expand All @@ -1115,7 +1117,7 @@ const void *RB_TakeVideoFrameCmd( const void *data )
avipadlen = avipadwidth - linelen;

cBuf = (byte*)(PADP(cmd->captureBuffer, packAlign));

qglReadPixels(0, 0, cmd->width, cmd->height, GL_RGB,
GL_UNSIGNED_BYTE, cBuf);

Expand All @@ -1136,11 +1138,11 @@ const void *RB_TakeVideoFrameCmd( const void *data )
{
byte *lineend, *memend;
byte *srcptr, *destptr;

srcptr = cBuf;
destptr = cmd->encodeBuffer;
memend = srcptr + memcount;

// swap R and B and remove line paddings
while(srcptr < memend)
{
Expand All @@ -1152,17 +1154,17 @@ const void *RB_TakeVideoFrameCmd( const void *data )
*destptr++ = srcptr[0];
srcptr += 3;
}

Com_Memset(destptr, '\0', avipadlen);
destptr += avipadlen;

srcptr += padlen;
}

ri.CL_WriteAVIVideoFrame(cmd->encodeBuffer, avipadwidth * cmd->height);
}

return (const void *)(cmd + 1);
return (const void *)(cmd + 1);
}

//============================================================================
Expand Down Expand Up @@ -1246,7 +1248,7 @@ void R_PrintLongString(const char *string) {
GfxInfo_f
================
*/
static void GfxInfo_f( void )
static void GfxInfo_f( void )
{
const char *enablestrings[] =
{
Expand Down Expand Up @@ -1322,7 +1324,7 @@ static void GfxInfo_f( void )
GfxMemInfo_f
================
*/
void GfxMemInfo_f( void )
void GfxMemInfo_f( void )
{
switch (glRefConfig.memInfo)
{
Expand Down Expand Up @@ -1452,7 +1454,7 @@ static const size_t numCommands = ARRAY_LEN( commands );
R_Register
===============
*/
void R_Register( void )
void R_Register( void )
{
//
// latched and archived variables
Expand Down Expand Up @@ -1534,7 +1536,7 @@ void R_Register( void )
r_baseNormalX = ri.Cvar_Get( "r_baseNormalX", "1.0", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_baseNormalY = ri.Cvar_Get( "r_baseNormalY", "1.0", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_baseParallax = ri.Cvar_Get( "r_baseParallax", "0.05", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_baseSpecular = ri.Cvar_Get( "r_baseSpecular", "0.04", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_baseSpecular = ri.Cvar_Get( "r_baseSpecular", "0.04", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_dlightMode = ri.Cvar_Get( "r_dlightMode", "1", CVAR_ARCHIVE | CVAR_LATCH, "" );
r_pshadowDist = ri.Cvar_Get( "r_pshadowDist", "128", CVAR_ARCHIVE, "" );
r_imageUpsample = ri.Cvar_Get( "r_imageUpsample", "0", CVAR_ARCHIVE | CVAR_LATCH, "" );
Expand Down Expand Up @@ -1681,6 +1683,8 @@ Ghoul2 Insert Start
Ghoul2 Insert End
*/

r_patchStitching = ri.Cvar_Get("r_patchStitching", "1", CVAR_ARCHIVE, "Enable stitching of neighbouring patch surfaces" );

se_language = ri.Cvar_Get ( "se_language", "english", CVAR_ARCHIVE | CVAR_NORESTART, "" );

for ( size_t i = 0; i < numCommands; i++ )
Expand Down Expand Up @@ -1943,14 +1947,14 @@ R_Init
void R_Init( void ) {
byte *ptr;
int i;

ri.Printf( PRINT_ALL, "----- R_Init -----\n" );

// clear all our internal state
Com_Memset( &tr, 0, sizeof( tr ) );
Com_Memset( &backEnd, 0, sizeof( backEnd ) );
Com_Memset( &tess, 0, sizeof( tess ) );


//
// init function tables
Expand Down Expand Up @@ -2242,7 +2246,7 @@ Q_EXPORT refexport_t* QDECL GetRefAPI ( int apiVersion, refimport_t *rimp ) {
Com_Memset( &re, 0, sizeof( re ) );

if ( apiVersion != REF_API_VERSION ) {
ri.Printf(PRINT_ALL, "Mismatched REF_API_VERSION: expected %i, got %i\n",
ri.Printf(PRINT_ALL, "Mismatched REF_API_VERSION: expected %i, got %i\n",
REF_API_VERSION, apiVersion );
return NULL;
}
Expand Down
12 changes: 6 additions & 6 deletions codemp/rd-vanilla/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1392,15 +1392,15 @@ static void R_LoadSurfaces( lump_t *surfs, lump_t *verts, lump_t *indexLump, wor
}
}

#ifdef PATCH_STITCHING
R_StitchAllPatches(worldData);
#endif
if ( r_patchStitching->integer ) {
R_StitchAllPatches(worldData);
}

R_FixSharedVertexLodError(worldData);

#ifdef PATCH_STITCHING
R_MovePatchSurfacesToHunk(worldData);
#endif
if ( r_patchStitching->integer ) {
R_MovePatchSurfacesToHunk(worldData);
}

ri.Printf( PRINT_ALL, "...loaded %d faces, %i meshes, %i trisurfs, %i flares\n", numFaces, numMeshes, numTriSurfs, numFlares );
}
Expand Down
Loading

0 comments on commit ea04786

Please sign in to comment.