mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-20 01:04:59 +01:00
fix(files): the banks keep the names asked for, only the opening takes the case of the disk
The textures, materials and sounds are kept by the names they're asked for. Given back as named on the disk, a file in another case missed the bank and was loaded again on every request. - FileExists with names and extensions finds the file in any case but gives back the name asked for; FileOnDisk gives the file to open, used where textures, sounds and scripts are opened - FileExists of a single name is a plain check again, the places checking it and opening the same name stay as they were - the texture format is told by the extension asked for again - a folder changed shortly before it was read is read again for a name missing from it, the time of a change being as coarse as the clock of the file system; a listing cut short isn't kept
This commit is contained in:
@@ -549,15 +549,13 @@ opengl_texture::load() {
|
||||
|
||||
data_state = resource_state::loading;
|
||||
|
||||
// the extension as the file has it on the disk, in any case
|
||||
auto const format { ToLower( type ) };
|
||||
if( format == ".dds" ) { load_DDS(); }
|
||||
else if( format == ".tga" ) { load_TGA(); }
|
||||
else if( format == ".png" ) { load_STBI(); }
|
||||
else if( format == ".ktx" ) { load_KTX(); }
|
||||
else if( format == ".bmp" ) { load_STBI(); }
|
||||
else if( format == ".jpg" ) { load_STBI(); }
|
||||
else if( format == ".tex" ) { load_TEX(); }
|
||||
if( type == ".dds" ) { load_DDS(); }
|
||||
else if( type == ".tga" ) { load_TGA(); }
|
||||
else if( type == ".png" ) { load_STBI(); }
|
||||
else if( type == ".ktx" ) { load_KTX(); }
|
||||
else if( type == ".bmp" ) { load_STBI(); }
|
||||
else if( type == ".jpg" ) { load_STBI(); }
|
||||
else if( type == ".tex" ) { load_TEX(); }
|
||||
else { goto fail; }
|
||||
}
|
||||
|
||||
@@ -642,7 +640,7 @@ void opengl_texture::load_STBI()
|
||||
{
|
||||
int x, y, n;
|
||||
stbi_set_flip_vertically_on_load(1);
|
||||
uint8_t *image = stbi_load((name + type).c_str(), &x, &y, &n, 4);
|
||||
uint8_t *image = stbi_load(FileOnDisk(name + type).c_str(), &x, &y, &n, 4);
|
||||
|
||||
if (!image) {
|
||||
data_state = resource_state::failed;
|
||||
@@ -820,7 +818,7 @@ DDSURFACEDESC2 opengl_texture::deserialize_ddsd(std::istream &s)
|
||||
void
|
||||
opengl_texture::load_DDS() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::size_t filesize = static_cast<size_t>(file.tellg()); // ios::ate already positioned us at the end of the file
|
||||
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||
|
||||
@@ -940,7 +938,7 @@ opengl_texture::load_DDS() {
|
||||
if( true == Global.gfx_texture_streaming ) {
|
||||
// the data is read by a worker thread, everything else about the texture is known already
|
||||
request = std::make_shared<texture_request>();
|
||||
request->file = name + type;
|
||||
request->file = FileOnDisk( name + type );
|
||||
request->offset = static_cast<std::size_t>( file.tellg() ) + offset;
|
||||
request->size = datasize;
|
||||
request->flip = flip;
|
||||
@@ -1002,7 +1000,7 @@ opengl_texture::load_DDS() {
|
||||
|
||||
void
|
||||
opengl_texture::load_KTX() {
|
||||
std::ifstream file( name + type, std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary | std::ios::ate ); file.unsetf( std::ios::skipws );
|
||||
std::size_t filesize = static_cast<size_t>(file.tellg()); // ios::ate already positioned us at the end of the file
|
||||
file.seekg( 0, std::ios::beg ); // rewind the caret afterwards
|
||||
|
||||
@@ -1063,7 +1061,7 @@ opengl_texture::load_KTX() {
|
||||
void
|
||||
opengl_texture::load_TEX() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
|
||||
char head[ 5 ];
|
||||
file.read( head, 4 );
|
||||
@@ -1110,7 +1108,7 @@ opengl_texture::load_TEX() {
|
||||
void
|
||||
opengl_texture::load_TGA() {
|
||||
|
||||
std::ifstream file( name + type, std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
std::ifstream file( FileOnDisk( name + type ), std::ios::binary ); file.unsetf( std::ios::skipws );
|
||||
|
||||
// Read the header of the TGA, compare it with the known headers for compressed and uncompressed TGAs
|
||||
unsigned char tgaheader[ 18 ];
|
||||
|
||||
Reference in New Issue
Block a user