From 9150b770e45788dee3f2735fdc95195e2a471cf1 Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 26 May 2024 23:12:16 +0300 Subject: [PATCH] engine: common: mod_bmodel: add function Mod_DecompressVisTo that will copy fat vis data into the provided buffer --- engine/common/mod_bmodel.c | 71 ++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/engine/common/mod_bmodel.c b/engine/common/mod_bmodel.c index 1de37c32..7ed4dd4f 100644 --- a/engine/common/mod_bmodel.c +++ b/engine/common/mod_bmodel.c @@ -578,6 +578,42 @@ void Mod_PrintWorldStats_f( void ) =============================================================================== */ +/* +=================== +Mod_DecompressPVS + +TODO: replace all Mod_DecompressPVS calls by this +=================== +*/ +static void Mod_DecompressPVSTo( byte *const out, const byte *in, size_t visbytes ) +{ + byte *dst = out; + + if( !in ) // no visinfo, make all visible + { + memset( out, 0xFF, visbytes ); + return; + } + + while( dst < out + visbytes ) + { + if( *in ) // uncompressed + { + *dst++ = *in++; + } + else // zero repeated `c` times + { + size_t c = in[1]; + if( c > out + visbytes - dst ) + c = out + visbytes - dst; + + memset( dst, 0, c ); + in += 2; + dst += c; + } + } +} + /* =================== Mod_DecompressPVS @@ -585,40 +621,7 @@ Mod_DecompressPVS */ static byte *Mod_DecompressPVS( const byte *in, int visbytes ) { - byte *out; - int c; - - out = g_visdata; - - if( !in ) - { - // no vis info, so make all visible - while( visbytes ) - { - *out++ = 0xff; - visbytes--; - } - return g_visdata; - } - - do - { - if( *in ) - { - *out++ = *in++; - continue; - } - - c = in[1]; - in += 2; - - while( c ) - { - *out++ = 0; - c--; - } - } while( out - g_visdata < visbytes ); - + Mod_DecompressPVSTo( g_visdata, in, visbytes ); return g_visdata; }