From e0eacf401451860d86a32c3c54190f65d5adb1e1 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 20 Mar 2021 16:06:15 +0900 Subject: [PATCH] [model] Make set and mix versions of Mod_LeafPVS The re-entrant version was a good start, but being able to mix while decompressing saves having to have a temporary buffer somewhere. --- include/QF/model.h | 6 ++-- libs/models/brush/model_brush.c | 57 +++++++++++++++++++++++++++++---- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/include/QF/model.h b/include/QF/model.h index 0a7069d3f..1c5969820 100644 --- a/include/QF/model.h +++ b/include/QF/model.h @@ -435,8 +435,10 @@ mleaf_t *Mod_PointInLeaf (const vec3_t p, model_t *model) __attribute__((pure)); byte *Mod_LeafPVS (const mleaf_t *leaf, const model_t *model); // NOTE: the buffer pointed to by out must be at least MAP_PVS_BYTES in size -void Mod_LeafPVS_r (const mleaf_t *leaf, const model_t *model, byte defvis, - byte *out); +void Mod_LeafPVS_set (const mleaf_t *leaf, const model_t *model, byte defvis, + byte *out); +void Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, + byte *out); void Mod_Print (void); diff --git a/libs/models/brush/model_brush.c b/libs/models/brush/model_brush.c index 6270de72b..1e2fa81a4 100644 --- a/libs/models/brush/model_brush.c +++ b/libs/models/brush/model_brush.c @@ -86,8 +86,8 @@ Mod_PointInLeaf (const vec3_t p, model_t *model) } static inline void -Mod_DecompressVis (const byte *in, const mod_brush_t *brush, byte defvis, - byte *out) +Mod_DecompressVis_set (const byte *in, const mod_brush_t *brush, byte defvis, + byte *out) { byte *start = out; int row, c; @@ -117,6 +117,35 @@ Mod_DecompressVis (const byte *in, const mod_brush_t *brush, byte defvis, } while (out - start < row); } +static inline void +Mod_DecompressVis_mix (const byte *in, const mod_brush_t *brush, byte defvis, + byte *out) +{ + byte *start = out; + int row, c; + + row = (brush->numleafs + 7) >> 3; + + if (!in) { // no vis info, so make all visible + while (row) { + *out++ |= defvis; + row--; + } + return; + } + + do { + if (*in) { + *out++ |= *in++; + continue; + } + + c = in[1]; + in += 2; + out += c; + } while (out - start < row); +} + VISIBLE byte * Mod_LeafPVS (const mleaf_t *leaf, const model_t *model) { @@ -127,19 +156,35 @@ Mod_LeafPVS (const mleaf_t *leaf, const model_t *model) } return mod_novis; } - Mod_DecompressVis (leaf->compressed_vis, &model->brush, 0xff, decompressed); + Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, 0xff, + decompressed); return decompressed; } VISIBLE void -Mod_LeafPVS_r (const mleaf_t *leaf, const model_t *model, byte defvis, - byte *out) +Mod_LeafPVS_set (const mleaf_t *leaf, const model_t *model, byte defvis, + byte *out) { if (leaf == model->brush.leafs) { memset (out, defvis, sizeof (mod_novis)); return; } - return Mod_DecompressVis (leaf->compressed_vis, &model->brush, defvis, out); + return Mod_DecompressVis_set (leaf->compressed_vis, &model->brush, defvis, + out); +} + +VISIBLE void +Mod_LeafPVS_mix (const mleaf_t *leaf, const model_t *model, byte defvis, + byte *out) +{ + if (leaf == model->brush.leafs) { + for (int i = MAP_PVS_BYTES; i-- > 0; ) { + *out++ |= defvis; + } + return; + } + return Mod_DecompressVis_mix (leaf->compressed_vis, &model->brush, defvis, + out); } // BRUSHMODEL LOADING =========================================================