From 6cbac51731e769bc2f5f6fd094ef3619ec39675a Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Mon, 27 May 2024 13:18:05 +0300 Subject: [PATCH] engine: common: add function for compressing visdata --- engine/common/mod_bmodel.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 60d2d8ce..33e9e2ac 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -625,6 +625,34 @@ static byte *Mod_DecompressPVS( const byte *in, int visbytes ) return g_visdata; } +static size_t Mod_CompressPVS( byte *out, const byte *in, size_t inbytes ) +{ + size_t i; + byte *dst = out; + + for( i = 0; i < inbytes; i++ ) + { + size_t j = i + 1, rep = 1; + + *dst++ = in[i]; + + // only compress zeros + if( in[i] ) + continue; + + for( ; j < inbytes && rep != 255; j++, rep++ ) + { + if( in[j] ) + break; + } + + *dst++ = rep; + i = j - 1; + } + + return dst - out; +} + /* ================== Mod_PointInLeaf