fixed shader stages using "wave" not being animated when the server time is a big number

This commit is contained in:
myT 2017-05-19 00:04:32 +02:00
parent 389cd1690d
commit a646bfdc87
2 changed files with 27 additions and 31 deletions

View file

@ -1,6 +1,8 @@
DD Mmm 17 - 1.49 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 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 0 (default) = text size scales with con_scale but not the resolution
con_scaleMode 1 = text size scales with con_scale and the resolution con_scaleMode 1 = text size scales with con_scale and the resolution

View file

@ -24,9 +24,17 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#include "tr_local.h" #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 ) switch ( func )
{ {
@ -56,11 +64,7 @@ static float *TableForFunc( genFunc_t func )
*/ */
static float EvalWaveForm( const waveForm_t *wf ) static float EvalWaveForm( const waveForm_t *wf )
{ {
float *table; return WaveValue( TableForFunc( wf->func ), wf->base, wf->amplitude, wf->phase, wf->frequency );
table = TableForFunc( wf->func );
return WAVEVALUE( table, wf->base, wf->amplitude, wf->phase, wf->frequency );
} }
static float EvalWaveFormClamped( const waveForm_t *wf ) static float EvalWaveFormClamped( const waveForm_t *wf )
@ -112,18 +116,15 @@ DEFORMATIONS
static void RB_CalcDeformVertexes( const deformStage_t* ds ) static void RB_CalcDeformVertexes( const deformStage_t* ds )
{ {
int i; float* xyz = (float*)tess.xyz;
vec3_t offset; float* normal = (float*)tess.normal;
float scale; vec3_t offset;
float *xyz = ( float * ) tess.xyz;
float *normal = ( float * ) tess.normal;
float *table;
if ( ds->deformationWave.frequency == 0 ) 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 ); VectorScale( normal, scale, offset );
@ -134,13 +135,12 @@ static void RB_CalcDeformVertexes( const deformStage_t* ds )
} }
else 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; const float off = ( xyz[0] + xyz[1] + xyz[2] ) * ds->deformationSpread;
const float scale = WaveValue( table, ds->deformationWave.base,
scale = WAVEVALUE( table, ds->deformationWave.base,
ds->deformationWave.amplitude, ds->deformationWave.amplitude,
ds->deformationWave.phase + off, ds->deformationWave.phase + off,
ds->deformationWave.frequency ); ds->deformationWave.frequency );
@ -214,23 +214,17 @@ static void RB_CalcBulgeVertexes( const deformStage_t* ds )
static void RB_CalcMoveVertexes( const deformStage_t* ds ) static void RB_CalcMoveVertexes( const deformStage_t* ds )
{ {
int i; const float* table = TableForFunc( ds->deformationWave.func );
float *xyz; const double scale = WaveValue( table, ds->deformationWave.base,
float *table;
double scale;
vec3_t offset;
table = TableForFunc( ds->deformationWave.func );
scale = WAVEVALUE( table, ds->deformationWave.base,
ds->deformationWave.amplitude, ds->deformationWave.amplitude,
ds->deformationWave.phase, ds->deformationWave.phase,
ds->deformationWave.frequency ); ds->deformationWave.frequency );
vec3_t offset;
VectorScale( ds->moveVector, scale, offset ); VectorScale( ds->moveVector, scale, offset );
xyz = ( float * ) tess.xyz; float* xyz = (float*)tess.xyz;
for ( i = 0; i < tess.numVertexes; i++, xyz += 4 ) { for ( int i = 0; i < tess.numVertexes; i++, xyz += 4 ) {
VectorAdd( xyz, offset, xyz ); VectorAdd( xyz, offset, xyz );
} }
} }