@@ -31,8 +31,9 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31
31
========================================================
32
32
Loads and prepares a map file for scene rendering.
33
33
34
- A single entry point:
35
- RE_LoadWorldMap(const char *name);
34
+ Two entry points, to be called in this order:
35
+ RE_LoadWorldSpawn(const std::string worldName);
36
+ RE_LoadWorldData();
36
37
========================================================
37
38
*/
38
39
@@ -411,11 +412,11 @@ static void LoadRGBEToBytes( const char *name, byte **ldrImage, int *width, int
411
412
Z_Free ( hdrImage );
412
413
}
413
414
414
- static std::vector<std::string> R_LoadExternalLightmaps ( const char *mapName )
415
+ static std::vector<std::string> R_LoadExternalLightmaps ( std::string worldName )
415
416
{
416
417
const char *const extensions[] {" .png" , " .tga" , " .webp" , " .crn" , " .jpg" , " .jpeg" };
417
418
std::vector<std::string> files[ ARRAY_LEN ( extensions ) ];
418
- for ( const std::string& filename : FS::PakPath::ListFiles ( mapName ) ) {
419
+ for ( const std::string& filename : FS::PakPath::ListFiles ( worldName ) ) {
419
420
for ( size_t i = 0 ; i < ARRAY_LEN ( extensions ); i++ )
420
421
{
421
422
if ( Str::IsISuffix ( extensions[ i ], filename ) )
@@ -440,7 +441,7 @@ static std::vector<std::string> R_LoadExternalLightmaps( const char *mapName )
440
441
R_LoadLightmaps
441
442
===============
442
443
*/
443
- static void R_LoadLightmaps ( lump_t *l, const char *bspName )
444
+ static void R_LoadLightmaps ( lump_t *l, std::string worldName )
444
445
{
445
446
tr.worldLightMapping = r_precomputedLighting->integer && tr.lightMode == lightMode_t::MAP;
446
447
@@ -454,11 +455,6 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
454
455
int len = l->filelen ;
455
456
if ( !len )
456
457
{
457
- char mapName[ MAX_QPATH ];
458
-
459
- Q_strncpyz ( mapName, bspName, sizeof ( mapName ) );
460
- COM_StripExtension3 ( mapName, mapName, sizeof ( mapName ) );
461
-
462
458
if ( tr.worldHDR_RGBE )
463
459
{
464
460
// we are about to upload textures
@@ -469,7 +465,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
469
465
byte *ldrImage;
470
466
471
467
std::vector<std::string> hdrFiles;
472
- for ( const std::string& filename : FS::PakPath::ListFiles ( mapName ) )
468
+ for ( const std::string& filename : FS::PakPath::ListFiles ( worldName ) )
473
469
{
474
470
if ( Str::IsISuffix ( " .hdr" , filename ) )
475
471
{
@@ -487,17 +483,17 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
487
483
488
484
for ( const std::string& filename : hdrFiles )
489
485
{
490
- Log::Debug (" ...loading external lightmap as RGB8 LDR '%s/%s'" , mapName , filename );
486
+ Log::Debug (" ...loading external lightmap as RGB8 LDR '%s/%s'" , worldName , filename );
491
487
492
488
width = height = 0 ;
493
- LoadRGBEToBytes ( va ( " %s/%s" , mapName , filename.c_str () ), &ldrImage, &width, &height );
489
+ LoadRGBEToBytes ( va ( " %s/%s" , worldName. c_str () , filename.c_str () ), &ldrImage, &width, &height );
494
490
495
491
imageParams_t imageParams = {};
496
492
imageParams.bits = IF_NOPICMIP | IF_LIGHTMAP;
497
493
imageParams.filterType = filterType_t::FT_DEFAULT;
498
494
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
499
495
500
- auto image = R_CreateImage ( va ( " %s/%s" , mapName , filename.c_str () ), (const byte **)&ldrImage, width, height, 1 , imageParams );
496
+ auto image = R_CreateImage ( va ( " %s/%s" , worldName. c_str () , filename.c_str () ), (const byte **)&ldrImage, width, height, 1 , imageParams );
501
497
502
498
tr.lightmaps .push_back ( image );
503
499
@@ -506,7 +502,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
506
502
507
503
if (tr.worldDeluxeMapping ) {
508
504
// load deluxemaps
509
- std::vector<std::string> lightmapFiles = R_LoadExternalLightmaps (mapName );
505
+ std::vector<std::string> lightmapFiles = R_LoadExternalLightmaps ( worldName );
510
506
if (lightmapFiles.empty ()) {
511
507
Log::Warn (" no lightmap files found" );
512
508
tr.worldLightMapping = false ;
@@ -517,21 +513,21 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
517
513
Log::Debug (" ...loading %i deluxemaps" , lightmapFiles.size ());
518
514
519
515
for (const std::string& filename : lightmapFiles) {
520
- Log::Debug (" ...loading external lightmap '%s/%s'" , mapName , filename);
516
+ Log::Debug (" ...loading external lightmap '%s/%s'" , worldName. c_str () , filename);
521
517
522
518
imageParams_t imageParams = {};
523
519
imageParams.bits = IF_NOPICMIP | IF_NORMALMAP;
524
520
imageParams.filterType = filterType_t::FT_DEFAULT;
525
521
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
526
522
527
- auto image = R_FindImageFile (va (" %s/%s" , mapName , filename.c_str ()), imageParams);
523
+ auto image = R_FindImageFile (va (" %s/%s" , worldName. c_str () , filename.c_str ()), imageParams);
528
524
tr.deluxemaps .push_back (image);
529
525
}
530
526
}
531
527
}
532
528
else
533
529
{
534
- std::vector<std::string> lightmapFiles = R_LoadExternalLightmaps (mapName );
530
+ std::vector<std::string> lightmapFiles = R_LoadExternalLightmaps ( worldName );
535
531
if (lightmapFiles.empty ()) {
536
532
Log::Warn (" no lightmap files found" );
537
533
tr.worldLightMapping = false ;
@@ -545,15 +541,15 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
545
541
R_SyncRenderThread ();
546
542
547
543
for (size_t i = 0 ; i < lightmapFiles.size (); i++) {
548
- Log::Debug (" ...loading external lightmap '%s/%s'" , mapName , lightmapFiles[i]);
544
+ Log::Debug (" ...loading external lightmap '%s/%s'" , worldName. c_str () , lightmapFiles[i]);
549
545
550
546
if (!tr.worldDeluxeMapping || i % 2 == 0 ) {
551
547
imageParams_t imageParams = {};
552
548
imageParams.bits = IF_NOPICMIP | IF_LIGHTMAP;
553
549
imageParams.filterType = filterType_t::FT_LINEAR;
554
550
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
555
551
556
- auto image = R_FindImageFile (va (" %s/%s" , mapName , lightmapFiles[i].c_str ()), imageParams);
552
+ auto image = R_FindImageFile (va (" %s/%s" , worldName. c_str () , lightmapFiles[i].c_str ()), imageParams);
557
553
tr.lightmaps .push_back (image);
558
554
}
559
555
else if (tr.worldDeluxeMapping )
@@ -563,7 +559,7 @@ static void R_LoadLightmaps( lump_t *l, const char *bspName )
563
559
imageParams.filterType = filterType_t::FT_LINEAR;
564
560
imageParams.wrapType = wrapTypeEnum_t::WT_CLAMP;
565
561
566
- auto image = R_FindImageFile (va (" %s/%s" , mapName , lightmapFiles[i].c_str ()), imageParams);
562
+ auto image = R_FindImageFile (va (" %s/%s" , worldName. c_str () , lightmapFiles[i].c_str ()), imageParams);
567
563
tr.deluxemaps .push_back ( image );
568
564
}
569
565
}
@@ -4465,25 +4461,24 @@ static void SetWorldLight() {
4465
4461
}
4466
4462
}
4467
4463
4468
- /*
4469
- =================
4470
- RE_LoadWorldMap
4464
+ std::string worldName;
4465
+ std::string bspBuffer;
4466
+ dheader_t *bspHeader;
4467
+ byte *bspStartMarker;
4471
4468
4472
- Called directly from cgame
4473
- =================
4474
- */
4475
- void RE_LoadWorldMap ( const char *name )
4469
+ // Called directly from cgame.
4470
+ void RE_LoadWorldSpawn ( const std::string name )
4476
4471
{
4477
- int i ;
4478
- dheader_t *header;
4479
- byte *startMarker ;
4472
+ worldName = name ;
4473
+
4474
+ Log::Debug ( " ----- RE_LoadWorldSpawn( %s ) ----- " , worldName ) ;
4480
4475
4481
4476
if ( tr.worldMapLoaded )
4482
4477
{
4483
4478
Sys::Drop ( " ERROR: attempted to redundantly load world map" );
4484
4479
}
4485
4480
4486
- Log::Debug ( " ----- RE_LoadWorldMap( %s ) ----- " , name ) ;
4481
+ tr. worldMapLoaded = true ;
4487
4482
4488
4483
// set default sun direction to be used if it isn't
4489
4484
// overridden by a shader
@@ -4493,17 +4488,19 @@ void RE_LoadWorldMap( const char *name )
4493
4488
4494
4489
VectorNormalize ( tr.sunDirection );
4495
4490
4496
- tr. worldMapLoaded = true ;
4491
+ std::string bspName = name + " .bsp " ;
4497
4492
4498
4493
// load it
4499
4494
std::error_code err;
4500
- std::string buffer = FS::PakPath::ReadFile ( name , err );
4495
+ bspBuffer = FS::PakPath::ReadFile ( bspName , err );
4501
4496
4502
4497
if ( err )
4503
4498
{
4504
- Sys::Drop ( " RE_LoadWorldMap : %s not found" , name );
4499
+ Sys::Drop ( " RE_LoadWorldSpawn : %s not found" , bspName );
4505
4500
}
4506
4501
4502
+ Log::Debug ( " Loading %s…" , bspName );
4503
+
4507
4504
// clear tr.world so if the level fails to load, the next
4508
4505
// try will not look at the partially loaded version
4509
4506
tr.world = nullptr ;
@@ -4514,45 +4511,45 @@ void RE_LoadWorldMap( const char *name )
4514
4511
tr.worldDeluxeMapping = false ; // set by R_LoadEntities
4515
4512
tr.worldHDR_RGBE = false ; // set by R_LoadEntities
4516
4513
tr.mapOverBrightBits = r_overbrightDefaultExponent.Get (); // maybe set by R_LoadEntities
4517
- tr.overbrightBits = std::min ( tr.mapOverBrightBits , r_overbrightBits.Get () ); // set by RE_LoadWorldMap
4518
- tr.mapLightFactor = 1 .0f ; // set by RE_LoadWorldMap
4519
- tr.identityLight = 1 .0f ; // set by RE_LoadWorldMap
4514
+ tr.overbrightBits = std::min ( tr.mapOverBrightBits , r_overbrightBits.Get () ); // set by RE_LoadWorldSpawn
4515
+ tr.mapLightFactor = 1 .0f ; // set by RE_LoadWorldSpawn
4516
+ tr.identityLight = 1 .0f ; // set by RE_LoadWorldSpawn
4520
4517
4521
4518
s_worldData = {};
4522
- Q_strncpyz ( s_worldData.name , name , sizeof ( s_worldData.name ) );
4519
+ Q_strncpyz ( s_worldData.name , bspName. c_str () , sizeof ( s_worldData.name ) );
4523
4520
4524
4521
Q_strncpyz ( s_worldData.baseName , COM_SkipPath ( s_worldData.name ), sizeof ( s_worldData.name ) );
4525
4522
COM_StripExtension3 ( s_worldData.baseName , s_worldData.baseName , sizeof ( s_worldData.baseName ) );
4526
4523
tr.loadingMap = s_worldData.baseName ;
4527
4524
4528
- startMarker = (byte*) ri.Hunk_Alloc ( 0 , ha_pref::h_low );
4525
+ bspStartMarker = (byte*) ri.Hunk_Alloc ( 0 , ha_pref::h_low );
4529
4526
4530
- header = ( dheader_t * ) buffer .data ();
4531
- fileBase = ( byte * ) header ;
4527
+ bspHeader = ( dheader_t * ) bspBuffer .data ();
4528
+ fileBase = ( byte * ) bspHeader ;
4532
4529
4533
- i = LittleLong ( header ->version );
4530
+ int i = LittleLong ( bspHeader ->version );
4534
4531
4535
4532
if ( i != BSP_VERSION && i != BSP_VERSION_Q3 )
4536
4533
{
4537
- Sys::Drop ( " RE_LoadWorldMap : %s has wrong version number (%i should be %i for ET or %i for Q3)" ,
4538
- name , i, BSP_VERSION, BSP_VERSION_Q3 );
4534
+ Sys::Drop ( " RE_LoadWorldSpawn : %s has wrong version number (%i should be %i for ET or %i for Q3)" ,
4535
+ bspName , i, BSP_VERSION, BSP_VERSION_Q3 );
4539
4536
}
4540
4537
4541
4538
// swap all the lumps
4542
4539
for ( unsigned j = 0 ; j < sizeof ( dheader_t ) / 4 ; j++ )
4543
4540
{
4544
- ( ( int * ) header ) [ j ] = LittleLong ( ( ( int * ) header ) [ j ] );
4541
+ ( ( int * ) bspHeader ) [ j ] = LittleLong ( ( ( int * ) bspHeader ) [ j ] );
4545
4542
}
4546
4543
4547
4544
if ( glConfig2.reflectionMappingAvailable ) {
4548
4545
// TODO: Take into account potential shader changes
4549
- headerString = Str::Format ( " %i %i %i %i %i" , header ->lumps [LUMP_PLANES].filelen , header ->lumps [LUMP_NODES].filelen ,
4550
- header ->lumps [LUMP_LEAFS].filelen , header ->lumps [LUMP_BRUSHES].filelen , header ->lumps [LUMP_SURFACES].filelen );
4546
+ headerString = Str::Format ( " %i %i %i %i %i" , bspHeader ->lumps [LUMP_PLANES].filelen , bspHeader ->lumps [LUMP_NODES].filelen ,
4547
+ bspHeader ->lumps [LUMP_LEAFS].filelen , bspHeader ->lumps [LUMP_BRUSHES].filelen , bspHeader ->lumps [LUMP_SURFACES].filelen );
4551
4548
}
4552
4549
4553
4550
// load into heap
4554
4551
4555
- std::string externalEntitiesFileName = FS::Path::StripExtension ( name ) + " .ent" ;
4552
+ std::string externalEntitiesFileName = worldName + " .ent" ;
4556
4553
std::string externalEntities = FS::PakPath::ReadFile ( externalEntitiesFileName, err );
4557
4554
if ( err )
4558
4555
{
@@ -4563,31 +4560,36 @@ void RE_LoadWorldMap( const char *name )
4563
4560
}
4564
4561
externalEntities = " " ;
4565
4562
}
4566
- R_LoadEntities ( &header ->lumps [ LUMP_ENTITIES ], externalEntities );
4563
+ R_LoadEntities ( &bspHeader ->lumps [ LUMP_ENTITIES ], externalEntities );
4567
4564
4568
4565
// Now we can set this after checking a possible worldspawn value for mapOverbrightBits
4569
4566
tr.overbrightBits = std::min ( tr.mapOverBrightBits , r_overbrightBits.Get () );
4567
+ }
4570
4568
4571
- R_LoadShaders ( &header->lumps [ LUMP_SHADERS ] );
4569
+ // Called directly from cgame.
4570
+ // Should be called after RE_LoadWorldSpawn().
4571
+ void RE_LoadWorldData ()
4572
+ {
4573
+ R_LoadShaders ( &bspHeader->lumps [ LUMP_SHADERS ] );
4572
4574
4573
- R_LoadLightmaps ( &header ->lumps [ LUMP_LIGHTMAPS ], name );
4575
+ R_LoadLightmaps ( &bspHeader ->lumps [ LUMP_LIGHTMAPS ], worldName );
4574
4576
4575
- R_LoadPlanes ( &header ->lumps [ LUMP_PLANES ] );
4577
+ R_LoadPlanes ( &bspHeader ->lumps [ LUMP_PLANES ] );
4576
4578
4577
- R_LoadSurfaces ( &header ->lumps [ LUMP_SURFACES ], &header ->lumps [ LUMP_DRAWVERTS ], &header ->lumps [ LUMP_DRAWINDEXES ] );
4579
+ R_LoadSurfaces ( &bspHeader ->lumps [ LUMP_SURFACES ], &bspHeader ->lumps [ LUMP_DRAWVERTS ], &bspHeader ->lumps [ LUMP_DRAWINDEXES ] );
4578
4580
4579
- R_LoadMarksurfaces ( &header ->lumps [ LUMP_LEAFSURFACES ] );
4581
+ R_LoadMarksurfaces ( &bspHeader ->lumps [ LUMP_LEAFSURFACES ] );
4580
4582
4581
- R_LoadNodesAndLeafs ( &header ->lumps [ LUMP_NODES ], &header ->lumps [ LUMP_LEAFS ] );
4583
+ R_LoadNodesAndLeafs ( &bspHeader ->lumps [ LUMP_NODES ], &bspHeader ->lumps [ LUMP_LEAFS ] );
4582
4584
4583
- R_LoadSubmodels ( &header ->lumps [ LUMP_MODELS ] );
4585
+ R_LoadSubmodels ( &bspHeader ->lumps [ LUMP_MODELS ] );
4584
4586
4585
4587
// moved fog lump loading here, so fogs can be tagged with a model num
4586
- R_LoadFogs ( &header ->lumps [ LUMP_FOGS ], &header ->lumps [ LUMP_BRUSHES ], &header ->lumps [ LUMP_BRUSHSIDES ] );
4588
+ R_LoadFogs ( &bspHeader ->lumps [ LUMP_FOGS ], &bspHeader ->lumps [ LUMP_BRUSHES ], &bspHeader ->lumps [ LUMP_BRUSHSIDES ] );
4587
4589
4588
- R_LoadVisibility ( &header ->lumps [ LUMP_VISIBILITY ] );
4590
+ R_LoadVisibility ( &bspHeader ->lumps [ LUMP_VISIBILITY ] );
4589
4591
4590
- R_LoadLightGrid ( &header ->lumps [ LUMP_LIGHTGRID ] );
4592
+ R_LoadLightGrid ( &bspHeader ->lumps [ LUMP_LIGHTGRID ] );
4591
4593
4592
4594
// create a static vbo for the world
4593
4595
// Do SetWorldLight() before R_CreateWorldVBO(), because the latter will use the world light values to generate materials
@@ -4600,7 +4602,7 @@ void RE_LoadWorldMap( const char *name )
4600
4602
FinishSkybox ();
4601
4603
}
4602
4604
4603
- s_worldData.dataSize = ( byte * ) ri.Hunk_Alloc ( 0 , ha_pref::h_low ) - startMarker ;
4605
+ s_worldData.dataSize = ( byte * ) ri.Hunk_Alloc ( 0 , ha_pref::h_low ) - bspStartMarker ;
4604
4606
// only set tr.world now that we know the entire level has loaded properly
4605
4607
tr.world = &s_worldData;
4606
4608
0 commit comments