From a646bfdc8740264e7cc15fe6b579ca19f7f27556 Mon Sep 17 00:00:00 2001 From: myT Date: Fri, 19 May 2017 00:04:32 +0200 Subject: [PATCH] fixed shader stages using "wave" not being animated when the server time is a big number --- changelog.txt | 2 ++ code/renderer/tr_shade_calc.cpp | 56 +++++++++++++++------------------ 2 files changed, 27 insertions(+), 31 deletions(-) diff --git a/changelog.txt b/changelog.txt index 6ed9ee9..7d3ea1e 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,8 @@ DD Mmm 17 - 1.49 +fix: shader stages using "wave" were not animated when the server time was too large + add: con_scaleMode specifies the console text scaling mode con_scaleMode 0 (default) = text size scales with con_scale but not the resolution con_scaleMode 1 = text size scales with con_scale and the resolution diff --git a/code/renderer/tr_shade_calc.cpp b/code/renderer/tr_shade_calc.cpp index 87846dc..ffa235e 100644 --- a/code/renderer/tr_shade_calc.cpp +++ b/code/renderer/tr_shade_calc.cpp @@ -24,9 +24,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "tr_local.h" -#define WAVEVALUE( table, base, amplitude, phase, freq ) ((base) + table[ myftol( ( ( (phase) + tess.shaderTime * (freq) ) * FUNCTABLE_SIZE ) ) & FUNCTABLE_MASK ] * (amplitude)) +static double WaveValue( const float* table, double base, double amplitude, double phase, double freq ) +{ + // the original code did a double to 32-bit int conversion of x + const double x = (phase + tess.shaderTime * freq) * FUNCTABLE_SIZE; + const int i = (int)((int64_t)x & (int64_t)FUNCTABLE_MASK); + const double r = base + table[i] * amplitude; -static float *TableForFunc( genFunc_t func ) + return r; +} + +static const float* TableForFunc( genFunc_t func ) { switch ( func ) { @@ -56,11 +64,7 @@ static float *TableForFunc( genFunc_t func ) */ static float EvalWaveForm( const waveForm_t *wf ) { - float *table; - - table = TableForFunc( wf->func ); - - return WAVEVALUE( table, wf->base, wf->amplitude, wf->phase, wf->frequency ); + return WaveValue( TableForFunc( wf->func ), wf->base, wf->amplitude, wf->phase, wf->frequency ); } static float EvalWaveFormClamped( const waveForm_t *wf ) @@ -112,18 +116,15 @@ DEFORMATIONS static void RB_CalcDeformVertexes( const deformStage_t* ds ) { - int i; - vec3_t offset; - float scale; - float *xyz = ( float * ) tess.xyz; - float *normal = ( float * ) tess.normal; - float *table; + float* xyz = (float*)tess.xyz; + float* normal = (float*)tess.normal; + vec3_t offset; if ( ds->deformationWave.frequency == 0 ) { - scale = EvalWaveForm( &ds->deformationWave ); + const float scale = EvalWaveForm( &ds->deformationWave ); - for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) + for ( int i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { VectorScale( normal, scale, offset ); @@ -134,13 +135,12 @@ static void RB_CalcDeformVertexes( const deformStage_t* ds ) } else { - table = TableForFunc( ds->deformationWave.func ); + const float* table = TableForFunc(ds->deformationWave.func); - for ( i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) + for ( int i = 0; i < tess.numVertexes; i++, xyz += 4, normal += 4 ) { - float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread; - - scale = WAVEVALUE( table, ds->deformationWave.base, + const float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread; + const float scale = WaveValue( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase + off, ds->deformationWave.frequency ); @@ -214,23 +214,17 @@ static void RB_CalcBulgeVertexes( const deformStage_t* ds ) static void RB_CalcMoveVertexes( const deformStage_t* ds ) { - int i; - float *xyz; - float *table; - double scale; - vec3_t offset; - - table = TableForFunc( ds->deformationWave.func ); - - scale = WAVEVALUE( table, ds->deformationWave.base, + const float* table = TableForFunc( ds->deformationWave.func ); + const double scale = WaveValue( table, ds->deformationWave.base, ds->deformationWave.amplitude, ds->deformationWave.phase, ds->deformationWave.frequency ); + vec3_t offset; VectorScale( ds->moveVector, scale, offset ); - xyz = ( float * ) tess.xyz; - for ( i = 0; i < tess.numVertexes; i++, xyz += 4 ) { + float* xyz = (float*)tess.xyz; + for ( int i = 0; i < tess.numVertexes; i++, xyz += 4 ) { VectorAdd( xyz, offset, xyz ); } }