Concat all found shaderlist.txt files to build the shader list
authorJānis Rūcis <parasti@gmail.com>
Sat, 29 May 2010 17:43:37 +0000 (20:43 +0300)
committerJānis Rūcis <parasti@gmail.com>
Sat, 29 May 2010 21:09:35 +0000 (00:09 +0300)
include/ifilesystem.h
plugins/shaders/shaders.cpp
plugins/vfspk3/vfs.cpp

index 339c82f..ed9e99f 100644 (file)
@@ -98,8 +98,8 @@ public:
   /// \brief Detach an \p observer previously-attached by calling \c attach.
   virtual void detach(ModuleObserver& observer) = 0;
 
-  virtual Archive* getArchive(const char* archiveName) = 0;
-  virtual void forEachArchive(const ArchiveNameCallback& callback) = 0;
+  virtual Archive* getArchive(const char* archiveName, bool pakonly=true) = 0;
+  virtual void forEachArchive(const ArchiveNameCallback& callback, bool pakonly=true, bool reverse=false) = 0;
 };
 
 #include "modulesystem.h"
index e95adaf..202a817 100644 (file)
@@ -1768,9 +1768,9 @@ void IfFound_dumpUnreferencedShader(bool& bFound, const char* filename)
     if(!bFound)
     {
       bFound = true;
-      globalOutputStream() << "Following shader files are not referenced in shaderlist.txt:\n";
+      globalOutputStream() << "Following shader files are not referenced in any shaderlist.txt:\n";
     }
-    globalOutputStream() << filename << "\n";
+    globalOutputStream() << "\t" << filename << "\n";
   }
 }
 typedef ReferenceCaller1<bool, const char*, IfFound_dumpUnreferencedShader> IfFoundDumpUnreferencedShaderCaller;
@@ -1840,6 +1840,30 @@ void FreeShaderList()
   }
 }
 
+void ShaderList_addFromArchive(const char *archivename)
+{
+  const char *shaderpath = GlobalRadiant().getGameDescriptionKeyValue("shaderpath");
+  if (string_empty(shaderpath))
+    return;
+
+  StringOutputStream shaderlist(256);
+  shaderlist << DirectoryCleaned(shaderpath) << "shaderlist.txt";
+
+  Archive *archive = GlobalFileSystem().getArchive(archivename, false);
+  if (archive)
+  {
+    ArchiveTextFile *file = archive->openTextFile(shaderlist.c_str());
+    if (file)
+    {
+      globalOutputStream() << "Found shaderlist.txt in " << archivename << "\n";
+      BuildShaderList(file->getInputStream());
+      file->release();
+    }
+  }
+}
+
+typedef FreeCaller1<const char *, ShaderList_addFromArchive> AddShaderListFromArchiveCaller;
+
 #include "stream/filestream.h"
 
 bool shaderlist_findOrInstall(const char* enginePath, const char* toolsPath, const char* shaderPath, const char* gamename)
@@ -1898,22 +1922,8 @@ void Shaders_Load()
         shaderlist_findOrInstall(enginePath, toolsPath, path.c_str(), gamename);
       }
 
-      StringOutputStream absShaderList(256);
-      absShaderList << enginePath << gamename << '/' << path.c_str() << "shaderlist.txt";
-
-      {
-        globalOutputStream() << "Parsing shader files from " << absShaderList.c_str() << "\n";
-        TextFileInputStream shaderlistFile(absShaderList.c_str());
-        if(shaderlistFile.failed())
-        {
-          globalErrorStream() << "Couldn't find '" << absShaderList.c_str() << "'\n";
-        }
-        else
-        {
-          BuildShaderList(shaderlistFile);
-          DumpUnreferencedShaders();
-        }
-      }
+      GlobalFileSystem().forEachArchive(AddShaderListFromArchiveCaller(), false, true);
+      DumpUnreferencedShaders();
     }
     else
     {
index 6220f77..8b52b53 100644 (file)
@@ -661,29 +661,33 @@ public:
     g_observers.detach(observer);
   }
 
-  Archive* getArchive(const char* archiveName)
+  Archive* getArchive(const char* archiveName, bool pakonly)
   {
     for(archives_t::iterator i = g_archives.begin(); i != g_archives.end(); ++i)
     {
-      if((*i).is_pakfile)
-      {
-        if(path_equal((*i).name.c_str(), archiveName))
-        {
-          return (*i).archive;
-        }
-      }
+      if(pakonly && !(*i).is_pakfile)
+        continue;
+
+      if(path_equal((*i).name.c_str(), archiveName))
+        return (*i).archive;
     }
     return 0;
   }
-  void forEachArchive(const ArchiveNameCallback& callback)
+  void forEachArchive(const ArchiveNameCallback& callback, bool pakonly, bool reverse)
   {
+    if (reverse)
+      g_archives.reverse();
+
     for(archives_t::iterator i = g_archives.begin(); i != g_archives.end(); ++i)
     {
-      if((*i).is_pakfile)
-      {
-        callback((*i).name.c_str());
-      }
+      if(pakonly && !(*i).is_pakfile)
+        continue;
+
+      callback((*i).name.c_str());
     }
+
+    if (reverse)
+      g_archives.reverse();
   }
 };