Add support for smaller lightmaps

Large lightmap can be disabled for very low-end hardware. A BSP file with a smaller lightmap (_sml.bsp) will be used instead of the standard one if the map supports it
This commit is contained in:
smallmodel 2024-12-02 19:25:02 +01:00
parent 499fe44bde
commit 861338b0fc
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
12 changed files with 92 additions and 9 deletions

View file

@ -509,6 +509,7 @@ extern "C" {
//
// cg_main.c
//
qboolean CG_UseLargeLightmaps(const char* mapName);
void CG_ProcessConfigString(int num, qboolean modelOnly);
const char *CG_ConfigString(int index);
void CG_AddToTeamChat(const char *str);

View file

@ -204,6 +204,25 @@ void CG_RegisterCvars(void)
temp = cgi.Cvar_Get("sv_running", "0", 0);
cgs.localServer = temp->integer;
}
/*
===============
CG_UseLargeLightmaps
Added in 2.0
Returns true if the standard BSP file should be used, false if the smaller lightmap BSP file should be used
===============
*/
qboolean CG_UseLargeLightmaps(const char* mapName) {
char buffer[MAX_QPATH];
Com_sprintf(buffer, sizeof(buffer), "maps/%s_sml.bsp", mapName);
if (cgi.FS_ReadFile(buffer, NULL, qtrue) == -1) {
return qtrue;
}
return cgi.Cvar_Get("r_largemap", "0", 0)->integer;
}
/*
================

View file

@ -190,8 +190,12 @@ void CG_ParseServerinfo(void)
Q_strncpyz(map, mapname, sizeof(map));
}
Com_sprintf(cgs.mapname, sizeof(cgs.mapname), "maps/%s.bsp", map);
if (CG_UseLargeLightmaps(mapname)) {
Com_sprintf(cgs.mapname, sizeof(cgs.mapname), "maps/%s.bsp", map);
} else {
Com_sprintf(cgs.mapname, sizeof(cgs.mapname), "maps/%s_sml.bsp", map);
}
// hide/show huds
if (cgs.gametype) {
cgi.Cmd_Execute(EXEC_NOW, "ui_addhud hud_timelimit\n");

View file

@ -923,7 +923,13 @@ void CL_InitCGame( void ) {
// find the current mapname
info = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SERVERINFO ];
mapname = Info_ValueForKey( info, "mapname" );
Com_sprintf( cl.mapname, sizeof( cl.mapname ), "maps/%s.bsp", mapname );
if (CL_UseLargeLightmap(mapname)) {
Com_sprintf(cl.mapname, sizeof(cl.mapname), "maps/%s.bsp", mapname);
} else {
// Added in 2.0
Com_sprintf(cl.mapname, sizeof(cl.mapname), "maps/%s_sml.bsp", mapname);
}
S_BeginRegistration();
CL_ShutdownCGame();

View file

@ -172,6 +172,26 @@ void CL_ServerStatusResponse( netadr_t from, msg_t *msg );
static qboolean cl_bCLSystemStarted = qfalse;
/*
===============
CL_UseLargeLightmap
Added in 2.0
Returns true if the standard BSP file should be used, false if the smaller lightmap BSP file should be used
===============
*/
qboolean CL_UseLargeLightmap(const char* mapName) {
char buffer[MAX_QPATH];
Com_sprintf(buffer, sizeof(buffer), "maps/%s_sml.bsp", mapName);
if (FS_ReadFileEx(buffer, NULL, qtrue) == -1) {
return qtrue;
}
return Cvar_Get("r_largemap", "0", 0)->integer;
}
/*
===============
CL_CDDialog

View file

@ -5799,8 +5799,15 @@ void UI_BeginLoad(const char *pszMapName)
loadName = "maps/";
loadName += pszMapName;
mapfile = loadName;
loadName += ".min";
mapfile = loadName + ".bsp";
if (CL_UseLargeLightmap(pszMapName)) {
mapfile += ".bsp";
} else {
// Added in 2.0
mapfile += "_sml.bsp";
}
if (UI_ArchiveLoadMapinfo(mapfile)) {
cls.loading = SS_LOADING2;

View file

@ -129,3 +129,7 @@ qboolean CL_FinishedIntro( void ) {
int R_CountTextureMemory() {
return 0;
}
qboolean CL_UseLargeLightmap(const char* mapName) {
return qtrue;
}

View file

@ -1217,6 +1217,9 @@ void CL_ForwardCommandToServer( const char *string );
// things like godmode, noclip, etc, are commands directed to the server,
// so when they are typed in at the console, they will need to be forwarded.
qboolean CL_UseLargeLightmap(const char* mapName);
// returns true if the standard BSP file should be used
void CL_CDDialog( void );
// bring up the "need a cd to play" dialog

View file

@ -102,6 +102,7 @@ cvar_t *r_depthbits;
cvar_t *r_colorbits;
cvar_t *r_stereo;
cvar_t *r_primitives;
cvar_t *r_largemap;
cvar_t *r_textureDetails;
cvar_t *r_texturebits;
@ -1346,11 +1347,18 @@ void R_Register( void )
r_picmip = ri.Cvar_Get ("r_picmip", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_picmip_cap = ri.Cvar_Get ("r_picmip_cap", "0", CVAR_ARCHIVE | CVAR_LATCH );
if (r_picmip->integer < r_picmip_cap->integer) {
ri.Cvar_Set("r_picmip", r_picmip_cap->string);
}
if (r_picmip->integer < 2) {
r_largemap = ri.Cvar_Get("r_largemap", "1", 0);
} else {
r_largemap = ri.Cvar_Get("r_largemap", "0", 0);
}
r_roundImagesDown = ri.Cvar_Get ("r_roundImagesDown", "1", CVAR_ARCHIVE | CVAR_LATCH );
r_colorMipLevels = ri.Cvar_Get ("r_colorMipLevels", "0", CVAR_LATCH );
if (r_picmip->integer < r_picmip_cap->integer) {
ri.Cvar_Set("r_picmip", r_picmip_cap->integer);
}
AssertCvarRange( r_picmip, 0, 16, qtrue );
r_textureDetails = ri.Cvar_Get("r_textureDetails", "1", 33);
r_texturebits = ri.Cvar_Get( "r_texturebits", "0", CVAR_ARCHIVE | CVAR_LATCH );

View file

@ -1451,6 +1451,7 @@ extern cvar_t *r_primitives; // "0" = based on compiled vertex array existance
// "2" = glDrawElements triangles
// "-1" = no drawing
extern cvar_t *r_largemap;
extern cvar_t *r_inGameVideo; // controls whether in game video should be draw
extern cvar_t *r_fastsky; // controls whether sky should be cleared or drawn
extern cvar_t *r_fastdlights;

View file

@ -193,7 +193,12 @@ static void SV_Map_f( void ) {
// make sure the level exists before trying to change, so that
// a typo at the server console won't end the game
Com_sprintf( expanded, sizeof( expanded ), "maps/%s.bsp", map );
// Added in 2.0
if ( CL_UseLargeLightmap( mapname ) ) {
Com_sprintf( expanded, sizeof( expanded ), "maps/%s.bsp", map );
} else {
Com_sprintf( expanded, sizeof( expanded ), "maps/%s_sml.bsp", map );
}
if( FS_ReadFile( expanded, NULL ) == -1 ) {
Com_Printf( "Can't find map %s\n", expanded );
return;

View file

@ -697,7 +697,12 @@ void SV_SpawnServer( const char *server, qboolean loadgame, qboolean restart, qb
char filename[ MAX_QPATH ];
TIKI_FreeAll();
Com_sprintf( filename, sizeof( filename ), "maps/%s.bsp", mapname );
if ( CL_UseLargeLightmap( mapname ) ) {
Com_sprintf( filename, sizeof( filename ), "maps/%s.bsp", mapname );
} else {
// Added in 2.0
Com_sprintf( filename, sizeof( filename ), "maps/%s_sml.bsp", mapname );
}
CM_LoadMap( filename, qfalse, &checksum );
// set checksum