#include "os/path.h"
#include "stream/stringstream.h"
-
typedef Modules<_QERPlugImageTable> ImageModules;
-
-ImageModules &Textures_getImageModules();
+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)
- {
- }
+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();
+ }
+ }
+ }
+ };
- 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();
- }
- }
- }
- };
+ Textures_getImageModules().foreachModule( LoadImageVisitor( name, image ) );
- 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;
+ return image;
}