]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/image.cpp
radiant: replace StringBuffer with std::string
[xonotic/netradiant.git] / radiant / image.cpp
index 7495db68a2d0f8ca44e5cdb1636cd85b690f5cfd..9d74d348fd637ebdfb16b578fddf335213fcdd94 100644 (file)
@@ -1,23 +1,23 @@
 /*
-Copyright (C) 2001-2006, William Joseph.
-All Rights Reserved.
+   Copyright (C) 2001-2006, William Joseph.
+   All Rights Reserved.
 
-This file is part of GtkRadiant.
+   This file is part of GtkRadiant.
 
-GtkRadiant is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
+   GtkRadiant is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2 of the License, or
+   (at your option) any later version.
 
-GtkRadiant is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
+   GtkRadiant is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-You should have received a copy of the GNU General Public License
-along with GtkRadiant; if not, write to the Free Software
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
+   You should have received a copy of the GNU General Public License
+   along with GtkRadiant; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ */
 
 #include "image.h"
 
@@ -30,41 +30,54 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include "os/path.h"
 #include "stream/stringstream.h"
 
-
 typedef Modules<_QERPlugImageTable> ImageModules;
 ImageModules& Textures_getImageModules();
+ImageModules& Textures_getFallbackImageModules();
 
 /// \brief Returns a new image for the first file matching \p name in one of the available texture formats, or 0 if no file is found.
-Image* QERApp_LoadImage(void* environment, const char* name)
-{
-  Image* image = 0;
-  class LoadImageVisitor : public ImageModules::Visitor
-  {
-    const char* m_name;
-    Image*& m_image;
-  public:
-    LoadImageVisitor(const char* name, Image*& image)
-      : m_name(name), m_image(image)
-    {
-    }
-    void visit(const char* name, const _QERPlugImageTable& table) const
-    {
-      if(m_image == 0)
-      {
-        StringOutputStream fullname(256);
-        fullname << m_name << '.' << name;
-        ArchiveFile* file = GlobalFileSystem().openFile(fullname.c_str());
-        if(file != 0)
-        {
-          m_image = table.loadImage(*file);
-          file->release();
-        }
-      }
-    }
-  };
+Image* QERApp_LoadImage( void* environment, const char* name ){
+       Image* image = 0;
+       class LoadImageVisitor : public ImageModules::Visitor
+       {
+       const char* m_name;
+       Image*& m_image;
+public:
+       LoadImageVisitor( const char* name, Image*& image )
+               : m_name( name ), m_image( image ){
+       }
+       void visit( const char* name, const _QERPlugImageTable& table ) const {
+               if ( m_image == 0 ) {
+                       StringOutputStream fullname( 256 );
+                       fullname << m_name << '.' << name;
+                       ArchiveFile* file = GlobalFileSystem().openFile( fullname.c_str() );
 
-  Textures_getImageModules().foreachModule(LoadImageVisitor(name, image));
+                       // also look for .dds image in dds/ prefix like Doom3 or DarkPlaces
+                       if ( file == 0 && !string_compare( name, "dds" ) )
+                       {
+                               fullname.clear();
+                               fullname << name << '/' << m_name << '.' << name;
+                               file = GlobalFileSystem().openFile( fullname.c_str() );
+                       }
 
-  return image;
-}
+                       if ( file != 0 ) {
+                               // tell user which image file is found for the given texture path
+                               globalOutputStream() << "Found image file: " << makeQuoted( fullname.c_str() ) << "\n";
+
+                               m_image = table.loadImage( *file );
+                               file->release();
+                       }
+               }
+       }
+       };
 
+       Textures_getImageModules().foreachModule( LoadImageVisitor( name, image ) );
+
+       // Games can provide their own fallback, so only do this when previous
+       // loading attempt did not work.
+       if ( image == 0 && !!string_compare_nocase( name, "textures/radiant" ) )
+       {
+               Textures_getFallbackImageModules().foreachModule( LoadImageVisitor( name, image ) );
+       }
+
+       return image;
+}