Namespace VoxelMemoryPool
parent
e20684ce69
commit
5ece3b840e
|
@ -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> mesh;
|
||||
std::vector<unsigned int> surface_index_to_material;
|
||||
{
|
||||
std::vector<zylann::voxel::magica::ModelInstance> model_instances;
|
||||
std::vector<magica::ModelInstance> model_instances;
|
||||
extract_model_instances(vox_data, model_instances);
|
||||
|
||||
// From this point we no longer need vox data so we can free some memory
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include <thread>
|
||||
|
||||
using namespace zylann;
|
||||
using namespace voxel;
|
||||
|
||||
namespace {
|
||||
VoxelServer *g_voxel_server = nullptr;
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
#include <core/math/math_funcs.h>
|
||||
#include <string.h>
|
||||
|
||||
using namespace zylann;
|
||||
using namespace voxel;
|
||||
|
||||
namespace {
|
||||
|
||||
inline uint8_t *allocate_channel_data(size_t size) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
#include <core/string/print_string.h>
|
||||
#include <core/variant/variant.h>
|
||||
|
||||
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
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
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<unsigned int>::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
|
||||
|
|
Loading…
Reference in New Issue