Просмотр исходного кода

Code style changes and minor cleanup

BearishSun 9 лет назад
Родитель
Сommit
692e25b595

+ 2 - 2
Source/BansheeCore/Source/BsTexture.cpp

@@ -407,7 +407,7 @@ namespace BansheeEngine
 
 
 		if (subresourceIdx >= (UINT32)mCPUSubresourceData.size())
 		if (subresourceIdx >= (UINT32)mCPUSubresourceData.size())
 		{
 		{
-			LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. " + toString((unsigned)mCPUSubresourceData.size()));
+			LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. " + toString((UINT32)mCPUSubresourceData.size()));
 			return;
 			return;
 		}
 		}
 
 
@@ -457,7 +457,7 @@ namespace BansheeEngine
 		UINT32 subresourceIdx = mProperties.mapToSubresourceIdx(face, mipLevel);
 		UINT32 subresourceIdx = mProperties.mapToSubresourceIdx(face, mipLevel);
 		if (subresourceIdx >= (UINT32)mCPUSubresourceData.size())
 		if (subresourceIdx >= (UINT32)mCPUSubresourceData.size())
 		{
 		{
-			LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. " + toString((unsigned)mCPUSubresourceData.size()));
+			LOGERR("Invalid subresource index: " + toString(subresourceIdx) + ". Supported range: 0 .. " + toString((UINT32)mCPUSubresourceData.size()));
 			return;
 			return;
 		}
 		}
 
 

+ 1 - 1
Source/BansheeUtility/CMakeLists.txt

@@ -17,7 +17,7 @@ include_directories(${BansheeUtility_INC})
 # Target
 # Target
 add_library(BansheeUtility SHARED ${BS_BANSHEEUTILITY_SRC})
 add_library(BansheeUtility SHARED ${BS_BANSHEEUTILITY_SRC})
 
 
-add_executable(BansheeUtilityTest Source/BansheeUtilityTest.cpp)
+add_executable(BansheeUtilityTest Source/BsUtilityTest.cpp)
 target_link_libraries(BansheeUtilityTest BansheeUtility)
 target_link_libraries(BansheeUtilityTest BansheeUtility)
 
 
 # Defines
 # Defines

+ 4 - 3
Source/BansheeUtility/Include/BsFileSystemTestSuite.h

@@ -10,11 +10,10 @@ namespace BansheeEngine
 	{
 	{
 	public:
 	public:
 		FileSystemTestSuite();
 		FileSystemTestSuite();
-		virtual void startUp();
-		virtual void shutDown();
+		void startUp() override;
+		void shutDown() override;
 
 
 	private:
 	private:
-		Path testDirectory;
 		void testExists_yes_file();
 		void testExists_yes_file();
 		void testExists_yes_dir();
 		void testExists_yes_dir();
 		void testExists_no();
 		void testExists_no();
@@ -36,5 +35,7 @@ namespace BansheeEngine
 		void testGetChildren();
 		void testGetChildren();
 		void testGetLastModifiedTime();
 		void testGetLastModifiedTime();
 		void testGetTempDirectoryPath();
 		void testGetTempDirectoryPath();
+
+		Path mTestDirectory;
 	};
 	};
 }
 }

+ 3 - 3
Source/BansheeUtility/Include/BsStdHeaders.h

@@ -85,6 +85,9 @@ namespace BansheeEngine
 	 *  @{
 	 *  @{
 	 */
 	 */
 
 
+	template <typename Key>
+	using HashType = typename std::conditional<std::is_enum<Key>::value, EnumClassHash, std::hash<Key>>::type;
+
 	/** Double ended queue. Allows for fast insertion and removal at both its beggining and end. */
 	/** Double ended queue. Allows for fast insertion and removal at both its beggining and end. */
 	template <typename T, typename A = StdAlloc<T>> 
 	template <typename T, typename A = StdAlloc<T>> 
 	using Deque = std::deque<T, A>;
 	using Deque = std::deque<T, A>;
@@ -117,9 +120,6 @@ namespace BansheeEngine
 	template <typename K, typename V, typename P = std::less<K>, typename A = StdAlloc<std::pair<const K, V>>> 
 	template <typename K, typename V, typename P = std::less<K>, typename A = StdAlloc<std::pair<const K, V>>> 
 	using MultiMap = std::multimap<K, V, P, A>;
 	using MultiMap = std::multimap<K, V, P, A>;
 
 
-	template <typename Key>
-	using HashType = typename std::conditional<std::is_enum<Key>::value, EnumClassHash, std::hash<Key>>::type;
-
 	/** An associative container containing an unordered set of elements. Usually faster than Set for larger data sets. */
 	/** An associative container containing an unordered set of elements. Usually faster than Set for larger data sets. */
 	template <typename T, typename H = HashType<T>, typename C = std::equal_to<T>, typename A = StdAlloc<T>> 
 	template <typename T, typename H = HashType<T>, typename C = std::equal_to<T>, typename A = StdAlloc<T>> 
 	using UnorderedSet = std::unordered_set<T, H, C, A>;
 	using UnorderedSet = std::unordered_set<T, H, C, A>;

+ 1 - 1
Source/BansheeUtility/Include/BsUtil.h

@@ -15,8 +15,8 @@ namespace BansheeEngine
 	inline void hash_combine(std::size_t& seed, const T& v)
 	inline void hash_combine(std::size_t& seed, const T& v)
 	{
 	{
 		using HashType = typename std::conditional<std::is_enum<T>::value, EnumClassHash, std::hash<T>>::type;
 		using HashType = typename std::conditional<std::is_enum<T>::value, EnumClassHash, std::hash<T>>::type;
+
 		HashType hasher;
 		HashType hasher;
-		// std::hash<T> hasher;
 		seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
 		seed ^= hasher(v) + 0x9e3779b9 + (seed<<6) + (seed>>2);
 	}
 	}
 
 

+ 2 - 18
Source/BansheeUtility/Source/BsFileSystem.cpp

@@ -2,12 +2,10 @@
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
 
 
 #include "BsFileSystem.h"
 #include "BsFileSystem.h"
-
 #include "BsDebug.h"
 #include "BsDebug.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-
 	void FileSystem::copy(const Path& oldPath, const Path& newPath, bool overwriteExisting)
 	void FileSystem::copy(const Path& oldPath, const Path& newPath, bool overwriteExisting)
 	{
 	{
 		Stack<std::tuple<Path, Path>> todo;
 		Stack<std::tuple<Path, Path>> todo;
@@ -40,25 +38,11 @@ namespace BansheeEngine
 				}
 				}
 			}
 			}
 
 
-			// bool destIsFile = !destinationPath.getWExtension().empty();
-
-			// if (!srcIsFile && destIsFile)
-			// {
-			// 	LOGWRN("Cannot copy a source folder to a destination file.");
-			// 	return;
-			// }
-			// else if (srcIsFile && !destIsFile)
-			// {
-			// 	Path destinationFilePath = destinationPath;
-			// 	destinationFilePath.append(sourcePath.getWTail());
-
-			// 	FileSystem::copyFile(sourcePath, destinationFilePath);
-			// }
-			if (srcIsFile)// && destIsFile)
+			if (srcIsFile)
 			{
 			{
 				FileSystem::copyFile(sourcePath, destinationPath);
 				FileSystem::copyFile(sourcePath, destinationPath);
 			}
 			}
-			else // if (!srcIsFile)// && !destIsFile)
+			else
 			{
 			{
 				if (!destExists)
 				if (!destExists)
 					FileSystem::createDir(destinationPath);
 					FileSystem::createDir(destinationPath);

+ 31 - 31
Source/BansheeUtility/Source/BsFileSystemTestSuite.cpp

@@ -38,8 +38,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::startUp()
 	void FileSystemTestSuite::startUp()
 	{
 	{
-		testDirectory = FileSystem::getWorkingDirectoryPath() + testDirectoryName;
-		if (FileSystem::exists(testDirectory))
+		mTestDirectory = FileSystem::getWorkingDirectoryPath() + testDirectoryName;
+		if (FileSystem::exists(mTestDirectory))
 		{
 		{
 			BS_EXCEPT(InternalErrorException,
 			BS_EXCEPT(InternalErrorException,
 			          String("Directory '") + testDirectoryName
 			          String("Directory '") + testDirectoryName
@@ -47,17 +47,17 @@ namespace BansheeEngine
 		}
 		}
 		else
 		else
 		{
 		{
-			FileSystem::createDir(testDirectory);
-			BS_TEST_ASSERT_MSG(FileSystem::exists(testDirectory), "FileSystemTestSuite::startUp(): test directory creation failed");
+			FileSystem::createDir(mTestDirectory);
+			BS_TEST_ASSERT_MSG(FileSystem::exists(mTestDirectory), "FileSystemTestSuite::startUp(): test directory creation failed");
 		}
 		}
 	}
 	}
 
 
 	void FileSystemTestSuite::shutDown()
 	void FileSystemTestSuite::shutDown()
 	{
 	{
-		FileSystem::remove(testDirectory, true);
-		if (FileSystem::exists(testDirectory))
+		FileSystem::remove(mTestDirectory, true);
+		if (FileSystem::exists(mTestDirectory))
 		{
 		{
-			LOGERR("FileSystemTestSuite failed to delete '" + testDirectory.toString()
+			LOGERR("FileSystemTestSuite failed to delete '" + mTestDirectory.toString()
 				   + "', you should remove it manually.");
 				   + "', you should remove it manually.");
 		}
 		}
 	}
 	}
@@ -88,7 +88,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testExists_yes_file()
 	void FileSystemTestSuite::testExists_yes_file()
 	{
 	{
-		Path path = testDirectory + "plop";
+		Path path = mTestDirectory + "plop";
 		createEmptyFile(path);
 		createEmptyFile(path);
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		FileSystem::remove(path);
 		FileSystem::remove(path);
@@ -96,7 +96,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testExists_yes_dir()
 	void FileSystemTestSuite::testExists_yes_dir()
 	{
 	{
-		Path path = testDirectory + "plop/";
+		Path path = mTestDirectory + "plop/";
 		FileSystem::createDir(path);
 		FileSystem::createDir(path);
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		FileSystem::remove(path);
 		FileSystem::remove(path);
@@ -109,7 +109,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testGetFileSize_zero()
 	void FileSystemTestSuite::testGetFileSize_zero()
 	{
 	{
-		Path path = testDirectory + "file-size-test-1";
+		Path path = mTestDirectory + "file-size-test-1";
 		createEmptyFile(path);
 		createEmptyFile(path);
 		BS_TEST_ASSERT(FileSystem::getFileSize(path) == 0);
 		BS_TEST_ASSERT(FileSystem::getFileSize(path) == 0);
 		FileSystem::remove(path);
 		FileSystem::remove(path);
@@ -117,7 +117,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testGetFileSize_not_zero()
 	void FileSystemTestSuite::testGetFileSize_not_zero()
 	{
 	{
-		Path path = testDirectory + "file-size-test-2";
+		Path path = mTestDirectory + "file-size-test-2";
 		createFile(path, "0123456789");
 		createFile(path, "0123456789");
 		BS_TEST_ASSERT(FileSystem::getFileSize(path) == 10);
 		BS_TEST_ASSERT(FileSystem::getFileSize(path) == 10);
 		FileSystem::remove(path);
 		FileSystem::remove(path);
@@ -125,35 +125,35 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testIsFile_yes()
 	void FileSystemTestSuite::testIsFile_yes()
 	{
 	{
-		Path path = testDirectory + "some-file-1";
+		Path path = mTestDirectory + "some-file-1";
 		createEmptyFile(path);
 		createEmptyFile(path);
 		BS_TEST_ASSERT(FileSystem::isFile(path));
 		BS_TEST_ASSERT(FileSystem::isFile(path));
 	}
 	}
 
 
 	void FileSystemTestSuite::testIsFile_no()
 	void FileSystemTestSuite::testIsFile_no()
 	{
 	{
-		Path path = testDirectory + "some-directory-1/";
+		Path path = mTestDirectory + "some-directory-1/";
 		FileSystem::createDir(path);
 		FileSystem::createDir(path);
 		BS_TEST_ASSERT(!FileSystem::isFile(path));
 		BS_TEST_ASSERT(!FileSystem::isFile(path));
 	}
 	}
 
 
 	void FileSystemTestSuite::testIsDirectory_yes()
 	void FileSystemTestSuite::testIsDirectory_yes()
 	{
 	{
-		Path path = testDirectory + "some-directory-2/";
+		Path path = mTestDirectory + "some-directory-2/";
 		FileSystem::createDir(path);
 		FileSystem::createDir(path);
 		BS_TEST_ASSERT(FileSystem::isDirectory(path));
 		BS_TEST_ASSERT(FileSystem::isDirectory(path));
 	}
 	}
 
 
 	void FileSystemTestSuite::testIsDirectory_no()
 	void FileSystemTestSuite::testIsDirectory_no()
 	{
 	{
-		Path path = testDirectory + "some-file-2";
+		Path path = mTestDirectory + "some-file-2";
 		createEmptyFile(path);
 		createEmptyFile(path);
 		BS_TEST_ASSERT(!FileSystem::isDirectory(path));
 		BS_TEST_ASSERT(!FileSystem::isDirectory(path));
 	}
 	}
 
 
 	void FileSystemTestSuite::testRemove_file()
 	void FileSystemTestSuite::testRemove_file()
 	{
 	{
-		Path path = testDirectory + "file-to-remove";
+		Path path = mTestDirectory + "file-to-remove";
 		createEmptyFile(path);
 		createEmptyFile(path);
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		FileSystem::remove(path);
 		FileSystem::remove(path);
@@ -162,7 +162,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testRemove_directory()
 	void FileSystemTestSuite::testRemove_directory()
 	{
 	{
-		Path path = testDirectory + "directory-to-remove/";
+		Path path = mTestDirectory + "directory-to-remove/";
 		FileSystem::createDir(path);
 		FileSystem::createDir(path);
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		BS_TEST_ASSERT(FileSystem::exists(path));
 		FileSystem::remove(path, true);
 		FileSystem::remove(path, true);
@@ -171,8 +171,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testMove()
 	void FileSystemTestSuite::testMove()
 	{
 	{
-		Path source = testDirectory + "move-source-1";
-		Path destination = testDirectory + "move-destination-1";
+		Path source = mTestDirectory + "move-source-1";
+		Path destination = mTestDirectory + "move-destination-1";
 		createFile(source, "move-data-source-1");
 		createFile(source, "move-data-source-1");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(!FileSystem::exists(destination));
 		BS_TEST_ASSERT(!FileSystem::exists(destination));
@@ -184,8 +184,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testMove_overwrite_existing()
 	void FileSystemTestSuite::testMove_overwrite_existing()
 	{
 	{
-		Path source = testDirectory + "move-source-2";
-		Path destination = testDirectory + "move-destination-2";
+		Path source = mTestDirectory + "move-source-2";
+		Path destination = mTestDirectory + "move-destination-2";
 		createFile(source, "move-data-source-2");
 		createFile(source, "move-data-source-2");
 		createFile(destination, "move-data-destination-2");
 		createFile(destination, "move-data-destination-2");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
@@ -198,8 +198,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testMove_no_overwrite_existing()
 	void FileSystemTestSuite::testMove_no_overwrite_existing()
 	{
 	{
-		Path source = testDirectory + "move-source-3";
-		Path destination = testDirectory + "move-destination-3";
+		Path source = mTestDirectory + "move-source-3";
+		Path destination = mTestDirectory + "move-destination-3";
 		createFile(source, "move-data-source-3");
 		createFile(source, "move-data-source-3");
 		createFile(destination, "move-data-destination-3");
 		createFile(destination, "move-data-destination-3");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
@@ -212,8 +212,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testCopy()
 	void FileSystemTestSuite::testCopy()
 	{
 	{
-		Path source = testDirectory + "copy-source-1";
-		Path destination = testDirectory + "copy-destination-1";
+		Path source = mTestDirectory + "copy-source-1";
+		Path destination = mTestDirectory + "copy-destination-1";
 		createFile(source, "copy-data-source-1");
 		createFile(source, "copy-data-source-1");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(!FileSystem::exists(destination));
 		BS_TEST_ASSERT(!FileSystem::exists(destination));
@@ -226,8 +226,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testCopy_overwrite_existing()
 	void FileSystemTestSuite::testCopy_overwrite_existing()
 	{
 	{
-		Path source = testDirectory + "copy-source-2";
-		Path destination = testDirectory + "copy-destination-2";
+		Path source = mTestDirectory + "copy-source-2";
+		Path destination = mTestDirectory + "copy-destination-2";
 		createFile(source, "copy-data-source-2");
 		createFile(source, "copy-data-source-2");
 		createFile(destination, "copy-data-destination-2");
 		createFile(destination, "copy-data-destination-2");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
@@ -241,8 +241,8 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testCopy_no_overwrite_existing()
 	void FileSystemTestSuite::testCopy_no_overwrite_existing()
 	{
 	{
-		Path source = testDirectory + "copy-source-3";
-		Path destination = testDirectory + "copy-destination-3";
+		Path source = mTestDirectory + "copy-source-3";
+		Path destination = mTestDirectory + "copy-destination-3";
 		createFile(source, "copy-data-source-3");
 		createFile(source, "copy-data-source-3");
 		createFile(destination, "copy-data-destination-3");
 		createFile(destination, "copy-data-destination-3");
 		BS_TEST_ASSERT(FileSystem::exists(source));
 		BS_TEST_ASSERT(FileSystem::exists(source));
@@ -259,7 +259,7 @@ namespace BansheeEngine
 
 
 	void FileSystemTestSuite::testGetChildren()
 	void FileSystemTestSuite::testGetChildren()
 	{
 	{
-		Path path = testDirectory + "get-children-test/";
+		Path path = mTestDirectory + "get-children-test/";
 		FileSystem::createDir(path);
 		FileSystem::createDir(path);
 		FileSystem::createDir(path + "foo/");
 		FileSystem::createDir(path + "foo/");
 		FileSystem::createDir(path + "bar/");
 		FileSystem::createDir(path + "bar/");
@@ -286,7 +286,7 @@ namespace BansheeEngine
 		std::time_t beforeTime;
 		std::time_t beforeTime;
 		time(&beforeTime);
 		time(&beforeTime);
 
 
-		Path path = testDirectory + "blah1234";
+		Path path = mTestDirectory + "blah1234";
 		createFile(path, "blah");
 		createFile(path, "blah");
 		std::time_t mtime = FileSystem::getLastModifiedTime(path);
 		std::time_t mtime = FileSystem::getLastModifiedTime(path);
 		BS_TEST_ASSERT(mtime >= beforeTime);
 		BS_TEST_ASSERT(mtime >= beforeTime);

+ 0 - 1
Source/BansheeUtility/Source/BansheeUtilityTest.cpp → Source/BansheeUtility/Source/BsUtilityTest.cpp

@@ -7,7 +7,6 @@ using namespace BansheeEngine;
 
 
 int main()
 int main()
 {
 {
-
 	SPtr<TestSuite> tests = FileSystemTestSuite::create<FileSystemTestSuite>();
 	SPtr<TestSuite> tests = FileSystemTestSuite::create<FileSystemTestSuite>();
 	ConsoleTestOutput testOutput;
 	ConsoleTestOutput testOutput;
 	tests->run(testOutput);
 	tests->run(testOutput);

+ 0 - 18
Source/BansheeUtility/Source/Unix/BsUnixFileSystem.cpp

@@ -67,16 +67,6 @@ namespace BansheeEngine
 		return false;
 		return false;
 	}
 	}
 
 
-	// bool unix_createFile(const String& path)
-	// {
-	// 	int fd = open(path.c_str(), O_RDWR|O_CREAT, 0755);
-
-	// 	if (fd != -1)
-	// 		close(fd2);
-
-	// 	return ???;
-	// }
-
 	bool unix_createDirectory(const String& path)
 	bool unix_createDirectory(const String& path)
 	{
 	{
 		if (unix_pathExists(path) && unix_isDirectory(path))
 		if (unix_pathExists(path) && unix_isDirectory(path))
@@ -112,7 +102,6 @@ namespace BansheeEngine
 		std::ofstream destinationStream(destination.toString().c_str(), std::ios::binary);
 		std::ofstream destinationStream(destination.toString().c_str(), std::ios::binary);
 
 
 		destinationStream << sourceStream.rdbuf();
 		destinationStream << sourceStream.rdbuf();
-		// std::cout << "copy: " << source.toString() << " to " << destination.toString() << std::endl;
 		sourceStream.close();
 		sourceStream.close();
 		destinationStream.close();
 		destinationStream.close();
 	}
 	}
@@ -131,13 +120,6 @@ namespace BansheeEngine
 	SPtr<DataStream> FileSystem::openFile(const Path& path, bool readOnly)
 	SPtr<DataStream> FileSystem::openFile(const Path& path, bool readOnly)
 	{
 	{
 		String pathString = path.toString();
 		String pathString = path.toString();
-		// const char_t* pathString = pathString.c_str();
-
-		// if (!pathExists(pathString) || !isFile(pathString))
-		// {
-		// 	LOGWRN("Attempting to open a file that doesn't exist: " + path.toString());
-		// 	return nullptr;
-		// }
 
 
 		DataStream::AccessMode accessMode = DataStream::READ;
 		DataStream::AccessMode accessMode = DataStream::READ;
 		if (!readOnly)
 		if (!readOnly)