godot_voxel/register_types.cpp

115 lines
3.9 KiB
C++
Raw Normal View History

#include "register_types.h"
#include "edition/voxel_tool.h"
#include "edition/voxel_tool_terrain.h"
#include "editor/editor_plugin.h"
#include "editor/graph/voxel_graph_editor_plugin.h"
#include "editor/terrain/voxel_terrain_editor_plugin.h"
#include "generators/graph/voxel_generator_graph.h"
2020-02-23 11:08:14 -08:00
#include "generators/graph/voxel_graph_node_db.h"
#include "generators/voxel_generator_flat.h"
2020-01-26 14:43:47 -08:00
#include "generators/voxel_generator_heightmap.h"
#include "generators/voxel_generator_image.h"
#include "generators/voxel_generator_noise.h"
#include "generators/voxel_generator_noise_2d.h"
#include "generators/voxel_generator_waves.h"
#include "meshers/blocky/voxel_library.h"
#include "meshers/blocky/voxel_mesher_blocky.h"
#include "meshers/dmc/voxel_mesher_dmc.h"
#include "meshers/transvoxel/voxel_mesher_transvoxel.h"
#include "streams/voxel_stream_block_files.h"
#include "streams/voxel_stream_file.h"
#include "streams/voxel_stream_region_files.h"
#include "terrain/voxel_box_mover.h"
#include "terrain/voxel_lod_terrain.h"
#include "terrain/voxel_map.h"
#include "terrain/voxel_terrain.h"
#include "voxel_buffer.h"
#include "voxel_memory_pool.h"
2020-01-17 12:43:28 -08:00
#include "voxel_string_names.h"
void register_voxel_types() {
VoxelMemoryPool::create_singleton();
VoxelStringNames::create_singleton();
VoxelGraphNodeDB::create_singleton();
VoxelServer::create_singleton();
2020-08-26 13:17:57 -07:00
Engine::get_singleton()->add_singleton(Engine::Singleton("VoxelServer", VoxelServer::get_singleton()));
// TODO Can I prevent users from instancing it? is "register_virtual_class" correct for a class that's not abstract?
ClassDB::register_class<VoxelServer>();
// Storage
2017-03-24 17:23:36 -07:00
ClassDB::register_class<VoxelBuffer>();
ClassDB::register_class<VoxelMap>();
// Voxel types
ClassDB::register_class<Voxel>();
ClassDB::register_class<VoxelLibrary>();
// Nodes
2017-03-24 17:23:36 -07:00
ClassDB::register_class<VoxelTerrain>();
ClassDB::register_class<VoxelLodTerrain>();
// Streams
2019-05-25 08:07:38 -07:00
ClassDB::register_class<VoxelStream>();
ClassDB::register_class<VoxelStreamFile>();
ClassDB::register_class<VoxelStreamBlockFiles>();
ClassDB::register_class<VoxelStreamRegionFiles>();
// Generators
ClassDB::register_class<VoxelGenerator>();
ClassDB::register_class<VoxelGeneratorFlat>();
ClassDB::register_class<VoxelGeneratorWaves>();
ClassDB::register_class<VoxelGeneratorHeightmap>();
ClassDB::register_class<VoxelGeneratorImage>();
ClassDB::register_class<VoxelGeneratorNoise2D>();
ClassDB::register_class<VoxelGeneratorNoise>();
ClassDB::register_class<VoxelGeneratorGraph>();
// Helpers
ClassDB::register_class<VoxelBoxMover>();
ClassDB::register_class<VoxelRaycastResult>();
2019-09-03 14:54:40 -07:00
ClassDB::register_class<VoxelTool>();
ClassDB::register_class<VoxelToolTerrain>();
2020-07-25 13:56:23 -07:00
ClassDB::register_class<VoxelBlockSerializer>();
// Meshers
ClassDB::register_class<VoxelMesher>();
ClassDB::register_class<VoxelMesherBlocky>();
ClassDB::register_class<VoxelMesherTransvoxel>();
ClassDB::register_class<VoxelMesherDMC>();
2019-08-29 14:55:02 -07:00
// Reminder: how to create a singleton accessible from scripts:
// Engine::get_singleton()->add_singleton(Engine::Singleton("SingletonName",singleton_instance));
2019-08-29 14:55:02 -07:00
#ifdef TOOLS_ENABLED
VoxelDebug::create_debug_box_mesh();
EditorPlugins::add_by_type<VoxelGraphEditorPlugin>();
EditorPlugins::add_by_type<VoxelTerrainEditorPlugin>();
2019-08-29 14:55:02 -07:00
#endif
}
void unregister_voxel_types() {
VoxelStringNames::destroy_singleton();
VoxelGraphNodeDB::destroy_singleton();
VoxelServer::destroy_singleton();
// Do this last as VoxelServer might still be holding some refs to voxel blocks
2020-01-25 17:59:53 -08:00
unsigned int used_blocks = VoxelMemoryPool::get_singleton()->debug_get_used_blocks();
if (used_blocks > 0) {
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?
2019-08-29 14:55:02 -07:00
#ifdef TOOLS_ENABLED
VoxelDebug::free_debug_box_mesh();
2020-08-26 13:17:57 -07:00
// TODO Seriously, no remove?
//EditorPlugins::remove_by_type<VoxelGraphEditorPlugin>();
2019-08-29 14:55:02 -07:00
#endif
}