Daniele Bartolini пре 10 година
родитељ
комит
c2b4b978d5

+ 1 - 1
src/compilers/bundle_compiler.cpp

@@ -113,7 +113,7 @@ bool BundleCompiler::compile(const char* type, const char* name, const char* pla
 	{
 		CompileOptions opts(_source_fs, output, platform, &buf);
 		compile(_type, src_path.c_str(), opts);
-		File* outf = _bundle_fs.open(path.c_str(), FOM_WRITE);
+		File* outf = _bundle_fs.open(path.c_str(), FileOpenMode::WRITE);
 		uint32_t size = array::size(output);
 		uint32_t written = outf->write(array::begin(output), size);
 		_bundle_fs.close(*outf);

+ 1 - 1
src/compilers/compile_options.h

@@ -46,7 +46,7 @@ struct CompileOptions
 	{
 		add_dependency(path);
 
-		File* file = _fs.open(path, FOM_READ);
+		File* file = _fs.open(path, FileOpenMode::READ);
 		uint32_t size = file->size();
 		Buffer buf(default_allocator());
 		array::resize(buf, size);

+ 3 - 3
src/core/filesystem/apk_file.cpp

@@ -17,7 +17,7 @@ namespace crown
 {
 
 ApkFile::ApkFile(AAssetManager* asset_manager, const char* path)
-	: File(FOM_READ)
+	: File(FileOpenMode::READ)
 	, _asset(NULL)
 {
 	_asset = AAssetManager_open(asset_manager, path, AASSET_MODE_RANDOM);
@@ -56,8 +56,8 @@ void ApkFile::skip(uint32_t bytes)
 
 uint32_t ApkFile::read(void* data, uint32_t size)
 {
-	CE_ASSERT_NOT_NULL(buffer);
-	return (uint32_t)AAsset_read(_asset, buffer, size);
+	CE_ASSERT_NOT_NULL(data);
+	return (uint32_t)AAsset_read(_asset, data, size);
 }
 
 uint32_t ApkFile::write(const void* /*data*/, uint32_t /*size*/)

+ 2 - 2
src/core/filesystem/apk_filesystem.cpp

@@ -20,10 +20,10 @@ ApkFilesystem::ApkFilesystem(AAssetManager* asset_manager)
 {
 }
 
-File* ApkFilesystem::open(const char* path, FileOpenMode mode)
+File* ApkFilesystem::open(const char* path, FileOpenMode::Enum mode)
 {
 	CE_ASSERT_NOT_NULL(path);
-	CE_ASSERT(mode == FOM_READ, "Cannot open for writing in Android assets folder");
+	CE_ASSERT(mode == FileOpenMode::READ, "Cannot open for writing in Android assets folder");
 	return CE_NEW(default_allocator(), ApkFile)(_asset_manager, path);
 }
 

+ 1 - 1
src/core/filesystem/apk_filesystem.h

@@ -27,7 +27,7 @@ public:
 	/// @copydoc Filesystem::open()
 	/// @note
 	/// @a mode can only be FOM_READ
-	File* open(const char* rel_path, FileOpenMode mode);
+	File* open(const char* path, FileOpenMode::Enum mode);
 
 	/// @copydoc Filesystem::close()
 	void close(File& file);

+ 1 - 1
src/core/filesystem/disk_file.cpp

@@ -11,7 +11,7 @@
 namespace crown
 {
 
-DiskFile::DiskFile(FileOpenMode mode, const char* path)
+DiskFile::DiskFile(const char* path, FileOpenMode::Enum mode)
 	: File(mode)
 {
 	_file.open(path, mode);

+ 1 - 1
src/core/filesystem/disk_file.h

@@ -20,7 +20,7 @@ class DiskFile: public File
 public:
 
 	/// Opens @a path with specified @a mode
-	DiskFile(FileOpenMode mode, const char* path);
+	DiskFile(const char* path, FileOpenMode::Enum mode);
 	virtual ~DiskFile();
 
 	/// @copydoc File::seek()

+ 2 - 2
src/core/filesystem/disk_filesystem.cpp

@@ -27,7 +27,7 @@ DiskFilesystem::DiskFilesystem(const char* prefix)
 {
 }
 
-File* DiskFilesystem::open(const char* path, FileOpenMode mode)
+File* DiskFilesystem::open(const char* path, FileOpenMode::Enum mode)
 {
 	CE_ASSERT_NOT_NULL(path);
 
@@ -35,7 +35,7 @@ File* DiskFilesystem::open(const char* path, FileOpenMode mode)
 	DynamicString abs_path(alloc);
 	get_absolute_path(path, abs_path);
 
-	return CE_NEW(default_allocator(), DiskFile)(mode, abs_path.c_str());
+	return CE_NEW(default_allocator(), DiskFile)(abs_path.c_str(), mode);
 }
 
 void DiskFilesystem::close(File& file)

+ 1 - 1
src/core/filesystem/disk_filesystem.h

@@ -32,7 +32,7 @@ public:
 	DiskFilesystem(const char* prefix);
 
 	/// Opens the file at the given @a path with the given @a mode.
-	File* open(const char* path, FileOpenMode mode);
+	File* open(const char* path, FileOpenMode::Enum mode);
 
 	/// Closes the given @a file.
 	void close(File& file);

+ 8 - 5
src/core/filesystem/file.h

@@ -10,10 +10,13 @@
 namespace crown
 {
 
-enum FileOpenMode
+struct FileOpenMode
 {
-	FOM_READ		= 1,
-	FOM_WRITE		= 2
+	enum Enum
+	{
+		READ,
+		WRITE
+	};
 };
 
 /// An abstraction to access data files.
@@ -24,7 +27,7 @@ class File
 public:
 
 	/// Opens the file with the given @a mode
-	File(FileOpenMode mode) : _open_mode(mode) {}
+	File(FileOpenMode::Enum mode) : _open_mode(mode) {}
 	virtual ~File() {};
 
 	/// Sets the position indicator of the file to position.
@@ -64,7 +67,7 @@ public:
 
 protected:
 
-	FileOpenMode _open_mode;
+	FileOpenMode::Enum _open_mode;
 };
 
 } // namespace crown

+ 1 - 1
src/core/filesystem/filesystem.h

@@ -26,7 +26,7 @@ public:
 	virtual ~Filesystem() {};
 
 	/// Opens the file at the given @a path with the given @a mode.
-	virtual File* open(const char* path, FileOpenMode mode) = 0;
+	virtual File* open(const char* path, FileOpenMode::Enum mode) = 0;
 
 	/// Closes the given @a file.
 	virtual void close(File& file) = 0;

+ 3 - 3
src/core/filesystem/os_file.h

@@ -43,14 +43,14 @@ public:
 		close();
 	}
 
-	void open(const char* path, FileOpenMode mode)
+	void open(const char* path, FileOpenMode::Enum mode)
 	{
 #if CROWN_PLATFORM_POSIX
-		_file = fopen(path, (mode == FOM_READ) ? "rb" : "wb");
+		_file = fopen(path, (mode == FileOpenMode::READ) ? "rb" : "wb");
 		CE_ASSERT(_file != NULL, "fopen: errno = %d", errno);
 #elif CROWN_PLATFORM_WINDOWS
 		_file = CreateFile(path
-			, (mode == FOM_READ) ? GENERIC_READ : GENERIC_WRITE
+			, (mode == FileOpenMode::READ) ? GENERIC_READ : GENERIC_WRITE
 			, 0
 			, NULL
 			, OPEN_ALWAYS

+ 3 - 3
src/renderers/shader.cpp

@@ -91,15 +91,15 @@ namespace shader_resource
 		opts.get_absolute_path("tmpvs", tmpvs_path);
 		opts.get_absolute_path("tmpfs", tmpfs_path);
 
-		File* vs_file = opts._fs.open(vs_code_path.c_str(), FOM_WRITE);
+		File* vs_file = opts._fs.open(vs_code_path.c_str(), FileOpenMode::WRITE);
 		vs_file->write(vs_code.c_str(), vs_code.length());
 		opts._fs.close(*vs_file);
 
-		File* fs_file = opts._fs.open(fs_code_path.c_str(), FOM_WRITE);
+		File* fs_file = opts._fs.open(fs_code_path.c_str(), FileOpenMode::WRITE);
 		fs_file->write(fs_code.c_str(), fs_code.length());
 		opts._fs.close(*fs_file);
 
-		File* varying_file = opts._fs.open(varying_def_path.c_str(), FOM_WRITE);
+		File* varying_file = opts._fs.open(varying_def_path.c_str(), FileOpenMode::WRITE);
 		varying_file->write(varying_def.c_str(), varying_def.length());
 		opts._fs.close(*varying_file);
 

+ 1 - 1
src/resource/resource_loader.cpp

@@ -88,7 +88,7 @@ int32_t ResourceLoader::run()
 		DynamicString path(alloc);
 		path::join(CROWN_DATA_DIRECTORY, name, path);
 
-		File* file = _fs.open(path.c_str(), FOM_READ);
+		File* file = _fs.open(path.c_str(), FileOpenMode::READ);
 		rr.data = rr.load_function(*file, *rr.allocator);
 		_fs.close(*file);
 

+ 1 - 1
src/resource/texture_resource.cpp

@@ -565,7 +565,7 @@ namespace texture_resource
 
 		DynamicString name = root.key("source").to_string();
 
-		File* source = opts._fs.open(name.c_str(), FOM_READ);
+		File* source = opts._fs.open(name.c_str(), FileOpenMode::READ);
 		BinaryReader br(*source);
 		ImageData image;