Add support for external entity files (.ent files).

This was ported from KMQ2.
This commit is contained in:
NeonKnightOA 2018-09-23 19:40:03 -03:00 committed by Yamagi Burmeister
parent 08037e7328
commit d036868600
3 changed files with 55 additions and 3 deletions

View file

@ -1610,16 +1610,60 @@ CMod_LoadVisibility(lump_t *l)
} }
void void
CMod_LoadEntityString(lump_t *l) CMod_LoadEntityString(lump_t *l, char *name)
{ {
/*
* Port from Knightmare's kmquake2: support for .ent files.
*/
if (sv_entfile->value)
{
char s[MAX_QPATH];
char *buffer = NULL;
int nameLen, bufLen;
nameLen = strlen(name);
strcpy(s, name);
s[nameLen-3] = 'e'; s[nameLen-2] = 'n'; s[nameLen-1] = 't';
bufLen = FS_LoadFile (s, (void **)&buffer);
if (buffer != NULL && bufLen > 1)
{
if (bufLen + 1 > sizeof(map_entitystring)) /* jit fix */
{
Com_Printf ("CMod_LoadEntityString: .ent file %s too large: %i > %i.\n", s, bufLen, sizeof(map_entitystring));
FS_FreeFile (buffer);
}
else
{
Com_Printf ("CMod_LoadEntityString: .ent file %s loaded.\n", s);
numentitychars = bufLen;
memcpy (map_entitystring, buffer, bufLen);
map_entitystring[bufLen] = 0; /* jit entity bug - null terminate the entity string! */
FS_FreeFile (buffer);
return;
}
}
/* If the .ent file is too small, don't load. */
else if (bufLen != -1)
{
Com_Printf ("CMod_LoadEntityString: .ent file %s too small.\n", s);
FS_FreeFile (buffer);
}
/* Fall back to bsp entity string if no .ent file loaded */
}
/*
* End of the kmquake2 .ent file support port.
*/
numentitychars = l->filelen; numentitychars = l->filelen;
if (l->filelen > MAX_MAP_ENTSTRING) /* if (l->filelen > MAX_MAP_ENTSTRING) */
if (l->filelen + 1 > sizeof(map_entitystring)) /* jit fix */
{ {
Com_Error(ERR_DROP, "Map has too large entity lump"); Com_Error(ERR_DROP, "Map has too large entity lump");
} }
memcpy(map_entitystring, cmod_base + l->fileofs, l->filelen); memcpy(map_entitystring, cmod_base + l->fileofs, l->filelen);
map_entitystring[l->filelen] = 0; /* jit entity bug - null terminate the entity string! */
} }
/* /*
@ -1707,7 +1751,8 @@ CM_LoadMap(char *name, qboolean clientload, unsigned *checksum)
CMod_LoadAreas(&header.lumps[LUMP_AREAS]); CMod_LoadAreas(&header.lumps[LUMP_AREAS]);
CMod_LoadAreaPortals(&header.lumps[LUMP_AREAPORTALS]); CMod_LoadAreaPortals(&header.lumps[LUMP_AREAPORTALS]);
CMod_LoadVisibility(&header.lumps[LUMP_VISIBILITY]); CMod_LoadVisibility(&header.lumps[LUMP_VISIBILITY]);
CMod_LoadEntityString(&header.lumps[LUMP_ENTITIES]); /* From kmquake2: adding an extra parameter for .ent support. */
CMod_LoadEntityString(&header.lumps[LUMP_ENTITIES], name);
FS_FreeFile(buf); FS_FreeFile(buf);

View file

@ -720,6 +720,9 @@ extern cvar_t *dedicated;
extern cvar_t *host_speeds; extern cvar_t *host_speeds;
extern cvar_t *log_stats; extern cvar_t *log_stats;
/* Ported from kmquake2: .ent file support - whether to use .ent file or not */
extern cvar_t *sv_entfile;
/* Hack for portable client */ /* Hack for portable client */
extern qboolean is_portable; extern qboolean is_portable;

View file

@ -49,6 +49,7 @@ cvar_t *maxclients; /* rename sv_maxclients */
cvar_t *sv_showclamp; cvar_t *sv_showclamp;
cvar_t *hostname; cvar_t *hostname;
cvar_t *public_server; /* should heartbeats be sent */ cvar_t *public_server; /* should heartbeats be sent */
cvar_t *sv_entfile; /* From kmquake2: whether to use .ent file */
void Master_Shutdown(void); void Master_Shutdown(void);
void SV_ConnectionlessPacket(void); void SV_ConnectionlessPacket(void);
@ -609,6 +610,9 @@ SV_Init(void)
public_server = Cvar_Get("public", "0", 0); public_server = Cvar_Get("public", "0", 0);
/* From kmquake2: whether to use .ent file. */
sv_entfile = Cvar_Get("sv_entfile", "1", CVAR_ARCHIVE);
SZ_Init(&net_message, net_message_buffer, sizeof(net_message_buffer)); SZ_Init(&net_message, net_message_buffer, sizeof(net_message_buffer));
} }