From 581bc2c769a760af3b3ce6fc54c5700f3474598b Mon Sep 17 00:00:00 2001 From: divverent Date: Fri, 22 May 2009 06:07:19 +0000 Subject: [PATCH] -lightmapsearchpower -lightmapsearchblocksize to optimize lightmap search for darkplaces and other lightmap-merging engines git-svn-id: svn://svn.icculus.org/netradiant/trunk@370 61c419a2-8eb2-4b30-bcec-8cead039b335 --- tools/quake3/q3map2/light.c | 27 ++++++++++++++++++++++++++- tools/quake3/q3map2/lightmaps_ydnar.c | 6 +++++- tools/quake3/q3map2/q3map2.h | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/quake3/q3map2/light.c b/tools/quake3/q3map2/light.c index eacfba31..1517ba96 100644 --- a/tools/quake3/q3map2/light.c +++ b/tools/quake3/q3map2/light.c @@ -1845,6 +1845,7 @@ int LightMain( int argc, char **argv ) float f; char mapSource[ 1024 ]; const char *value; + int lightmapMergeSize = 0; /* note it */ @@ -2171,10 +2172,24 @@ int LightMain( int argc, char **argv ) else if( !strcmp( argv[ i ], "-nolightmapsearch" ) ) { - noLightmapSearch = qtrue; + lightmapSearchBlockSize = 1; Sys_Printf( "No lightmap searching - all lightmaps will be sequential\n" ); } + else if( !strcmp( argv[ i ], "-lightmapsearchpower" ) ) + { + lightmapMergeSize = (game->lightmapSize << atoi(argv[i+1])); + ++i; + Sys_Printf( "Restricted lightmap searching enabled - optimize for lightmap merge power %d (size %d)\n", atoi(argv[i]), lightmapMergeSize ); + } + + else if( !strcmp( argv[ i ], "-lightmapsearchblocksize" ) ) + { + lightmapSearchBlockSize = atoi(argv[i+1]); + ++i; + Sys_Printf( "Restricted lightmap searching enabled - block size set to %d\n", lightmapSearchBlockSize ); + } + else if( !strcmp( argv[ i ], "-shade" ) ) { shade = qtrue; @@ -2467,6 +2482,16 @@ int LightMain( int argc, char **argv ) } } + + /* fix up lightmap search power */ + if(lightmapMergeSize) + { + lightmapSearchBlockSize = (lightmapMergeSize / lmCustomSize) * (lightmapMergeSize / lmCustomSize); + if(lightmapSearchBlockSize < 1) + lightmapSearchBlockSize = 1; + + Sys_Printf( "Restricted lightmap searching enabled - block size adjusted to %d\n", lightmapSearchBlockSize ); + } /* clean up map name */ strcpy( source, ExpandArg( argv[ i ] ) ); diff --git a/tools/quake3/q3map2/lightmaps_ydnar.c b/tools/quake3/q3map2/lightmaps_ydnar.c index e6875c0e..eee4f6f8 100644 --- a/tools/quake3/q3map2/lightmaps_ydnar.c +++ b/tools/quake3/q3map2/lightmaps_ydnar.c @@ -2016,7 +2016,11 @@ static void FindOutLightmaps( rawLightmap_t *lm ) y = 0; /* walk the list of lightmap pages */ - for( i = ((noLightmapSearch && numOutLightmaps >= LIGHTMAP_RESERVE_COUNT) ? (numOutLightmaps - LIGHTMAP_RESERVE_COUNT) : 0); i < numOutLightmaps; i++ ) + if(lightmapSearchBlockSize <= 0) + i = 0; + else + i = ((numOutLightmaps - LIGHTMAP_RESERVE_COUNT) / lightmapSearchBlockSize) * lightmapSearchBlockSize; + for( ; i < numOutLightmaps; i++ ) { /* get the output lightmap */ olm = &outLightmaps[ i ]; diff --git a/tools/quake3/q3map2/q3map2.h b/tools/quake3/q3map2/q3map2.h index f5ab7619..cf8eefd6 100644 --- a/tools/quake3/q3map2/q3map2.h +++ b/tools/quake3/q3map2/q3map2.h @@ -2179,7 +2179,7 @@ Q_EXTERN qboolean dark Q_ASSIGN( qfalse ); Q_EXTERN qboolean sunOnly Q_ASSIGN( qfalse ); Q_EXTERN int approximateTolerance Q_ASSIGN( 0 ); Q_EXTERN qboolean noCollapse Q_ASSIGN( qfalse ); -Q_EXTERN qboolean noLightmapSearch Q_ASSIGN( qfalse ); +Q_EXTERN int lightmapSearchBlockSize Q_ASSIGN( 0 ); Q_EXTERN qboolean exportLightmaps Q_ASSIGN( qfalse ); Q_EXTERN qboolean externalLightmaps Q_ASSIGN( qfalse ); Q_EXTERN int lmCustomSize Q_ASSIGN( LIGHTMAP_WIDTH ); -- 2.39.2