diff --git a/ref/gl/gl2_shim/gl2_shim.c b/ref/gl/gl2_shim/gl2_shim.c index e2bf2c45..d88b2ab9 100644 --- a/ref/gl/gl2_shim/gl2_shim.c +++ b/ref/gl/gl2_shim/gl2_shim.c @@ -216,14 +216,12 @@ static char *GL_PrintInfoLog( GLhandleARB object, qboolean program ) static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type ) { - char *shader, shader_buf[MAX_SHADERLEN + 1]; + char shader_buf[MAX_SHADERLEN + 1]; char tmp[256]; - int i; - GLint status, len; - GLuint id, loc; - int version = gl2wrap_config.version; + GLint status; + const int version = gl2wrap_config.version; - shader = shader_buf; + char *shader = shader_buf; //shader[0] = '\n'; shader[0] = 0; @@ -232,7 +230,7 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type ) Q_snprintf( tmp, sizeof( tmp ), "#define VER %d\n", version ); Q_strncat( shader, tmp, MAX_SHADERLEN ); - for( i = 0; i < GL2_FLAG_MAX; ++i ) + for( int i = 0; i < GL2_FLAG_MAX; ++i ) { Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", gl2wrap_flag_name[i], FBitSet( prog->flags, BIT( i ))); Q_strncat( shader, tmp, MAX_SHADERLEN ); @@ -240,8 +238,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type ) if( version >= 310 ) { - loc = 0; - for( i = 0; i < GL2_ATTR_MAX; ++i ) + GLuint loc = 0; + for( int i = 0; i < GL2_ATTR_MAX; ++i ) { if( FBitSet( prog->flags, BIT( i ))) { @@ -262,8 +260,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type ) else Q_strncat( shader, gl2wrap_vert_src, MAX_SHADERLEN ); - id = pglCreateShaderObjectARB( type ); - len = Q_strlen( shader ); + GLuint id = pglCreateShaderObjectARB( type ); + GLint len = Q_strlen( shader ); pglShaderSourceARB( id, 1, (void *)&shader, &len ); pglCompileShaderARB( id ); pglGetObjectParameterivARB( id, GL_OBJECT_COMPILE_STATUS_ARB, &status ); @@ -282,9 +280,8 @@ static GLuint GL2_GenerateShader( gl2wrap_prog_t *prog, GLenum type ) static gl2wrap_prog_t *GL2_GetProg( const GLuint flags ) { - int i, loc; - GLuint status = 0, vp, fp, glprog; - gl2wrap_prog_t *prog; + int i; + GLuint status = 0; // try to find existing prog matching this feature set @@ -308,22 +305,22 @@ static gl2wrap_prog_t *GL2_GetProg( const GLuint flags ) // new prog; generate shaders gEngfuncs.Con_DPrintf( S_NOTE "%s: Generating progs for 0x%04x\n", __func__, flags ); - prog = &gl2wrap.progs[i]; + gl2wrap_prog_t *prog = &gl2wrap.progs[i]; prog->flags = flags; - vp = GL2_GenerateShader( prog, GL_VERTEX_SHADER_ARB ); - fp = GL2_GenerateShader( prog, GL_FRAGMENT_SHADER_ARB ); + GLuint vp = GL2_GenerateShader( prog, GL_VERTEX_SHADER_ARB ); + GLuint fp = GL2_GenerateShader( prog, GL_FRAGMENT_SHADER_ARB ); if( !vp || !fp ) { prog->flags = 0; return NULL; } - glprog = pglCreateProgramObjectARB(); + GLuint glprog = pglCreateProgramObjectARB(); pglAttachObjectARB( glprog, vp ); pglAttachObjectARB( glprog, fp ); - loc = 0; + int loc = 0; for( i = 0; i < GL2_ATTR_MAX; ++i ) { if( FBitSet( flags, BIT( i ))) @@ -383,9 +380,7 @@ static gl2wrap_prog_t *GL2_GetProg( const GLuint flags ) { if( gl2wrap_config.vao_mandatory || gl2wrap_config.incremental ) { - int j; - - for( j = 0; j < gl2wrap_config.cycle_buffers; j++ ) + for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ ) { pglBindVertexArray( prog->vao_begin[j] ); pglEnableVertexAttribArrayARB( prog->attridx[i] ); @@ -449,13 +444,11 @@ static gl2wrap_prog_t *GL2_SetProg( const GLuint flags ) static void GL2_InitTriQuads( void ) { - int i; - for( i = 0; i < ( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ); i++ ) + for( int i = 0; i < ( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ); i++ ) { - int j; GLushort triquads_array[TRIQUADS_SIZE]; - for( j = 0; j < TRIQUADS_SIZE / 6; j++ ) + for( int j = 0; j < TRIQUADS_SIZE / 6; j++ ) { triquads_array[j * 6] = j * 4 + i; triquads_array[j * 6 + 1] = j * 4 + 1 + i; @@ -474,19 +467,17 @@ static void GL2_InitTriQuads( void ) static void GL2_InitIncrementalBuffer( int i, GLuint size ) { - int j; - gl2wrap.attrbufobj[i] = Mem_Calloc( r_temppool, gl2wrap_config.cycle_buffers * sizeof( GLuint )); if( gl2wrap_config.buf_storage ) gl2wrap.mappings[i] = Mem_Calloc( r_temppool, gl2wrap_config.cycle_buffers * sizeof( void * )); pglGenBuffersARB( gl2wrap_config.cycle_buffers, gl2wrap.attrbufobj[i] ); - for( j = 0; j < gl2wrap_config.cycle_buffers; j++ ) + for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ ) { rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] ); if( gl2wrap_config.buf_storage ) { - GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | + const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT ); pglBufferStorage( GL_ARRAY_BUFFER_ARB, size, NULL, GL_MAP_WRITE_BIT | MB( gl2wrap_config.coherent, COHERENT ) | GL_MAP_PERSISTENT_BIT ); gl2wrap.mappings[i][j] = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, flags ); @@ -512,10 +503,9 @@ static qboolean GL2_InitProgs( void ) BIT( GL2_ATTR_POS ) | BIT( GL2_ATTR_TEXCOORD0 ) | BIT( GL2_FLAG_ALPHA_TEST ) | BIT( GL2_FLAG_FOG ), // out = tex0 * ucolor + FEAT_ALPHA_TEST + FEAT_FOG }; const size_t precache_progs_count = sizeof( precache_progs ) / sizeof( precache_progs[0] ); - int i; gEngfuncs.Con_DPrintf( S_NOTE "GL2_InitProgs: Pre-generating %u progs, version %d...\n", (uint)( precache_progs_count ), gl2wrap_config.version ); - for( i = 0; i < (int)( precache_progs_count ); ++i ) + for( int i = 0; i < (int)( precache_progs_count ); ++i ) if( !GL2_GetProg( precache_progs[i] )) return false; return true; @@ -524,7 +514,6 @@ static qboolean GL2_InitProgs( void ) int GL2_ShimInit( void ) { - int i; GLuint total; if( gl2wrap_init ) @@ -612,7 +601,7 @@ int GL2_ShimInit( void ) total = 0; - for( i = 0; i < GL2_ATTR_MAX; ++i ) + for( int i = 0; i < GL2_ATTR_MAX; ++i ) { GLuint size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat ); if( !gl2wrap_config.buf_storage ) @@ -632,9 +621,7 @@ int GL2_ShimInit( void ) pglGenBuffersARB( gl2wrap_config.cycle_buffers, gl2wrap.attrbufobj[i] ); if( gl2wrap_config.supports_mapbuffer ) { - int j; - - for( j = 0; j < gl2wrap_config.cycle_buffers; j++ ) + for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ ) { rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] ); pglBufferDataARB( GL_ARRAY_BUFFER_ARB, MAX_BEGINEND_VERTS, NULL, GL_STREAM_DRAW_ARB ); @@ -672,8 +659,6 @@ int GL2_ShimInit( void ) void GL2_ShimShutdown( void ) { - int i; - if( !gl2wrap_init ) return; @@ -682,7 +667,7 @@ void GL2_ShimShutdown( void ) GL2_FreeArrays(); pglDeleteBuffersARB(( !!pglDrawRangeElementsBaseVertex ? 1 : 4 ), gl2wrap.triquads_ibo ); - for( i = 0; i < MAX_PROGS; ++i ) + for( int i = 0; i < MAX_PROGS; ++i ) { if( gl2wrap.progs[i].flags ) { @@ -696,12 +681,11 @@ void GL2_ShimShutdown( void ) } - for( i = 0; i < GL2_ATTR_MAX; ++i ) + for( int i = 0; i < GL2_ATTR_MAX; ++i ) { - int j; if( gl2wrap_config.buf_storage ) { - for( j = 0; j < gl2wrap_config.cycle_buffers; j++ ) + for( int j = 0; j < gl2wrap_config.cycle_buffers; j++ ) { pglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][j] ); pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); @@ -726,8 +710,6 @@ void GL2_ShimShutdown( void ) static void GL2_ResetPersistentBuffer( void ) { - int i; - #ifdef QUAD_BATCH GL2_FlushPrims(); #endif @@ -736,13 +718,13 @@ static void GL2_ResetPersistentBuffer( void ) if( gl2wrap_config.incremental ) { gl2wrap.attrbufcycle = ( gl2wrap.attrbufcycle + 1 ) % gl2wrap_config.cycle_buffers; - for( i = 0; i < GL2_ATTR_MAX; ++i ) + for( int i = 0; i < GL2_ATTR_MAX; ++i ) { - int size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat ); + const int size = GL2_MAX_VERTS * gl2wrap_attr_size[i] * sizeof( GLfloat ); rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][gl2wrap.attrbufcycle] ); if( gl2wrap_config.buf_storage ) { - GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | + const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT ); pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); gl2wrap.mappings[i][gl2wrap.attrbufcycle] = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, 0, size, flags ); @@ -802,19 +784,17 @@ When buffer storage not supported, we still may use cached VAO, but map/unmap it */ static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count ) { - int i; if( !gl2wrap_config.buf_storage ) { - for( i = 0; i < GL2_ATTR_MAX; i++ ) + for( int i = 0; i < GL2_ATTR_MAX; i++ ) { if( prog->attridx[i] >= 0 ) { - void *mem; - GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | + const GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | MB( gl2wrap_config.async, UNSYNCHRONIZED ) | MB( gl2wrap_config.force_flush, FLUSH_EXPLICIT ); rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap.attrbufobj[i][gl2wrap.attrbufcycle] ); - mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_attr_size[i] * 4 * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count, flags ); + void *mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_attr_size[i] * 4 * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count, flags ); memcpy( mem, gl2wrap.attrbuf[i] + gl2wrap_attr_size[i] * gl2wrap.begin, gl2wrap_attr_size[i] * 4 * count ); if( gl2wrap_config.force_flush ) pglFlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, gl2wrap_attr_size[i] * 4 * count ); @@ -825,7 +805,7 @@ static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count ) else if( !gl2wrap_config.coherent ) { // non-coherent buffers anyway require unmapping or flushing after write - for( i = 0; i < GL2_ATTR_MAX; i++ ) + for( int i = 0; i < GL2_ATTR_MAX; i++ ) { if( prog->attridx[i] >= 0 ) { @@ -838,10 +818,9 @@ static void GL2_UpdateIncrementalBuffer( gl2wrap_prog_t *prog, int count ) static void GL2_FlushPrims( void ) { - int i; int startindex = 0; GLuint flags = gl2wrap.cur_flags; - GLint count = gl2wrap.end - gl2wrap.begin; + const GLint count = gl2wrap.end - gl2wrap.begin; gl2wrap_prog_t *prog; if( !gl2wrap.prim || !count ) @@ -856,7 +835,7 @@ static void GL2_FlushPrims( void ) // disable all vertex attrib pointers if( !gl2wrap_config.vao_mandatory ) { - for( i = 0; i < GL2_ATTR_MAX; ++i ) + for( int i = 0; i < GL2_ATTR_MAX; ++i ) pglDisableVertexAttribArrayARB( i ); } @@ -877,7 +856,7 @@ static void GL2_FlushPrims( void ) { if( gl2wrap_config.vao_mandatory ) pglBindVertexArray( prog->vao_begin[gl2wrap.attrbufcycle] ); - for( i = 0; i < GL2_ATTR_MAX; ++i ) + for( int i = 0; i < GL2_ATTR_MAX; ++i ) { if( prog->attridx[i] >= 0 ) { @@ -1006,12 +985,13 @@ static void APIENTRY GL2_TexImage2D( GLenum target, GLint level, GLint internalf internalformat == GL_LUMINANCE8 || internalformat == GL_LUMINANCE4 )) // strip alpha from texture { - unsigned char *in = data, *out; - int i = 0, size = width * height * 4; + unsigned char *in = data; + const int size = width * height * 4; + unsigned char *out = (unsigned char *)malloc( size ); - data = out = (unsigned char *)malloc( size ); + data = out; - for( i = 0; i < size; i += 4, in += 4, out += 4 ) + for( int i = 0; i < size; i += 4, in += 4, out += 4 ) { memcpy( out, in, 3 ); out[3] = 255; @@ -1450,7 +1430,7 @@ static void GL2_UpdatePersistentArrayBuffer( gl2wrap_prog_t *prog, int size, int { if( gl2wrap_arrays.stream_counter + size > GL2_MAX_VERTS * 64 ) { - GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | + const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT ); pglUnmapBufferARB( GL_ARRAY_BUFFER_ARB ); gl2wrap_arrays.stream_counter = 0; @@ -1476,9 +1456,8 @@ Like persistent buffer, but map every time when copying data when BufferStorage */ static void GL2_UpdateIncrementalArrayBuffer( gl2wrap_prog_t *prog, int size, int offset, GLuint start, GLuint end, int stride, int attr ) { - void *mem; qboolean inv = false; - GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | MB( inv,INVALIDATE_BUFFER ) | + const GLuint flags = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT | MB( inv,INVALIDATE_BUFFER ) | MB( gl2wrap_config.async, UNSYNCHRONIZED ) | MB( gl2wrap_config.force_flush, FLUSH_EXPLICIT ); if( gl2wrap_arrays.stream_counter + size > GL2_MAX_VERTS * 64 ) @@ -1488,7 +1467,7 @@ static void GL2_UpdateIncrementalArrayBuffer( gl2wrap_prog_t *prog, int size, in gl2wrap_arrays.stream_counter = 0; inv = true; } - mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_counter, size, flags ); + void *mem = pglMapBufferRange( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_counter, size, flags ); memcpy( mem, ((char *)gl2wrap_arrays.ptr[attr].userptr ) + offset, size ); if( gl2wrap_config.force_flush ) pglFlushMappedBufferRange( GL_ARRAY_BUFFER_ARB, 0, size ); @@ -1506,7 +1485,7 @@ Prepare BufferStorage */ static void GL2_AllocArrayPersistenStorage( void ) { - GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | + const GLuint flags = GL_MAP_WRITE_BIT | MB( !gl2wrap_config.coherent, FLUSH_EXPLICIT ) | GL_MAP_PERSISTENT_BIT | MB( gl2wrap_config.coherent, COHERENT ); pglGenBuffersARB( 1, &gl2wrap_arrays.stream_buffer ); rpglBindBufferARB( GL_ARRAY_BUFFER_ARB, gl2wrap_arrays.stream_buffer ); @@ -1552,9 +1531,7 @@ Usage of client pointers is forbidden with non-default VAO and unavailiable in C */ static void GL2_SetupArrays( GLuint start, GLuint end ) { - gl2wrap_prog_t *prog; unsigned int flags = gl2wrap_arrays.flags; - int i; if( !flags ) return; // Legacy pointers not used @@ -1567,7 +1544,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) SetBits( flags, BIT( GL2_FLAG_ALPHA_TEST )); if( gl2wrap_state.fog ) SetBits( flags, BIT( GL2_FLAG_FOG )); - prog = GL2_SetProg( flags );// | GL2_ATTR_TEXCOORD0 ); + gl2wrap_prog_t *prog = GL2_SetProg( flags );// | GL2_ATTR_TEXCOORD0 ); if( !prog ) return; @@ -1578,7 +1555,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) pglBindVertexArray( gl2wrap_arrays.vao_dynamic ); } - for( i = 0; i < GL2_ATTR_MAX; i++ ) + for( int i = 0; i < GL2_ATTR_MAX; i++ ) { if( prog->attridx[i] < 0 ) continue; @@ -1590,7 +1567,7 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) if( gl2wrap_config.vao_mandatory && !gl2wrap_arrays.ptr[i].vbo ) { // detect stride by type - int stride = gl2wrap_arrays.ptr[i].stride, size, offset; + int stride = gl2wrap_arrays.ptr[i].stride; if( stride == 0 ) { @@ -1610,8 +1587,8 @@ static void GL2_SetupArrays( GLuint start, GLuint end ) gEngfuncs.Con_Printf( S_ERROR "NON-vbo array for DrawElements call, SKIPPING!\n" ); continue; } - size = ( end - start ) * stride; - offset = start * stride; + int size = ( end - start ) * stride; + int offset = start * stride; // Logical buffer start can lie before real buffer start // but attrib pointer cannot have negative buffer offset diff --git a/ref/gl/gl_alias.c b/ref/gl/gl_alias.c index 543213cd..b6ed8aab 100644 --- a/ref/gl/gl_alias.c +++ b/ref/gl/gl_alias.c @@ -86,12 +86,9 @@ StripLength */ static int StripLength( int starttri, int startv ) { - int m1, m2, j, k; - dtriangle_t *last, *check; - g_used[starttri] = 2; - last = &g_triangles[starttri]; + dtriangle_t *last = &g_triangles[starttri]; g_stripverts[0] = last->vertindex[(startv+0) % 3]; g_stripverts[1] = last->vertindex[(startv+1) % 3]; @@ -100,8 +97,10 @@ static int StripLength( int starttri, int startv ) g_striptris[0] = starttri; g_stripcount = 1; - m1 = last->vertindex[(startv+2)%3]; - m2 = last->vertindex[(startv+1)%3]; + int m1 = last->vertindex[(startv+2)%3]; + int m2 = last->vertindex[(startv+1)%3]; + int j; + dtriangle_t *check; nexttri: // look for a matching triangle for( j = starttri + 1, check = &g_triangles[starttri + 1]; j < m_pAliasHeader->numtris; j++, check++ ) @@ -109,7 +108,7 @@ nexttri: if( check->facesfront != last->facesfront ) continue; - for( k = 0; k < 3; k++ ) + for( int k = 0; k < 3; k++ ) { if( check->vertindex[k] != m1 ) continue; @@ -152,12 +151,9 @@ FanLength */ static int FanLength( int starttri, int startv ) { - int m1, m2, j, k; - dtriangle_t *last, *check; - g_used[starttri] = 2; - last = &g_triangles[starttri]; + dtriangle_t *last = &g_triangles[starttri]; g_stripverts[0] = last->vertindex[(startv+0) % 3]; g_stripverts[1] = last->vertindex[(startv+1) % 3]; @@ -166,8 +162,10 @@ static int FanLength( int starttri, int startv ) g_striptris[0] = starttri; g_stripcount = 1; - m1 = last->vertindex[(startv+0) % 3]; - m2 = last->vertindex[(startv+2) % 3]; + int m1 = last->vertindex[(startv+0) % 3]; + int m2 = last->vertindex[(startv+2) % 3]; + int j; + dtriangle_t *check; nexttri: // look for a matching triangle @@ -176,7 +174,7 @@ nexttri: if( check->facesfront != last->facesfront ) continue; - for( k = 0; k < 3; k++ ) + for( int k = 0; k < 3; k++ ) { if( check->vertindex[k] != m1 ) continue; @@ -219,12 +217,8 @@ for the model, which holds for all frames */ static void BuildTris( void ) { - int len, bestlen, besttype = 0; - int bestverts[1024]; - int besttris[1024]; - int type, startv; - int i, j, k; - float s, t; + int bestverts[1024]; + int besttris[1024]; // // build tristrips @@ -233,16 +227,18 @@ static void BuildTris( void ) g_numcommands = 0; g_numorder = 0; - for( i = 0; i < m_pAliasHeader->numtris; i++ ) + for( int i = 0; i < m_pAliasHeader->numtris; i++ ) { // pick an unused triangle and start the trifan if( g_used[i] ) continue; - bestlen = 0; - for( type = 0; type < 2; type++ ) + int bestlen = 0; + int besttype = 0; + for( int type = 0; type < 2; type++ ) { - for( startv = 0; startv < 3; startv++ ) + for( int startv = 0; startv < 3; startv++ ) { + int len; if( type == 1 ) len = StripLength( i, startv ); else len = FanLength( i, startv ); @@ -251,32 +247,32 @@ static void BuildTris( void ) besttype = type; bestlen = len; - for( j = 0; j < bestlen + 2; j++ ) + for( int j = 0; j < bestlen + 2; j++ ) bestverts[j] = g_stripverts[j]; - for( j = 0; j < bestlen; j++ ) + for( int j = 0; j < bestlen; j++ ) besttris[j] = g_striptris[j]; } } } // mark the tris on the best strip as used - for( j = 0; j < bestlen; j++ ) + for( int j = 0; j < bestlen; j++ ) g_used[besttris[j]] = 1; if( besttype == 1 ) g_commands[g_numcommands++] = (bestlen + 2); else g_commands[g_numcommands++] = -(bestlen + 2); - for( j = 0; j < bestlen + 2; j++ ) + for( int j = 0; j < bestlen + 2; j++ ) { // emit a vertex into the reorder buffer - k = bestverts[j]; + int k = bestverts[j]; g_vertexorder[g_numorder++] = k; // emit s/t coords into the commands stream - s = g_stverts[k].s; - t = g_stverts[k].t; + float s = g_stverts[k].s; + float t = g_stverts[k].t; if( !g_triangles[besttris[0]].facesfront && g_stverts[k].onseam ) s += m_pAliasHeader->skinwidth / 2; // on back side @@ -299,9 +295,6 @@ GL_MakeAliasModelDisplayLists */ static void GL_MakeAliasModelDisplayLists( model_t *m ) { - trivertex_t *verts; - int i, j; - BuildTris( ); // save the data out @@ -311,11 +304,11 @@ static void GL_MakeAliasModelDisplayLists( model_t *m ) memcpy( m_pAliasHeader->commands, g_commands, g_numcommands * 4 ); m_pAliasHeader->posedata = Mem_Malloc( m->mempool, m_pAliasHeader->numposes * m_pAliasHeader->poseverts * sizeof( trivertex_t )); - verts = m_pAliasHeader->posedata; + trivertex_t *verts = m_pAliasHeader->posedata; - for( i = 0; i < m_pAliasHeader->numposes; i++ ) + for( int i = 0; i < m_pAliasHeader->numposes; i++ ) { - for( j = 0; j < g_numorder; j++ ) + for( int j = 0; j < g_numorder; j++ ) *verts++ = m_pAliasHeader->pposeverts[i][g_vertexorder[j]]; } } @@ -336,8 +329,7 @@ Mod_CreateSkinData */ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width, int height ) { - static rgbdata_t skin; - int i; + static rgbdata_t skin; skin.width = width; skin.height = height; @@ -352,7 +344,7 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width, if( !gEngfuncs.Image_CustomPalette() ) { - for( i = 0; i < skin.width * skin.height; i++ ) + for( int i = 0; i < skin.width * skin.height; i++ ) { if( data[i] > 224 && data[i] != 255 ) { @@ -365,13 +357,10 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width, // for alias models only player can have remap textures if( mod != NULL && !Q_stricmp( mod->name, "player" )) { - texture_t *tx = NULL; - int i, size; - - i = mod->numtextures; + int i = mod->numtextures; mod->textures = (texture_t **)Mem_Realloc( mod->mempool, mod->textures, ( i + 1 ) * sizeof( texture_t* )); - size = width * height + 768; - tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size ); + int size = width * height + 768; + texture_t *tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size ); mod->textures[i] = tx; Q_strncpy( tx->name, "DM_Skin", sizeof( tx->name )); @@ -396,11 +385,12 @@ static rgbdata_t *Mod_CreateSkinData( model_t *mod, const byte *data, int width, static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_t *pskintype, int skinnum, int size ) { const byte *ptexture = (const byte *)&pskintype[1]; - rgbdata_t *pic; - string name, lumaname, checkname; + string name, checkname; Q_snprintf( name, sizeof( name ), "%s:frame%i", loadmodel->name, skinnum ); Q_snprintf( checkname, sizeof( checkname ), "%s_%i.tga", loadmodel->name, skinnum ); + + rgbdata_t *pic; if( !gEngfuncs.fsapi->FileExists( checkname, false ) || ( pic = gEngfuncs.FS_LoadImage( checkname, NULL, 0 )) == NULL ) pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight ); @@ -412,6 +402,7 @@ static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_ if( FBitSet( R_GetTexture( m_pAliasHeader->gl_texturenum[skinnum][0] )->flags, TF_HAS_LUMA )) { + string lumaname; Q_snprintf( lumaname, sizeof( lumaname ), "%s:luma%i", loadmodel->name, skinnum ); pic = Mod_CreateSkinData( NULL, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight ); @@ -427,27 +418,23 @@ static const void *Mod_LoadSingleSkin( model_t *loadmodel, const daliasskintype_ static const void *Mod_LoadGroupSkin( model_t *loadmodel, const daliasskintype_t *pskintype, int skinnum, int size ) { - const daliasskininterval_t *pinskinintervals; - const daliasskingroup_t *pinskingroup; - const byte *ptexture; - rgbdata_t *pic; - string name, lumaname; - int i, j; - // animating skin group. yuck. - pinskingroup = (const daliasskingroup_t *)&pskintype[1]; - pinskinintervals = (const daliasskininterval_t *)(&pinskingroup[1]); - ptexture = (const byte *)&pinskinintervals[pinskingroup->numskins]; + const daliasskingroup_t *pinskingroup = (const daliasskingroup_t *)&pskintype[1]; + const daliasskininterval_t *pinskinintervals = (const daliasskininterval_t *)(&pinskingroup[1]); + const byte *ptexture = (const byte *)&pinskinintervals[pinskingroup->numskins]; + int i; for( i = 0; i < pinskingroup->numskins; i++ ) { + string name; Q_snprintf( name, sizeof( name ), "%s_%i_%i", loadmodel->name, skinnum, i ); - pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight ); + rgbdata_t *pic = Mod_CreateSkinData( loadmodel, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight ); m_pAliasHeader->gl_texturenum[skinnum][i & 3] = GL_LoadTextureInternal( name, pic, 0 ); gEngfuncs.FS_FreeImage( pic ); if( FBitSet( R_GetTexture( m_pAliasHeader->gl_texturenum[skinnum][i & 3] )->flags, TF_HAS_LUMA )) { + string lumaname; Q_snprintf( lumaname, sizeof( lumaname ), "%s_%i_%i_luma", loadmodel->name, skinnum, i ); pic = Mod_CreateSkinData( NULL, ptexture, m_pAliasHeader->skinwidth, m_pAliasHeader->skinheight ); m_pAliasHeader->fb_texturenum[skinnum][i & 3] = GL_LoadTextureInternal( lumaname, pic, TF_MAKELUMA ); @@ -457,7 +444,7 @@ static const void *Mod_LoadGroupSkin( model_t *loadmodel, const daliasskintype_t ptexture += size; } - for( j = i; i < 4; i++ ) + for( int j = i; i < 4; i++ ) { m_pAliasHeader->gl_texturenum[skinnum][i & 3] = m_pAliasHeader->gl_texturenum[skinnum][i - j]; m_pAliasHeader->fb_texturenum[skinnum][i & 3] = m_pAliasHeader->fb_texturenum[skinnum][i - j]; @@ -473,12 +460,10 @@ Mod_LoadAllSkins */ static const void *Mod_LoadAllSkins( model_t *mod, int numskins, const daliasskintype_t *pskintype ) { - int i, size; - - size = m_pAliasHeader->skinwidth * m_pAliasHeader->skinheight; + int size = m_pAliasHeader->skinwidth * m_pAliasHeader->skinheight; // TODO: texture replacement support here - for( i = 0; i < numskins; i++ ) + for( int i = 0; i < numskins; i++ ) { if( pskintype->type == ALIAS_SKIN_SINGLE ) pskintype = Mod_LoadSingleSkin( mod, pskintype, i, size ); @@ -498,27 +483,22 @@ Mod_LoadAliasModel */ void Mod_LoadAliasModel( model_t *mod, const void *buffer, qboolean *loaded ) { - const daliasskintype_t *pskintype; - const dtriangle_t *pintriangles; - const daliashdr_t *pinmodel; - const stvert_t *pinstverts; - if( loaded ) *loaded = false; - pinmodel = (const daliashdr_t *)buffer; + const daliashdr_t *pinmodel = (const daliashdr_t *)buffer; m_pAliasHeader = mod->cache.data; if( !m_pAliasHeader ) return; // load the skins - pskintype = (const daliasskintype_t *)&pinmodel[1]; + const daliasskintype_t *pskintype = (const daliasskintype_t *)&pinmodel[1]; pskintype = Mod_LoadAllSkins( mod, m_pAliasHeader->numskins, pskintype ); // load base s and t vertices - pinstverts = (const stvert_t *)pskintype; + const stvert_t *pinstverts = (const stvert_t *)pskintype; memset( g_stverts, 0, sizeof( g_stverts )); memcpy( g_stverts, pinstverts, sizeof( g_stverts[0] ) * m_pAliasHeader->numverts ); // load triangle lists - pintriangles = (const dtriangle_t *)&pinstverts[m_pAliasHeader->numverts]; + const dtriangle_t *pintriangles = (const dtriangle_t *)&pinstverts[m_pAliasHeader->numverts]; memset( g_triangles, 0, sizeof( g_triangles )); memcpy( g_triangles, pintriangles, sizeof( g_triangles[0] ) * m_pAliasHeader->numtris ); @@ -532,18 +512,15 @@ void Mod_LoadAliasModel( model_t *mod, const void *buffer, qboolean *loaded ) void Mod_AliasUnloadTextures( void *data ) { - aliashdr_t *palias; - int i, j; - - palias = data; + aliashdr_t *palias = data; if( !palias ) return; // already freed - for( i = 0; i < MAX_SKINS; i++ ) + for( int i = 0; i < MAX_SKINS; i++ ) { if( !palias->gl_texturenum[i][0] ) break; - for( j = 0; j < 4; j++ ) + for( int j = 0; j < 4; j++ ) { GL_FreeTexture( palias->gl_texturenum[i][j] ); GL_FreeTexture( palias->fb_texturenum[i][j] ); @@ -588,15 +565,14 @@ R_AliasLighting */ static void R_AliasLighting( float *lv, const vec3_t normal ) { - float illum = g_alias.ambientlight; - float r, lightcos; + float illum = g_alias.ambientlight; - lightcos = DotProduct( normal, g_alias.lightvec_local ); // -1 colinear, 1 opposite + float lightcos = DotProduct( normal, g_alias.lightvec_local ); // -1 colinear, 1 opposite if( lightcos > 1.0f ) lightcos = 1.0f; illum += g_alias.shadelight; - r = SHADE_LAMBERT; + float r = SHADE_LAMBERT; // do modified hemispherical lighting if( r <= 1.0f ) @@ -637,22 +613,16 @@ GL_DrawAliasFrame */ static void GL_DrawAliasFrame( aliashdr_t *paliashdr ) { - float lv_tmp; - trivertex_t *verts0; - trivertex_t *verts1; - vec3_t vert, norm; - int *order; - int count; - - verts0 = verts1 = paliashdr->posedata; + trivertex_t *verts0 = paliashdr->posedata; + trivertex_t *verts1 = paliashdr->posedata; verts0 += g_alias.oldpose * paliashdr->poseverts; verts1 += g_alias.newpose * paliashdr->poseverts; - order = paliashdr->commands; + int *order = paliashdr->commands; while( 1 ) { // get the vertex count and primitive type - count = *order++; + int count = *order++; if( !count ) break; // done if( count < 0 ) @@ -679,10 +649,13 @@ static void GL_DrawAliasFrame( aliashdr_t *paliashdr ) } order += 2; + vec3_t norm; VectorLerp( m_bytenormals[verts0->lightnormalindex], g_alias.lerpfrac, m_bytenormals[verts1->lightnormalindex], norm ); VectorNormalize( norm ); + float lv_tmp; R_AliasLighting( &lv_tmp, norm ); pglColor4f( g_alias.lightcolor[0] * lv_tmp, g_alias.lightcolor[1] * lv_tmp, g_alias.lightcolor[2] * lv_tmp, tr.blend ); + vec3_t vert; VectorLerp( verts0->v, g_alias.lerpfrac, verts1->v, vert ); pglVertex3fv( vert ); verts0++, verts1++; @@ -699,33 +672,27 @@ GL_DrawAliasShadow */ static void GL_DrawAliasShadow( aliashdr_t *paliashdr ) { - trivertex_t *verts0; - trivertex_t *verts1; - float vec_x, vec_y; - vec3_t av, point; - int *order; - int count; - if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW )) return; if( glState.stencilEnabled ) pglEnable( GL_STENCIL_TEST ); - vec_x = -g_alias.lightvec[0] * 8.0f; - vec_y = -g_alias.lightvec[1] * 8.0f; + float vec_x = -g_alias.lightvec[0] * 8.0f; + float vec_y = -g_alias.lightvec[1] * 8.0f; r_stats.c_alias_polys += paliashdr->numtris; - verts0 = verts1 = paliashdr->posedata; + trivertex_t *verts0 = paliashdr->posedata; + trivertex_t *verts1 = paliashdr->posedata; verts0 += g_alias.oldpose * paliashdr->poseverts; verts1 += g_alias.newpose * paliashdr->poseverts; - order = paliashdr->commands; + int *order = paliashdr->commands; while( 1 ) { // get the vertex count and primitive type - count = *order++; + int count = *order++; if( !count ) break; // done if( count < 0 ) @@ -745,6 +712,7 @@ static void GL_DrawAliasShadow( aliashdr_t *paliashdr ) order += 2; // normals and vertexes come from the frame list + vec3_t av, point; VectorLerp( verts0->v, g_alias.lerpfrac, verts1->v, av ); point[0] = av[0] * paliashdr->scale[0] + paliashdr->scale_origin[0]; point[1] = av[1] * paliashdr->scale[1] + paliashdr->scale_origin[1]; @@ -818,13 +786,8 @@ R_SetupAliasFrame */ static void R_SetupAliasFrame( cl_entity_t *e, aliashdr_t *paliashdr ) { - int newpose, oldpose; - int newframe, oldframe; - int numposes, cycle; - float interval; - - oldframe = e->latched.prevframe; - newframe = e->curstate.frame; + int oldframe = e->latched.prevframe; + int newframe = e->curstate.frame; if( newframe < 0 ) { @@ -840,13 +803,14 @@ static void R_SetupAliasFrame( cl_entity_t *e, aliashdr_t *paliashdr ) if(( oldframe >= paliashdr->numframes ) || ( oldframe < 0 )) oldframe = newframe; - numposes = paliashdr->frames[newframe].numposes; + int numposes = paliashdr->frames[newframe].numposes; + int oldpose, newpose; if( numposes > 1 ) { oldpose = newpose = paliashdr->frames[newframe].firstpose; - interval = 1.0f / paliashdr->frames[newframe].interval; - cycle = (int)(g_alias.time * interval); + float interval = 1.0f / paliashdr->frames[newframe].interval; + int cycle = (int)(g_alias.time * interval); oldpose += (cycle + 0) % numposes; // lerpframe from newpose += (cycle + 1) % numposes; // lerpframe to g_alias.lerpfrac = ( g_alias.time * interval ); @@ -872,15 +836,13 @@ R_StudioDrawAbsBBox */ static void R_AliasDrawAbsBBox( cl_entity_t *e, const vec3_t absmin, const vec3_t absmax ) { - vec3_t p[8]; - int i; - // looks ugly, skip if( r_drawentities->value != 5 || e == tr.viewent ) return; // compute a full bounding box - for( i = 0; i < 8; i++ ) + vec3_t p[8]; + for( int i = 0; i < 8; i++ ) { p[i][0] = ( i & 1 ) ? absmin[0] : absmax[0]; p[i][1] = ( i & 2 ) ? absmin[1] : absmax[1]; @@ -893,7 +855,7 @@ static void R_AliasDrawAbsBBox( cl_entity_t *e, const vec3_t absmin, const vec3_ pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); TriBegin( TRI_QUADS ); - for( i = 0; i < 6; i++ ) + for( int i = 0; i < 6; i++ ) { TriBrightness( g_alias.shadelight / 255.0f ); TriVertex3fv( p[boxpnt[i][0]] ); @@ -971,16 +933,9 @@ R_DrawAliasModel */ void R_DrawAliasModel( cl_entity_t *e ) { - model_t *clmodel; - vec3_t absmin, absmax; - remap_info_t *pinfo = NULL; - int anim, skin; - alight_t lighting; - player_info_t *playerinfo; - vec3_t dir, angles; - - clmodel = RI.currententity->model; + model_t *clmodel = RI.currententity->model; + vec3_t absmin, absmax; VectorAdd( e->origin, clmodel->mins, absmin ); VectorAdd( e->origin, clmodel->maxs, absmax ); @@ -997,6 +952,7 @@ void R_DrawAliasModel( cl_entity_t *e ) R_AliasSetupTimings(); // angles will be modify below keep original + vec3_t angles; VectorCopy( e->angles, angles ); R_AliasLerpMovement( e ); @@ -1010,6 +966,8 @@ void R_DrawAliasModel( cl_entity_t *e ) // // get lighting information // + alight_t lighting; + vec3_t dir; lighting.plightvec = dir; R_EntityDynamicLight( e, &lighting, FBitSet( RI.rvp.flags, RF_DRAW_WORLD ), g_alias.time, g_alias.lightspot, g_alias.lightvec ); @@ -1027,6 +985,7 @@ void R_DrawAliasModel( cl_entity_t *e ) GL_SetRenderMode( e->curstate.rendermode ); // setup remapping only for players + player_info_t *playerinfo; if( e->player && ( playerinfo = pfnPlayerInfo( e->curstate.number - 1 )) != NULL ) { // get remap colors @@ -1046,8 +1005,9 @@ void R_DrawAliasModel( cl_entity_t *e ) pglScalef( m_pAliasHeader->scale[0], m_pAliasHeader->scale[1], m_pAliasHeader->scale[2] ); } - anim = (int)(g_alias.time * 10) & 3; - skin = bound( 0, RI.currententity->curstate.skin, m_pAliasHeader->numskins - 1 ); + int anim = (int)(g_alias.time * 10) & 3; + int skin = bound( 0, RI.currententity->curstate.skin, m_pAliasHeader->numskins - 1 ); + remap_info_t *pinfo = NULL; if( m_fDoRemap ) pinfo = gEngfuncs.CL_GetRemapInfoForEntity( e ); if( r_lightmap->value && !r_fullbright->value ) diff --git a/ref/gl/gl_backend.c b/ref/gl/gl_backend.c index 4e1d5b8e..0b6d0a15 100644 --- a/ref/gl/gl_backend.c +++ b/ref/gl/gl_backend.c @@ -59,14 +59,10 @@ GL_BackendEndFrame */ void GL_BackendEndFrame( void ) { - mleaf_t *curleaf; - if( r_speeds->value <= 0 || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD )) return; - if( !RI.viewleaf ) - curleaf = WORLDMODEL->leafs; - else curleaf = RI.viewleaf; + mleaf_t *curleaf = RI.viewleaf ? RI.viewleaf : WORLDMODEL->leafs; switch( (int)r_speeds->value ) { @@ -180,9 +176,6 @@ GL_Bind */ void GL_Bind( int tmu, unsigned int texnum ) { - const gl_texture_t *texture; - GLuint glTarget; - // missed or invalid texture? if( texnum <= 0 || texnum >= MAX_TEXTURES ) { @@ -195,8 +188,8 @@ void GL_Bind( int tmu, unsigned int texnum ) GL_SelectTexture( tmu ); else tmu = glState.activeTMU; - texture = R_GetTexture( texnum ); - glTarget = texture->target; + const gl_texture_t *texture = R_GetTexture( texnum ); + GLuint glTarget = texture->target; if( glTarget == GL_TEXTURE_2D_ARRAY_EXT ) glTarget = GL_TEXTURE_2D; @@ -236,9 +229,7 @@ GL_CleanUpTextureUnits */ void GL_CleanUpTextureUnits( int last ) { - int i; - - for( i = glState.activeTMU; i > (last - 1); i-- ) + for( int i = glState.activeTMU; i > (last - 1); i-- ) { // disable upper units if( glState.currentTextureTargets[i] != GL_NONE ) @@ -556,12 +547,10 @@ static const envmap_t r_envMapInfo[6] = qboolean VID_ScreenShot( const char *filename, int shot_type ) { - rgbdata_t *r_shot; - uint flags = IMAGE_FLIP_Y; - int width = 0, height = 0; - qboolean result; + uint flags = IMAGE_FLIP_Y; + int width = 0, height = 0; - r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); + rgbdata_t *r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); r_shot->width = (gpGlobals->width + 3) & ~3; r_shot->height = (gpGlobals->height + 3) & ~3; r_shot->flags = IMAGE_HAS_COLOR; @@ -596,7 +585,7 @@ qboolean VID_ScreenShot( const char *filename, int shot_type ) gEngfuncs.Image_Process( &r_shot, width, height, flags, 0.0f ); // write image - result = gEngfuncs.FS_SaveImage( filename, r_shot ); + qboolean result = gEngfuncs.FS_SaveImage( filename, r_shot ); gEngfuncs.fsapi->AllowDirectPaths( false ); // always reset after store screenshot gEngfuncs.FS_FreeImage( r_shot ); @@ -610,16 +599,11 @@ VID_CubemapShot */ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qboolean skyshot ) { - rgbdata_t *r_shot, *r_side; - byte *temp = NULL; - byte *buffer = NULL; - string basename; - int i = 1, flags, result; - if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || !WORLDMODEL ) return false; // make sure the specified size is valid + int i = 1; while( i < size ) i<<=1; if( i != size ) return false; @@ -627,10 +611,10 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo return false; // alloc space - temp = Mem_Malloc( r_temppool, size * size * 3 ); - buffer = Mem_Malloc( r_temppool, size * size * 3 * 6 ); - r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); - r_side = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); + byte *temp = Mem_Malloc( r_temppool, size * size * 3 ); + byte *buffer = Mem_Malloc( r_temppool, size * size * 3 * 6 ); + rgbdata_t *r_shot = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); + rgbdata_t *r_side = Mem_Calloc( r_temppool, sizeof( rgbdata_t )); // use client vieworg if( !vieworg ) vieworg = RI.rvp.vieworigin; @@ -640,6 +624,7 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo // go into 3d mode R_Set2DMode( false ); + int flags; if( skyshot ) { R_DrawCubemapView( vieworg, r_skyBoxInfo[i].angles, size ); @@ -672,11 +657,12 @@ qboolean VID_CubemapShot( const char *base, uint size, const float *vieworg, qbo r_shot->buffer = buffer; // make sure what we have right extension + string basename; Q_strncpy( basename, base, sizeof( basename )); COM_ReplaceExtension( basename, ".tga", sizeof( basename )); // write image as 6 sides - result = gEngfuncs.FS_SaveImage( basename, r_shot ); + int result = gEngfuncs.FS_SaveImage( basename, r_shot ); gEngfuncs.FS_FreeImage( r_shot ); gEngfuncs.FS_FreeImage( r_side ); @@ -693,20 +679,16 @@ timerefresh [noflip] */ void SCR_TimeRefresh_f( void ) { - int i; - double start, stop; - double time; - if( ENGINE_GET_PARM( PARM_CONNSTATE ) != ca_active ) return; - start = gEngfuncs.pfnTime(); + double start = gEngfuncs.pfnTime(); // run without page flipping like GoldSrc if( gEngfuncs.Cmd_Argc() == 1 ) { pglDrawBuffer( GL_FRONT ); - for( i = 0; i < 128; i++ ) + for( int i = 0; i < 128; i++ ) { gpGlobals->viewangles[1] = i / 128.0f * 360.0f; R_RenderScene(); @@ -716,7 +698,7 @@ void SCR_TimeRefresh_f( void ) } else { - for( i = 0; i < 128; i++ ) + for( int i = 0; i < 128; i++ ) { R_BeginFrame( true ); gpGlobals->viewangles[1] = i / 128.0f * 360.0f; @@ -725,7 +707,7 @@ void SCR_TimeRefresh_f( void ) } } - stop = gEngfuncs.pfnTime (); - time = (stop - start); + double stop = gEngfuncs.pfnTime (); + double time = (stop - start); gEngfuncs.Con_Printf( "%f seconds (%f fps)\n", time, 128 / time ); } diff --git a/ref/gl/gl_beams.c b/ref/gl/gl_beams.c index 8d61ba7d..8f0319f6 100644 --- a/ref/gl/gl_beams.c +++ b/ref/gl/gl_beams.c @@ -44,9 +44,7 @@ static float rgNoise[NOISE_DIVISIONS+1]; // global noise array // Fractal noise generator, power of 2 wavelength static void FracNoise( float *noise, int divs ) { - int div2; - - div2 = divs >> 1; + int div2 = divs >> 1; if( divs < 2 ) return; // noise is normalized to +/- scale @@ -61,11 +59,10 @@ static void FracNoise( float *noise, int divs ) static void SineNoise( float *noise, int divs ) { - float freq = 0; - float step = M_PI_F / (float)divs; - int i; + float freq = 0; + float step = M_PI_F / (float)divs; - for( i = 0; i < divs; i++ ) + for( int i = 0; i < divs; i++ ) { noise[i] = sin( freq ); freq += step; @@ -116,10 +113,9 @@ Cull the beam by bbox */ static qboolean R_BeamCull( const vec3_t start, const vec3_t end, qboolean pvsOnly ) { - vec3_t mins, maxs; - int i; + vec3_t mins, maxs; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( start[i] < end[i] ) { @@ -168,18 +164,11 @@ general code for drawing beams */ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments, int flags ) { - int noiseIndex, noiseStep; - int i, total_segs, segs_drawn; - float div, length, fraction, factor; - float flMaxWidth, vLast, vStep, brightness; - vec3_t perp1, vLastNormal; - beamseg_t curSeg; - if( segments < 2 ) return; - length = VectorLength( delta ); - flMaxWidth = width * 0.5f; - div = 1.0f / ( segments - 1 ); + float length = VectorLength( delta ); + float flMaxWidth = width * 0.5f; + float div = 1.0f / ( segments - 1 ); if( length * div < flMaxWidth * 1.414f ) { @@ -193,10 +182,10 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f div = 1.0f / (segments - 1); length *= 0.01f; - vStep = length * div; // Texture length texels per space pixel + float vStep = length * div; // Texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) - vLast = fmod( freq * speed, 1 ); + float vLast = fmod( freq * speed, 1 ); if( flags & FBEAM_SINENOISE ) { @@ -214,35 +203,38 @@ static void R_DrawSegs( vec3_t source, vec3_t delta, float width, float scale, f } // Iterator to resample noise waveform (it needs to be generated in powers of 2) - noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ); - brightness = 1.0f; - noiseIndex = 0; + int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ); + float brightness = 1.0f; + int noiseIndex = 0; if( FBitSet( flags, FBEAM_SHADEIN )) brightness = 0; // Choose two vectors that are perpendicular to the beam + vec3_t perp1; R_BeamComputePerpendicular( delta, perp1 ); - total_segs = segments; - segs_drawn = 0; + int total_segs = segments; + int segs_drawn = 0; + beamseg_t curSeg; + vec3_t vLastNormal; // specify all the segments. - for( i = 0; i < segments; i++ ) + for( int i = 0; i < segments; i++ ) { - beamseg_t nextSeg; - vec3_t vPoint1, vPoint2; + beamseg_t nextSeg; + vec3_t vPoint1, vPoint2; Assert( noiseIndex < ( NOISE_DIVISIONS << 16 )); - fraction = i * div; + float fraction = i * div; VectorMA( source, fraction, delta, nextSeg.pos ); // distort using noise if( scale != 0 ) { - factor = rgNoise[noiseIndex>>16] * scale; + float factor = rgNoise[noiseIndex>>16] * scale; if( FBitSet( flags, FBEAM_SINENOISE )) { @@ -350,38 +342,36 @@ Draw beamtours */ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - int i, noiseIndex, noiseStep; - float div, length, fraction, factor, vLast, vStep; - vec3_t last1, last2, point, screen, screenLast, tmp, normal; - if( segments < 2 ) return; if( segments > NOISE_DIVISIONS ) segments = NOISE_DIVISIONS; - length = VectorLength( delta ) * 0.01f; + float length = VectorLength( delta ) * 0.01f; if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); + float div = 1.0f / (segments - 1); - vStep = length * div; // Texture length texels per space pixel + float vStep = length * div; // Texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) - vLast = fmod( freq * speed, 1 ); + float vLast = fmod( freq * speed, 1 ); scale = scale * length; // Iterator to resample noise waveform (it needs to be generated in powers of 2) - noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ); - noiseIndex = 0; + int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ); + int noiseIndex = 0; - for( i = 0; i < segments; i++ ) + vec3_t screenLast = { 0 }; + + for( int i = 0; i < segments; i++ ) { - float s, c; - - fraction = i * div; + float fraction = i * div; + float s, c; SinCos( fraction * M_PI2_F, &s, &c ); + vec3_t point; point[0] = s * freq * delta[2] + source[0]; point[1] = c * freq * delta[2] + source[1]; point[2] = source[2]; @@ -391,7 +381,7 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, { if(( noiseIndex >> 16 ) < NOISE_DIVISIONS ) { - factor = rgNoise[noiseIndex>>16] * scale; + float factor = rgNoise[noiseIndex>>16] * scale; VectorMA( point, factor, RI.vup, point ); // rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal @@ -401,20 +391,24 @@ static void R_DrawTorus( vec3_t source, vec3_t delta, float width, float scale, } // Transform point into screen space + vec3_t screen; TriWorldToScreen( point, screen ); if( i != 0 ) { // build world-space normal to screen-space direction vector + vec3_t tmp; VectorSubtract( screen, screenLast, tmp ); // we don't need Z, we're in screen space tmp[2] = 0; VectorNormalize( tmp ); + vec3_t normal; VectorScale( RI.vup, -tmp[0], normal ); // Build point along noraml line (normal is -y, x) VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line + vec3_t last1, last2; VectorMA( point, width, normal, last1 ); VectorMA( point, -width, normal, last2 ); @@ -439,36 +433,31 @@ Draw beamdisk */ static void R_DrawDisk( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - float div, length, fraction; - float w, vLast, vStep; - vec3_t point; - int i; - if( segments < 2 ) return; if( segments > NOISE_DIVISIONS ) // UNDONE: Allow more segments? segments = NOISE_DIVISIONS; - length = VectorLength( delta ) * 0.01f; + float length = VectorLength( delta ) * 0.01f; if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); - vStep = length * div; // Texture length texels per space pixel + float div = 1.0f / (segments - 1); + float vStep = length * div; // Texture length texels per space pixel // scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) - vLast = fmod( freq * speed, 1 ); + float vLast = fmod( freq * speed, 1 ); scale = scale * length; // clamp the beam width - w = fmod( freq, width * 0.1f ) * delta[2]; + float w = fmod( freq, width * 0.1f ) * delta[2]; // NOTE: we must force the degenerate triangles to be on the edge - for( i = 0; i < segments; i++ ) + for( int i = 0; i < segments; i++ ) { - float s, c; - - fraction = i * div; + float s, c; + float fraction = i * div; + vec3_t point; VectorCopy( source, point ); TriBrightness( 1.0f ); @@ -497,34 +486,29 @@ Draw beam cylinder */ static void R_DrawCylinder( vec3_t source, vec3_t delta, float width, float scale, float freq, float speed, int segments ) { - float div, length, fraction; - float vLast, vStep; - vec3_t point; - int i; - if( segments < 2 ) return; if( segments > NOISE_DIVISIONS ) segments = NOISE_DIVISIONS; - length = VectorLength( delta ) * 0.01f; + float length = VectorLength( delta ) * 0.01f; if( length < 0.5f ) length = 0.5f; // don't lose all of the noise/texture on short beams - div = 1.0f / (segments - 1); - vStep = length * div; // texture length texels per space pixel + float div = 1.0f / (segments - 1); + float vStep = length * div; // texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) - vLast = fmod( freq * speed, 1 ); + float vLast = fmod( freq * speed, 1 ); scale = scale * length; - for ( i = 0; i < segments; i++ ) + for ( int i = 0; i < segments; i++ ) { - float s, c; - - fraction = i * div; + float s, c; + float fraction = i * div; SinCos( fraction * M_PI2_F, &s, &c ); + vec3_t point; point[0] = s * freq * delta[2] + source[0]; point[1] = c * freq * delta[2] + source[1]; point[2] = source[2] + width; @@ -554,17 +538,13 @@ drawi followed beam */ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) { - particle_t *pnew, *particles; - float fraction, div, vLast, vStep; - vec3_t last1, last2, tmp, screen; - vec3_t delta, screenLast, normal; - gEngfuncs.R_FreeDeadParticles( &pbeam->particles ); - particles = pbeam->particles; - pnew = NULL; + particle_t *particles = pbeam->particles; + particle_t *pnew = NULL; - div = 0; + vec3_t delta; + float div = 0; if( FBitSet( pbeam->flags, FBEAM_STARTENTITY )) { if( particles ) @@ -597,6 +577,7 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) // nothing to draw if( !particles ) return; + vec3_t screen, screenLast; if( !pnew && div != 0 ) { VectorCopy( pbeam->source, delta ); @@ -619,24 +600,27 @@ static void R_DrawBeamFollow( BEAM *pbeam, float frametime ) // first beam segment for this trail // build world-space normal to screen-space direction vector + vec3_t tmp; VectorSubtract( screen, screenLast, tmp ); // we don't need Z, we're in screen space tmp[2] = 0; VectorNormalize( tmp ); // Build point along noraml line (normal is -y, x) + vec3_t normal; VectorScale( RI.vup, tmp[0], normal ); // Build point along normal line (normal is -y, x) VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line + vec3_t last1, last2; VectorMA( delta, pbeam->width, normal, last1 ); VectorMA( delta, -pbeam->width, normal, last2 ); div = 1.0f / pbeam->amplitude; - fraction = ( pbeam->die - gp_cl->time ) * div; + float fraction = ( pbeam->die - gp_cl->time ) * div; - vLast = 0.0f; - vStep = 1.0f; + float vLast = 0.0f; + float vStep = 1.0f; while( particles ) { @@ -704,45 +688,43 @@ Draw beamring */ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitude, float freq, float speed, int segments ) { - int i, j, noiseIndex, noiseStep; - float div, length, fraction, factor, vLast, vStep; - vec3_t last1, last2, point, screen, screenLast; - vec3_t tmp, normal, center, xaxis, yaxis; - float radius, x, y, scale; - if( segments < 2 ) return; + vec3_t screenLast; VectorClear( screenLast ); segments = segments * M_PI_F; if( segments > NOISE_DIVISIONS * 8 ) segments = NOISE_DIVISIONS * 8; - length = VectorLength( delta ) * 0.01f * M_PI_F; + float length = VectorLength( delta ) * 0.01f * M_PI_F; if( length < 0.5f ) length = 0.5f; // Don't lose all of the noise/texture on short beams - div = 1.0f / ( segments - 1 ); + float div = 1.0f / ( segments - 1 ); - vStep = length * div / 8.0f; // texture length texels per space pixel + float vStep = length * div / 8.0f; // texture length texels per space pixel // Scroll speed 3.5 -- initial texture position, scrolls 3.5/sec (1.0 is entire texture) - vLast = fmod( freq * speed, 1.0f ); - scale = amplitude * length / 8.0f; + float vLast = fmod( freq * speed, 1.0f ); + float scale = amplitude * length / 8.0f; // Iterator to resample noise waveform (it needs to be generated in powers of 2) - noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ) * 8; - noiseIndex = 0; + int noiseStep = (int)((float)( NOISE_DIVISIONS - 1 ) * div * 65536.0f ) * 8; + int noiseIndex = 0; VectorScale( delta, 0.5f, delta ); + vec3_t center; VectorAdd( source, delta, center ); + vec3_t xaxis; VectorCopy( delta, xaxis ); - radius = VectorLength( xaxis ); + float radius = VectorLength( xaxis ); // cull beamring // -------------------------------- // Compute box center +/- radius + vec3_t last1, tmp, screen; VectorSet( last1, radius, radius, scale ); VectorAdd( center, last1, tmp ); // maxs VectorSubtract( center, last1, screen ); // mins @@ -756,21 +738,24 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud return; } + vec3_t yaxis; VectorSet( yaxis, xaxis[1], -xaxis[0], 0.0f ); VectorNormalize( yaxis ); VectorScale( yaxis, radius, yaxis ); - j = segments / 8; + int j = segments / 8; - for( i = 0; i < segments + 1; i++ ) + for( int i = 0; i < segments + 1; i++ ) { - fraction = i * div; + float fraction = i * div; + float x, y; SinCos( fraction * M_PI2_F, &x, &y ); + vec3_t point; VectorMAMAM( x, xaxis, y, yaxis, 1.0f, center, point ); // distort using noise - factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale; + float factor = rgNoise[(noiseIndex >> 16) & (NOISE_DIVISIONS - 1)] * scale; VectorMA( point, factor, RI.vup, point ); // Rotate the noise along the perpendicluar axis a bit to keep the bolt from looking diagonal @@ -791,10 +776,12 @@ static void R_DrawRing( vec3_t source, vec3_t delta, float width, float amplitud VectorNormalize( tmp ); // Build point along normal line (normal is -y, x) + vec3_t normal; VectorScale( RI.vup, tmp[0], normal ); VectorMA( normal, tmp[1], RI.vright, normal ); // Make a wide line + vec3_t last2; VectorMA( point, width, normal, last1 ); VectorMA( point, -width, normal, last2 ); @@ -826,11 +813,9 @@ compute attachment point for beam */ static qboolean R_BeamComputePoint( int beamEnt, vec3_t pt ) { - cl_entity_t *ent; - int attach; - - ent = gEngfuncs.R_BeamGetEntity( beamEnt ); + cl_entity_t *ent = gEngfuncs.R_BeamGetEntity( beamEnt ); + int attach; if( beamEnt < 0 ) attach = BEAMENT_ATTACHMENT( -beamEnt ); else attach = BEAMENT_ATTACHMENT( beamEnt ); @@ -914,10 +899,7 @@ Update beam vars and draw it */ static void R_BeamDraw( BEAM *pbeam, float frametime ) { - model_t *model; - vec3_t delta; - - model = CL_ModelHandle( pbeam->modelIndex ); + model_t *model = CL_ModelHandle( pbeam->modelIndex ); SetBits( pbeam->flags, FBEAM_ISACTIVE ); if( !model || model->type != mod_sprite ) @@ -955,6 +937,7 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) } // compute segments from the new endpoints + vec3_t delta; VectorSubtract( pbeam->target, pbeam->source, delta ); VectorClear( pbeam->delta ); @@ -987,12 +970,11 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) if( pbeam->type == TE_BEAMHOSE ) { - float flDot; - + vec3_t delta; VectorSubtract( pbeam->target, pbeam->source, delta ); VectorNormalize( delta ); - flDot = DotProduct( delta, RI.vforward ); + float flDot = DotProduct( delta, RI.vforward ); // abort if the player's looking along it away from the source if( flDot > 0 ) @@ -1001,16 +983,16 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) } else { - float flFade = pow( flDot, 10 ); - vec3_t localDir, vecProjection, tmp; - float flDistance; + float flFade = pow( flDot, 10 ); // fade the beam if the player's not looking at the source + vec3_t localDir; VectorSubtract( RI.rvp.vieworigin, pbeam->source, localDir ); flDot = DotProduct( delta, localDir ); + vec3_t vecProjection, tmp; VectorScale( delta, flDot, vecProjection ); VectorSubtract( localDir, vecProjection, tmp ); - flDistance = VectorLength( tmp ); + float flDistance = VectorLength( tmp ); if( flDistance > 30 ) { @@ -1037,10 +1019,8 @@ static void R_BeamDraw( BEAM *pbeam, float frametime ) if( pbeam->type == TE_BEAMFOLLOW ) { - cl_entity_t *pStart; - // XASH SPECIFIC: get brightness from head entity - pStart = gEngfuncs.R_BeamGetEntity( pbeam->startEntity ); + cl_entity_t *pStart = gEngfuncs.R_BeamGetEntity( pbeam->startEntity ); if( pStart && pStart->curstate.rendermode != kRenderNormal ) pbeam->brightness = CL_FxBlend( pStart ) / 255.0f; } @@ -1160,16 +1140,14 @@ initialize beam from server entity */ static void R_BeamDrawCustomEntity( cl_entity_t *ent ) { - BEAM beam; - float amp = ent->curstate.body / 100.0f; - float blend = CL_FxBlend( ent ) / 255.0f; - float r, g, b; - int beamFlags; + float amp = ent->curstate.body / 100.0f; + float blend = CL_FxBlend( ent ) / 255.0f; - r = ent->curstate.rendercolor.r / 255.0f; - g = ent->curstate.rendercolor.g / 255.0f; - b = ent->curstate.rendercolor.b / 255.0f; + float r = ent->curstate.rendercolor.r / 255.0f; + float g = ent->curstate.rendercolor.g / 255.0f; + float b = ent->curstate.rendercolor.b / 255.0f; + BEAM beam; R_BeamSetup( &beam, ent->origin, ent->curstate.angles, ent->curstate.modelindex, 0, ent->curstate.scale, amp, blend, ent->curstate.animtime ); R_BeamSetAttributes( &beam, r, g, b, ent->curstate.framerate, ent->curstate.frame ); beam.pFollowModel = NULL; @@ -1203,7 +1181,7 @@ static void R_BeamDrawCustomEntity( cl_entity_t *ent ) break; } - beamFlags = ( ent->curstate.rendermode & 0xF0 ); + int beamFlags = ( ent->curstate.rendermode & 0xF0 ); if( FBitSet( beamFlags, BEAM_FSINE )) SetBits( beam.flags, FBEAM_SINENOISE ); @@ -1231,18 +1209,15 @@ draw beam loop */ void CL_DrawBeams( int fTrans, BEAM *active_beams ) { - BEAM *pBeam; - int i, flags; - pglShadeModel( GL_SMOOTH ); pglDepthMask( fTrans ? GL_FALSE : GL_TRUE ); // server beams don't allocate beam chains // all params are stored in cl_entity_t - for( i = 0; i < tr.draw_list->num_beam_entities; i++ ) + for( int i = 0; i < tr.draw_list->num_beam_entities; i++ ) { RI.currentbeam = tr.draw_list->beam_entities[i]; - flags = RI.currentbeam->curstate.rendermode & 0xF0; + int flags = RI.currentbeam->curstate.rendermode & 0xF0; if( fTrans && FBitSet( flags, FBEAM_SOLID )) continue; @@ -1257,7 +1232,7 @@ void CL_DrawBeams( int fTrans, BEAM *active_beams ) RI.currentbeam = NULL; // draw temporary entity beams - for( pBeam = active_beams; pBeam; pBeam = pBeam->next ) + for( BEAM *pBeam = active_beams; pBeam; pBeam = pBeam->next ) { if( fTrans && FBitSet( pBeam->flags, FBEAM_SOLID )) continue; diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index 038abd41..b98dbd49 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -84,9 +84,7 @@ static qboolean Mod_LooksLikeWaterTexture( const char *name ) static void Mod_BrushUnloadTextures( model_t *mod ) { - int i; - - for( i = 0; i < mod->numtextures; i++ ) + for( int i = 0; i < mod->numtextures; i++ ) { texture_t *tx = mod->textures[i]; if( !tx ) @@ -163,34 +161,24 @@ static qboolean Mod_ProcessRenderData( model_t *mod, qboolean create, const byte static intptr_t GL_RefGetParm( int parm, int arg ) { - gl_texture_t *glt; - switch( parm ) { case PARM_TEX_WIDTH: - glt = R_GetTexture( arg ); - return glt->width; + return R_GetTexture( arg )->width; case PARM_TEX_HEIGHT: - glt = R_GetTexture( arg ); - return glt->height; + return R_GetTexture( arg )->height; case PARM_TEX_SRC_WIDTH: - glt = R_GetTexture( arg ); - return glt->srcWidth; + return R_GetTexture( arg )->srcWidth; case PARM_TEX_SRC_HEIGHT: - glt = R_GetTexture( arg ); - return glt->srcHeight; + return R_GetTexture( arg )->srcHeight; case PARM_TEX_GLFORMAT: - glt = R_GetTexture( arg ); - return glt->format; + return R_GetTexture( arg )->format; case PARM_TEX_ENCODE: - glt = R_GetTexture( arg ); - return glt->encode; + return R_GetTexture( arg )->encode; case PARM_TEX_MIPCOUNT: - glt = R_GetTexture( arg ); - return glt->numMips; + return R_GetTexture( arg )->numMips; case PARM_TEX_DEPTH: - glt = R_GetTexture( arg ); - return glt->depth; + return R_GetTexture( arg )->depth; case PARM_TEX_SKYBOX: Assert( arg >= 0 && arg < 6 ); return tr.skyboxTextures[arg]; @@ -200,14 +188,11 @@ static intptr_t GL_RefGetParm( int parm, int arg ) arg = bound( 0, arg, MAX_LIGHTMAPS - 1 ); return tr.lightmapTextures[arg]; case PARM_TEX_TARGET: - glt = R_GetTexture( arg ); - return glt->target; + return R_GetTexture( arg )->target; case PARM_TEX_TEXNUM: - glt = R_GetTexture( arg ); - return glt->texnum; + return R_GetTexture( arg )->texnum; case PARM_TEX_FLAGS: - glt = R_GetTexture( arg ); - return glt->flags; + return R_GetTexture( arg )->flags; case PARM_TEX_MEMORY: return GL_TexMemory(); case PARM_ACTIVE_TMU: @@ -342,14 +327,12 @@ R_SetupSky */ static void GAME_EXPORT R_SetupSky( int *skyboxTextures ) { - int i; - R_UnloadSkybox(); if( !skyboxTextures ) return; - for( i = 0; i < SKYBOX_MAX_SIDES; i++ ) + for( int i = 0; i < SKYBOX_MAX_SIDES; i++ ) tr.skyboxTextures[i] = skyboxTextures[i]; } @@ -415,9 +398,6 @@ static const char *R_GetConfigName( void ) static void R_NewMap( void ) { - texture_t *tx; - int i; - tr.worldmodel = gp_cl->models[1]; R_ClearDecals(); // clear all level decals @@ -425,7 +405,7 @@ static void R_NewMap( void ) R_StudioResetPlayerModels(); // clear out efrags in case the level hasn't been reloaded - for( i = 0; i < WORLDMODEL->numleafs; i++ ) + for( int i = 0; i < WORLDMODEL->numleafs; i++ ) WORLDMODEL->leafs[i+1].efrags = NULL; glState.isFogEnabled = false; @@ -433,12 +413,12 @@ static void R_NewMap( void ) pglDisable( GL_FOG ); // clearing texture chains - for( i = 0; i < WORLDMODEL->numtextures; i++ ) + for( int i = 0; i < WORLDMODEL->numtextures; i++ ) { if( !WORLDMODEL->textures[i] ) continue; - tx = WORLDMODEL->textures[i]; + texture_t *tx = WORLDMODEL->textures[i]; if( !Q_strncmp( tx->name, "sky", 3 ) && tx->width == ( tx->height * 2 )) tr.skytexturenum = i; diff --git a/ref/gl/gl_cull.c b/ref/gl/gl_cull.c index 2848593b..50334849 100644 --- a/ref/gl/gl_cull.c +++ b/ref/gl/gl_cull.c @@ -65,7 +65,7 @@ cull invisible surfaces */ int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint clipflags ) { - cl_entity_t *e = RI.currententity; + const cl_entity_t *e = RI.currententity; if( surf->visframe != tr.framecount && e == CL_GetEntityByIndex( 0 )) return CULL_VISFRAME; diff --git a/ref/gl/gl_decals.c b/ref/gl/gl_decals.c index 66c79ff7..ba3cda91 100644 --- a/ref/gl/gl_decals.c +++ b/ref/gl/gl_decals.c @@ -63,8 +63,6 @@ void R_ClearDecals( void ) // unlink pdecal from any surface it's attached to static void R_DecalUnlink( decal_t *pdecal ) { - decal_t *tmp; - if( pdecal->psurface ) { if( pdecal->psurface->pdecals == pdecal ) @@ -73,7 +71,7 @@ static void R_DecalUnlink( decal_t *pdecal ) } else { - tmp = pdecal->psurface->pdecals; + decal_t *tmp = pdecal->psurface->pdecals; if( !tmp ) gEngfuncs.Host_Error( "%s: bad decal list\n", __func__ ); while( tmp->pnext ) @@ -201,10 +199,8 @@ static void R_SetupDecalTextureSpaceBasis( decal_t *pDecal, msurface_t *surf, in // Build the initial list of vertices from the surface verts into the global array, 'verts'. static void R_SetupDecalVertsForMSurface( decal_t *pDecal, msurface_t *surf, vec3_t textureSpaceBasis[3], float *verts ) { - float *v; - int i; - - for( i = 0, v = surf->polys->verts[0]; i < surf->polys->numverts; i++, v += VERTEXSIZE, verts += VERTEXSIZE ) + float *v = surf->polys->verts[0]; + for( int i = 0; i < surf->polys->numverts; i++, v += VERTEXSIZE, verts += VERTEXSIZE ) { VectorCopy( v, verts ); // copy model space coordinates verts[3] = DotProduct( verts, textureSpaceBasis[0] ) - pDecal->dx + 0.5f; @@ -255,8 +251,6 @@ static int R_ClipInside( float *vert, int edge ) static void R_ClipIntersect( float *one, float *two, float *out, int edge ) { - float t; - // t is the parameter of the line between one and two clipped to the edge // or the fraction of the clipped point between one & two // vert[0], vert[1], vert[2] is X, Y, Z @@ -265,6 +259,7 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge ) // vert[5] is lightmap u // vert[6] is lightmap v + float t; if( edge < TOP_EDGE ) { if( edge == LEFT_EDGE ) @@ -307,16 +302,13 @@ static void R_ClipIntersect( float *one, float *two, float *out, int edge ) static int SHClip( float *vert, int vertCount, float *out, int edge ) { - int j, outCount; - float *s, *p; + int outCount = 0; - outCount = 0; + float *s = &vert[(vertCount - 1) * VERTEXSIZE]; - s = &vert[(vertCount - 1) * VERTEXSIZE]; - - for( j = 0; j < vertCount; j++ ) + for( int j = 0; j < vertCount; j++ ) { - p = &vert[j * VERTEXSIZE]; + float *p = &vert[j * VERTEXSIZE]; if( R_ClipInside( p, edge )) { @@ -356,11 +348,10 @@ static int SHClip( float *vert, int vertCount, float *out, int edge ) static float *R_DoDecalSHClip( float *pInVerts, decal_t *pDecal, int nStartVerts, int *pVertCount ) { - float *pOutVerts = g_DecalClipVerts[0]; - int outCount; + float *pOutVerts = g_DecalClipVerts[0]; // clip the polygon to the decal texture space - outCount = SHClip( pInVerts, nStartVerts, g_DecalClipVerts2[0], LEFT_EDGE ); + int outCount = SHClip( pInVerts, nStartVerts, g_DecalClipVerts2[0], LEFT_EDGE ); outCount = SHClip( g_DecalClipVerts2[0], outCount, g_DecalClipVerts[0], RIGHT_EDGE ); outCount = SHClip( g_DecalClipVerts[0], outCount, g_DecalClipVerts2[0], TOP_EDGE ); outCount = SHClip( g_DecalClipVerts2[0], outCount, pOutVerts, BOTTOM_EDGE ); @@ -391,12 +382,9 @@ static float *R_DecalVertsClip( decal_t *pDecal, msurface_t *surf, int texture, // Generate lighting coordinates at each vertex for decal vertices v[] on surface psurf static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) { - float sample_size; - int j; + float sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - - for( j = 0; j < vertCount; j++, v += VERTEXSIZE ) + for( int j = 0; j < vertCount; j++, v += VERTEXSIZE ) { // lightmap texture coordinates R_LightmapCoord( v, surf, sample_size, &v[5] ); @@ -406,24 +394,21 @@ static void R_DecalVertsLight( float *v, msurface_t *surf, int vertCount ) // Check for intersecting decals on this surface static decal_t *R_DecalIntersect( decalinfo_t *decalinfo, msurface_t *surf, int *pcount ) { - int texture; - decal_t *plast, *pDecal; - vec3_t decalExtents[2]; - float lastArea = 2; - int mapSize[2]; - - plast = NULL; + decal_t *plast = NULL; + float lastArea = 2; *pcount = 0; // (Same as R_SetupDecalClip). - texture = decalinfo->m_iTexture; + int texture = decalinfo->m_iTexture; // precalculate the extents of decalinfo's decal in world space. + int mapSize[2]; R_GetDecalDimensions( texture, &mapSize[0], &mapSize[1] ); + vec3_t decalExtents[2]; VectorScale( decalinfo->m_Basis[0], ((mapSize[0] / decalinfo->m_scale) * 0.5f), decalExtents[0] ); VectorScale( decalinfo->m_Basis[1], ((mapSize[1] / decalinfo->m_scale) * 0.5f), decalExtents[1] ); - pDecal = surf->pdecals; + decal_t *pDecal = surf->pdecals; while( pDecal ) { @@ -494,26 +479,22 @@ creates mesh for decal on first rendering */ static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, msurface_t *surf ) { - int lnumverts; - glpoly2_t *poly; - float *v; - int i; - if( pdecal->polys ) // already created? return pdecal->polys; - v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &lnumverts ); + int lnumverts; + float *v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &lnumverts ); if( !lnumverts ) return NULL; // probably this never happens // allocate glpoly // REFTODO: com_studiocache pool! - poly = Mem_Calloc( r_temppool, sizeof( glpoly2_t ) + lnumverts * VERTEXSIZE * sizeof( float )); + glpoly2_t *poly = Mem_Calloc( r_temppool, sizeof( glpoly2_t ) + lnumverts * VERTEXSIZE * sizeof( float )); poly->next = pdecal->polys; poly->flags = surf->flags; pdecal->polys = poly; poly->numverts = lnumverts; - for( i = 0; i < lnumverts; i++, v += VERTEXSIZE ) + for( int i = 0; i < lnumverts; i++, v += VERTEXSIZE ) { VectorCopy( v, poly->verts[i] ); poly->verts[i][3] = v[3]; @@ -528,10 +509,8 @@ static glpoly2_t *R_DecalCreatePoly( decalinfo_t *decalinfo, decal_t *pdecal, ms // Add the decal to the surface's list of decals. static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t *decalinfo ) { - decal_t *pold; - pdecal->pnext = NULL; - pold = surf->pdecals; + decal_t *pold = surf->pdecals; if( pold ) { @@ -558,15 +537,13 @@ static void R_AddDecalToSurface( decal_t *pdecal, msurface_t *surf, decalinfo_t static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, float y ) { - decal_t *pdecal, *pold; - int count, vertCount; - if( !surf ) return; // ??? - pold = R_DecalIntersect( decalinfo, surf, &count ); + int count; + decal_t *pold = R_DecalIntersect( decalinfo, surf, &count ); if( count < MAX_OVERLAP_DECALS ) pold = NULL; - pdecal = R_DecalAlloc( pold ); + decal_t *pdecal = R_DecalAlloc( pold ); if( !pdecal ) return; // r_decals == 0 ??? pdecal->flags = decalinfo->m_Flags; @@ -583,6 +560,7 @@ static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, fl // check to see if the decal actually intersects the surface // if not, then remove the decal + int vertCount; R_DecalVertsClip( pdecal, surf, decalinfo->m_iTexture, &vertCount ); if( !vertCount ) @@ -598,10 +576,7 @@ static void R_DecalCreate( decalinfo_t *decalinfo, msurface_t *surf, float x, fl static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) { // get the texture associated with this surface - mtexinfo_t *tex = surf->texinfo; - decal_t *decal = surf->pdecals; - vec4_t textureU, textureV; - float s, t, w, h; + mtexinfo_t *tex = surf->texinfo; connstate_t state = ENGINE_GET_PARM( PARM_CONNSTATE ); // we in restore mode @@ -609,6 +584,7 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) { // NOTE: we may have the decal on this surface that come from another level. // check duplicate with same position and texture + decal_t *decal = surf->pdecals; while( decal != NULL ) { if( VectorCompare( decal->position, decalinfo->m_Position ) && decal->texture == decalinfo->m_iTexture ) @@ -617,12 +593,13 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) } } + vec4_t textureU, textureV; Vector4Copy( tex->vecs[0], textureU ); Vector4Copy( tex->vecs[1], textureV ); // project decal center into the texture space of the surface - s = DotProduct( decalinfo->m_Position, textureU ) + textureU[3] - surf->texturemins[0]; - t = DotProduct( decalinfo->m_Position, textureV ) + textureV[3] - surf->texturemins[1]; + float s = DotProduct( decalinfo->m_Position, textureU ) + textureU[3] - surf->texturemins[0]; + float t = DotProduct( decalinfo->m_Position, textureV ) + textureV[3] - surf->texturemins[1]; // Determine the decal basis (measured in world space) // Note that the decal basis vectors 0 and 1 will always lie in the same @@ -642,10 +619,10 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) // (decalWidth * decalBasis[0], decalHeight * decalBasis[1]) // in texture coordinates: - w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) + + float w = fabs( decalinfo->m_decalWidth * DotProduct( textureU, decalinfo->m_Basis[0] )) + fabs( decalinfo->m_decalHeight * DotProduct( textureU, decalinfo->m_Basis[1] )); - h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) + + float h = fabs( decalinfo->m_decalWidth * DotProduct( textureV, decalinfo->m_Basis[0] )) + fabs( decalinfo->m_decalHeight * DotProduct( textureV, decalinfo->m_Basis[1] )); // move s,t to upper left corner @@ -668,16 +645,12 @@ static void R_DecalSurface( msurface_t *surf, decalinfo_t *decalinfo ) static void R_DecalNodeSurfaces( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) { // iterate over all surfaces in the node - msurface_t *surf; - int i; - int firstsurface, numsurfaces; + int firstsurface = node_firstsurface( node, model ); + int numsurfaces = node_numsurfaces( node, model ); - firstsurface = node_firstsurface( node, model ); - numsurfaces = node_numsurfaces( node, model ); + msurface_t *surf = model->surfaces + firstsurface; - surf = model->surfaces + firstsurface; - - for( i = 0; i < numsurfaces; i++, surf++ ) + for( int i = 0; i < numsurfaces; i++, surf++ ) { // never apply decals on the water or sky surfaces if( surf->flags & (SURF_DRAWTURB|SURF_DRAWSKY|SURF_CONVEYOR)) @@ -697,17 +670,14 @@ static void R_DecalNodeSurfaces( model_t *model, mnode_t *node, decalinfo_t *dec //----------------------------------------------------------------------------- static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) { - mplane_t *splitplane; - float dist; - if( node->contents < 0 ) { // hit a leaf return; } - splitplane = node->plane; - dist = DotProduct( decalinfo->m_Position, splitplane->normal ) - splitplane->dist; + mplane_t *splitplane = node->plane; + float dist = DotProduct( decalinfo->m_Position, splitplane->normal ) - splitplane->dist; if( dist > decalinfo->m_Size ) { @@ -730,18 +700,14 @@ static void R_DecalNode( model_t *model, mnode_t *node, decalinfo_t *decalinfo ) // Shoots a decal onto the surface of the BSP. position is the center of the decal in world coords void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos, int flags, float scale ) { - decalinfo_t decalInfo; - cl_entity_t *ent = NULL; - model_t *model = NULL; - int width, height; - hull_t *hull; - if( textureIndex <= 0 || textureIndex >= MAX_TEXTURES ) { gEngfuncs.Con_Printf( S_ERROR "Decal has invalid texture!\n" ); return; } + cl_entity_t *ent = NULL; + model_t *model = NULL; if( entityIndex > 0 ) { ent = CL_GetEntityByIndex( entityIndex ); @@ -762,19 +728,20 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos return; } + decalinfo_t decalInfo; decalInfo.m_pModel = model; - hull = &model->hulls[0]; // always use #0 hull + hull_t *hull = &model->hulls[0]; // always use #0 hull // NOTE: all the decals at 'first shoot' placed into local space of parent entity // and won't transform again on a next restore, levelchange etc if( ent && !FBitSet( flags, FDECAL_LOCAL_SPACE )) { - vec3_t pos_l; + vec3_t pos_l; // transform decal position in local bmodel space if( !VectorIsNull( ent->angles )) { - matrix4x4 matrix; + matrix4x4 matrix; Matrix4x4_CreateFromEntity( matrix, ent->angles, ent->origin, 1.0f ); Matrix4x4_VectorITransform( matrix, pos, pos_l ); @@ -804,6 +771,7 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos decalInfo.m_Entity = entityIndex; decalInfo.m_Flags = flags; + int width, height; R_GetDecalDimensions( textureIndex, &width, &height ); decalInfo.m_Size = width >> 1; if(( height >> 1 ) > decalInfo.m_Size ) @@ -823,18 +791,18 @@ void R_DecalShoot( int textureIndex, int entityIndex, int modelIndex, vec3_t pos // triangles the same way. float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *outCount ) { - glpoly2_t *p = pDecal->polys; - int i, count; - float *v, *v2; + glpoly2_t *p = pDecal->polys; + float *v; + int count; if( p ) { v = g_DecalClipVerts[0]; count = p->numverts; - v2 = p->verts[0]; + float *v2 = p->verts[0]; // if we have mesh so skip clipping and just copy vertexes out (perf) - for( i = 0; i < count; i++, v += VERTEXSIZE, v2 += VERTEXSIZE ) + for( int i = 0; i < count; i++, v += VERTEXSIZE, v2 += VERTEXSIZE ) { VectorCopy( v2, v ); v[3] = v2[3]; @@ -860,10 +828,8 @@ float *R_DecalSetupVerts( decal_t *pDecal, msurface_t *surf, int texture, int *o void DrawSingleDecal( decal_t *pDecal, msurface_t *fa ) { - float *v; - int i, numVerts; - - v = R_DecalSetupVerts( pDecal, fa, pDecal->texture, &numVerts ); + int numVerts; + float *v = R_DecalSetupVerts( pDecal, fa, pDecal->texture, &numVerts ); if( !numVerts ) return; GL_Bind( XASH_TEXTURE0, pDecal->texture ); @@ -874,7 +840,7 @@ void DrawSingleDecal( decal_t *pDecal, msurface_t *fa ) pglBegin( GL_POLYGON ); - for( i = 0; i < numVerts; i++, v += VERTEXSIZE ) + for( int i = 0; i < numVerts; i++, v += VERTEXSIZE ) { pglTexCoord2f( v[3], v[4] ); pglVertex3fv( v ); @@ -885,12 +851,9 @@ void DrawSingleDecal( decal_t *pDecal, msurface_t *fa ) void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) { - decal_t *p; - cl_entity_t *e; - if( !fa->pdecals ) return; - e = RI.currententity; + cl_entity_t *e = RI.currententity; Assert( e != NULL ); if( single ) @@ -916,15 +879,14 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) if( FBitSet( fa->flags, SURF_TRANSPARENT ) && glState.stencilEnabled ) { - mtexinfo_t *tex = fa->texinfo; + mtexinfo_t *tex = fa->texinfo; - for( p = fa->pdecals; p; p = p->pnext ) + for( decal_t *p = fa->pdecals; p; p = p->pnext ) { if( p->texture ) { - float *o, *v; - int i, numVerts; - o = R_DecalSetupVerts( p, fa, p->texture, &numVerts ); + int numVerts; + float *o = R_DecalSetupVerts( p, fa, p->texture, &numVerts ); pglEnable( GL_STENCIL_TEST ); pglStencilFunc( GL_ALWAYS, 1, 0xFFFFFFFF ); @@ -933,7 +895,8 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) pglStencilOp( GL_KEEP, GL_KEEP, GL_REPLACE ); pglBegin( GL_POLYGON ); - for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE ) + float *v = o; + for( int i = 0; i < numVerts; i++, v += VERTEXSIZE ) { v[5] = ( DotProduct( v, tex->vecs[0] ) + tex->vecs[0][3] ) / tex->texture->width; v[6] = ( DotProduct( v, tex->vecs[1] ) + tex->vecs[1][3] ) / tex->texture->height; @@ -948,7 +911,8 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) pglEnable( GL_ALPHA_TEST ); pglBegin( GL_POLYGON ); - for( i = 0, v = o; i < numVerts; i++, v += VERTEXSIZE ) + v = o; + for( int i = 0; i < numVerts; i++, v += VERTEXSIZE ) { pglTexCoord2f( v[5], v[6] ); pglVertex3fv( v ); @@ -968,18 +932,18 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) if( reverse && e->curstate.rendermode == kRenderTransTexture ) { - decal_t *list[1024]; - int i, count; + decal_t *list[1024]; + int count = 0; - for( p = fa->pdecals, count = 0; p && count < 1024; p = p->pnext ) + for( decal_t *p = fa->pdecals; p && count < 1024; p = p->pnext ) if( p->texture ) list[count++] = p; - for( i = count - 1; i >= 0; i-- ) + for( int i = count - 1; i >= 0; i-- ) DrawSingleDecal( list[i], fa ); } else { - for( p = fa->pdecals; p; p = p->pnext ) + for( decal_t *p = fa->pdecals; p; p = p->pnext ) { if( !p->texture ) continue; DrawSingleDecal( p, fa ); @@ -1019,13 +983,10 @@ void DrawSurfaceDecals( msurface_t *fa, qboolean single, qboolean reverse ) void DrawDecalsBatch( void ) { - cl_entity_t *e; - int i; - if( !tr.num_draw_decals ) return; - e = RI.currententity; + cl_entity_t *e = RI.currententity; Assert( e != NULL ); if( e->curstate.rendermode != kRenderTransTexture ) @@ -1041,7 +1002,7 @@ void DrawDecalsBatch( void ) if( gl_polyoffset.value ) GL_PushPolygonOffset( -1.0f, -gl_polyoffset.value ); - for( i = 0; i < tr.num_draw_decals; i++ ) + for( int i = 0; i < tr.num_draw_decals; i++ ) { DrawSurfaceDecals( tr.draw_decals[i], false, false ); } @@ -1093,16 +1054,13 @@ static qboolean R_DecalUnProject( decal_t *pdecal, decallist_t *entry ) //----------------------------------------------------------------------------- static int DecalListAdd( decallist_t *pList, int count ) { - vec3_t tmp; - decallist_t *pdecal; - int i; + decallist_t *pdecal = pList + count; - pdecal = pList + count; - - for( i = 0; i < count; i++ ) + for( int i = 0; i < count; i++ ) { if( !Q_strcmp( pdecal->name, pList[i].name ) && pdecal->entityIndex == pList[i].entityIndex ) { + vec3_t tmp; VectorSubtract( pdecal->position, pList[i].position, tmp ); // Merge if( VectorLength( tmp ) < DECAL_OVERLAP_DISTANCE ) @@ -1116,10 +1074,8 @@ static int DecalListAdd( decallist_t *pList, int count ) static int DecalDepthCompare( const void *a, const void *b ) { - const decallist_t *elem1, *elem2; - - elem1 = (const decallist_t *)a; - elem2 = (const decallist_t *)b; + const decallist_t *elem1 = (const decallist_t *)a; + const decallist_t *elem2 = (const decallist_t *)b; if( elem1->depth > elem2->depth ) return 1; @@ -1136,23 +1092,21 @@ static int DecalDepthCompare( const void *a, const void *b ) //----------------------------------------------------------------------------- int R_CreateDecalList( decallist_t *pList ) { - int total = 0; - int i, depth; + int total = 0; if( WORLDMODEL ) { - for( i = 0; i < MAX_RENDER_DECALS; i++ ) + for( int i = 0; i < MAX_RENDER_DECALS; i++ ) { - decal_t *decal = &gDecalPool[i]; - decal_t *pdecals; + decal_t *decal = &gDecalPool[i]; // decal is in use and is not a custom decal if( decal->psurface == NULL || FBitSet( decal->flags, FDECAL_DONTSAVE )) continue; // compute depth - depth = 0; - pdecals = decal->psurface->pdecals; + int depth = 0; + decal_t *pdecals = decal->psurface->pdecals; while( pdecals && pdecals != decal ) { @@ -1192,15 +1146,12 @@ remove all decals with specified texture */ void R_DecalRemoveAll( int textureIndex ) { - decal_t *pdecal; - int i; - if( textureIndex < 0 || textureIndex >= MAX_TEXTURES ) return; // out of bounds - for( i = 0; i < gDecalCount; i++ ) + for( int i = 0; i < gDecalCount; i++ ) { - pdecal = &gDecalPool[i]; + decal_t *pdecal = &gDecalPool[i]; // don't remove permanent decals if( FBitSet( pdecal->flags, FDECAL_PERMANENT )) @@ -1220,17 +1171,13 @@ remove all decals from specified entity */ void R_EntityRemoveDecals( model_t *mod ) { - msurface_t *psurf; - decal_t *p; - int i; - if( !mod || mod->type != mod_brush ) return; - psurf = &mod->surfaces[mod->firstmodelsurface]; - for( i = 0; i < mod->nummodelsurfaces; i++, psurf++ ) + msurface_t *psurf = &mod->surfaces[mod->firstmodelsurface]; + for( int i = 0; i < mod->nummodelsurfaces; i++, psurf++ ) { - for( p = psurf->pdecals; p; p = p->pnext ) + for( decal_t *p = psurf->pdecals; p; p = p->pnext ) R_DecalUnlink( p ); } } @@ -1245,13 +1192,10 @@ used for full decals restart */ void R_ClearAllDecals( void ) { - decal_t *pdecal; - int i; - // because gDecalCount may be zeroed after recach the decal limit - for( i = 0; i < MAX_RENDER_DECALS; i++ ) + for( int i = 0; i < MAX_RENDER_DECALS; i++ ) { - pdecal = &gDecalPool[i]; + decal_t *pdecal = &gDecalPool[i]; R_DecalUnlink( pdecal ); } diff --git a/ref/gl/gl_draw.c b/ref/gl/gl_draw.c index 26974c11..e65c9bd4 100644 --- a/ref/gl/gl_draw.c +++ b/ref/gl/gl_draw.c @@ -22,9 +22,8 @@ R_GetImageParms */ void R_GetTextureParms( int *w, int *h, int texnum ) { - gl_texture_t *glt; + gl_texture_t *glt = R_GetTexture( texnum ); - glt = R_GetTexture( texnum ); if( w ) *w = glt->srcWidth; if( h ) *h = glt->srcHeight; } @@ -60,9 +59,7 @@ GL_UpdateTexture */ void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, const byte *buffer, pixformat_t fmt ) { - byte *raw = NULL; - gl_texture_t *tex; - GLenum gl_format; + GLenum gl_format; switch( fmt ) { @@ -92,6 +89,7 @@ void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, co height = NearestPOW( height, false ); } + byte *raw; if( cols != width || rows != height ) { raw = GL_ResampleTexture( buffer, cols, rows, width, height, false ); @@ -106,7 +104,7 @@ void GL_UpdateTexture( int texnum, int cols, int rows, int width, int height, co if( rows > glConfig.max_2d_texture_size ) gEngfuncs.Host_Error( "%s: size %i exceeds hardware limits\n", __func__, rows ); - tex = R_GetTexture( texnum ); + gl_texture_t *tex = R_GetTexture( texnum ); GL_Bind( GL_KEEP_UNIT, texnum ); if( cols == tex->width && rows == tex->height ) @@ -130,11 +128,11 @@ void R_Set2DMode( qboolean enable ) { if( enable ) { - matrix4x4 projection_matrix, worldview_matrix; - if( glState.in2DMode ) return; + matrix4x4 projection_matrix; + // set 2D virtual screen size switch( tr.rotation ) { @@ -160,6 +158,7 @@ void R_Set2DMode( qboolean enable ) GL_LoadMatrix( projection_matrix ); pglMatrixMode( GL_MODELVIEW ); + matrix4x4 worldview_matrix; Matrix4x4_LoadIdentity( worldview_matrix ); GL_LoadMatrix( worldview_matrix ); diff --git a/ref/gl/gl_frustum.c b/ref/gl/gl_frustum.c index e3aa897e..3dcee4ec 100644 --- a/ref/gl/gl_frustum.c +++ b/ref/gl/gl_frustum.c @@ -30,9 +30,8 @@ static void GL_FrustumSetPlane( gl_frustum_t *out, int side, const vec3_t vecNor void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float flFovX, float flFovY ) { - float xs, xc; - vec3_t farpoint, nearpoint; vec3_t normal, iforward; + float xs, xc; // horizontal fov used for left and right planes SinCos( DEG2RAD( flFovX ) * 0.5f, &xs, &xc ); @@ -58,6 +57,7 @@ void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float f GL_FrustumSetPlane( out, FRUSTUM_TOP, normal, DotProduct( RI.cullorigin, normal )); // setup far plane + vec3_t farpoint; VectorMA( RI.cullorigin, flZFar, RI.cull_vforward, farpoint ); GL_FrustumSetPlane( out, FRUSTUM_FAR, iforward, DotProduct( iforward, farpoint )); @@ -65,16 +65,16 @@ void GL_FrustumInitProj( gl_frustum_t *out, float flZNear, float flZFar, float f if( flZNear == 0.0f ) return; // setup near plane + vec3_t nearpoint; VectorMA( RI.cullorigin, flZNear, RI.cull_vforward, nearpoint ); GL_FrustumSetPlane( out, FRUSTUM_NEAR, RI.cull_vforward, DotProduct( RI.cull_vforward, nearpoint )); } void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yTop, float yBottom, float flZNear, float flZFar ) { - vec3_t iforward, iright, iup; - // setup the near and far planes float orgOffset = DotProduct( RI.cullorigin, RI.cull_vforward ); + vec3_t iforward; VectorNegate( RI.cull_vforward, iforward ); // because quake ortho is inverted and far and near should be swaped @@ -83,6 +83,7 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT // setup left and right planes orgOffset = DotProduct( RI.cullorigin, RI.cull_vright ); + vec3_t iright; VectorNegate( RI.cull_vright, iright ); GL_FrustumSetPlane( out, FRUSTUM_LEFT, RI.cull_vright, xLeft + orgOffset ); @@ -90,6 +91,7 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT // setup top and buttom planes orgOffset = DotProduct( RI.cullorigin, RI.cull_vup ); + vec3_t iup; VectorNegate( RI.cull_vup, iup ); GL_FrustumSetPlane( out, FRUSTUM_TOP, RI.cull_vup, yTop + orgOffset ); @@ -100,7 +102,6 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const vec3_t maxs, int userClipFlags ) { int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags; - int i, bit; if( unlikely( r_nocull.value )) return false; @@ -108,7 +109,7 @@ qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const ve if( !iClipFlags ) return false; - for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 ) + for( int i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 ) { const mplane_t *p = &out->planes[FRUSTUM_PLANES - i]; @@ -160,7 +161,6 @@ qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const ve qboolean GL_FrustumCullSphere( const gl_frustum_t *out, const vec3_t center, float radius, int userClipFlags ) { int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags; - int i, bit; if( unlikely( r_nocull.value )) return false; @@ -168,7 +168,7 @@ qboolean GL_FrustumCullSphere( const gl_frustum_t *out, const vec3_t center, flo if( !iClipFlags ) return false; - for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 ) + for( int i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 ) { const mplane_t *p = &out->planes[FRUSTUM_PLANES - i]; diff --git a/ref/gl/gl_image.c b/ref/gl/gl_image.c index 7da56351..42e09012 100644 --- a/ref/gl/gl_image.c +++ b/ref/gl/gl_image.c @@ -98,9 +98,6 @@ GL_ApplyTextureParams */ void GL_ApplyTextureParams( gl_texture_t *tex ) { - vec4_t border = { 0.0f, 0.0f, 0.0f, 1.0f }; - qboolean nomipmap; - if( !glw_state.initialized ) return; @@ -111,7 +108,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex ) return; // set texture filter - nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP ); + qboolean nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP ); if( !GL_TextureFilteringEnabled( tex )) { pglTexParameteri( tex->target, GL_TEXTURE_MIN_FILTER, nomipmap ? GL_NEAREST : GL_NEAREST_MIPMAP_NEAREST ); @@ -172,6 +169,7 @@ void GL_ApplyTextureParams( gl_texture_t *tex ) if( tex->target == GL_TEXTURE_3D || tex->target == GL_TEXTURE_CUBE_MAP_ARB ) pglTexParameteri( tex->target, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER ); + const vec4_t border = { 0.0f, 0.0f, 0.0f, 1.0f }; pglTexParameterfv( tex->target, GL_TEXTURE_BORDER_COLOR, border ); } else if( FBitSet( tex->flags, TF_CLAMP )) @@ -216,8 +214,7 @@ GL_UpdateTextureParams */ static void GL_UpdateTextureParams( int iTexture ) { - gl_texture_t *tex = &gl_textures[iTexture]; - qboolean nomipmap; + gl_texture_t *tex = &gl_textures[iTexture]; Assert( tex != NULL ); @@ -233,7 +230,7 @@ static void GL_UpdateTextureParams( int iTexture ) if( GL_Support( GL_TEXTURE_LOD_BIAS ) && ( tex->numMips > 1 ) && !FBitSet( tex->flags, TF_DEPTHMAP )) pglTexParameterf( tex->target, GL_TEXTURE_LOD_BIAS_EXT, gl_texture_lodbias.value ); - nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP ); + qboolean nomipmap = tex->numMips <= 1 || FBitSet( tex->flags, TF_NOMIPMAP|TF_DEPTHMAP ); if( !GL_TextureFilteringEnabled( tex )) { @@ -254,8 +251,6 @@ R_SetTextureParameters */ void R_SetTextureParameters( void ) { - int i; - if( GL_Support( GL_ANISOTROPY_EXT )) { if( gl_texture_anisotropy.value > glConfig.max_texture_anisotropy ) @@ -278,7 +273,7 @@ void R_SetTextureParameters( void ) ClearBits( gl_lightmap_nearest.flags, FCVAR_CHANGED ); // change all the existing mipmapped texture objects - for( i = 0; i < gl_numTextures; i++ ) + for( int i = 0; i < gl_numTextures; i++ ) GL_UpdateTextureParams( i ); } @@ -406,9 +401,6 @@ static size_t GL_CalcTextureSize( GLenum format, int width, int height, int dept static int GL_CalcMipmapCount( gl_texture_t *tex, qboolean haveBuffer ) { - int width, height; - int mipcount; - Assert( tex != NULL ); if( !haveBuffer || tex->target == GL_TEXTURE_3D ) @@ -419,10 +411,11 @@ static int GL_CalcMipmapCount( gl_texture_t *tex, qboolean haveBuffer ) return 1; // mip-maps can't exceeds 16 + int mipcount; for( mipcount = 0; mipcount < 16; mipcount++ ) { - width = Q_max( 1, ( tex->width >> mipcount )); - height = Q_max( 1, ( tex->height >> mipcount )); + int width = Q_max( 1, ( tex->width >> mipcount )); + int height = Q_max( 1, ( tex->height >> mipcount )); if( width == 1 && height == 1 ) break; } @@ -473,14 +466,15 @@ static void GL_SetTextureDimensions( gl_texture_t *tex, int width, int height, i if( !GL_Support( GL_ARB_TEXTURE_NPOT_EXT )) { - int step = (int)gl_round_down.value; - int scaled_width, scaled_height; + int step = (int)gl_round_down.value; + int scaled_width; for( scaled_width = 1; scaled_width < width; scaled_width <<= 1 ); if( step > 0 && width < scaled_width && ( step == 1 || ( scaled_width - width ) > ( scaled_width >> step ))) scaled_width >>= 1; + int scaled_height; for( scaled_height = 1; scaled_height < height; scaled_height <<= 1 ); if( step > 0 && height < scaled_height && ( step == 1 || ( scaled_height - height ) > ( scaled_height >> step ))) @@ -687,22 +681,20 @@ box filter 3x3 */ static void GL_BoxFilter3x3( byte *out, const byte *in, int w, int h, int x, int y ) { - int r = 0, g = 0, b = 0, a = 0; - int acount = 0; - int i, j, u, v; - const byte *pixel; + int r = 0, g = 0, b = 0, a = 0; + int acount = 0; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { - u = ( i - 1 ) + x; + int u = ( i - 1 ) + x; - for( j = 0; j < 3; j++ ) + for( int j = 0; j < 3; j++ ) { - v = ( j - 1 ) + y; + int v = ( j - 1 ) + y; if( u >= 0 && u < w && v >= 0 && v < h ) { - pixel = &in[( u + v * w ) * 4]; + const byte *pixel = &in[( u + v * w ) * 4]; if( pixel[3] != 0 ) { @@ -734,14 +726,13 @@ Apply box-filter to 1-bit alpha */ static byte *GL_ApplyFilter( const byte *source, int width, int height ) { - byte *in = (byte *)source; - byte *out = (byte *)source; - int i; + byte *in = (byte *)source; + byte *out = (byte *)source; if( FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE ) || glConfig.max_multisamples > 1 ) return in; - for( i = 0; source && i < width * height; i++, in += 4 ) + for( int i = 0; source && i < width * height; i++, in += 4 ) { if( in[0] == 0 && in[1] == 0 && in[2] == 0 && in[3] == 0 ) GL_BoxFilter3x3( in, source, width, height, i % width, i / width ); @@ -759,18 +750,13 @@ Operates in place, quartering the size of the texture */ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, int flags ) { - byte *out = in; - int instride = ALIGN( srcWidth * 4, 1 ); - int mipWidth, mipHeight, outpadding; - int row, x, y, z; - vec3_t normal; - if( !in ) return; - mipWidth = Q_max( 1, ( srcWidth >> 1 )); - mipHeight = Q_max( 1, ( srcHeight >> 1 )); - outpadding = ALIGN( mipWidth * 4, 1 ) - mipWidth * 4; - row = srcWidth << 2; + byte *out = in; + int instride = ALIGN( srcWidth * 4, 1 ); + int mipWidth = Q_max( 1, ( srcWidth >> 1 )); + int mipHeight = Q_max( 1, ( srcHeight >> 1 )); + int outpadding = ALIGN( mipWidth * 4, 1 ) - mipWidth * 4; if( FBitSet( flags, TF_ALPHACONTRAST )) { @@ -779,15 +765,17 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, } // move through all layers - for( z = 0; z < srcDepth; z++ ) + for( int z = 0; z < srcDepth; z++ ) { if( FBitSet( flags, TF_NORMALMAP )) { - for( y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding ) + for( int y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding ) { byte *next = ((( y << 1 ) + 1 ) < srcHeight ) ? ( in + instride ) : in; - for( x = 0, row = 0; x < mipWidth; x++, row += 8, out += 4 ) + int row = 0; + for( int x = 0; x < mipWidth; x++, row += 8, out += 4 ) { + vec3_t normal; if((( x << 1 ) + 1 ) < srcWidth ) { normal[0] = MAKE_SIGNED( in[row+0] ) + MAKE_SIGNED( in[row+4] ) @@ -816,10 +804,11 @@ static void GL_BuildMipMap( byte *in, int srcWidth, int srcHeight, int srcDepth, } else { - for( y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding ) + for( int y = 0; y < mipHeight; y++, in += instride * 2, out += outpadding ) { byte *next = ((( y << 1 ) + 1 ) < srcHeight ) ? ( in + instride ) : in; - for( x = 0, row = 0; x < mipWidth; x++, row += 8, out += 4 ) + int row = 0; + for( int x = 0; x < mipWidth; x++, row += 8, out += 4 ) { if((( x << 1 ) + 1 ) < srcWidth ) { @@ -960,11 +949,10 @@ show GL-errors on load images */ static void GL_CheckTexImageError( gl_texture_t *tex ) { - int err; - Assert( tex != NULL ); // catch possible errors + int err; if( gl_check_errors.value && ( err = pglGetError()) != GL_NO_ERROR ) gEngfuncs.Con_Printf( S_OPENGL_ERROR "%s while uploading %s [%s]\n", GL_ErrorString( err ), tex->name, GL_TargetToString( tex->target )); } @@ -978,14 +966,6 @@ upload texture into video memory */ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) { - byte *buf, *data; - size_t texsize, size; - uint width, height, depth; - uint i, j, numSides; - qboolean normalMap; - qboolean texture3d; - const byte *bufend; - // dedicated server if( !glw_state.initialized ) return true; @@ -1025,19 +1005,19 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) gEngfuncs.Con_Reportf( "%s: %s s&3 [%d x %d]\n", __func__, tex->name, pic->width, pic->height ); } - buf = pic->buffer; - bufend = pic->buffer + pic->size; // total image size include all the layers, cube sides, mipmaps - texsize = GL_CalcTextureSize( tex->format, tex->width, tex->height, tex->depth ); - normalMap = FBitSet( tex->flags, TF_NORMALMAP ) ? true : false; - numSides = FBitSet( pic->flags, IMAGE_CUBEMAP ) ? 6 : 1; - texture3d = ( tex->target == GL_TEXTURE_3D ); + byte *buf = pic->buffer; + const byte *bufend = pic->buffer + pic->size; // total image size include all the layers, cube sides, mipmaps + size_t texsize = GL_CalcTextureSize( tex->format, tex->width, tex->height, tex->depth ); + qboolean normalMap = FBitSet( tex->flags, TF_NORMALMAP ) ? true : false; + uint numSides = FBitSet( pic->flags, IMAGE_CUBEMAP ) ? 6 : 1; + qboolean texture3d = ( tex->target == GL_TEXTURE_3D ); // uploading texture into video memory, change the binding glState.currentTextures[glState.activeTMU] = tex->texnum; glState.currentTexturesIndex[glState.activeTMU] = tex - gl_textures; pglBindTexture( tex->target, tex->texnum ); - for( i = 0; i < numSides; i++ ) + for( uint i = 0; i < numSides; i++ ) { // track the buffer bounds if( buf != NULL && buf >= bufend ) @@ -1045,13 +1025,13 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) if( ImageCompressed( pic->type )) { - for( j = 0; j < Q_max( 1, pic->numMips ); j++ ) + for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ ) { - width = Q_max( 1, ( tex->width >> j )); - height = Q_max( 1, ( tex->height >> j )); - depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth; + uint width = Q_max( 1, ( tex->width >> j )); + uint height = Q_max( 1, ( tex->height >> j )); + uint depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth; texsize = GL_CalcTextureSize( tex->format, width, height, depth ); - size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth ); + size_t size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth ); GL_TextureImageCompressed( tex, i, j, width, height, depth, size, buf ); tex->size += texsize; buf += size; // move pointer @@ -1062,13 +1042,13 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) } else if( Q_max( 1, pic->numMips ) > 1 ) // not-compressed DDS { - for( j = 0; j < Q_max( 1, pic->numMips ); j++ ) + for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ ) { - width = Q_max( 1, ( tex->width >> j )); - height = Q_max( 1, ( tex->height >> j )); - depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth; + uint width = Q_max( 1, ( tex->width >> j )); + uint height = Q_max( 1, ( tex->height >> j )); + uint depth = texture3d ? Q_max( 1, ( tex->depth >> j )) : tex->depth; texsize = GL_CalcTextureSize( tex->format, width, height, depth ); - size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth ); + size_t size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, depth ); GL_TextureImageRAW( tex, i, j, width, height, depth, pic->type, buf ); tex->size += texsize; buf += size; // move pointer @@ -1083,6 +1063,7 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) int mipCount = GL_CalcMipmapCount( tex, ( buf != NULL )); // NOTE: only single uncompressed textures can be resamples, no mips, no layers, no sides + byte *data; if(( tex->depth == 1 ) && (( pic->width != tex->width ) || ( pic->height != tex->height ))) data = GL_ResampleTexture( buf, pic->width, pic->height, tex->width, tex->height, normalMap ); else data = buf; @@ -1091,12 +1072,11 @@ static qboolean GL_UploadTexture( gl_texture_t *tex, rgbdata_t *pic ) data = GL_ApplyFilter( data, tex->width, tex->height ); // mips will be auto-generated if desired - for( j = 0; j < mipCount; j++ ) + for( int j = 0; j < mipCount; j++ ) { - width = Q_max( 1, ( tex->width >> j )); - height = Q_max( 1, ( tex->height >> j )); + uint width = Q_max( 1, ( tex->width >> j )); + uint height = Q_max( 1, ( tex->height >> j )); texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth ); - size = gEngfuncs.Image_CalcImageSize( pic->type, width, height, tex->depth ); GL_TextureImageRAW( tex, i, j, width, height, tex->depth, pic->type, data ); if( mipCount > 1 ) GL_BuildMipMap( data, width, height, tex->depth, tex->flags ); @@ -1174,12 +1154,12 @@ static void GL_ProcessImage( gl_texture_t *tex, rgbdata_t *pic ) if( FBitSet( pic->flags, IMAGE_PLAYERDECAL ) && pic->buffer && pic->type == PF_RGBA_32 && FBitSet( pic->flags, IMAGE_HAS_ALPHA ) && !FBitSet( pic->flags, IMAGE_PREMULTIPLIED )) { - int i, cnt = (int)( pic->width * pic->height ); - byte *p = pic->buffer; + int cnt = (int)( pic->width * pic->height ); + byte *p = pic->buffer; - for( i = 0; i < cnt; i++, p += 4 ) + for( int i = 0; i < cnt; i++, p += 4 ) { - int a = p[3]; + int a = p[3]; p[0] = ( p[0] * a + 127 ) / 255; p[1] = ( p[1] * a + 127 ) / 255; p[2] = ( p[2] * a + 127 ) / 255; @@ -1200,12 +1180,10 @@ GL_CheckTexName */ static qboolean GL_CheckTexName( const char *name ) { - int len; - if( COM_StringEmptyOrNULL( name )) return false; - len = Q_strlen( name ); + int len = Q_strlen( name ); // because multi-layered textures can exceed name string if( len >= sizeof( gl_textures->name )) @@ -1224,13 +1202,10 @@ GL_TextureForName */ static gl_texture_t *GL_TextureForName( const char *name ) { - gl_texture_t *tex; - uint hash; - // find the texture in array - hash = COM_HashKey( name, TEXTURES_HASH_SIZE ); + uint hash = COM_HashKey( name, TEXTURES_HASH_SIZE ); - for( tex = gl_texturesHashTable[hash]; tex != NULL; tex = tex->nextHash ) + for( gl_texture_t *tex = gl_texturesHashTable[hash]; tex != NULL; tex = tex->nextHash ) { if( !Q_stricmp( tex->name, name )) return tex; @@ -1265,9 +1240,7 @@ static gl_texture_t *GL_AllocTexture( const char *name, texFlags_t flags ) if( texnum >= MAX_TEXTURES || gl_textures[texnum].texnum != 0 ) { // find a free texture_t slot - uint i; - - for( i = 0; i < MAX_TEXTURES; i++ ) + for( uint i = 0; i < MAX_TEXTURES; i++ ) { if( gl_textures[i].texnum ) continue; @@ -1309,9 +1282,6 @@ GL_DeleteTexture */ static void GL_DeleteTexture( gl_texture_t *tex ) { - gl_texture_t **prev; - gl_texture_t *cur; - Assert( tex != NULL ); // already freed? @@ -1325,11 +1295,11 @@ static void GL_DeleteTexture( gl_texture_t *tex ) } // remove from hash table - prev = &gl_texturesHashTable[tex->hashValue]; + gl_texture_t **prev = &gl_texturesHashTable[tex->hashValue]; while( 1 ) { - cur = *prev; + gl_texture_t *cur = *prev; if( !cur ) break; if( cur == tex ) @@ -1374,25 +1344,21 @@ recalc image room */ void GL_UpdateTexSize( int texnum, int width, int height, int depth ) { - int i, j, texsize; - int numSides; - gl_texture_t *tex; - if( texnum <= 0 || texnum >= MAX_TEXTURES ) return; - tex = &gl_textures[texnum]; - numSides = FBitSet( tex->flags, TF_CUBEMAP ) ? 6 : 1; + gl_texture_t *tex = &gl_textures[texnum]; + int numSides = FBitSet( tex->flags, TF_CUBEMAP ) ? 6 : 1; GL_SetTextureDimensions( tex, width, height, depth ); tex->size = 0; // recompute now - for( i = 0; i < numSides; i++ ) + for( int i = 0; i < numSides; i++ ) { - for( j = 0; j < Q_max( 1, tex->numMips ); j++ ) + for( int j = 0; j < Q_max( 1, tex->numMips ); j++ ) { width = Q_max( 1, ( tex->width >> j )); height = Q_max( 1, ( tex->height >> j )); - texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth ); + int texsize = GL_CalcTextureSize( tex->format, width, height, tex->depth ); tex->size += texsize; } } @@ -1405,14 +1371,13 @@ GL_LoadTexture */ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ) { - gl_texture_t *tex; - rgbdata_t *pic; - uint picFlags = 0; + uint picFlags = 0; if( !GL_CheckTexName( name )) return 0; // see if already loaded + gl_texture_t *tex; if(( tex = GL_TextureForName( name ))) return (tex - gl_textures); @@ -1425,7 +1390,7 @@ int GL_LoadTexture( const char *name, const byte *buf, size_t size, int flags ) // set some image flags gEngfuncs.Image_SetForceFlags( picFlags ); - pic = gEngfuncs.FS_LoadImage( name, buf, size ); + rgbdata_t *pic = gEngfuncs.FS_LoadImage( name, buf, size ); if( !pic ) return 0; // couldn't loading image // allocate the new one @@ -1453,19 +1418,15 @@ GL_LoadTextureArray */ int GL_LoadTextureArray( const char **names, int flags ) { - rgbdata_t *pic, *src; - char basename[256]; - uint numLayers = 0; - char name[256]; - gl_texture_t *tex; - size_t len = 0; - int ret = 0; - uint i, j; - if( !names || !names[0] || !glw_state.initialized ) return 0; + char name[256]; + char basename[256]; + // count layers (g-cont. this is pontentially unsafe loop) + uint numLayers = 0; + uint i; for( i = 0; i < glConfig.max_2d_texture_layers && ( *names[i] != '\0' ); i++ ) numLayers++; name[0] = '\0'; @@ -1473,6 +1434,8 @@ int GL_LoadTextureArray( const char **names, int flags ) if( numLayers <= 0 ) return 0; // create complexname from layer names + size_t len = 0; + int ret = 0; for( i = 0; i < numLayers - 1; i++ ) { COM_FileBase( names[i], basename, sizeof( basename )); @@ -1494,15 +1457,17 @@ int GL_LoadTextureArray( const char **names, int flags ) return 0; // see if already loaded + gl_texture_t *tex; if(( tex = GL_TextureForName( name ))) return (tex - gl_textures); // load all the images and pack it into single image - for( i = 0, pic = NULL; i < numLayers; i++ ) + rgbdata_t *pic = NULL; + for( i = 0; i < numLayers; i++ ) { - size_t srcsize, dstsize, mipsize; + size_t srcsize, dstsize, mipsize; - src = gEngfuncs.FS_LoadImage( names[i], NULL, 0 ); + rgbdata_t *src = gEngfuncs.FS_LoadImage( names[i], NULL, 0 ); if( !src ) break; // coldn't find layer if( pic ) @@ -1550,7 +1515,7 @@ int GL_LoadTextureArray( const char **names, int flags ) mipsize = srcsize = dstsize = 0; - for( j = 0; j < Q_max( 1, pic->numMips ); j++ ) + for( uint j = 0; j < Q_max( 1, pic->numMips ); j++ ) { int width = Q_max( 1, ( pic->width >> j )); int height = Q_max( 1, ( pic->height >> j )); @@ -1603,12 +1568,11 @@ GL_LoadTextureFromBuffer */ int GL_LoadTextureFromBuffer( const char *name, rgbdata_t *pic, texFlags_t flags, qboolean update ) { - gl_texture_t *tex; - if( !GL_CheckTexName( name )) return 0; // see if already loaded + gl_texture_t *tex; if(( tex = GL_TextureForName( name )) && !update ) return (tex - gl_textures); @@ -1648,9 +1612,8 @@ creates texture from buffer */ int GL_CreateTexture( const char *name, int width, int height, const void *buffer, texFlags_t flags ) { - qboolean update = FBitSet( flags, TF_UPDATE ) ? true : false; - int datasize = 1; - rgbdata_t r_empty; + qboolean update = FBitSet( flags, TF_UPDATE ) ? true : false; + int datasize = 1; if( FBitSet( flags, TF_ARB_16BIT )) datasize = 2; @@ -1658,6 +1621,8 @@ int GL_CreateTexture( const char *name, int width, int height, const void *buffe datasize = 4; ClearBits( flags, TF_UPDATE ); + + rgbdata_t r_empty; memset( &r_empty, 0, sizeof( r_empty )); r_empty.width = width; r_empty.height = height; @@ -1750,12 +1715,11 @@ GL_FindTexture */ int GL_FindTexture( const char *name ) { - gl_texture_t *tex; - if( !GL_CheckTexName( name )) return 0; // see if already loaded + gl_texture_t *tex; if(( tex = GL_TextureForName( name ))) return (tex - gl_textures); @@ -1783,13 +1747,11 @@ GL_ProcessTexture */ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ) { - gl_texture_t *image; - rgbdata_t *pic; - int flags = 0; + int flags = 0; if( texnum <= 0 || texnum >= MAX_TEXTURES ) return; // missed image - image = &gl_textures[texnum]; + gl_texture_t *image = &gl_textures[texnum]; // select mode if( gamma != -1.0f ) @@ -1819,7 +1781,7 @@ void GL_ProcessTexture( int texnum, float gamma, int topColor, int bottomColor ) } // all the operations makes over the image copy not an original - pic = gEngfuncs.FS_CopyImage( image->original ); + rgbdata_t *pic = gEngfuncs.FS_CopyImage( image->original ); // we need to expand image into RGBA buffer if( pic->type == PF_INDEXED_24 || pic->type == PF_INDEXED_32 ) @@ -1842,9 +1804,9 @@ return size of all uploaded textures */ int GL_TexMemory( void ) { - int i, total = 0; + int total = 0; - for( i = 0; i < gl_numTextures; i++ ) + for( int i = 0; i < gl_numTextures; i++ ) total += gl_textures[i].size; return total; @@ -1887,13 +1849,14 @@ R_TextureList_f */ void R_TextureList_f( void ) { - gl_texture_t *image; - int i, texCount, bytes = 0; + int bytes = 0; gEngfuncs.Con_Printf( "\n" ); gEngfuncs.Con_Printf( " -id- -w- -h- -size- -fmt- -type- -data- -encode- -wrap- -depth- -name--------\n" ); - for( i = texCount = 0, image = gl_textures; i < gl_numTextures; i++, image++ ) + int texCount = 0; + gl_texture_t *image = gl_textures; + for( int i = 0; i < gl_numTextures; i++, image++ ) { if( !image->texnum ) continue; @@ -2123,13 +2086,11 @@ R_ShutdownImages */ void R_ShutdownImages( void ) { - gl_texture_t *tex; - int i; - gEngfuncs.Cmd_RemoveCommand( "texturelist" ); GL_CleanupAllTextureUnits(); - for( i = 0, tex = gl_textures; i < gl_numTextures; i++, tex++ ) + gl_texture_t *tex = gl_textures; + for( int i = 0; i < gl_numTextures; i++, tex++ ) GL_DeleteTexture( tex ); memset( tr.lightmapTextures, 0, sizeof( tr.lightmapTextures )); @@ -2154,10 +2115,8 @@ void R_TextureReplacementReport( const char *modelname, int gl_texturenum, const qboolean R_SearchForTextureReplacement( char *out, size_t size, const char *modelname, const char *fmt, ... ) { va_list ap; - int ret; - va_start( ap, fmt ); - ret = Q_vsnprintf( out, size, fmt, ap ); + int ret = Q_vsnprintf( out, size, fmt, ap ); va_end( ap ); if( ret < 0 ) @@ -2183,18 +2142,7 @@ was there. This is used to test for texture thrashing. */ void R_ShowTextures( void ) { - float w, h; - int start, k; - int base_w, base_h; - rgba_t color = { 255, 255, 255, 255 }; - int charHeight; - static qboolean showHelp = true; - float time; //nc add - float time_cubemap; //nc add - float cbm_cos, cbm_sin; //nc add - int per_page; //nc add - qboolean empty_page; - int skipped_empty_pages; + static qboolean showHelp = true; if( !r_showtextures->value ) return; @@ -2207,42 +2155,41 @@ void R_ShowTextures( void ) pglClear( GL_COLOR_BUFFER_BIT ); - w = 200; - h = 200; + float w = 200; + float h = 200; - time = gp_cl->time * 0.5f; + float time = gp_cl->time * 0.5f; time -= floor( time ); - time_cubemap = gp_cl->time * 0.25f; + float time_cubemap = gp_cl->time * 0.25f; time_cubemap -= floor( time_cubemap ); time_cubemap *= M_PI2_F; + float cbm_cos, cbm_sin; SinCos( time_cubemap, &cbm_sin, &cbm_cos ); + int charHeight; gEngfuncs.Con_DrawStringLen( NULL, NULL, &charHeight ); - base_w = gpGlobals->width / w; - base_h = gpGlobals->height / ( h + charHeight * 2 ); - per_page = base_w * base_h; - start = per_page * ( r_showtextures->value - 1 ) + 1; // skip empty null texture + int base_w = gpGlobals->width / w; + int base_h = gpGlobals->height / ( h + charHeight * 2 ); + int per_page = base_w * base_h; + int start = per_page * ( r_showtextures->value - 1 ) + 1; // skip empty null texture GL_SetRenderMode( kRenderTransTexture ); // nc changed from normal to trans, Con_DrawString does this anyway - empty_page = true; - skipped_empty_pages = 0; + qboolean empty_page = true; + int skipped_empty_pages = 0; while( empty_page ) { - for( k = 0; k < per_page; k++ ) + for( int k = 0; k < per_page; k++ ) { - const gl_texture_t *image; - int i; - - i = k + start; + int i = k + start; if( i >= MAX_TEXTURES ) { empty_page = false; break; } - image = R_GetTexture( i ); + const gl_texture_t *image = R_GetTexture( i ); if( pglIsTexture( image->texnum )) { empty_page = false; @@ -2264,24 +2211,19 @@ void R_ShowTextures( void ) gEngfuncs.CL_CenterPrint( text, 0.25f ); } - for( k = 0; k < per_page; k++ ) + const rgba_t color = { 255, 255, 255, 255 }; + for( int k = 0; k < per_page; k++ ) { - const gl_texture_t *image; - int textlen, i; - char text[MAX_VA_STRING]; - string shortname; - float x, y; - - i = k + start; + int i = k + start; if ( i >= MAX_TEXTURES ) break; - image = R_GetTexture( i ); + const gl_texture_t *image = R_GetTexture( i ); if( !pglIsTexture( image->texnum )) continue; - x = k % base_w * gpGlobals->width / base_w; - y = k / base_w * gpGlobals->height / base_h; + float x = k % base_w * gpGlobals->width / base_w; + float y = k / base_w * gpGlobals->height / base_h; pglColor4f( 1.0f, 1.0f, 1.0f, 1.0f ); GL_Bind( XASH_TEXTURE0, i ); @@ -2334,7 +2276,9 @@ void R_ShowTextures( void ) if( FBitSet( image->flags, TF_DEPTHMAP ) && !FBitSet( image->flags, TF_NOCOMPARE )) pglTexParameteri( image->target, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB ); + string shortname; COM_FileBase( image->name, shortname, sizeof( shortname )); + int textlen; gEngfuncs.Con_DrawStringLen( shortname, &textlen, NULL ); if( textlen > w ) @@ -2346,6 +2290,7 @@ void R_ShowTextures( void ) } gEngfuncs.Con_DrawString( x + 1, y + h, shortname, color ); + char text[MAX_VA_STRING]; if( image->target == GL_TEXTURE_3D || image->target == GL_TEXTURE_2D_ARRAY_EXT ) Q_snprintf( text, sizeof( text ), "%ix%ix%i %s", image->width, image->height, image->depth, GL_TargetToString( image->target )); else diff --git a/ref/gl/gl_opengl.c b/ref/gl/gl_opengl.c index d9936274..49e657eb 100644 --- a/ref/gl/gl_opengl.c +++ b/ref/gl/gl_opengl.c @@ -591,14 +591,11 @@ GL_SetDefaultTexState */ static void GL_SetDefaultTexState( void ) { - - int i; - memset( glState.currentTextures, -1, MAX_TEXTURE_UNITS * sizeof( *glState.currentTextures )); memset( glState.texCoordArrayMode, 0, MAX_TEXTURE_UNITS * sizeof( *glState.texCoordArrayMode )); memset( glState.genSTEnabled, 0, MAX_TEXTURE_UNITS * sizeof( *glState.genSTEnabled )); - for( i = 0; i < MAX_TEXTURE_UNITS; i++ ) + for( int i = 0; i < MAX_TEXTURE_UNITS; i++ ) { glState.currentTextureTargets[i] = GL_NONE; glState.texIdentityMatrix[i] = true; @@ -734,8 +731,6 @@ static void R_RenderInfo_f( void ) #if XASH_GLES static void GL_InitExtensionsGLES( void ) { - int extid; - // intialize wrapper type #if XASH_NANOGL glConfig.context = CONTEXT_TYPE_GLES_1_X; @@ -752,7 +747,7 @@ static void GL_InitExtensionsGLES( void ) glConfig.hardware_type = GLHW_GENERIC; - for( extid = GL_OPENGL_110 + 1; extid < GL_EXTCOUNT; extid++ ) + for( int extid = GL_OPENGL_110 + 1; extid < GL_EXTCOUNT; extid++ ) { switch( extid ) { @@ -1032,10 +1027,9 @@ void GL_InitExtensions( void ) if( !major && glConfig.version_string ) { const char *str = glConfig.version_string; - float ver; while( *str && ( *str < '0' || *str > '9' )) str++; - ver = Q_atof(str); + float ver = Q_atof(str); if( ver ) { glConfig.version_major = ver; @@ -1056,16 +1050,15 @@ void GL_InitExtensions( void ) pglGetIntegerv( GL_NUM_EXTENSIONS, &n ); if( n && pglGetStringi ) { - int i, len = 1; - char *str; + int len = 1; - for( i = 0; i < n; i++ ) + for( int i = 0; i < n; i++ ) len += Q_strlen((const char *)pglGetStringi( GL_EXTENSIONS, i )) + 1; - str = (char*)Mem_Calloc( r_temppool, len ); + char *str = (char*)Mem_Calloc( r_temppool, len ); glConfig.extensions_string = str; - for( i = 0; i < n; i++ ) + for( int i = 0; i < n; i++ ) { int l = Q_strncpy( str, pglGetStringi( GL_EXTENSIONS, i ), len ); str += l; @@ -1355,7 +1348,7 @@ void GL_CheckForErrors_( const char *filename, const int fileline ) if( !gl_check_errors.value || !gpGlobals->developer ) return; - int err = pglGetError( ); + int err = pglGetError(); if( err == GL_NO_ERROR ) return; diff --git a/ref/gl/gl_rmain.c b/ref/gl/gl_rmain.c index 05684861..110de077 100644 --- a/ref/gl/gl_rmain.c +++ b/ref/gl/gl_rmain.c @@ -85,16 +85,13 @@ Sorting translucent entities by rendermode then by distance */ static int R_TransEntityCompare( const void *a, const void *b ) { - cl_entity_t *ent1, *ent2; - vec3_t vecLen, org; - float dist1, dist2; - int rendermode1; - int rendermode2; + cl_entity_t *ent1 = *(cl_entity_t **)a; + cl_entity_t *ent2 = *(cl_entity_t **)b; + int rendermode1 = R_GetEntityRenderMode( ent1 ); + int rendermode2 = R_GetEntityRenderMode( ent2 ); - ent1 = *(cl_entity_t **)a; - ent2 = *(cl_entity_t **)b; - rendermode1 = R_GetEntityRenderMode( ent1 ); - rendermode2 = R_GetEntityRenderMode( ent2 ); + vec3_t vecLen, org; + float dist1, dist2; // sort by distance if( ent1->model->type != mod_brush || rendermode1 != kRenderTransAlpha ) @@ -139,19 +136,17 @@ Returns true if we behind to screen */ int R_WorldToScreen( const vec3_t point, vec3_t screen ) { - matrix4x4 worldToScreen; - qboolean behind; - float w; - if( !point || !screen ) return true; + matrix4x4 worldToScreen; Matrix4x4_Copy( worldToScreen, RI.worldviewProjectionMatrix ); screen[0] = worldToScreen[0][0] * point[0] + worldToScreen[0][1] * point[1] + worldToScreen[0][2] * point[2] + worldToScreen[0][3]; screen[1] = worldToScreen[1][0] * point[0] + worldToScreen[1][1] * point[1] + worldToScreen[1][2] * point[2] + worldToScreen[1][3]; - w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3]; + float w = worldToScreen[3][0] * point[0] + worldToScreen[3][1] * point[1] + worldToScreen[3][2] * point[2] + worldToScreen[3][3]; screen[2] = 0.0f; // just so we have something valid here + qboolean behind; if( w < 0.001f ) { behind = true; @@ -176,18 +171,16 @@ Convert a given point from screen into world space */ void R_ScreenToWorld( const vec3_t screen, vec3_t point ) { - matrix4x4 screenToWorld; - float w; - if( !point || !screen ) return; + matrix4x4 screenToWorld; Matrix4x4_Invert_Full( screenToWorld, RI.worldviewProjectionMatrix ); point[0] = screen[0] * screenToWorld[0][0] + screen[1] * screenToWorld[0][1] + screen[2] * screenToWorld[0][2] + screenToWorld[0][3]; point[1] = screen[0] * screenToWorld[1][0] + screen[1] * screenToWorld[1][1] + screen[2] * screenToWorld[1][2] + screenToWorld[1][3]; point[2] = screen[0] * screenToWorld[2][0] + screen[1] * screenToWorld[2][1] + screen[2] * screenToWorld[2][2] + screenToWorld[2][3]; - w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3]; + float w = screen[0] * screenToWorld[3][0] + screen[1] * screenToWorld[3][1] + screen[2] * screenToWorld[3][2] + screenToWorld[3][3]; if( w != 0.0f ) VectorScale( point, ( 1.0f / w ), point ); } @@ -301,13 +294,11 @@ R_Clear */ static void R_Clear( int bitMask ) { - int bits; - if( ENGINE_GET_PARM( PARM_DEV_OVERVIEW )) pglClearColor( 0.0f, 1.0f, 0.0f, 1.0f ); // green background (Valve rules) else pglClearColor( 0.5f, 0.5f, 0.5f, 1.0f ); - bits = GL_DEPTH_BUFFER_BIT; + int bits = GL_DEPTH_BUFFER_BIT; if( glState.stencilEnabled ) bits |= GL_STENCIL_BUFFER_BIT; @@ -381,8 +372,6 @@ R_SetupProjectionMatrix */ static void R_SetupProjectionMatrix( matrix4x4 m ) { - GLfloat xMin, xMax, yMin, yMax, zNear, zFar; - if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW )) { const ref_overview_t *ov = gEngfuncs.GetOverviewParms(); @@ -392,14 +381,14 @@ static void R_SetupProjectionMatrix( matrix4x4 m ) RI.farClip = R_GetFarClip(); - zNear = 4.0f; - zFar = Q_max( 256.0f, RI.farClip ); + GLfloat zNear = 4.0f; + GLfloat zFar = Q_max( 256.0f, RI.farClip ); - yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f ); - yMin = -yMax; + GLfloat yMax = zNear * tan( RI.rvp.fov_y * M_PI_F / 360.0f ); + GLfloat yMin = -yMax; - xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f ); - xMin = -xMax; + GLfloat xMax = zNear * tan( RI.rvp.fov_x * M_PI_F / 360.0f ); + GLfloat xMin = -xMax; if( tr.rotation & 1 ) { @@ -554,13 +543,11 @@ void R_SetupGL( qboolean set_gl_state ) if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP )) { - int x, x2, y, y2; - // set up viewport (main, playersetup) - x = floor( RI.rvp.viewport[0] * gpGlobals->width / gpGlobals->width ); - x2 = ceil(( RI.rvp.viewport[0] + RI.rvp.viewport[2] ) * gpGlobals->width / gpGlobals->width ); - y = floor( gpGlobals->height - RI.rvp.viewport[1] * gpGlobals->height / gpGlobals->height ); - y2 = ceil( gpGlobals->height - ( RI.rvp.viewport[1] + RI.rvp.viewport[3] ) * gpGlobals->height / gpGlobals->height ); + int x = floor( RI.rvp.viewport[0] * gpGlobals->width / gpGlobals->width ); + int x2 = ceil(( RI.rvp.viewport[0] + RI.rvp.viewport[2] ) * gpGlobals->width / gpGlobals->width ); + int y = floor( gpGlobals->height - RI.rvp.viewport[1] * gpGlobals->height / gpGlobals->height ); + int y2 = ceil( gpGlobals->height - ( RI.rvp.viewport[1] + RI.rvp.viewport[3] ) * gpGlobals->height / gpGlobals->height ); if( tr.rotation & 1 ) pglViewport( y2, x, y - y2, x2 - x ); @@ -608,20 +595,16 @@ static gl_texture_t *R_RecursiveFindWaterTexture( const mnode_t *node, const mno if( node->contents < 0 ) { - mleaf_t *pleaf; - msurface_t **mark; - int i, c; - // ignore non-liquid leaves if( node->contents != CONTENTS_WATER && node->contents != CONTENTS_LAVA && node->contents != CONTENTS_SLIME ) return NULL; // find texture - pleaf = (mleaf_t *)node; - mark = pleaf->firstmarksurface; - c = pleaf->nummarksurfaces; + mleaf_t *pleaf = (mleaf_t *)node; + msurface_t **mark = pleaf->firstmarksurface; + int c = pleaf->nummarksurfaces; - for( i = 0; i < c; i++, mark++ ) + for( int i = 0; i < c; i++, mark++ ) { if( (*mark)->flags & SURF_DRAWTURB && (*mark)->texinfo && (*mark)->texinfo->texture ) return R_GetTexture( (*mark)->texinfo->texture->gl_texturenum ); @@ -671,10 +654,6 @@ from underwater leaf (idea: XaeroX) */ static void R_CheckFog( void ) { - cl_entity_t *ent; - gl_texture_t *tex; - int i, cnt, count; - // quake global fog if( FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE )) { @@ -717,7 +696,8 @@ static void R_CheckFog( void ) return; } - ent = gEngfuncs.CL_GetWaterEntity( RI.rvp.vieworigin ); + cl_entity_t *ent = gEngfuncs.CL_GetWaterEntity( RI.rvp.vieworigin ); + int cnt; if( ent && ent->model && ent->model->type == mod_brush && ent->curstate.skin < 0 ) cnt = ent->curstate.skin; else cnt = RI.viewleaf->contents; @@ -726,16 +706,15 @@ static void R_CheckFog( void ) if( !IsLiquidContents( RI.cached_contents ) && IsLiquidContents( cnt )) { - tex = NULL; + gl_texture_t *tex = NULL; // check for water texture if( ent && ent->model && ent->model->type == mod_brush ) { - msurface_t *surf; + int count = ent->model->nummodelsurfaces; - count = ent->model->nummodelsurfaces; - - for( i = 0, surf = &ent->model->surfaces[ent->model->firstmodelsurface]; i < count; i++, surf++ ) + msurface_t *surf = &ent->model->surfaces[ent->model->firstmodelsurface]; + for( int i = 0; i < count; i++, surf++ ) { if( surf->flags & SURF_DRAWTURB && surf->texinfo && surf->texinfo->texture ) { @@ -817,13 +796,11 @@ R_DrawEntitiesOnList */ static void R_DrawEntitiesOnList( void ) { - int i; - tr.blend = 1.0f; GL_CheckForErrors(); // first draw solid entities - for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) + for( int i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) { RI.currententity = tr.draw_list->solid_entities[i]; RI.currentmodel = RI.currententity->model; @@ -855,7 +832,7 @@ static void R_DrawEntitiesOnList( void ) GL_CheckForErrors(); // draw sprites seperately, because of alpha blending - for( i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) + for( int i = 0; i < tr.draw_list->num_solid_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) { RI.currententity = tr.draw_list->solid_entities[i]; RI.currentmodel = RI.currententity->model; @@ -886,7 +863,7 @@ static void R_DrawEntitiesOnList( void ) GL_CheckForErrors(); // then draw translucent entities - for( i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) + for( int i = 0; i < tr.draw_list->num_trans_entities && !FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW ); i++ ) { RI.currententity = tr.draw_list->trans_entities[i]; RI.currentmodel = RI.currententity->model; @@ -1174,11 +1151,8 @@ CL_FxBlend */ int CL_FxBlend( cl_entity_t *e ) { - int blend = 0; - float offset, dist; - vec3_t tmp; - - offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx + int blend = 0; + float offset = ((int)e->index ) * 363.0f; // Use ent index to de-sync these fx switch( e->curstate.renderfx ) { @@ -1257,9 +1231,11 @@ int CL_FxBlend( cl_entity_t *e ) break; case kRenderFxHologram: case kRenderFxDistort: + { + vec3_t tmp; VectorCopy( e->origin, tmp ); VectorSubtract( tmp, RI.rvp.vieworigin, tmp ); - dist = DotProduct( tmp, RI.vforward ); + float dist = DotProduct( tmp, RI.vforward ); // turn off distance fade if( e->curstate.renderfx == kRenderFxDistort ) @@ -1277,6 +1253,7 @@ int CL_FxBlend( cl_entity_t *e ) blend += gEngfuncs.COM_RandomLong( -32, 31 ); } break; + } default: blend = e->curstate.renderamt; break; diff --git a/ref/gl/gl_rpart.c b/ref/gl/gl_rpart.c index 24a9c882..96b36fd6 100644 --- a/ref/gl/gl_rpart.c +++ b/ref/gl/gl_rpart.c @@ -47,12 +47,6 @@ update particle color, position, free expired and draw it */ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float partsize ) { - particle_t *p; - vec3_t right, up; - color24 color; - int alpha; - float size; - if( !cl_active_particles ) return; // nothing to draw? @@ -66,11 +60,11 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float pglBegin( GL_QUADS ); - for( p = cl_active_particles; p; p = p->next ) + for( particle_t *p = cl_active_particles; p; p = p->next ) { if(( p->type != pt_blob ) || ( p->unused == 255 )) { - size = partsize; // get initial size of particle + float size = partsize; // get initial size of particle // scale up to keep particles from disappearing size += (p->org[0] - RI.rvp.vieworigin[0]) * RI.cull_vforward[0]; @@ -81,13 +75,14 @@ void CL_DrawParticles( double frametime, particle_t *cl_active_particles, float else size = partsize + size * 0.002f; // scale the axes by radius + vec3_t right, up; VectorScale( RI.cull_vright, size, right ); VectorScale( RI.cull_vup, size, up ); p->color = bound( 0, p->color, 255 ); - color = tr.palette[p->color]; + color24 color = tr.palette[p->color]; - alpha = 255 * (p->die - gp_cl->time) * 16.0f; + int alpha = 255 * (p->die - gp_cl->time) * 16.0f; if( alpha > 255 || p->type == pt_static ) alpha = 255; @@ -120,11 +115,10 @@ check tracer bbox */ static qboolean CL_CullTracer( particle_t *p, const vec3_t start, const vec3_t end ) { - vec3_t mins, maxs; - int i; + vec3_t mins, maxs; // compute the bounding box - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { if( start[i] < end[i] ) { @@ -157,11 +151,6 @@ update tracer color, position, free expired and draw it */ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) { - float scale, atten, gravity; - vec3_t screenLast, screen; - vec3_t start, end, delta; - particle_t *p; - // update tracer color if this is changed if( FBitSet( tracerred->flags|tracergreen->flags|tracerblue->flags|traceralpha->flags, FCVAR_CHANGED )) { @@ -187,17 +176,18 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) pglDisable( GL_ALPHA_TEST ); pglDepthMask( GL_FALSE ); - gravity = frametime * gp_movevars->gravity; - scale = 1.0 - (frametime * 0.9); + float gravity = frametime * gp_movevars->gravity; + float scale = 1.0 - (frametime * 0.9); if( scale < 0.0f ) scale = 0.0f; pglBegin( GL_QUADS ); - for( p = cl_active_tracers; p; p = p->next ) + for( particle_t *p = cl_active_tracers; p; p = p->next ) { - atten = (p->die - gp_cl->time); + float atten = (p->die - gp_cl->time); if( atten > 0.1f ) atten = 0.1f; + vec3_t start, end, delta; VectorScale( p->vel, ( p->ramp * atten ), delta ); VectorAdd( p->org, delta, end ); VectorCopy( p->org, start ); @@ -206,7 +196,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) { vec3_t verts[4], tmp2; vec3_t tmp, normal; - color24 color; + vec3_t screen, screenLast; // Transform point into screen space TriWorldToScreen( start, screen ); @@ -235,7 +225,7 @@ void CL_DrawTracers( double frametime, particle_t *cl_active_tracers ) p->color = TRACER_COLORINDEX_DEFAULT; } - color = gTracerColors[p->color]; + color24 color = gTracerColors[p->color]; pglColor4ub( color.r, color.g, color.b, p->unused ); pglTexCoord2f( 0.0f, 0.8f ); diff --git a/ref/gl/gl_rsurf.c b/ref/gl/gl_rsurf.c index cd957c61..8cf66fff 100644 --- a/ref/gl/gl_rsurf.c +++ b/ref/gl/gl_rsurf.c @@ -130,14 +130,13 @@ void Mod_SetOrthoBounds( const float *mins, const float *maxs ) void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample_size, vec2_t coords ) { const mextrasurf_t *info = surf->info; - float s, t; - s = DotProduct( v, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; + float s = DotProduct( v, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; s += surf->light_s * sample_size; s += sample_size * 0.5f; s /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width; - t = DotProduct( v, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; + float t = DotProduct( v, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; t += surf->light_t * sample_size; t += sample_size * 0.5f; t /= BLOCK_SIZE * sample_size; //fa->texinfo->texture->width; @@ -148,10 +147,9 @@ void R_LightmapCoord( const vec3_t v, const msurface_t *surf, const float sample static void R_TextureCoord( const vec3_t v, const msurface_t *surf, vec2_t coords ) { const mtexinfo_t *info = surf->texinfo; - float s, t; - s = DotProduct( v, info->vecs[0] ); - t = DotProduct( v, info->vecs[1] ); + float s = DotProduct( v, info->vecs[0] ); + float t = DotProduct( v, info->vecs[1] ); if( !FBitSet( surf->flags, SURF_DRAWTURB )) { @@ -188,14 +186,14 @@ static void R_GetEdgePosition( const model_t *mod, const msurface_t *fa, int i, static void BoundPoly( int numverts, float *verts, vec3_t mins, vec3_t maxs ) { - int i, j; float *v; + int i; ClearBounds( mins, maxs ); for( i = 0, v = verts; i < numverts; i++ ) { - for( j = 0; j < 3; j++, v++ ) + for( int j = 0; j < 3; j++, v++ ) { if( *v < mins[j] ) mins[j] = *v; if( *v > maxs[j] ) maxs[j] = *v; @@ -207,19 +205,18 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu { vec3_t front[SUBDIVIDE_SIZE], back[SUBDIVIDE_SIZE]; float dist[SUBDIVIDE_SIZE]; - float m, frac, *v; - int i, j, k, f, b; + float *v; + int j; vec3_t mins, maxs; - glpoly2_t *poly; if( numverts > ( SUBDIVIDE_SIZE - 4 )) gEngfuncs.Host_Error( "%s: too many vertexes on face ( %i )\n", __func__, numverts ); BoundPoly( numverts, verts, mins, maxs ); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { - m = ( mins[i] + maxs[i] ) * 0.5f; + float m = ( mins[i] + maxs[i] ) * 0.5f; m = SUBDIVIDE_SIZE * floor( m / SUBDIVIDE_SIZE + 0.5f ); if( maxs[i] - m < 8 ) continue; if( m - mins[i] < 8 ) continue; @@ -234,7 +231,7 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu v -= i; VectorCopy( verts, v ); - f = b = 0; + int f = 0, b = 0; v = verts; for( j = 0; j < numverts; j++, v += 3 ) { @@ -256,8 +253,8 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu if(( dist[j] > 0 ) != ( dist[j+1] > 0 )) { // clip point - frac = dist[j] / ( dist[j] - dist[j+1] ); - for( k = 0; k < 3; k++ ) + float frac = dist[j] / ( dist[j] - dist[j+1] ); + for( int k = 0; k < 3; k++ ) front[f][k] = back[b][k] = v[k] + frac * (v[3+k] - v[k]); f++; b++; @@ -273,35 +270,29 @@ static void SubdividePolygon_r( model_t *loadmodel, msurface_t *warpface, int nu ClearBits( warpface->flags, SURF_DRAWTURB_QUADS ); // add a point in the center to help keep warp valid - poly = Mem_Calloc( loadmodel->mempool, sizeof( glpoly2_t ) + numverts * VERTEXSIZE * sizeof( float )); + glpoly2_t *poly = Mem_Calloc( loadmodel->mempool, sizeof( glpoly2_t ) + numverts * VERTEXSIZE * sizeof( float )); poly->next = warpface->polys; poly->flags = warpface->flags; warpface->polys = poly; poly->numverts = numverts; - for( i = 0; i < numverts; i++, verts += 3 ) + for( int i = 0; i < numverts; i++, verts += 3 ) { VectorCopy( verts, poly->verts[i] ); R_TextureCoord( verts, warpface, &poly->verts[i][3] ); - // lightmap texcoords for subdivided surfaces will be calculated later } } static void GL_BuildLightmapWater( model_t *mod, msurface_t *fa ) { - float sample_size; - glpoly2_t *poly; - if( !mod || !fa->texinfo || !fa->texinfo->texture ) return; // bad polygon? - sample_size = gEngfuncs.Mod_SampleSizeForFace( fa ); + float sample_size = gEngfuncs.Mod_SampleSizeForFace( fa ); - for( poly = fa->polys; poly; poly = poly->next ) + for( glpoly2_t *poly = fa->polys; poly; poly = poly->next ) { - int i; - - for( i = 0; i < poly->numverts; i++ ) + for( int i = 0; i < poly->numverts; i++ ) { vec3_t vec; VectorCopy( poly->verts[i], vec ); @@ -320,9 +311,6 @@ recalculate fog color for current pass count */ static void GL_SetupFogColorForSurfacesEx( int passes, float density, qboolean blend_lightmaps ) { - vec4_t fogColor; - float factor, div; - if( !glState.isFogEnabled ) return; @@ -332,8 +320,9 @@ static void GL_SetupFogColorForSurfacesEx( int passes, float density, qboolean b return; } - div = passes - 1; - factor = passes; + float div = passes - 1; + float factor = passes; + vec4_t fogColor; fogColor[0] = pow( RI.fogColor[0] / div, ( 1.0f / factor )); fogColor[1] = pow( RI.fogColor[1] / div, ( 1.0f / factor )); fogColor[2] = pow( RI.fogColor[2] / div, ( 1.0f / factor )); @@ -373,10 +362,9 @@ can be done reasonably. void GL_SubdivideSurface( model_t *loadmodel, msurface_t *fa ) { vec3_t verts[SUBDIVIDE_SIZE]; - int i; // convert edges back to a normal polygon - for( i = 0; i < fa->numedges; i++ ) + for( int i = 0; i < fa->numedges; i++ ) R_GetEdgePosition( loadmodel, fa, i, verts[i] ); if( glConfig.context == CONTEXT_TYPE_GL ) @@ -393,19 +381,15 @@ GL_BuildPolygonFromSurface */ static int GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) { - int i, lnumverts, nColinElim = 0; - float sample_size; - texture_t *tex; - gl_texture_t *glt; - glpoly2_t *poly; + int nColinElim = 0; if( !mod || !fa->texinfo || !fa->texinfo->texture ) return nColinElim; // bad polygon ? if( FBitSet( fa->flags, SURF_CONVEYOR ) && fa->texinfo->texture->gl_texturenum != 0 ) { - glt = R_GetTexture( fa->texinfo->texture->gl_texturenum ); - tex = fa->texinfo->texture; + gl_texture_t *glt = R_GetTexture( fa->texinfo->texture->gl_texturenum ); + texture_t *tex = fa->texinfo->texture; Assert( glt != NULL && tex != NULL ); // update conveyor widths for keep properly speed of scrolling @@ -413,13 +397,13 @@ static int GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) glt->srcHeight = tex->height; } - sample_size = gEngfuncs.Mod_SampleSizeForFace( fa ); + float sample_size = gEngfuncs.Mod_SampleSizeForFace( fa ); // reconstruct the polygon - lnumverts = fa->numedges; + int lnumverts = fa->numedges; // detach if already created, reconstruct again - poly = fa->polys; + glpoly2_t *poly = fa->polys; fa->polys = NULL; // quake simple models (healthkits etc) need to be reconstructed their polys because LM coords has changed after the map change @@ -429,7 +413,7 @@ static int GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) fa->polys = poly; poly->numverts = lnumverts; - for( i = 0; i < lnumverts; i++ ) + for( int i = 0; i < lnumverts; i++ ) { R_GetEdgePosition( mod, fa, i, poly->verts[i] ); R_TextureCoord( poly->verts[i], fa, &poly->verts[i][3] ); @@ -439,14 +423,13 @@ static int GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) // remove co-linear points - Ed if( !gl_keeptjunctions.value && !FBitSet( fa->flags, SURF_UNDERWATER )) { - for( i = 0; i < lnumverts; i++ ) + for( int i = 0; i < lnumverts; i++ ) { vec3_t v1, v2; - float *prev, *this, *next; - prev = poly->verts[(i + lnumverts - 1) % lnumverts]; - next = poly->verts[(i + 1) % lnumverts]; - this = poly->verts[i]; + float *prev = poly->verts[(i + lnumverts - 1) % lnumverts]; + float *next = poly->verts[(i + 1) % lnumverts]; + float *this = poly->verts[i]; VectorSubtract( this, prev, v1 ); VectorNormalize( v1 ); @@ -456,11 +439,9 @@ static int GL_BuildPolygonFromSurface( model_t *mod, msurface_t *fa ) // skip co-linear points if(( fabs( v1[0] - v2[0] ) <= 0.001f) && (fabs( v1[1] - v2[1] ) <= 0.001f) && (fabs( v1[2] - v2[2] ) <= 0.001f)) { - int j, k; - - for( j = i + 1; j < lnumverts; j++ ) + for( int j = i + 1; j < lnumverts; j++ ) { - for( k = 0; k < VERTEXSIZE; k++ ) + for( int k = 0; k < VERTEXSIZE; k++ ) poly->verts[j-1][k] = poly->verts[j][k]; } @@ -487,7 +468,7 @@ Returns the proper texture for a given time and base texture, do not process ran static texture_t *R_TextureAnim( texture_t *b ) { texture_t *base = b; - int count, reletive; + int reletive; if( RI.currententity->curstate.frame ) { @@ -515,7 +496,7 @@ static texture_t *R_TextureAnim( texture_t *b ) } - count = 0; + int count = 0; while( base->anim_min > reletive || base->anim_max <= reletive ) { @@ -538,7 +519,7 @@ Returns the proper texture for a given time and surface static texture_t *R_TextureAnimation( msurface_t *s ) { texture_t *base = s->texinfo->texture; - int count, reletive; + int reletive; if( RI.currententity && RI.currententity->curstate.frame ) { @@ -568,7 +549,7 @@ static texture_t *R_TextureAnimation( msurface_t *s ) reletive = (int)(gp_cl->time * speed) % base->anim_total; } - count = 0; + int count = 0; while( base->anim_min > reletive || base->anim_max <= reletive ) { @@ -589,19 +570,16 @@ R_AddDynamicLights static void R_AddDynamicLights( const msurface_t *surf ) { const mextrasurf_t *info = surf->info; - int lnum, smax, tmax; int sample_frac = 1.0; - float sample_size; - mtexinfo_t *tex; // no dlighted surfaces here if( !surf->dlightbits ) return; - sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = (info->lightextents[0] / sample_size) + 1; - tmax = (info->lightextents[1] / sample_size) + 1; - tex = surf->texinfo; + float sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); + int smax = (info->lightextents[0] / sample_size) + 1; + int tmax = (info->lightextents[1] / sample_size) + 1; + mtexinfo_t *tex = surf->texinfo; if( FBitSet( tex->flags, TEX_WORLD_LUXELS )) { @@ -612,30 +590,26 @@ static void R_AddDynamicLights( const msurface_t *surf ) else sample_frac = LM_SAMPLE_SIZE; } - for( lnum = 0; lnum < MAX_DLIGHTS; lnum++ ) + for( int lnum = 0; lnum < MAX_DLIGHTS; lnum++ ) { - dlight_t *dl; vec3_t impact, origin_l; - float dist, rad, minlight; - float sl, tl; - int t; if( !FBitSet( surf->dlightbits, BIT( lnum ))) continue; // not lit by this light - dl = &gp_dlights[lnum]; + dlight_t *dl = &gp_dlights[lnum]; // transform light origin to local bmodel space if( !tr.modelviewIdentity ) Matrix4x4_VectorITransform( RI.objectMatrix, dl->origin, origin_l ); else VectorCopy( dl->origin, origin_l ); - rad = dl->radius; - dist = PlaneDiff( origin_l, surf->plane ); + float rad = dl->radius; + float dist = PlaneDiff( origin_l, surf->plane ); rad -= fabs( dist ); // rad is now the highest intensity on the plane - minlight = dl->minlight; + float minlight = dl->minlight; if( rad < minlight ) continue; @@ -648,18 +622,17 @@ static void R_AddDynamicLights( const msurface_t *surf ) } else VectorMA( origin_l, -dist, surf->plane->normal, impact ); - sl = DotProduct( impact, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; - tl = DotProduct( impact, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; + float sl = DotProduct( impact, info->lmvecs[0] ) + info->lmvecs[0][3] - info->lightmapmins[0]; + float tl = DotProduct( impact, info->lmvecs[1] ) + info->lmvecs[1][3] - info->lightmapmins[1]; - for( t = 0; t < tmax; t++ ) + for( int t = 0; t < tmax; t++ ) { int td = (tl - sample_size * t) * sample_frac; - int s; if( td < 0 ) td = -td; - for( s = 0; s < smax; s++ ) + for( int s = 0; s < smax; s++ ) { int sd = (sl - sample_size * s) * sample_frac; float dist; @@ -747,7 +720,6 @@ format in r_blocklights */ static void R_BuildLightMap( const msurface_t *surf, byte *dest, int stride, qboolean dynamic ) { - int map, t; const mextrasurf_t *info = surf->info; int lightscale; @@ -765,18 +737,16 @@ static void R_BuildLightMap( const msurface_t *surf, byte *dest, int stride, qbo memset( r_blocklights, 0, sizeof( uint ) * size * 3 ); // add all the lightmaps - for( map = 0; map < MAXLIGHTMAPS && surf->samples; map++ ) + for( int map = 0; map < MAXLIGHTMAPS && surf->samples; map++ ) { const color24 *lm = &surf->samples[map * size]; - uint scale; - int i; if( surf->styles[map] >= 255 ) break; - scale = g_lightstylevalue[surf->styles[map]]; + uint scale = g_lightstylevalue[surf->styles[map]]; - for( i = 0; i < size; i++ ) + for( int i = 0; i < size; i++ ) { r_blocklights[i * 3 + 0] += lm[i].r * scale; r_blocklights[i * 3 + 1] += lm[i].g * scale; @@ -788,17 +758,14 @@ static void R_BuildLightMap( const msurface_t *surf, byte *dest, int stride, qbo if( surf->dlightframe == tr.framecount && dynamic ) R_AddDynamicLights( surf ); - for( t = 0; t < tmax; t++ ) + for( int t = 0; t < tmax; t++ ) { - int s; - - for( s = 0; s < smax; s++ ) + for( int s = 0; s < smax; s++ ) { const uint *bl = &r_blocklights[(s + (t * smax)) * 3]; byte *dst = &dest[(t * stride) + (s * 4)]; - int i; - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { int t = bl[i] * lightscale >> 14; @@ -827,11 +794,6 @@ R_DrawTriangleOutlines */ static void R_DrawTriangleOutlines( void ) { - int i, j; - msurface_t *surf; - glpoly2_t *p; - float *v; - if( !gl_wireframe.value ) return; @@ -841,16 +803,16 @@ static void R_DrawTriangleOutlines( void ) pglPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); // render static surfaces first - for( i = 0; i < MAX_LIGHTMAPS; i++ ) + for( int i = 0; i < MAX_LIGHTMAPS; i++ ) { - for( surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->info->lightmapchain ) + for( msurface_t *surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->info->lightmapchain ) { - p = surf->polys; + glpoly2_t *p = surf->polys; for( ; p != NULL; p = p->chain ) { pglBegin( GL_POLYGON ); - v = p->verts[0]; - for( j = 0; j < p->numverts; j++, v += VERTEXSIZE ) + float *v = p->verts[0]; + for( int j = 0; j < p->numverts; j++, v += VERTEXSIZE ) pglVertex3fv( v ); pglEnd (); } @@ -858,15 +820,15 @@ static void R_DrawTriangleOutlines( void ) } // render surfaces with dynamic lightmaps - for( surf = gl_lms.dynamic_surfaces; surf != NULL; surf = surf->info->lightmapchain ) + for( msurface_t *surf = gl_lms.dynamic_surfaces; surf != NULL; surf = surf->info->lightmapchain ) { - p = surf->polys; + glpoly2_t *p = surf->polys; for( ; p != NULL; p = p->chain ) { pglBegin( GL_POLYGON ); - v = p->verts[0]; - for( j = 0; j < p->numverts; j++, v += VERTEXSIZE ) + float *v = p->verts[0]; + for( int j = 0; j < p->numverts; j++, v += VERTEXSIZE ) pglVertex3fv( v ); pglEnd (); } @@ -884,9 +846,7 @@ DrawGLPoly */ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale ) { - float *v; float sOffset, tOffset; - int i; if( !p ) return; @@ -898,8 +858,7 @@ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale ) { const cl_entity_t *e = RI.currententity; float flConveyorSpeed; - float flRate, flAngle, sy, cy; - gl_texture_t *texture; + float sy, cy; if( e == CL_GetEntityByIndex( 0 ) && FBitSet( gp_host->features, ENGINE_QUAKE_COMPATIBLE )) { @@ -911,10 +870,10 @@ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale ) flConveyorSpeed = (e->curstate.rendercolor.g<<8|e->curstate.rendercolor.b) / 16.0f; if( e->curstate.rendercolor.r ) flConveyorSpeed = -flConveyorSpeed; } - texture = R_GetTexture( glState.currentTexturesIndex[glState.activeTMU] ); + gl_texture_t *texture = R_GetTexture( glState.currentTexturesIndex[glState.activeTMU] ); - flRate = fabs( flConveyorSpeed ) / (float)texture->srcWidth; - flAngle = ( flConveyorSpeed >= 0 ) ? 180 : 0; + float flRate = fabs( flConveyorSpeed ) / (float)texture->srcWidth; + float flAngle = ( flConveyorSpeed >= 0 ) ? 180 : 0; SinCos( flAngle * ( M_PI_F / 180.0f ), &sy, &cy ); sOffset = gp_cl->time * cy * flRate; @@ -937,7 +896,8 @@ static void DrawGLPoly( glpoly2_t *p, float xScale, float yScale ) pglBegin( GL_POLYGON ); - for( i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE ) + float *v = p->verts[0]; + for( int i = 0; i < p->numverts; i++, v += VERTEXSIZE ) { if( hasScale ) pglTexCoord2f(( v[3] + sOffset ) * xScale, ( v[4] + tOffset ) * yScale ); @@ -961,10 +921,7 @@ Does a water warp on the pre-fragmented glpoly_t chain */ static void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples ) { - float *v, nv, waveHeight; - float s, t, os, ot; - glpoly2_t *p; - int i; + float waveHeight; const qboolean useQuads = FBitSet( warp->flags, SURF_DRAWTURB_QUADS ) && glConfig.context == CONTEXT_TYPE_GL; @@ -981,8 +938,10 @@ static void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples if( useQuads ) pglBegin( GL_QUADS ); - for( p = warp->polys; p; p = p->next ) + for( glpoly2_t *p = warp->polys; p; p = p->next ) { + float *v; + if( reverse ) v = p->verts[0] + ( p->numverts - 1 ) * VERTEXSIZE; else v = p->verts[0]; @@ -990,8 +949,11 @@ static void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples if( !useQuads ) pglBegin( GL_POLYGON ); - for( i = 0; i < p->numverts; i++ ) + for( int i = 0; i < p->numverts; i++ ) { + float nv; + float s, t; + if( waveHeight ) { nv = r_turbsin[(int)(gp_cl->time * 160.0f + v[1] + v[0]) & 255] + 8.0f; @@ -1000,8 +962,8 @@ static void EmitWaterPolys( msurface_t *warp, qboolean reverse, qboolean ripples } else nv = v[2]; - os = v[3]; - ot = v[4]; + float os = v[3]; + float ot = v[4]; if( !ripples ) { @@ -1045,7 +1007,6 @@ Render water lightmaps static void EmitWaterLightPolys( msurface_t *warp, float soffset, float toffset, qboolean dynamic ) { const qboolean useQuads = FBitSet( warp->flags, SURF_DRAWTURB_QUADS ); - glpoly2_t *p; float waveHeight = RI.currententity->curstate.scale; // set the current waveheight @@ -1055,15 +1016,14 @@ static void EmitWaterLightPolys( msurface_t *warp, float soffset, float toffset, if( useQuads ) pglBegin( GL_QUADS ); - for( p = warp->polys; p; p = p->next ) + for( glpoly2_t *p = warp->polys; p; p = p->next ) { float *v = p->verts[0]; - int i; if( !useQuads ) pglBegin( GL_POLYGON ); - for( i = 0; i < p->numverts; i++, v += VERTEXSIZE ) + for( int i = 0; i < p->numverts; i++, v += VERTEXSIZE ) { if( !dynamic ) pglTexCoord2f( v[5], v[6] ); else pglTexCoord2f( v[5] - soffset, v[6] - toffset ); @@ -1106,13 +1066,10 @@ static void DrawGLPolyChain( glpoly2_t *p, float soffset, float toffset, msurfac for( ; p != NULL; p = p->chain ) { - float *v; - int i; - pglBegin( GL_POLYGON ); - v = p->verts[0]; - for( i = 0; i < p->numverts; i++, v += VERTEXSIZE ) + float *v = p->verts[0]; + for( int i = 0; i < p->numverts; i++, v += VERTEXSIZE ) { if( !dynamic ) pglTexCoord2f( v[5], v[6] ); else pglTexCoord2f( v[5] - soffset, v[6] - toffset ); @@ -1155,8 +1112,7 @@ R_BlendLightmaps */ static void R_BlendLightmaps( void ) { - msurface_t *surf, *newsurf = NULL; - int i; + msurface_t *newsurf = NULL; if( !R_HasLightmap() ) return; @@ -1193,13 +1149,13 @@ static void R_BlendLightmaps( void ) pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // render static lightmaps first - for( i = 0; i < MAX_LIGHTMAPS; i++ ) + for( int i = 0; i < MAX_LIGHTMAPS; i++ ) { if( gl_lms.lightmap_surfaces[i] ) { GL_Bind( XASH_TEXTURE0, tr.lightmapTextures[i] ); - for( surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->info->lightmapchain ) + for( msurface_t *surf = gl_lms.lightmap_surfaces[i]; surf != NULL; surf = surf->info->lightmapchain ) { DrawGLPolyChain( surf->polys, 0.0f, 0.0f, surf ); } @@ -1214,16 +1170,14 @@ static void R_BlendLightmaps( void ) GL_Bind( XASH_TEXTURE0, tr.dlightTexture ); newsurf = gl_lms.dynamic_surfaces; - for( surf = gl_lms.dynamic_surfaces; surf != NULL; surf = surf->info->lightmapchain ) + for( msurface_t *surf = gl_lms.dynamic_surfaces; surf != NULL; surf = surf->info->lightmapchain ) { - int smax, tmax; - int sample_size; mextrasurf_t *info = surf->info; byte *base; - sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = ( info->lightextents[0] / sample_size ) + 1; - tmax = ( info->lightextents[1] / sample_size ) + 1; + int sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); + int smax = ( info->lightextents[0] / sample_size ) + 1; + int tmax = ( info->lightextents[1] / sample_size ) + 1; if( LM_AllocBlock( smax, tmax, &surf->info->dlight_s, &surf->info->dlight_t )) { @@ -1234,12 +1188,11 @@ static void R_BlendLightmaps( void ) } else { - msurface_t *drawsurf; - // upload what we have so far LM_UploadBlock( true ); // draw all surfaces that use this lightmap + msurface_t *drawsurf; for( drawsurf = newsurf; drawsurf != surf; drawsurf = drawsurf->info->lightmapchain ) { DrawGLPolyChain( drawsurf->polys, @@ -1267,7 +1220,7 @@ static void R_BlendLightmaps( void ) // draw remainder of dynamic lightmaps that haven't been uploaded yet if( newsurf ) LM_UploadBlock( true ); - for( surf = newsurf; surf != NULL; surf = surf->info->lightmapchain ) + for( msurface_t *surf = newsurf; surf != NULL; surf = surf->info->lightmapchain ) { DrawGLPolyChain( surf->polys, ( surf->light_s - surf->info->dlight_s ) * ( 1.0f / (float)BLOCK_SIZE ), @@ -1293,9 +1246,6 @@ R_RenderFullbrights */ static void R_RenderFullbrights( qboolean allow_vbo ) { - mextrasurf_t *es, *p; - int i; - if( !R_SeparatePassActive( &draw_fullbrights )) return; @@ -1311,15 +1261,15 @@ static void R_RenderFullbrights( qboolean allow_vbo ) if( allow_vbo && gl_polyoffset.value ) GL_PushPolygonOffset( -1.0f, -gl_polyoffset.value ); - for( i = draw_fullbrights.first; i <= draw_fullbrights.last; i++ ) + for( int i = draw_fullbrights.first; i <= draw_fullbrights.last; i++ ) { - es = fullbright_surfaces[i]; + mextrasurf_t *es = fullbright_surfaces[i]; if( !es ) continue; GL_Bind( XASH_TEXTURE0, i ); - for( p = es; p; p = p->lumachain ) + for( mextrasurf_t *p = es; p; p = p->lumachain ) DrawGLPoly( p->surf->polys, 0.0f, 0.0f ); fullbright_surfaces[i] = NULL; @@ -1345,11 +1295,6 @@ R_RenderDetails */ static void R_RenderDetails( int passes ) { - gl_texture_t *glt; - mextrasurf_t *es, *p; - msurface_t *fa; - int i; - if( !R_SeparatePassActive( &draw_details )) return; @@ -1367,18 +1312,18 @@ static void R_RenderDetails( int passes ) pglEnable( GL_POLYGON_OFFSET_FILL ); } - for( i = draw_details.first; i <= draw_details.last; i++ ) + for( int i = draw_details.first; i <= draw_details.last; i++ ) { - es = detail_surfaces[i]; + mextrasurf_t *es = detail_surfaces[i]; if( !es ) continue; GL_Bind( XASH_TEXTURE0, i ); - for( p = es; p; p = p->detailchain ) + for( mextrasurf_t *p = es; p; p = p->detailchain ) { - fa = p->surf; - glt = R_GetTexture( fa->texinfo->texture->gl_texturenum ); // get texture scale + msurface_t *fa = p->surf; + gl_texture_t *glt = R_GetTexture( fa->texinfo->texture->gl_texturenum ); // get texture scale DrawGLPoly( fa->polys, glt->xscale, glt->yscale ); } @@ -1529,14 +1474,12 @@ R_RenderBrushPoly */ static void R_RenderBrushPoly( msurface_t *fa, int cull_type ) { - texture_t *t; - r_stats.c_world_polys++; if( fa->flags & SURF_DRAWSKY ) return; // already handled - t = R_TextureAnimation( fa ); + texture_t *t = R_TextureAnimation( fa ); if( FBitSet( fa->flags, SURF_DRAWTURB )) { @@ -1565,10 +1508,6 @@ R_DrawTextureChains */ static void R_DrawTextureChains( void ) { - int i; - msurface_t *s; - texture_t *t; - // make sure what color is reset pglColor4ub( 255, 255, 255, 255 ); R_LoadIdentity(); // set identity matrix @@ -1586,7 +1525,7 @@ static void R_DrawTextureChains( void ) } // clip skybox surfaces - for( s = skychain; s != NULL; s = s->texturechain ) + for( msurface_t *s = skychain; s != NULL; s = s->texturechain ) R_AddSkyBoxSurface( s ); if( FBitSet( tr.world->flags, FWORLD_SKYSPHERE ) && !FBitSet( tr.world->flags, FWORLD_CUSTOM_SKYBOX )) @@ -1599,12 +1538,12 @@ static void R_DrawTextureChains( void ) R_DrawVBO( !r_fullbright->value && !!WORLDMODEL->lightdata, true ); - for( i = 0; i < WORLDMODEL->numtextures; i++ ) + for( int i = 0; i < WORLDMODEL->numtextures; i++ ) { - t = WORLDMODEL->textures[i]; + texture_t *t = WORLDMODEL->textures[i]; if( !t ) continue; - s = t->texturechain; + msurface_t *s = t->texturechain; if( !s || ( i == tr.skytexturenum )) continue; @@ -1634,10 +1573,6 @@ R_DrawAlphaTextureChains */ void R_DrawAlphaTextureChains( void ) { - int i; - msurface_t *s; - texture_t *t; - if( !R_SeparatePassActive( &draw_alpha_surfaces )) return; @@ -1659,13 +1594,13 @@ void R_DrawAlphaTextureChains( void ) RI.currentmodel = RI.currententity->model; RI.currententity->curstate.rendermode = kRenderTransAlpha; - for( i = draw_alpha_surfaces.first; i <= draw_alpha_surfaces.last; i++ ) + for( int i = draw_alpha_surfaces.first; i <= draw_alpha_surfaces.last; i++ ) { - t = WORLDMODEL->textures[i]; + texture_t *t = WORLDMODEL->textures[i]; if( !t ) continue; - s = t->texturechain; + msurface_t *s = t->texturechain; if( !s || !FBitSet( s->flags, SURF_TRANSPARENT )) continue; @@ -1690,10 +1625,6 @@ R_DrawWaterSurfaces */ void R_DrawWaterSurfaces( void ) { - int i; - msurface_t *s; - texture_t *t; - if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) || FBitSet( RI.rvp.flags, RF_ONLY_CLIENTDRAW )) return; @@ -1715,12 +1646,12 @@ void R_DrawWaterSurfaces( void ) pglTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); pglColor4f( 1.0f, 1.0f, 1.0f, gp_movevars->wateralpha ); - for( i = draw_wateralpha.first; i <= draw_wateralpha.last; i++ ) + for( int i = draw_wateralpha.first; i <= draw_wateralpha.last; i++ ) { - t = WORLDMODEL->textures[i]; + texture_t *t = WORLDMODEL->textures[i]; if( !t ) continue; - s = t->texturechain; + msurface_t *s = t->texturechain; if( !s ) continue; if( !FBitSet( s->flags, SURF_DRAWTURB )) @@ -1759,19 +1690,17 @@ compare translucent surfaces */ static int R_SurfaceCompare( const void *a, const void *b ) { - msurface_t *surf1, *surf2; vec3_t org1, org2; - float len1, len2; - surf1 = (msurface_t *)((sortedface_t *)a)->surf; - surf2 = (msurface_t *)((sortedface_t *)b)->surf; + msurface_t *surf1 = (msurface_t *)((sortedface_t *)a)->surf; + msurface_t *surf2 = (msurface_t *)((sortedface_t *)b)->surf; VectorAdd( RI.currententity->origin, surf1->info->origin, org1 ); VectorAdd( RI.currententity->origin, surf2->info->origin, org2 ); // compare by plane dists - len1 = DotProduct( org1, RI.vforward ) - RI.viewplanedist; - len2 = DotProduct( org2, RI.vforward ) - RI.viewplanedist; + float len1 = DotProduct( org1, RI.vforward ) - RI.viewplanedist; + float len2 = DotProduct( org2, RI.vforward ) - RI.viewplanedist; if( len1 > len2 ) return -1; @@ -1888,7 +1817,6 @@ R_DrawBrushModel */ void R_DrawBrushModel( cl_entity_t *e ) { - int old_rendermode; vec3_t mins, maxs; qboolean rotated; qboolean allow_vbo = R_HasEnabledVBO(); @@ -1922,7 +1850,7 @@ void R_DrawBrushModel( cl_entity_t *e ) return; memset( gl_lms.lightmap_surfaces, 0, sizeof( gl_lms.lightmap_surfaces )); - old_rendermode = e->curstate.rendermode; + int old_rendermode = e->curstate.rendermode; gl_lms.dynamic_surfaces = NULL; if( rotated ) @@ -2198,23 +2126,18 @@ Allocate memory for arrays, fill it with vertex attribs and upload to GPU void R_GenerateVBO( void ) { model_t *world = WORLDMODEL; - msurface_t *surfaces; - int numsurfaces; - int numtextures; const int numlightmaps = gl_lms.current_lightmap_texture; - int k, len = 0; - vboarray_t *vbo; + int len = 0; uint maxindex = 0; - double t1, t2, t3; if( R_HasGeneratedVBO() || !world || !world->surfaces ) return; - t1 = gEngfuncs.pfnTime(); + double t1 = gEngfuncs.pfnTime(); - surfaces = world->surfaces; - numsurfaces = world->numsurfaces; - numtextures = world->numtextures; + msurface_t *surfaces = world->surfaces; + int numsurfaces = world->numsurfaces; + int numtextures = world->numtextures; vbos.mempool = Mem_AllocPool("Render VBO Zone"); @@ -2229,21 +2152,19 @@ void R_GenerateVBO( void ) vbos.textures = Mem_Calloc( vbos.mempool, numtextures * numlightmaps * sizeof( vbotexture_t ) ); vbos.surfdata = Mem_Calloc( vbos.mempool, WORLDMODEL->numsurfaces * sizeof( vbosurfdata_t ) ); + vboarray_t *vbo; vbos.arraylist = vbo = Mem_Calloc( vbos.mempool, sizeof( vboarray_t ) ); vbos.decaldata = Mem_Calloc( vbos.mempool, sizeof( vbodecaldata_t ) ); vbos.decaldata->lm = Mem_Calloc( vbos.mempool, sizeof( msurface_t* ) * numlightmaps ); // count array lengths - for( k = 0; k < numlightmaps; k++ ) + for( int k = 0; k < numlightmaps; k++ ) { - int j; - - for( j = 0; j < numtextures; j++ ) + for( int j = 0; j < numtextures; j++ ) { - int i; vbotexture_t *vbotex = &vbos.textures[k * numtextures + j]; - for( i = 0; i < numsurfaces; i++ ) + for( int i = 0; i < numsurfaces; i++ ) { msurface_t *surf = &surfaces[i]; @@ -2290,20 +2211,17 @@ void R_GenerateVBO( void ) // allocate last array vbo->array = Mem_Calloc( vbos.mempool, sizeof( vbovertex_t ) * vbo->array_len ); - t2 = gEngfuncs.pfnTime(); + double t2 = gEngfuncs.pfnTime(); gEngfuncs.Con_Printf( S_NOTE "%s: allocated array of %d verts in %.3g seconds\n", __func__, vbo->array_len, t2 - t1 ); // switch to list begin vbo = vbos.arraylist; // fill and upload - for( k = 0; k < numlightmaps; k++ ) + for( int k = 0; k < numlightmaps; k++ ) { - int j; - - for( j = 0; j < numtextures; j++ ) + for( int j = 0; j < numtextures; j++ ) { - int i; vbotexture_t *vbotex = &vbos.textures[k * numtextures + j]; // preallocate index arrays @@ -2313,10 +2231,9 @@ void R_GenerateVBO( void ) if( maxindex < vbotex->len ) maxindex = vbotex->len; - for( i = 0; i < numsurfaces; i++ ) + for( int i = 0; i < numsurfaces; i++ ) { msurface_t *surf = &surfaces[i]; - int l; if( surf->lightmaptexturenum != k ) continue; @@ -2350,7 +2267,7 @@ void R_GenerateVBO( void ) } // fill vbovertex_t - for( l = 0; l < surf->polys->numverts; l++ ) + for( int l = 0; l < surf->polys->numverts; l++ ) { float *v = surf->polys->verts[l]; @@ -2407,7 +2324,7 @@ void R_GenerateVBO( void ) pglBindBufferARB( GL_ARRAY_BUFFER_ARB, 0 ); mtst.tmu_gl = XASH_TEXTURE0; - t3 = gEngfuncs.pfnTime(); + double t3 = gEngfuncs.pfnTime(); gEngfuncs.Con_Reportf( S_NOTE "%s: uploaded VBOs in %.3g seconds, %.3g seconds total\n", __func__, t3 - t2, t3 - t1 ); } @@ -2421,14 +2338,13 @@ generate decal mesh and put it to array */ void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf ) { - int numVerts, i; - float *v; + int numVerts; int decalindex = pdecal - &gDecalPool[0]; if( !vbos.decaldata ) return; - v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &numVerts ); + float *v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &numVerts ); if( numVerts > DECAL_VERTS_CUT ) { @@ -2437,7 +2353,7 @@ void R_AddDecalVBO( decal_t *pdecal, msurface_t *surf ) return; } - for( i = 0; i < numVerts; i++ ) + for( int i = 0; i < numVerts; i++ ) memcpy( &vbos.decaldata->decalarray[decalindex * DECAL_VERTS_CUT + i], v + i * VERTEXSIZE, VERTEXSIZE * 4 ); pglBindBufferARB( GL_ARRAY_BUFFER_ARB, vbos.decaldata->decalvbo ); @@ -2456,9 +2372,7 @@ free all vbo data */ void R_ClearVBO( void ) { - vboarray_t *vbo; - - for( vbo = vbos.arraylist; vbo; vbo = vbo->next ) + for( vboarray_t *vbo = vbos.arraylist; vbo; vbo = vbo->next ) pglDeleteBuffersARB( 1, &vbo->glindex ); vbos.arraylist = NULL; @@ -2816,8 +2730,6 @@ static void R_AdditionalPasses( vboarray_t *vbo, int indexlen, void *indexarray, static void R_DrawDlightedDecals( vboarray_t *vbo, msurface_t *newsurf, msurface_t *surf, int decalcount, texture_t *texture ) { - msurface_t *decalsurf; - decal_t *pdecal; int decali = 0; pglDepthMask( GL_FALSE ); @@ -2828,16 +2740,14 @@ static void R_DrawDlightedDecals( vboarray_t *vbo, msurface_t *newsurf, msurface R_SetupVBOArrayDecalDlight( decalcount ); - for( decalsurf = newsurf; ( decali < decalcount ) && (!surf ||( decalsurf != surf )); decalsurf = decalsurf->info->lightmapchain ) + for( msurface_t *decalsurf = newsurf; ( decali < decalcount ) && (!surf ||( decalsurf != surf )); decalsurf = decalsurf->info->lightmapchain ) { - for( pdecal = decalsurf->pdecals; pdecal; pdecal = pdecal->pnext ) + for( decal_t *pdecal = decalsurf->pdecals; pdecal; pdecal = pdecal->pnext ) { - gl_texture_t *glt; - if( !pdecal->texture ) continue; - glt = R_GetTexture( pdecal->texture ); + gl_texture_t *glt = R_GetTexture( pdecal->texture ); GL_Bind( mtst.tmu_gl, pdecal->texture ); @@ -2918,7 +2828,6 @@ static void R_FlushDlights( vboarray_t *vbo, int min_index, int max_index, int d static void R_AddSurfaceDecalsDlight( msurface_t *surf, int *pdecalcount ) { - decal_t *pdecal; int decalcount = *pdecalcount; #if SPARSE_DECALS_UPLOAD if( decalcount == 0 ) @@ -2927,18 +2836,17 @@ static void R_AddSurfaceDecalsDlight( msurface_t *surf, int *pdecalcount ) pglBufferDataARB( GL_ARRAY_BUFFER_ARB, sizeof( vbos.decal_dlight ), NULL, GL_STREAM_DRAW_ARB ); } #endif - for( pdecal = surf->pdecals; pdecal; pdecal = pdecal->pnext ) + for( decal_t *pdecal = surf->pdecals; pdecal; pdecal = pdecal->pnext ) { int decalindex = pdecal - &gDecalPool[0]; int numVerts = vbos.decaldata->decals[decalindex].numVerts; - int i; if( numVerts == -1 ) { // build decal array float *v = R_DecalSetupVerts( pdecal, surf, pdecal->texture, &numVerts ); - for( i = 0; i < numVerts; i++, v += VERTEXSIZE ) + for( int i = 0; i < numVerts; i++, v += VERTEXSIZE ) { VectorCopy( v, vbos.decal_dlight[decalcount * DECAL_VERTS_MAX + i].pos ); vbos.decal_dlight[decalcount * DECAL_VERTS_MAX + i].gl_tc[0] = v[3]; @@ -2950,7 +2858,7 @@ static void R_AddSurfaceDecalsDlight( msurface_t *surf, int *pdecalcount ) else { // copy from vbo - for( i = 0; i < numVerts; i++ ) + for( int i = 0; i < numVerts; i++ ) { VectorCopy( vbos.decaldata->decalarray[decalindex * DECAL_VERTS_CUT + i].pos, vbos.decal_dlight[decalcount * DECAL_VERTS_MAX + i].pos ); vbos.decal_dlight[decalcount * DECAL_VERTS_MAX + i].gl_tc[0] = vbos.decaldata->decalarray[decalindex * DECAL_VERTS_CUT + i].gl_tc[0]; @@ -2981,7 +2889,6 @@ static void R_DrawVBODlights( vboarray_t *vbo, vbotexture_t *vbotex, texture_t * { vboindex_t *dlightarray = vbos.dlight_index; // preallocated array unsigned int dlightindex = 0; - msurface_t *surf, *newsurf; int decalcount = 0; int min_index = 65536; int max_index = 0; @@ -2992,6 +2899,8 @@ static void R_DrawVBODlights( vboarray_t *vbo, vbotexture_t *vbotex, texture_t * LM_InitBlock(); + msurface_t *surf, *newsurf; + if( vbos.dlight_vbo ) { // calculate minimum indexbase @@ -3019,17 +2928,13 @@ static void R_DrawVBODlights( vboarray_t *vbo, vbotexture_t *vbotex, texture_t * // accumulate indexes for every dlighted surface until dlight block full for( surf = newsurf = vbotex->dlightchain; surf; surf = surf->info->lightmapchain ) { - int smax, tmax; byte *base; uint indexbase = vbos.surfdata[((char*)surf - (char*)WORLDMODEL->surfaces) / sizeof( *surf )].startindex; - uint index; - mextrasurf_t *info; // this stores current dlight offset - int sample_size; - info = surf->info; - sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = ( info->lightextents[0] / sample_size ) + 1; - tmax = ( info->lightextents[1] / sample_size ) + 1; + mextrasurf_t *info = surf->info; // this stores current dlight offset + int sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); + int smax = ( info->lightextents[0] / sample_size ) + 1; + int tmax = ( info->lightextents[1] / sample_size ) + 1; // find space for this surface and get offsets @@ -3087,7 +2992,7 @@ static void R_DrawVBODlights( vboarray_t *vbo, vbotexture_t *vbotex, texture_t * vbos.dlight_tc[indexbase + 1][0] = surf->polys->verts[1][5] - ( surf->light_s - info->dlight_s ) * ( 1.0f / (float)BLOCK_SIZE ); vbos.dlight_tc[indexbase + 1][1] = surf->polys->verts[1][6] - ( surf->light_t - info->dlight_t ) * ( 1.0f / (float)BLOCK_SIZE ); - for( index = indexbase + 2; index < indexbase + surf->polys->numverts; index++ ) + for( uint index = indexbase + 2; index < indexbase + surf->polys->numverts; index++ ) { dlightarray[dlightindex++] = indexbase - min_index; dlightarray[dlightindex++] = index - 1 - min_index; @@ -3237,7 +3142,6 @@ static void R_SetupVBOArrayDecalDyn( qboolean drawlightmap, float *v ) static void R_DrawStaticDecals( vboarray_t *vbo, qboolean drawlightmap, int ilightmap ) { int k = ilightmap; - msurface_t *lightmapchain; pglDepthMask( GL_FALSE ); pglEnable( GL_BLEND ); @@ -3248,20 +3152,17 @@ static void R_DrawStaticDecals( vboarray_t *vbo, qboolean drawlightmap, int ilig R_SetupVBOArrayDecal( drawlightmap ); // all surfaces having decals and this lightmap - for( lightmapchain = vbos.decaldata->lm[k]; lightmapchain; lightmapchain = lightmapchain->info->lightmapchain ) + for( msurface_t *lightmapchain = vbos.decaldata->lm[k]; lightmapchain; lightmapchain = lightmapchain->info->lightmapchain ) { - decal_t *pdecal; - // all decals of surface - for( pdecal = lightmapchain->pdecals; pdecal; pdecal = pdecal->pnext ) + for( decal_t *pdecal = lightmapchain->pdecals; pdecal; pdecal = pdecal->pnext ) { - gl_texture_t *glt; int decalindex = pdecal - &gDecalPool[0]; if( !pdecal->texture ) continue; - glt = R_GetTexture( pdecal->texture ); + gl_texture_t *glt = R_GetTexture( pdecal->texture ); GL_Bind( mtst.tmu_gl, pdecal->texture ); @@ -3286,9 +3187,7 @@ static void R_DrawStaticDecals( vboarray_t *vbo, qboolean drawlightmap, int ilig if( vbos.decaldata->decals[decalindex].numVerts == -1 ) { int numVerts; - float *v; - - v = R_DecalSetupVerts( pdecal, lightmapchain, pdecal->texture, &numVerts ); + float *v = R_DecalSetupVerts( pdecal, lightmapchain, pdecal->texture, &numVerts ); // to many verts to keep in sparse array, so build it now R_SetupVBOArrayDecalDyn( drawlightmap, v ); @@ -3359,7 +3258,6 @@ void R_DrawVBO( qboolean drawlightmap, qboolean drawtextures ) { int numtextures = WORLDMODEL->numtextures; int numlightmaps = gl_lms.current_lightmap_texture; - int k; vboarray_t *vbo = vbos.arraylist; if( !R_HasGeneratedVBO() || !R_HasEnabledVBO() ) @@ -3385,16 +3283,14 @@ void R_DrawVBO( qboolean drawlightmap, qboolean drawtextures ) if( vbos.maxtexture > numtextures ) vbos.maxtexture = numtextures; - for( k = vbos.minlightmap; k < vbos.maxlightmap; k++ ) + for( int k = vbos.minlightmap; k < vbos.maxlightmap; k++ ) { - int j; - if( drawlightmap ) { GL_Bind( mtst.tmu_lm, mtst.lm = tr.lightmapTextures[k] ); } - for( j = vbos.mintexture; j < vbos.maxtexture; j++ ) + for( int j = vbos.mintexture; j < vbos.maxtexture; j++ ) { vbotexture_t *vbotex = &vbos.textures[k * numtextures + j]; texture_t *tex = NULL; @@ -3474,15 +3370,13 @@ void R_DrawVBO( qboolean drawlightmap, qboolean drawtextures ) qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap ) { const int idx = surf - WORLDMODEL->surfaces; - vbotexture_t *vbotex; - int texturenum; if( !R_HasGeneratedVBO() || !R_HasEnabledVBO( )) return false; // find vbotexture_t assotiated with this surface - vbotex = vbos.surfdata[idx].vbotexture; - texturenum = vbos.surfdata[idx].texturenum; + vbotexture_t *vbotex = vbos.surfdata[idx].vbotexture; + int texturenum = vbos.surfdata[idx].texturenum; if( !vbotex ) return false; @@ -3520,10 +3414,9 @@ qboolean R_AddSurfToVBO( msurface_t *surf, qboolean buildlightmap ) else { uint indexbase = vbos.surfdata[idx].startindex; - uint index; // GL_TRIANGLE_FAN: 0 1 2 0 2 3 0 3 4 ... - for( index = indexbase + 2; index < indexbase + surf->polys->numverts; index++ ) + for( uint index = indexbase + 2; index < indexbase + surf->polys->numverts; index++ ) { vbotex->indexarray[vbotex->curindex++] = indexbase; vbotex->indexarray[vbotex->curindex++] = index - 1; @@ -3665,12 +3558,12 @@ R_DrawTopViewLeaf */ static void R_DrawTopViewLeaf( mleaf_t *pleaf, uint clipflags ) { - msurface_t **mark, *surf; + msurface_t **mark; int i; for( i = 0, mark = pleaf->firstmarksurface; i < pleaf->nummarksurfaces; i++, mark++ ) { - surf = *mark; + msurface_t *surf = *mark; // don't process the same surface twice if( surf->visframe == tr.framecount ) @@ -3702,13 +3595,11 @@ R_DrawWorldTopView */ static void R_DrawWorldTopView( mnode_t *node, uint clipflags ) { - int i, c, clipped; msurface_t *surf; + int c; do { - int numsurfaces, firstsurface; - if( node->contents == CONTENTS_SOLID ) return; // hit a solid leaf @@ -3717,14 +3608,14 @@ static void R_DrawWorldTopView( mnode_t *node, uint clipflags ) if( clipflags && !r_nocull.value ) { - for( i = 0; i < 6; i++ ) + for( int i = 0; i < 6; i++ ) { const mplane_t *p = &RI.frustum.planes[i]; if( !FBitSet( clipflags, BIT( i ))) continue; - clipped = BOX_ON_PLANE_SIDE( node->minmaxs, node->minmaxs + 3, p ); + int clipped = BOX_ON_PLANE_SIDE( node->minmaxs, node->minmaxs + 3, p ); if( clipped == 2 ) return; if( clipped == 1 ) ClearBits( clipflags, BIT( i )); } @@ -3742,8 +3633,8 @@ static void R_DrawWorldTopView( mnode_t *node, uint clipflags ) } // draw stuff - numsurfaces = node_numsurfaces( node, WORLDMODEL ); - firstsurface = node_firstsurface( node, WORLDMODEL ); + int numsurfaces = node_numsurfaces( node, WORLDMODEL ); + int firstsurface = node_firstsurface( node, WORLDMODEL ); for( c = numsurfaces, surf = WORLDMODEL->surfaces + firstsurface; c; c--, surf++ ) { @@ -3776,8 +3667,6 @@ R_DrawWorld */ void R_DrawWorld( void ) { - double start, end; - // paranoia issues: when gl_renderer is "0" we need have something valid for currententity // to prevent crashing until HeadShield drawing. RI.currententity = CL_GetEntityByIndex( 0 ); @@ -3800,11 +3689,11 @@ void R_DrawWorld( void ) R_ClearSkyBox (); - start = gEngfuncs.pfnTime(); + double start = gEngfuncs.pfnTime(); if( FBitSet( RI.rvp.flags, RF_DRAW_OVERVIEW )) R_DrawWorldTopView( WORLDMODEL->nodes, RI.frustum.clipFlags ); else R_RecursiveWorldNode( WORLDMODEL->nodes, RI.frustum.clipFlags ); - end = gEngfuncs.pfnTime(); + double end = gEngfuncs.pfnTime(); r_stats.t_world_node = end - start; @@ -3846,9 +3735,7 @@ void R_MarkLeaves( void ) qboolean novis = false; qboolean force = false; mleaf_t *leaf = NULL; - mnode_t *node; vec3_t test; - int i; if( !FBitSet( RI.rvp.flags, RF_DRAW_WORLD )) return; @@ -3894,11 +3781,11 @@ void R_MarkLeaves( void ) if( force && !novis ) gEngfuncs.R_FatPVS( test, r_pvs_radius->value, RI.visbytes, true, novis ); - for( i = 0; i < WORLDMODEL->numleafs; i++ ) + for( int i = 0; i < WORLDMODEL->numleafs; i++ ) { if( CHECKVISBIT( RI.visbytes, i )) { - node = (mnode_t *)&WORLDMODEL->leafs[i+1]; + mnode_t *node = (mnode_t *)&WORLDMODEL->leafs[i+1]; do { if( node->visframe == tr.visframecount ) @@ -3917,10 +3804,7 @@ GL_CreateSurfaceLightmap */ static void GL_CreateSurfaceLightmap( msurface_t *surf, model_t *loadmodel ) { - int smax, tmax; - int sample_size; mextrasurf_t *info = surf->info; - byte *base; if( !loadmodel->lightdata ) return; @@ -3928,9 +3812,9 @@ static void GL_CreateSurfaceLightmap( msurface_t *surf, model_t *loadmodel ) if( FBitSet( surf->flags, SURF_DRAWTILED )) return; - sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); - smax = ( info->lightextents[0] / sample_size ) + 1; - tmax = ( info->lightextents[1] / sample_size ) + 1; + int sample_size = gEngfuncs.Mod_SampleSizeForFace( surf ); + int smax = ( info->lightextents[0] / sample_size ) + 1; + int tmax = ( info->lightextents[1] / sample_size ) + 1; if( !LM_AllocBlock( smax, tmax, &surf->light_s, &surf->light_t )) { @@ -3943,7 +3827,7 @@ static void GL_CreateSurfaceLightmap( msurface_t *surf, model_t *loadmodel ) surf->lightmaptexturenum = gl_lms.current_lightmap_texture; - base = gl_lms.lightmap_buffer; + byte *base = gl_lms.lightmap_buffer; base += ( surf->light_t * BLOCK_SIZE + surf->light_s ) * 4; R_UpdateSurfaceCachedLight( surf ); @@ -3960,14 +3844,11 @@ when gamma is changed */ void GL_RebuildLightmaps( void ) { - int i, j; - model_t *m; - if( !ENGINE_GET_PARM( PARM_CLIENT_ACTIVE ) ) return; // wait for worldmodel // release old lightmaps - for( i = 0; i < MAX_LIGHTMAPS; i++ ) + for( int i = 0; i < MAX_LIGHTMAPS; i++ ) { if( !tr.lightmapTextures[i] ) break; GL_FreeTexture( tr.lightmapTextures[i] ); @@ -3981,15 +3862,16 @@ void GL_RebuildLightmaps( void ) LM_InitBlock(); - for( i = 0; i < gp_cl->nummodels; i++ ) + for( int i = 0; i < gp_cl->nummodels; i++ ) { - if(( m = CL_ModelHandle( i + 1 )) == NULL ) + model_t *m = CL_ModelHandle( i + 1 ); + if( m == NULL ) continue; if( m->name[0] == '*' || m->type != mod_brush ) continue; - for( j = 0; j < m->numsurfaces; j++ ) + for( int j = 0; j < m->numsurfaces; j++ ) GL_CreateSurfaceLightmap( m->surfaces + j, m ); } LM_UploadBlock( false ); @@ -4011,11 +3893,10 @@ with all the surfaces from all brush models */ void GL_BuildLightmaps( void ) { - int i, j, nColinElim = 0; - model_t *m; + int nColinElim = 0; // release old lightmaps - for( i = 0; i < MAX_LIGHTMAPS; i++ ) + for( int i = 0; i < MAX_LIGHTMAPS; i++ ) { if( !tr.lightmapTextures[i] ) break; GL_FreeTexture( tr.lightmapTextures[i] ); @@ -4044,15 +3925,16 @@ void GL_BuildLightmaps( void ) LM_InitBlock(); - for( i = 0; i < gp_cl->nummodels; i++ ) + for( int i = 0; i < gp_cl->nummodels; i++ ) { - if(( m = CL_ModelHandle( i + 1 )) == NULL ) + model_t *m = CL_ModelHandle( i + 1 ); + if( m == NULL ) continue; if( m->name[0] == '*' || m->type != mod_brush ) continue; - for( j = 0; j < m->numsurfaces; j++ ) + for( int j = 0; j < m->numsurfaces; j++ ) { // clearing all decal chains m->surfaces[j].pdecals = NULL; @@ -4070,9 +3952,9 @@ void GL_BuildLightmaps( void ) } // clearing visframe - for( j = 0; j < m->numleafs; j++ ) + for( int j = 0; j < m->numleafs; j++ ) m->leafs[j+1].visframe = 0; - for( j = 0; j < m->numnodes; j++ ) + for( int j = 0; j < m->numnodes; j++ ) m->nodes[j].visframe = 0; } diff --git a/ref/gl/gl_sprite.c b/ref/gl/gl_sprite.c index 03f794bf..23e041e9 100644 --- a/ref/gl/gl_sprite.c +++ b/ref/gl/gl_sprite.c @@ -31,19 +31,12 @@ between frames where are we lerping */ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **oldframe, mspriteframe_t **curframe ) { - msprite_t *psprite; - mspritegroup_t *pspritegroup; - int i, j, numframes, frame; - float lerpFrac, time, jtime, jinterval; - float *pintervals, fullinterval, targettime; - int m_fDoInterp; - - psprite = ent->model->cache.data; - frame = (int)ent->curstate.frame; - lerpFrac = 1.0f; + msprite_t *psprite = ent->model->cache.data; + int frame = (int)ent->curstate.frame; + float lerpFrac = 1.0f; // misc info - m_fDoInterp = (ent->curstate.effects & EF_NOINTERP) ? false : true; + int m_fDoInterp = (ent->curstate.effects & EF_NOINTERP) ? false : true; if( frame < 0 ) { @@ -106,20 +99,21 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old } else if( psprite->frames[frame].type == FRAME_GROUP ) { - pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; - pintervals = pspritegroup->intervals; - numframes = pspritegroup->numframes; - fullinterval = pintervals[numframes-1]; - jinterval = pintervals[1] - pintervals[0]; - time = gp_cl->time; - jtime = 0.0f; + mspritegroup_t *pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; + float *pintervals = pspritegroup->intervals; + int numframes = pspritegroup->numframes; + float fullinterval = pintervals[numframes-1]; + float jinterval = pintervals[1] - pintervals[0]; + float time = gp_cl->time; + float jtime = 0.0f; // when loading in Mod_LoadSpriteGroup, we guaranteed all interval values // are positive, so we don't have to worry about division by zero - targettime = time - ((int)(time / fullinterval)) * fullinterval; + float targettime = time - ((int)(time / fullinterval)) * fullinterval; // LordHavoc: since I can't measure the time properly when it loops from numframes - 1 to 0, // i instead measure the time of the first frame, hoping it is consistent + int i, j; for( i = 0, j = numframes - 1; i < (numframes - 1); i++ ) { if( pintervals[i] > targettime ) @@ -178,7 +172,7 @@ static float R_GetSpriteFrameInterpolant( cl_entity_t *ent, mspriteframe_t **old lerpFrac = 1.0f; } - pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr; + mspritegroup_t *pspritegroup = (mspritegroup_t *)psprite->frames[ent->latched.prevblending[0]].frameptr; if( oldframe ) *oldframe = pspritegroup->frames[angleframe]; pspritegroup = (mspritegroup_t *)psprite->frames[frame].frameptr; @@ -225,16 +219,13 @@ Set sprite brightness factor */ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, float *pscale ) { - float dist, brightness; - vec3_t glowDist; - pmtrace_t *tr; - + vec3_t glowDist; VectorSubtract( origin, RI.rvp.vieworigin, glowDist ); - dist = VectorLength( glowDist ); + float dist = VectorLength( glowDist ); if( !FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP )) { - tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE)); + pmtrace_t *tr = gEngfuncs.EV_VisTraceLine( RI.rvp.vieworigin, origin, r_traceglow.value ? PM_GLASS_IGNORE : (PM_GLASS_IGNORE|PM_STUDIO_IGNORE)); if(( 1.0f - tr->fraction ) * dist > 8.0f ) return 0.0f; @@ -243,7 +234,7 @@ static float R_SpriteGlowBlend( vec3_t origin, int rendermode, int renderfx, flo if( renderfx == kRenderFxNoDissipation ) return 1.0f; - brightness = GLARE_FALLOFF / ( dist * dist ); + float brightness = GLARE_FALLOFF / ( dist * dist ); brightness = bound( 0.05f, brightness, 1.0f ); *pscale *= dist * ( 1.0f / 200.0f ); @@ -373,28 +364,19 @@ R_DrawSpriteModel */ void R_DrawSpriteModel( cl_entity_t *e ) { - mspriteframe_t *frame = NULL, *oldframe = NULL; - msprite_t *psprite; - model_t *model; - int i, type; - float angle, dot, sr, cr; - float lerp = 1.0f, ilerp, scale; - vec3_t v_forward, v_right, v_up; - vec3_t origin, color, color2 = { 0.0f }; - if( FBitSet( RI.rvp.flags, RF_DRAW_CUBEMAP )) return; - model = e->model; - psprite = (msprite_t * )model->cache.data; + model_t *model = e->model; + msprite_t *psprite = (msprite_t *)model->cache.data; + vec3_t origin, color, color2 = { 0.0f }; + vec3_t v_right, v_up; VectorCopy( e->origin, origin ); // set render origin // do movewith if( e->curstate.aiment > 0 && e->curstate.movetype == MOVETYPE_FOLLOW ) { - cl_entity_t *parent; - - parent = CL_GetEntityByIndex( e->curstate.aiment ); + cl_entity_t *parent = CL_GetEntityByIndex( e->curstate.aiment ); if( parent && parent->model ) { @@ -407,7 +389,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) } } - scale = e->curstate.scale; + float scale = e->curstate.scale; if( !scale ) scale = 1.0f; if( R_SpriteOccluded( e, origin, &scale )) @@ -473,11 +455,13 @@ void R_DrawSpriteModel( cl_entity_t *e ) pglAlphaFunc( GL_GREATER, 1.0f / 3.0f ); } + mspriteframe_t *frame = NULL, *oldframe = NULL; + float lerp = 1.0f; if( R_SpriteAllowLerping( e, psprite )) lerp = R_GetSpriteFrameInterpolant( e, &oldframe, &frame ); else frame = oldframe = gEngfuncs.R_GetSpriteFrame( model, e->curstate.frame, e->angles[YAW] ); - type = psprite->type; + int type = psprite->type; // automatically roll parallel sprites if requested if( e->angles[ROLL] != 0.0f && type == SPR_FWD_PARALLEL ) @@ -486,32 +470,40 @@ void R_DrawSpriteModel( cl_entity_t *e ) switch( type ) { case SPR_ORIENTED: + { + vec3_t v_forward; AngleVectors( e->angles, v_forward, v_right, v_up ); VectorScale( v_forward, 0.01f, v_forward ); // to avoid z-fighting VectorSubtract( origin, v_forward, origin ); break; + } case SPR_FACING_UPRIGHT: VectorSet( v_right, origin[1] - RI.rvp.vieworigin[1], -(origin[0] - RI.rvp.vieworigin[0]), 0.0f ); VectorSet( v_up, 0.0f, 0.0f, 1.0f ); VectorNormalize( v_right ); break; case SPR_FWD_PARALLEL_UPRIGHT: - dot = RI.vforward[2]; + { + float dot = RI.vforward[2]; if(( dot > 0.999848f ) || ( dot < -0.999848f )) // cos(1 degree) = 0.999848 return; // invisible VectorSet( v_up, 0.0f, 0.0f, 1.0f ); VectorSet( v_right, RI.vforward[1], -RI.vforward[0], 0.0f ); VectorNormalize( v_right ); break; + } case SPR_FWD_PARALLEL_ORIENTED: - angle = e->angles[ROLL] * (M_PI2 / 360.0f); + { + float angle = e->angles[ROLL] * (M_PI2 / 360.0f); + float sr, cr; SinCos( angle, &sr, &cr ); - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { v_right[i] = (RI.vright[i] * cr + RI.vup[i] * sr); v_up[i] = RI.vright[i] * -sr + RI.vup[i] * cr; } break; + } case SPR_FWD_PARALLEL: // normal sprite default: VectorCopy( RI.vright, v_right ); @@ -533,7 +525,7 @@ void R_DrawSpriteModel( cl_entity_t *e ) { // draw two combined lerped frames lerp = bound( 0.0f, lerp, 1.0f ); - ilerp = 1.0f - lerp; + float ilerp = 1.0f - lerp; if( ilerp != 0.0f ) { diff --git a/ref/gl/gl_studio.c b/ref/gl/gl_studio.c index 11b26610..579f3c2e 100644 --- a/ref/gl/gl_studio.c +++ b/ref/gl/gl_studio.c @@ -208,15 +208,12 @@ Compute a full bounding box for current sequence */ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) { - vec3_t studio_mins, studio_maxs; - vec3_t mins, maxs, p1, p2; cl_entity_t *e = RI.currententity; - mstudioseqdesc_t *pseqdesc; - int i; if( !m_pStudioHeader ) return false; + vec3_t mins, maxs; // check if we have valid mins\maxs if( !VectorIsNull( RI.currentmodel->mins ) && !VectorIsNull( RI.currentmodel->maxs )) { @@ -233,16 +230,18 @@ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) if( e->curstate.sequence < 0 || e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; // add sequence box to the model box AddPointToBounds( pseqdesc->bbmin, mins, maxs ); AddPointToBounds( pseqdesc->bbmax, mins, maxs ); + vec3_t studio_mins, studio_maxs; ClearBounds( studio_mins, studio_maxs ); // compute a full bounding box - for( i = 0; i < 8; i++ ) + for( int i = 0; i < 8; i++ ) { + vec3_t p1, p2; p1[0] = ( i & 1 ) ? mins[0] : maxs[0]; p1[1] = ( i & 2 ) ? mins[1] : maxs[1]; p1[2] = ( i & 4 ) ? mins[2] : maxs[2]; @@ -259,11 +258,9 @@ static qboolean R_StudioComputeBBox( vec3_t bbox[8] ) static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3x4 result ) { - float flWeight0, flWeight1, flWeight2, flWeight3; - int i, numbones = 0; - float flTotal; + int numbones = 0; - for( i = 0; i < MAXSTUDIOBONEWEIGHTS; i++ ) + for( int i = 0; i < MAXSTUDIOBONEWEIGHTS; i++ ) { if( boneweights->bone[i] != -1 ) numbones++; @@ -275,11 +272,11 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 vec4_t *boneMat1 = (vec4_t *)g_studio.worldtransform[boneweights->bone[1]]; vec4_t *boneMat2 = (vec4_t *)g_studio.worldtransform[boneweights->bone[2]]; vec4_t *boneMat3 = (vec4_t *)g_studio.worldtransform[boneweights->bone[3]]; - flWeight0 = boneweights->weight[0] / 255.0f; - flWeight1 = boneweights->weight[1] / 255.0f; - flWeight2 = boneweights->weight[2] / 255.0f; - flWeight3 = boneweights->weight[3] / 255.0f; - flTotal = flWeight0 + flWeight1 + flWeight2 + flWeight3; + float flWeight0 = boneweights->weight[0] / 255.0f; + float flWeight1 = boneweights->weight[1] / 255.0f; + float flWeight2 = boneweights->weight[2] / 255.0f; + float flWeight3 = boneweights->weight[3] / 255.0f; + float flTotal = flWeight0 + flWeight1 + flWeight2 + flWeight3; if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error @@ -301,10 +298,10 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 vec4_t *boneMat0 = (vec4_t *)g_studio.worldtransform[boneweights->bone[0]]; vec4_t *boneMat1 = (vec4_t *)g_studio.worldtransform[boneweights->bone[1]]; vec4_t *boneMat2 = (vec4_t *)g_studio.worldtransform[boneweights->bone[2]]; - flWeight0 = boneweights->weight[0] / 255.0f; - flWeight1 = boneweights->weight[1] / 255.0f; - flWeight2 = boneweights->weight[2] / 255.0f; - flTotal = flWeight0 + flWeight1 + flWeight2; + float flWeight0 = boneweights->weight[0] / 255.0f; + float flWeight1 = boneweights->weight[1] / 255.0f; + float flWeight2 = boneweights->weight[2] / 255.0f; + float flTotal = flWeight0 + flWeight1 + flWeight2; if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error @@ -325,9 +322,9 @@ static void R_StudioComputeSkinMatrix( mstudioboneweight_t *boneweights, matrix3 { vec4_t *boneMat0 = (vec4_t *)g_studio.worldtransform[boneweights->bone[0]]; vec4_t *boneMat1 = (vec4_t *)g_studio.worldtransform[boneweights->bone[1]]; - flWeight0 = boneweights->weight[0] / 255.0f; - flWeight1 = boneweights->weight[1] / 255.0f; - flTotal = flWeight0 + flWeight1; + float flWeight0 = boneweights->weight[0] / 255.0f; + float flWeight1 = boneweights->weight[1] / 255.0f; + float flTotal = flWeight0 + flWeight1; if( flTotal < 1.0f ) flWeight0 += 1.0f - flTotal; // compensate rounding error @@ -513,7 +510,6 @@ void R_StudioLerpMovement( cl_entity_t *e, double time, vec3_t origin, vec3_t an if( !VectorCompareEpsilon( e->curstate.angles, e->latched.prevangles, ON_EPSILON )) { vec4_t q, q1, q2; - AngleQuaternion( e->curstate.angles, q1, false ); AngleQuaternion( e->latched.prevangles, q2, false ); QuaternionSlerp( q2, q1, f, q ); @@ -634,19 +630,16 @@ static void R_StudioFxTransform( cl_entity_t *ent, matrix3x4 transform ) } else if( !gEngfuncs.COM_RandomLong( 0, 49 )) { - float offset; int axis = gEngfuncs.COM_RandomLong( 0, 1 ); if( axis == 1 ) axis = 2; // choose between x & z - offset = gEngfuncs.COM_RandomFloat( -10.0f, 10.0f ); + float offset = gEngfuncs.COM_RandomFloat( -10.0f, 10.0f ); transform[gEngfuncs.COM_RandomLong( 0, 2 )][3] += offset; } break; case kRenderFxExplode: { - float scale; - - scale = 1.0f + ( g_studio.time - ent->curstate.animtime ) * 10.0f; + float scale = 1.0f + ( g_studio.time - ent->curstate.animtime ) * 10.0f; if( scale > 2.0f ) scale = 2.0f; // don't blow up more than 200% transform[0][1] *= scale; @@ -665,15 +658,12 @@ StudioCalcBoneAdj */ static void R_StudioCalcBoneAdj( float dadt, float *adj, const byte *pcontroller1, const byte *pcontroller2, byte mouthopen ) { - mstudiobonecontroller_t *pbonecontroller; - float value = 0.0f; - int i, j; + mstudiobonecontroller_t *pbonecontroller = (mstudiobonecontroller_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex); - pbonecontroller = (mstudiobonecontroller_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bonecontrollerindex); - - for( j = 0; j < m_pStudioHeader->numbonecontrollers; j++ ) + for( int j = 0; j < m_pStudioHeader->numbonecontrollers; j++ ) { - i = pbonecontroller[j].index; + float value = 0.0f; + int i = pbonecontroller[j].index; if( i == STUDIO_MOUTH ) { @@ -730,10 +720,7 @@ StudioCalcRotations */ static void R_StudioCalcRotations( cl_entity_t *e, float pos[][3], vec4_t *q, mstudioseqdesc_t *pseqdesc, mstudioanim_t *panim, float f ) { - int i, frame; - float adj[MAXSTUDIOCONTROLLERS]; - float s, dadt; - mstudiobone_t *pbone; + float adj[MAXSTUDIOCONTROLLERS]; // bah, fix this bug with changing sequences too fast if( f > pseqdesc->numframes - 1 ) @@ -748,17 +735,16 @@ static void R_StudioCalcRotations( cl_entity_t *e, float pos[][3], vec4_t *q, ms f = -0.01f; } - frame = (int)f; - - dadt = R_StudioEstimateInterpolant( e ); - s = (f - frame); + int frame = (int)f; + float dadt = R_StudioEstimateInterpolant( e ); + float s = (f - frame); // add in programtic controllers - pbone = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + mstudiobone_t *pbone = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); R_StudioCalcBoneAdj( dadt, adj, e->curstate.controller, e->latched.prevcontroller, e->mouth.mouthopen ); - for( i = 0; i < m_pStudioHeader->numbones; i++, pbone++, panim++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++, pbone++, panim++ ) R_StudioCalcBones( frame, s, pbone, panim, adj, pos[i], q[i] ); if( pseqdesc->motiontype & STUDIO_X ) pos[pseqdesc->motionbone][0] = 0.0f; @@ -774,28 +760,22 @@ StudioMergeBones */ static void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) { - int i, j; - mstudiobone_t *pbones; - mstudioseqdesc_t *pseqdesc; - mstudioanim_t *panim; - matrix3x4 bonematrix; static vec4_t q[MAXSTUDIOBONES]; static float pos[MAXSTUDIOBONES][3]; - float f; if( e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + float f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); - f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); - - panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, m_pSubModel, pseqdesc ); + mstudioanim_t *panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, m_pSubModel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + mstudiobone_t *pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { + int j; for( j = 0; j < g_studio.cached_numbones; j++ ) { if( !Q_stricmp( pbones[i].name, g_studio.cached_bonenames[j] )) @@ -808,6 +788,7 @@ static void R_StudioMergeBones( cl_entity_t *e, model_t *m_pSubModel ) if( j >= g_studio.cached_numbones ) { + matrix3x4 bonematrix; Matrix3x4_FromOriginQuat( bonematrix, q[i], pos[i] ); if( pbones[i].parent == -1 ) { @@ -834,11 +815,6 @@ StudioSetupBones */ static void R_StudioSetupBones( cl_entity_t *e ) { - float f; - mstudiobone_t *pbones; - mstudioseqdesc_t *pseqdesc; - mstudioanim_t *panim; - matrix3x4 bonematrix; static vec3_t pos[MAXSTUDIOBONES]; static vec4_t q[MAXSTUDIOBONES]; static vec3_t pos2[MAXSTUDIOBONES]; @@ -847,28 +823,23 @@ static void R_StudioSetupBones( cl_entity_t *e ) static vec4_t q3[MAXSTUDIOBONES]; static vec3_t pos4[MAXSTUDIOBONES]; static vec4_t q4[MAXSTUDIOBONES]; - int i; if( e->curstate.sequence >= m_pStudioHeader->numseq ) e->curstate.sequence = 0; - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->curstate.sequence; + float f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); - f = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); - - panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); + mstudioanim_t *panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); R_StudioCalcRotations( e, pos, q, pseqdesc, panim, f ); if( pseqdesc->numblends > 1 ) { - float s; - float dadt; - panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, f ); - dadt = R_StudioEstimateInterpolant( e ); - s = (e->curstate.blending[0] * dadt + e->latched.prevblending[0] * (1.0f - dadt)) / 255.0f; + float dadt = R_StudioEstimateInterpolant( e ); + float s = (e->curstate.blending[0] * dadt + e->latched.prevblending[0] * (1.0f - dadt)) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q, pos, q2, pos2, s ); @@ -893,7 +864,6 @@ static void R_StudioSetupBones( cl_entity_t *e ) // blend from last sequence static vec3_t pos1b[MAXSTUDIOBONES]; static vec4_t q1b[MAXSTUDIOBONES]; - float s; pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + e->latched.prevsequence; panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); @@ -906,7 +876,7 @@ static void R_StudioSetupBones( cl_entity_t *e ) panim += m_pStudioHeader->numbones; R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, e->latched.prevframe ); - s = (e->latched.prevseqblending[0]) / 255.0f; + float s = (e->latched.prevseqblending[0]) / 255.0f; R_StudioSlerpBones( m_pStudioHeader->numbones, q1b, pos1b, q2, pos2, s ); if( pseqdesc->numblends == 4 ) @@ -925,7 +895,7 @@ static void R_StudioSetupBones( cl_entity_t *e ) } } - s = 1.0f - ( g_studio.time - e->latched.sequencetime ) / 0.2f; + float s = 1.0f - ( g_studio.time - e->latched.sequencetime ) / 0.2f; R_StudioSlerpBones( m_pStudioHeader->numbones, q, pos, q1b, pos1b, s ); } else @@ -934,7 +904,7 @@ static void R_StudioSetupBones( cl_entity_t *e ) e->latched.prevframe = f; } - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + mstudiobone_t *pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); // calc gait animation if( m_pPlayerInfo && m_pPlayerInfo->gaitsequence != 0 ) @@ -949,7 +919,7 @@ static void R_StudioSetupBones( cl_entity_t *e ) panim = gEngfuncs.R_StudioGetAnim( m_pStudioHeader, RI.currentmodel, pseqdesc ); R_StudioCalcRotations( e, pos2, q2, pseqdesc, panim, m_pPlayerInfo->gaitframe ); - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { if( !Q_strcmp( pbones[i].name, "Bip01 Spine" )) copy_bones = false; @@ -963,8 +933,9 @@ static void R_StudioSetupBones( cl_entity_t *e ) } } - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { + matrix3x4 bonematrix; Matrix3x4_FromOriginQuat( bonematrix, q[i], pos[i] ); if( pbones[i].parent == -1 ) @@ -991,13 +962,10 @@ StudioSaveBones */ static void R_StudioSaveBones( void ) { - mstudiobone_t *pbones; - int i; - - pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); + mstudiobone_t *pbones = (mstudiobone_t *)((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); g_studio.cached_numbones = m_pStudioHeader->numbones; - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { Matrix3x4_Copy( g_studio.cached_bonestransform[i], g_studio.bonestransform[i] ); Matrix3x4_Copy( g_studio.cached_lighttransform[i], g_studio.lighttransform[i] ); @@ -1015,25 +983,22 @@ NOTE: m_pSubModel must be set static void R_StudioBuildNormalTable( void ) { cl_entity_t *e = RI.currententity; - mstudiomesh_t *pmesh; - int i, j; Assert( m_pSubModel != NULL ); // reset chrome cache - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) g_studio.chromeage[i] = 0; - for( i = 0; i < m_pSubModel->numverts; i++ ) + for( int i = 0; i < m_pSubModel->numverts; i++ ) g_studio.normaltable[i] = -1; - for( j = 0; j < m_pSubModel->nummesh; j++ ) + for( int j = 0; j < m_pSubModel->nummesh; j++ ) { - short *ptricmds; - - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + mstudiomesh_t *pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; + short *ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + int i; while(( i = *( ptricmds++ ))) { if( i < 0 ) i = -i; @@ -1065,23 +1030,17 @@ g_studio.verts must be computed */ static void R_StudioGenerateNormals( void ) { - int v0, v1, v2; - vec3_t e0, e1, norm; - mstudiomesh_t *pmesh; - int i, j; - Assert( m_pSubModel != NULL ); - for( i = 0; i < m_pSubModel->numverts; i++ ) + for( int i = 0; i < m_pSubModel->numverts; i++ ) VectorClear( g_studio.norms[i] ); - for( j = 0; j < m_pSubModel->nummesh; j++ ) + for( int j = 0; j < m_pSubModel->nummesh; j++ ) { - short *ptricmds; - - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + mstudiomesh_t *pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + j; + short *ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + int i; while(( i = *( ptricmds++ ))) { if( i < 0 ) @@ -1090,12 +1049,13 @@ static void R_StudioGenerateNormals( void ) if( i > 2 ) { - v0 = ptricmds[0]; ptricmds += 4; - v1 = ptricmds[0]; ptricmds += 4; + vec3_t e0, e1, norm; + int v0 = ptricmds[0]; ptricmds += 4; + int v1 = ptricmds[0]; ptricmds += 4; for( i -= 2; i > 0; i--, ptricmds += 4 ) { - v2 = ptricmds[0]; + int v2 = ptricmds[0]; VectorSubtract( g_studio.verts[v1], g_studio.verts[v0], e0 ); VectorSubtract( g_studio.verts[v2], g_studio.verts[v0], e1 ); @@ -1118,13 +1078,13 @@ static void R_StudioGenerateNormals( void ) if( i > 2 ) { qboolean odd = false; - - v0 = ptricmds[0]; ptricmds += 4; - v1 = ptricmds[0]; ptricmds += 4; + vec3_t e0, e1, norm; + int v0 = ptricmds[0]; ptricmds += 4; + int v1 = ptricmds[0]; ptricmds += 4; for( i -= 2; i > 0; i--, ptricmds += 4 ) { - v2 = ptricmds[0]; + int v2 = ptricmds[0]; VectorSubtract( g_studio.verts[v1], g_studio.verts[v0], e0 ); VectorSubtract( g_studio.verts[v2], g_studio.verts[v0], e1 ); @@ -1148,7 +1108,7 @@ static void R_StudioGenerateNormals( void ) } } - for( i = 0; i < m_pSubModel->numverts; i++ ) + for( int i = 0; i < m_pSubModel->numverts; i++ ) VectorNormalize( g_studio.norms[i] ); } @@ -1160,8 +1120,6 @@ StudioSetupChrome */ static void R_StudioSetupChrome( float *pchrome, int bone, vec3_t normal ) { - float n; - if( g_studio.chromeage[bone] != g_studio.framecount ) { // calculate vectors from the viewer to the bone. This roughly adjusts for position @@ -1187,7 +1145,7 @@ static void R_StudioSetupChrome( float *pchrome, int bone, vec3_t normal ) } // calc s coord - n = DotProduct( normal, g_studio.chromeright[bone] ); + float n = DotProduct( normal, g_studio.chromeright[bone] ); pchrome[0] = (n + 1.0f) * 32.0f; // calc t coord @@ -1203,13 +1161,10 @@ StudioCalcAttachments */ static void R_StudioCalcAttachments( void ) { - mstudioattachment_t *pAtt; - int i; - // calculate attachment points - pAtt = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex); + mstudioattachment_t *pAtt = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex); - for( i = 0; i < Q_min( MAXSTUDIOATTACHMENTS, m_pStudioHeader->numattachments ); i++ ) + for( int i = 0; i < Q_min( MAXSTUDIOATTACHMENTS, m_pStudioHeader->numattachments ); i++ ) { Matrix3x4_VectorTransform( g_studio.lighttransform[pAtt[i].bone], pAtt[i].org, RI.currententity->attachment[i] ); } @@ -1223,14 +1178,12 @@ pfnStudioSetupModel */ static void R_StudioSetupModel( int bodypart, void **ppbodypart, void **ppsubmodel ) { - int index; - if( bodypart > m_pStudioHeader->numbodyparts ) bodypart = 0; m_pBodyPart = (mstudiobodyparts_t *)((byte *)m_pStudioHeader + m_pStudioHeader->bodypartindex) + bodypart; - index = RI.currententity->curstate.body / m_pBodyPart->base; + int index = RI.currententity->curstate.body / m_pBodyPart->base; index = index % m_pBodyPart->nummodels; m_pSubModel = (mstudiomodel_t *)((byte *)m_pStudioHeader + m_pBodyPart->modelindex) + index; @@ -1261,25 +1214,23 @@ pfnStudioEntityLight */ static void R_StudioEntityLight( alight_t *lightinfo ) { - int lnum, i, j, k; - float minstrength, dist2, f, r2; float lstrength[MAX_LOCALLIGHTS]; cl_entity_t *ent = RI.currententity; - vec3_t mid, origin; g_studio.numlocallights = 0; if( !ent || !r_dynamic->value ) return; - for( i = 0; i < MAX_LOCALLIGHTS; i++ ) + for( int i = 0; i < MAX_LOCALLIGHTS; i++ ) lstrength[i] = 0; + vec3_t origin; Matrix3x4_OriginFromMatrix( g_studio.rotationmatrix, origin ); - dist2 = 1000000.0f; - k = 0; + float dist2 = 1000000.0f; + int k = 0; - for( lnum = 0; lnum < MAX_ELIGHTS; lnum++ ) + for( int lnum = 0; lnum < MAX_ELIGHTS; lnum++ ) { dlight_t *el = &tr.elights[lnum]; @@ -1294,11 +1245,13 @@ static void R_StudioEntityLight( alight_t *lightinfo ) else VectorCopy( ent->origin, el->origin ); } + vec3_t mid; VectorSubtract( origin, el->origin, mid ); - f = DotProduct( mid, mid ); - r2 = el->radius * el->radius; + float f = DotProduct( mid, mid ); + float r2 = el->radius * el->radius; + float minstrength; if( f > r2 ) minstrength = r2 / f; else minstrength = 1.0f; @@ -1306,7 +1259,8 @@ static void R_StudioEntityLight( alight_t *lightinfo ) { if( g_studio.numlocallights >= MAX_LOCALLIGHTS ) { - for( j = 0, k = -1; j < g_studio.numlocallights; j++ ) + k = -1; + for( int j = 0; j < g_studio.numlocallights; j++ ) { if( lstrength[j] < dist2 && lstrength[j] < minstrength ) { @@ -1342,7 +1296,6 @@ R_StudioSetupLighting static void R_StudioSetupLighting( alight_t *plight ) { float scale = 1.0f; - int i; if( !m_pStudioHeader || !plight ) return; @@ -1354,7 +1307,7 @@ static void R_StudioSetupLighting( alight_t *plight ) g_studio.shadelight = plight->shadelight; VectorCopy( plight->plightvec, g_studio.lightvec ); - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { Matrix3x4_VectorIRotate( g_studio.lighttransform[i], plight->plightvec, g_studio.blightvec[i] ); if( scale > 1.0f ) VectorNormalize( g_studio.blightvec[i] ); // in case model may be scaled @@ -1371,15 +1324,13 @@ R_StudioLighting */ static void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) { - float illum; - if( FBitSet( flags, STUDIO_NF_FULLBRIGHT )) { *lv = 1.0f; return; } - illum = g_studio.ambientlight; + float illum = g_studio.ambientlight; if( FBitSet( flags, STUDIO_NF_FLATSHADE )) { @@ -1387,15 +1338,14 @@ static void R_StudioLighting( float *lv, int bone, int flags, vec3_t normal ) } else { - float r, lightcos; - + float lightcos; if( bone != -1 ) lightcos = DotProduct( normal, g_studio.blightvec[bone] ); else lightcos = DotProduct( normal, g_studio.lightvec ); // -1 colinear, 1 opposite if( lightcos > 1.0f ) lightcos = 1.0f; illum += g_studio.shadelight; - r = SHADE_LAMBERT; + float r = SHADE_LAMBERT; // do modified hemispherical lighting if( r <= 1.0f ) @@ -1428,30 +1378,23 @@ R_LightLambert */ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, const vec3_t color, byte *out ) { - vec3_t finalLight; - int i; - if( !g_studio.numlocallights ) { VectorScale( color, 255.0f, out ); return; } + vec3_t finalLight; VectorSet( finalLight, 0, 0, 0 ); - for( i = 0; i < g_studio.numlocallights; i++ ) + for( int i = 0; i < g_studio.numlocallights; i++ ) { - float r; - - r = DotProduct( normal, light[i] ); + float r = DotProduct( normal, light[i] ); if( likely( !tr.fFlipViewModel )) r = -r; if( r > 0.0f ) { - vec3_t localLight; - float temp; - if( light[i][3] == 0.0f ) { float r2 = DotProduct( light[i], light[i] ); @@ -1461,8 +1404,9 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, else light[i][3] = 0.0001f; } - temp = r * light[i][3]; + float temp = r * light[i][3]; + vec3_t localLight; VectorAddScalar( g_studio.locallightcolor[i], temp, localLight ); VectorAdd( finalLight, localLight, finalLight ); } @@ -1470,7 +1414,7 @@ static void R_LightLambert( vec4_t light[MAX_LOCALLIGHTS], const vec3_t normal, if( !VectorIsNull( finalLight )) { - for( i = 0; i < 3; i++ ) + for( int i = 0; i < 3; i++ ) { float c = finalLight[i] + LinearGammaTable( color[i] * 1023.0f ); @@ -1510,11 +1454,9 @@ R_LightStrength */ static void R_LightStrength( int bone, vec3_t localpos, vec4_t light[MAX_LOCALLIGHTS] ) { - int i; - if( g_studio.lightage[bone] != g_studio.framecount ) { - for( i = 0; i < g_studio.numlocallights; i++ ) + for( int i = 0; i < g_studio.numlocallights; i++ ) { dlight_t *el = g_studio.locallight[i]; Matrix3x4_VectorITransform( g_studio.lighttransform[bone], el->origin, g_studio.lightbonepos[bone][i] ); @@ -1523,7 +1465,7 @@ static void R_LightStrength( int bone, vec3_t localpos, vec4_t light[MAX_LOCALLI g_studio.lightage[bone] = g_studio.framecount; } - for( i = 0; i < g_studio.numlocallights; i++ ) + for( int i = 0; i < g_studio.numlocallights; i++ ) { VectorSubtract( localpos, g_studio.lightbonepos[bone][i], light[i] ); light[i][3] = 0.0f; @@ -1564,15 +1506,15 @@ Doesn't changes studio global state at all */ mstudiotexture_t *R_StudioGetTexture( cl_entity_t *e ) { - mstudiotexture_t *ptexture; - studiohdr_t *phdr, *thdr; + studiohdr_t *phdr; if(( phdr = gEngfuncs.Mod_Extradata( mod_studio, e->model )) == NULL ) return NULL; - thdr = m_pStudioHeader; + studiohdr_t *thdr = m_pStudioHeader; if( !thdr ) return NULL; + mstudiotexture_t *ptexture; if( m_fDoRemap ) ptexture = gEngfuncs.CL_GetRemapInfoForEntity( e )->ptexture; else ptexture = (mstudiotexture_t *)((byte *)thdr + thdr->textureindex); @@ -1721,10 +1663,8 @@ generic path */ static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) { - float *lv, *av; - int i, idx; + int i; qboolean glowShell = (scale > 0.0f) ? true : false; - vec3_t vert; while(( i = *( ptricmds++ ))) { @@ -1737,13 +1677,15 @@ static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float for( ; i > 0; i--, ptricmds += 4 ) { + int idx; if( glowShell ) { color24 *clr = &RI.currententity->curstate.rendercolor; idx = g_studio.normaltable[ptricmds[0]]; - av = g_studio.verts[ptricmds[0]]; - lv = g_studio.norms[ptricmds[0]]; + float *av = g_studio.verts[ptricmds[0]]; + float *lv = g_studio.norms[ptricmds[0]]; + vec3_t vert; VectorMA( av, scale, lv, vert ); pglColor4ub( clr->r, clr->g, clr->b, 255 ); pglTexCoord2f( g_studio.chrome[idx][0] * s, g_studio.chrome[idx][1] * t ); @@ -1752,7 +1694,6 @@ static void R_StudioDrawChromeMesh( short *ptricmds, vec3_t *pstudionorms, float else { idx = ptricmds[1]; - lv = (float *)g_studio.lightvalues[ptricmds[1]]; R_StudioSetColorBegin( ptricmds, pstudionorms ); pglTexCoord2f( g_studio.chrome[idx][0] * s, g_studio.chrome[idx][1] * t ); pglVertex3fv( g_studio.verts[ptricmds[0]] ); @@ -1824,8 +1765,7 @@ static void R_StudioBuildArrayNormalMesh( short *ptricmds, vec3_t *pstudionorms, for( ; i > 0; i--, ptricmds += 4 ) { - GLubyte *cl; - cl = g_studio.arraycolor[g_studio.numverts]; + GLubyte *cl = g_studio.arraycolor[g_studio.numverts]; vertexState = R_StudioBuildIndices( tri_strip, vertexState ); @@ -1864,8 +1804,7 @@ static void R_StudioBuildArrayFloatMesh( short *ptricmds, vec3_t *pstudionorms ) for( ; i > 0; i--, ptricmds += 4 ) { - GLubyte *cl; - cl = g_studio.arraycolor[g_studio.numverts]; + GLubyte *cl = g_studio.arraycolor[g_studio.numverts]; vertexState = R_StudioBuildIndices( tri_strip, vertexState ); @@ -1889,10 +1828,8 @@ generic path */ static void R_StudioBuildArrayChromeMesh( short *ptricmds, vec3_t *pstudionorms, float s, float t, float scale ) { - float *lv, *av; - int i, idx; + int i; qboolean glowShell = (scale > 0.0f) ? true : false; - vec3_t vert; while(( i = *( ptricmds++ ))) { @@ -1907,23 +1844,23 @@ static void R_StudioBuildArrayChromeMesh( short *ptricmds, vec3_t *pstudionorms, for( ; i > 0; i--, ptricmds += 4 ) { - GLubyte *cl; - cl = g_studio.arraycolor[g_studio.numverts]; - lv = (float *)g_studio.lightvalues[ptricmds[1]]; + GLubyte *cl = g_studio.arraycolor[g_studio.numverts]; vertexState = R_StudioBuildIndices( tri_strip, vertexState ); + int idx; if( glowShell ) { idx = g_studio.normaltable[ptricmds[0]]; - av = g_studio.verts[ptricmds[0]]; - lv = g_studio.norms[ptricmds[0]]; + float *av = g_studio.verts[ptricmds[0]]; + float *lv = g_studio.norms[ptricmds[0]]; cl[0] = RI.currententity->curstate.rendercolor.r; cl[1] = RI.currententity->curstate.rendercolor.g; cl[2] = RI.currententity->curstate.rendercolor.b; cl[3] = 255; + vec3_t vert; VectorMA( av, scale, lv, vert ); VectorCopy( vert, g_studio.arrayverts[g_studio.numverts] ); } @@ -1978,33 +1915,24 @@ R_StudioDrawPoints */ static void R_StudioDrawPoints( void ) { - int i, j, k, m_skinnum; float shellscale = 0.0f; qboolean need_sort = false; - byte *pvertbone; - byte *pnormbone; - vec3_t *pstudioverts; - vec3_t *pstudionorms; - mstudiotexture_t *ptexture; - mstudiomesh_t *pmesh; - short *pskinref; - float lv_tmp; if( !m_pStudioHeader ) return; g_studio.numverts = g_studio.numelems = 0; - m_skinnum = RI.currententity->curstate.skin; - ptexture = (mstudiotexture_t *)((byte *)m_pStudioHeader + m_pStudioHeader->textureindex); - pvertbone = ((byte *)m_pStudioHeader + m_pSubModel->vertinfoindex); - pnormbone = ((byte *)m_pStudioHeader + m_pSubModel->norminfoindex); + int m_skinnum = RI.currententity->curstate.skin; + mstudiotexture_t *ptexture = (mstudiotexture_t *)((byte *)m_pStudioHeader + m_pStudioHeader->textureindex); + byte *pvertbone = ((byte *)m_pStudioHeader + m_pSubModel->vertinfoindex); + byte *pnormbone = ((byte *)m_pStudioHeader + m_pSubModel->norminfoindex); - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex); - pstudioverts = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->vertindex); - pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex); + mstudiomesh_t *pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex); + vec3_t *pstudioverts = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->vertindex); + vec3_t *pstudionorms = (vec3_t *)((byte *)m_pStudioHeader + m_pSubModel->normindex); - pskinref = (short *)((byte *)m_pStudioHeader + m_pStudioHeader->skinindex); + short *pskinref = (short *)((byte *)m_pStudioHeader + m_pStudioHeader->skinindex); if( m_skinnum > 0 && m_skinnum < m_pStudioHeader->numskinfamilies ) pskinref += (m_skinnum * m_pStudioHeader->numskinref); @@ -2014,14 +1942,14 @@ static void R_StudioDrawPoints( void ) mstudioboneweight_t *pnormweight = (mstudioboneweight_t *)((byte *)m_pStudioHeader + m_pSubModel->blendnorminfoindex); matrix3x4 skinMat; - for( i = 0; i < m_pSubModel->numverts; i++ ) + for( int i = 0; i < m_pSubModel->numverts; i++ ) { R_StudioComputeSkinMatrix( &pvertweight[i], skinMat ); Matrix3x4_VectorTransform( skinMat, pstudioverts[i], g_studio.verts[i] ); R_LightStrength( pvertbone[i], pstudioverts[i], g_studio.lightpos[i] ); } - for( i = 0; i < m_pSubModel->numnorms; i++ ) + for( int i = 0; i < m_pSubModel->numnorms; i++ ) { R_StudioComputeSkinMatrix( &pnormweight[i], skinMat ); Matrix3x4_VectorRotate( skinMat, pstudionorms[i], g_studio.norms[i] ); @@ -2029,7 +1957,7 @@ static void R_StudioDrawPoints( void ) } else { - for( i = 0; i < m_pSubModel->numverts; i++ ) + for( int i = 0; i < m_pSubModel->numverts; i++ ) { Matrix3x4_VectorTransform( g_studio.bonestransform[pvertbone[i]], pstudioverts[i], g_studio.verts[i] ); R_LightStrength( pvertbone[i], pstudioverts[i], g_studio.lightpos[i] ); @@ -2045,7 +1973,8 @@ static void R_StudioDrawPoints( void ) R_StudioGenerateNormals(); } - for( j = k = 0; j < m_pSubModel->nummesh; j++ ) + int k = 0; + for( int j = 0; j < m_pSubModel->nummesh; j++ ) { g_nFaceFlags = ptexture[pskinref[pmesh[j].skinref]].flags | g_nForceFaceFlags; @@ -2058,7 +1987,7 @@ static void R_StudioDrawPoints( void ) if( RI.currententity->curstate.rendermode == kRenderTransAdd ) { - for( i = 0; i < pmesh[j].numnorms; i++, k++, pstudionorms++, pnormbone++ ) + for( int i = 0; i < pmesh[j].numnorms; i++, k++, pstudionorms++, pnormbone++ ) { if( FBitSet( g_nFaceFlags, STUDIO_NF_CHROME )) R_StudioSetupChrome( g_studio.chrome[k], *pnormbone, (float *)pstudionorms ); @@ -2067,8 +1996,9 @@ static void R_StudioDrawPoints( void ) } else { - for( i = 0; i < pmesh[j].numnorms; i++, k++, pstudionorms++, pnormbone++ ) + for( int i = 0; i < pmesh[j].numnorms; i++, k++, pstudionorms++, pnormbone++ ) { + float lv_tmp; if( FBitSet( m_pStudioHeader->flags, STUDIO_HAS_BONEWEIGHTS )) R_StudioLighting( &lv_tmp, -1, g_nFaceFlags, g_studio.norms[k] ); else R_StudioLighting( &lv_tmp, *pnormbone, g_nFaceFlags, (float *)pstudionorms ); @@ -2110,21 +2040,19 @@ static void R_StudioDrawPoints( void ) } } - for( j = 0; j < m_pSubModel->nummesh; j++ ) + for( int j = 0; j < m_pSubModel->nummesh; j++ ) { float oldblend = tr.blend; uint startArrayVerts = g_studio.numverts; uint startArrayElems = g_studio.numelems; - short *ptricmds; - float s, t; pmesh = g_studio.meshes[j].mesh; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + short *ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); g_nFaceFlags = ptexture[pskinref[pmesh->skinref]].flags | g_nForceFaceFlags; - s = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].width; - t = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].height; + float s = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].width; + float t = 1.0f / (float)ptexture[pskinref[pmesh->skinref]].height; if( FBitSet( g_nFaceFlags, STUDIO_NF_MASKED )) { @@ -2192,22 +2120,17 @@ R_StudioDrawHulls */ static void R_StudioDrawHulls( void ) { - float alpha, lv; - int i, j; - - if( r_drawentities->value == 4 ) - alpha = 0.5f; - else alpha = 1.0f; + float alpha = ( r_drawentities->value == 4 ) ? 0.5f : 1.0f; GL_Bind( XASH_TEXTURE0, tr.whiteTexture ); pglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); - for( i = 0; i < m_pStudioHeader->numhitboxes; i++ ) + for( int i = 0; i < m_pStudioHeader->numhitboxes; i++ ) { mstudiobbox_t *pbbox = (mstudiobbox_t *)((byte *)m_pStudioHeader + m_pStudioHeader->hitboxindex); vec3_t tmp, p[8]; - for( j = 0; j < 8; j++ ) + for( int j = 0; j < 8; j++ ) { tmp[0] = (j & 1) ? pbbox[i].bbmin[0] : pbbox[i].bbmax[0]; tmp[1] = (j & 2) ? pbbox[i].bbmin[1] : pbbox[i].bbmax[1]; @@ -2216,13 +2139,14 @@ static void R_StudioDrawHulls( void ) Matrix3x4_VectorTransform( g_studio.bonestransform[pbbox[i].bone], tmp, p[j] ); } - j = (pbbox[i].group % 8); + int j = (pbbox[i].group % 8); TriBegin( TRI_QUADS ); TriColor4f( hullcolor[j][0], hullcolor[j][1], hullcolor[j][2], alpha ); for( j = 0; j < 6; j++ ) { + float lv; VectorClear( tmp ); tmp[j % 3] = (j < 3) ? 1.0f : -1.0f; R_StudioLighting( &lv, pbbox[i].bone, 0, tmp ); @@ -2246,8 +2170,6 @@ R_StudioDrawAbsBBox static void R_StudioDrawAbsBBox( void ) { vec3_t p[8], tmp; - float lv; - int i; // looks ugly, skip if( RI.currententity == tr.viewent ) @@ -2261,8 +2183,9 @@ static void R_StudioDrawAbsBBox( void ) TriRenderMode( kRenderTransAdd ); TriBegin( TRI_QUADS ); - for( i = 0; i < 6; i++ ) + for( int i = 0; i < 6; i++ ) { + float lv; VectorClear( tmp ); tmp[i % 3] = (i < 3) ? 1.0f : -1.0f; R_StudioLighting( &lv, -1, 0, tmp ); @@ -2287,11 +2210,10 @@ static void R_StudioDrawBones( void ) { mstudiobone_t *pbones = (mstudiobone_t *) ((byte *)m_pStudioHeader + m_pStudioHeader->boneindex); vec3_t point; - int i; pglDisable( GL_TEXTURE_2D ); - for( i = 0; i < m_pStudioHeader->numbones; i++ ) + for( int i = 0; i < m_pStudioHeader->numbones; i++ ) { if( pbones[i].parent >= 0 ) { @@ -2335,17 +2257,14 @@ static void R_StudioDrawBones( void ) static void R_StudioDrawAttachments( void ) { - int i; - pglDisable( GL_TEXTURE_2D ); pglDisable( GL_DEPTH_TEST ); - for( i = 0; i < m_pStudioHeader->numattachments; i++ ) + for( int i = 0; i < m_pStudioHeader->numattachments; i++ ) { - mstudioattachment_t *pattachments; vec3_t v[4]; - pattachments = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex); + mstudioattachment_t *pattachments = (mstudioattachment_t *)((byte *)m_pStudioHeader + m_pStudioHeader->attachmentindex); Matrix3x4_VectorTransform( g_studio.bonestransform[pattachments[i].bone], pattachments[i].org, v[0] ); Matrix3x4_VectorTransform( g_studio.bonestransform[pattachments[i].bone], pattachments[i].vectors[0], v[1] ); Matrix3x4_VectorTransform( g_studio.bonestransform[pattachments[i].bone], pattachments[i].vectors[1], v[2] ); @@ -2404,12 +2323,11 @@ R_StudioSetupPlayerModel static model_t *R_StudioSetupPlayerModel( int index ) { player_info_t *info = gEngfuncs.pfnPlayerInfo( index ); - player_model_t *state; if( index < 0 || index >= gp_cl->maxclients ) return NULL; - state = &g_studio.player_models[index]; + player_model_t *state = &g_studio.player_models[index]; // g-cont: force for "dev-mode", non-local games and menu preview if(( gpGlobals->developer || !ENGINE_GET_PARM( PARM_SINGLEPLAYER_GAME ) || !FBitSet( RI.rvp.flags, RF_DRAW_WORLD ) ) && info->model[0] ) @@ -2449,13 +2367,9 @@ check for texture flags */ int R_GetEntityRenderMode( cl_entity_t *ent ) { - int i, opaque, trans; - mstudiotexture_t *ptexture; - cl_entity_t *oldent; - model_t *model = NULL; - studiohdr_t *phdr; + model_t *model = NULL; - oldent = RI.currententity; + cl_entity_t *oldent = RI.currententity; RI.currententity = ent; if( ent->player ) // check it for real playermodel @@ -2466,6 +2380,7 @@ int R_GetEntityRenderMode( cl_entity_t *ent ) RI.currententity = oldent; + studiohdr_t *phdr; if(( phdr = gEngfuncs.Mod_Extradata( mod_studio, model )) == NULL ) { if( R_ModelOpaque( ent->curstate.rendermode )) @@ -2476,9 +2391,10 @@ int R_GetEntityRenderMode( cl_entity_t *ent ) } return ent->curstate.rendermode; } - ptexture = (mstudiotexture_t *)((byte *)phdr + phdr->textureindex); + mstudiotexture_t *ptexture = (mstudiotexture_t *)((byte *)phdr + phdr->textureindex); - for( opaque = trans = i = 0; i < phdr->numtextures; i++, ptexture++ ) + int opaque = 0, trans = 0; + for( int i = 0; i < phdr->numtextures; i++, ptexture++ ) { // ignore chrome & additive it's just a specular-like effect if( FBitSet( ptexture->flags, STUDIO_NF_ADDITIVE ) && !FBitSet( ptexture->flags, STUDIO_NF_CHROME )) @@ -2500,11 +2416,7 @@ R_StudioClientEvents */ static void R_StudioClientEvents( void ) { - mstudioseqdesc_t *pseqdesc; - mstudioevent_t *pevent; cl_entity_t *e = RI.currententity; - int i, sequence; - float end, start; if( g_studio.frametime == 0.0 ) return; // gamepaused @@ -2532,16 +2444,16 @@ static void R_StudioClientEvents( void ) el->radius = 24; } - sequence = bound( 0, e->curstate.sequence, m_pStudioHeader->numseq - 1 ); - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + sequence; + int sequence = bound( 0, e->curstate.sequence, m_pStudioHeader->numseq - 1 ); + mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + sequence; // no events for this animation if( pseqdesc->numevents == 0 ) return; - end = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); - start = end - e->curstate.framerate * gp_host->frametime * pseqdesc->fps; - pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex); + float end = R_StudioEstimateFrame( e, pseqdesc, g_studio.time ); + float start = end - e->curstate.framerate * gp_host->frametime * pseqdesc->fps; + mstudioevent_t *pevent = (mstudioevent_t *)((byte *)m_pStudioHeader + pseqdesc->eventindex); if( e->latched.sequencetime == e->curstate.animtime ) { @@ -2549,7 +2461,7 @@ static void R_StudioClientEvents( void ) start = -0.01f; } - for( i = 0; i < pseqdesc->numevents; i++ ) + for( int i = 0; i < pseqdesc->numevents; i++ ) { // ignore all non-client-side events if( pevent[i].event < EVENT_CLIENT ) @@ -2619,7 +2531,6 @@ R_StudioSetupRenderer static void R_StudioSetupRenderer( int rendermode ) { studiohdr_t *phdr = m_pStudioHeader; - int i; if( rendermode > kRenderTransAdd ) rendermode = 0; g_studio.rendermode = bound( 0, rendermode, kRenderTransAdd ); @@ -2637,7 +2548,7 @@ static void R_StudioSetupRenderer( int rendermode ) // NOTE: extended boneinfo goes immediately after bones mstudioboneinfo_t *boneinfo = (mstudioboneinfo_t *)((byte *)phdr + phdr->boneindex + phdr->numbones * sizeof( mstudiobone_t )); - for( i = 0; i < phdr->numbones; i++ ) + for( int i = 0; i < phdr->numbones; i++ ) Matrix3x4_ConcatTransforms( g_studio.worldtransform[i], g_studio.bonestransform[i], boneinfo[i].poseToBone ); } } @@ -2680,11 +2591,7 @@ R_StudioDrawPointsShadow */ static void R_StudioDrawPointsShadow( void ) { - float *av; - float vec_x, vec_y; - mstudiomesh_t *pmesh; vec3_t point; - int i, k; if( FBitSet( RI.currententity->curstate.effects, EF_NOSHADOW )) return; @@ -2692,18 +2599,17 @@ static void R_StudioDrawPointsShadow( void ) if( glState.stencilEnabled ) pglEnable( GL_STENCIL_TEST ); - vec_x = -g_studio.lightvec[0] * 8.0f; - vec_y = -g_studio.lightvec[1] * 8.0f; + float vec_x = -g_studio.lightvec[0] * 8.0f; + float vec_y = -g_studio.lightvec[1] * 8.0f; - for( k = 0; k < m_pSubModel->nummesh; k++ ) + for( int k = 0; k < m_pSubModel->nummesh; k++ ) { - short *ptricmds; - - pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + k; - ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); + mstudiomesh_t *pmesh = (mstudiomesh_t *)((byte *)m_pStudioHeader + m_pSubModel->meshindex) + k; + short *ptricmds = (short *)((byte *)m_pStudioHeader + pmesh->triindex); r_stats.c_studio_polys += pmesh->numtris; + int i; while(( i = *( ptricmds++ ))) { if( i < 0 ) @@ -2719,7 +2625,7 @@ static void R_StudioDrawPointsShadow( void ) for( ; i > 0; i--, ptricmds += 4 ) { - av = g_studio.verts[ptricmds[0]]; + float *av = g_studio.verts[ptricmds[0]]; point[0] = av[0] - (vec_x * ( av[2] - g_studio.lightspot[2] )); point[1] = av[1] - (vec_y * ( av[2] - g_studio.lightspot[2] )); point[2] = g_studio.lightspot[2] + 1.0f; @@ -2811,9 +2717,7 @@ StudioRenderFinal */ static void R_StudioRenderFinal( void ) { - int i, rendermode; - - rendermode = R_StudioGetForceFaceFlags() ? kRenderTransAdd : RI.currententity->curstate.rendermode; + int rendermode = R_StudioGetForceFaceFlags() ? kRenderTransAdd : RI.currententity->curstate.rendermode; R_StudioSetupRenderer( rendermode ); if( r_drawentities->value == 2 ) @@ -2826,7 +2730,7 @@ static void R_StudioRenderFinal( void ) } else { - for( i = 0; i < m_pStudioHeader->numbodyparts; i++ ) + for( int i = 0; i < m_pStudioHeader->numbodyparts; i++ ) { R_StudioSetupModel( i, (void**)&m_pBodyPart, (void**)&m_pSubModel ); @@ -2927,9 +2831,7 @@ StudioEstimateGait static void R_StudioEstimateGait( entity_state_t *pplayer ) { vec3_t est_velocity; - float dt; - - dt = bound( 0.0f, g_studio.frametime, 1.0f ); + float dt = bound( 0.0f, g_studio.frametime, 1.0f ); if( dt == 0.0f || m_pPlayerInfo->renderframe == tr.realframecount ) { @@ -2982,17 +2884,14 @@ StudioProcessGait */ static void R_StudioProcessGait( entity_state_t *pplayer ) { - mstudioseqdesc_t *pseqdesc; - int iBlend; - float dt, flYaw; // view direction relative to movement - if( RI.currententity->curstate.sequence >= m_pStudioHeader->numseq ) RI.currententity->curstate.sequence = 0; - dt = bound( 0.0f, g_studio.frametime, 1.0f ); + float dt = bound( 0.0f, g_studio.frametime, 1.0f ); - pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + RI.currententity->curstate.sequence; + mstudioseqdesc_t *pseqdesc = (mstudioseqdesc_t *)((byte *)m_pStudioHeader + m_pStudioHeader->seqindex) + RI.currententity->curstate.sequence; + int iBlend; R_StudioPlayerBlend( pseqdesc, &iBlend, &RI.currententity->angles[PITCH] ); RI.currententity->latched.prevangles[PITCH] = RI.currententity->angles[PITCH]; @@ -3002,7 +2901,7 @@ static void R_StudioProcessGait( entity_state_t *pplayer ) R_StudioEstimateGait( pplayer ); // calc side to side turning - flYaw = RI.currententity->angles[YAW] - m_pPlayerInfo->gaityaw; + float flYaw = RI.currententity->angles[YAW] - m_pPlayerInfo->gaityaw; flYaw = flYaw - (int)(flYaw / 360) * 360; if( flYaw < -180.0f ) flYaw = flYaw + 360.0f; if( flYaw > 180.0f ) flYaw = flYaw - 360.0f; @@ -3057,11 +2956,10 @@ R_StudioDrawPlayer */ static int R_StudioDrawPlayer( int flags, entity_state_t *pplayer ) { - int m_nPlayerIndex; alight_t lighting; vec3_t dir; - m_nPlayerIndex = pplayer->number - 1; + int m_nPlayerIndex = pplayer->number - 1; if( m_nPlayerIndex < 0 || m_nPlayerIndex >= gp_cl->maxclients ) return 0; @@ -3205,15 +3103,12 @@ static int R_StudioDrawModel( int flags ) if( RI.currententity->curstate.renderfx == kRenderFxDeadPlayer ) { - entity_state_t deadplayer; - int result; - if( RI.currententity->curstate.renderamt <= 0 || RI.currententity->curstate.renderamt > gp_cl->maxclients ) return 0; // get copy of player - deadplayer = *R_StudioGetPlayerState( RI.currententity->curstate.renderamt - 1 ); + entity_state_t deadplayer = *R_StudioGetPlayerState( RI.currententity->curstate.renderamt - 1 ); // clear weapon, movement state deadplayer.number = RI.currententity->curstate.renderamt; @@ -3225,7 +3120,7 @@ static int R_StudioDrawModel( int flags ) VectorCopy( RI.currententity->curstate.origin, deadplayer.origin ); g_studio.interpolate = false; - result = R_StudioDrawPlayer( flags, &deadplayer ); // draw as though it were a player + int result = R_StudioDrawPlayer( flags, &deadplayer ); // draw as though it were a player g_studio.interpolate = true; return result; @@ -3313,9 +3208,7 @@ static void R_StudioDrawModelInternal( cl_entity_t *e, int flags ) static cl_entity_t *R_FindParentEntity( cl_entity_t *e, cl_entity_t **entities, uint num_entities ) { - uint i; - - for( i = 0; i < num_entities; i++ ) + for( uint i = 0; i < num_entities; i++ ) { if( entities[i]->index == e->curstate.aiment ) return entities[i]; @@ -3376,7 +3269,6 @@ R_RunViewmodelEvents */ void R_RunViewmodelEvents( void ) { - int i; vec3_t simorg; if( r_drawviewmodel->value == 0 ) @@ -3397,7 +3289,7 @@ void R_RunViewmodelEvents( void ) R_StudioSetupTimings(); VectorCopy( gp_cl->simorg, simorg ); - for( i = 0; i < 4; i++ ) + for( int i = 0; i < 4; i++ ) VectorCopy( simorg, RI.currententity->attachment[i] ); RI.currentmodel = RI.currententity->model; @@ -3462,7 +3354,6 @@ load model texture with unique name */ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture_t *ptexture ) { - size_t size; int flags = 0; char texname[128], name[128], mdlname[128]; texture_t *tx = NULL; @@ -3474,13 +3365,11 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture // store some textures for remapping if( !Q_strnicmp( ptexture->name, "DM_Base", 7 ) || !Q_strnicmp( ptexture->name, "remap", 5 )) { - int i, size; char val[6]; - byte *pixels; - i = mod->numtextures; + int i = mod->numtextures; mod->textures = (texture_t **)Mem_Realloc( mod->mempool, mod->textures, ( i + 1 ) * sizeof( texture_t* )); - size = ptexture->width * ptexture->height + 768; + int size = ptexture->width * ptexture->height + 768; tx = Mem_Calloc( mod->mempool, sizeof( *tx ) + size ); mod->textures[i] = tx; @@ -3509,7 +3398,7 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture tx->height = ptexture->height; // the pixels immediately follow the structures - pixels = (byte *)phdr + ptexture->index; + byte *pixels = (byte *)phdr + ptexture->index; memcpy( tx+1, pixels, size ); ptexture->flags |= STUDIO_NF_COLORMAP; // yes, this is colormap image @@ -3544,7 +3433,7 @@ static void R_StudioLoadTexture( model_t *mod, studiohdr_t *phdr, mstudiotexture { // NOTE: replace index with pointer to start of imagebuffer, ImageLib expected it gEngfuncs.Image_SetMDLPointer((byte *)phdr + ptexture->index); - size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768; + size_t size = sizeof( mstudiotexture_t ) + ptexture->width * ptexture->height + 768; // build the texname Q_snprintf( texname, sizeof( texname ), "#%s/%s.mdl", mdlname, name ); @@ -3570,16 +3459,14 @@ Mod_StudioLoadTextures void Mod_StudioLoadTextures( model_t *mod, void *data ) { studiohdr_t *phdr = (studiohdr_t *)data; - mstudiotexture_t *ptexture; - int i; if( !phdr ) return; - ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); + mstudiotexture_t *ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); if( phdr->textureindex > 0 ) { - for( i = 0; i < phdr->numtextures; i++ ) + for( int i = 0; i < phdr->numtextures; i++ ) R_StudioLoadTexture( mod, phdr, &ptexture[i] ); } } @@ -3592,16 +3479,14 @@ Mod_StudioUnloadTextures void Mod_StudioUnloadTextures( void *data ) { studiohdr_t *phdr = (studiohdr_t *)data; - mstudiotexture_t *ptexture; - int i; if( !phdr ) return; - ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); + mstudiotexture_t *ptexture = (mstudiotexture_t *)(((byte *)phdr) + phdr->textureindex); // release all textures - for( i = 0; i < phdr->numtextures; i++ ) + for( int i = 0; i < phdr->numtextures; i++ ) { if( ptexture[i].index == tr.defaultTexture ) continue; diff --git a/ref/gl/gl_triapi.c b/ref/gl/gl_triapi.c index 6f580f0b..1b9748c7 100644 --- a/ref/gl/gl_triapi.c +++ b/ref/gl/gl_triapi.c @@ -222,9 +222,7 @@ convert world coordinates (x,y,z) into screen (x, y) */ int TriWorldToScreen( const float *world, float *screen ) { - int retval; - - retval = R_WorldToScreen( world, screen ); + int retval = R_WorldToScreen( world, screen ); screen[0] = 0.5f * screen[0] * (float)RI.rvp.viewport[2]; screen[1] = -0.5f * screen[1] * (float)RI.rvp.viewport[3]; @@ -243,12 +241,11 @@ bind current texture */ int TriSpriteTexture( model_t *pSpriteModel, int frame ) { - int gl_texturenum; - if( !pSpriteModel || pSpriteModel->type != mod_sprite || !pSpriteModel->cache.data ) return 0; - if(( gl_texturenum = gEngfuncs.R_GetSpriteFrame( pSpriteModel, frame, 0.0f )->gl_texturenum ) == 0 ) + int gl_texturenum = gEngfuncs.R_GetSpriteFrame( pSpriteModel, frame, 0.0f )->gl_texturenum; + if( gl_texturenum == 0 ) return 0; if( gl_texturenum <= 0 || gl_texturenum >= MAX_TEXTURES ) @@ -364,11 +361,9 @@ TriBrightness */ void TriBrightness( float brightness ) { - float r, g, b; - - r = ds.triRGBA[0] * ds.triRGBA[3] * brightness; - g = ds.triRGBA[1] * ds.triRGBA[3] * brightness; - b = ds.triRGBA[2] * ds.triRGBA[3] * brightness; + float r = ds.triRGBA[0] * ds.triRGBA[3] * brightness; + float g = ds.triRGBA[1] * ds.triRGBA[3] * brightness; + float b = ds.triRGBA[2] * ds.triRGBA[3] * brightness; _TriColor4f( r, g, b, 1.0f ); } diff --git a/ref/gl/gl_warp.c b/ref/gl/gl_warp.c index cfa78356..eee773c0 100644 --- a/ref/gl/gl_warp.c +++ b/ref/gl/gl_warp.c @@ -77,20 +77,20 @@ static struct static void DrawSkyPolygon( int nump, vec3_t vecs ) { - int i, j, axis; - float s, t, dv, *vp; - vec3_t v, av; - // decide which face it maps to + vec3_t v; VectorClear( v ); - for( i = 0, vp = vecs; i < nump; i++, vp += 3 ) + float *vp = vecs; + for( int i = 0; i < nump; i++, vp += 3 ) VectorAdd( vp, v, v ); + vec3_t av; av[0] = fabs( v[0] ); av[1] = fabs( v[1] ); av[2] = fabs( v[2] ); + int axis; if( av[0] > av[1] && av[0] > av[2] ) axis = (v[0] < 0) ? 1 : 0; else if( av[1] > av[2] && av[1] > av[0] ) @@ -98,18 +98,18 @@ static void DrawSkyPolygon( int nump, vec3_t vecs ) else axis = (v[2] < 0) ? 5 : 4; // project new texture coords - for( i = 0; i < nump; i++, vecs += 3 ) + for( int i = 0; i < nump; i++, vecs += 3 ) { - j = vec_to_st[axis][2]; - dv = (j > 0) ? vecs[j-1] : -vecs[-j-1]; + int j = vec_to_st[axis][2]; + float dv = (j > 0) ? vecs[j-1] : -vecs[-j-1]; if( dv == 0.0f ) continue; j = vec_to_st[axis][0]; - s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv; + float s = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv; j = vec_to_st[axis][1]; - t = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv; + float t = (j < 0) ? -vecs[-j-1] / dv : vecs[j-1] / dv; if( s < RI.skyMins[0][axis] ) RI.skyMins[0][axis] = s; if( t < RI.skyMins[1][axis] ) RI.skyMins[1][axis] = t; @@ -220,18 +220,17 @@ loc1: static void MakeSkyVec( float s, float t, int axis ) { - int j, k, farclip; - vec3_t v, b; - - farclip = RI.farClip; + int farclip = RI.farClip; + vec3_t b; b[0] = s * (farclip >> 1); b[1] = t * (farclip >> 1); b[2] = (farclip >> 1); - for( j = 0; j < 3; j++ ) + vec3_t v; + for( int j = 0; j < 3; j++ ) { - k = st_to_vec[axis][j]; + int k = st_to_vec[axis][j]; v[j] = (k < 0) ? -b[-k-1] : b[k-1]; v[j] += RI.cullorigin[j]; } @@ -264,9 +263,7 @@ R_ClearSkyBox */ void R_ClearSkyBox( void ) { - int i; - - for( i = 0; i < SKYBOX_MAX_SIDES; i++ ) + for( int i = 0; i < SKYBOX_MAX_SIDES; i++ ) { RI.skyMins[0][i] = RI.skyMins[1][i] = 9999999.0f; RI.skyMaxs[0][i] = RI.skyMaxs[1][i] = -9999999.0f; @@ -280,18 +277,14 @@ R_AddSkyBoxSurface */ void R_AddSkyBoxSurface( msurface_t *fa ) { - vec3_t verts[MAX_CLIP_VERTS]; - glpoly2_t *p; - float *v; - int i; - if( FBitSet( tr.world->flags, FWORLD_SKYSPHERE ) && fa->polys && !FBitSet( tr.world->flags, FWORLD_CUSTOM_SKYBOX )) { - glpoly2_t *p = fa->polys; + glpoly2_t *p = fa->polys; // draw the sky poly pglBegin( GL_POLYGON ); - for( i = 0, v = p->verts[0]; i < p->numverts; i++, v += VERTEXSIZE ) + float *v = p->verts[0]; + for( int i = 0; i < p->numverts; i++, v += VERTEXSIZE ) { pglTexCoord2f( v[3], v[4] ); pglVertex3fv( v ); @@ -300,9 +293,10 @@ void R_AddSkyBoxSurface( msurface_t *fa ) } // calculate vertex values for sky box - for( p = fa->polys; p; p = p->next ) + vec3_t verts[MAX_CLIP_VERTS]; + for( glpoly2_t *p = fa->polys; p; p = p->next ) { - for( i = 0; i < p->numverts; i++ ) + for( int i = 0; i < p->numverts; i++ ) VectorSubtract( p->verts[i], RI.cullorigin, verts[i] ); ClipSkyPolygon( p->numverts, verts[0], 0 ); } @@ -317,10 +311,8 @@ Unload previous skybox */ void R_UnloadSkybox( void ) { - int i; - // release old skybox - for( i = 0; i < SKYBOX_MAX_SIDES; i++ ) + for( int i = 0; i < SKYBOX_MAX_SIDES; i++ ) { if( !tr.skyboxTextures[i] ) continue; GL_FreeTexture( tr.skyboxTextures[i] ); @@ -387,18 +379,16 @@ R_CloudVertex */ static void R_CloudVertex( float s, float t, int axis, vec3_t v ) { - int j, k, farclip; - vec3_t b; - - farclip = RI.farClip; + int farclip = RI.farClip; + vec3_t b; b[0] = s * (farclip >> 1); b[1] = t * (farclip >> 1); b[2] = (farclip >> 1); - for( j = 0; j < 3; j++ ) + for( int j = 0; j < 3; j++ ) { - k = st_to_vec[axis][j]; + int k = st_to_vec[axis][j]; v[j] = (k < 0) ? -b[-k-1] : b[k-1]; v[j] += RI.cullorigin[j]; } @@ -411,16 +401,14 @@ R_CloudTexCoord */ static void R_CloudTexCoord( const vec3_t v, float speed, float *s, float *t ) { - float length, speedscale; - vec3_t dir; - - speedscale = gp_cl->time * speed; + float speedscale = gp_cl->time * speed; speedscale -= (int)speedscale & ~127; + vec3_t dir; VectorSubtract( v, RI.rvp.vieworigin, dir ); dir[2] *= 3.0f; // flatten the sphere - length = VectorLength( dir ); + float length = VectorLength( dir ); length = 6.0f * 63.0f / length; *s = ( speedscale + dir[0] * length ) * (1.0f / 128.0f); @@ -434,16 +422,14 @@ R_CloudDrawPoly */ static void R_CloudDrawPoly( const float *verts ) { - const float *v; - float s, t; - int i; - GL_SetRenderMode( kRenderNormal ); GL_Bind( XASH_TEXTURE0, tr.solidskyTexture ); pglBegin( GL_QUADS ); - for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE ) + const float *v = verts; + for( int i = 0; i < 4; i++, v += VERTEXSIZE ) { + float s, t; R_CloudTexCoord( v, 8.0f, &s, &t ); pglTexCoord2f( s, t ); pglVertex3fv( v ); @@ -454,8 +440,10 @@ static void R_CloudDrawPoly( const float *verts ) GL_Bind( XASH_TEXTURE0, tr.alphaskyTexture ); pglBegin( GL_QUADS ); - for( i = 0, v = verts; i < 4; i++, v += VERTEXSIZE ) + v = verts; + for( int i = 0; i < 4; i++, v += VERTEXSIZE ) { + float s, t; R_CloudTexCoord( v, 16.0f, &s, &t ); pglTexCoord2f( s, t ); pglVertex3fv( v ); @@ -472,29 +460,24 @@ R_CloudRenderSide */ static void R_CloudRenderSide( int axis ) { - vec3_t verts[4]; - float final_verts[4][VERTEXSIZE]; - float di, qi, dj, qj; - vec3_t vup, vright; - vec3_t temp, temp2; - int i, j; - + vec3_t verts[4]; R_CloudVertex( -1.0f, -1.0f, axis, verts[0] ); R_CloudVertex( -1.0f, 1.0f, axis, verts[1] ); R_CloudVertex( 1.0f, 1.0f, axis, verts[2] ); R_CloudVertex( 1.0f, -1.0f, axis, verts[3] ); + vec3_t vup, vright; VectorSubtract( verts[2], verts[3], vup ); VectorSubtract( verts[2], verts[1], vright ); - di = SKYCLOUDS_QUALITY; - qi = 1.0f / di; - dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides - qj = 1.0f / dj; + float di = SKYCLOUDS_QUALITY; + float qi = 1.0f / di; + float dj = (axis < 4) ? di * 2 : di; //subdivide vertically more than horizontally on skybox sides + float qj = 1.0f / dj; - for( i = 0; i < di; i++ ) + for( int i = 0; i < di; i++ ) { - for( j = 0; j < dj; j++ ) + for( int j = 0; j < dj; j++ ) { if( i * qi < RI.skyMins[0][axis] / 2 + 0.5f - qi || i * qi > RI.skyMaxs[0][axis] / 2 + 0.5f @@ -502,9 +485,11 @@ static void R_CloudRenderSide( int axis ) || j * qj > RI.skyMaxs[1][axis] / 2 + 0.5f ) continue; + vec3_t temp, temp2; VectorScale( vright, qi * i, temp ); VectorScale( vup, qj * j, temp2 ); VectorAdd( temp, temp2, temp ); + float final_verts[4][VERTEXSIZE]; VectorAdd( verts[0], temp, final_verts[0] ); VectorScale( vup, qj, temp ); @@ -653,10 +638,6 @@ static void R_GetRippleTextureSize( const texture_t *image, int *width, int *hei qboolean R_UploadRipples( texture_t *image ) { - const gl_texture_t *glt; - const uint32_t *pixels; - int y; - int width, height, size; qboolean update = g_ripple.update; if( !r_ripple.value ) @@ -666,13 +647,14 @@ qboolean R_UploadRipples( texture_t *image ) } // discard unuseful textures - glt = R_GetTexture( image->gl_texturenum ); + const gl_texture_t *glt = R_GetTexture( image->gl_texturenum ); if( !glt || !glt->original || !glt->original->buffer ) { GL_Bind( XASH_TEXTURE0, image->gl_texturenum ); return false; } + int width, height; if( !image->fb_texturenum ) { rgbdata_t pic = { 0 }; @@ -708,15 +690,14 @@ qboolean R_UploadRipples( texture_t *image ) R_GetRippleTextureSize( image, &width, &height ); - size = r_ripple.value == 1.0f ? 64 : RIPPLES_CACHEWIDTH; - pixels = (const uint32_t *)glt->original->buffer; + int size = r_ripple.value == 1.0f ? 64 : RIPPLES_CACHEWIDTH; + const uint32_t *pixels = (const uint32_t *)glt->original->buffer; - for( y = 0; y < height; y++ ) + for( int y = 0; y < height; y++ ) { int ry = (float)y / height * size; - int x; - for( x = 0; x < width; x++ ) + for( int x = 0; x < width; x++ ) { int rx = (float)x / width * size; int val = g_ripple.curbuf[ry * RIPPLES_CACHEWIDTH + rx] / 16; diff --git a/ref/gl/vgl_shim/vgl_shim.c b/ref/gl/vgl_shim/vgl_shim.c index b5b94a1c..9e483d5b 100644 --- a/ref/gl/vgl_shim/vgl_shim.c +++ b/ref/gl/vgl_shim/vgl_shim.c @@ -124,17 +124,15 @@ extern GLboolean fogging; static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type ) { - char *shader, shader_buf[MAX_SHADERLEN + 1]; + char shader_buf[MAX_SHADERLEN + 1]; char tmp[256]; - int i; - GLint status, len; - GLuint id; + GLint status; - shader = shader_buf; + char *shader = shader_buf; shader[0] = '\n'; shader[1] = 0; - for ( i = 0; i < VGL_FLAG_MAX; ++i ) + for ( int i = 0; i < VGL_FLAG_MAX; ++i ) { Q_snprintf( tmp, sizeof( tmp ), "#define %s %d\n", vgl_flag_name[i], prog->flags & ( 1 << i ) ); Q_strncat( shader, tmp, MAX_SHADERLEN ); @@ -145,8 +143,8 @@ static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type ) else Q_strncat( shader, vgl_vert_src, MAX_SHADERLEN ); - id = glCreateShader( type ); - len = Q_strlen( shader ); + GLuint id = glCreateShader( type ); + GLint len = Q_strlen( shader ); glShaderSource( id, 1, (const void *)&shader, &len ); glCompileShader( id ); glGetShaderiv( id, GL_COMPILE_STATUS, &status ); @@ -163,9 +161,7 @@ static GLuint VGL_GenerateShader( const vgl_prog_t *prog, GLenum type ) static vgl_prog_t *VGL_GetProg( const GLuint flags ) { - int i, loc, status; - GLuint vp, fp, glprog; - vgl_prog_t *prog; + int i, status; // try to find existing prog matching this feature set @@ -189,22 +185,22 @@ static vgl_prog_t *VGL_GetProg( const GLuint flags ) // new prog; generate shaders gEngfuncs.Con_DPrintf( S_NOTE "VGL_GetProg(): Generating progs for 0x%04x\n", flags ); - prog = &vgl.progs[i]; + vgl_prog_t *prog = &vgl.progs[i]; prog->flags = flags; - vp = VGL_GenerateShader( prog, GL_VERTEX_SHADER ); - fp = VGL_GenerateShader( prog, GL_FRAGMENT_SHADER ); + GLuint vp = VGL_GenerateShader( prog, GL_VERTEX_SHADER ); + GLuint fp = VGL_GenerateShader( prog, GL_FRAGMENT_SHADER ); if ( !vp || !fp ) { prog->flags = 0; return NULL; } - glprog = glCreateProgram(); + GLuint glprog = glCreateProgram(); glAttachShader( glprog, vp ); glAttachShader( glprog, fp ); - loc = 0; + int loc = 0; for ( i = 0; i < VGL_ATTR_MAX; ++i ) { if ( flags & ( 1 << i ) ) @@ -283,8 +279,7 @@ static vgl_prog_t *VGL_SetProg( const GLuint flags ) int VGL_ShimInit( void ) { - int i; - GLuint total, size; + GLuint total; static const GLuint precache_progs[] = { 0x0001, // out = ucolor 0x0005, // out = tex0 * ucolor @@ -308,9 +303,9 @@ int VGL_ShimInit( void ) vgl.uchanged = GL_TRUE; total = 0; - for ( i = 0; i < VGL_ATTR_MAX; ++i ) + for ( int i = 0; i < VGL_ATTR_MAX; ++i ) { - size = VGL_MAX_VERTS * vgl_attr_size[i] * sizeof( GLfloat ); + GLuint size = VGL_MAX_VERTS * vgl_attr_size[i] * sizeof( GLfloat ); vgl.attrbuf[i] = memalign( 0x100, size ); total += size; } @@ -319,7 +314,7 @@ int VGL_ShimInit( void ) gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): %u bytes allocated for vertex buffer\n", total ); gEngfuncs.Con_DPrintf( S_NOTE "VGL_ShimInit(): Pre-generating %u progs...\n", sizeof( precache_progs ) / sizeof( *precache_progs ) ); - for ( i = 0; i < (int)( sizeof( precache_progs ) / sizeof( *precache_progs ) ); ++i ) + for ( int i = 0; i < (int)( sizeof( precache_progs ) / sizeof( *precache_progs ) ); ++i ) VGL_GetProg( precache_progs[i] ); vgl_init = 1; @@ -328,8 +323,6 @@ int VGL_ShimInit( void ) void VGL_ShimShutdown( void ) { - int i; - if ( !vgl_init ) return; @@ -339,14 +332,14 @@ void VGL_ShimShutdown( void ) /* // FIXME: this sometimes causes the game to block on glDeleteProgram for up to a minute // but since this is only called on shutdown or game change, it should be fine to skip - for ( i = 0; i < MAX_PROGS; ++i ) + for ( int i = 0; i < MAX_PROGS; ++i ) { if ( vgl.progs[i].flags ) glDeleteProgram( vgl.progs[i].glprog ); } */ - for ( i = 0; i < VGL_ATTR_MAX; ++i ) + for ( int i = 0; i < VGL_ATTR_MAX; ++i ) free( vgl.attrbuf[i] ); memset( &vgl, 0, sizeof( vgl ) ); @@ -361,22 +354,20 @@ void VGL_ShimEndFrame( void ) static void VGL_Begin( GLenum prim ) { - int i; vgl.prim = prim; vgl.begin = vgl.end; // pos always enabled vgl.cur_flags = 1 << VGL_ATTR_POS; // disable all vertex attrib pointers - for ( i = 0; i < VGL_ATTR_MAX; ++i ) + for ( int i = 0; i < VGL_ATTR_MAX; ++i ) glDisableVertexAttribArray( i ); } static void VGL_End( void ) { - int i; - vgl_prog_t *prog; GLuint flags = vgl.cur_flags; - GLint count = vgl.end - vgl.begin; + const GLint count = vgl.end - vgl.begin; + const vgl_prog_t *prog; if ( !vgl.prim || !count ) goto _leave; // end without begin @@ -394,7 +385,7 @@ static void VGL_End( void ) goto _leave; } - for ( i = 0; i < VGL_ATTR_MAX; ++i ) + for ( int i = 0; i < VGL_ATTR_MAX; ++i ) { if ( prog->attridx[i] >= 0 ) {