From 5a9a5779260560f88af13d86019b9a340b07c139 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 12 Jan 2025 02:27:24 +0300 Subject: [PATCH 01/14] NUKE leftover CPU lightGrid functionality We do this in GLSL now, and the results of this code are not actually used for anything. --- src/engine/renderer/tr_animation.cpp | 6 -- src/engine/renderer/tr_bsp.cpp | 13 ---- src/engine/renderer/tr_light.cpp | 92 ---------------------------- src/engine/renderer/tr_local.h | 7 +-- src/engine/renderer/tr_mesh.cpp | 6 -- src/engine/renderer/tr_model_iqm.cpp | 11 ---- src/engine/renderer/tr_scene.cpp | 1 - src/engine/renderer/tr_world.cpp | 3 - 8 files changed, 2 insertions(+), 137 deletions(-) diff --git a/src/engine/renderer/tr_animation.cpp b/src/engine/renderer/tr_animation.cpp index 9e5fe88fd5..fd56eee833 100644 --- a/src/engine/renderer/tr_animation.cpp +++ b/src/engine/renderer/tr_animation.cpp @@ -679,12 +679,6 @@ void R_AddMD5Surfaces( trRefEntity_t *ent ) return; } - // set up lighting now that we know we aren't culled - if ( !personalModel || glConfig2.shadowMapping ) - { - R_SetupEntityLighting( &tr.refdef, ent, nullptr ); - } - // see if we are in a fog volume fogNum = R_FogWorldBox( ent->worldBounds ); diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index f366f28379..1535882283 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4338,14 +4338,6 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) // check for ambient color else if ( !Q_stricmp( keyname, "_color" ) || !Q_stricmp( keyname, "ambientColor" ) ) { - if ( r_forceAmbient->value <= 0 ) - { - sscanf( value, "%f %f %f", &tr.worldEntity.ambientLight[ 0 ], &tr.worldEntity.ambientLight[ 1 ], - &tr.worldEntity.ambientLight[ 2 ] ); - - VectorCopy( tr.worldEntity.ambientLight, tr.worldEntity.ambientLight ); - VectorScale( tr.worldEntity.ambientLight, r_ambientScale->value, tr.worldEntity.ambientLight ); - } } // check for deluxe mapping support @@ -5048,11 +5040,6 @@ void RE_LoadWorldMap( const char *name ) VectorNormalize( tr.sunDirection ); - // set default ambient color - tr.worldEntity.ambientLight[ 0 ] = r_forceAmbient->value; - tr.worldEntity.ambientLight[ 1 ] = r_forceAmbient->value; - tr.worldEntity.ambientLight[ 2 ] = r_forceAmbient->value; - tr.worldMapLoaded = true; // load it diff --git a/src/engine/renderer/tr_light.cpp b/src/engine/renderer/tr_light.cpp index c134b3ea5f..760b32210d 100644 --- a/src/engine/renderer/tr_light.cpp +++ b/src/engine/renderer/tr_light.cpp @@ -260,98 +260,6 @@ int R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, ve return true; } -/* -================= -R_SetupEntityLightingGrid -================= -*/ -static void R_SetupEntityLightingGrid( trRefEntity_t *ent, vec3_t forcedOrigin ) -{ - vec3_t lightOrigin; - - if ( forcedOrigin ) - { - VectorCopy( forcedOrigin, lightOrigin ); - } - else - { - if ( ent->e.renderfx & RF_LIGHTING_ORIGIN ) - { - // separate lightOrigins are needed so an object that is - // sinking into the ground can still be lit, and so - // multi-part models can be lit identically - VectorCopy( ent->e.lightingOrigin, lightOrigin ); - } - else - { - VectorCopy( ent->e.origin, lightOrigin ); - } - } - - R_LightForPoint( lightOrigin, ent->ambientLight, ent->directedLight, - ent->lightDir ); -} - -/* -================= -R_SetupEntityLighting - -Calculates all the lighting values that will be used -by the Calc_* functions -================= -*/ -void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent, vec3_t forcedOrigin ) -{ - // lighting calculations - if ( ent->lightingCalculated ) - { - return; - } - - ent->lightingCalculated = true; - - // if NOWORLDMODEL, only use dynamic lights (menu system, etc) - if ( !( refdef->rdflags & RDF_NOWORLDMODEL ) && tr.world - && tr.world->lightGridData1 && tr.world->lightGridData2 ) - { - R_SetupEntityLightingGrid( ent, forcedOrigin ); - } - else - { - /* Historically those values were multiplied by - tr.identityLight but tr.identityLight is always 1.0f - in Dæmon engine as the overbright bit implementation - is fully software. */ - - //% ent->ambientLight[0] = ent->ambientLight[1] = ent->ambientLight[2] = 150.0f; - //% ent->directedLight[0] = ent->directedLight[1] = ent->directedLight[2] = 150.0f; - //% VectorCopy( tr.sunDirection, ent->lightDir ); - ent->ambientLight[ 0 ] = 64.0f / 255.0f; - ent->ambientLight[ 1 ] = 64.0f / 255.0f; - ent->ambientLight[ 2 ] = 96.0f / 255.0f; - - ent->directedLight[ 0 ] = 255.0f / 255.0f; - ent->directedLight[ 1 ] = 232.0f / 255.0f; - ent->directedLight[ 2 ] = 224.0f / 255.0f; - - VectorSet( ent->lightDir, -1, 1, 1.25 ); - VectorNormalize( ent->lightDir ); - } - - if ( ( ent->e.renderfx & RF_MINLIGHT ) ) // && VectorLength(ent->ambientLight) <= 0) - { - /* Historically those values were multiplied by - tr.identityLight but tr.identityLight is always 1.0f - in Dæmon engine as the as the overbright bit - implementation is fully software. */ - - // give everything a minimum light add - ent->ambientLight[ 0 ] += 0.125f; - ent->ambientLight[ 1 ] += 0.125f; - ent->ambientLight[ 2 ] += 0.125f; - } -} - /* ================= R_SetupLightOrigin diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 42988156a4..65cc4fdb0e 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -465,10 +465,6 @@ enum class shaderProfilerRenderSubGroupsMode { // local float axisLength; // compensate for non-normalized axis - bool lightingCalculated; - vec3_t lightDir; // normalized direction towards light - vec3_t ambientLight; // color normalized to 0-1 - vec3_t directedLight; cullResult_t cull; vec3_t localBounds[ 2 ]; @@ -2755,6 +2751,8 @@ enum class shaderProfilerRenderSubGroupsMode { std::vector lightmaps; std::vector deluxemaps; + vec3_t ambientLight; + image_t *lightGrid1Image; image_t *lightGrid2Image; @@ -3563,7 +3561,6 @@ inline bool checkGLErrors() */ void R_AddBrushModelInteractions( trRefEntity_t *ent, trRefLight_t *light, interactionType_t iaType ); - void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent, vec3_t forcedOrigin ); float R_InterpolateLightGrid( world_t *w, int from[3], int to[3], float *factors[3], vec3_t ambientLight, vec3_t directedLight, vec3_t lightDir ); diff --git a/src/engine/renderer/tr_mesh.cpp b/src/engine/renderer/tr_mesh.cpp index 3338777fc1..8aefcda50b 100644 --- a/src/engine/renderer/tr_mesh.cpp +++ b/src/engine/renderer/tr_mesh.cpp @@ -302,12 +302,6 @@ void R_AddMDVSurfaces( trRefEntity_t *ent ) return; } - // set up lighting now that we know we aren't culled - if ( !personalModel || glConfig2.shadowMapping ) - { - R_SetupEntityLighting( &tr.refdef, ent, nullptr ); - } - // see if we are in a fog volume fogNum = R_FogWorldBox( ent->worldBounds ); diff --git a/src/engine/renderer/tr_model_iqm.cpp b/src/engine/renderer/tr_model_iqm.cpp index 167bc98e40..c865571542 100644 --- a/src/engine/renderer/tr_model_iqm.cpp +++ b/src/engine/renderer/tr_model_iqm.cpp @@ -948,10 +948,8 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) { personalModel = (ent->e.renderfx & RF_THIRD_PERSON) && tr.viewParms.portalLevel == 0; - // // cull the entire model if merged bounding box of both frames // is outside the view frustum. - // R_CullIQM( ent ); // HACK: Never cull first-person models, due to issues with a certain model's bounds @@ -962,16 +960,7 @@ void R_AddIQMSurfaces( trRefEntity_t *ent ) { return; } - // - // set up lighting now that we know we aren't culled - // - if ( !personalModel || glConfig2.shadowMapping ) { - R_SetupEntityLighting( &tr.refdef, ent, nullptr ); - } - - // // see if we are in a fog volume - // fogNum = R_FogWorldBox( ent->worldBounds ); for ( i = 0 ; i < IQModel->num_surfaces ; i++ ) { diff --git a/src/engine/renderer/tr_scene.cpp b/src/engine/renderer/tr_scene.cpp index 2aa9d5cf6a..aa02565b4a 100644 --- a/src/engine/renderer/tr_scene.cpp +++ b/src/engine/renderer/tr_scene.cpp @@ -274,7 +274,6 @@ void RE_AddRefEntityToScene( const refEntity_t *ent ) } backEndData[ tr.smpFrame ]->entities[ r_numEntities ].e = *ent; - backEndData[ tr.smpFrame ]->entities[ r_numEntities ].lightingCalculated = false; r_numEntities++; } diff --git a/src/engine/renderer/tr_world.cpp b/src/engine/renderer/tr_world.cpp index 2f05042212..4ca207aec0 100644 --- a/src/engine/renderer/tr_world.cpp +++ b/src/engine/renderer/tr_world.cpp @@ -322,9 +322,6 @@ void R_AddBSPModelSurfaces( trRefEntity_t *ent ) return; } - // Tr3B: BSP inline models should always use vertex lighting - R_SetupEntityLighting( &tr.refdef, ent, boundsCenter ); - fogNum = R_FogWorldBox( ent->worldBounds ); for ( i = 0; i < bspModel->numSurfaces; i++ ) From 2c0785dafbcb6a5f25b61b1868af29bf3dad57d6 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 12 Jan 2025 02:48:30 +0300 Subject: [PATCH 02/14] Fix ambientColor keyword, use r_forceAmbient These will now actually modify the lightGrid. --- src/engine/renderer/tr_bsp.cpp | 33 +++++++++++++++++++++++++++------ src/engine/renderer/tr_local.h | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index 1535882283..d98a2c1762 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -3955,7 +3955,7 @@ static void R_LoadFogs( lump_t *l, lump_t *brushesLump, lump_t *sidesLump ) Log::Debug("%i fog volumes loaded", s_worldData.numFogs ); } -static void R_SetDefaultLightGrid() +static void R_SetConstantColorLightGrid( const byte color[3] ) { world_t *w = &s_worldData; @@ -3983,9 +3983,9 @@ static void R_SetDefaultLightGrid() bspGridPoint2_t *gridPoint2 = (bspGridPoint2_t *) (gridPoint1 + w->numLightGridPoints); // default some white light from above - gridPoint1->color[ 0 ] = 64; - gridPoint1->color[ 1 ] = 64; - gridPoint1->color[ 2 ] = 64; + gridPoint1->color[ 0 ] = color[0]; + gridPoint1->color[ 1 ] = color[1]; + gridPoint1->color[ 2 ] = color[2]; gridPoint1->ambientPart = 128; gridPoint2->direction[ 0 ] = floatToSnorm8(0.0f); gridPoint2->direction[ 1 ] = floatToSnorm8(0.0f); @@ -4039,9 +4039,16 @@ void R_LoadLightGrid( lump_t *l ) vec3_t ambientColor, directedColor, direction; float scale; + if ( tr.ambientLightSet ) { + const byte color[3]{ floatToUnorm8( tr.ambientLight[0] ), floatToUnorm8( tr.ambientLight[1] ), + floatToUnorm8( tr.ambientLight[2] ) }; + R_SetConstantColorLightGrid( color ); + } + if ( !r_precomputedLighting->integer ) { - R_SetDefaultLightGrid(); + const byte color[3] { 64, 64, 64 }; + R_SetConstantColorLightGrid( color ); return; } @@ -4081,7 +4088,8 @@ void R_LoadLightGrid( lump_t *l ) { Log::Warn("light grid mismatch, default light grid used" ); - R_SetDefaultLightGrid(); + const byte color[3]{ 64, 64, 64 }; + R_SetConstantColorLightGrid( color ); return; } @@ -4116,6 +4124,12 @@ void R_LoadLightGrid( lump_t *l ) tmpDirected[ 2 ] = in->directed[ 2 ]; tmpDirected[ 3 ] = 255; + if ( tmpAmbient[0] < r_forceAmbient->value && + tmpAmbient[1] < r_forceAmbient->value && + tmpAmbient[2] < r_forceAmbient->value ) { + VectorSet( tmpAmbient, r_forceAmbient->value, r_forceAmbient->value, r_forceAmbient->value ); + } + if ( tr.legacyOverBrightClamping ) { R_ColorShiftLightingBytes( tmpAmbient ); @@ -4338,6 +4352,13 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) // check for ambient color else if ( !Q_stricmp( keyname, "_color" ) || !Q_stricmp( keyname, "ambientColor" ) ) { + if ( r_forceAmbient->value <= 0 ) { + sscanf( value, "%f %f %f", &tr.ambientLight[0], &tr.ambientLight[1], + &tr.ambientLight[2] ); + + VectorScale( tr.ambientLight, r_ambientScale->value, tr.ambientLight ); + tr.ambientLightSet = true; + } } // check for deluxe mapping support diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 65cc4fdb0e..86b0313806 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2752,6 +2752,7 @@ enum class shaderProfilerRenderSubGroupsMode { std::vector deluxemaps; vec3_t ambientLight; + bool ambientLightSet = false; image_t *lightGrid1Image; image_t *lightGrid2Image; From 7b0ceeb0e2ff22101bbad65333e8e436d3be1973 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 12 Jan 2025 02:53:28 +0300 Subject: [PATCH 03/14] Change r_forceAmbient to a new-style cvar --- src/engine/renderer/tr_bsp.cpp | 10 +++++----- src/engine/renderer/tr_init.cpp | 6 +++--- src/engine/renderer/tr_light.cpp | 12 ++++++------ src/engine/renderer/tr_local.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index d98a2c1762..d0c9a062e8 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4124,10 +4124,10 @@ void R_LoadLightGrid( lump_t *l ) tmpDirected[ 2 ] = in->directed[ 2 ]; tmpDirected[ 3 ] = 255; - if ( tmpAmbient[0] < r_forceAmbient->value && - tmpAmbient[1] < r_forceAmbient->value && - tmpAmbient[2] < r_forceAmbient->value ) { - VectorSet( tmpAmbient, r_forceAmbient->value, r_forceAmbient->value, r_forceAmbient->value ); + if ( tmpAmbient[0] < r_forceAmbient.Get() && + tmpAmbient[1] < r_forceAmbient.Get() && + tmpAmbient[2] < r_forceAmbient.Get() ) { + VectorSet( tmpAmbient, r_forceAmbient.Get(), r_forceAmbient.Get(), r_forceAmbient.Get() ); } if ( tr.legacyOverBrightClamping ) @@ -4352,7 +4352,7 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) // check for ambient color else if ( !Q_stricmp( keyname, "_color" ) || !Q_stricmp( keyname, "ambientColor" ) ) { - if ( r_forceAmbient->value <= 0 ) { + if ( r_forceAmbient.Get() == 0 ) { sscanf( value, "%f %f %f", &tr.ambientLight[0], &tr.ambientLight[1], &tr.ambientLight[2] ); diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 543adc87c0..7bf2283a9b 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -216,7 +216,8 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA cvar_t *r_wolfFog; cvar_t *r_noFog; - cvar_t *r_forceAmbient; + Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid", Cvar::NONE, + 0.125f, 0.0f, 0.3f ); cvar_t *r_ambientScale; cvar_t *r_lightScale; cvar_t *r_debugSort; @@ -1165,8 +1166,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p r_wolfFog = Cvar_Get( "r_wolfFog", "1", CVAR_CHEAT ); r_noFog = Cvar_Get( "r_noFog", "0", CVAR_CHEAT ); - r_forceAmbient = Cvar_Get( "r_forceAmbient", "0.125", CVAR_LATCH ); - AssertCvarRange( r_forceAmbient, 0.0f, 0.3f, false ); + Cvar::Latch( r_forceAmbient ); r_smp = Cvar_Get( "r_smp", "0", CVAR_LATCH ); diff --git a/src/engine/renderer/tr_light.cpp b/src/engine/renderer/tr_light.cpp index 760b32210d..c6fbaf27db 100644 --- a/src/engine/renderer/tr_light.cpp +++ b/src/engine/renderer/tr_light.cpp @@ -248,13 +248,13 @@ int R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, ve VectorNormalize( lightDir ); - if ( ambientLight[ 0 ] < r_forceAmbient->value && - ambientLight[ 1 ] < r_forceAmbient->value && - ambientLight[ 2 ] < r_forceAmbient->value ) + if ( ambientLight[ 0 ] < r_forceAmbient.Get() && + ambientLight[ 1 ] < r_forceAmbient.Get() && + ambientLight[ 2 ] < r_forceAmbient.Get() ) { - ambientLight[ 0 ] = r_forceAmbient->value; - ambientLight[ 1 ] = r_forceAmbient->value; - ambientLight[ 2 ] = r_forceAmbient->value; + ambientLight[ 0 ] = r_forceAmbient.Get(); + ambientLight[ 1 ] = r_forceAmbient.Get(); + ambientLight[ 2 ] = r_forceAmbient.Get(); } return true; diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 86b0313806..313e9bcc55 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2890,7 +2890,7 @@ enum class shaderProfilerRenderSubGroupsMode { extern cvar_t *r_wolfFog; extern cvar_t *r_noFog; - extern cvar_t *r_forceAmbient; + extern Cvar::Range> r_forceAmbient; extern cvar_t *r_ambientScale; extern cvar_t *r_lightScale; From 5a071e2cfe78b815f17fc75b2df5e192b8ca236a Mon Sep 17 00:00:00 2001 From: VReaperV Date: Sun, 12 Jan 2025 02:57:29 +0300 Subject: [PATCH 04/14] Change r_ambientScale to a new-style cvar --- src/engine/renderer/gl_shader.cpp | 2 +- src/engine/renderer/tr_bsp.cpp | 2 +- src/engine/renderer/tr_init.cpp | 4 ++-- src/engine/renderer/tr_local.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/renderer/gl_shader.cpp b/src/engine/renderer/gl_shader.cpp index 0c4b21bd45..d37926ffdb 100644 --- a/src/engine/renderer/gl_shader.cpp +++ b/src/engine/renderer/gl_shader.cpp @@ -599,7 +599,7 @@ static std::string GenEngineConstants() { // Engine constants std::string str; - AddDefine( str, "r_AmbientScale", r_ambientScale->value ); + AddDefine( str, "r_AmbientScale", r_ambientScale.Get() ); AddDefine( str, "r_SpecularScale", r_specularScale->value ); AddDefine( str, "r_zNear", r_znear->value ); diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index d0c9a062e8..94ef1e982f 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -4356,7 +4356,7 @@ void R_LoadEntities( lump_t *l, std::string &externalEntities ) sscanf( value, "%f %f %f", &tr.ambientLight[0], &tr.ambientLight[1], &tr.ambientLight[2] ); - VectorScale( tr.ambientLight, r_ambientScale->value, tr.ambientLight ); + VectorScale( tr.ambientLight, r_ambientScale.Get(), tr.ambientLight ); tr.ambientLightSet = true; } } diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 7bf2283a9b..686592e4e0 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -218,7 +218,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Cvar::Range> r_forceAmbient( "r_forceAmbient", "Minimal light amount in lightGrid", Cvar::NONE, 0.125f, 0.0f, 0.3f ); - cvar_t *r_ambientScale; + Cvar::Cvar r_ambientScale( "r_ambientScale", "Scale lightGrid produced by ambientColor keyword by this much", Cvar::CHEAT, 1.0 ); cvar_t *r_lightScale; cvar_t *r_debugSort; cvar_t *r_printShaders; @@ -1192,7 +1192,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p r_gamma = Cvar_Get( "r_gamma", "1.0", CVAR_ARCHIVE ); r_facePlaneCull = Cvar_Get( "r_facePlaneCull", "1", 0 ); - r_ambientScale = Cvar_Get( "r_ambientScale", "1.0", CVAR_CHEAT | CVAR_LATCH ); + Cvar::Latch( r_ambientScale ); r_lightScale = Cvar_Get( "r_lightScale", "2", CVAR_CHEAT ); r_vboFaces = Cvar_Get( "r_vboFaces", "1", CVAR_CHEAT ); diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index 313e9bcc55..d25fe86f70 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2891,7 +2891,7 @@ enum class shaderProfilerRenderSubGroupsMode { extern cvar_t *r_noFog; extern Cvar::Range> r_forceAmbient; - extern cvar_t *r_ambientScale; + extern Cvar::Cvar r_ambientScale; extern cvar_t *r_lightScale; extern Cvar::Cvar r_drawSky; // Controls whether sky should be drawn or cleared. From 05dba78ddeb855246087895012a91d75592263f1 Mon Sep 17 00:00:00 2001 From: VReaperV Date: Wed, 22 Jan 2025 03:06:46 +0300 Subject: [PATCH 05/14] NUKE unused geometricRenderTargets --- src/engine/renderer/tr_local.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/engine/renderer/tr_local.h b/src/engine/renderer/tr_local.h index d25fe86f70..3bf09cf9e7 100644 --- a/src/engine/renderer/tr_local.h +++ b/src/engine/renderer/tr_local.h @@ -2851,7 +2851,6 @@ enum class shaderProfilerRenderSubGroupsMode { extern const matrix_t quakeToOpenGLMatrix; extern const matrix_t openGLToQuakeMatrix; extern const matrix_t flipZMatrix; - extern const GLenum geometricRenderTargets[]; extern int shadowMapResolutions[ 5 ]; extern int sunShadowMapResolutions[ 5 ]; From 1d253ad464534178efc1ae58ee05540fd800cdcf Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Jan 2025 20:03:24 -0600 Subject: [PATCH 06/14] Define appropriate flags for all engine commands Commands can have flags such as 'BASE' or 'RENDERER' which determine the command listing commands that they appear in. If a command has no flags at all, it does not appear in /listCmds, which seems bad. So I disabled the two-argument StaticCmd constructor without flags in the engine, and defined flags for all the commands using it. Also I changed the set of available flags a bit. Nuked SYSTEM because it is too vague, and added SERVER and CLIENT. --- src/common/Command.cpp | 6 +++++- src/common/Command.h | 30 +++++++++++++++++--------- src/engine/client/cl_main.cpp | 14 ++++++------ src/engine/framework/BaseCommands.cpp | 2 +- src/engine/framework/CommandSystem.cpp | 7 +++--- src/engine/qcommon/files.cpp | 6 +++--- src/engine/renderer/tr_animation.cpp | 3 ++- src/engine/renderer/tr_bsp.cpp | 2 +- src/engine/renderer/tr_fbo.cpp | 2 +- src/engine/renderer/tr_image.cpp | 2 +- src/engine/renderer/tr_init.cpp | 6 +++--- src/engine/renderer/tr_model.cpp | 2 +- src/engine/renderer/tr_shader.cpp | 6 ++++-- src/engine/renderer/tr_skin.cpp | 2 +- src/engine/server/sv_ccmds.cpp | 6 +++--- src/engine/sys/sdl_glimp.cpp | 2 +- 16 files changed, 58 insertions(+), 40 deletions(-) diff --git a/src/common/Command.cpp b/src/common/Command.cpp index 75f3e40a7b..22ea4c3df8 100644 --- a/src/common/Command.cpp +++ b/src/common/Command.cpp @@ -493,11 +493,13 @@ namespace Cmd { return *Cmd::GetEnv(); } +#ifndef BUILD_ENGINE StaticCmd::StaticCmd(std::string name, std::string description) :CmdBase(0){ //Register this command statically AddCommand(std::move(name), *this, std::move(description)); } +#endif StaticCmd::StaticCmd(std::string name, const int flags, std::string description) :CmdBase(flags){ @@ -509,9 +511,11 @@ namespace Cmd { return {}; } +#ifndef BUILD_ENGINE LambdaCmd::LambdaCmd(std::string name, std::string description, RunFn run, CompleteFn complete) :StaticCmd(std::move(name), std::move(description)), run(run), complete(complete) { } +#endif LambdaCmd::LambdaCmd(std::string name, int flags, std::string description, RunFn run, CompleteFn complete) :StaticCmd(std::move(name), flags, std::move(description)), run(run), complete(complete) { } @@ -528,7 +532,7 @@ class InjectFaultCmd : public Cmd::StaticCmd { public: InjectFaultCmd() : StaticCmd( - VM_STRING_PREFIX "injectFault", "make the program error and crash") {} + VM_STRING_PREFIX "injectFault", Cmd::BASE, "make the program error and crash") {} void Run(const Cmd::Args& args) const override { diff --git a/src/common/Command.h b/src/common/Command.h index 17360e5566..54f5898647 100644 --- a/src/common/Command.h +++ b/src/common/Command.h @@ -41,15 +41,18 @@ namespace Cmd { * mass removal of commands. */ enum { - BASE = BIT(0), - CVAR = BIT(1), - ALIAS = BIT(2), - SYSTEM = BIT(3), - RENDERER = BIT(4), - AUDIO = BIT(5), - SGAME_VM = BIT(6), - CGAME_VM = BIT(7), - KEY_BINDING = BIT(8), + BASE = BIT(0), // anything in the dummy app? + SERVER = BIT(1), + CLIENT = BIT(2), // client stuff other than renderer, audio, keys + RENDERER = BIT(3), + AUDIO = BIT(4), + KEY_BINDING = BIT(5), + + // ones you should not use when defining a StaticCmd + SGAME_VM = BIT(27), + CGAME_VM = BIT(28), + CVAR = BIT(29), // auto-generated cvar show/set command + ALIAS = BIT(30), PROXY_FOR_OLD = BIT(31) // OLD: The command has been registered through the proxy function in cmd.c }; @@ -154,14 +157,19 @@ namespace Cmd { * instanciated and removes it when it is destroyed. A typical usage is * * class MyCmd : public Cmd::StaticCmd { - * MyCmd() : Cmd::StaticCmd("my_command", NAMESPACE, "my_description"){} + * MyCmd() : Cmd::StaticCmd("my_command", Cmd::NAMESPACE, "my_description"){} * //Other stuff * }; * static MyCmd MyCmdRegistration; + * + * The 'namespace' flag(s) is mandatory in the engine (so that the command will appear + * in /listCmds), but ignored in the gamelogic (there they automatically get [CS]GAME_VM). */ class StaticCmd : public CmdBase { protected: +#ifndef BUILD_ENGINE StaticCmd(std::string name, std::string description); +#endif StaticCmd(std::string name, int flags, std::string description); }; @@ -180,7 +188,9 @@ namespace Cmd { public: using RunFn = std::function; using CompleteFn = std::function; +#ifndef BUILD_ENGINE LambdaCmd(std::string name, std::string description, RunFn run, CompleteFn complete = NoopComplete); +#endif LambdaCmd(std::string name, int flags, std::string description, RunFn run, CompleteFn complete = NoopComplete); void Run(const Args& args) const override; diff --git a/src/engine/client/cl_main.cpp b/src/engine/client/cl_main.cpp index c98bc13f66..639ed7ed6d 100644 --- a/src/engine/client/cl_main.cpp +++ b/src/engine/client/cl_main.cpp @@ -292,7 +292,7 @@ class DemoRecordStopCmd: public Cmd::StaticCmd { public: DemoRecordStopCmd() - : Cmd::StaticCmd("demo_record_stop", Cmd::SYSTEM, "Stops recording a demo") + : Cmd::StaticCmd("demo_record_stop", Cmd::CLIENT, "Stops recording a demo") {} void Run(const Cmd::Args&) const override @@ -312,7 +312,7 @@ class DemoRecordCmd : public Cmd::StaticCmd { public: DemoRecordCmd() - : Cmd::StaticCmd("demo_record", Cmd::SYSTEM, "Begins recording a demo from the current position") + : Cmd::StaticCmd("demo_record", Cmd::CLIENT, "Begins recording a demo from the current position") {} void Run(const Cmd::Args& args) const override @@ -562,7 +562,7 @@ void CL_ReadDemoMessage() class DemoPlayCmd: public Cmd::StaticCmd { public: - DemoPlayCmd(): Cmd::StaticCmd("demo_play", Cmd::SYSTEM, "Starts playing a demo file") { + DemoPlayCmd(): Cmd::StaticCmd("demo_play", Cmd::CLIENT, "Starts playing a demo file") { } void Run(const Cmd::Args& args) const override { @@ -1223,7 +1223,7 @@ class RconCmd: public Cmd::StaticCmd { public: RconCmd(): - StaticCmd("rcon", Cmd::SYSTEM, "Sends a remote console command") + StaticCmd("rcon", Cmd::CLIENT, "Sends a remote console command") {} void Run(const Cmd::Args& args) const override @@ -1287,7 +1287,7 @@ class RconDiscoverCmd: public Cmd::StaticCmd { public: RconDiscoverCmd(): - StaticCmd("rconDiscover", Cmd::SYSTEM, "Sends a request to the server to populate rcon.client cvars") + StaticCmd("rconDiscover", Cmd::CLIENT, "Sends a request to the server to populate rcon.client cvars") {} void Run(const Cmd::Args&) const override @@ -1528,7 +1528,7 @@ class DemoVideoCmd: public Cmd::StaticCmd { public: DemoVideoCmd() - : Cmd::StaticCmd("demo_video", Cmd::SYSTEM, + : Cmd::StaticCmd("demo_video", Cmd::CLIENT, "Begins recording a video from the current demo") {} @@ -1586,7 +1586,7 @@ class DemoStopVideoCmd: public Cmd::StaticCmd { public: DemoStopVideoCmd() - : Cmd::StaticCmd("demo_video_stop", Cmd::SYSTEM, "Stops recording a video") + : Cmd::StaticCmd("demo_video_stop", Cmd::CLIENT, "Stops recording a video") {} void Run(const Cmd::Args&) const override diff --git a/src/engine/framework/BaseCommands.cpp b/src/engine/framework/BaseCommands.cpp index 39ad163aa4..ccd96ab45a 100644 --- a/src/engine/framework/BaseCommands.cpp +++ b/src/engine/framework/BaseCommands.cpp @@ -1010,7 +1010,7 @@ namespace Cmd { class ShowFPSCommand : public Cmd::StaticCmd { public: - ShowFPSCommand() : StaticCmd("showfps", "prints engine frame rate") {} + ShowFPSCommand() : StaticCmd("showfps", Cmd::BASE, "prints engine frame rate") {} void Run(const Cmd::Args&) const override { Print("FPS: %.1f", Application::GetFPS()); diff --git a/src/engine/framework/CommandSystem.cpp b/src/engine/framework/CommandSystem.cpp index 7ba2f6395c..58021ffa16 100644 --- a/src/engine/framework/CommandSystem.cpp +++ b/src/engine/framework/CommandSystem.cpp @@ -396,11 +396,12 @@ namespace Cmd { static ListCmdsCmd listCmdsRegistration("listCmds", BASE, "lists all the commands", ~(CVAR|ALIAS)); static ListCmdsCmd listBaseCmdsRegistration("listBaseCmds", BASE, "lists all the base commands", BASE); - static ListCmdsCmd listSystemCmdsRegistration("listSystemCmds", BASE | SYSTEM, "lists all the system commands", SYSTEM); + static ListCmdsCmd listServerCmdsRegistration("listServerCmds", BASE | SERVER, "lists all the server commands", SERVER); + static ListCmdsCmd listClientCmdsRegistration("listClientCmds", BASE | CLIENT, "lists all the client commands", CLIENT | RENDERER | AUDIO | KEY_BINDING); static ListCmdsCmd listRendererCmdsRegistration("listRendererCmds", BASE | RENDERER, "lists all the renderer commands", RENDERER); static ListCmdsCmd listAudioCmdsRegistration("listAudioCmds", BASE | AUDIO, "lists all the audio commands", AUDIO); - static ListCmdsCmd listCGameCmdsRegistration("listCGameCmds", BASE | CGAME_VM, "lists all the client-side game commands", CGAME_VM); - static ListCmdsCmd listGameCmdsRegistration("listSGameCmds", BASE | SGAME_VM, "lists all the server-side game commands", CGAME_VM); static ListCmdsCmd listKeyCmdsRegistration("listKeyBindingCmds", BASE | KEY_BINDING, "lists all the key binding commands", KEY_BINDING); + static ListCmdsCmd listCGameCmdsRegistration("listCGameCmds", BASE, "lists all the client-side game commands", CGAME_VM); + static ListCmdsCmd listGameCmdsRegistration("listSGameCmds", BASE, "lists all the server-side game commands", SGAME_VM); static ListCmdsCmd listOldStyleCmdsRegistration("listOldStyleCmds", BASE, "lists all the commands registered through the C interface", PROXY_FOR_OLD); } diff --git a/src/engine/qcommon/files.cpp b/src/engine/qcommon/files.cpp index 9b532b30a3..dffaa10b35 100644 --- a/src/engine/qcommon/files.cpp +++ b/src/engine/qcommon/files.cpp @@ -766,7 +766,7 @@ bool FS_ComparePaks(char* neededpaks, int len) class WhichCmd: public Cmd::StaticCmd { public: WhichCmd() - : Cmd::StaticCmd("which", Cmd::SYSTEM, "shows which pak a file is in") {} + : Cmd::StaticCmd("which", Cmd::BASE, "shows which pak a file is in") {} void Run(const Cmd::Args& args) const override { @@ -797,7 +797,7 @@ static WhichCmd WhichCmdRegistration; class ListPathsCmd: public Cmd::StaticCmd { public: ListPathsCmd() - : Cmd::StaticCmd("listPaths", Cmd::SYSTEM, "list filesystem search paths") {} + : Cmd::StaticCmd("listPaths", Cmd::BASE, "list filesystem search paths") {} void Run(const Cmd::Args&) const override { @@ -810,7 +810,7 @@ static ListPathsCmd ListPathsCmdRegistration; class DirCmd: public Cmd::StaticCmd { public: - DirCmd(): Cmd::StaticCmd("dir", Cmd::SYSTEM, "list all files in a given directory with the option to pass a filter") {} + DirCmd(): Cmd::StaticCmd("dir", Cmd::BASE, "list all files in a given directory with the option to pass a filter") {} void Run(const Cmd::Args& args) const override { diff --git a/src/engine/renderer/tr_animation.cpp b/src/engine/renderer/tr_animation.cpp index fd56eee833..ea39201019 100644 --- a/src/engine/renderer/tr_animation.cpp +++ b/src/engine/renderer/tr_animation.cpp @@ -584,7 +584,8 @@ skelAnimation_t *R_GetAnimationByHandle( qhandle_t index ) class ListAnimationsCmd : public Cmd::StaticCmd { public: - ListAnimationsCmd() : StaticCmd("listAnimations", "list model animations loaded in renderer") {} + ListAnimationsCmd() : StaticCmd( + "listAnimations", Cmd::RENDERER, "list model animations loaded in renderer") {} void Run( const Cmd::Args & ) const override { diff --git a/src/engine/renderer/tr_bsp.cpp b/src/engine/renderer/tr_bsp.cpp index 94ef1e982f..c1b1c6c32e 100644 --- a/src/engine/renderer/tr_bsp.cpp +++ b/src/engine/renderer/tr_bsp.cpp @@ -5030,7 +5030,7 @@ void R_BuildCubeMaps() } static Cmd::LambdaCmd buildCubeMapsCmd( - "buildcubemaps", "generate cube probes for reflection mapping", + "buildcubemaps", Cmd::RENDERER, "generate cube probes for reflection mapping", []( const Cmd::Args & ) { R_BuildCubeMaps(); }); /* diff --git a/src/engine/renderer/tr_fbo.cpp b/src/engine/renderer/tr_fbo.cpp index 98beddeacb..45d006e871 100644 --- a/src/engine/renderer/tr_fbo.cpp +++ b/src/engine/renderer/tr_fbo.cpp @@ -594,7 +594,7 @@ void R_ShutdownFBOs() class ListFBOsCmd : public Cmd::StaticCmd { public: - ListFBOsCmd() : StaticCmd("listFBOs", "list renderer's OpenGL framebuffer objects") {} + ListFBOsCmd() : StaticCmd("listFBOs", Cmd::RENDERER, "list renderer's OpenGL framebuffer objects") {} void Run( const Cmd::Args & ) const override { diff --git a/src/engine/renderer/tr_image.cpp b/src/engine/renderer/tr_image.cpp index b7d32839b5..974d84848a 100644 --- a/src/engine/renderer/tr_image.cpp +++ b/src/engine/renderer/tr_image.cpp @@ -140,7 +140,7 @@ void GL_TextureMode( const char *string ) class ListImagesCmd : public Cmd::StaticCmd { public: - ListImagesCmd() : StaticCmd("listImages", "list images loaded in renderer") {} + ListImagesCmd() : StaticCmd("listImages", Cmd::RENDERER, "list images loaded in renderer") {} void Run( const Cmd::Args &args ) const override { diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index 686592e4e0..a8c1d67c21 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -525,7 +525,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA class ListModesCmd : public Cmd::StaticCmd { public: - ListModesCmd() : StaticCmd("listModes", "list suggested screen/window dimensions") {} + ListModesCmd() : StaticCmd("listModes", Cmd::RENDERER, "list suggested screen/window dimensions") {} void Run( const Cmd::Args& ) const override { int i; @@ -1085,14 +1085,14 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p // FIXME: uses regular logging not Print() static Cmd::LambdaCmd gfxInfoCmd( - "gfxinfo", "dump graphics driver and configuration info", + "gfxinfo", Cmd::RENDERER, "dump graphics driver and configuration info", []( const Cmd::Args & ) { GfxInfo_f(); }); class GlslRestartCmd : public Cmd::StaticCmd { public: GlslRestartCmd() : StaticCmd( - "glsl_restart", "recompile GLSL shaders (useful when shaderpath is set)") {} + "glsl_restart", Cmd::RENDERER, "recompile GLSL shaders (useful when shaderpath is set)") {} void Run( const Cmd::Args & ) const override { diff --git a/src/engine/renderer/tr_model.cpp b/src/engine/renderer/tr_model.cpp index a8ce4a733a..8d85386946 100644 --- a/src/engine/renderer/tr_model.cpp +++ b/src/engine/renderer/tr_model.cpp @@ -309,7 +309,7 @@ void R_ModelInit() class ListModelsCmd : public Cmd::StaticCmd { public: - ListModelsCmd() : StaticCmd("listModels", "list loaded 3D models") {} + ListModelsCmd() : StaticCmd("listModels", Cmd::RENDERER, "list loaded 3D models") {} void Run( const Cmd::Args &args ) const override { diff --git a/src/engine/renderer/tr_shader.cpp b/src/engine/renderer/tr_shader.cpp index f5c2b10184..77b52a80ce 100644 --- a/src/engine/renderer/tr_shader.cpp +++ b/src/engine/renderer/tr_shader.cpp @@ -6641,7 +6641,8 @@ A second parameter will cause it to print in sorted order class ListShadersCmd : public Cmd::StaticCmd { public: - ListShadersCmd() : StaticCmd("listShaders", "list q3shaders currently registered in the renderer") {} + ListShadersCmd() : StaticCmd( + "listShaders", Cmd::RENDERER, "list q3shaders currently registered in the renderer") {} void Run( const Cmd::Args &args ) const override { @@ -6858,7 +6859,8 @@ static ListShadersCmd listShadersCmdRegistration; class ShaderExpCmd : public Cmd::StaticCmd { public: - ShaderExpCmd() : StaticCmd("shaderexp", "evaluate a q3shader expression (RB_EvalExpression)") {} + ShaderExpCmd() : StaticCmd( + "shaderexp", Cmd::RENDERER, "evaluate a q3shader expression (RB_EvalExpression)") {} void Run( const Cmd::Args &args ) const override { diff --git a/src/engine/renderer/tr_skin.cpp b/src/engine/renderer/tr_skin.cpp index ee552a4a73..2f3afbf110 100644 --- a/src/engine/renderer/tr_skin.cpp +++ b/src/engine/renderer/tr_skin.cpp @@ -330,7 +330,7 @@ skin_t *R_GetSkinByHandle( qhandle_t hSkin ) class ListSkinsCmd : public Cmd::StaticCmd { public: - ListSkinsCmd() : StaticCmd("listSkins", "list model skins") {} + ListSkinsCmd() : StaticCmd("listSkins", Cmd::RENDERER, "list model skins") {} void Run( const Cmd::Args & ) const override { diff --git a/src/engine/server/sv_ccmds.cpp b/src/engine/server/sv_ccmds.cpp index 3598e153f7..aaafd26b8c 100644 --- a/src/engine/server/sv_ccmds.cpp +++ b/src/engine/server/sv_ccmds.cpp @@ -47,7 +47,7 @@ These commands can only be entered from stdin or by a remote operator datagram class MapCmd: public Cmd::StaticCmd { public: MapCmd(Str::StringRef name, Str::StringRef description, bool cheat): - Cmd::StaticCmd(name, Cmd::SYSTEM, description), cheat(cheat) { + Cmd::StaticCmd(name, Cmd::SERVER, description), cheat(cheat) { } void Run(const Cmd::Args& args) const override { @@ -255,7 +255,7 @@ class StatusCmd: public Cmd::StaticCmd { public: StatusCmd(): - StaticCmd("status", Cmd::SYSTEM, "Shows a table with server and player information") + StaticCmd("status", Cmd::SERVER, "Shows a table with server and player information") {} void Run(const Cmd::Args&) const override @@ -402,7 +402,7 @@ class ListMapsCmd: public Cmd::StaticCmd { public: ListMapsCmd(): - StaticCmd("listmaps", Cmd::SYSTEM, "Lists all maps available to the server") + StaticCmd("listmaps", Cmd::SERVER, "Lists all maps available to the server") {} void Run(const Cmd::Args&) const override diff --git a/src/engine/sys/sdl_glimp.cpp b/src/engine/sys/sdl_glimp.cpp index d484be43f8..36519fccd3 100644 --- a/src/engine/sys/sdl_glimp.cpp +++ b/src/engine/sys/sdl_glimp.cpp @@ -501,7 +501,7 @@ void GLimp_Shutdown() } static Cmd::LambdaCmd minimizeCmd( - "minimize", "minimize the window", + "minimize", Cmd::CLIENT, "minimize the window", []( const Cmd::Args & ) { SDL_MinimizeWindow( window ); }); static void SetSwapInterval( int swapInterval ) From 13331e200b22c43efe5d112d08422c165b4a95b7 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 17 Jan 2025 20:07:41 -0600 Subject: [PATCH 07/14] When listing commands, use alphabetical order --- src/engine/framework/CommandSystem.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/engine/framework/CommandSystem.cpp b/src/engine/framework/CommandSystem.cpp index 58021ffa16..133adffdf6 100644 --- a/src/engine/framework/CommandSystem.cpp +++ b/src/engine/framework/CommandSystem.cpp @@ -351,12 +351,11 @@ namespace Cmd { void Run(const Cmd::Args& args) const override { CommandMap& commands = GetCommandMap(); - std::vector matches; - std::vector matchesNames; + std::vector matches; unsigned long maxNameLength = 0; //Find all the matching commands and their names - for (auto it = commands.cbegin(); it != commands.cend(); ++it) { + for (CommandMap::const_iterator it = commands.cbegin(); it != commands.cend(); ++it) { const commandRecord_t& record = it->second; // /listCmds's argument is used for prefix matching @@ -365,16 +364,19 @@ namespace Cmd { } if (record.cmd->GetFlags() & showCmdFlags) { - matches.push_back(&it->second); - matchesNames.push_back(&it->first); + matches.push_back(it); maxNameLength = std::max(maxNameLength, it->first.size()); } } + // TODO: case insensitive compare function? + std::sort(matches.begin(), matches.end(), + [](CommandMap::const_iterator a, CommandMap::const_iterator b) { return a->first < b->first; }); + //Print the matches, keeping the description aligned - for (unsigned i = 0; i < matches.size(); i++) { - int toFill = maxNameLength - matchesNames[i]->size(); - Print(" %s%s %s", matchesNames[i]->c_str(), std::string(toFill, ' ').c_str(), matches[i]->description.c_str()); + for (CommandMap::const_iterator it : matches) { + int toFill = maxNameLength - it->first.size(); + Print(" %s%s %s", it->first, std::string(toFill, ' '), it->second.description); } Print("%zu commands", matches.size()); From b65a63f3b4fdb409579e51c0a5238a1912776bf4 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 13 Dec 2024 20:04:54 -0600 Subject: [PATCH 08/14] NET_OpenIP: fix using wrong port num --- src/engine/qcommon/net_ip.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index 125f2e1366..f9ba0a360d 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -1630,7 +1630,7 @@ static void NET_OpenIP() if ( net_enabled->integer & NET_ENABLEV4 ) { - for ( i = ( port6 == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i-- ) + for ( i = ( port == PORT_ANY ? 1 : MAX_TRY_PORTS ); i; i-- ) { ip_socket = NET_IPSocket( net_ip->string, port, &boundto4, &err ); From f70cf74fbc3459792f3b2b0c509979ab047980a2 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 13 Dec 2024 21:10:24 -0600 Subject: [PATCH 09/14] Fix /net_restart on Windows with running server It was producing errors about the port being already in use, and thus switching to port 27961 instead of 27960. This was caused by the socket being inherited by NaCl processes. --- src/engine/qcommon/net_ip.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index f9ba0a360d..5ed12e70b6 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -935,7 +935,13 @@ SOCKET NET_IPSocket( const char *net_interface, int port, struct sockaddr_in *bi Log::Notice( "Opening IP socket: %s:%s", net_interface ? net_interface : "0.0.0.0", port ? va( "%i", port ) : "*" ); - if ( ( newsocket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ) ) == INVALID_SOCKET ) +#ifdef _WIN32 + newsocket = WSASocketW( PF_INET, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT ); +#else + newsocket = socket( PF_INET, SOCK_DGRAM, IPPROTO_UDP ); +#endif + + if ( newsocket == INVALID_SOCKET ) { *err = socketError; Log::Warn( "NET_IPSocket: socket: %s", NET_ErrorString() ); @@ -1020,7 +1026,13 @@ SOCKET NET_IP6Socket( const char *net_interface, int port, struct sockaddr_in6 * // Print the name in brackets if there is a colon: Log::Notice( "Opening IP6 socket: %s%s%s:%s", brackets ? "[" : "", net_interface ? net_interface : "[::]", brackets ? "]" : "", port ? va( "%i", port ) : "*" ); - if ( ( newsocket = socket( PF_INET6, SOCK_DGRAM, IPPROTO_UDP ) ) == INVALID_SOCKET ) +#ifdef _WIN32 + newsocket = WSASocketW( PF_INET6, SOCK_DGRAM, IPPROTO_UDP, nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT ); +#else + newsocket = socket( PF_INET6, SOCK_DGRAM, IPPROTO_UDP ); +#endif + + if ( newsocket == INVALID_SOCKET ) { *err = socketError; Log::Warn( "NET_IP6Socket: socket: %s", NET_ErrorString() ); @@ -1223,7 +1235,13 @@ void NET_OpenSocks( int port ) Log::Notice( "Opening connection to SOCKS server." ); - if ( ( socks_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ) ) == INVALID_SOCKET ) +#ifdef _WIN32 + socks_socket = WSASocketW( AF_INET, SOCK_STREAM, IPPROTO_TCP, nullptr, 0, WSA_FLAG_NO_HANDLE_INHERIT ); +#else + socks_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP ); +#endif + + if ( socks_socket == INVALID_SOCKET ) { Log::Warn( "NET_OpenSocks: socket: %s", NET_ErrorString() ); return; From 5abe6336cc907229a6b39b096c1bc9cca3eabd56 Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 29 Nov 2024 00:46:14 -0600 Subject: [PATCH 10/14] Refactor NET_Config; drop cvar modified checks NET_Config(bool enableNetworking) was a function to either open the network sockets if the arg is true, or close them if it is false. It checked the modified flag of a bunch of net_ cvars, with the idea that if it is requested to enable networking while it was already enabled, to not do anything unless the configuration is changed. But actually this situation can never happen, so we can drop the modify checks and always reinitialize. NET_Config( true ) was only done in 4 places, none of which could possibly omit the network (re-)initialization: - NET_Init - only called once on startup - NET_Restart - the point of /net_restart is to force reinitialization - SV_Startup - this is only done in clients and starting the server is a state change for clients so restart can't be skipped - SV_Shutdown - this is only done in clients and stopping the server is a state change for clients so restart can't be skipped. Also split NET_Config into two functions NET_EnableNetworking and NET_DisableNetworking for better readability. --- src/engine/qcommon/net_ip.cpp | 157 ++++++++++------------------------ src/engine/qcommon/qcommon.h | 3 +- src/engine/server/sv_init.cpp | 4 +- 3 files changed, 49 insertions(+), 115 deletions(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index 5ed12e70b6..e7637bb1bf 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -35,6 +35,7 @@ Maryland 20850 USA. #include "qcommon/q_shared.h" #include "qcommon/qcommon.h" #include +#include "engine/framework/Application.h" #include "engine/framework/Network.h" #include "server/server.h" @@ -120,11 +121,6 @@ namespace net { static bool usingSocks = false; static bool networkingEnabled = false; -#ifndef BUILD_SERVER -static bool serverMode = false; -#else -static const bool serverMode = true; -#endif cvar_t *net_enabled; @@ -1598,7 +1594,7 @@ static int NET_EnsureValidPortNo( int port ) NET_OpenIP ==================== */ -static void NET_OpenIP() +static void NET_OpenIP( bool serverMode ) { int i; int err = 0; @@ -1689,10 +1685,8 @@ static void NET_OpenIP() NET_GetCvars ==================== */ -static bool NET_GetCvars() +static void NET_GetCvars() { - int modified; - #ifdef BUILD_SERVER // I want server owners to explicitly turn on IPv6 support. net_enabled = Cvar_Get( "net_enabled", "1", CVAR_LATCH ); @@ -1702,147 +1696,82 @@ static bool NET_GetCvars() * used if available due to ping */ net_enabled = Cvar_Get( "net_enabled", "3", CVAR_LATCH ); #endif - modified = net_enabled->modified; - net_enabled->modified = false; net_ip = Cvar_Get( "net_ip", "0.0.0.0", CVAR_LATCH ); - modified += net_ip->modified; - net_ip->modified = false; - net_ip6 = Cvar_Get( "net_ip6", "::", CVAR_LATCH ); - modified += net_ip6->modified; - net_ip6->modified = false; - net_port = Cvar_Get( "net_port", va( "%i", PORT_SERVER ), CVAR_LATCH ); - modified += net_port->modified; - net_port->modified = false; - net_port6 = Cvar_Get( "net_port6", va( "%i", PORT_SERVER ), CVAR_LATCH ); - modified += net_port6->modified; - net_port6->modified = false; // Some cvars for configuring multicast options which facilitates scanning for servers on local subnets. net_mcast6addr = Cvar_Get( "net_mcast6addr", NET_MULTICAST_IP6, CVAR_LATCH ); - modified += net_mcast6addr->modified; - net_mcast6addr->modified = false; - #ifdef _WIN32 net_mcast6iface = Cvar_Get( "net_mcast6iface", "0", CVAR_LATCH ); #else net_mcast6iface = Cvar_Get( "net_mcast6iface", "", CVAR_LATCH ); #endif - modified += net_mcast6iface->modified; - net_mcast6iface->modified = false; net_socksEnabled = Cvar_Get( "net_socksEnabled", "0", CVAR_LATCH ); - modified += net_socksEnabled->modified; - net_socksEnabled->modified = false; - net_socksServer = Cvar_Get( "net_socksServer", "", CVAR_LATCH ); - modified += net_socksServer->modified; - net_socksServer->modified = false; - net_socksPort = Cvar_Get( "net_socksPort", "1080", CVAR_LATCH ); - modified += net_socksPort->modified; - net_socksPort->modified = false; - net_socksUsername = Cvar_Get( "net_socksUsername", "", CVAR_LATCH ); - modified += net_socksUsername->modified; - net_socksUsername->modified = false; - net_socksPassword = Cvar_Get( "net_socksPassword", "", CVAR_LATCH ); - modified += net_socksPassword->modified; - net_socksPassword->modified = false; - - return modified ? true : false; } -/* -==================== -NET_Config -==================== -*/ -void NET_Config( bool enableNetworking ) +void NET_EnableNetworking( bool serverMode ) { - bool modified; - bool stop; - bool start; -#ifndef BUILD_SERVER - bool svRunning; -#endif - // get any latched changes to cvars - modified = NET_GetCvars(); -#ifndef BUILD_SERVER - svRunning = !!com_sv_running->integer; - modified |= ( svRunning != serverMode ); -#endif + NET_GetCvars(); - if ( !net_enabled->integer ) - { - enableNetworking = false; - } + // always cycle off and on because this function is only called on a state change or forced restart + NET_DisableNetworking(); - // if enable state is the same and no cvars were modified, we have nothing to do - if ( enableNetworking == networkingEnabled && !modified ) + if ( !( net_enabled->integer & ( NET_ENABLEV4 | NET_ENABLEV6 ) ) ) { return; } - start = enableNetworking; - if ( enableNetworking == networkingEnabled ) - { - stop = enableNetworking; - } - else + networkingEnabled = true; + + NET_OpenIP( serverMode ); + NET_SetMulticast6(); + SV_NET_Config(); +} + +void NET_DisableNetworking() +{ + if ( !networkingEnabled ) { - stop = !enableNetworking; + return; } -#ifndef BUILD_SERVER - serverMode = svRunning; -#endif - networkingEnabled = enableNetworking; + networkingEnabled = false; - if ( stop ) + if ( ip_socket != INVALID_SOCKET ) { - if ( ip_socket != INVALID_SOCKET ) - { - closesocket( ip_socket ); - ip_socket = INVALID_SOCKET; - } + closesocket( ip_socket ); + ip_socket = INVALID_SOCKET; + } - if ( multicast6_socket != INVALID_SOCKET ) + if ( multicast6_socket != INVALID_SOCKET ) + { + if ( multicast6_socket != ip6_socket ) { - if ( multicast6_socket != ip6_socket ) - { - closesocket( multicast6_socket ); - } - - multicast6_socket = INVALID_SOCKET; + closesocket( multicast6_socket ); } - if ( ip6_socket != INVALID_SOCKET ) - { - closesocket( ip6_socket ); - ip6_socket = INVALID_SOCKET; - } + multicast6_socket = INVALID_SOCKET; + } - if ( socks_socket != INVALID_SOCKET ) - { - closesocket( socks_socket ); - socks_socket = INVALID_SOCKET; - } + if ( ip6_socket != INVALID_SOCKET ) + { + closesocket( ip6_socket ); + ip6_socket = INVALID_SOCKET; } - if ( start ) + if ( socks_socket != INVALID_SOCKET ) { - if ( net_enabled->integer ) - { - NET_OpenIP(); - NET_SetMulticast6(); - SV_NET_Config(); - } + closesocket( socks_socket ); + socks_socket = INVALID_SOCKET; } } @@ -1868,7 +1797,7 @@ void NET_Init() Log::Notice( "Winsock Initialized" ); #endif - NET_Config( true ); + NET_EnableNetworking( Application::GetTraits().isServer ); Cmd_AddCommand( "net_restart", NET_Restart_f ); } @@ -1885,7 +1814,7 @@ void NET_Shutdown() return; } - NET_Config( false ); + NET_DisableNetworking(); #ifdef _WIN32 WSACleanup(); @@ -1948,8 +1877,12 @@ NET_Restart_f */ void NET_Restart_f() { - NET_Config( false ); + NET_DisableNetworking(); SV_NET_Config(); Net::ShutDownDNS(); - NET_Config( true ); +#ifdef BUILD_SERVER + NET_EnableNetworking( true ); +#else + NET_EnableNetworking( !!com_sv_running->integer ); +#endif } diff --git a/src/engine/qcommon/qcommon.h b/src/engine/qcommon/qcommon.h index 1dbdf3e0e7..dc01323ef2 100644 --- a/src/engine/qcommon/qcommon.h +++ b/src/engine/qcommon/qcommon.h @@ -149,7 +149,8 @@ extern cvar_t *net_enabled; void NET_Init(); void NET_Shutdown(); void NET_Restart_f(); -void NET_Config( bool enableNetworking ); +void NET_EnableNetworking( bool serverMode ); +void NET_DisableNetworking(); void NET_SendPacket( netsrc_t sock, int length, const void *data, const netadr_t& to ); diff --git a/src/engine/server/sv_init.cpp b/src/engine/server/sv_init.cpp index 9cff95dfa0..8a3c55510b 100644 --- a/src/engine/server/sv_init.cpp +++ b/src/engine/server/sv_init.cpp @@ -345,7 +345,7 @@ void SV_Startup() Cvar_Set( "sv_running", "1" ); #ifndef BUILD_SERVER - NET_Config( true ); + NET_EnableNetworking( true ); #endif // Join the IPv6 multicast group now that a map is running, so clients can scan for us on the local network. @@ -767,7 +767,7 @@ void SV_Shutdown( const char *finalmsg ) Cvar_Set( "sv_running", "0" ); #ifndef BUILD_SERVER - NET_Config( true ); + NET_EnableNetworking( false ); #endif SV_NET_Config(); // clear master server DNS queries From e008a9a7cdefb0a00cab9b20ef606bc00e20411f Mon Sep 17 00:00:00 2001 From: slipher Date: Fri, 13 Dec 2024 21:16:04 -0600 Subject: [PATCH 11/14] NET_Shutdown: fix bogus early return --- src/engine/qcommon/net_ip.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/engine/qcommon/net_ip.cpp b/src/engine/qcommon/net_ip.cpp index e7637bb1bf..0b26f1c920 100644 --- a/src/engine/qcommon/net_ip.cpp +++ b/src/engine/qcommon/net_ip.cpp @@ -1809,16 +1809,14 @@ NET_Shutdown */ void NET_Shutdown() { - if ( !networkingEnabled ) - { - return; - } - NET_DisableNetworking(); #ifdef _WIN32 - WSACleanup(); - winsockInitialized = false; + if ( winsockInitialized ) + { + WSACleanup(); + winsockInitialized = false; + } #endif } From d6a5813aa87da0df59f1404fd8889ad9c6914ce4 Mon Sep 17 00:00:00 2001 From: slipher Date: Wed, 22 Jan 2025 09:11:00 -0600 Subject: [PATCH 12/14] Comment on confusing NET_EnableNetworking calls --- src/engine/server/sv_init.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/engine/server/sv_init.cpp b/src/engine/server/sv_init.cpp index 8a3c55510b..306b5e24d5 100644 --- a/src/engine/server/sv_init.cpp +++ b/src/engine/server/sv_init.cpp @@ -345,6 +345,7 @@ void SV_Startup() Cvar_Set( "sv_running", "1" ); #ifndef BUILD_SERVER + // For clients, reconfigure to open server ports. NET_EnableNetworking( true ); #endif @@ -767,6 +768,7 @@ void SV_Shutdown( const char *finalmsg ) Cvar_Set( "sv_running", "0" ); #ifndef BUILD_SERVER + // For clients, reconfigure to close server ports. NET_EnableNetworking( false ); #endif From 8cc5260844812e86691409ba1d9214d9ce9d70aa Mon Sep 17 00:00:00 2001 From: VReaperV Date: Tue, 21 Jan 2025 23:15:07 +0300 Subject: [PATCH 13/14] Fix backEnd.currentVAO This was previously getting reset in `R_Init()`, so it was always 0 after a map was loaded. This also meant that the call to `glDeleteVertexArrays()` in `RE_Shutdown()` was silently erroring out if a map was loaded (or `vid_restart` used). --- src/engine/renderer/tr_init.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/engine/renderer/tr_init.cpp b/src/engine/renderer/tr_init.cpp index a8c1d67c21..1354bbc132 100644 --- a/src/engine/renderer/tr_init.cpp +++ b/src/engine/renderer/tr_init.cpp @@ -341,11 +341,6 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA return false; } - if( glConfig2.glCoreProfile ) { - glGenVertexArrays( 1, &backEnd.currentVAO ); - glBindVertexArray( backEnd.currentVAO ); - } - glState.tileStep[ 0 ] = TILE_SIZE * ( 1.0f / glConfig.vidWidth ); glState.tileStep[ 1 ] = TILE_SIZE * ( 1.0f / glConfig.vidHeight ); @@ -381,6 +376,11 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA GLSL_InitGPUShaders(); } + if ( glConfig2.glCoreProfile ) { + glGenVertexArrays( 1, &backEnd.currentVAO ); + glBindVertexArray( backEnd.currentVAO ); + } + GL_CheckErrors(); // set default state From 3265f2dbdc45760709b481bee54e59135238c317 Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 23 Jan 2025 07:40:08 +0100 Subject: [PATCH 14/14] cmake: build Saigo arm nexe with -O0 to avoid a bug --- cmake/DaemonFlags.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmake/DaemonFlags.cmake b/cmake/DaemonFlags.cmake index e8da09c008..0bd6eb94f0 100644 --- a/cmake/DaemonFlags.cmake +++ b/cmake/DaemonFlags.cmake @@ -231,6 +231,17 @@ else() endif() endif() + if (NACL AND USE_NACL_SAIGO AND SAIGO_ARCH STREQUAL "arm") + # This should be set for every build type because build type flags + # are set after the other custom flags and then have the last word. + # DEBUG should already use -O0 anyway. + # See: https://github.com/Unvanquished/Unvanquished/issues/3297 + set_c_cxx_flag("-O0" DEBUG) + set_c_cxx_flag("-O0" RELEASE) + set_c_cxx_flag("-O0" RELWITHDEBINFO) + set_c_cxx_flag("-O0" MINSIZEREL) + endif() + # Extra debug flags. set_c_cxx_flag("-g3" RELWITHDEBINFO) set_c_cxx_flag("-g3" DEBUG)