//=========================================================================== // // Parameter: - // Returns: - // Changes Globals: - //=========================================================================== int FindMiptex (char *name) { int i; char path[1024]; miptex_t *mt; for (i = 0; i < nummiptex; i++) { if (!strcmp (name, textureref[i].name)) { return i; } //end if } //end for if (nummiptex == MAX_MAP_TEXTURES) Error ("MAX_MAP_TEXTURES"); strcpy (textureref[i].name, name); // load the miptex to get the flags and values sprintf (path, "%stextures/%s.wal", gamedir, name); if (TryLoadFile (path, (void **)&mt) != -1) { textureref[i].value = LittleLong (mt->value); textureref[i].flags = LittleLong (mt->flags); textureref[i].contents = LittleLong (mt->contents); strcpy (textureref[i].animname, mt->animname); FreeMemory(mt); } //end if nummiptex++; if (textureref[i].animname[0]) FindMiptex (textureref[i].animname); return i; } //end of the function FindMipTex
BEGIN_INANITY ptr<File> FileSystem::LoadFile(const String& fileName) { ptr<File> file = TryLoadFile(fileName); if(file) return file; THROW("Can't load file " + fileName); }
/* ====================== CalcTextureReflectivity_Quake2 ====================== */ void CalcTextureReflectivity_Quake2( void ){ int i; int j, k, texels; int color[3]; int texel; byte *palette; char path[1024]; float r, scale; miptex_t *mt; sprintf( path, "%spics/colormap.pcx", gamedir ); // get the game palette Load256Image( path, NULL, &palette, NULL, NULL ); // allways set index 0 even if no textures texture_reflectivity[0][0] = 0.5; texture_reflectivity[0][1] = 0.5; texture_reflectivity[0][2] = 0.5; for ( i = 0 ; i < numtexinfo ; i++ ) { // see if an earlier texinfo allready got the value for ( j = 0 ; j < i ; j++ ) { if ( !strcmp( texinfo[i].texture, texinfo[j].texture ) ) { VectorCopy( texture_reflectivity[j], texture_reflectivity[i] ); break; } } if ( j != i ) { continue; } // load the wal file sprintf( path, "%stextures/%s.wal", gamedir, texinfo[i].texture ); if ( TryLoadFile( path, (void **)&mt ) == -1 ) { Sys_Printf( "Couldn't load %s\n", path ); texture_reflectivity[i][0] = 0.5; texture_reflectivity[i][1] = 0.5; texture_reflectivity[i][2] = 0.5; continue; } texels = LittleLong( mt->width ) * LittleLong( mt->height ); color[0] = color[1] = color[2] = 0; for ( j = 0 ; j < texels ; j++ ) { texel = ( (byte *)mt )[LittleLong( mt->offsets[0] ) + j]; for ( k = 0 ; k < 3 ; k++ ) color[k] += palette[texel * 3 + k]; } for ( j = 0 ; j < 3 ; j++ ) { r = color[j] / texels / 255.0; texture_reflectivity[i][j] = r; } // scale the reflectivity up, because the textures are // so dim scale = ColorNormalize( texture_reflectivity[i], texture_reflectivity[i] ); if ( scale < 0.5 ) { scale *= 2; VectorScale( texture_reflectivity[i], scale, texture_reflectivity[i] ); } #if 0 texture_reflectivity[i][0] = 0.5; texture_reflectivity[i][1] = 0.5; texture_reflectivity[i][2] = 0.5; #endif } }
/* ====================== CalcTextureReflectivity_Heretic2 ====================== */ void CalcTextureReflectivity_Heretic2( void ){ int i; int j, texels; int color[3]; int texel; char path[1024]; float r; miptex_m8_t *mt; miptex_m32_t *mt32; byte *pos; // allways set index 0 even if no textures texture_reflectivity[0][0] = 0.5; texture_reflectivity[0][1] = 0.5; texture_reflectivity[0][2] = 0.5; for ( i = 0 ; i < numtexinfo ; i++ ) { // see if an earlier texinfo allready got the value for ( j = 0 ; j < i ; j++ ) { if ( !strcmp( texinfo[i].texture, texinfo[j].texture ) ) { VectorCopy( texture_reflectivity[j], texture_reflectivity[i] ); break; } } if ( j != i ) { continue; } // load the wal file sprintf( path, "%stextures/%s.m32", gamedir, texinfo[i].texture ); if ( TryLoadFile( path, (void **)&mt32 ) == -1 ) { sprintf( path, "%stextures/%s.m8", gamedir, texinfo[i].texture ); if ( TryLoadFile( path, (void **)&mt ) == -1 ) { Sys_Printf( "Couldn't load %s\n", path ); texture_reflectivity[i][0] = 0.5; texture_reflectivity[i][1] = 0.5; texture_reflectivity[i][2] = 0.5; continue; } texels = LittleLong( mt->width[0] ) * LittleLong( mt->height[0] ); color[0] = color[1] = color[2] = 0; for ( j = 0 ; j < texels ; j++ ) { texel = ( (byte *)mt )[LittleLong( mt->offsets[0] ) + j]; color[0] += mt->palette[texel].r; color[1] += mt->palette[texel].g; color[2] += mt->palette[texel].b; } free( mt ); } else { texels = LittleLong( mt32->width[0] ) * LittleLong( mt32->height[0] ); color[0] = color[1] = color[2] = 0; for ( j = 0 ; j < texels ; j++ ) { pos = (byte *)mt32 + mt32->offsets[0] + ( j << 2 ); color[0] += *pos++; // r color[1] += *pos++; // g color[2] += *pos++; // b } free( mt32 ); } for ( j = 0 ; j < 3 ; j++ ) { r = color[j] / ( (float) texels * 255.0 ); texture_reflectivity[i][j] = r; } } }