qbsp: fix -onlyents

This commit is contained in:
Eric Wasylishen 2021-08-31 23:53:40 -06:00
parent bc44af4d1d
commit 3cbf54749e
4 changed files with 35 additions and 8 deletions

View File

@ -744,7 +744,7 @@ DefaultExtension(char *path, const char *extension)
/* (extension should include the .) */ /* (extension should include the .) */
src = path + strlen(path) - 1; src = path + strlen(path) - 1;
while (*src != PATHSEPERATOR && src != path) { while (*src != PATHSEPERATOR && *src != '\\' && src != path) {
if (*src == '.') if (*src == '.')
return; /* it has an extension */ return; /* it has an extension */
src--; src--;
@ -784,7 +784,7 @@ StripExtension(char *path)
length = strlen(path) - 1; length = strlen(path) - 1;
while (length > 0 && path[length] != '.') { while (length > 0 && path[length] != '.') {
length--; length--;
if (path[length] == '/') if (path[length] == '/' || path[length] == '\\')
return; /* no extension */ return; /* no extension */
} }
if (length) if (length)
@ -799,7 +799,7 @@ StrippedExtension(const std::string& path) {
length = static_cast<int>(path.size()) - 1; length = static_cast<int>(path.size()) - 1;
while (length > 0 && path[length] != '.') { while (length > 0 && path[length] != '.') {
length--; length--;
if (path[length] == '/') if (path[length] == '/' || path[length] == '\\')
return path; /* no extension */ return path; /* no extension */
} }
if (length) if (length)
@ -842,9 +842,10 @@ ExtractFileBase(char *path, char *dest)
src = path + strlen(path) - 1; src = path + strlen(path) - 1;
/* back up until a \ or the start */ /* back up until a \ or the start */
while (src != path && *(src - 1) != PATHSEPERATOR) while (src != path && *(src - 1) != PATHSEPERATOR
&& *(src - 1) != '\\') {
src--; src--;
}
while (*src && *src != '.') { while (*src && *src != '.') {
*dest++ = *src++; *dest++ = *src++;
} }

View File

@ -27,5 +27,6 @@ int ExportMapTexinfo(int texinfonum);
void BeginBSPFile(void); void BeginBSPFile(void);
void FinishBSPFile(void); void FinishBSPFile(void);
void UpdateBSPFileEntitiesLump();
#endif #endif

View File

@ -302,9 +302,8 @@ UpdateEntLump(void)
FixRotateOrigin(entity); FixRotateOrigin(entity);
} }
//LoadBSPFile(); // FIXME: fix -onlyents
WriteEntitiesToString(); WriteEntitiesToString();
//WriteBSPFile(); // FIXME: fix -onlyents UpdateBSPFileEntitiesLump();
if (!options.fAllverbose) if (!options.fAllverbose)
options.fVerbose = false; options.fVerbose = false;

View File

@ -469,3 +469,29 @@ FinishBSPFile(void)
options.fVerbose = options.fAllverbose; options.fVerbose = options.fAllverbose;
} }
/*
==================
UpdateBSPFileEntitiesLump
==================
*/
void
UpdateBSPFileEntitiesLump()
{
bspdata_t bspdata;
StripExtension(options.szBSPName);
DefaultExtension(options.szBSPName, ".bsp");
// load the .bsp
LoadBSPFile(options.szBSPName, &bspdata);
ConvertBSPFormat(&bspdata, &bspver_generic);
// replace the existing entities lump with map.exported_entities
CopyString(map.exported_entities, true, &bspdata.data.mbsp.entdatasize, (void**)&bspdata.data.mbsp.dentdata);
// write the .bsp back to disk
ConvertBSPFormat(&bspdata, bspdata.loadversion);
WriteBSPFile(options.szBSPName, &bspdata);
logprint("Wrote %s\n", options.szBSPName);
}