浏览代码

More android fixes

Panagiotis Christopoulos Charitos 4 年之前
父节点
当前提交
ce3df8b283
共有 3 个文件被更改,包括 43 次插入56 次删除
  1. 36 50
      AnKi/Resource/ResourceFilesystem.cpp
  2. 4 6
      AnKi/Resource/ResourceFilesystem.h
  3. 3 0
      Tools/Android/GenerateAndroidProject.py

+ 36 - 50
AnKi/Resource/ResourceFilesystem.cpp

@@ -246,7 +246,7 @@ Error ResourceFilesystem::init(const ConfigSet& config, const CString& cacheDir)
 
 
 #if ANKI_OS_ANDROID
 #if ANKI_OS_ANDROID
 	// Add the files of the .apk
 	// Add the files of the .apk
-	ANKI_CHECK(addNewPath("", excludedStrings, true));
+	ANKI_CHECK(addNewPath("APK package", excludedStrings, true));
 #endif
 #endif
 
 
 	for(auto& path : paths)
 	for(auto& path : paths)
@@ -268,9 +268,9 @@ void ResourceFilesystem::addCachePath(const CString& path)
 	m_paths.emplaceBack(m_alloc, std::move(p));
 	m_paths.emplaceBack(m_alloc, std::move(p));
 }
 }
 
 
-Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto& excludedStrings, Bool special)
+Error ResourceFilesystem::addNewPath(const CString& filepath, const StringListAuto& excludedStrings, Bool special)
 {
 {
-	U32 fileCount = 0;
+	U32 fileCount = 0; // Count files manually because it's slower to get that number from the list
 	static const CString extension(".ankizip");
 	static const CString extension(".ankizip");
 
 
 	auto rejectPath = [&](CString p) -> Bool {
 	auto rejectPath = [&](CString p) -> Bool {
@@ -286,6 +286,7 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 	};
 	};
 
 
 	PtrSize pos;
 	PtrSize pos;
+	Path path;
 	if(special)
 	if(special)
 	{
 	{
 		// Android apk, read the file that contains the directory structure
 		// Android apk, read the file that contains the directory structure
@@ -299,36 +300,24 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 		StringListAuto filenames(m_alloc);
 		StringListAuto filenames(m_alloc);
 		filenames.splitString(txt, '\n');
 		filenames.splitString(txt, '\n');
 
 
-		if(filenames.isEmpty())
-		{
-			ANKI_RESOURCE_LOGE("DirStructure.txt is empty");
-			return Error::USER_DATA;
-		}
-
 		// Create the Path
 		// Create the Path
-		m_paths.emplaceFront(m_alloc, Path());
-		Path& p = m_paths.getFront();
-		while(!filenames.isEmpty())
+		for(const String& filename : filenames)
 		{
 		{
-			const String& filename = filenames.getFront();
 			if(!rejectPath(filename))
 			if(!rejectPath(filename))
 			{
 			{
-				p.m_files.pushBack(m_alloc, filename);
+				path.m_files.pushBack(m_alloc, filename);
 				++fileCount;
 				++fileCount;
 			}
 			}
-			filenames.popFront();
 		}
 		}
 
 
-		p.m_path.sprintf(m_alloc, "%s", &path[0]);
-		p.m_isArchive = false;
-		p.m_isSpecial = true;
+		path.m_isSpecial = true;
 	}
 	}
-	else if((pos = path.find(extension)) != CString::NPOS && pos == path.getLength() - extension.getLength())
+	else if((pos = filepath.find(extension)) != CString::NPOS && pos == filepath.getLength() - extension.getLength())
 	{
 	{
 		// It's an archive
 		// It's an archive
 
 
 		// Open
 		// Open
-		unzFile zfile = unzOpen(&path[0]);
+		unzFile zfile = unzOpen(&filepath[0]);
 		if(!zfile)
 		if(!zfile)
 		{
 		{
 			ANKI_RESOURCE_LOGE("Failed to open archive");
 			ANKI_RESOURCE_LOGE("Failed to open archive");
@@ -343,10 +332,6 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 			return Error::FILE_ACCESS;
 			return Error::FILE_ACCESS;
 		}
 		}
 
 
-		Path p;
-		p.m_isArchive = true;
-		p.m_path.sprintf(m_alloc, "%s", &path[0]);
-
 		do
 		do
 		{
 		{
 			Array<char, 1024> filename;
 			Array<char, 1024> filename;
@@ -362,49 +347,43 @@ Error ResourceFilesystem::addNewPath(const CString& path, const StringListAuto&
 			const Bool itsADir = info.uncompressed_size == 0;
 			const Bool itsADir = info.uncompressed_size == 0;
 			if(!itsADir && !rejectPath(&filename[0]))
 			if(!itsADir && !rejectPath(&filename[0]))
 			{
 			{
-				p.m_files.pushBackSprintf(m_alloc, "%s", &filename[0]);
+				path.m_files.pushBackSprintf(m_alloc, "%s", &filename[0]);
 				++fileCount;
 				++fileCount;
 			}
 			}
 		} while(unzGoToNextFile(zfile) == UNZ_OK);
 		} while(unzGoToNextFile(zfile) == UNZ_OK);
 
 
-		m_paths.emplaceFront(m_alloc, std::move(p));
 		unzClose(zfile);
 		unzClose(zfile);
+
+		path.m_isArchive = true;
 	}
 	}
 	else
 	else
 	{
 	{
 		// It's simple directory
 		// It's simple directory
 
 
-		m_paths.emplaceFront(m_alloc, Path());
-		Path& p = m_paths.getFront();
-		p.m_path.sprintf(m_alloc, "%s", &path[0]);
-		p.m_isArchive = false;
-
-		ANKI_CHECK(walkDirectoryTree(path, m_alloc, [&, this](const CString& fname, Bool isDir) -> Error {
-			if(isDir)
+		ANKI_CHECK(walkDirectoryTree(filepath, m_alloc, [&, this](const CString& fname, Bool isDir) -> Error {
+			if(!isDir && !rejectPath(fname))
 			{
 			{
-				return Error::NONE;
-			}
-
-			if(rejectPath(fname))
-			{
-				return Error::NONE;
+				path.m_files.pushBackSprintf(m_alloc, "%s", fname.cstr());
+				++fileCount;
 			}
 			}
 
 
-			Path& p = m_paths.getFront();
-			p.m_files.pushBackSprintf(m_alloc, "%s", fname.cstr());
-
-			++fileCount;
 			return Error::NONE;
 			return Error::NONE;
 		}));
 		}));
+	}
 
 
-		if(p.m_files.getSize() < 1)
-		{
-			ANKI_RESOURCE_LOGE("Directory is empty: %s", &path[0]);
-			return Error::USER_DATA;
-		}
+	ANKI_ASSERT(path.m_files.getSize() == fileCount);
+	if(fileCount == 0)
+	{
+		ANKI_RESOURCE_LOGW("Ignoring empty resource path: %s", &filepath[0]);
+	}
+	else
+	{
+		path.m_path.sprintf(m_alloc, "%s", &filepath[0]);
+		m_paths.emplaceFront(m_alloc, std::move(path));
+
+		ANKI_RESOURCE_LOGI("Added new data path \"%s\" that contains %u files", &filepath[0], fileCount);
 	}
 	}
 
 
-	ANKI_RESOURCE_LOGI("Added new data path \"%s\" that contains %u files", &path[0], fileCount);
 	return Error::NONE;
 	return Error::NONE;
 }
 }
 
 
@@ -454,7 +433,14 @@ Error ResourceFilesystem::openFile(const ResourceFilename& filename, ResourceFil
 				else
 				else
 				{
 				{
 					StringAuto newFname(m_alloc);
 					StringAuto newFname(m_alloc);
-					newFname.sprintf("%s/%s", &p.m_path[0], &filename[0]);
+					if(!p.m_isSpecial)
+					{
+						newFname.sprintf("%s/%s", &p.m_path[0], &filename[0]);
+					}
+					else
+					{
+						newFname.sprintf("%s", &filename[0]);
+					}
 
 
 					CResourceFile* file = m_alloc.newInstance<CResourceFile>(m_alloc);
 					CResourceFile* file = m_alloc.newInstance<CResourceFile>(m_alloc);
 					rfile = file;
 					rfile = file;

+ 4 - 6
AnKi/Resource/ResourceFilesystem.h

@@ -126,11 +126,8 @@ private:
 		Path(const Path&) = delete; // Non-copyable
 		Path(const Path&) = delete; // Non-copyable
 
 
 		Path(Path&& b)
 		Path(Path&& b)
-			: m_files(std::move(b.m_files))
-			, m_path(std::move(b.m_path))
-			, m_isArchive(std::move(b.m_isArchive))
-			, m_isCache(std::move(b.m_isCache))
 		{
 		{
+			*this = std::move(b);
 		}
 		}
 
 
 		Path& operator=(const Path&) = delete; // Non-copyable
 		Path& operator=(const Path&) = delete; // Non-copyable
@@ -139,8 +136,9 @@ private:
 		{
 		{
 			m_files = std::move(b.m_files);
 			m_files = std::move(b.m_files);
 			m_path = std::move(b.m_path);
 			m_path = std::move(b.m_path);
-			m_isArchive = std::move(b.m_isArchive);
-			m_isCache = std::move(b.m_isCache);
+			m_isArchive = b.m_isArchive;
+			m_isCache = b.m_isCache;
+			m_isSpecial = b.m_isSpecial;
 			return *this;
 			return *this;
 		}
 		}
 	};
 	};

+ 3 - 0
Tools/Android/GenerateAndroidProject.py

@@ -72,6 +72,9 @@ def main():
     os.mkdir(os.path.join(project_dir, "assets/AnKi/"))
     os.mkdir(os.path.join(project_dir, "assets/AnKi/"))
     os.symlink(os.path.join(this_script_dir, "../../AnKi/Shaders"), os.path.join(project_dir, "assets/AnKi/Shaders"))
     os.symlink(os.path.join(this_script_dir, "../../AnKi/Shaders"), os.path.join(project_dir, "assets/AnKi/Shaders"))
     os.symlink(os.path.join(this_script_dir, "../../EngineAssets"), os.path.join(project_dir, "assets/EngineAssets"))
     os.symlink(os.path.join(this_script_dir, "../../EngineAssets"), os.path.join(project_dir, "assets/EngineAssets"))
+    os.mkdir(os.path.join(project_dir, "assets/ThirdParty/"))
+    os.symlink(os.path.join(this_script_dir, "../../ThirdParty/Fsr"), os.path.join(project_dir,
+                                                                                   "assets/ThirdParty/Fsr"))
     os.symlink(ctx.asserts_dir, os.path.join(project_dir, "assets/Assets"))
     os.symlink(ctx.asserts_dir, os.path.join(project_dir, "assets/Assets"))
 
 
     # Write the asset directory structure to a file
     # Write the asset directory structure to a file