mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
ref: common: refactor variable declarations
This commit is contained in:
@@ -45,11 +45,9 @@ void *_Mem_Realloc( poolhandle_t poolptr, void *memptr, size_t size, qboolean cl
|
||||
|
||||
void GL_InitRandomTable( void )
|
||||
{
|
||||
int tu, tv;
|
||||
|
||||
for( tu = 0; tu < MOD_FRAMES; tu++ )
|
||||
for( int tu = 0; tu < MOD_FRAMES; tu++ )
|
||||
{
|
||||
for( tv = 0; tv < MOD_FRAMES; tv++ )
|
||||
for( int tv = 0; tv < MOD_FRAMES; tv++ )
|
||||
{
|
||||
rtable[tu][tv] = gEngfuncs.COM_RandomLong( 0, 0x7FFF );
|
||||
}
|
||||
|
||||
@@ -25,30 +25,25 @@ Assume input buffer is RGBA
|
||||
*/
|
||||
byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int outWidth, int outHeight, qboolean isNormalMap )
|
||||
{
|
||||
uint frac, fracStep;
|
||||
uint *in = (uint *)source;
|
||||
uint p1[0x1000], p2[0x1000];
|
||||
byte *pix1, *pix2, *pix3, *pix4;
|
||||
uint *out, *inRow1, *inRow2;
|
||||
static byte *scaledImage = NULL; // pointer to a scaled image
|
||||
vec3_t normal;
|
||||
int i, x, y;
|
||||
uint p1[0x1000], p2[0x1000];
|
||||
|
||||
if( !source ) return NULL;
|
||||
|
||||
scaledImage = Mem_Realloc( r_temppool, scaledImage, outWidth * outHeight * 4 );
|
||||
fracStep = inWidth * 0x10000 / outWidth;
|
||||
out = (uint *)scaledImage;
|
||||
const uint fracStep = inWidth * 0x10000 / outWidth;
|
||||
uint *in = (uint *)source;
|
||||
uint *out = (uint *)scaledImage;
|
||||
|
||||
frac = fracStep >> 2;
|
||||
for( i = 0; i < outWidth; i++ )
|
||||
uint frac = fracStep >> 2;
|
||||
for( int i = 0; i < outWidth; i++ )
|
||||
{
|
||||
p1[i] = 4 * (frac >> 16);
|
||||
frac += fracStep;
|
||||
}
|
||||
|
||||
frac = (fracStep >> 2) * 3;
|
||||
for( i = 0; i < outWidth; i++ )
|
||||
for( int i = 0; i < outWidth; i++ )
|
||||
{
|
||||
p2[i] = 4 * (frac >> 16);
|
||||
frac += fracStep;
|
||||
@@ -56,17 +51,18 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out
|
||||
|
||||
if( isNormalMap )
|
||||
{
|
||||
for( y = 0; y < outHeight; y++, out += outWidth )
|
||||
for( int y = 0; y < outHeight; y++, out += outWidth )
|
||||
{
|
||||
inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight);
|
||||
inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight);
|
||||
uint *inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight);
|
||||
uint *inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight);
|
||||
|
||||
for( x = 0; x < outWidth; x++ )
|
||||
for( int x = 0; x < outWidth; x++ )
|
||||
{
|
||||
pix1 = (byte *)inRow1 + p1[x];
|
||||
pix2 = (byte *)inRow1 + p2[x];
|
||||
pix3 = (byte *)inRow2 + p1[x];
|
||||
pix4 = (byte *)inRow2 + p2[x];
|
||||
byte *pix1 = (byte *)inRow1 + p1[x];
|
||||
byte *pix2 = (byte *)inRow1 + p2[x];
|
||||
byte *pix3 = (byte *)inRow2 + p1[x];
|
||||
byte *pix4 = (byte *)inRow2 + p2[x];
|
||||
vec3_t normal;
|
||||
|
||||
normal[0] = MAKE_SIGNED( pix1[0] ) + MAKE_SIGNED( pix2[0] ) + MAKE_SIGNED( pix3[0] ) + MAKE_SIGNED( pix4[0] );
|
||||
normal[1] = MAKE_SIGNED( pix1[1] ) + MAKE_SIGNED( pix2[1] ) + MAKE_SIGNED( pix3[1] ) + MAKE_SIGNED( pix4[1] );
|
||||
@@ -84,17 +80,17 @@ byte *GL_ResampleTexture( const byte *source, int inWidth, int inHeight, int out
|
||||
}
|
||||
else
|
||||
{
|
||||
for( y = 0; y < outHeight; y++, out += outWidth )
|
||||
for( int y = 0; y < outHeight; y++, out += outWidth )
|
||||
{
|
||||
inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight);
|
||||
inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight);
|
||||
uint *inRow1 = in + inWidth * (int)(((float)y + 0.25f) * inHeight / outHeight);
|
||||
uint *inRow2 = in + inWidth * (int)(((float)y + 0.75f) * inHeight / outHeight);
|
||||
|
||||
for( x = 0; x < outWidth; x++ )
|
||||
for( int x = 0; x < outWidth; x++ )
|
||||
{
|
||||
pix1 = (byte *)inRow1 + p1[x];
|
||||
pix2 = (byte *)inRow1 + p2[x];
|
||||
pix3 = (byte *)inRow2 + p1[x];
|
||||
pix4 = (byte *)inRow2 + p2[x];
|
||||
byte *pix1 = (byte *)inRow1 + p1[x];
|
||||
byte *pix2 = (byte *)inRow1 + p2[x];
|
||||
byte *pix3 = (byte *)inRow2 + p1[x];
|
||||
byte *pix4 = (byte *)inRow2 + p2[x];
|
||||
|
||||
((byte *)(out+x))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0]) >> 2;
|
||||
((byte *)(out+x))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1]) >> 2;
|
||||
|
||||
@@ -30,7 +30,6 @@ CL_RunLightStyles
|
||||
void CL_RunLightStyles( lightstyle_t *ls )
|
||||
{
|
||||
const model_t *world = gp_cl->models[1];
|
||||
int i;
|
||||
float frametime = gp_cl->time - gp_cl->oldtime;
|
||||
|
||||
if( !world )
|
||||
@@ -38,18 +37,15 @@ void CL_RunLightStyles( lightstyle_t *ls )
|
||||
|
||||
if( r_fullbright->value || !world->lightdata )
|
||||
{
|
||||
for( i = 0; i < MAX_LIGHTSTYLES; i++ )
|
||||
for( int i = 0; i < MAX_LIGHTSTYLES; i++ )
|
||||
g_lightstylevalue[i] = 256 * 256;
|
||||
return;
|
||||
}
|
||||
|
||||
// light animations
|
||||
// 'm' is normal light, 'a' is no light, 'z' is double bright
|
||||
for( i = 0; i < MAX_LIGHTSTYLES; i++ )
|
||||
for( int i = 0; i < MAX_LIGHTSTYLES; i++ )
|
||||
{
|
||||
int k, flight, clight;
|
||||
float l, lerpfrac, backlerp;
|
||||
|
||||
if( !gp_cl->paused && frametime <= 0.1f )
|
||||
ls[i].time += frametime; // evaluate local time
|
||||
|
||||
@@ -65,7 +61,7 @@ void CL_RunLightStyles( lightstyle_t *ls )
|
||||
continue;
|
||||
}
|
||||
|
||||
flight = (int)Q_floor( ls[i].time * 10 );
|
||||
int flight = (int)Q_floor( ls[i].time * 10 );
|
||||
|
||||
if( !ls[i].interp || !cl_lightstyle_lerping->value )
|
||||
{
|
||||
@@ -73,14 +69,14 @@ void CL_RunLightStyles( lightstyle_t *ls )
|
||||
continue;
|
||||
}
|
||||
|
||||
clight = (int)Q_ceil( ls[i].time * 10 );
|
||||
lerpfrac = ( ls[i].time * 10 ) - flight;
|
||||
backlerp = 1.0f - lerpfrac;
|
||||
int clight = (int)Q_ceil( ls[i].time * 10 );
|
||||
float lerpfrac = ( ls[i].time * 10 ) - flight;
|
||||
float backlerp = 1.0f - lerpfrac;
|
||||
|
||||
// interpolate animating light
|
||||
// frame just gone
|
||||
k = ls[i].map[flight % ls[i].length];
|
||||
l = (float)( k * 22.0f ) * backlerp;
|
||||
int k = ls[i].map[flight % ls[i].length];
|
||||
float l = (float)( k * 22.0f ) * backlerp;
|
||||
|
||||
// upcoming frame
|
||||
k = ls[i].map[clight % ls[i].length];
|
||||
@@ -498,14 +494,6 @@ R_EntityDynamicLight
|
||||
*/
|
||||
void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_world, double time, vec3_t lightspot, vec3_t lightvec )
|
||||
{
|
||||
movevars_t *mv = gp_movevars;
|
||||
vec3_t lightDir, vecSrc, vecEnd;
|
||||
vec3_t origin, dist, finalLight;
|
||||
float add, radius, total;
|
||||
colorVec light;
|
||||
uint lnum;
|
||||
dlight_t *dl;
|
||||
|
||||
if( !plight || !ent )
|
||||
return;
|
||||
|
||||
@@ -519,21 +507,26 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
return;
|
||||
}
|
||||
|
||||
movevars_t *mv = gp_movevars;
|
||||
vec3_t lightDir;
|
||||
|
||||
// determine plane to get lightvalues from: ceil or floor
|
||||
if( FBitSet( ent->curstate.effects, EF_INVLIGHT ))
|
||||
VectorSet( lightDir, 0.0f, 0.0f, 1.0f );
|
||||
else
|
||||
VectorSet( lightDir, 0.0f, 0.0f, -1.0f );
|
||||
|
||||
vec3_t origin;
|
||||
VectorCopy( ent->origin, origin );
|
||||
|
||||
vec3_t vecSrc, vecEnd;
|
||||
VectorSet( vecSrc, origin[0], origin[1], origin[2] - lightDir[2] * 8.0f );
|
||||
|
||||
colorVec light;
|
||||
light.r = light.g = light.b = light.a = 0;
|
||||
|
||||
if(( mv->skycolor[0] + mv->skycolor[1] + mv->skycolor[2] ) != 0 )
|
||||
{
|
||||
msurface_t *psurf = NULL;
|
||||
pmtrace_t trace;
|
||||
vec3_t skyvec;
|
||||
|
||||
if( FBitSet( gp_host->features, ENGINE_WRITE_LARGE_COORD ))
|
||||
@@ -543,7 +536,8 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
|
||||
VectorSubtract( origin, skyvec, vecEnd );
|
||||
|
||||
trace = gEngfuncs.CL_TraceLine( vecSrc, vecEnd, PM_WORLD_ONLY );
|
||||
pmtrace_t trace = gEngfuncs.CL_TraceLine( vecSrc, vecEnd, PM_WORLD_ONLY );
|
||||
msurface_t *psurf;
|
||||
if( trace.ent > 0 )
|
||||
psurf = gEngfuncs.EV_TraceSurface( trace.ent, vecSrc, vecEnd );
|
||||
else
|
||||
@@ -562,9 +556,6 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
|
||||
if(( light.r + light.g + light.b ) == 0 )
|
||||
{
|
||||
colorVec gcolor;
|
||||
float grad[4];
|
||||
|
||||
VectorScale( lightDir, 2048.0f, vecEnd );
|
||||
VectorAdd( vecEnd, vecSrc, vecEnd );
|
||||
|
||||
@@ -572,6 +563,9 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
|
||||
if( VectorIsNull( lightvec ))
|
||||
{
|
||||
float grad[4];
|
||||
colorVec gcolor;
|
||||
|
||||
vecSrc[0] -= 16.0f;
|
||||
vecSrc[1] -= 16.0f;
|
||||
vecEnd[0] -= 16.0f;
|
||||
@@ -615,27 +609,29 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
light.b *= ent->curstate.iuser4 / 10.0f;
|
||||
}
|
||||
|
||||
vec3_t finalLight;
|
||||
VectorSet( finalLight, light.r, light.g, light.b );
|
||||
ent->cvFloorColor = light;
|
||||
|
||||
total = Q_max( Q_max( light.r, light.g ), light.b );
|
||||
float total = Q_max( Q_max( light.r, light.g ), light.b );
|
||||
if( total == 0.0f )
|
||||
total = 1.0f;
|
||||
|
||||
// scale lightdir by light intentsity
|
||||
VectorScale( lightDir, total, lightDir );
|
||||
|
||||
for( lnum = 0; lnum < MAX_DLIGHTS; lnum++ )
|
||||
for( uint lnum = 0; lnum < MAX_DLIGHTS; lnum++ )
|
||||
{
|
||||
dl = &gp_dlights[lnum];
|
||||
const dlight_t *dl = &gp_dlights[lnum];
|
||||
|
||||
if( dl->die < time || !r_dynamic->value )
|
||||
continue;
|
||||
|
||||
vec3_t dist;
|
||||
VectorSubtract( ent->origin, dl->origin, dist );
|
||||
|
||||
radius = VectorLength( dist );
|
||||
add = ( dl->radius - radius );
|
||||
float radius = VectorLength( dist );
|
||||
float add = ( dl->radius - radius );
|
||||
|
||||
if( add > 0.0f )
|
||||
{
|
||||
@@ -654,14 +650,15 @@ void R_EntityDynamicLight( cl_entity_t *ent, alight_t *plight, qboolean draw_wor
|
||||
}
|
||||
}
|
||||
|
||||
float scale;
|
||||
if( ent->model->type == mod_alias )
|
||||
add = 0.9f;
|
||||
scale = 0.9f;
|
||||
else if( ent->model->type == mod_studio && FBitSet( ent->model->flags, STUDIO_AMBIENT_LIGHT ))
|
||||
add = 0.6f;
|
||||
scale = 0.6f;
|
||||
else
|
||||
add = bound( 0.75f, v_direct->value, 1.0f );
|
||||
scale = bound( 0.75f, v_direct->value, 1.0f );
|
||||
|
||||
VectorScale( lightDir, add, lightDir );
|
||||
VectorScale( lightDir, scale, lightDir );
|
||||
|
||||
plight->shadelight = VectorLength( lightDir );
|
||||
plight->ambientlight = total - plight->shadelight;
|
||||
|
||||
@@ -140,15 +140,14 @@ static void Matrix4x4_CreateTranslate( matrix4x4 out, float x, float y, float z
|
||||
|
||||
static void Matrix4x4_CreateRotate( matrix4x4 out, float angle, float x, float y, float z )
|
||||
{
|
||||
float len, c, s;
|
||||
|
||||
len = x * x + y * y + z * z;
|
||||
float len = x * x + y * y + z * z;
|
||||
if( len != 0.0f )
|
||||
len = 1.0f / sqrt( len );
|
||||
x *= len;
|
||||
y *= len;
|
||||
z *= len;
|
||||
|
||||
float c, s;
|
||||
angle *= ( -M_PI_F / 180.0f );
|
||||
SinCos( angle, &s, &c );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user