From 5ece3b840e267ca9a5e942d01b50fac0ffc16b6b Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Mon, 3 Jan 2022 23:20:38 +0000 Subject: [PATCH] Namespace VoxelMemoryPool --- editor/vox/vox_mesh_importer.cpp | 7 +++++-- register_types.cpp | 10 ++++++++-- server/voxel_server.cpp | 1 + storage/voxel_buffer_internal.cpp | 3 +++ storage/voxel_memory_pool.cpp | 4 ++++ storage/voxel_memory_pool.h | 6 +++++- 6 files changed, 26 insertions(+), 5 deletions(-) diff --git a/editor/vox/vox_mesh_importer.cpp b/editor/vox/vox_mesh_importer.cpp index f8cc96e3..a57c35d9 100644 --- a/editor/vox/vox_mesh_importer.cpp +++ b/editor/vox/vox_mesh_importer.cpp @@ -8,6 +8,9 @@ #include "../../util/profiling.h" #include "vox_import_funcs.h" +using namespace zylann; +using namespace voxel; + String VoxelVoxMeshImporter::get_importer_name() const { return "VoxelVoxMeshImporter"; } @@ -225,7 +228,7 @@ Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_ ERR_FAIL_INDEX_V(p_pivot_mode, PIVOT_MODES_COUNT, ERR_INVALID_PARAMETER); - zylann::voxel::magica::Data vox_data; + magica::Data vox_data; const Error load_err = vox_data.load_from_file(p_source_file); ERR_FAIL_COND_V(load_err != OK, load_err); @@ -246,7 +249,7 @@ Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_ Ref mesh; std::vector surface_index_to_material; { - std::vector model_instances; + std::vector model_instances; extract_model_instances(vox_data, model_instances); // From this point we no longer need vox data so we can free some memory diff --git a/register_types.cpp b/register_types.cpp index 1e3882bd..a56fbab3 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -62,9 +62,12 @@ #endif void register_voxel_types() { + using namespace zylann; + using namespace voxel; + VoxelMemoryPool::create_singleton(); VoxelStringNames::create_singleton(); - zylann::voxel::VoxelGraphNodeDB::create_singleton(); + VoxelGraphNodeDB::create_singleton(); VoxelServer::create_singleton(); Engine::get_singleton()->add_singleton(Engine::Singleton("VoxelServer", VoxelServer::get_singleton())); @@ -168,13 +171,16 @@ void register_voxel_types() { } void unregister_voxel_types() { + using namespace zylann; + using namespace voxel; + // At this point, the GDScript module has nullified GDScriptLanguage::singleton!! // That means it's impossible to free scripts still referenced by VoxelServer. And that can happen, because // users can write custom generators, which run inside threads, and these threads are hosted in the server... // See https://github.com/Zylann/godot_voxel/issues/189 VoxelStringNames::destroy_singleton(); - zylann::voxel::VoxelGraphNodeDB::destroy_singleton(); + VoxelGraphNodeDB::destroy_singleton(); VoxelServer::destroy_singleton(); // Do this last as VoxelServer might still be holding some refs to voxel blocks diff --git a/server/voxel_server.cpp b/server/voxel_server.cpp index 5881bea5..6fa3778a 100644 --- a/server/voxel_server.cpp +++ b/server/voxel_server.cpp @@ -12,6 +12,7 @@ #include using namespace zylann; +using namespace voxel; namespace { VoxelServer *g_voxel_server = nullptr; diff --git a/storage/voxel_buffer_internal.cpp b/storage/voxel_buffer_internal.cpp index 3a8f4b6a..bed48358 100644 --- a/storage/voxel_buffer_internal.cpp +++ b/storage/voxel_buffer_internal.cpp @@ -13,6 +13,9 @@ #include #include +using namespace zylann; +using namespace voxel; + namespace { inline uint8_t *allocate_channel_data(size_t size) { diff --git a/storage/voxel_memory_pool.cpp b/storage/voxel_memory_pool.cpp index 3feae4e7..ccc8d1da 100644 --- a/storage/voxel_memory_pool.cpp +++ b/storage/voxel_memory_pool.cpp @@ -6,6 +6,8 @@ #include #include +namespace zylann::voxel { + namespace { VoxelMemoryPool *g_memory_pool = nullptr; } // namespace @@ -163,3 +165,5 @@ size_t VoxelMemoryPool::debug_get_total_memory() const { //MutexLock lock(_mutex); return _total_memory; } + +} // namespace zylann::voxel diff --git a/storage/voxel_memory_pool.h b/storage/voxel_memory_pool.h index 09353c5e..38fdb5f6 100644 --- a/storage/voxel_memory_pool.h +++ b/storage/voxel_memory_pool.h @@ -9,6 +9,8 @@ #include #include +namespace zylann::voxel { + // Pool based on a scenario where allocated blocks are often the same size. // A pool of blocks is assigned for each power of two. // The majority of VoxelBuffers use powers of two so most of the time @@ -78,7 +80,7 @@ private: // `get_next_power_of_two_32` takes unsigned int CRASH_COND(size > std::numeric_limits::max()); #endif - return zylann::math::get_shift_from_power_of_two_32(zylann::math::get_next_power_of_two_32(size)); + return math::get_shift_from_power_of_two_32(math::get_next_power_of_two_32(size)); } inline size_t get_size_from_pool_index(unsigned int i) const { @@ -99,4 +101,6 @@ private: size_t _total_memory = 0; }; +} // namespace zylann::voxel + #endif // VOXEL_MEMORY_POOL_H