Remove COM_Parse, use parser_t

Game controls hull sizes now
This commit is contained in:
Jonathan 2021-09-20 19:45:09 -04:00
parent 9f1f575761
commit 2ebfdb096f
16 changed files with 102 additions and 127 deletions

View File

@ -28,11 +28,11 @@ set(COMMON_INCLUDES
${CMAKE_SOURCE_DIR}/include/common/mathlib.hh ${CMAKE_SOURCE_DIR}/include/common/mathlib.hh
${CMAKE_SOURCE_DIR}/include/common/polylib.hh ${CMAKE_SOURCE_DIR}/include/common/polylib.hh
${CMAKE_SOURCE_DIR}/include/common/threads.hh ${CMAKE_SOURCE_DIR}/include/common/threads.hh
${CMAKE_SOURCE_DIR}/include/common/bsputils.hh) ${CMAKE_SOURCE_DIR}/include/common/bsputils.hh
${CMAKE_SOURCE_DIR}/include/common/parser.hh)
set(QBSP_INCLUDES set(QBSP_INCLUDES
${CMAKE_SOURCE_DIR}/include/qbsp/file.hh ${CMAKE_SOURCE_DIR}/include/qbsp/file.hh
${CMAKE_SOURCE_DIR}/include/qbsp/parser.hh
${CMAKE_SOURCE_DIR}/include/qbsp/qbsp.hh ${CMAKE_SOURCE_DIR}/include/qbsp/qbsp.hh
${CMAKE_SOURCE_DIR}/include/qbsp/wad.hh ${CMAKE_SOURCE_DIR}/include/qbsp/wad.hh
${CMAKE_SOURCE_DIR}/include/qbsp/brush.hh ${CMAKE_SOURCE_DIR}/include/qbsp/brush.hh
@ -59,6 +59,7 @@ set(QBSP_SOURCES
${CMAKE_SOURCE_DIR}/common/mesh.cc ${CMAKE_SOURCE_DIR}/common/mesh.cc
${CMAKE_SOURCE_DIR}/common/mathlib.cc ${CMAKE_SOURCE_DIR}/common/mathlib.cc
${CMAKE_SOURCE_DIR}/common/bsputils.cc ${CMAKE_SOURCE_DIR}/common/bsputils.cc
${CMAKE_SOURCE_DIR}/common/parser.cc
${CMAKE_SOURCE_DIR}/qbsp/brush.cc ${CMAKE_SOURCE_DIR}/qbsp/brush.cc
${CMAKE_SOURCE_DIR}/qbsp/csg4.cc ${CMAKE_SOURCE_DIR}/qbsp/csg4.cc
${CMAKE_SOURCE_DIR}/qbsp/file.cc ${CMAKE_SOURCE_DIR}/qbsp/file.cc
@ -66,7 +67,6 @@ set(QBSP_SOURCES
${CMAKE_SOURCE_DIR}/qbsp/map.cc ${CMAKE_SOURCE_DIR}/qbsp/map.cc
${CMAKE_SOURCE_DIR}/qbsp/merge.cc ${CMAKE_SOURCE_DIR}/qbsp/merge.cc
${CMAKE_SOURCE_DIR}/qbsp/outside.cc ${CMAKE_SOURCE_DIR}/qbsp/outside.cc
${CMAKE_SOURCE_DIR}/qbsp/parser.cc
${CMAKE_SOURCE_DIR}/qbsp/portals.cc ${CMAKE_SOURCE_DIR}/qbsp/portals.cc
${CMAKE_SOURCE_DIR}/qbsp/qbsp.cc ${CMAKE_SOURCE_DIR}/qbsp/qbsp.cc
${CMAKE_SOURCE_DIR}/qbsp/solidbsp.cc ${CMAKE_SOURCE_DIR}/qbsp/solidbsp.cc

View File

@ -5,6 +5,7 @@ set(BSPINFO_SOURCES
${CMAKE_SOURCE_DIR}/common/bspfile.cc ${CMAKE_SOURCE_DIR}/common/bspfile.cc
${CMAKE_SOURCE_DIR}/common/log.cc ${CMAKE_SOURCE_DIR}/common/log.cc
${CMAKE_SOURCE_DIR}/common/threads.cc ${CMAKE_SOURCE_DIR}/common/threads.cc
${CMAKE_SOURCE_DIR}/common/parser.cc
${COMMON_INCLUDES}) ${COMMON_INCLUDES})
add_executable(bspinfo ${BSPINFO_SOURCES}) add_executable(bspinfo ${BSPINFO_SOURCES})

View File

@ -10,6 +10,7 @@ set(BSPUTIL_SOURCES
${CMAKE_SOURCE_DIR}/common/qvec.cc ${CMAKE_SOURCE_DIR}/common/qvec.cc
${CMAKE_SOURCE_DIR}/common/log.cc ${CMAKE_SOURCE_DIR}/common/log.cc
${CMAKE_SOURCE_DIR}/common/threads.cc ${CMAKE_SOURCE_DIR}/common/threads.cc
${CMAKE_SOURCE_DIR}/common/parser.cc
${COMMON_INCLUDES}) ${COMMON_INCLUDES})
add_executable(bsputil ${BSPUTIL_SOURCES}) add_executable(bsputil ${BSPUTIL_SOURCES})

View File

@ -131,88 +131,6 @@ void SetQdirFromPath(const std::string &basedirname, std::filesystem::path path)
} }
} }
/*
* ==============
* COM_Parse
* Parse a token out of a string
* ==============
*/
const char *COM_Parse(const char *data)
{
int c;
int len;
len = 0;
com_token[0] = 0;
if (!data)
return NULL;
/* skip whitespace */
skipwhite:
while ((c = *data) <= ' ') {
if (c == 0) {
com_eof = true;
return NULL; /* end of file; */
}
data++;
}
/* skip // (double forward slash) comments */
if (c == '/' && data[1] == '/') {
while (*data && *data != '\n')
data++;
goto skipwhite;
}
/* skip C-style comments */
if (c == '/' && data[1] == '*') {
data += 2;
while (*data && !(*data == '*' && data[1] == '/'))
data++;
if (*data)
data += 2;
goto skipwhite;
}
/* handle quoted strings specially */
if (c == '\"') {
data++;
do {
c = *data;
if (c)
data++;
if (c == '\"') {
com_token[len] = 0;
return data;
}
com_token[len] = c;
len++;
} while (1);
}
/* parse single characters */
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':') {
com_token[len] = c;
len++;
com_token[len] = 0;
return data + 1;
}
/* parse a regular word */
do {
com_token[len] = c;
data++;
len++;
c = *data;
if (c == '{' || c == '}' || c == ')' || c == '(' || c == '\'' || c == ':')
break;
} while (c > 32);
com_token[len] = 0;
return data;
}
int Q_strncasecmp(const char *s1, const char *s2, int n) int Q_strncasecmp(const char *s1, const char *s2, int n)
{ {
int c1, c2; int c1, c2;

View File

@ -27,6 +27,7 @@
#include <light/entities.hh> #include <light/entities.hh>
#include <light/ltface.hh> #include <light/ltface.hh>
#include <common/bsputils.hh> #include <common/bsputils.hh>
#include <common/parser.hh>
#include <fmt/ostream.h> #include <fmt/ostream.h>
@ -116,16 +117,15 @@ keyvalues_t::iterator entdict_t::end()
std::vector<entdict_t> EntData_Parse(const char *entdata) std::vector<entdict_t> EntData_Parse(const char *entdata)
{ {
std::vector<entdict_t> result; std::vector<entdict_t> result;
const char *data = entdata; parser_t parser(entdata);
/* go through all the entities */ /* go through all the entities */
while (1) { while (1) {
/* parse the opening brace */ /* parse the opening brace */
data = COM_Parse(data); if (!parser.parse_token())
if (!data)
break; break;
if (com_token[0] != '{') if (parser.token != "{")
FError("found {} when expecting {", com_token); FError("found {} when expecting {", parser.token);
/* Allocate a new entity */ /* Allocate a new entity */
entdict_t entity; entdict_t entity;
@ -133,30 +133,26 @@ std::vector<entdict_t> EntData_Parse(const char *entdata)
/* go through all the keys in this entity */ /* go through all the keys in this entity */
while (1) { while (1) {
/* parse key */ /* parse key */
data = COM_Parse(data); if (!parser.parse_token())
if (!data)
FError("EOF without closing brace"); FError("EOF without closing brace");
std::string keystr{com_token}; if (parser.token == "}")
if (keystr == "}")
break; break;
if (keystr.length() > MAX_ENT_KEY - 1) if (parser.token.length() > MAX_ENT_KEY - 1)
FError("Key length > {}: '{}'", MAX_ENT_KEY - 1, keystr); FError("Key length > {}: '{}'", MAX_ENT_KEY - 1, parser.token);
std::string keystr = parser.token;
/* parse value */ /* parse value */
data = COM_Parse(data); if (!parser.parse_token())
if (!data)
FError("EOF without closing brace"); FError("EOF without closing brace");
std::string valstring{com_token}; if (parser.token == "}")
if (valstring[0] == '}')
FError("closing brace without data"); FError("closing brace without data");
if (valstring.length() > MAX_ENT_VALUE - 1) if (parser.token.length() > MAX_ENT_VALUE - 1)
FError("Value length > {}", MAX_ENT_VALUE - 1); FError("Value length > {}", MAX_ENT_VALUE - 1);
entity.set(keystr, valstring); entity.set(keystr, parser.token);
} }
result.push_back(entity); result.push_back(entity);

View File

@ -20,7 +20,7 @@
*/ */
#include <qbsp/qbsp.hh> #include <qbsp/qbsp.hh>
#include <qbsp/parser.hh> #include <common/parser.hh>
bool parser_t::parse_token(parseflags flags) bool parser_t::parse_token(parseflags flags)
{ {

View File

@ -156,11 +156,6 @@ int LittleLong(int l);
float BigFloat(float l); float BigFloat(float l);
float LittleFloat(float l); float LittleFloat(float l);
const char *COM_Parse(const char *data);
extern char com_token[1024];
extern bool com_eof;
// temporary // temporary
#ifdef _WIN32 #ifdef _WIN32
#define copystring _strdup #define copystring _strdup

View File

@ -546,5 +546,54 @@ qmat4x4d inverse(const qmat4x4d &input);
qmat2x2f inverse(const qmat2x2f &input); qmat2x2f inverse(const qmat2x2f &input);
}; // namespace qv }; // namespace qv
// TODO: bounds type template<typename T>
using qboundsd = std::array<qvec3d, 2>; struct qbounds
{
using vec = qvec<3, T>;
vec mins, maxs;
// default constructor is an "empty" bounds
constexpr qbounds() :
mins(VECT_MAX, VECT_MAX, VECT_MAX),
maxs(-VECT_MAX, -VECT_MAX, -VECT_MAX)
{
}
// construct from mins/maxs
constexpr qbounds(const vec &mins, const vec &maxs) :
mins(mins),
maxs(maxs)
{
}
// add point to bounds
constexpr qbounds &operator+=(const vec &v)
{
mins = qv::min(mins, v);
maxs = qv::max(maxs, v);
return *this;
}
// add bounds to bounds
constexpr qbounds &operator+=(const qbounds &v)
{
mins = qv::min(mins, v.mins);
maxs = qv::max(maxs, v.maxs);
return *this;
}
constexpr vec &operator[](const int32_t &index)
{
return (index == 0 ? mins : index == 1 ? maxs : throw std::exception());
}
constexpr const vec &operator[](const int32_t &index) const
{
return (index == 0 ? mins : index == 1 ? maxs : throw std::exception());
}
};
using qboundsd = qbounds<double>;

View File

@ -21,7 +21,7 @@
#pragma once #pragma once
#include <qbsp/parser.hh> #include <common/parser.hh>
#include "common/cmdlib.hh" #include "common/cmdlib.hh"
#include <optional> #include <optional>

View File

@ -30,6 +30,7 @@ set(LIGHT_SOURCES
${CMAKE_SOURCE_DIR}/common/log.cc ${CMAKE_SOURCE_DIR}/common/log.cc
${CMAKE_SOURCE_DIR}/common/threads.cc ${CMAKE_SOURCE_DIR}/common/threads.cc
${CMAKE_SOURCE_DIR}/common/bsputils.cc ${CMAKE_SOURCE_DIR}/common/bsputils.cc
${CMAKE_SOURCE_DIR}/common/parser.cc
${COMMON_INCLUDES} ${COMMON_INCLUDES}
${LIGHT_INCLUDES}) ${LIGHT_INCLUDES})

View File

@ -21,6 +21,7 @@
#include <cstring> #include <cstring>
#include <fstream> #include <fstream>
#include <common/cmdlib.hh> #include <common/cmdlib.hh>
#include <common/parser.hh>
#include <light/light.hh> #include <light/light.hh>
#include <light/entities.hh> #include <light/entities.hh>
@ -1466,22 +1467,22 @@ bool ParseLightsFile(const std::filesystem::path &fname)
{ {
std::getline(f, buf); std::getline(f, buf);
const char *t = COM_Parse(buf.c_str()); parser_t parser(buf.c_str());
if (!t) if (!parser.parse_token())
continue; continue;
entdict_t d {}; entdict_t d {};
d.set("_surface", com_token); d.set("_surface", parser.token);
t = COM_Parse(t); parser.parse_token();
float r = atof(com_token); float r = std::stof(parser.token);
t = COM_Parse(t); parser.parse_token();
float g = atof(com_token); float g = std::stof(parser.token);
t = COM_Parse(t); parser.parse_token();
float b = atof(com_token); float b = std::stof(parser.token);
d.set("_color", fmt::format("{} {} {}", r, g, b)); d.set("_color", fmt::format("{} {} {}", r, g, b));
t = COM_Parse(t); parser.parse_token();
d.set("light", com_token); d.set("light", parser.token);
// might be hdr rgbi values here // might be hdr rgbi values here
radlights.push_back(d); radlights.push_back(d);

View File

@ -980,7 +980,7 @@ brush_t *LoadBrush(const mapentity_t *src, const mapbrush_t *mapbrush, const con
return NULL; return NULL;
} }
if (hullnum) { if (hullnum > 0) {
auto &hulls = options.target_game->get_hull_sizes(); auto &hulls = options.target_game->get_hull_sizes();
Q_assert(hullnum < hulls.size()); Q_assert(hullnum < hulls.size());
ExpandBrush(&hullbrush, *(hulls.begin() + hullnum), facelist); ExpandBrush(&hullbrush, *(hulls.begin() + hullnum), facelist);

View File

@ -33,7 +33,7 @@
#include <fmt/ostream.h> #include <fmt/ostream.h>
#include <qbsp/qbsp.hh> #include <qbsp/qbsp.hh>
#include <qbsp/parser.hh> #include <common/parser.hh>
#include <qbsp/wad.hh> #include <qbsp/wad.hh>
#include <common/qvec.hh> #include <common/qvec.hh>

View File

@ -480,7 +480,10 @@ static void UpdateEntLump(void)
UpdateBSPFileEntitiesLump(); UpdateBSPFileEntitiesLump();
if (!options.fAllverbose) if (!options.fAllverbose)
{
options.fVerbose = false; options.fVerbose = false;
log_mask &= ~((1 << LOG_STAT) | (1 << LOG_PROGRESS));
}
} }
/* /*
@ -709,7 +712,10 @@ static void CreateSingleHull(const int hullnum)
entity = &map.entities.at(i); entity = &map.entities.at(i);
ProcessEntity(entity, hullnum); ProcessEntity(entity, hullnum);
if (!options.fAllverbose) if (!options.fAllverbose)
{
options.fVerbose = false; // don't print rest of entities options.fVerbose = false; // don't print rest of entities
log_mask &= ~((1 << LOG_STAT) | (1 << LOG_PROGRESS));
}
} }
} }
@ -723,7 +729,10 @@ static void CreateHulls(void)
{ {
/* create the hulls sequentially */ /* create the hulls sequentially */
if (!options.fNoverbose) if (!options.fNoverbose)
options.fVerbose = true; {
options.fVerbose = true;
log_mask |= (1 << LOG_STAT) | (1 << LOG_PROGRESS);
}
auto &hulls = options.target_game->get_hull_sizes(); auto &hulls = options.target_game->get_hull_sizes();
@ -802,7 +811,10 @@ static void ProcessFile(void)
BeginBSPFile(); BeginBSPFile();
if (!options.fAllverbose) if (!options.fAllverbose)
{
options.fVerbose = false; options.fVerbose = false;
log_mask &= ~((1 << LOG_STAT) | (1 << LOG_PROGRESS));
}
CreateHulls(); CreateHulls();
WriteEntitiesToString(); WriteEntitiesToString();

View File

@ -18,6 +18,7 @@ set(VIS_SOURCES
${CMAKE_SOURCE_DIR}/common/bspfile.cc ${CMAKE_SOURCE_DIR}/common/bspfile.cc
${CMAKE_SOURCE_DIR}/common/log.cc ${CMAKE_SOURCE_DIR}/common/log.cc
${CMAKE_SOURCE_DIR}/common/threads.cc ${CMAKE_SOURCE_DIR}/common/threads.cc
${CMAKE_SOURCE_DIR}/common/parser.cc
${COMMON_INCLUDES} ${COMMON_INCLUDES}
${VIS_INCLUDES}) ${VIS_INCLUDES})