light: refactor tracelist and selfshadowlist to be std::vector
This commit is contained in:
parent
b669767fe0
commit
6bb842cd47
|
|
@ -198,9 +198,10 @@ extern const bouncelight_t *bouncelights;
|
|||
extern int numbouncelights;
|
||||
extern byte thepalette[768];
|
||||
|
||||
/* tracelist is a null terminated array of BSP models to use for LOS tests */
|
||||
extern const modelinfo_t *const *tracelist;
|
||||
extern const modelinfo_t *const *selfshadowlist;
|
||||
/* tracelist is a std::vector of pointers to modelinfo_t to use for LOS tests */
|
||||
extern std::vector<const modelinfo_t *> tracelist;
|
||||
extern std::vector<const modelinfo_t *> selfshadowlist;
|
||||
|
||||
|
||||
void LightFaceInit(const bsp2_t *bsp, struct ltface_ctx *ctx);
|
||||
void LightFaceShutdown(struct ltface_ctx *ctx);
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@ static byte *lux_file_p; // start of free space after luxfile data
|
|||
static byte *lux_file_end; // end of space for luxfile data
|
||||
|
||||
std::vector<modelinfo_t> modelinfo;
|
||||
const modelinfo_t *const *tracelist;
|
||||
const modelinfo_t *const *selfshadowlist;
|
||||
std::vector<const modelinfo_t *> tracelist;
|
||||
std::vector<const modelinfo_t *> selfshadowlist;
|
||||
|
||||
int oversample = 1;
|
||||
int write_litfile = 0; /* 0 for none, 1 for .lit, 2 for bspx, 3 for both */
|
||||
|
|
@ -349,20 +349,12 @@ LightThreadBounce(void *arg)
|
|||
static void
|
||||
FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
||||
{
|
||||
int i, numshadowmodels, numselfshadowmodels;
|
||||
const modelinfo_t **shadowmodels;
|
||||
const modelinfo_t **selfshadowmodels;
|
||||
float lightmapscale;
|
||||
|
||||
assert(modelinfo.size() == 0);
|
||||
assert(tracelist.size() == 0);
|
||||
assert(selfshadowlist.size() == 0);
|
||||
|
||||
modelinfo.reserve(bsp->nummodels);
|
||||
|
||||
shadowmodels = (const modelinfo_t **)malloc(sizeof(modelinfo_t *) * (bsp->nummodels + 1));
|
||||
memset(shadowmodels, 0, sizeof(modelinfo_t *) * (bsp->nummodels + 1));
|
||||
|
||||
selfshadowmodels = (const modelinfo_t **)malloc(sizeof(modelinfo_t *) * (bsp->nummodels + 1));
|
||||
memset(selfshadowmodels, 0, sizeof(modelinfo_t *) * (bsp->nummodels + 1));
|
||||
|
||||
if (!bsp->nummodels) {
|
||||
Error("Corrupt .BSP: bsp->nummodels is 0!");
|
||||
}
|
||||
|
|
@ -370,7 +362,7 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
if (lmscaleoverride)
|
||||
SetWorldKeyValue("_lightmap_scale", lmscaleoverride);
|
||||
|
||||
lightmapscale = atoi(WorldValueForKey("_lightmap_scale").c_str());
|
||||
float lightmapscale = atoi(WorldValueForKey("_lightmap_scale").c_str());
|
||||
if (!lightmapscale)
|
||||
lightmapscale = 16; /* the default */
|
||||
if (lightmapscale <= 0)
|
||||
|
|
@ -378,19 +370,22 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
if (lmscaleoverride || lightmapscale != 16)
|
||||
logprint("Forcing lightmap scale of %gqu\n", lightmapscale);
|
||||
/*I'm going to do this check in the hopes that there's a benefit to cheaper scaling in engines (especially software ones that might be able to just do some mip hacks). This tool doesn't really care.*/
|
||||
for (i = 1; i < lightmapscale;)
|
||||
i++;
|
||||
if (i != lightmapscale)
|
||||
logprint("WARNING: lightmap scale is not a power of 2\n");
|
||||
{
|
||||
int i;
|
||||
for (i = 1; i < lightmapscale;) {
|
||||
i++;
|
||||
}
|
||||
if (i != lightmapscale) {
|
||||
logprint("WARNING: lightmap scale is not a power of 2\n");
|
||||
}
|
||||
}
|
||||
|
||||
/* The world always casts shadows */
|
||||
modelinfo_t world { &bsp->dmodels[0], lightmapscale };
|
||||
world.shadow.setFloatValue(1.0f); /* world always casts shadows */
|
||||
modelinfo.push_back(world);
|
||||
|
||||
shadowmodels[0] = &modelinfo[0];
|
||||
numshadowmodels = 1;
|
||||
numselfshadowmodels = 0;
|
||||
tracelist.push_back(&modelinfo[0]);
|
||||
|
||||
for (int i = 1; i < bsp->nummodels; i++) {
|
||||
modelinfo_t info { &bsp->dmodels[i], lightmapscale };
|
||||
|
|
@ -410,9 +405,9 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
|
||||
/* Check if this model will cast shadows (shadow => shadowself) */
|
||||
if (info.shadow.boolValue()) {
|
||||
shadowmodels[numshadowmodels++] = &modelinfo[i];
|
||||
tracelist.push_back(&modelinfo[i]);
|
||||
} else if (info.shadowself.boolValue()){
|
||||
selfshadowmodels[numselfshadowmodels++] = &modelinfo[i];
|
||||
selfshadowlist.push_back(&modelinfo[i]);
|
||||
}
|
||||
|
||||
/* Set up the offset for rotate_* entities */
|
||||
|
|
@ -437,9 +432,6 @@ FindModelInfo(const bsp2_t *bsp, const char *lmscaleoverride)
|
|||
}
|
||||
|
||||
assert(modelinfo.size() == bsp->nummodels);
|
||||
|
||||
tracelist = shadowmodels;
|
||||
selfshadowlist = selfshadowmodels;
|
||||
}
|
||||
|
||||
/* return 0 if either vector is zero-length */
|
||||
|
|
|
|||
|
|
@ -582,15 +582,14 @@ TraceLine(const dmodel_t *model, const int traceflags,
|
|||
static qboolean
|
||||
BSP_TestLight(const vec3_t start, const vec3_t stop, const dmodel_t *self)
|
||||
{
|
||||
const modelinfo_t *const *model;
|
||||
const int traceflags = TRACE_HIT_SOLID;
|
||||
int result = TRACE_HIT_NONE;
|
||||
|
||||
/* Check against the list of global shadow casters */
|
||||
for (model = tracelist; *model; model++) {
|
||||
if ((*model)->model == self)
|
||||
for (const modelinfo_t *model : tracelist) {
|
||||
if (model->model == self)
|
||||
continue;
|
||||
result = TraceLine((*model)->model, traceflags, start, stop);
|
||||
result = TraceLine(model->model, traceflags, start, stop);
|
||||
if (result != TRACE_HIT_NONE)
|
||||
break;
|
||||
}
|
||||
|
|
@ -618,10 +617,12 @@ BSP_TestSky(const vec3_t start, const vec3_t dirn, const dmodel_t *self)
|
|||
|
||||
/* If good, check it isn't shadowed by another model */
|
||||
traceflags = TRACE_HIT_SOLID;
|
||||
for (model = tracelist + 1; *model; model++) {
|
||||
if ((*model)->model == self)
|
||||
for (const modelinfo_t *model : tracelist) {
|
||||
if (model == tracelist.at(0))
|
||||
continue;
|
||||
result = TraceLine((*model)->model, traceflags, start, stop);
|
||||
if (model->model == self)
|
||||
continue;
|
||||
result = TraceLine(model->model, traceflags, start, stop);
|
||||
if (result != TRACE_HIT_NONE)
|
||||
return false;
|
||||
}
|
||||
|
|
@ -671,11 +672,10 @@ BSP_DirtTrace(const vec3_t start, const vec3_t dirn, const vec_t dist, const dmo
|
|||
}
|
||||
|
||||
/* Check against the list of global shadow casters */
|
||||
const modelinfo_t *const *model;
|
||||
for (model = tracelist; *model; model++) {
|
||||
if ((*model)->model == self)
|
||||
for (const modelinfo_t *model : tracelist) {
|
||||
if (model->model == self)
|
||||
continue;
|
||||
if (TraceFaces (&ti, (*model)->model->headnode[0], start, stop)) {
|
||||
if (TraceFaces (&ti, model->model->headnode[0], start, stop)) {
|
||||
if (hitdist_out) {
|
||||
vec3_t delta;
|
||||
VectorSubtract(ti.point, start, delta);
|
||||
|
|
|
|||
|
|
@ -173,15 +173,14 @@ void
|
|||
Embree_TraceInit(const bsp2_t *bsp)
|
||||
{
|
||||
bsp_static = bsp;
|
||||
assert(tracelist != NULL);
|
||||
assert(device == nullptr);
|
||||
|
||||
std::vector<const bsp2_dface_t *> skyfaces, solidfaces, fencefaces, selfshadowfaces;
|
||||
|
||||
/* Check against the list of global shadow casters */
|
||||
for (const modelinfo_t *const *model = tracelist; *model; model++) {
|
||||
for (int i=0; i<(*model)->model->numfaces; i++) {
|
||||
const bsp2_dface_t *face = &bsp->dfaces[(*model)->model->firstface + i];
|
||||
for (const modelinfo_t *model : tracelist) {
|
||||
for (int i=0; i<model->model->numfaces; i++) {
|
||||
const bsp2_dface_t *face = &bsp->dfaces[model->model->firstface + i];
|
||||
const char *texname = Face_TextureName(bsp, face);
|
||||
|
||||
if (!strncmp("sky", texname, 3)) {
|
||||
|
|
@ -197,9 +196,9 @@ Embree_TraceInit(const bsp2_t *bsp)
|
|||
}
|
||||
|
||||
/* Self-shadow models */
|
||||
for (const modelinfo_t *const *model = selfshadowlist; *model; model++) {
|
||||
for (int i=0; i<(*model)->model->numfaces; i++) {
|
||||
const bsp2_dface_t *face = &bsp->dfaces[(*model)->model->firstface + i];
|
||||
for (const modelinfo_t *model : selfshadowlist) {
|
||||
for (int i=0; i<model->model->numfaces; i++) {
|
||||
const bsp2_dface_t *face = &bsp->dfaces[model->model->firstface + i];
|
||||
selfshadowfaces.push_back(face);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue