Remove now unused FileAccessBuffered.
This commit is contained in:
parent
1396c74734
commit
781efc26e0
7 changed files with 1 additions and 387 deletions
|
@ -1,150 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* file_access_buffered.cpp */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#include "file_access_buffered.h"
|
||||
|
||||
#include "core/error/error_macros.h"
|
||||
|
||||
Error FileAccessBuffered::set_error(Error p_error) const {
|
||||
return (last_error = p_error);
|
||||
}
|
||||
|
||||
void FileAccessBuffered::set_cache_size(int p_size) {
|
||||
cache_size = p_size;
|
||||
}
|
||||
|
||||
int FileAccessBuffered::get_cache_size() {
|
||||
return cache_size;
|
||||
}
|
||||
|
||||
int FileAccessBuffered::cache_data_left() const {
|
||||
if (file.offset >= file.size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size()) {
|
||||
return read_data_block(file.offset, cache_size);
|
||||
}
|
||||
|
||||
return cache.buffer.size() - (file.offset - cache.offset);
|
||||
}
|
||||
|
||||
void FileAccessBuffered::seek(size_t p_position) {
|
||||
file.offset = p_position;
|
||||
}
|
||||
|
||||
void FileAccessBuffered::seek_end(int64_t p_position) {
|
||||
file.offset = file.size + p_position;
|
||||
}
|
||||
|
||||
size_t FileAccessBuffered::get_position() const {
|
||||
return file.offset;
|
||||
}
|
||||
|
||||
size_t FileAccessBuffered::get_len() const {
|
||||
return file.size;
|
||||
}
|
||||
|
||||
bool FileAccessBuffered::eof_reached() const {
|
||||
return file.offset > file.size;
|
||||
}
|
||||
|
||||
uint8_t FileAccessBuffered::get_8() const {
|
||||
ERR_FAIL_COND_V_MSG(!file.open, 0, "Can't get data, when file is not opened.");
|
||||
|
||||
uint8_t byte = 0;
|
||||
if (cache_data_left() >= 1) {
|
||||
byte = cache.buffer[file.offset - cache.offset];
|
||||
}
|
||||
|
||||
++file.offset;
|
||||
|
||||
return byte;
|
||||
}
|
||||
|
||||
int FileAccessBuffered::get_buffer(uint8_t *p_dest, int p_length) const {
|
||||
ERR_FAIL_COND_V_MSG(!file.open, -1, "Can't get buffer, when file is not opened.");
|
||||
|
||||
if (p_length > cache_size) {
|
||||
int total_read = 0;
|
||||
|
||||
if (!(cache.offset == -1 || file.offset < cache.offset || file.offset >= cache.offset + cache.buffer.size())) {
|
||||
int size = (cache.buffer.size() - (file.offset - cache.offset));
|
||||
size = size - (size % 4);
|
||||
//const uint8_t* read = cache.buffer.ptr();
|
||||
//memcpy(p_dest, read.ptr() + (file.offset - cache.offset), size);
|
||||
memcpy(p_dest, cache.buffer.ptr() + (file.offset - cache.offset), size);
|
||||
p_dest += size;
|
||||
p_length -= size;
|
||||
file.offset += size;
|
||||
total_read += size;
|
||||
}
|
||||
|
||||
int err = read_data_block(file.offset, p_length, p_dest);
|
||||
if (err >= 0) {
|
||||
total_read += err;
|
||||
file.offset += err;
|
||||
}
|
||||
|
||||
return total_read;
|
||||
}
|
||||
|
||||
int to_read = p_length;
|
||||
int total_read = 0;
|
||||
while (to_read > 0) {
|
||||
int left = cache_data_left();
|
||||
if (left == 0) {
|
||||
file.offset += to_read;
|
||||
return total_read;
|
||||
}
|
||||
if (left < 0) {
|
||||
return left;
|
||||
}
|
||||
|
||||
int r = MIN(left, to_read);
|
||||
//const uint8_t* read = cache.buffer.ptr();
|
||||
//memcpy(p_dest+total_read, &read.ptr()[file.offset - cache.offset], r);
|
||||
memcpy(p_dest + total_read, cache.buffer.ptr() + (file.offset - cache.offset), r);
|
||||
|
||||
file.offset += r;
|
||||
total_read += r;
|
||||
to_read -= r;
|
||||
}
|
||||
|
||||
return p_length;
|
||||
}
|
||||
|
||||
bool FileAccessBuffered::is_open() const {
|
||||
return file.open;
|
||||
}
|
||||
|
||||
Error FileAccessBuffered::get_error() const {
|
||||
return last_error;
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* file_access_buffered.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef FILE_ACCESS_BUFFERED_H
|
||||
#define FILE_ACCESS_BUFFERED_H
|
||||
|
||||
#include "core/os/file_access.h"
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
class FileAccessBuffered : public FileAccess {
|
||||
public:
|
||||
enum {
|
||||
DEFAULT_CACHE_SIZE = 128 * 1024,
|
||||
};
|
||||
|
||||
private:
|
||||
int cache_size = DEFAULT_CACHE_SIZE;
|
||||
|
||||
int cache_data_left() const;
|
||||
mutable Error last_error;
|
||||
|
||||
protected:
|
||||
Error set_error(Error p_error) const;
|
||||
|
||||
mutable struct File {
|
||||
bool open = false;
|
||||
int size = 0;
|
||||
int offset = 0;
|
||||
String name;
|
||||
int access_flags = 0;
|
||||
} file;
|
||||
|
||||
mutable struct Cache {
|
||||
Vector<uint8_t> buffer;
|
||||
int offset = 0;
|
||||
} cache;
|
||||
|
||||
virtual int read_data_block(int p_offset, int p_size, uint8_t *p_dest = nullptr) const = 0;
|
||||
|
||||
void set_cache_size(int p_size);
|
||||
int get_cache_size();
|
||||
|
||||
public:
|
||||
virtual size_t get_position() const; ///< get position in the file
|
||||
virtual size_t get_len() const; ///< get size of the file
|
||||
|
||||
virtual void seek(size_t p_position); ///< seek to a given position
|
||||
virtual void seek_end(int64_t p_position = 0); ///< seek from the end of file
|
||||
|
||||
virtual bool eof_reached() const;
|
||||
|
||||
virtual uint8_t get_8() const;
|
||||
virtual int get_buffer(uint8_t *p_dest, int p_length) const; ///< get an array of bytes
|
||||
|
||||
virtual bool is_open() const;
|
||||
|
||||
virtual Error get_error() const;
|
||||
|
||||
FileAccessBuffered() {}
|
||||
virtual ~FileAccessBuffered() {}
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,139 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* file_access_buffered_fa.h */
|
||||
/*************************************************************************/
|
||||
/* This file is part of: */
|
||||
/* GODOT ENGINE */
|
||||
/* https://godotengine.org */
|
||||
/*************************************************************************/
|
||||
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
|
||||
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
|
||||
/* */
|
||||
/* Permission is hereby granted, free of charge, to any person obtaining */
|
||||
/* a copy of this software and associated documentation files (the */
|
||||
/* "Software"), to deal in the Software without restriction, including */
|
||||
/* without limitation the rights to use, copy, modify, merge, publish, */
|
||||
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
||||
/* permit persons to whom the Software is furnished to do so, subject to */
|
||||
/* the following conditions: */
|
||||
/* */
|
||||
/* The above copyright notice and this permission notice shall be */
|
||||
/* included in all copies or substantial portions of the Software. */
|
||||
/* */
|
||||
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
||||
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
||||
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
||||
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
||||
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
||||
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifndef FILE_ACCESS_BUFFERED_FA_H
|
||||
#define FILE_ACCESS_BUFFERED_FA_H
|
||||
|
||||
#include "core/io/file_access_buffered.h"
|
||||
|
||||
template <class T>
|
||||
class FileAccessBufferedFA : public FileAccessBuffered {
|
||||
T f;
|
||||
|
||||
int read_data_block(int p_offset, int p_size, uint8_t *p_dest = 0) const {
|
||||
ERR_FAIL_COND_V_MSG(!f.is_open(), -1, "Can't read data block when file is not opened.");
|
||||
|
||||
((T *)&f)->seek(p_offset);
|
||||
|
||||
if (p_dest) {
|
||||
f.get_buffer(p_dest, p_size);
|
||||
return p_size;
|
||||
|
||||
} else {
|
||||
cache.offset = p_offset;
|
||||
cache.buffer.resize(p_size);
|
||||
|
||||
// on Vector
|
||||
//uint8_t* write = cache.buffer.ptrw();
|
||||
//f.get_buffer(write.ptrw(), p_size);
|
||||
|
||||
// on vector
|
||||
f.get_buffer(cache.buffer.ptrw(), p_size);
|
||||
|
||||
return p_size;
|
||||
}
|
||||
}
|
||||
|
||||
static FileAccess *create() {
|
||||
return memnew(FileAccessBufferedFA<T>());
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void _set_access_type(AccessType p_access) {
|
||||
f._set_access_type(p_access);
|
||||
FileAccessBuffered::_set_access_type(p_access);
|
||||
}
|
||||
|
||||
public:
|
||||
void flush() {
|
||||
f.flush();
|
||||
}
|
||||
|
||||
void store_8(uint8_t p_dest) {
|
||||
f.store_8(p_dest);
|
||||
}
|
||||
|
||||
void store_buffer(const uint8_t *p_src, int p_length) {
|
||||
f.store_buffer(p_src, p_length);
|
||||
}
|
||||
|
||||
bool file_exists(const String &p_name) {
|
||||
return f.file_exists(p_name);
|
||||
}
|
||||
|
||||
Error _open(const String &p_path, int p_mode_flags) {
|
||||
close();
|
||||
|
||||
Error ret = f._open(p_path, p_mode_flags);
|
||||
if (ret != OK)
|
||||
return ret;
|
||||
//ERR_FAIL_COND_V( ret != OK, ret );
|
||||
|
||||
file.size = f.get_len();
|
||||
file.offset = 0;
|
||||
file.open = true;
|
||||
file.name = p_path;
|
||||
file.access_flags = p_mode_flags;
|
||||
|
||||
cache.buffer.resize(0);
|
||||
cache.offset = 0;
|
||||
|
||||
return set_error(OK);
|
||||
}
|
||||
|
||||
void close() {
|
||||
f.close();
|
||||
|
||||
file.offset = 0;
|
||||
file.size = 0;
|
||||
file.open = false;
|
||||
file.name = "";
|
||||
|
||||
cache.buffer.resize(0);
|
||||
cache.offset = 0;
|
||||
set_error(OK);
|
||||
}
|
||||
|
||||
virtual uint64_t _get_modified_time(const String &p_file) {
|
||||
return f._get_modified_time(p_file);
|
||||
}
|
||||
|
||||
virtual uint32_t _get_unix_permissions(const String &p_file) {
|
||||
return f._get_unix_permissions(p_file);
|
||||
}
|
||||
|
||||
virtual Error _set_unix_permissions(const String &p_file, uint32_t p_permissions) {
|
||||
return f._set_unix_permissions(p_file, p_permissions);
|
||||
}
|
||||
|
||||
FileAccessBufferedFA() {}
|
||||
};
|
||||
|
||||
#endif // FILE_ACCESS_BUFFERED_FA_H
|
|
@ -127,7 +127,6 @@ void OS_Unix::initialize_core() {
|
|||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
|
||||
//FileAccessBufferedFA<FileAccessUnix>::make_default();
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "os_android.h"
|
||||
|
||||
#include "core/config/project_settings.h"
|
||||
#include "core/io/file_access_buffered_fa.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
#include "file_access_android.h"
|
||||
|
@ -63,15 +62,13 @@ void OS_Android::initialize_core() {
|
|||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
|
||||
else {
|
||||
#ifdef USE_JAVA_FILE_ACCESS
|
||||
FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid>>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessJAndroid>(FileAccess::ACCESS_RESOURCES);
|
||||
#else
|
||||
//FileAccess::make_default<FileAccessBufferedFA<FileAccessAndroid> >(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
|
||||
#endif
|
||||
}
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
|
||||
FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
|
||||
//FileAccessBufferedFA<FileAccessUnix>::make_default();
|
||||
if (use_apk_expansion)
|
||||
DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
|
||||
else
|
||||
|
|
|
@ -31,7 +31,6 @@
|
|||
#include "os_javascript.h"
|
||||
|
||||
#include "core/debugger/engine_debugger.h"
|
||||
#include "core/io/file_access_buffered_fa.h"
|
||||
#include "core/io/json.h"
|
||||
#include "drivers/unix/dir_access_unix.h"
|
||||
#include "drivers/unix/file_access_unix.h"
|
||||
|
|
|
@ -183,7 +183,6 @@ void OS_Windows::initialize() {
|
|||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_RESOURCES);
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_USERDATA);
|
||||
FileAccess::make_default<FileAccessWindows>(FileAccess::ACCESS_FILESYSTEM);
|
||||
//FileAccessBufferedFA<FileAccessWindows>::make_default();
|
||||
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_RESOURCES);
|
||||
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_USERDATA);
|
||||
DirAccess::make_default<DirAccessWindows>(DirAccess::ACCESS_FILESYSTEM);
|
||||
|
|
Loading…
Reference in a new issue