Skip to content

Commit 895cb2c

Browse files
authored
load entities string from an optional file maps/<map>.ent
1 parent 2a353e5 commit 895cb2c

2 files changed

Lines changed: 53 additions & 11 deletions

File tree

src/common/cm/cm_load.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -514,16 +514,26 @@ static void CMod_LoadBrushSides(const byte *const cmod_base, const lump_t *l)
514514
CMod_LoadEntityString
515515
=================
516516
*/
517-
static void CMod_LoadEntityString(const byte *const cmod_base, const lump_t *l)
517+
static void CMod_LoadEntityString(const byte *const cmod_base, const lump_t *l, std::string &externalEntities)
518518
{
519519
const char *p, *token;
520520
char keyname[ MAX_TOKEN_CHARS ];
521521
char value[ MAX_TOKEN_CHARS ];
522522

523-
cm.entityString = ( char * ) CM_Alloc( l->filelen + 1);
524-
cm.numEntityChars = l->filelen;
525-
memcpy( cm.entityString, cmod_base + l->fileofs, l->filelen );
526-
cm.entityString[l->filelen] = '\0';
523+
if ( externalEntities.empty() )
524+
{
525+
cm.entityString = ( char * ) CM_Alloc( l->filelen + 1);
526+
cm.numEntityChars = l->filelen;
527+
memcpy( cm.entityString, cmod_base + l->fileofs, l->filelen );
528+
cm.entityString[l->filelen] = '\0';
529+
}
530+
else
531+
{
532+
int len = externalEntities.length();
533+
cm.entityString = ( char * ) CM_Alloc( len + 1 );
534+
cm.numEntityChars = len;
535+
memcpy( cm.entityString, externalEntities.c_str(), len + 1 );
536+
}
527537

528538
p = cm.entityString;
529539

@@ -764,6 +774,17 @@ void CM_LoadMap(Str::StringRef name)
764774
Sys::Drop("Could not load %s", mapFile.c_str());
765775
}
766776

777+
std::string externalEntities = FS::PakPath::ReadFile( "maps/" + name + ".ent", err );
778+
if ( err )
779+
{
780+
const std::error_code notFound( Util::ordinal( FS::filesystem_error::no_such_file ), FS::filesystem_category() );
781+
if ( err != notFound )
782+
{
783+
Sys::Drop( "Could not read file 'maps/%s.ent': %s", name.c_str(), err.message() );
784+
}
785+
externalEntities = "";
786+
}
787+
767788
// clear collision map data
768789
CM_ClearMap();
769790

@@ -801,7 +822,7 @@ void CM_LoadMap(Str::StringRef name)
801822
CMod_LoadBrushes(cmod_base, &header.lumps[LUMP_BRUSHES]);
802823
CMod_LoadSubmodels(cmod_base, &header.lumps[LUMP_MODELS]);
803824
CMod_LoadNodes(cmod_base, &header.lumps[LUMP_NODES]);
804-
CMod_LoadEntityString(cmod_base, &header.lumps[LUMP_ENTITIES]);
825+
CMod_LoadEntityString(cmod_base, &header.lumps[LUMP_ENTITIES], externalEntities);
805826
CMod_LoadVisibility(cmod_base, &header.lumps[LUMP_VISIBILITY]);
806827
CMod_LoadSurfaces(cmod_base,
807828
&header.lumps[LUMP_SURFACES], &header.lumps[LUMP_DRAWVERTS], &header.lumps[LUMP_DRAWINDEXES]);

src/engine/renderer/tr_bsp.cpp

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4281,7 +4281,7 @@ void R_LoadLightGrid( lump_t *l )
42814281
R_LoadEntities
42824282
================
42834283
*/
4284-
void R_LoadEntities( lump_t *l )
4284+
void R_LoadEntities( lump_t *l, std::string &externalEntities )
42854285
{
42864286
int i;
42874287
const char *p, *pOld, *token;
@@ -4305,9 +4305,18 @@ void R_LoadEntities( lump_t *l )
43054305
w->lightGridSize[ 2 ] = 128;
43064306

43074307
// store for reference by the cgame
4308-
w->entityString = (char*) ri.Hunk_Alloc( l->filelen + 1, ha_pref::h_low );
4309-
//strcpy(w->entityString, (char *)(fileBase + l->fileofs));
4310-
Q_strncpyz( w->entityString, ( char * )( fileBase + l->fileofs ), l->filelen + 1 );
4308+
if ( externalEntities.empty() )
4309+
{
4310+
w->entityString = (char*) ri.Hunk_Alloc( l->filelen + 1, ha_pref::h_low );
4311+
//strcpy(w->entityString, (char *)(fileBase + l->fileofs));
4312+
Q_strncpyz( w->entityString, ( char * )( fileBase + l->fileofs ), l->filelen + 1 );
4313+
}
4314+
else
4315+
{
4316+
w->entityString = (char*) ri.Hunk_Alloc( externalEntities.length() + 1, ha_pref::h_low );
4317+
Q_strncpyz( w->entityString, externalEntities.c_str(), externalEntities.length() + 1 );
4318+
}
4319+
43114320
w->entityParsePoint = w->entityString;
43124321

43134322
p = w->entityString;
@@ -6942,7 +6951,19 @@ void RE_LoadWorldMap( const char *name )
69426951
}
69436952

69446953
// load into heap
6945-
R_LoadEntities( &header->lumps[ LUMP_ENTITIES ] );
6954+
6955+
std::string externalEntitiesFileName = FS::Path::StripExtension( name ) + ".ent";
6956+
std::string externalEntities = FS::PakPath::ReadFile( externalEntitiesFileName, err );
6957+
if ( err )
6958+
{
6959+
const std::error_code notFound( Util::ordinal( FS::filesystem_error::no_such_file ), FS::filesystem_category() );
6960+
if ( err != notFound )
6961+
{
6962+
Sys::Drop( "Could not read file '%s': %s", externalEntitiesFileName.c_str(), err.message() );
6963+
}
6964+
externalEntities = "";
6965+
}
6966+
R_LoadEntities( &header->lumps[ LUMP_ENTITIES ], externalEntities );
69466967

69476968
R_LoadShaders( &header->lumps[ LUMP_SHADERS ] );
69486969

0 commit comments

Comments
 (0)