Skip to content

Commit

Permalink
Add support for smaller lightmaps
Browse files Browse the repository at this point in the history
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
  • Loading branch information
smallmodel committed Dec 2, 2024
1 parent 499fe44 commit a1fe3c9
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 9 deletions.
19 changes: 19 additions & 0 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/*
================
Expand Down
8 changes: 6 additions & 2 deletions code/cgame/cg_servercmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
8 changes: 7 additions & 1 deletion code/client/cl_cgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
20 changes: 20 additions & 0 deletions code/client/cl_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion code/client/cl_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions code/null/null_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,7 @@ qboolean CL_FinishedIntro( void ) {
int R_CountTextureMemory() {
return 0;
}

qboolean CL_UseLargeLightmap(const char* mapName) {
return qtrue;
}
3 changes: 3 additions & 0 deletions code/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 11 additions & 3 deletions code/renderergl1/tr_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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->integer);
}

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 );
Expand Down
1 change: 1 addition & 0 deletions code/renderergl1/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion code/server/sv_ccmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion code/server/sv_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1fe3c9

Please sign in to comment.