Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/common/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,27 @@ std::string Build(Str::StringRef base, Str::StringRef path)
return out;
}

std::string NormalizeSlashes(Str::StringRef path)
{
std::string out;
out.reserve(path.size());
bool lastSlash = true;

for (char c : path) {
if (c == '/' || c == '\\') {
if (!lastSlash) {
lastSlash = true;
out.push_back('/');
}
} else {
out.push_back( c );
lastSlash = false;
}
}

return out;
}

std::string DirName(Str::StringRef path)
{
if (path.empty())
Expand Down
5 changes: 5 additions & 0 deletions src/common/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ namespace Path {
// Build a path from components
std::string Build(Str::StringRef base, Str::StringRef path);

// Replace \ with /
// Remove multiple consecutive slashes
// Remove initial slashes
std::string NormalizeSlashes(Str::StringRef path);

// Get the directory portion of a path:
// a/b/c => a/b
// a/b/ => a
Expand Down
19 changes: 8 additions & 11 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ unsigned int GenerateImageHashValue( const char *fname )
{
letter = Str::ctolower( fname[ i ] );

if ( letter == '\\' )
{
letter = '/'; // damn path names
}

hash += ( unsigned )( letter ) * ( i + 119 );
i++;
}
Expand Down Expand Up @@ -1823,19 +1818,21 @@ Finds or loads the given image.
Returns nullptr if it fails, not a default image.
==============
*/
image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
image_t *R_FindImageFile( const char *imageName0, imageParams_t &imageParams )
{
if ( !imageName )
if ( !imageName0 )
{
return nullptr;
}

unsigned hash = GenerateImageHashValue( imageName );
std::string imageName = FS::Path::NormalizeSlashes( imageName0 );

unsigned hash = GenerateImageHashValue( imageName.c_str() );

// See if the image is already loaded.
for ( image_t *image = r_imageHashTable[ hash ]; image; image = image->next )
{
if ( !Q_strnicmp( imageName, image->name, sizeof( image->name ) ) )
if ( Str::IsIEqual( imageName, image->name ) )
{
if ( imageParams == image->initialParams || r_allowImageParamMismatch.Get() )
{
Expand Down Expand Up @@ -1894,7 +1891,7 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
byte *pic[ MAX_TEXTURE_MIPS * MAX_TEXTURE_LAYERS ];
pic[ 0 ] = nullptr;

R_LoadImage( imageName, pic, &width, &height, &numLayers, &numMips, &imageParams.bits );
R_LoadImage( imageName.c_str(), pic, &width, &height, &numLayers, &numMips, &imageParams.bits);

if ( *pic )
{
Expand All @@ -1914,7 +1911,7 @@ image_t *R_FindImageFile( const char *imageName, imageParams_t &imageParams )
R_ProcessLightmap( *pic, width, height, imageParams.bits );
}

image_t *image = R_CreateImage( imageName, (const byte **)pic, width, height, numMips, imageParams );
image_t *image = R_CreateImage( imageName.c_str(), (const byte**)pic, width, height, numMips, imageParams);
image->initialParams = initialParams;

Z_Free( *pic );
Expand Down
15 changes: 3 additions & 12 deletions src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,7 @@ static unsigned int generateHashValue( const char *fname, const int size )

if ( letter == '.' )
{
break; // don't include extension
}

if ( letter == '\\' )
{
letter = '/'; // damn path names
}

if ( letter == PATH_SEP )
{
letter = '/'; // damn path names
break; // don't include extension. FIXME: could have multiple dots
}

hash += ( unsigned )( letter ) * ( i + 119 );
Expand Down Expand Up @@ -6247,7 +6237,8 @@ shader_t *R_FindShader( const char *name, int flags )
return tr.defaultShader;
}

COM_StripExtension3( name, strippedName, sizeof( strippedName ) );
COM_StripExtension3( FS::Path::NormalizeSlashes( name ).c_str(),
strippedName, sizeof( strippedName ) );

hash = generateHashValue( strippedName, FILE_HASH_SIZE );

Expand Down
Loading