2016-05-01 06:00:02 -07:00
|
|
|
#include "register_types.h"
|
2021-12-30 21:06:00 -08:00
|
|
|
#include "constants/voxel_string_names.h"
|
2020-01-26 12:29:44 -08:00
|
|
|
#include "edition/voxel_tool.h"
|
2021-01-17 14:18:41 -08:00
|
|
|
#include "edition/voxel_tool_buffer.h"
|
2021-02-20 19:06:40 -08:00
|
|
|
#include "edition/voxel_tool_lod_terrain.h"
|
2020-07-28 12:32:33 -07:00
|
|
|
#include "edition/voxel_tool_terrain.h"
|
2020-02-19 11:26:14 -08:00
|
|
|
#include "generators/graph/voxel_generator_graph.h"
|
2020-02-23 11:08:14 -08:00
|
|
|
#include "generators/graph/voxel_graph_node_db.h"
|
2020-12-18 13:19:02 -08:00
|
|
|
#include "generators/simple/voxel_generator_flat.h"
|
|
|
|
#include "generators/simple/voxel_generator_heightmap.h"
|
|
|
|
#include "generators/simple/voxel_generator_image.h"
|
|
|
|
#include "generators/simple/voxel_generator_noise.h"
|
|
|
|
#include "generators/simple/voxel_generator_noise_2d.h"
|
|
|
|
#include "generators/simple/voxel_generator_waves.h"
|
2020-10-31 15:11:25 -07:00
|
|
|
#include "generators/voxel_generator_script.h"
|
2022-01-09 15:23:59 -08:00
|
|
|
#include "meshers/blocky/voxel_blocky_library.h"
|
2019-04-28 09:58:29 -07:00
|
|
|
#include "meshers/blocky/voxel_mesher_blocky.h"
|
2020-09-10 16:36:23 -07:00
|
|
|
#include "meshers/cubes/voxel_mesher_cubes.h"
|
2019-04-28 09:58:29 -07:00
|
|
|
#include "meshers/dmc/voxel_mesher_dmc.h"
|
|
|
|
#include "meshers/transvoxel/voxel_mesher_transvoxel.h"
|
2022-01-08 20:53:33 -08:00
|
|
|
#include "server/voxel_server_gd.h"
|
2022-02-15 13:49:20 -08:00
|
|
|
#include "storage/voxel_buffer_gd.h"
|
2020-09-14 11:33:02 -07:00
|
|
|
#include "storage/voxel_memory_pool.h"
|
2021-01-31 08:51:42 -08:00
|
|
|
#include "streams/region/voxel_stream_region_files.h"
|
2021-01-28 14:02:49 -08:00
|
|
|
#include "streams/sqlite/voxel_stream_sqlite.h"
|
2020-09-12 13:10:05 -07:00
|
|
|
#include "streams/vox_loader.h"
|
2022-02-12 15:52:44 -08:00
|
|
|
#include "streams/voxel_block_serializer_gd.h"
|
2019-08-23 17:44:27 -07:00
|
|
|
#include "streams/voxel_stream_block_files.h"
|
2020-10-31 15:11:25 -07:00
|
|
|
#include "streams/voxel_stream_script.h"
|
2022-03-20 15:57:53 -07:00
|
|
|
#include "terrain/fixed_lod/voxel_box_mover.h"
|
|
|
|
#include "terrain/fixed_lod/voxel_terrain.h"
|
2021-12-30 21:06:00 -08:00
|
|
|
#include "terrain/instancing/voxel_instance_component.h"
|
|
|
|
#include "terrain/instancing/voxel_instance_library_scene_item.h"
|
2021-02-07 13:40:55 -08:00
|
|
|
#include "terrain/instancing/voxel_instancer.h"
|
2022-03-20 15:57:53 -07:00
|
|
|
#include "terrain/variable_lod/voxel_lod_terrain.h"
|
2021-04-15 12:25:55 -07:00
|
|
|
#include "terrain/voxel_mesh_block.h"
|
2020-09-06 11:01:12 -07:00
|
|
|
#include "terrain/voxel_viewer.h"
|
2020-08-31 13:51:30 -07:00
|
|
|
#include "util/macros.h"
|
2022-04-03 12:07:17 -07:00
|
|
|
#include "util/noise/fast_noise_lite/fast_noise_lite.h"
|
|
|
|
#include "util/noise/fast_noise_lite/fast_noise_lite_gradient.h"
|
2022-04-07 14:34:07 -07:00
|
|
|
#include "util/tasks/godot/threaded_task_gd.h"
|
2021-01-01 16:59:12 -08:00
|
|
|
|
2021-12-30 21:06:00 -08:00
|
|
|
#ifdef VOXEL_ENABLE_FAST_NOISE_2
|
|
|
|
#include "util/noise/fast_noise_2.h"
|
|
|
|
#endif
|
|
|
|
|
2021-12-13 13:38:10 -08:00
|
|
|
#include <core/config/engine.h>
|
2016-05-01 06:00:02 -07:00
|
|
|
|
2020-10-23 16:08:14 -07:00
|
|
|
#ifdef TOOLS_ENABLED
|
2021-07-31 10:48:47 -07:00
|
|
|
#include "editor/editor_plugin.h"
|
|
|
|
#include "editor/fast_noise_lite/fast_noise_lite_editor_plugin.h"
|
|
|
|
#include "editor/graph/voxel_graph_editor_plugin.h"
|
|
|
|
#include "editor/instance_library/voxel_instance_library_editor_plugin.h"
|
2021-12-30 14:20:30 -08:00
|
|
|
#include "editor/instancer/voxel_instancer_editor_plugin.h"
|
2021-07-31 10:48:47 -07:00
|
|
|
#include "editor/terrain/voxel_terrain_editor_plugin.h"
|
|
|
|
#include "editor/vox/vox_editor_plugin.h"
|
2020-10-23 16:08:14 -07:00
|
|
|
#include "editor/voxel_debug.h"
|
2021-12-30 21:06:00 -08:00
|
|
|
#ifdef VOXEL_ENABLE_FAST_NOISE_2
|
|
|
|
#include "editor/fast_noise_2/fast_noise_2_editor_plugin.h"
|
2020-10-23 16:08:14 -07:00
|
|
|
#endif
|
2021-12-30 21:06:00 -08:00
|
|
|
#endif // TOOLS_ENABLED
|
2020-10-23 16:08:14 -07:00
|
|
|
|
2021-04-03 12:40:35 -07:00
|
|
|
#ifdef VOXEL_RUN_TESTS
|
|
|
|
#include "tests/tests.h"
|
|
|
|
#endif
|
|
|
|
|
2016-05-01 06:00:02 -07:00
|
|
|
void register_voxel_types() {
|
2022-01-03 15:20:38 -08:00
|
|
|
using namespace zylann;
|
|
|
|
using namespace voxel;
|
|
|
|
|
2020-08-10 12:57:03 -07:00
|
|
|
VoxelMemoryPool::create_singleton();
|
|
|
|
VoxelStringNames::create_singleton();
|
2022-01-03 15:20:38 -08:00
|
|
|
VoxelGraphNodeDB::create_singleton();
|
2020-08-25 15:00:38 -07:00
|
|
|
VoxelServer::create_singleton();
|
2022-01-08 20:53:33 -08:00
|
|
|
gd::VoxelServer::create_singleton();
|
2020-08-10 12:57:03 -07:00
|
|
|
|
2022-01-08 20:53:33 -08:00
|
|
|
Engine::get_singleton()->add_singleton(Engine::Singleton("VoxelServer", gd::VoxelServer::get_singleton()));
|
2020-08-26 13:17:57 -07:00
|
|
|
|
|
|
|
// TODO Can I prevent users from instancing it? is "register_virtual_class" correct for a class that's not abstract?
|
2022-01-08 20:53:33 -08:00
|
|
|
ClassDB::register_class<gd::VoxelServer>();
|
2020-08-26 13:17:57 -07:00
|
|
|
|
2021-02-14 13:55:31 -08:00
|
|
|
// Misc
|
2022-01-09 15:23:59 -08:00
|
|
|
ClassDB::register_class<VoxelBlockyModel>();
|
|
|
|
ClassDB::register_class<VoxelBlockyLibrary>();
|
2020-09-12 18:17:11 -07:00
|
|
|
ClassDB::register_class<VoxelColorPalette>();
|
2021-02-14 13:55:31 -08:00
|
|
|
ClassDB::register_class<VoxelInstanceLibrary>();
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelInstanceLibraryItem>();
|
2022-01-10 14:56:18 -08:00
|
|
|
ClassDB::register_class<VoxelInstanceLibraryMultiMeshItem>();
|
2021-07-25 12:37:30 -07:00
|
|
|
ClassDB::register_class<VoxelInstanceLibrarySceneItem>();
|
2022-01-31 13:23:39 -08:00
|
|
|
ClassDB::register_class<VoxelDataBlockEnterInfo>();
|
2020-09-12 18:17:11 -07:00
|
|
|
|
2019-04-28 09:58:29 -07:00
|
|
|
// Storage
|
2022-02-15 13:49:20 -08:00
|
|
|
ClassDB::register_class<gd::VoxelBuffer>();
|
2019-04-28 09:58:29 -07:00
|
|
|
|
|
|
|
// Nodes
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelNode>();
|
2017-03-24 17:23:36 -07:00
|
|
|
ClassDB::register_class<VoxelTerrain>();
|
2019-05-03 16:02:10 -07:00
|
|
|
ClassDB::register_class<VoxelLodTerrain>();
|
2020-09-06 11:01:12 -07:00
|
|
|
ClassDB::register_class<VoxelViewer>();
|
2021-02-07 13:30:07 -08:00
|
|
|
ClassDB::register_class<VoxelInstanceGenerator>();
|
2021-02-14 13:55:31 -08:00
|
|
|
ClassDB::register_class<VoxelInstancer>();
|
2021-07-25 12:37:30 -07:00
|
|
|
ClassDB::register_class<VoxelInstanceComponent>();
|
2019-04-28 09:58:29 -07:00
|
|
|
|
2019-05-27 16:40:09 -07:00
|
|
|
// Streams
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelStream>();
|
2019-08-17 11:43:08 -07:00
|
|
|
ClassDB::register_class<VoxelStreamBlockFiles>();
|
2019-08-17 11:56:21 -07:00
|
|
|
ClassDB::register_class<VoxelStreamRegionFiles>();
|
2020-10-31 15:11:25 -07:00
|
|
|
ClassDB::register_class<VoxelStreamScript>();
|
2021-01-28 14:02:49 -08:00
|
|
|
ClassDB::register_class<VoxelStreamSQLite>();
|
2019-04-28 09:58:29 -07:00
|
|
|
|
2020-01-26 14:34:26 -08:00
|
|
|
// Generators
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelGenerator>();
|
2020-02-17 14:05:16 -08:00
|
|
|
ClassDB::register_class<VoxelGeneratorFlat>();
|
|
|
|
ClassDB::register_class<VoxelGeneratorWaves>();
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelGeneratorHeightmap>();
|
2020-01-26 14:34:26 -08:00
|
|
|
ClassDB::register_class<VoxelGeneratorImage>();
|
|
|
|
ClassDB::register_class<VoxelGeneratorNoise2D>();
|
|
|
|
ClassDB::register_class<VoxelGeneratorNoise>();
|
2020-02-19 11:26:14 -08:00
|
|
|
ClassDB::register_class<VoxelGeneratorGraph>();
|
2020-10-31 15:11:25 -07:00
|
|
|
ClassDB::register_class<VoxelGeneratorScript>();
|
2020-01-26 14:34:26 -08:00
|
|
|
|
2020-09-12 18:17:11 -07:00
|
|
|
// Utilities
|
2018-09-30 16:11:33 -07:00
|
|
|
ClassDB::register_class<VoxelBoxMover>();
|
2019-09-24 10:48:30 -07:00
|
|
|
ClassDB::register_class<VoxelRaycastResult>();
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelTool>();
|
|
|
|
ClassDB::register_abstract_class<VoxelToolTerrain>();
|
|
|
|
ClassDB::register_abstract_class<VoxelToolLodTerrain>();
|
2021-01-17 14:18:41 -08:00
|
|
|
// I had to bind this one despite it being useless as-is because otherwise Godot lazily initializes its class.
|
|
|
|
// And this can happen in a thread, causing crashes due to the concurrent access
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelToolBuffer>();
|
2022-02-12 15:52:44 -08:00
|
|
|
ClassDB::register_class<gd::VoxelBlockSerializer>();
|
2020-09-12 13:10:05 -07:00
|
|
|
ClassDB::register_class<VoxelVoxLoader>();
|
2022-04-03 12:07:17 -07:00
|
|
|
ClassDB::register_class<ZN_FastNoiseLite>();
|
|
|
|
ClassDB::register_class<ZN_FastNoiseLiteGradient>();
|
2022-04-07 14:34:07 -07:00
|
|
|
ClassDB::register_class<ZN_ThreadedTask>();
|
2021-02-20 19:02:32 -08:00
|
|
|
// See SCsub
|
2021-12-30 21:06:00 -08:00
|
|
|
#ifdef VOXEL_ENABLE_FAST_NOISE_2
|
2021-02-20 19:02:32 -08:00
|
|
|
ClassDB::register_class<FastNoise2>();
|
|
|
|
#endif
|
2019-04-28 09:58:29 -07:00
|
|
|
|
|
|
|
// Meshers
|
2022-03-13 17:26:25 -07:00
|
|
|
ClassDB::register_abstract_class<VoxelMesher>();
|
2019-04-28 09:58:29 -07:00
|
|
|
ClassDB::register_class<VoxelMesherBlocky>();
|
|
|
|
ClassDB::register_class<VoxelMesherTransvoxel>();
|
|
|
|
ClassDB::register_class<VoxelMesherDMC>();
|
2020-09-10 16:36:23 -07:00
|
|
|
ClassDB::register_class<VoxelMesherCubes>();
|
2019-08-29 14:55:02 -07:00
|
|
|
|
2020-02-22 14:45:22 -08:00
|
|
|
// Reminder: how to create a singleton accessible from scripts:
|
|
|
|
// Engine::get_singleton()->add_singleton(Engine::Singleton("SingletonName",singleton_instance));
|
|
|
|
|
2022-02-15 13:49:20 -08:00
|
|
|
// Reminders
|
2022-04-09 07:00:34 -07:00
|
|
|
ZN_PRINT_VERBOSE(format("Size of Variant: {}", sizeof(Variant)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of Object: {}", sizeof(Object)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of RefCounted: {}", sizeof(RefCounted)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of Node: {}", sizeof(Node)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of Node3D: {}", sizeof(Node3D)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of gd::VoxelBuffer: {}", sizeof(gd::VoxelBuffer)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelBufferInternal: {}", sizeof(VoxelBufferInternal)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelMeshBlock: {}", sizeof(VoxelMeshBlock)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelTerrain: {}", sizeof(VoxelTerrain)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelLodTerrain: {}", sizeof(VoxelLodTerrain)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelInstancer: {}", sizeof(VoxelInstancer)));
|
|
|
|
ZN_PRINT_VERBOSE(format("Size of VoxelDataMap: {}", sizeof(VoxelDataMap)));
|
2020-08-29 14:09:54 -07:00
|
|
|
|
2019-08-29 14:55:02 -07:00
|
|
|
#ifdef TOOLS_ENABLED
|
2020-03-01 10:12:16 -08:00
|
|
|
EditorPlugins::add_by_type<VoxelGraphEditorPlugin>();
|
2020-08-14 12:33:09 -07:00
|
|
|
EditorPlugins::add_by_type<VoxelTerrainEditorPlugin>();
|
2021-02-14 13:55:31 -08:00
|
|
|
EditorPlugins::add_by_type<VoxelInstanceLibraryEditorPlugin>();
|
2022-04-03 12:07:17 -07:00
|
|
|
EditorPlugins::add_by_type<ZN_FastNoiseLiteEditorPlugin>();
|
2022-01-09 14:13:10 -08:00
|
|
|
EditorPlugins::add_by_type<magica::VoxEditorPlugin>();
|
2021-12-30 14:20:30 -08:00
|
|
|
EditorPlugins::add_by_type<VoxelInstancerEditorPlugin>();
|
2021-12-30 21:06:00 -08:00
|
|
|
#ifdef VOXEL_ENABLE_FAST_NOISE_2
|
|
|
|
EditorPlugins::add_by_type<FastNoise2EditorPlugin>();
|
2019-08-29 14:55:02 -07:00
|
|
|
#endif
|
2021-12-30 21:06:00 -08:00
|
|
|
#endif // TOOLS_ENABLED
|
2021-04-03 12:40:35 -07:00
|
|
|
|
|
|
|
#ifdef VOXEL_RUN_TESTS
|
2021-12-17 11:30:23 -08:00
|
|
|
zylann::voxel::tests::run_voxel_tests();
|
2021-04-03 12:40:35 -07:00
|
|
|
#endif
|
2022-01-09 15:23:59 -08:00
|
|
|
|
|
|
|
// Compatibility with older version
|
|
|
|
ClassDB::add_compatibility_class("VoxelLibrary", "VoxelBlockyLibrary");
|
|
|
|
ClassDB::add_compatibility_class("Voxel", "VoxelBlockyModel");
|
2022-01-10 14:56:18 -08:00
|
|
|
ClassDB::add_compatibility_class("VoxelInstanceLibraryItem", "VoxelInstanceLibraryMultiMeshItem");
|
|
|
|
// Not possible to add a compat class for this one because the new name is indistinguishable from an old one.
|
|
|
|
// However this is an abstract class so it should not be found in resources hopefully
|
|
|
|
//ClassDB::add_compatibility_class("VoxelInstanceLibraryItemBase", "VoxelInstanceLibraryItem");
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void unregister_voxel_types() {
|
2022-01-03 15:20:38 -08:00
|
|
|
using namespace zylann;
|
|
|
|
using namespace voxel;
|
|
|
|
|
2020-08-29 14:55:52 -07:00
|
|
|
// At this point, the GDScript module has nullified GDScriptLanguage::singleton!!
|
2020-08-29 14:09:54 -07:00
|
|
|
// 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...
|
2020-08-29 14:55:52 -07:00
|
|
|
// See https://github.com/Zylann/godot_voxel/issues/189
|
2020-08-29 14:09:54 -07:00
|
|
|
|
2020-08-25 15:00:38 -07:00
|
|
|
VoxelStringNames::destroy_singleton();
|
2022-01-03 15:20:38 -08:00
|
|
|
VoxelGraphNodeDB::destroy_singleton();
|
2022-01-08 20:53:33 -08:00
|
|
|
gd::VoxelServer::destroy_singleton();
|
2020-08-25 15:00:38 -07:00
|
|
|
VoxelServer::destroy_singleton();
|
|
|
|
|
|
|
|
// Do this last as VoxelServer might still be holding some refs to voxel blocks
|
2022-04-09 07:05:04 -07:00
|
|
|
const unsigned int used_blocks = VoxelMemoryPool::get_singleton().debug_get_used_blocks();
|
2020-01-25 17:59:53 -08:00
|
|
|
if (used_blocks > 0) {
|
2020-08-25 15:00:38 -07:00
|
|
|
ERR_PRINT(String("VoxelMemoryPool: "
|
|
|
|
"{0} memory blocks are still used when unregistering the module. Recycling leak?")
|
|
|
|
.format(varray(used_blocks)));
|
2020-01-25 17:59:53 -08:00
|
|
|
}
|
2020-02-19 13:59:41 -08:00
|
|
|
VoxelMemoryPool::destroy_singleton();
|
2020-08-26 13:17:57 -07:00
|
|
|
// TODO No remove?
|
2020-02-19 11:26:14 -08:00
|
|
|
|
2019-08-29 14:55:02 -07:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-01-04 14:57:21 -08:00
|
|
|
zylann::free_debug_resources();
|
2020-03-01 10:12:16 -08:00
|
|
|
|
2020-08-26 13:17:57 -07:00
|
|
|
// TODO Seriously, no remove?
|
2020-03-01 10:12:16 -08:00
|
|
|
//EditorPlugins::remove_by_type<VoxelGraphEditorPlugin>();
|
2019-08-29 14:55:02 -07:00
|
|
|
#endif
|
2016-05-01 06:00:02 -07:00
|
|
|
}
|