allow radlights to specify an entity dictionary instead (if the input is a .ent, it is an entity dict) which is more flexible

This commit is contained in:
Jonathan 2022-06-22 17:03:00 -04:00
parent 383843a454
commit cb3ef7b19f
6 changed files with 40 additions and 21 deletions

View File

@ -173,14 +173,9 @@ void entdict_t::parse(parser_base_t &parser)
}
}
/*
* ==================
* EntData_Parse
* ==================
*/
std::vector<entdict_t> EntData_Parse(const std::string &entdata)
void EntData_ParseInto(const std::string &entdata, std::vector<entdict_t> &vector)
{
std::vector<entdict_t> result;
parser_t parser(entdata);
/* go through all the entities */
@ -190,8 +185,20 @@ std::vector<entdict_t> EntData_Parse(const std::string &entdata)
break;
// emplace a new entdict_t out of the parser
result.emplace_back(parser);
vector.emplace_back(parser);
}
}
/*
* ==================
* EntData_Parse
* ==================
*/
std::vector<entdict_t> EntData_Parse(const std::string &entdata)
{
std::vector<entdict_t> result;
EntData_ParseInto(entdata, result);
return result;
}

View File

@ -69,5 +69,6 @@ public:
void parse(parser_base_t &parser);
};
void EntData_ParseInto(const std::string &entdata, std::vector<entdict_t> &vector);
std::vector<entdict_t> EntData_Parse(const std::string &entdata);
std::string EntData_Write(const std::vector<entdict_t> &ents);

View File

@ -536,7 +536,7 @@ public:
extern settings::light_settings options;
extern uint8_t *filebase;
extern std::vector<uint8_t> filebase;
extern std::vector<uint8_t> lit_filebase;
extern std::vector<uint8_t> lux_filebase;

View File

@ -1297,16 +1297,29 @@ static void GL_SubdivideSurface(const mface_t *face, const modelinfo_t *face_mod
SubdividePolygon(face, face_modelinfo, bsp, face->numedges, verts, options.surflight_subdivide.value());
}
static bool ParseEntityLights(std::ifstream &f)
{
std::string str{std::istreambuf_iterator<char>(f), std::istreambuf_iterator<char>()};
parser_t p(str);
EntData_ParseInto(str, radlights);
return true;
}
bool ParseLightsFile(const fs::path &fname)
{
// note: this creates dupes. super bright light! (and super slow, too)
std::string buf;
std::ifstream f(fname);
if (!f)
return false;
// use entity-style format
if (fname.extension() == ".ent") {
return ParseEntityLights(f);
}
while (!f.eof()) {
std::string buf;
std::getline(f, buf);
parser_t parser(buf);
@ -1404,7 +1417,7 @@ static void MakeSurfaceLights(const mbsp_t *bsp)
}
}
if (surflights_dump_file) {
if (surflights_dump_file.is_open()) {
surflights_dump_file.close();
fmt::print("wrote surface lights to '{}'\n", surflights_dump_filename);
}

View File

@ -62,7 +62,7 @@ bool dirt_in_use = false;
static facesup_t *faces_sup; // lit2/bspx stuff
/// start of lightmap data
uint8_t *filebase;
std::vector<uint8_t> filebase;
/// offset of start of free space after data (should be kept a multiple of 4)
static int file_p;
/// offset of end of free space for lightmap data
@ -223,7 +223,7 @@ void GetFileSpace(uint8_t **lightdata, uint8_t **colordata, uint8_t **deluxdata,
{
light_mutex.lock();
*lightdata = filebase + file_p;
*lightdata = filebase.data() + file_p;
*colordata = lit_filebase.data() + lit_file_p;
*deluxdata = lux_filebase.data() + lux_file_p;
@ -255,7 +255,7 @@ void GetFileSpace_PreserveOffsetInBsp(uint8_t **lightdata, uint8_t **colordata,
{
Q_assert(lightofs >= 0);
*lightdata = filebase + lightofs;
*lightdata = filebase.data() + lightofs;
if (colordata) {
*colordata = lit_filebase.data() + (lightofs * 3);
@ -428,14 +428,12 @@ static void LightWorld(bspdata_t *bspdata, bool forcedscale)
mbsp_t &bsp = std::get<mbsp_t>(bspdata->bsp);
delete[] filebase;
filebase.clear();
lit_filebase.clear();
lux_filebase.clear();
/* greyscale data stored in a separate buffer */
filebase = new uint8_t[MAX_MAP_LIGHTING]{};
if (!filebase)
FError("allocation of {} bytes failed.", MAX_MAP_LIGHTING);
filebase.resize(MAX_MAP_LIGHTING);
file_p = 0;
file_end = MAX_MAP_LIGHTING;
@ -515,7 +513,7 @@ static void LightWorld(bspdata_t *bspdata, bool forcedscale)
memcpy(bsp.dlightdata.data(), lit_filebase.data(), bsp.dlightdata.size());
} else {
bsp.dlightdata.resize(file_p);
memcpy(bsp.dlightdata.data(), filebase, bsp.dlightdata.size());
memcpy(bsp.dlightdata.data(), filebase.data(), bsp.dlightdata.size());
}
} else {
// NOTE: bsp.lightdatasize is already valid in the -litonly case

View File

@ -3240,7 +3240,7 @@ static void WriteLightmaps(
if (bsp->loadversion->game->has_rgb_lightmap) {
lightofs = lit - lit_filebase.data();
} else {
lightofs = out - filebase;
lightofs = out - filebase.data();
}
if (facesup) {