From 9525dc35a88250fecf01d51775a0c64857edaa86 Mon Sep 17 00:00:00 2001 From: Yamagi Burmeister Date: Sun, 7 Oct 2018 09:43:19 +0200 Subject: [PATCH] Some small cleanups to entity file support. - Fix some compiler warning about wrong format strings. - Comply to code style. - Remove unnecessary comments. --- src/common/collision.c | 37 +++++++++++++++---------------------- src/common/header/common.h | 2 +- src/server/sv_main.c | 3 +-- 3 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/common/collision.c b/src/common/collision.c index 61d07faf..5a239e32 100644 --- a/src/common/collision.c +++ b/src/common/collision.c @@ -1612,58 +1612,51 @@ CMod_LoadVisibility(lump_t *l) void 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; + 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); + bufLen = FS_LoadFile(s, (void **)&buffer); + if (buffer != NULL && bufLen > 1) { - if (bufLen + 1 > sizeof(map_entitystring)) /* jit fix */ + if (bufLen + 1 > sizeof(map_entitystring)) { - Com_Printf ("CMod_LoadEntityString: .ent file %s too large: %i > %i.\n", s, bufLen, sizeof(map_entitystring)); - FS_FreeFile (buffer); + Com_Printf("CMod_LoadEntityString: .ent file %s too large: %i > %lu.\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); + memcpy(map_entitystring, buffer, bufLen); map_entitystring[bufLen] = 0; /* jit entity bug - null terminate the entity string! */ - FS_FreeFile (buffer); + 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); + /* If the .ent file is too small, don't load. */ + 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; - /* if (l->filelen > MAX_MAP_ENTSTRING) */ - if (l->filelen + 1 > sizeof(map_entitystring)) /* jit fix */ + if (l->filelen + 1 > sizeof(map_entitystring)) { Com_Error(ERR_DROP, "Map has too large entity lump"); } memcpy(map_entitystring, cmod_base + l->fileofs, l->filelen); - map_entitystring[l->filelen] = 0; /* jit entity bug - null terminate the entity string! */ + map_entitystring[l->filelen] = 0; } /* diff --git a/src/common/header/common.h b/src/common/header/common.h index 672c4de2..4cd3094b 100644 --- a/src/common/header/common.h +++ b/src/common/header/common.h @@ -720,7 +720,7 @@ extern cvar_t *dedicated; extern cvar_t *host_speeds; extern cvar_t *log_stats; -/* Ported from kmquake2: .ent file support - whether to use .ent file or not */ +/* External entity files. */ extern cvar_t *sv_entfile; /* Hack for portable client */ diff --git a/src/server/sv_main.c b/src/server/sv_main.c index 584bbfac..85b7448f 100644 --- a/src/server/sv_main.c +++ b/src/server/sv_main.c @@ -49,7 +49,7 @@ cvar_t *maxclients; /* rename sv_maxclients */ cvar_t *sv_showclamp; cvar_t *hostname; cvar_t *public_server; /* should heartbeats be sent */ -cvar_t *sv_entfile; /* From kmquake2: whether to use .ent file */ +cvar_t *sv_entfile; /* External entity files. */ void Master_Shutdown(void); void SV_ConnectionlessPacket(void); @@ -610,7 +610,6 @@ SV_Init(void) 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));