Removed VoxelStreamFile
This commit is contained in:
parent
82beda502a
commit
b66b9a01a9
@ -26,7 +26,6 @@
|
||||
#include "streams/sqlite/voxel_stream_sqlite.h"
|
||||
#include "streams/vox_loader.h"
|
||||
#include "streams/voxel_stream_block_files.h"
|
||||
#include "streams/voxel_stream_file.h"
|
||||
#include "streams/voxel_stream_script.h"
|
||||
#include "terrain/voxel_box_mover.h"
|
||||
#include "terrain/voxel_lod_terrain.h"
|
||||
@ -71,7 +70,6 @@ void register_voxel_types() {
|
||||
|
||||
// Streams
|
||||
ClassDB::register_virtual_class<VoxelStream>();
|
||||
ClassDB::register_class<VoxelStreamFile>();
|
||||
ClassDB::register_class<VoxelStreamBlockFiles>();
|
||||
ClassDB::register_class<VoxelStreamRegionFiles>();
|
||||
ClassDB::register_class<VoxelStreamScript>();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "../../util/macros.h"
|
||||
#include "../../util/profiling.h"
|
||||
#include "../../util/utility.h"
|
||||
|
||||
#include <core/io/json.h>
|
||||
#include <core/os/os.h>
|
||||
#include <algorithm>
|
||||
@ -18,6 +19,8 @@ const uint8_t FORMAT_VERSION_LEGACY_1 = 1;
|
||||
const char *META_FILE_NAME = "meta.vxrm";
|
||||
} // namespace
|
||||
|
||||
thread_local VoxelBlockSerializerInternal VoxelStreamRegionFiles::_block_serializer;
|
||||
|
||||
VoxelStreamRegionFiles::VoxelStreamRegionFiles() {
|
||||
_meta.version = FORMAT_VERSION;
|
||||
_meta.block_size_po2 = 4;
|
||||
@ -287,7 +290,7 @@ VoxelFileResult VoxelStreamRegionFiles::save_meta() {
|
||||
|
||||
Error err;
|
||||
VoxelFileLockerWrite file_wlock(meta_path);
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::WRITE, &err);
|
||||
FileAccessRef f = FileAccess::open(meta_path, FileAccess::WRITE, &err);
|
||||
if (!f) {
|
||||
ERR_PRINT(String("Could not save {0}").format(varray(meta_path)));
|
||||
return VOXEL_FILE_CANT_OPEN;
|
||||
@ -334,7 +337,7 @@ VoxelFileResult VoxelStreamRegionFiles::load_meta() {
|
||||
{
|
||||
Error err;
|
||||
VoxelFileLockerRead file_rlock(meta_path);
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::READ, &err);
|
||||
FileAccessRef f = FileAccess::open(meta_path, FileAccess::READ, &err);
|
||||
if (!f) {
|
||||
return VOXEL_FILE_CANT_OPEN;
|
||||
}
|
||||
|
@ -3,7 +3,8 @@
|
||||
|
||||
#include "../../util/fixed_array.h"
|
||||
#include "../file_utils.h"
|
||||
#include "../voxel_stream_file.h"
|
||||
#include "../voxel_block_serializer.h"
|
||||
#include "../voxel_stream.h"
|
||||
#include "region_file.h"
|
||||
|
||||
class FileAccess;
|
||||
@ -17,8 +18,8 @@ class FileAccess;
|
||||
//
|
||||
// Region files are not thread-safe. Because of this, internal mutexing may often constrain the use by one thread only.
|
||||
//
|
||||
class VoxelStreamRegionFiles : public VoxelStreamFile {
|
||||
GDCLASS(VoxelStreamRegionFiles, VoxelStreamFile)
|
||||
class VoxelStreamRegionFiles : public VoxelStream {
|
||||
GDCLASS(VoxelStreamRegionFiles, VoxelStream)
|
||||
public:
|
||||
VoxelStreamRegionFiles();
|
||||
~VoxelStreamRegionFiles();
|
||||
@ -108,6 +109,8 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
static thread_local VoxelBlockSerializerInternal _block_serializer;
|
||||
|
||||
// TODO This is not thread-friendly.
|
||||
// `VoxelRegionFile` is not thread-safe so we have to limit the usage to one thread at once, blocking the others.
|
||||
// A refactoring should be done to allow better threading.
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "voxel_stream_block_files.h"
|
||||
#include "../server/voxel_server.h"
|
||||
#include "../util/utility.h"
|
||||
|
||||
#include <core/os/dir_access.h>
|
||||
#include <core/os/file_access.h>
|
||||
|
||||
@ -12,6 +13,8 @@ const char *META_FILE_NAME = "meta.vxbm";
|
||||
const char *BLOCK_FILE_EXTENSION = ".vxb";
|
||||
} // namespace
|
||||
|
||||
thread_local VoxelBlockSerializerInternal VoxelStreamBlockFiles::_block_serializer;
|
||||
|
||||
VoxelStreamBlockFiles::VoxelStreamBlockFiles() {
|
||||
// Defaults
|
||||
_meta.block_size_po2 = 4;
|
||||
@ -51,7 +54,7 @@ VoxelStream::Result VoxelStreamBlockFiles::emerge_block(
|
||||
VoxelFileLockerRead file_rlock(file_path);
|
||||
{
|
||||
Error err;
|
||||
f = open_file(file_path, FileAccess::READ, &err);
|
||||
f = FileAccess::open(file_path, FileAccess::READ, &err);
|
||||
// Had to add ERR_FILE_CANT_OPEN because that's what Godot actually returns when the file doesn't exist...
|
||||
if (f == nullptr && (err == ERR_FILE_NOT_FOUND || err == ERR_FILE_CANT_OPEN)) {
|
||||
return RESULT_BLOCK_NOT_FOUND;
|
||||
@ -135,7 +138,7 @@ void VoxelStreamBlockFiles::immerge_block(Ref<VoxelBuffer> buffer, Vector3i orig
|
||||
{
|
||||
Error err;
|
||||
// Create file if not exists, always truncate
|
||||
f = open_file(file_path, FileAccess::WRITE, &err);
|
||||
f = FileAccess::open(file_path, FileAccess::WRITE, &err);
|
||||
}
|
||||
ERR_FAIL_COND(f == nullptr);
|
||||
|
||||
@ -188,7 +191,7 @@ VoxelFileResult VoxelStreamBlockFiles::save_meta() {
|
||||
{
|
||||
Error err;
|
||||
VoxelFileLockerWrite file_wlock(meta_path);
|
||||
FileAccess *f = open_file(meta_path, FileAccess::WRITE, &err);
|
||||
FileAccess *f = FileAccess::open(meta_path, FileAccess::WRITE, &err);
|
||||
ERR_FAIL_COND_V(f == nullptr, VOXEL_FILE_CANT_OPEN);
|
||||
|
||||
f->store_buffer((uint8_t *)FORMAT_META_MAGIC, 4);
|
||||
@ -228,7 +231,7 @@ VoxelFileResult VoxelStreamBlockFiles::load_meta() {
|
||||
{
|
||||
Error open_result;
|
||||
VoxelFileLockerRead file_rlock(meta_path);
|
||||
FileAccessRef f = open_file(meta_path, FileAccess::READ, &open_result);
|
||||
FileAccessRef f = FileAccess::open(meta_path, FileAccess::READ, &open_result);
|
||||
// Had to add ERR_FILE_CANT_OPEN because that's what Godot actually returns when the file doesn't exist...
|
||||
if (!_meta_saved && (open_result == ERR_FILE_NOT_FOUND || open_result == ERR_FILE_CANT_OPEN)) {
|
||||
// This is a new terrain, save the meta we have and consider it current
|
||||
|
@ -2,15 +2,16 @@
|
||||
#define VOXEL_STREAM_BLOCK_FILES_H
|
||||
|
||||
#include "file_utils.h"
|
||||
#include "voxel_stream_file.h"
|
||||
#include "voxel_block_serializer.h"
|
||||
#include "voxel_stream.h"
|
||||
|
||||
class FileAccess;
|
||||
|
||||
// Loads and saves blocks to the filesystem, under a directory.
|
||||
// Each block gets its own file, which may produce a lot of them, but it makes it simple to implement.
|
||||
// This is a naive implementation and may be very slow in practice, so maybe it will be removed in the future.
|
||||
class VoxelStreamBlockFiles : public VoxelStreamFile {
|
||||
GDCLASS(VoxelStreamBlockFiles, VoxelStreamFile)
|
||||
class VoxelStreamBlockFiles : public VoxelStream {
|
||||
GDCLASS(VoxelStreamBlockFiles, VoxelStream)
|
||||
public:
|
||||
VoxelStreamBlockFiles();
|
||||
|
||||
@ -32,6 +33,8 @@ private:
|
||||
String get_block_file_path(const Vector3i &block_pos, unsigned int lod) const;
|
||||
Vector3i get_block_position(const Vector3i &origin_in_voxels) const;
|
||||
|
||||
static thread_local VoxelBlockSerializerInternal _block_serializer;
|
||||
|
||||
String _directory_path;
|
||||
|
||||
struct Meta {
|
||||
|
@ -1,20 +0,0 @@
|
||||
#include "voxel_stream_file.h"
|
||||
#include "../server/voxel_server.h"
|
||||
#include "../util/profiling.h"
|
||||
#include <core/os/file_access.h>
|
||||
#include <core/os/os.h>
|
||||
|
||||
thread_local VoxelBlockSerializerInternal VoxelStreamFile::_block_serializer;
|
||||
|
||||
FileAccess *VoxelStreamFile::open_file(const String &fpath, int mode_flags, Error *err) {
|
||||
VOXEL_PROFILE_SCOPE();
|
||||
//uint64_t time_before = OS::get_singleton()->get_ticks_usec();
|
||||
FileAccess *f = FileAccess::open(fpath, mode_flags, err);
|
||||
//uint64_t time_spent = OS::get_singleton()->get_ticks_usec() - time_before;
|
||||
//_stats.time_spent_opening_files += time_spent;
|
||||
//++_stats.file_openings;
|
||||
return f;
|
||||
}
|
||||
|
||||
void VoxelStreamFile::_bind_methods() {
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
#ifndef VOXEL_STREAM_FILE_H
|
||||
#define VOXEL_STREAM_FILE_H
|
||||
|
||||
#include "voxel_block_serializer.h"
|
||||
#include "voxel_stream.h"
|
||||
|
||||
class FileAccess;
|
||||
|
||||
// TODO Might be removed in the future, it doesn't add much.
|
||||
|
||||
// Helper common base for some file streams.
|
||||
class VoxelStreamFile : public VoxelStream {
|
||||
GDCLASS(VoxelStreamFile, VoxelStream)
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
|
||||
FileAccess *open_file(const String &fpath, int mode_flags, Error *err);
|
||||
|
||||
static thread_local VoxelBlockSerializerInternal _block_serializer;
|
||||
};
|
||||
|
||||
#endif // VOXEL_STREAM_FILE_H
|
@ -3,7 +3,6 @@
|
||||
#include "../math/rect3i.h"
|
||||
#include "../meshers/transvoxel/voxel_mesher_transvoxel.h"
|
||||
#include "../server/voxel_server.h"
|
||||
#include "../streams/voxel_stream_file.h"
|
||||
#include "../util/macros.h"
|
||||
#include "../util/profiling.h"
|
||||
#include "../util/profiling_clock.h"
|
||||
@ -291,9 +290,8 @@ void VoxelLodTerrain::set_block_size_po2(unsigned int p_block_size_po2) {
|
||||
ERR_FAIL_COND(p_block_size_po2 > 32);
|
||||
|
||||
unsigned int block_size_po2 = p_block_size_po2;
|
||||
Ref<VoxelStreamFile> file_stream = _stream;
|
||||
if (file_stream.is_valid()) {
|
||||
block_size_po2 = file_stream->get_block_size_po2();
|
||||
if (_stream.is_valid()) {
|
||||
block_size_po2 = _stream->get_block_size_po2();
|
||||
}
|
||||
|
||||
if (block_size_po2 == get_block_size_pow2()) {
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "voxel_terrain.h"
|
||||
#include "../edition/voxel_tool_terrain.h"
|
||||
#include "../server/voxel_server.h"
|
||||
#include "../streams/voxel_stream_file.h"
|
||||
#include "../util/macros.h"
|
||||
#include "../util/profiling.h"
|
||||
#include "../util/profiling_clock.h"
|
||||
@ -136,9 +135,8 @@ void VoxelTerrain::set_block_size_po2(unsigned int p_block_size_po2) {
|
||||
ERR_FAIL_COND(p_block_size_po2 > 32);
|
||||
|
||||
unsigned int block_size_po2 = p_block_size_po2;
|
||||
Ref<VoxelStreamFile> file_stream = _stream;
|
||||
if (file_stream.is_valid()) {
|
||||
block_size_po2 = file_stream->get_block_size_po2();
|
||||
if (_stream.is_valid()) {
|
||||
block_size_po2 = _stream->get_block_size_po2();
|
||||
}
|
||||
|
||||
if (block_size_po2 == get_block_size_pow2()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user