Browse Source

added the ability to specify resources to include by folder (as opposed to only per file)

Eugene 9 years ago
parent
commit
ce741498fd

+ 9 - 4
Source/ToolCore/Build/BuildAndroid.cpp

@@ -31,6 +31,7 @@
 #include "../Project/Project.h"
 #include "../Project/ProjectBuildSettings.h"
 #include "../Platform/PlatformAndroid.h"
+#include "../Assets/AssetDatabase.h"
 
 #include "AndroidProjectGenerator.h"
 
@@ -286,18 +287,22 @@ void BuildAndroid::Initialize()
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
-    String projectResources = project->GetResourcePath();
+    
 
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
+    BuildDefaultResourceEntries();
 
     // TODO: smart filtering of cache
-    AddResourceDir(project->GetProjectPath() + "Cache/");
-    AddResourceDir(projectResources);
+    String projectResources = project->GetResourcePath();
+    AddProjectResourceDir(projectResources);
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    AddProjectResourceDir(cachePath);
 
-    BuildDefaultResourceEntries();
+    BuildProjectResourceEntries();
 }
 
 void BuildAndroid::Build(const String& buildPath)

+ 58 - 44
Source/ToolCore/Build/BuildBase.cpp

@@ -22,14 +22,13 @@
 
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/FileSystem.h>
-#include <Atomic/Resource/JSONFile.h> // EGS:
-
+#include <Atomic/Resource/JSONFile.h>
 
 #include "../Subprocess/SubprocessSystem.h"
 #include "../Project/Project.h"
 #include "../ToolEnvironment.h"
-#include "../Assets/Asset.h" // EGS:
-
+#include "../Assets/Asset.h"
+#include "../Assets/AssetDatabase.h"
 
 #include "BuildSystem.h"
 #include "BuildEvents.h"
@@ -349,14 +348,14 @@ void BuildBase::BuildFilteredProjectResourceEntries()
     // obtaining a list of files to include in the build.
     VariantMap resourceTags;
     AssetBuildConfig::ApplyConfig(resourceTags);
-    Vector<String> resourceFilesToInclude;
+    Vector<String> assetBuildConfigFiles;
     VariantMap::ConstIterator itr = resourceTags.Begin();
 
     while (itr != resourceTags.End())
     {
         if (itr->first_ == assetBuildTag_)
         {
-            resourceFilesToInclude = itr->second_.GetStringVector();
+            assetBuildConfigFiles = itr->second_.GetStringVector();
             break;
         }
         
@@ -367,57 +366,63 @@ void BuildBase::BuildFilteredProjectResourceEntries()
         }
     }
 
-    // check if the files in assetbuildconfig.json exist,
-    // as well as their corresponding .asset file
-    Vector<String> filesInResourceFolder;
+    // find any folders defined in assetbuildconfig.json, and add the non-".asset" files in them.
     FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    fileSystem->ScanDir(filesInResourceFolder, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
-
-    Vector<String> filesToAdd;
-    Vector<String> filesToRemove;
-    for (unsigned i = 0; i < resourceFilesToInclude.Size(); ++i)
+    Vector<String> filesInFolderToAdd;
+    
+    for (unsigned i = 0; i < assetBuildConfigFiles.Size(); ++i)
     {
-        // .asset file is of primary importance since we used it to identify the associated cached file.
-        // without the .asset file the resource becomes redundant.
-        String &filename = resourceFilesToInclude[i];
-        if (!filesInResourceFolder.Contains(filename + ".asset"))
+        String &filename = assetBuildConfigFiles[i];
+        if (GetExtension(filename) == String::EMPTY &&
+            fileSystem->DirExists(project_->GetResourcePath() + filename))
         {
-            BuildWarn(ToString("BuildBase::BuildFilteredProjectResourceEntries - File \"%s\" associated .asset file not found in the Resources folder.\nRemoving \"%s\" from build pakcage", filename.CString()));
-            if (filesInResourceFolder.Contains(filename))
+            Vector<String> filesInFolder;
+            fileSystem->ScanDir(filesInFolder, project_->GetResourcePath() + filename, "*.*", SCAN_FILES, true);
+            for (unsigned j = 0; j < filesInFolder.Size(); ++j)
             {
-                filesToRemove.Push(filename);
-                continue;
+                if (GetExtension(filesInFolder[j]) != ".asset")
+                    filesInFolderToAdd.Push(filesInFolder[j]);
             }
         }
-        filesToAdd.Push(filename + ".asset");
     }
 
-    // remove files not to include
-    for (unsigned i = 0; i < filesToRemove.Size(); ++i)
+    // add the files defined using a folder in assetbuildconfig.json
+    for (unsigned i = 0; i < filesInFolderToAdd.Size(); ++i)
     {
-        String &filename = filesToRemove[i];
-        if (resourceFilesToInclude.Contains(filename))
-        {
-            resourceFilesToInclude.Remove(filename);
-        }
+        assetBuildConfigFiles.Push(filesInFolderToAdd[i]);
     }
 
-    // add files to include
-    for (unsigned i = 0; i < filesToAdd.Size(); ++i)
+    // check if the files in assetbuildconfig.json exist,
+    // as well as their corresponding .asset file
+    Vector<String> filesInResourceFolder;
+    Vector<String> resourceFilesToInclude;
+    fileSystem->ScanDir(filesInResourceFolder, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
+
+    for (unsigned i = 0; i < assetBuildConfigFiles.Size(); ++i)
     {
-        String &filename = filesToAdd[i];
-        if (!resourceFilesToInclude.Contains(filename))
+        // .asset file is of primary importance since we used it to identify the associated cached file.
+        // without the .asset file the resource is removed from being included in the build.
+        String &filename = assetBuildConfigFiles[i];
+        if (filesInResourceFolder.Contains(filename) &&
+            filesInResourceFolder.Contains(filename + ".asset"))
         {
             resourceFilesToInclude.Push(filename);
+            resourceFilesToInclude.Push(filename + ".asset");
         }
     }
 
+    // add valid files included from the assetbuildconfig.json
+    for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
+    {
+        AddToResourcePackager(*it, project_->GetResourcePath());
+    }
+
     // Get associated cache GUID from the asset file
     Vector<String> filesWithGUIDtoInclude;
+
     for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
     {
         String &filename = *it;
-        
         if (GetExtension(*it) == ".asset")
         {
             SharedPtr<File> file(new File(context_, project_->GetResourcePath() + *it));
@@ -434,35 +439,44 @@ void BuildBase::BuildFilteredProjectResourceEntries()
         }
     }
     
-    // obtain files in cache folder,
-    // check if the file contains the guid, and add it to the resourceFilesToInclude
+    // Obtain files in cache folder,
+    // Check if the file contains the guid, and add it to the resourceFilesToInclude
     Vector<String> filesInCacheFolder;
     Vector<String> cacheFilesToInclude;
-    fileSystem->ScanDir(filesInCacheFolder, project_->GetProjectPath() + "Cache/", "*.*", SCAN_FILES, true);
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    fileSystem->ScanDir(filesInCacheFolder, cachePath, "*.*", SCAN_FILES, true);
 
-    for (unsigned i = 0; i < filesWithGUIDtoInclude.Size(); i++)
+    for (unsigned i = 0; i < filesWithGUIDtoInclude.Size(); ++i)
     {
         String &guid = filesWithGUIDtoInclude[i];
-        for (unsigned j = 0; j < filesInCacheFolder.Size(); j++)
+        for (unsigned j = 0; j < filesInCacheFolder.Size(); ++j)
         {
             String &filename = GetFileName(filesInCacheFolder[j]);
             if (filename.Contains(guid))
             {
                 cacheFilesToInclude.Push(filesInCacheFolder[j]);
                 // do not continue...
-                // there might be multiple files with the same guid
+                // there might be multiple files with the same guid having an guid_animaiton extention.
             }
         }
     }
 
-    for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
+    // Add the DDS files when building in windows
+#ifdef ATOMIC_PLATFORM_DESKTOP
+    Vector<String> filesInCacheDDSfolder;
+    fileSystem->ScanDir(filesInCacheDDSfolder, cachePath + "DDS/", "*.dds", SCAN_FILES, true);
+
+    for (unsigned i = 0; i < filesInCacheDDSfolder.Size(); ++i)
     {
-        AddToResourcePackager(*it, project_->GetResourcePath());
+        cacheFilesToInclude.Push(filesInCacheDDSfolder[i]);
     }
+#endif
 
+    // Add the cache files to the resource packager
     for (auto it = cacheFilesToInclude.Begin(); it != cacheFilesToInclude.End(); ++it)
     {
-        AddToResourcePackager(*it, project_->GetProjectPath() + "Cache/");
+        AddToResourcePackager(*it, cachePath);
     }
 }
 

+ 0 - 1
Source/ToolCore/Build/BuildBase.h

@@ -99,7 +99,6 @@ protected:
 private:
     void BuildFilteredProjectResourceEntries();
     void BuildAllProjectResourceEntries();
-    
 
     PlatformID platformID_;
 

+ 9 - 5
Source/ToolCore/Build/BuildIOS.cpp

@@ -28,6 +28,7 @@
 #include "../ToolEnvironment.h"
 #include "../Project/Project.h"
 #include "../Project/ProjectBuildSettings.h"
+#include "../Assets/AssetDatabase.h"
 
 #include "../Subprocess/SubprocessSystem.h"
 
@@ -149,19 +150,22 @@ void BuildIOS::Initialize()
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
-    String projectResources = project->GetResourcePath();
+    
 
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
+    BuildDefaultResourceEntries();
 
     // TODO: smart filtering of cache
-    AddResourceDir(project->GetProjectPath() + "Cache/");
-    AddResourceDir(projectResources);
-
-    BuildDefaultResourceEntries();
+    String projectResources = project->GetResourcePath();
+    AddProjectResourceDir(projectResources);
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    AddProjectResourceDir(cachePath);
 
+    BuildProjectResourceEntries();
 }
 
 void BuildIOS::RunConvertPList()

+ 8 - 5
Source/ToolCore/Build/BuildMac.cpp

@@ -53,19 +53,22 @@ void BuildMac::Initialize()
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
-    String projectResources = project->GetResourcePath();
+    
 
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
+    BuildDefaultResourceEntries();
 
     // TODO: smart filtering of cache
-    AddResourceDir(project->GetProjectPath() + "Cache/");
-    AddResourceDir(projectResources);
-
-    BuildDefaultResourceEntries();
+    String projectResources = project->GetResourcePath();
+    AddProjectResourceDir(projectResources);
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    AddProjectResourceDir(cachePath);
 
+    BuildProjectResourceEntries();
 }
 
 bool BuildMac::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)

+ 9 - 4
Source/ToolCore/Build/BuildWeb.cpp

@@ -28,6 +28,7 @@
 #include "../ToolSystem.h"
 #include "../ToolEnvironment.h"
 #include "../Project/Project.h"
+#include "../Assets/AssetDatabase.h"
 
 #include "BuildEvents.h"
 #include "BuildSystem.h"
@@ -54,19 +55,23 @@ void BuildWeb::Initialize()
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
-    String projectResources = project->GetResourcePath();
 
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
+    BuildDefaultResourceEntries();
 
     // TODO: smart filtering of cache
-    AddResourceDir(project->GetProjectPath() + "Cache/");
-    AddResourceDir(projectResources);
+    String projectResources = project->GetResourcePath();
+    AddProjectResourceDir(projectResources);
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    AddProjectResourceDir(cachePath);
 
-    BuildDefaultResourceEntries();
+    BuildProjectResourceEntries();
 }
+
 void BuildWeb::Build(const String& buildPath)
 {
     ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();

+ 5 - 5
Source/ToolCore/Build/BuildWindows.cpp

@@ -60,9 +60,12 @@ void BuildWindows::Initialize()
     }
     BuildDefaultResourceEntries();
     
-    // EGS: Build the project resources and cache
+    // Include the project resources and cache separately
     AddProjectResourceDir(project->GetProjectPath());
-    AddProjectResourceDir(project->GetProjectPath() + "Cache/");
+    AssetDatabase* db = GetSubsystem<AssetDatabase>();
+    String cachePath = db->GetCachePath();
+    AddProjectResourceDir(cachePath);
+
     BuildProjectResourceEntries();
 }
 
@@ -149,9 +152,6 @@ void BuildWindows::BuildAtomicNET()
         SplitPath(results[i], pathName, fileName, ext);
         fileSystem->Copy(assembliesPath + results[i], ToString("%s/AtomicPlayer_Resources/AtomicNET/Atomic/Assemblies/%s.dll", buildPath_.CString(), fileName.CString()));
     }
-
-
-
 }
 
 void BuildWindows::Build(const String& buildPath)