From b67ca3d903b8753009f9dcf08e3362e48d80602f Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Sun, 9 Jan 2022 22:13:10 +0000 Subject: [PATCH] Namespaced every registered class --- doc/source/getting_the_module.md | 2 +- doc/source/module_development.md | 5 +- edition/voxel_raycast_result.cpp | 4 ++ edition/voxel_raycast_result.h | 4 ++ edition/voxel_tool.cpp | 5 +- edition/voxel_tool.h | 10 ++- edition/voxel_tool_buffer.cpp | 5 +- edition/voxel_tool_buffer.h | 4 ++ edition/voxel_tool_lod_terrain.cpp | 28 ++++----- edition/voxel_tool_lod_terrain.h | 7 ++- edition/voxel_tool_terrain.cpp | 5 +- edition/voxel_tool_terrain.h | 12 ++-- editor/about_window.cpp | 4 ++ editor/about_window.h | 4 ++ .../fast_noise_2_editor_plugin.cpp | 4 ++ .../fast_noise_2/fast_noise_2_editor_plugin.h | 4 ++ .../fast_noise_lite_editor_plugin.cpp | 4 ++ .../fast_noise_lite_editor_plugin.h | 4 ++ editor/graph/voxel_graph_editor.cpp | 7 ++- editor/graph/voxel_graph_editor.h | 11 +++- editor/graph/voxel_graph_editor_plugin.cpp | 4 ++ editor/graph/voxel_graph_editor_plugin.h | 5 +- .../voxel_graph_node_inspector_wrapper.cpp | 5 +- .../voxel_graph_node_inspector_wrapper.h | 6 +- .../voxel_instance_library_editor_plugin.cpp | 6 +- .../voxel_instance_library_editor_plugin.h | 9 ++- .../voxel_instancer_editor_plugin.cpp | 4 ++ .../instancer/voxel_instancer_editor_plugin.h | 4 ++ .../terrain/voxel_terrain_editor_plugin.cpp | 5 +- editor/terrain/voxel_terrain_editor_plugin.h | 5 ++ editor/vox/vox_editor_plugin.cpp | 4 ++ editor/vox/vox_editor_plugin.h | 4 ++ editor/vox/vox_importer.cpp | 12 ++-- editor/vox/vox_importer.h | 4 ++ editor/vox/vox_mesh_importer.cpp | 21 +++---- editor/vox/vox_mesh_importer.h | 4 ++ generators/graph/voxel_generator_graph.cpp | 13 ++-- generators/graph/voxel_generator_graph.h | 39 ++++++------ generators/simple/voxel_generator_flat.cpp | 4 +- generators/simple/voxel_generator_flat.h | 6 +- .../simple/voxel_generator_heightmap.cpp | 4 +- generators/simple/voxel_generator_heightmap.h | 10 ++- generators/simple/voxel_generator_image.cpp | 5 +- generators/simple/voxel_generator_image.h | 4 ++ generators/simple/voxel_generator_noise.cpp | 4 +- generators/simple/voxel_generator_noise.h | 6 +- .../simple/voxel_generator_noise_2d.cpp | 4 +- generators/simple/voxel_generator_noise_2d.h | 4 ++ generators/simple/voxel_generator_waves.h | 4 ++ generators/voxel_generator.cpp | 4 +- generators/voxel_generator.h | 8 ++- generators/voxel_generator_script.cpp | 4 ++ generators/voxel_generator_script.h | 4 ++ meshers/blocky/voxel.cpp | 45 ++++++------- meshers/blocky/voxel.h | 36 ++++++----- meshers/blocky/voxel_library.cpp | 5 +- meshers/blocky/voxel_library.h | 6 +- meshers/blocky/voxel_mesher_blocky.cpp | 7 +-- meshers/blocky/voxel_mesher_blocky.h | 6 +- meshers/cubes/voxel_color_palette.cpp | 4 +- meshers/cubes/voxel_color_palette.h | 10 ++- meshers/cubes/voxel_mesher_cubes.cpp | 7 +-- meshers/cubes/voxel_mesher_cubes.h | 12 ++-- meshers/dmc/voxel_mesher_dmc.cpp | 4 ++ meshers/dmc/voxel_mesher_dmc.h | 16 +++-- .../transvoxel/voxel_mesher_transvoxel.cpp | 5 +- meshers/transvoxel/voxel_mesher_transvoxel.h | 12 ++-- meshers/voxel_mesher.cpp | 4 +- meshers/voxel_mesher.h | 11 ++-- register_types.cpp | 2 +- server/voxel_server.h | 2 - server/voxel_server_updater.cpp | 6 +- server/voxel_server_updater.h | 4 ++ storage/voxel_buffer.cpp | 5 +- storage/voxel_buffer.h | 55 ++++++++-------- storage/voxel_buffer_internal.h | 3 +- storage/voxel_data_map.h | 4 +- streams/region/region_file.h | 4 +- streams/region/voxel_stream_region_files.cpp | 7 ++- streams/region/voxel_stream_region_files.h | 23 ++++--- streams/sqlite/voxel_stream_sqlite.cpp | 7 +-- streams/sqlite/voxel_stream_sqlite.h | 20 +++--- streams/vox_loader.cpp | 5 +- streams/vox_loader.h | 4 ++ streams/voxel_block_request.h | 6 +- streams/voxel_block_serializer.cpp | 4 +- streams/voxel_block_serializer.h | 6 +- streams/voxel_stream.h | 12 ++-- streams/voxel_stream_block_files.h | 19 +++--- streams/voxel_stream_script.cpp | 4 +- streams/voxel_stream_script.h | 8 ++- terrain/instancing/voxel_instance_component.h | 4 ++ .../instancing/voxel_instance_generator.cpp | 4 +- terrain/instancing/voxel_instance_generator.h | 16 +++-- terrain/instancing/voxel_instance_library.cpp | 4 ++ terrain/instancing/voxel_instance_library.h | 4 ++ .../voxel_instance_library_item.cpp | 4 ++ .../instancing/voxel_instance_library_item.h | 6 +- .../voxel_instance_library_item_base.cpp | 4 ++ .../voxel_instance_library_item_base.h | 6 +- .../voxel_instance_library_scene_item.cpp | 8 ++- .../voxel_instance_library_scene_item.h | 4 ++ terrain/instancing/voxel_instancer.cpp | 5 +- terrain/instancing/voxel_instancer.h | 17 +++-- .../instancing/voxel_instancer_rigidbody.h | 4 ++ terrain/voxel_box_mover.cpp | 7 ++- terrain/voxel_box_mover.h | 4 ++ terrain/voxel_lod_terrain.cpp | 26 ++++---- terrain/voxel_lod_terrain.h | 63 ++++++++++--------- terrain/voxel_node.cpp | 4 ++ terrain/voxel_node.h | 6 +- terrain/voxel_terrain.cpp | 11 ++-- terrain/voxel_terrain.h | 26 ++++---- terrain/voxel_viewer.cpp | 5 +- terrain/voxel_viewer.h | 4 ++ util/noise/fast_noise_2.cpp | 10 +-- util/noise/fast_noise_2.h | 16 +++-- util/noise/fast_noise_lite.cpp | 6 +- util/noise/fast_noise_lite.h | 14 +++-- util/noise/fast_noise_lite_gradient.cpp | 4 ++ util/noise/fast_noise_lite_gradient.h | 10 ++- 121 files changed, 692 insertions(+), 376 deletions(-) diff --git a/doc/source/getting_the_module.md b/doc/source/getting_the_module.md index b0e65406..fcec4ea6 100644 --- a/doc/source/getting_the_module.md +++ b/doc/source/getting_the_module.md @@ -13,7 +13,7 @@ There are no release builds yet. We need to setup Github Releases for this. For Release builds correspond to a development milestone. Each has a branch (for example `godot3.4`, `godot3.3`...). They are feature freezes and may only receive bug fixes later on. Usually, they are made at the same time a new version of Godot comes out. Because the plugin is a module at the moment, and we don't have the same pipeline as the Godot devs, it comes as a whole custom build of the Godot editor, and might differ a little from the official version. -Not all export templates might be available yet. So you can develop your game and test it with the editor, but if you want to export it, you may need to compile the templates yourself. +The engine is massive and targets a lot of platforms, while our module is small in comparison and we don't have dedicated build containers, so not all export templates are available. You can develop your game and test it with the editor on main desktop platforms, but if you want to export it, you may need to compile the templates yourself. ### Development builds diff --git a/doc/source/module_development.md b/doc/source/module_development.md index 5e95a0bc..b2ad1b03 100644 --- a/doc/source/module_development.md +++ b/doc/source/module_development.md @@ -156,10 +156,9 @@ In performance-critical areas which run a lot: The intented namespaces are `zylann::` as main, and `zylann::voxel::` for voxel-related stuff. There may be others for different parts of the module. Namespaces are a work in progress, so a lot of places still miss them. -Registered classes are largely prefixed with `Voxel`, and not namespaced yet. -Godot's core codebase is generally not using namespaces. Classes registered to the engine must have a unique name regardless of namespaces, so in this module, they are primarily used to wrap the rest of the code. It is however desirable for registered classes to be in a namespace as well for consistency, and to avoid having to type fully-qualified names all the time. +Registered classes are also namespaced, but are still largely prefixed with `Voxel`. Classes registered to the engine must have a unique name regardless of namespaces. -It should be possible to use namespaces around a module class, since Godot4 started using them [here](https://github.com/godotengine/godot/blob/a8a20a0e02c8459513542f77eaed9b7350812c94/core/core_bind.h#L47) for core bindings (the [reason](https://github.com/godotengine/godot/pull/51627) was very specific though). In GDExtension it was not tested yet, but if there is a problem we'll have to do a PR to fix it. +If a registered class needs the same name as an internal one, it can be placed into a `::gd` sub-namespace. On the other hand, internal classes can also be suffixed `Internal`. ### Version control diff --git a/edition/voxel_raycast_result.cpp b/edition/voxel_raycast_result.cpp index d2d8d029..42b7c2c2 100644 --- a/edition/voxel_raycast_result.cpp +++ b/edition/voxel_raycast_result.cpp @@ -1,5 +1,7 @@ #include "voxel_raycast_result.h" +namespace zylann::voxel { + Vector3i VoxelRaycastResult::_b_get_position() const { return position; } @@ -21,3 +23,5 @@ void VoxelRaycastResult::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "previous_position"), "", "get_previous_position"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "distance"), "", "get_distance"); } + +} // namespace zylann::voxel diff --git a/edition/voxel_raycast_result.h b/edition/voxel_raycast_result.h index a2185fa2..2af7a63f 100644 --- a/edition/voxel_raycast_result.h +++ b/edition/voxel_raycast_result.h @@ -4,6 +4,8 @@ #include "../util/math/vector3i.h" #include +namespace zylann::voxel { + // This class exists only to make the script API nicer. class VoxelRaycastResult : public RefCounted { GDCLASS(VoxelRaycastResult, RefCounted) @@ -20,4 +22,6 @@ private: static void _bind_methods(); }; +} // namespace zylann::voxel + #endif // VOXEL_RAYCAST_RESULT_H diff --git a/edition/voxel_tool.cpp b/edition/voxel_tool.cpp index 094f4fe2..ecb43ede 100644 --- a/edition/voxel_tool.cpp +++ b/edition/voxel_tool.cpp @@ -3,8 +3,7 @@ #include "../util/macros.h" #include "../util/profiling.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelTool::VoxelTool() { _sdf_scale = VoxelBufferInternal::get_sdf_quantization_scale(VoxelBufferInternal::DEFAULT_SDF_CHANNEL_DEPTH); @@ -344,3 +343,5 @@ void VoxelTool::_bind_methods() { BIND_ENUM_CONSTANT(MODE_SET); BIND_ENUM_CONSTANT(MODE_TEXTURE_PAINT); } + +} // namespace zylann::voxel diff --git a/edition/voxel_tool.h b/edition/voxel_tool.h index b47101cb..bfacdb59 100644 --- a/edition/voxel_tool.h +++ b/edition/voxel_tool.h @@ -7,7 +7,9 @@ #include "funcs.h" #include "voxel_raycast_result.h" +namespace zylann::voxel { class VoxelBuffer; +} namespace zylann::voxel::ops { @@ -82,6 +84,8 @@ struct TextureBlendSphereOp { // TODO Need to review VoxelTool to account for transformed volumes +namespace zylann::voxel { + // High-level generic voxel edition utility. // Ease of use comes at cost. // It's not a class to instantiate alone, get it from the voxel objects you want to work with @@ -222,9 +226,11 @@ protected: Mode _mode = MODE_ADD; // Used on smooth terrain - zylann::voxel::ops::TextureParams _texture_params; + ops::TextureParams _texture_params; }; -VARIANT_ENUM_CAST(VoxelTool::Mode) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelTool::Mode) #endif // VOXEL_TOOL_H diff --git a/edition/voxel_tool_buffer.cpp b/edition/voxel_tool_buffer.cpp index c28a7eb6..6d44f020 100644 --- a/edition/voxel_tool_buffer.cpp +++ b/edition/voxel_tool_buffer.cpp @@ -3,8 +3,7 @@ #include "../util/profiling.h" #include "funcs.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelToolBuffer::VoxelToolBuffer(Ref vb) { ERR_FAIL_COND(vb.is_null()); @@ -127,3 +126,5 @@ void VoxelToolBuffer::paste( _buffer->get_buffer().copy_voxel_metadata_in_area( p_voxels->get_buffer(), Box3i(Vector3i(), p_voxels->get_buffer().get_size()), p_pos); } + +} // namespace zylann::voxel diff --git a/edition/voxel_tool_buffer.h b/edition/voxel_tool_buffer.h index d3b6f9ea..1b030244 100644 --- a/edition/voxel_tool_buffer.h +++ b/edition/voxel_tool_buffer.h @@ -3,6 +3,8 @@ #include "voxel_tool.h" +namespace zylann::voxel { + class VoxelToolBuffer : public VoxelTool { GDCLASS(VoxelToolBuffer, VoxelTool) public: @@ -29,4 +31,6 @@ private: Ref _buffer; }; +} // namespace zylann::voxel + #endif // VOXEL_TOOL_BUFFER_H diff --git a/edition/voxel_tool_lod_terrain.cpp b/edition/voxel_tool_lod_terrain.cpp index 15202447..3d4168bb 100644 --- a/edition/voxel_tool_lod_terrain.cpp +++ b/edition/voxel_tool_lod_terrain.cpp @@ -14,8 +14,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelToolLodTerrain::VoxelToolLodTerrain(VoxelLodTerrain *terrain) : _terrain(terrain) { ERR_FAIL_COND(terrain == nullptr); @@ -28,7 +27,8 @@ bool VoxelToolLodTerrain::is_area_editable(const Box3i &box) const { return _terrain->is_area_editable(box); } -template float get_sdf_interpolated(const Volume_F &f, Vector3 pos) { +template +float get_sdf_interpolated(const Volume_F &f, Vector3 pos) { const Vector3i c = Vector3iUtil::from_floored(pos); const float s000 = f(Vector3i(c.x, c.y, c.z)); @@ -131,8 +131,7 @@ Ref VoxelToolLodTerrain::raycast( // `voxel_raycast` operates on a discrete grid of cubic voxels, so to account for the smooth interpolation, // we may offset the ray so that cubes act as if they were centered on the filtered result. const Vector3 offset(0.5, 0.5, 0.5); - if (zylann::voxel_raycast( - pos + offset, dir, predicate, max_distance, hit_pos, prev_pos, hit_distance, hit_distance_prev)) { + if (voxel_raycast(pos + offset, dir, predicate, max_distance, hit_pos, prev_pos, hit_distance, hit_distance_prev)) { // Approximate surface float d = hit_distance; @@ -165,7 +164,7 @@ Ref VoxelToolLodTerrain::raycast( return res; } -namespace zylann::voxel::ops { +namespace ops { struct DoSphere { Vector3 center; @@ -217,7 +216,7 @@ struct DoSphere { } }; -} //namespace zylann::voxel::ops +} //namespace ops void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) { VOXEL_PROFILE_SCOPE(); @@ -256,12 +255,11 @@ void VoxelToolLodTerrain::do_sphere(Vector3 center, float radius) { _post_edit(box); } -namespace zylann::voxel { - -template class VoxelToolAsyncEdit : public IThreadedTask { +template +class VoxelToolAsyncEdit : public IThreadedTask { public: VoxelToolAsyncEdit(Op_T op, std::shared_ptr data) : _op(op), _data(data) { - _tracker = gd_make_shared(1); + _tracker = gd_make_shared(1); } void run(ThreadedTaskContext ctx) override { @@ -293,8 +291,6 @@ private: std::shared_ptr _tracker; }; -} // namespace zylann::voxel - void VoxelToolLodTerrain::do_sphere_async(Vector3 center, float radius) { ERR_FAIL_COND(_terrain == nullptr); @@ -387,8 +383,6 @@ void VoxelToolLodTerrain::set_raycast_binary_search_iterations(int iterations) { _raycast_binary_search_iterations = math::clamp(iterations, 0, 16); } -namespace zylann::voxel { - // Turns floating chunks of voxels into rigidbodies: // Detects separate groups of connected voxels within a box. Each group fully contained in the box is removed from // the source volume, and turned into a rigidbody. @@ -716,8 +710,6 @@ Array separate_floating_chunks(VoxelTool &voxel_tool, Box3i world_box, Node *par return nodes; } -} // namespace zylann::voxel - Array VoxelToolLodTerrain::separate_floating_chunks(AABB world_box, Node *parent_node) { ERR_FAIL_COND_V(_terrain == nullptr, Array()); ERR_FAIL_COND_V(!math::is_valid_size(world_box.size), Array()); @@ -741,3 +733,5 @@ void VoxelToolLodTerrain::_bind_methods() { D_METHOD("separate_floating_chunks", "box", "parent_node"), &VoxelToolLodTerrain::separate_floating_chunks); ClassDB::bind_method(D_METHOD("do_sphere_async", "center", "radius"), &VoxelToolLodTerrain::do_sphere_async); } + +} // namespace zylann::voxel diff --git a/edition/voxel_tool_lod_terrain.h b/edition/voxel_tool_lod_terrain.h index 11bacae2..e799831e 100644 --- a/edition/voxel_tool_lod_terrain.h +++ b/edition/voxel_tool_lod_terrain.h @@ -3,11 +3,10 @@ #include "voxel_tool.h" -class VoxelLodTerrain; - namespace zylann::voxel { + +class VoxelLodTerrain; class VoxelDataMap; -} class VoxelToolLodTerrain : public VoxelTool { GDCLASS(VoxelToolLodTerrain, VoxelTool) @@ -45,4 +44,6 @@ private: int _raycast_binary_search_iterations = 0; }; +} // namespace zylann::voxel + #endif // VOXEL_TOOL_LOD_TERRAIN_H diff --git a/edition/voxel_tool_terrain.cpp b/edition/voxel_tool_terrain.cpp index ada64260..4020c3c7 100644 --- a/edition/voxel_tool_terrain.cpp +++ b/edition/voxel_tool_terrain.cpp @@ -5,8 +5,7 @@ #include "../util/godot/funcs.h" #include "../util/voxel_raycast.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelToolTerrain::VoxelToolTerrain() {} @@ -412,3 +411,5 @@ void VoxelToolTerrain::_bind_methods() { ClassDB::bind_method(D_METHOD("for_each_voxel_metadata_in_area", "voxel_area", "callback"), &VoxelToolTerrain::for_each_voxel_metadata_in_area); } + +} // namespace zylann::voxel diff --git a/edition/voxel_tool_terrain.h b/edition/voxel_tool_terrain.h index 68ea4df7..10b3b57e 100644 --- a/edition/voxel_tool_terrain.h +++ b/edition/voxel_tool_terrain.h @@ -3,12 +3,11 @@ #include "voxel_tool.h" +namespace zylann::voxel { + class VoxelTerrain; class VoxelLibrary; - -namespace zylann::voxel { class VoxelDataMap; -} class VoxelToolTerrain : public VoxelTool { GDCLASS(VoxelToolTerrain, VoxelTool) @@ -36,9 +35,8 @@ public: // For easier unit testing (the regular one needs a terrain setup etc, harder to test atm) // The `_static` suffix is because it otherwise conflicts with the non-static method when registering the class - static void run_blocky_random_tick_static(zylann::voxel::VoxelDataMap &map, Box3i voxel_box, - const VoxelLibrary &lib, int voxel_count, int batch_count, void *callback_data, - bool (*callback)(void *, Vector3i, int64_t)); + static void run_blocky_random_tick_static(VoxelDataMap &map, Box3i voxel_box, const VoxelLibrary &lib, + int voxel_count, int batch_count, void *callback_data, bool (*callback)(void *, Vector3i, int64_t)); void for_each_voxel_metadata_in_area(AABB voxel_area, const Callable &callback); @@ -55,4 +53,6 @@ private: VoxelTerrain *_terrain = nullptr; }; +} // namespace zylann::voxel + #endif // VOXEL_TOOL_TERRAIN_H diff --git a/editor/about_window.cpp b/editor/about_window.cpp index 6390b3ef..250f05b9 100644 --- a/editor/about_window.cpp +++ b/editor/about_window.cpp @@ -10,6 +10,8 @@ #define VOXEL_ARRAY_LENGTH(a) (sizeof(a) / sizeof(a[0])) +namespace zylann::voxel { + namespace { struct ThirdParty { const char *name; @@ -300,3 +302,5 @@ void VoxelAboutWindow::_bind_methods() { // ClassDB::bind_method( // D_METHOD("_on_third_party_list_item_selected"), &VoxelAboutWindow::_on_third_party_list_item_selected); } + +} // namespace zylann::voxel diff --git a/editor/about_window.h b/editor/about_window.h index c0998582..287b70a1 100644 --- a/editor/about_window.h +++ b/editor/about_window.h @@ -6,6 +6,8 @@ class TextureRect; class RichTextLabel; +namespace zylann::voxel { + class VoxelAboutWindow : public AcceptDialog { GDCLASS(VoxelAboutWindow, AcceptDialog) public: @@ -24,4 +26,6 @@ private: RichTextLabel *_third_party_rich_text_label; }; +} // namespace zylann::voxel + #endif // VOXEL_ABOUT_WINDOW_H diff --git a/editor/fast_noise_2/fast_noise_2_editor_plugin.cpp b/editor/fast_noise_2/fast_noise_2_editor_plugin.cpp index 2f364d67..110758a1 100644 --- a/editor/fast_noise_2/fast_noise_2_editor_plugin.cpp +++ b/editor/fast_noise_2/fast_noise_2_editor_plugin.cpp @@ -4,6 +4,8 @@ #include #include +namespace zylann { + class FastNoise2Viewer : public Control { GDCLASS(FastNoise2Viewer, Control) public: @@ -115,3 +117,5 @@ FastNoise2EditorPlugin::FastNoise2EditorPlugin(EditorNode *p_node) { plugin.instantiate(); add_inspector_plugin(plugin); } + +} // namespace zylann diff --git a/editor/fast_noise_2/fast_noise_2_editor_plugin.h b/editor/fast_noise_2/fast_noise_2_editor_plugin.h index cc39bf7b..fac71983 100644 --- a/editor/fast_noise_2/fast_noise_2_editor_plugin.h +++ b/editor/fast_noise_2/fast_noise_2_editor_plugin.h @@ -3,6 +3,8 @@ #include +namespace zylann { + class FastNoise2EditorPlugin : public EditorPlugin { GDCLASS(FastNoise2EditorPlugin, EditorPlugin) public: @@ -13,4 +15,6 @@ public: FastNoise2EditorPlugin(EditorNode *p_node); }; +} // namespace zylann + #endif // FAST_NOISE_2_EDITOR_PLUGIN_H diff --git a/editor/fast_noise_lite/fast_noise_lite_editor_plugin.cpp b/editor/fast_noise_lite/fast_noise_lite_editor_plugin.cpp index 9e580199..43b22184 100644 --- a/editor/fast_noise_lite/fast_noise_lite_editor_plugin.cpp +++ b/editor/fast_noise_lite/fast_noise_lite_editor_plugin.cpp @@ -5,6 +5,8 @@ #include #include +namespace zylann { + class FastNoiseLiteViewer : public Control { GDCLASS(FastNoiseLiteViewer, Control) public: @@ -182,3 +184,5 @@ FastNoiseLiteEditorPlugin::FastNoiseLiteEditorPlugin(EditorNode *p_node) { plugin.instantiate(); add_inspector_plugin(plugin); } + +} // namespace zylann diff --git a/editor/fast_noise_lite/fast_noise_lite_editor_plugin.h b/editor/fast_noise_lite/fast_noise_lite_editor_plugin.h index dc41b349..332f1aca 100644 --- a/editor/fast_noise_lite/fast_noise_lite_editor_plugin.h +++ b/editor/fast_noise_lite/fast_noise_lite_editor_plugin.h @@ -3,6 +3,8 @@ #include +namespace zylann { + class FastNoiseLiteEditorPlugin : public EditorPlugin { GDCLASS(FastNoiseLiteEditorPlugin, EditorPlugin) public: @@ -13,4 +15,6 @@ public: FastNoiseLiteEditorPlugin(EditorNode *p_node); }; +} // namespace zylann + #endif // FAST_NOISE_LITE_EDITOR_PLUGIN_H diff --git a/editor/graph/voxel_graph_editor.cpp b/editor/graph/voxel_graph_editor.cpp index f2eef7b9..513e0cab 100644 --- a/editor/graph/voxel_graph_editor.cpp +++ b/editor/graph/voxel_graph_editor.cpp @@ -14,15 +14,14 @@ #include #include +namespace zylann::voxel { + const char *VoxelGraphEditor::SIGNAL_NODE_SELECTED = "node_selected"; const char *VoxelGraphEditor::SIGNAL_NOTHING_SELECTED = "nothing_selected"; const char *VoxelGraphEditor::SIGNAL_NODES_DELETED = "nodes_deleted"; //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -using namespace zylann; -using namespace voxel; - // Shows a 2D slice of the 3D set of values coming from an output port class VoxelGraphEditorNodePreview : public VBoxContainer { GDCLASS(VoxelGraphEditorNodePreview, VBoxContainer) @@ -1006,3 +1005,5 @@ void VoxelGraphEditor::_bind_methods() { ADD_SIGNAL(MethodInfo(SIGNAL_NOTHING_SELECTED, PropertyInfo(Variant::INT, "nothing_selected"))); ADD_SIGNAL(MethodInfo(SIGNAL_NODES_DELETED, PropertyInfo(Variant::INT, "nodes_deleted"))); } + +} // namespace zylann::voxel diff --git a/editor/graph/voxel_graph_editor.h b/editor/graph/voxel_graph_editor.h index e0a75343..6c2d0d87 100644 --- a/editor/graph/voxel_graph_editor.h +++ b/editor/graph/voxel_graph_editor.h @@ -4,14 +4,17 @@ #include "../voxel_debug.h" #include -class VoxelGeneratorGraph; class GraphEdit; class PopupMenu; class AcceptDialog; class UndoRedo; +class Node3D; + +namespace zylann::voxel { + +class VoxelGeneratorGraph; class VoxelRangeAnalysisDialog; class VoxelNode; -class Node3D; class VoxelGraphEditor : public Control { GDCLASS(VoxelGraphEditor, Control) @@ -79,7 +82,9 @@ private: bool _nothing_selected_check_scheduled = false; float _time_before_preview_update = 0.f; Node3D *_voxel_node = nullptr; - zylann::DebugRenderer _debug_renderer; + DebugRenderer _debug_renderer; }; +} // namespace zylann::voxel + #endif // VOXEL_GRAPH_EDITOR_H diff --git a/editor/graph/voxel_graph_editor_plugin.cpp b/editor/graph/voxel_graph_editor_plugin.cpp index 0baad020..8afca7ff 100644 --- a/editor/graph/voxel_graph_editor_plugin.cpp +++ b/editor/graph/voxel_graph_editor_plugin.cpp @@ -7,6 +7,8 @@ #include #include +namespace zylann::voxel { + VoxelGraphEditorPlugin::VoxelGraphEditorPlugin(EditorNode *p_node) { //EditorInterface *ed = get_editor_interface(); _graph_editor = memnew(VoxelGraphEditor); @@ -131,3 +133,5 @@ void VoxelGraphEditorPlugin::_bind_methods() { // D_METHOD("_on_graph_editor_nothing_selected"), &VoxelGraphEditorPlugin::_on_graph_editor_nothing_selected); ClassDB::bind_method(D_METHOD("_hide_deferred"), &VoxelGraphEditorPlugin::_hide_deferred); } + +} // namespace zylann::voxel diff --git a/editor/graph/voxel_graph_editor_plugin.h b/editor/graph/voxel_graph_editor_plugin.h index b1dd2fa6..a7e82f0f 100644 --- a/editor/graph/voxel_graph_editor_plugin.h +++ b/editor/graph/voxel_graph_editor_plugin.h @@ -3,8 +3,9 @@ #include +namespace zylann::voxel { + class VoxelGraphEditor; -//class ToolButton; class VoxelGraphEditorPlugin : public EditorPlugin { GDCLASS(VoxelGraphEditorPlugin, EditorPlugin) @@ -28,4 +29,6 @@ private: bool _deferred_visibility_scheduled = false; }; +} // namespace zylann::voxel + #endif // VOXEL_GRAPH_EDITOR_PLUGIN_H diff --git a/editor/graph/voxel_graph_node_inspector_wrapper.cpp b/editor/graph/voxel_graph_node_inspector_wrapper.cpp index 95b796ce..31737af8 100644 --- a/editor/graph/voxel_graph_node_inspector_wrapper.cpp +++ b/editor/graph/voxel_graph_node_inspector_wrapper.cpp @@ -3,8 +3,7 @@ #include "../../util/macros.h" #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { void VoxelGraphNodeInspectorWrapper::setup(Ref p_graph, uint32_t p_node_id, UndoRedo *ur) { _graph = p_graph; @@ -151,3 +150,5 @@ bool VoxelGraphNodeInspectorWrapper::_dont_undo_redo() const { void VoxelGraphNodeInspectorWrapper::_bind_methods() { ClassDB::bind_method(D_METHOD("_dont_undo_redo"), &VoxelGraphNodeInspectorWrapper::_dont_undo_redo); } + +} // namespace zylann::voxel diff --git a/editor/graph/voxel_graph_node_inspector_wrapper.h b/editor/graph/voxel_graph_node_inspector_wrapper.h index e4a4f075..b814823a 100644 --- a/editor/graph/voxel_graph_node_inspector_wrapper.h +++ b/editor/graph/voxel_graph_node_inspector_wrapper.h @@ -6,6 +6,8 @@ class UndoRedo; +namespace zylann::voxel { + // Nodes aren't resources so this translates them into a form the inspector can understand. // This makes it easier to support undo/redo and sub-resources. // WARNING: `AnimationPlayer` will allow to keyframe properties, but there really is no support for that. @@ -27,8 +29,10 @@ private: static void _bind_methods(); Ref _graph; - uint32_t _node_id = zylann::ProgramGraph::NULL_ID; + uint32_t _node_id = ProgramGraph::NULL_ID; UndoRedo *_undo_redo = nullptr; }; +} // namespace zylann::voxel + #endif // VOXEL_GRAPH_NODE_INSPECTOR_WRAPPER_H diff --git a/editor/instance_library/voxel_instance_library_editor_plugin.cpp b/editor/instance_library/voxel_instance_library_editor_plugin.cpp index ce6f5d91..9cfa3907 100644 --- a/editor/instance_library/voxel_instance_library_editor_plugin.cpp +++ b/editor/instance_library/voxel_instance_library_editor_plugin.cpp @@ -6,14 +6,14 @@ #include #include -namespace { +namespace zylann::voxel { + enum Buttons { BUTTON_ADD_MULTIMESH_ITEM, BUTTON_UPDATE_MULTIMESH_ITEM_FROM_SCENE, BUTTON_ADD_SCENE_ITEM, BUTTON_REMOVE_ITEM }; -} // namespace bool VoxelInstanceLibraryEditorInspectorPlugin::can_handle(Object *p_object) { return Object::cast_to(p_object) != nullptr; @@ -287,3 +287,5 @@ void VoxelInstanceLibraryEditorPlugin::_bind_methods() { // ClassDB::bind_method(D_METHOD("_on_open_scene_dialog_file_selected", "fpath"), // &VoxelInstanceLibraryEditorPlugin::_on_open_scene_dialog_file_selected); } + +} // namespace zylann::voxel diff --git a/editor/instance_library/voxel_instance_library_editor_plugin.h b/editor/instance_library/voxel_instance_library_editor_plugin.h index 3dcdfb8e..b525b37f 100644 --- a/editor/instance_library/voxel_instance_library_editor_plugin.h +++ b/editor/instance_library/voxel_instance_library_editor_plugin.h @@ -7,6 +7,9 @@ class Control; class MenuButton; class ConfirmationDialog; + +namespace zylann::voxel { + class VoxelInstanceLibraryEditorPlugin; class VoxelInstanceLibraryEditorInspectorPlugin : public EditorInspectorPlugin { @@ -25,7 +28,9 @@ private: class VoxelInstanceLibraryEditorPlugin : public EditorPlugin { GDCLASS(VoxelInstanceLibraryEditorPlugin, EditorPlugin) public: - virtual String get_name() const { return "VoxelInstanceLibrary"; } + virtual String get_name() const { + return "VoxelInstanceLibrary"; + } VoxelInstanceLibraryEditorPlugin(EditorNode *p_node); @@ -57,4 +62,6 @@ private: Ref _inspector_plugin; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCE_LIBRARY_EDITOR_PLUGIN_H diff --git a/editor/instancer/voxel_instancer_editor_plugin.cpp b/editor/instancer/voxel_instancer_editor_plugin.cpp index 02351c9f..a3c2a5b4 100644 --- a/editor/instancer/voxel_instancer_editor_plugin.cpp +++ b/editor/instancer/voxel_instancer_editor_plugin.cpp @@ -1,6 +1,8 @@ #include "voxel_instancer_editor_plugin.h" #include "../../terrain/instancing/voxel_instancer.h" +namespace zylann::voxel { + VoxelInstancerEditorPlugin::VoxelInstancerEditorPlugin(EditorNode *p_node) {} bool VoxelInstancerEditorPlugin::handles(Object *p_object) const { @@ -23,3 +25,5 @@ void VoxelInstancerEditorPlugin::make_visible(bool visible) { } } } + +} // namespace zylann::voxel diff --git a/editor/instancer/voxel_instancer_editor_plugin.h b/editor/instancer/voxel_instancer_editor_plugin.h index bfc8500a..c8ce428c 100644 --- a/editor/instancer/voxel_instancer_editor_plugin.h +++ b/editor/instancer/voxel_instancer_editor_plugin.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel { + class VoxelInstancer; class VoxelInstancerEditorPlugin : public EditorPlugin { @@ -18,4 +20,6 @@ private: VoxelInstancer *_node = nullptr; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCER_EDITOR_PLUGIN_H diff --git a/editor/terrain/voxel_terrain_editor_plugin.cpp b/editor/terrain/voxel_terrain_editor_plugin.cpp index 174d4c25..b1fa59c2 100644 --- a/editor/terrain/voxel_terrain_editor_plugin.cpp +++ b/editor/terrain/voxel_terrain_editor_plugin.cpp @@ -9,8 +9,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { class VoxelTerrainEditorTaskIndicator : public HBoxContainer { GDCLASS(VoxelTerrainEditorTaskIndicator, HBoxContainer) @@ -351,3 +350,5 @@ void VoxelTerrainEditorPlugin::_bind_methods() { // ClassDB::bind_method(D_METHOD("_on_terrain_tree_entered"), &VoxelTerrainEditorPlugin::_on_terrain_tree_entered); // ClassDB::bind_method(D_METHOD("_on_terrain_tree_exited"), &VoxelTerrainEditorPlugin::_on_terrain_tree_exited); } + +} // namespace zylann::voxel diff --git a/editor/terrain/voxel_terrain_editor_plugin.h b/editor/terrain/voxel_terrain_editor_plugin.h index fc09f49b..c7cd1e6e 100644 --- a/editor/terrain/voxel_terrain_editor_plugin.h +++ b/editor/terrain/voxel_terrain_editor_plugin.h @@ -4,6 +4,9 @@ #include class MenuButton; + +namespace zylann::voxel { + class VoxelAboutWindow; class VoxelNode; class VoxelTerrainEditorTaskIndicator; @@ -48,4 +51,6 @@ private: VoxelTerrainEditorTaskIndicator *_task_indicator = nullptr; }; +} // namespace zylann::voxel + #endif // VOXEL_TERRAIN_EDITOR_PLUGIN_H diff --git a/editor/vox/vox_editor_plugin.cpp b/editor/vox/vox_editor_plugin.cpp index 6c353cd9..c367c23d 100644 --- a/editor/vox/vox_editor_plugin.cpp +++ b/editor/vox/vox_editor_plugin.cpp @@ -2,6 +2,8 @@ #include "vox_importer.h" #include "vox_mesh_importer.h" +namespace zylann::voxel::magica { + VoxEditorPlugin::VoxEditorPlugin(EditorNode *p_node) { Ref vox_scene_importer; vox_scene_importer.instantiate(); @@ -12,3 +14,5 @@ VoxEditorPlugin::VoxEditorPlugin(EditorNode *p_node) { vox_mesh_importer.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(vox_mesh_importer); } + +} // namespace zylann::voxel::magica diff --git a/editor/vox/vox_editor_plugin.h b/editor/vox/vox_editor_plugin.h index 0af089d6..2868f2ad 100644 --- a/editor/vox/vox_editor_plugin.h +++ b/editor/vox/vox_editor_plugin.h @@ -3,10 +3,14 @@ #include +namespace zylann::voxel::magica { + class VoxEditorPlugin : public EditorPlugin { GDCLASS(VoxEditorPlugin, EditorPlugin) public: VoxEditorPlugin(EditorNode *p_node); }; +} // namespace zylann::voxel::magica + #endif // VOX_EDITOR_PLUGIN_H diff --git a/editor/vox/vox_importer.cpp b/editor/vox/vox_importer.cpp index 2d03ab17..067f9077 100644 --- a/editor/vox/vox_importer.cpp +++ b/editor/vox/vox_importer.cpp @@ -13,8 +13,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel::magica { String VoxelVoxImporter::get_importer_name() const { return "VoxelVoxImporter"; @@ -65,7 +64,8 @@ bool VoxelVoxImporter::get_option_visibility( return true; } -static void add_mesh_instance(Ref mesh, Node *parent, Node *owner, Vector3 offset, bool p_enable_baked_lighting) { +static void add_mesh_instance( + Ref mesh, ::Node *parent, ::Node *owner, Vector3 offset, bool p_enable_baked_lighting) { MeshInstance3D *mesh_instance = memnew(MeshInstance3D); mesh_instance->set_mesh(mesh); parent->add_child(mesh_instance); @@ -82,8 +82,6 @@ struct VoxMesh { Vector3 pivot; }; -namespace zylann::voxel::magica { - static Error process_scene_node_recursively(const Data &data, int node_id, Node3D *parent_node, Node3D *&out_root_node, int depth, const Vector &meshes, float scale, bool p_enable_baked_lighting) { // @@ -151,8 +149,6 @@ static Error process_scene_node_recursively(const Data &data, int node_id, Node3 return OK; } -} // namespace zylann::voxel::magica - /*static Error save_stex(const Ref &p_image, const String &p_to_path, bool p_mipmaps, int p_texture_flags, bool p_streamable, bool p_detect_3d, bool p_detect_srgb) { @@ -399,3 +395,5 @@ Error VoxelVoxImporter::import(const String &p_source_file, const String &p_save return OK; } + +} // namespace zylann::voxel::magica diff --git a/editor/vox/vox_importer.h b/editor/vox/vox_importer.h index 7bb28203..6c8f68b3 100644 --- a/editor/vox/vox_importer.h +++ b/editor/vox/vox_importer.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel::magica { + // TODO Rename VoxelVoxSceneImporter // Imports a vox file as a scene, where the internal scene layout is preserved as nodes class VoxelVoxImporter : public ResourceImporter { @@ -25,4 +27,6 @@ public: List *r_platform_variants, List *r_gen_files, Variant *r_metadata = nullptr) override; }; +} // namespace zylann::voxel::magica + #endif // VOX_IMPORTER_H diff --git a/editor/vox/vox_mesh_importer.cpp b/editor/vox/vox_mesh_importer.cpp index be5dbc20..dc9ca3bc 100644 --- a/editor/vox/vox_mesh_importer.cpp +++ b/editor/vox/vox_mesh_importer.cpp @@ -8,8 +8,7 @@ #include "../../util/profiling.h" #include "vox_import_funcs.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel::magica { String VoxelVoxMeshImporter::get_importer_name() const { return "VoxelVoxMeshImporter"; @@ -60,8 +59,6 @@ bool VoxelVoxMeshImporter::get_option_visibility( return true; } -namespace zylann::voxel::magica { - struct ForEachModelInstanceArgs { const Model *model; // Pivot position, which turns out to be at the center in MagicaVoxel @@ -70,8 +67,7 @@ struct ForEachModelInstanceArgs { }; template -static Error for_each_model_instance_in_scene_graph( - const Data &data, int node_id, Transform3D transform, int depth, F f) { +Error for_each_model_instance_in_scene_graph(const Data &data, int node_id, Transform3D transform, int depth, F f) { // ERR_FAIL_COND_V(depth > 10, ERR_INVALID_DATA); const Node *vox_node = data.get_node(node_id); @@ -110,7 +106,8 @@ static Error for_each_model_instance_in_scene_graph( return OK; } -template void for_each_model_instance(const Data &vox_data, F f) { +template +void for_each_model_instance(const Data &vox_data, F f) { if (vox_data.get_model_count() == 0) { return; } @@ -216,8 +213,6 @@ bool make_single_voxel_grid( return true; } -} // namespace zylann::voxel::magica - Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { @@ -228,7 +223,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); - magica::Data vox_data; + Data vox_data; const Error load_err = vox_data.load_from_file(p_source_file); ERR_FAIL_COND_V(load_err != OK, load_err); @@ -249,7 +244,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 @@ -288,7 +283,7 @@ Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_ break; }; - mesh = magica::build_mesh(voxels, **mesher, surface_index_to_material, atlas, p_scale, offset); + mesh = build_mesh(voxels, **mesher, surface_index_to_material, atlas, p_scale, offset); // Deallocate large temporary memory to free space. // This is a workaround because VoxelBuffer uses this by default, however it doesn't fit the present use case. // Eventually we should avoid using this pool here. @@ -367,3 +362,5 @@ Error VoxelVoxMeshImporter::import(const String &p_source_file, const String &p_ return OK; } + +} // namespace zylann::voxel::magica diff --git a/editor/vox/vox_mesh_importer.h b/editor/vox/vox_mesh_importer.h index f9063dc8..64ea76a6 100644 --- a/editor/vox/vox_mesh_importer.h +++ b/editor/vox/vox_mesh_importer.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel::magica { + // Imports a vox file as a single mesh, where all contents of the vox scene is merged class VoxelVoxMeshImporter : public ResourceImporter { GDCLASS(VoxelVoxMeshImporter, ResourceImporter) @@ -31,4 +33,6 @@ public: }; }; +} // namespace zylann::voxel::magica + #endif // VOX_MESH_IMPORTER_H diff --git a/generators/graph/voxel_generator_graph.cpp b/generators/graph/voxel_generator_graph.cpp index 01f8ee9b..bb520300 100644 --- a/generators/graph/voxel_generator_graph.cpp +++ b/generators/graph/voxel_generator_graph.cpp @@ -6,8 +6,7 @@ #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { const char *VoxelGeneratorGraph::SIGNAL_NODE_NAME_CHANGED = "node_name_changed"; @@ -399,8 +398,6 @@ void VoxelGeneratorGraph::gather_indices_and_weights(Span we } } -namespace zylann::voxel { - template void fill_zx_slice(Span channel_data, float sdf_scale, Vector3i rmin, Vector3i rmax, int ry, int x_stride, const float *src_data, Vector3i buffer_size, F convert_func) { @@ -455,8 +452,6 @@ static void fill_zx_slice(const VoxelGraphRuntime::Buffer &sdf_buffer, VoxelBuff } } -} // namespace zylann::voxel - VoxelGenerator::Result VoxelGeneratorGraph::generate_block(VoxelBlockRequest &input) { std::shared_ptr runtime_ptr; { @@ -1208,7 +1203,7 @@ static Dictionary get_graph_as_variant_data(const ProgramGraph &graph) { } Dictionary VoxelGeneratorGraph::get_graph_as_variant_data() const { - return ::get_graph_as_variant_data(_graph); + return zylann::voxel::get_graph_as_variant_data(_graph); } static bool var_to_id(Variant v, uint32_t &out_id, uint32_t min = 0) { @@ -1282,7 +1277,7 @@ static bool load_graph_from_variant_data(ProgramGraph &graph, Dictionary data) { void VoxelGeneratorGraph::load_graph_from_variant_data(Dictionary data) { clear(); - if (::load_graph_from_variant_data(_graph, data)) { + if (zylann::voxel::load_graph_from_variant_data(_graph, data)) { register_subresources(); // It's possible to auto-compile on load because `graph_data` is the only property set by the loader, // which is enough to have all information we need @@ -1673,3 +1668,5 @@ void VoxelGeneratorGraph::_bind_methods() { #endif BIND_ENUM_CONSTANT(NODE_TYPE_COUNT); } + +} // namespace zylann::voxel diff --git a/generators/graph/voxel_generator_graph.h b/generators/graph/voxel_generator_graph.h index 50550f6a..24b63994 100644 --- a/generators/graph/voxel_generator_graph.h +++ b/generators/graph/voxel_generator_graph.h @@ -6,6 +6,8 @@ #include "voxel_graph_runtime.h" #include +namespace zylann::voxel { + class VoxelGeneratorGraph : public VoxelGenerator { GDCLASS(VoxelGeneratorGraph, VoxelGenerator) public: @@ -76,7 +78,7 @@ public: // Important: functions editing the graph are NOT thread-safe. // They are expected to be used by the main thread (editor or game logic). - uint32_t create_node(NodeTypeID type_id, Vector2 position, uint32_t id = zylann::ProgramGraph::NULL_ID); + uint32_t create_node(NodeTypeID type_id, Vector2 position, uint32_t id = ProgramGraph::NULL_ID); void remove_node(uint32_t node_id); bool can_connect( @@ -84,9 +86,8 @@ public: void add_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index); void remove_connection( uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index); - void get_connections(std::vector &connections) const; - bool try_get_connection_to( - zylann::ProgramGraph::PortLocation dst, zylann::ProgramGraph::PortLocation &out_src) const; + void get_connections(std::vector &connections) const; + bool try_get_connection_to(ProgramGraph::PortLocation dst, ProgramGraph::PortLocation &out_src) const; bool has_node(uint32_t node_id) const; @@ -153,22 +154,22 @@ public: // Internal - zylann::voxel::VoxelGraphRuntime::CompilationResult compile(); + VoxelGraphRuntime::CompilationResult compile(); bool is_good() const; void generate_set(Span in_x, Span in_y, Span in_z); // Returns state from the last generator used in the current thread - static const zylann::voxel::VoxelGraphRuntime::State &get_last_state_from_current_thread(); + static const VoxelGraphRuntime::State &get_last_state_from_current_thread(); static Span get_last_execution_map_debug_from_current_thread(); - bool try_get_output_port_address(zylann::ProgramGraph::PortLocation port, uint32_t &out_address) const; + bool try_get_output_port_address(ProgramGraph::PortLocation port, uint32_t &out_address) const; void find_dependencies(uint32_t node_id, std::vector &out_dependencies) const; // Debug - zylann::math::Interval debug_analyze_range(Vector3i min_pos, Vector3i max_pos, bool optimize_execution_map) const; + math::Interval debug_analyze_range(Vector3i min_pos, Vector3i max_pos, bool optimize_execution_map) const; float debug_measure_microseconds_per_voxel(bool singular); void debug_load_waves_preset(); @@ -198,12 +199,12 @@ private: }; static void gather_indices_and_weights(Span weight_outputs, - const zylann::voxel::VoxelGraphRuntime::State &state, Vector3i rmin, Vector3i rmax, int ry, - zylann::voxel::VoxelBufferInternal &out_voxel_buffer, zylann::FixedArray spare_indices); + const VoxelGraphRuntime::State &state, Vector3i rmin, Vector3i rmax, int ry, + VoxelBufferInternal &out_voxel_buffer, FixedArray spare_indices); static void _bind_methods(); - zylann::ProgramGraph _graph; + ProgramGraph _graph; // This generator performs range analysis using nodes of the graph. Terrain surface can only appear when SDF // crosses zero within a block. For each generated block, an estimated range of the output is calculated. // If that range is beyond this threshold (either negatively or positively), then blocks will be given a uniform @@ -228,15 +229,15 @@ private: // Only compiling and generation methods are thread-safe. struct Runtime { - zylann::voxel::VoxelGraphRuntime runtime; + VoxelGraphRuntime runtime; // Indices that are not used in the graph. // This is used when there are less than 4 texture weight outputs. - zylann::FixedArray spare_texture_indices; + FixedArray spare_texture_indices; // Index to the SDF output int sdf_output_buffer_index = -1; - zylann::FixedArray weight_outputs; + FixedArray weight_outputs; // List of indices to feed queries. The order doesn't matter, can be different from `weight_outputs`. - zylann::FixedArray weight_output_indices; + FixedArray weight_output_indices; unsigned int weight_outputs_count = 0; }; @@ -247,13 +248,15 @@ private: std::vector x_cache; std::vector y_cache; std::vector z_cache; - zylann::voxel::VoxelGraphRuntime::State state; - zylann::voxel::VoxelGraphRuntime::ExecutionMap optimized_execution_map; + VoxelGraphRuntime::State state; + VoxelGraphRuntime::ExecutionMap optimized_execution_map; }; static thread_local Cache _cache; }; -VARIANT_ENUM_CAST(VoxelGeneratorGraph::NodeTypeID) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelGeneratorGraph::NodeTypeID) #endif // VOXEL_GENERATOR_GRAPH_H diff --git a/generators/simple/voxel_generator_flat.cpp b/generators/simple/voxel_generator_flat.cpp index 6664fe6d..84891828 100644 --- a/generators/simple/voxel_generator_flat.cpp +++ b/generators/simple/voxel_generator_flat.cpp @@ -1,6 +1,6 @@ #include "voxel_generator_flat.h" -using namespace zylann::voxel; +namespace zylann::voxel { VoxelGeneratorFlat::VoxelGeneratorFlat() {} @@ -136,3 +136,5 @@ void VoxelGeneratorFlat::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "voxel_type", PROPERTY_HINT_RANGE, "0,65536,1"), "set_voxel_type", "get_voxel_type"); } + +} // namespace zylann::voxel diff --git a/generators/simple/voxel_generator_flat.h b/generators/simple/voxel_generator_flat.h index 19f79c30..44e0d788 100644 --- a/generators/simple/voxel_generator_flat.h +++ b/generators/simple/voxel_generator_flat.h @@ -3,6 +3,8 @@ #include "../voxel_generator.h" +namespace zylann::voxel { + class VoxelGeneratorFlat : public VoxelGenerator { GDCLASS(VoxelGeneratorFlat, VoxelGenerator) @@ -27,7 +29,7 @@ protected: private: struct Parameters { - zylann::voxel::VoxelBufferInternal::ChannelId channel = zylann::voxel::VoxelBufferInternal::CHANNEL_SDF; + VoxelBufferInternal::ChannelId channel = VoxelBufferInternal::CHANNEL_SDF; int voxel_type = 1; float height = 0; float iso_scale = 0.1; @@ -37,4 +39,6 @@ private: RWLock _parameters_lock; }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_FLAT_H diff --git a/generators/simple/voxel_generator_heightmap.cpp b/generators/simple/voxel_generator_heightmap.cpp index 34207c35..93d98c88 100644 --- a/generators/simple/voxel_generator_heightmap.cpp +++ b/generators/simple/voxel_generator_heightmap.cpp @@ -2,7 +2,7 @@ #include "../../util/fixed_array.h" #include "../../util/span.h" -using namespace zylann::voxel; +namespace zylann::voxel { VoxelGeneratorHeightmap::VoxelGeneratorHeightmap() {} @@ -83,3 +83,5 @@ void VoxelGeneratorHeightmap::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height_range"), "set_height_range", "get_height_range"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "iso_scale"), "set_iso_scale", "get_iso_scale"); } + +} // namespace zylann::voxel diff --git a/generators/simple/voxel_generator_heightmap.h b/generators/simple/voxel_generator_heightmap.h index d3a24c9a..0af9b7d5 100644 --- a/generators/simple/voxel_generator_heightmap.h +++ b/generators/simple/voxel_generator_heightmap.h @@ -5,6 +5,8 @@ #include "../voxel_generator.h" #include +namespace zylann::voxel { + class VoxelGeneratorHeightmap : public VoxelGenerator { GDCLASS(VoxelGeneratorHeightmap, VoxelGenerator) public: @@ -26,7 +28,7 @@ public: protected: template - Result generate(zylann::voxel::VoxelBufferInternal &out_buffer, Height_F height_func, Vector3i origin, int lod) { + Result generate(VoxelBufferInternal &out_buffer, Height_F height_func, Vector3i origin, int lod) { Parameters params; { RWLockRead rlock(_parameters_lock); @@ -35,7 +37,7 @@ protected: const int channel = params.channel; const Vector3i bs = out_buffer.get_size(); - const bool use_sdf = channel == zylann::voxel::VoxelBufferInternal::CHANNEL_SDF; + const bool use_sdf = channel == VoxelBufferInternal::CHANNEL_SDF; if (origin.y > get_height_start() + get_height_range()) { // The bottom of the block is above the highest ground can go (default is air) @@ -111,7 +113,7 @@ private: }; struct Parameters { - zylann::voxel::VoxelBufferInternal::ChannelId channel = zylann::voxel::VoxelBufferInternal::CHANNEL_SDF; + VoxelBufferInternal::ChannelId channel = VoxelBufferInternal::CHANNEL_SDF; int matter_type = 1; Range range; float iso_scale = 0.1; @@ -121,4 +123,6 @@ private: Parameters _parameters; }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_HEIGHTMAP_H diff --git a/generators/simple/voxel_generator_image.cpp b/generators/simple/voxel_generator_image.cpp index 999bae18..5a7e7518 100644 --- a/generators/simple/voxel_generator_image.cpp +++ b/generators/simple/voxel_generator_image.cpp @@ -2,8 +2,7 @@ #include "../../util/fixed_array.h" #include "../../util/span.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { namespace { @@ -95,3 +94,5 @@ void VoxelGeneratorImage::_bind_methods() { PropertyInfo(Variant::OBJECT, "image", PROPERTY_HINT_RESOURCE_TYPE, "Image"), "set_image", "get_image"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "blur_enabled"), "set_blur_enabled", "is_blur_enabled"); } + +} // namespace zylann::voxel diff --git a/generators/simple/voxel_generator_image.h b/generators/simple/voxel_generator_image.h index 222a75b8..9b432491 100644 --- a/generators/simple/voxel_generator_image.h +++ b/generators/simple/voxel_generator_image.h @@ -4,6 +4,8 @@ #include "voxel_generator_heightmap.h" #include +namespace zylann::voxel { + // Provides infinite tiling heightmap based on an image class VoxelGeneratorImage : public VoxelGeneratorHeightmap { GDCLASS(VoxelGeneratorImage, VoxelGeneratorHeightmap) @@ -40,4 +42,6 @@ private: RWLock _parameters_lock; }; +} // namespace zylann::voxel + #endif // HEADER_VOXEL_GENERATOR_IMAGE diff --git a/generators/simple/voxel_generator_noise.cpp b/generators/simple/voxel_generator_noise.cpp index e5d6811c..d6de97d2 100644 --- a/generators/simple/voxel_generator_noise.cpp +++ b/generators/simple/voxel_generator_noise.cpp @@ -2,7 +2,7 @@ #include #include -using namespace zylann::voxel; +namespace zylann::voxel { VoxelGeneratorNoise::VoxelGeneratorNoise() {} @@ -251,3 +251,5 @@ void VoxelGeneratorNoise::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height_start"), "set_height_start", "get_height_start"); ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "height_range"), "set_height_range", "get_height_range"); } + +} // namespace zylann::voxel diff --git a/generators/simple/voxel_generator_noise.h b/generators/simple/voxel_generator_noise.h index 510e02bd..2cd72c1e 100644 --- a/generators/simple/voxel_generator_noise.h +++ b/generators/simple/voxel_generator_noise.h @@ -4,6 +4,8 @@ #include "../voxel_generator.h" #include +namespace zylann::voxel { + class VoxelGeneratorNoise : public VoxelGenerator { GDCLASS(VoxelGeneratorNoise, VoxelGenerator) @@ -35,7 +37,7 @@ private: Ref _noise; struct Parameters { - zylann::voxel::VoxelBufferInternal::ChannelId channel = zylann::voxel::VoxelBufferInternal::CHANNEL_SDF; + VoxelBufferInternal::ChannelId channel = VoxelBufferInternal::CHANNEL_SDF; Ref noise; float height_start = 0; float height_range = 300; @@ -45,4 +47,6 @@ private: RWLock _parameters_lock; }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_NOISE_H diff --git a/generators/simple/voxel_generator_noise_2d.cpp b/generators/simple/voxel_generator_noise_2d.cpp index 3b403f38..cad46a45 100644 --- a/generators/simple/voxel_generator_noise_2d.cpp +++ b/generators/simple/voxel_generator_noise_2d.cpp @@ -2,7 +2,7 @@ #include #include -using namespace zylann::voxel; +namespace zylann::voxel { VoxelGeneratorNoise2D::VoxelGeneratorNoise2D() {} @@ -117,3 +117,5 @@ void VoxelGeneratorNoise2D::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve"), "set_curve", "get_curve"); } + +} // namespace zylann::voxel diff --git a/generators/simple/voxel_generator_noise_2d.h b/generators/simple/voxel_generator_noise_2d.h index 5e8d54e0..cf830b94 100644 --- a/generators/simple/voxel_generator_noise_2d.h +++ b/generators/simple/voxel_generator_noise_2d.h @@ -4,6 +4,8 @@ #include "voxel_generator_heightmap.h" #include +namespace zylann::voxel { + class VoxelGeneratorNoise2D : public VoxelGeneratorHeightmap { GDCLASS(VoxelGeneratorNoise2D, VoxelGeneratorHeightmap) @@ -38,4 +40,6 @@ private: RWLock _parameters_lock; }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_NOISE_2D_H diff --git a/generators/simple/voxel_generator_waves.h b/generators/simple/voxel_generator_waves.h index c190508a..fe8b7008 100644 --- a/generators/simple/voxel_generator_waves.h +++ b/generators/simple/voxel_generator_waves.h @@ -3,6 +3,8 @@ #include "voxel_generator_heightmap.h" +namespace zylann::voxel { + class VoxelGeneratorWaves : public VoxelGeneratorHeightmap { GDCLASS(VoxelGeneratorWaves, VoxelGeneratorHeightmap) @@ -33,4 +35,6 @@ private: RWLock _parameters_lock; }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_WAVES_H diff --git a/generators/voxel_generator.cpp b/generators/voxel_generator.cpp index 74f622a7..6f02d0ad 100644 --- a/generators/voxel_generator.cpp +++ b/generators/voxel_generator.cpp @@ -1,7 +1,7 @@ #include "voxel_generator.h" #include "../constants/voxel_string_names.h" -using namespace zylann::voxel; +namespace zylann::voxel { VoxelGenerator::VoxelGenerator() {} @@ -39,3 +39,5 @@ void VoxelGenerator::_bind_methods() { ClassDB::bind_method( D_METHOD("generate_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelGenerator::_b_generate_block); } + +} // namespace zylann::voxel diff --git a/generators/voxel_generator.h b/generators/voxel_generator.h index 8d9a8716..23f195f0 100644 --- a/generators/voxel_generator.h +++ b/generators/voxel_generator.h @@ -4,6 +4,8 @@ #include "../streams/voxel_block_request.h" #include +namespace zylann::voxel { + union VoxelSingleValue { uint64_t i; float f; @@ -27,7 +29,9 @@ public: virtual Result generate_block(VoxelBlockRequest &input); // TODO Single sample - virtual bool supports_single_generation() const { return false; } + virtual bool supports_single_generation() const { + return false; + } // TODO Not sure if it's a good API regarding performance virtual VoxelSingleValue generate_single(Vector3i pos, unsigned int channel); @@ -46,4 +50,6 @@ protected: void _b_generate_block(Ref out_buffer, Vector3 origin_in_voxels, int lod); }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_H diff --git a/generators/voxel_generator_script.cpp b/generators/voxel_generator_script.cpp index a98f1b33..6cddc81c 100644 --- a/generators/voxel_generator_script.cpp +++ b/generators/voxel_generator_script.cpp @@ -2,6 +2,8 @@ #include "../constants/voxel_string_names.h" #include "../util/godot/funcs.h" +namespace zylann::voxel { + VoxelGeneratorScript::VoxelGeneratorScript() {} VoxelGenerator::Result VoxelGeneratorScript::generate_block(VoxelBlockRequest &input) { @@ -48,3 +50,5 @@ void VoxelGeneratorScript::_bind_methods() { // BIND_VMETHOD(MethodInfo(Variant::INT, "_get_used_channels_mask")); } + +} // namespace zylann::voxel diff --git a/generators/voxel_generator_script.h b/generators/voxel_generator_script.h index 62414d8c..6c594573 100644 --- a/generators/voxel_generator_script.h +++ b/generators/voxel_generator_script.h @@ -5,6 +5,8 @@ #include // needed for GDVIRTUAL macro #include // Also needed for GDVIRTUAL macro... +namespace zylann::voxel { + // Generator based on a script, like GDScript, C# or NativeScript. // The script is expected to properly handle multithreading. class VoxelGeneratorScript : public VoxelGenerator { @@ -23,4 +25,6 @@ private: static void _bind_methods(); }; +} // namespace zylann::voxel + #endif // VOXEL_GENERATOR_SCRIPT_H diff --git a/meshers/blocky/voxel.cpp b/meshers/blocky/voxel.cpp index 9f67c27c..84651d5a 100644 --- a/meshers/blocky/voxel.cpp +++ b/meshers/blocky/voxel.cpp @@ -5,8 +5,7 @@ #define STRLEN(x) (sizeof(x) / sizeof(x[0])) -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { Voxel::Voxel() : _id(-1), _material_id(0), _transparency_index(0), _color(1.f, 1.f, 1.f), _geometry_type(GEOMETRY_NONE) {} @@ -474,6 +473,27 @@ void Voxel::bake(BakedData &baked_data, int p_atlas_size, bool bake_tangents) { _empty = baked_data.empty; } +Array Voxel::_b_get_collision_aabbs() const { + Array array; + array.resize(_collision_aabbs.size()); + for (size_t i = 0; i < _collision_aabbs.size(); ++i) { + array[i] = _collision_aabbs[i]; + } + return array; +} + +void Voxel::_b_set_collision_aabbs(Array array) { + for (int i = 0; i < array.size(); ++i) { + const Variant v = array[i]; + ERR_FAIL_COND(v.get_type() != Variant::AABB); + } + _collision_aabbs.resize(array.size()); + for (int i = 0; i < array.size(); ++i) { + const AABB aabb = array[i]; + _collision_aabbs[i] = aabb; + } +} + void Voxel::_bind_methods() { ClassDB::bind_method(D_METHOD("set_voxel_name", "name"), &Voxel::set_voxel_name); ClassDB::bind_method(D_METHOD("get_voxel_name"), &Voxel::get_voxel_name); @@ -542,23 +562,4 @@ void Voxel::_bind_methods() { BIND_ENUM_CONSTANT(SIDE_COUNT); } -Array Voxel::_b_get_collision_aabbs() const { - Array array; - array.resize(_collision_aabbs.size()); - for (size_t i = 0; i < _collision_aabbs.size(); ++i) { - array[i] = _collision_aabbs[i]; - } - return array; -} - -void Voxel::_b_set_collision_aabbs(Array array) { - for (int i = 0; i < array.size(); ++i) { - const Variant v = array[i]; - ERR_FAIL_COND(v.get_type() != Variant::AABB); - } - _collision_aabbs.resize(array.size()); - for (int i = 0; i < array.size(); ++i) { - const AABB aabb = array[i]; - _collision_aabbs[i] = aabb; - } -} +} // namespace zylann::voxel diff --git a/meshers/blocky/voxel.h b/meshers/blocky/voxel.h index dc06a4a4..eef80434 100644 --- a/meshers/blocky/voxel.h +++ b/meshers/blocky/voxel.h @@ -7,6 +7,8 @@ #include #include +namespace zylann::voxel { + class VoxelLibrary; // TODO Rename VoxelBlockyLibraryItem? @@ -34,12 +36,12 @@ public: // Model sides: // They are separated because this way we can occlude them easily. // Due to these defining cube side triangles, normals are known already. - zylann::FixedArray, zylann::voxel::Cube::SIDE_COUNT> side_positions; - zylann::FixedArray, zylann::voxel::Cube::SIDE_COUNT> side_uvs; - zylann::FixedArray, zylann::voxel::Cube::SIDE_COUNT> side_indices; - zylann::FixedArray, zylann::voxel::Cube::SIDE_COUNT> side_tangents; + FixedArray, Cube::SIDE_COUNT> side_positions; + FixedArray, Cube::SIDE_COUNT> side_uvs; + FixedArray, Cube::SIDE_COUNT> side_indices; + FixedArray, Cube::SIDE_COUNT> side_tangents; - zylann::FixedArray side_pattern_indices; + FixedArray side_pattern_indices; void clear() { positions.clear(); @@ -48,7 +50,7 @@ public: indices.clear(); tangents.clear(); - for (int side = 0; side < zylann::voxel::Cube::SIDE_COUNT; ++side) { + for (int side = 0; side < Cube::SIDE_COUNT; ++side) { side_positions[side].clear(); side_uvs[side].clear(); side_indices[side].clear(); @@ -73,13 +75,13 @@ public: Voxel(); enum Side { - SIDE_NEGATIVE_X = zylann::voxel::Cube::SIDE_NEGATIVE_X, - SIDE_POSITIVE_X = zylann::voxel::Cube::SIDE_POSITIVE_X, - SIDE_NEGATIVE_Y = zylann::voxel::Cube::SIDE_NEGATIVE_Y, - SIDE_POSITIVE_Y = zylann::voxel::Cube::SIDE_POSITIVE_Y, - SIDE_NEGATIVE_Z = zylann::voxel::Cube::SIDE_NEGATIVE_Z, - SIDE_POSITIVE_Z = zylann::voxel::Cube::SIDE_POSITIVE_Z, - SIDE_COUNT = zylann::voxel::Cube::SIDE_COUNT + SIDE_NEGATIVE_X = Cube::SIDE_NEGATIVE_X, + SIDE_POSITIVE_X = Cube::SIDE_POSITIVE_X, + SIDE_NEGATIVE_Y = Cube::SIDE_NEGATIVE_Y, + SIDE_POSITIVE_Y = Cube::SIDE_POSITIVE_Y, + SIDE_NEGATIVE_Z = Cube::SIDE_NEGATIVE_Z, + SIDE_POSITIVE_Z = Cube::SIDE_POSITIVE_Z, + SIDE_COUNT = Cube::SIDE_COUNT }; // Properties @@ -192,7 +194,7 @@ private: Color _color; GeometryType _geometry_type; - zylann::FixedArray _cube_tiles; + FixedArray _cube_tiles; Ref _custom_mesh; std::vector _collision_aabbs; bool _random_tickable = false; @@ -200,7 +202,9 @@ private: uint32_t _collision_mask = 1; }; -VARIANT_ENUM_CAST(Voxel::GeometryType) -VARIANT_ENUM_CAST(Voxel::Side) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::Voxel::GeometryType) +VARIANT_ENUM_CAST(zylann::voxel::Voxel::Side) #endif // VOXEL_TYPE_H diff --git a/meshers/blocky/voxel_library.cpp b/meshers/blocky/voxel_library.cpp index 7133f85b..d44e88f4 100644 --- a/meshers/blocky/voxel_library.cpp +++ b/meshers/blocky/voxel_library.cpp @@ -6,8 +6,7 @@ #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelLibrary::VoxelLibrary() {} @@ -431,3 +430,5 @@ Ref VoxelLibrary::_b_get_voxel_by_name(StringName name) { ERR_FAIL_COND_V(id == -1, Ref()); return _voxel_types[id]; } + +} // namespace zylann::voxel diff --git a/meshers/blocky/voxel_library.h b/meshers/blocky/voxel_library.h index 5ec9d33b..5bff6a62 100644 --- a/meshers/blocky/voxel_library.h +++ b/meshers/blocky/voxel_library.h @@ -5,6 +5,8 @@ #include "voxel.h" #include +namespace zylann::voxel { + // TODO Rename VoxelBlockyLibrary // Stores a list of models that can be used with VoxelMesherBlocky @@ -19,7 +21,7 @@ public: struct BakedData { // 2D array: { X : pattern A, Y : pattern B } => Does A occlude B // Where index is X + Y * pattern count - zylann::DynamicBitset side_pattern_culling; + DynamicBitset side_pattern_culling; unsigned int side_pattern_count = 0; // Lots of data can get moved but it's only on load. std::vector models; @@ -107,4 +109,6 @@ private: BakedData _baked_data; }; +} // namespace zylann::voxel + #endif // VOXEL_LIBRARY_H diff --git a/meshers/blocky/voxel_mesher_blocky.cpp b/meshers/blocky/voxel_mesher_blocky.cpp index 5a155159..32553566 100644 --- a/meshers/blocky/voxel_mesher_blocky.cpp +++ b/meshers/blocky/voxel_mesher_blocky.cpp @@ -330,10 +330,7 @@ void generate_blocky_mesh( } } -} // namespace zylann::voxel - -using namespace zylann; -using namespace voxel; +//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// thread_local VoxelMesherBlocky::Cache VoxelMesherBlocky::_cache; @@ -554,3 +551,5 @@ void VoxelMesherBlocky::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "occlusion_darkness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_occlusion_darkness", "get_occlusion_darkness"); } + +} // namespace zylann::voxel diff --git a/meshers/blocky/voxel_mesher_blocky.h b/meshers/blocky/voxel_mesher_blocky.h index 97a36877..6e1f1143 100644 --- a/meshers/blocky/voxel_mesher_blocky.h +++ b/meshers/blocky/voxel_mesher_blocky.h @@ -7,6 +7,8 @@ #include #include +namespace zylann::voxel { + // TODO Rename VoxelMesherModelBatch // Interprets voxel values as indexes to models in a VoxelLibrary, and batches them together. @@ -70,7 +72,7 @@ private: }; struct Cache { - zylann::FixedArray arrays_per_material; + FixedArray arrays_per_material; }; // Parameters @@ -81,4 +83,6 @@ private: static thread_local Cache _cache; }; +} // namespace zylann::voxel + #endif // VOXEL_MESHER_BLOCKY_H diff --git a/meshers/cubes/voxel_color_palette.cpp b/meshers/cubes/voxel_color_palette.cpp index bd087444..de268382 100644 --- a/meshers/cubes/voxel_color_palette.cpp +++ b/meshers/cubes/voxel_color_palette.cpp @@ -1,6 +1,6 @@ #include "voxel_color_palette.h" -using namespace zylann; +namespace zylann::voxel { VoxelColorPalette::VoxelColorPalette() { // Default palette @@ -79,3 +79,5 @@ void VoxelColorPalette::_bind_methods() { BIND_CONSTANT(MAX_COLORS); } + +} // namespace zylann::voxel diff --git a/meshers/cubes/voxel_color_palette.h b/meshers/cubes/voxel_color_palette.h index 2e9d65e1..3dfedbc2 100644 --- a/meshers/cubes/voxel_color_palette.h +++ b/meshers/cubes/voxel_color_palette.h @@ -5,6 +5,8 @@ #include "../../util/math/color8.h" #include +namespace zylann::voxel { + // Associates small numbers to colors, so colored voxels can be specified using less memory. class VoxelColorPalette : public Resource { GDCLASS(VoxelColorPalette, Resource) @@ -23,11 +25,11 @@ public: // Internal - inline void set_color8(uint8_t i, zylann::Color8 c) { + inline void set_color8(uint8_t i, Color8 c) { _colors[i] = c; } - inline zylann::Color8 get_color8(uint8_t i) const { + inline Color8 get_color8(uint8_t i) const { return _colors[i]; } @@ -37,7 +39,9 @@ private: static void _bind_methods(); - zylann::FixedArray _colors; + FixedArray _colors; }; +} // namespace zylann::voxel + #endif // VOXEL_COLOR_PALETTE_H diff --git a/meshers/cubes/voxel_mesher_cubes.cpp b/meshers/cubes/voxel_mesher_cubes.cpp index 974f2974..443b49f9 100644 --- a/meshers/cubes/voxel_mesher_cubes.cpp +++ b/meshers/cubes/voxel_mesher_cubes.cpp @@ -694,8 +694,6 @@ Ref make_greedy_atlas( return image; } -} // namespace zylann::voxel - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// thread_local VoxelMesherCubes::Cache VoxelMesherCubes::_cache; @@ -707,9 +705,6 @@ VoxelMesherCubes::VoxelMesherCubes() { VoxelMesherCubes::~VoxelMesherCubes() {} void VoxelMesherCubes::build(VoxelMesher::Output &output, const VoxelMesher::Input &input) { - using namespace zylann; - using namespace voxel; - VOXEL_PROFILE_SCOPE(); const int channel = VoxelBufferInternal::CHANNEL_COLOR; Cache &cache = _cache; @@ -1032,3 +1027,5 @@ void VoxelMesherCubes::_bind_methods() { BIND_ENUM_CONSTANT(COLOR_MESHER_PALETTE); BIND_ENUM_CONSTANT(COLOR_SHADER_PALETTE); } + +} // namespace zylann::voxel diff --git a/meshers/cubes/voxel_mesher_cubes.h b/meshers/cubes/voxel_mesher_cubes.h index c8741039..6004100e 100644 --- a/meshers/cubes/voxel_mesher_cubes.h +++ b/meshers/cubes/voxel_mesher_cubes.h @@ -5,6 +5,8 @@ #include "voxel_color_palette.h" #include +namespace zylann::voxel { + // A super simple mesher only producing colored cubes class VoxelMesherCubes : public VoxelMesher { GDCLASS(VoxelMesherCubes, VoxelMesher) @@ -83,7 +85,7 @@ public: unsigned int size_y; unsigned int surface_index; }; - std::vector colors; + std::vector colors; std::vector images; void clear() { @@ -104,7 +106,7 @@ private: }; struct Cache { - zylann::FixedArray arrays_per_material; + FixedArray arrays_per_material; std::vector mask_memory_pool; GreedyAtlasData greedy_atlas_data; }; @@ -117,7 +119,9 @@ private: static thread_local Cache _cache; }; -VARIANT_ENUM_CAST(VoxelMesherCubes::ColorMode); -VARIANT_ENUM_CAST(VoxelMesherCubes::Materials); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherCubes::ColorMode); +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherCubes::Materials); #endif // VOXEL_MESHER_CUBES_H diff --git a/meshers/dmc/voxel_mesher_dmc.cpp b/meshers/dmc/voxel_mesher_dmc.cpp index b082bec0..690330af 100644 --- a/meshers/dmc/voxel_mesher_dmc.cpp +++ b/meshers/dmc/voxel_mesher_dmc.cpp @@ -1338,6 +1338,8 @@ void polygonize_volume_directly(const VoxelBufferInternal &voxels, Vector3i min, } //namespace zylann::voxel::dmc +namespace zylann::voxel { + #define BUILD_OCTREE_BOTTOM_UP thread_local VoxelMesherDMC::Cache VoxelMesherDMC::_cache; @@ -1585,3 +1587,5 @@ void VoxelMesherDMC::_bind_methods() { BIND_ENUM_CONSTANT(SEAM_NONE); BIND_ENUM_CONSTANT(SEAM_MARCHING_SQUARE_SKIRTS); } + +} // namespace zylann::voxel diff --git a/meshers/dmc/voxel_mesher_dmc.h b/meshers/dmc/voxel_mesher_dmc.h index aa3d7416..e4b7485d 100644 --- a/meshers/dmc/voxel_mesher_dmc.h +++ b/meshers/dmc/voxel_mesher_dmc.h @@ -60,6 +60,8 @@ struct DualGrid { } // namespace zylann::voxel::dmc +namespace zylann::voxel { + // Mesher extending Marching Cubes using a dual grid. class VoxelMesherDMC : public VoxelMesher { GDCLASS(VoxelMesherDMC, VoxelMesher) @@ -120,9 +122,9 @@ private: }; struct Cache { - zylann::voxel::dmc::MeshBuilder mesh_builder; - zylann::voxel::dmc::DualGrid dual_grid; - zylann::voxel::dmc::OctreeNodePool octree_node_pool; + dmc::MeshBuilder mesh_builder; + dmc::DualGrid dual_grid; + dmc::OctreeNodePool octree_node_pool; }; // Parameters @@ -142,8 +144,10 @@ private: Stats _stats; }; -VARIANT_ENUM_CAST(VoxelMesherDMC::SimplifyMode) -VARIANT_ENUM_CAST(VoxelMesherDMC::MeshMode) -VARIANT_ENUM_CAST(VoxelMesherDMC::SeamMode) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherDMC::SimplifyMode) +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherDMC::MeshMode) +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherDMC::SeamMode) #endif // VOXEL_MESHER_DMC_H diff --git a/meshers/transvoxel/voxel_mesher_transvoxel.cpp b/meshers/transvoxel/voxel_mesher_transvoxel.cpp index 4359cfca..fc4a4847 100644 --- a/meshers/transvoxel/voxel_mesher_transvoxel.cpp +++ b/meshers/transvoxel/voxel_mesher_transvoxel.cpp @@ -5,8 +5,7 @@ #include "../../util/profiling.h" #include "transvoxel_tables.cpp" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelMesherTransvoxel::VoxelMesherTransvoxel() { set_padding(transvoxel::MIN_PADDING, transvoxel::MAX_PADDING); @@ -306,3 +305,5 @@ void VoxelMesherTransvoxel::_bind_methods() { BIND_ENUM_CONSTANT(TEXTURES_NONE); BIND_ENUM_CONSTANT(TEXTURES_BLEND_4_OVER_16); } + +} // namespace zylann::voxel diff --git a/meshers/transvoxel/voxel_mesher_transvoxel.h b/meshers/transvoxel/voxel_mesher_transvoxel.h index 1ee87557..e0bbec03 100644 --- a/meshers/transvoxel/voxel_mesher_transvoxel.h +++ b/meshers/transvoxel/voxel_mesher_transvoxel.h @@ -6,13 +6,15 @@ class ArrayMesh; +namespace zylann::voxel { + class VoxelMesherTransvoxel : public VoxelMesher { GDCLASS(VoxelMesherTransvoxel, VoxelMesher) public: enum TexturingMode { - TEXTURES_NONE = zylann::voxel::transvoxel::TEXTURES_NONE, - TEXTURES_BLEND_4_OVER_16 = zylann::voxel::transvoxel::TEXTURES_BLEND_4_OVER_16 + TEXTURES_NONE = transvoxel::TEXTURES_NONE, + TEXTURES_BLEND_4_OVER_16 = transvoxel::TEXTURES_BLEND_4_OVER_16 }; VoxelMesherTransvoxel(); @@ -40,7 +42,7 @@ protected: static void _bind_methods(); private: - void fill_surface_arrays(Array &arrays, const zylann::voxel::transvoxel::MeshArrays &src); + void fill_surface_arrays(Array &arrays, const transvoxel::MeshArrays &src); TexturingMode _texture_mode = TEXTURES_NONE; @@ -53,6 +55,8 @@ private: MeshOptimizationParams _mesh_optimization_params; }; -VARIANT_ENUM_CAST(VoxelMesherTransvoxel::TexturingMode); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelMesherTransvoxel::TexturingMode); #endif // VOXEL_MESHER_TRANSVOXEL_H diff --git a/meshers/voxel_mesher.cpp b/meshers/voxel_mesher.cpp index 670ef3c2..f878d4a1 100644 --- a/meshers/voxel_mesher.cpp +++ b/meshers/voxel_mesher.cpp @@ -2,7 +2,7 @@ #include "../storage/voxel_buffer.h" #include "../util/godot/funcs.h" -using namespace zylann; +namespace zylann::voxel { Ref VoxelMesher::build_mesh(Ref voxels, Array materials) { ERR_FAIL_COND_V(voxels.is_null(), Ref()); @@ -66,3 +66,5 @@ void VoxelMesher::_bind_methods() { ClassDB::bind_method(D_METHOD("get_minimum_padding"), &VoxelMesher::get_minimum_padding); ClassDB::bind_method(D_METHOD("get_maximum_padding"), &VoxelMesher::get_maximum_padding); } + +} // namespace zylann::voxel diff --git a/meshers/voxel_mesher.h b/meshers/voxel_mesher.h index 0f73ea05..98b31b23 100644 --- a/meshers/voxel_mesher.h +++ b/meshers/voxel_mesher.h @@ -5,24 +5,23 @@ #include "../util/fixed_array.h" #include -class VoxelBuffer; - namespace zylann::voxel { + +class VoxelBuffer; class VoxelBufferInternal; -} class VoxelMesher : public Resource { GDCLASS(VoxelMesher, Resource) public: struct Input { - const zylann::voxel::VoxelBufferInternal &voxels; + const VoxelBufferInternal &voxels; int lod; // = 0; // Not initialized because it confused GCC }; struct Output { // Each surface correspond to a different material Vector surfaces; - zylann::FixedArray, zylann::voxel::Cube::SIDE_COUNT> transition_surfaces; + FixedArray, Cube::SIDE_COUNT> transition_surfaces; Mesh::PrimitiveType primitive_type = Mesh::PRIMITIVE_TRIANGLES; unsigned int mesh_flags = 0; Ref atlas_image; @@ -68,4 +67,6 @@ private: unsigned int _maximum_padding = 0; }; +} // namespace zylann::voxel + #endif // VOXEL_MESHER_H diff --git a/register_types.cpp b/register_types.cpp index 89e4fd8f..1cde591d 100644 --- a/register_types.cpp +++ b/register_types.cpp @@ -160,7 +160,7 @@ void register_voxel_types() { EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); - EditorPlugins::add_by_type(); + EditorPlugins::add_by_type(); EditorPlugins::add_by_type(); #ifdef VOXEL_ENABLE_FAST_NOISE_2 EditorPlugins::add_by_type(); diff --git a/server/voxel_server.h b/server/voxel_server.h index ab9f6093..acb05973 100644 --- a/server/voxel_server.h +++ b/server/voxel_server.h @@ -12,8 +12,6 @@ #include -class VoxelNode; - namespace zylann { class AsyncDependencyTracker; } diff --git a/server/voxel_server_updater.cpp b/server/voxel_server_updater.cpp index 5a02b4ea..7257a4d8 100644 --- a/server/voxel_server_updater.cpp +++ b/server/voxel_server_updater.cpp @@ -5,9 +5,9 @@ // Needed for doing `Node *root = SceneTree::get_root()`, Window* is forward-declared #include -namespace { +namespace zylann::voxel { + bool g_updater_created = false; -} VoxelServerUpdater::VoxelServerUpdater() { PRINT_VERBOSE("Creating VoxelServerUpdater"); @@ -53,3 +53,5 @@ void VoxelServerUpdater::_notification(int p_what) { break; } } + +} // namespace zylann::voxel diff --git a/server/voxel_server_updater.h b/server/voxel_server_updater.h index 71ba54d5..b44e8f53 100644 --- a/server/voxel_server_updater.h +++ b/server/voxel_server_updater.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel { + // TODO Hack to make VoxelServer update... need ways to integrate callbacks from main loop! class VoxelServerUpdater : public Node { GDCLASS(VoxelServerUpdater, Node) @@ -17,4 +19,6 @@ private: VoxelServerUpdater(); }; +} // namespace zylann::voxel + #endif // VOXEL_SERVER_UPDATER_H diff --git a/storage/voxel_buffer.cpp b/storage/voxel_buffer.cpp index 0852697a..63898824 100644 --- a/storage/voxel_buffer.cpp +++ b/storage/voxel_buffer.cpp @@ -4,8 +4,7 @@ #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { const char *VoxelBuffer::CHANNEL_ID_HINT_STRING = "Type,Sdf,Color,Indices,Weights,Data5,Data6,Data7"; @@ -196,3 +195,5 @@ void VoxelBuffer::_bind_methods() { BIND_CONSTANT(MAX_SIZE); } + +} // namespace zylann::voxel diff --git a/storage/voxel_buffer.h b/storage/voxel_buffer.h index e40fb2ab..c84f2192 100644 --- a/storage/voxel_buffer.h +++ b/storage/voxel_buffer.h @@ -4,9 +4,12 @@ #include "voxel_buffer_internal.h" #include -class VoxelTool; class Image; +namespace zylann::voxel { + +class VoxelTool; + // TODO I wish I could call the original class `VoxelBuffer` and expose this other one with that name. // Godot doesn't seem to allow doing that. So the original class had to be named `VoxelBufferInternal`... @@ -18,33 +21,33 @@ class VoxelBuffer : public RefCounted { public: enum ChannelId { - CHANNEL_TYPE = zylann::voxel::VoxelBufferInternal::CHANNEL_TYPE, - CHANNEL_SDF = zylann::voxel::VoxelBufferInternal::CHANNEL_SDF, - CHANNEL_COLOR = zylann::voxel::VoxelBufferInternal::CHANNEL_COLOR, - CHANNEL_INDICES = zylann::voxel::VoxelBufferInternal::CHANNEL_INDICES, - CHANNEL_WEIGHTS = zylann::voxel::VoxelBufferInternal::CHANNEL_WEIGHTS, - CHANNEL_DATA5 = zylann::voxel::VoxelBufferInternal::CHANNEL_DATA5, - CHANNEL_DATA6 = zylann::voxel::VoxelBufferInternal::CHANNEL_DATA6, - CHANNEL_DATA7 = zylann::voxel::VoxelBufferInternal::CHANNEL_DATA7, - MAX_CHANNELS = zylann::voxel::VoxelBufferInternal::MAX_CHANNELS, + CHANNEL_TYPE = VoxelBufferInternal::CHANNEL_TYPE, + CHANNEL_SDF = VoxelBufferInternal::CHANNEL_SDF, + CHANNEL_COLOR = VoxelBufferInternal::CHANNEL_COLOR, + CHANNEL_INDICES = VoxelBufferInternal::CHANNEL_INDICES, + CHANNEL_WEIGHTS = VoxelBufferInternal::CHANNEL_WEIGHTS, + CHANNEL_DATA5 = VoxelBufferInternal::CHANNEL_DATA5, + CHANNEL_DATA6 = VoxelBufferInternal::CHANNEL_DATA6, + CHANNEL_DATA7 = VoxelBufferInternal::CHANNEL_DATA7, + MAX_CHANNELS = VoxelBufferInternal::MAX_CHANNELS, }; // TODO use C++17 inline to initialize right here... static const char *CHANNEL_ID_HINT_STRING; enum Compression { - COMPRESSION_NONE = zylann::voxel::VoxelBufferInternal::COMPRESSION_NONE, - COMPRESSION_UNIFORM = zylann::voxel::VoxelBufferInternal::COMPRESSION_UNIFORM, + COMPRESSION_NONE = VoxelBufferInternal::COMPRESSION_NONE, + COMPRESSION_UNIFORM = VoxelBufferInternal::COMPRESSION_UNIFORM, //COMPRESSION_RLE, - COMPRESSION_COUNT = zylann::voxel::VoxelBufferInternal::COMPRESSION_COUNT + COMPRESSION_COUNT = VoxelBufferInternal::COMPRESSION_COUNT }; enum Depth { - DEPTH_8_BIT = zylann::voxel::VoxelBufferInternal::DEPTH_8_BIT, - DEPTH_16_BIT = zylann::voxel::VoxelBufferInternal::DEPTH_16_BIT, - DEPTH_32_BIT = zylann::voxel::VoxelBufferInternal::DEPTH_32_BIT, - DEPTH_64_BIT = zylann::voxel::VoxelBufferInternal::DEPTH_64_BIT, - DEPTH_COUNT = zylann::voxel::VoxelBufferInternal::DEPTH_COUNT + DEPTH_8_BIT = VoxelBufferInternal::DEPTH_8_BIT, + DEPTH_16_BIT = VoxelBufferInternal::DEPTH_16_BIT, + DEPTH_32_BIT = VoxelBufferInternal::DEPTH_32_BIT, + DEPTH_64_BIT = VoxelBufferInternal::DEPTH_64_BIT, + DEPTH_COUNT = VoxelBufferInternal::DEPTH_COUNT }; // Limit was made explicit for serialization reasons, and also because there must be a reasonable one @@ -53,18 +56,18 @@ public: // Constructs a new buffer VoxelBuffer(); // Reference an existing buffer - VoxelBuffer(std::shared_ptr &other); + VoxelBuffer(std::shared_ptr &other); ~VoxelBuffer(); - inline const zylann::voxel::VoxelBufferInternal &get_buffer() const { + inline const VoxelBufferInternal &get_buffer() const { #ifdef DEBUG_ENABLED CRASH_COND(_buffer == nullptr); #endif return *_buffer; } - inline zylann::voxel::VoxelBufferInternal &get_buffer() { + inline VoxelBufferInternal &get_buffer() { #ifdef DEBUG_ENABLED CRASH_COND(_buffer == nullptr); #endif @@ -163,11 +166,13 @@ private: static void _bind_methods(); // Not sure yet if we'll really need shared_ptr or just no pointer - std::shared_ptr _buffer; + std::shared_ptr _buffer; }; -VARIANT_ENUM_CAST(VoxelBuffer::ChannelId) -VARIANT_ENUM_CAST(VoxelBuffer::Depth) -VARIANT_ENUM_CAST(VoxelBuffer::Compression) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelBuffer::ChannelId) +VARIANT_ENUM_CAST(zylann::voxel::VoxelBuffer::Depth) +VARIANT_ENUM_CAST(zylann::voxel::VoxelBuffer::Compression) #endif // VOXEL_BUFFER_H diff --git a/storage/voxel_buffer_internal.h b/storage/voxel_buffer_internal.h index d0480611..3ea7c324 100644 --- a/storage/voxel_buffer_internal.h +++ b/storage/voxel_buffer_internal.h @@ -12,11 +12,12 @@ #include #include -class VoxelTool; class Image; namespace zylann::voxel { +class VoxelTool; + // TODO This class is still suffixed "Internal" to avoid conflict with the registered Godot class. // Even though the other class is not namespaced yet, it is unsure if it will remain that way after the future port // to GDExtension diff --git a/storage/voxel_data_map.h b/storage/voxel_data_map.h index 2bf9b8f5..ecd2d2f0 100644 --- a/storage/voxel_data_map.h +++ b/storage/voxel_data_map.h @@ -8,10 +8,10 @@ #include #include -class VoxelGenerator; - namespace zylann::voxel { +class VoxelGenerator; + // Infinite voxel storage by means of octants like Gridmap, within a constant LOD. // Convenience functions to access VoxelBuffers internally will lock them to protect against multithreaded access. // However, the map itself is not thread-safe. diff --git a/streams/region/region_file.h b/streams/region/region_file.h index b9807e2e..bce2f0c7 100644 --- a/streams/region/region_file.h +++ b/streams/region/region_file.h @@ -84,8 +84,8 @@ public: bool set_format(const RegionFormat &format); const RegionFormat &get_format() const; - Error load_block(Vector3i position, VoxelBufferInternal &out_block, zylann::voxel::BlockSerializer &serializer); - Error save_block(Vector3i position, VoxelBufferInternal &block, zylann::voxel::BlockSerializer &serializer); + Error load_block(Vector3i position, VoxelBufferInternal &out_block, BlockSerializer &serializer); + Error save_block(Vector3i position, VoxelBufferInternal &block, BlockSerializer &serializer); unsigned int get_header_block_count() const; bool has_block(Vector3i position) const; diff --git a/streams/region/voxel_stream_region_files.cpp b/streams/region/voxel_stream_region_files.cpp index 5c6727fd..845945a6 100644 --- a/streams/region/voxel_stream_region_files.cpp +++ b/streams/region/voxel_stream_region_files.cpp @@ -8,8 +8,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { namespace { const uint8_t FORMAT_VERSION = 3; @@ -195,7 +194,7 @@ void VoxelStreamRegionFiles::_immerge_block(VoxelBufferInternal &voxel_buffer, V if (load_res != FILE_OK && load_res != FILE_CANT_OPEN) { // The file is present but there is a problem with it String meta_path = _directory_path.plus_file(META_FILE_NAME); - ERR_PRINT(String("Could not read {0}: error {1}").format(varray(meta_path, ::to_string(load_res)))); + ERR_PRINT(String("Could not read {0}: error {1}").format(varray(meta_path, zylann::to_string(load_res)))); return; } } @@ -896,3 +895,5 @@ void VoxelStreamRegionFiles::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "block_size_po2"), "set_block_size_po2", "get_region_size_po2"); ADD_PROPERTY(PropertyInfo(Variant::INT, "sector_size"), "set_sector_size", "get_sector_size"); } + +} // namespace zylann::voxel diff --git a/streams/region/voxel_stream_region_files.h b/streams/region/voxel_stream_region_files.h index 52bd41fd..959a98f1 100644 --- a/streams/region/voxel_stream_region_files.h +++ b/streams/region/voxel_stream_region_files.h @@ -9,6 +9,8 @@ class FileAccess; +namespace zylann::voxel { + // TODO Rename VoxelStreamRegionForest // Loads and saves blocks to the filesystem, in multiple region files indexed by world position, under a directory. @@ -24,8 +26,8 @@ public: VoxelStreamRegionFiles(); ~VoxelStreamRegionFiles(); - Result emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; - void immerge_block(zylann::voxel::VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; + Result emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; + void immerge_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; void emerge_blocks(Span p_blocks, Vector &out_results) override; void immerge_blocks(Span p_blocks) override; @@ -64,11 +66,11 @@ private: EMERGE_FAILED }; - EmergeResult _emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod); - void _immerge_block(zylann::voxel::VoxelBufferInternal &voxel_buffer, Vector3i origin_in_voxels, int lod); + EmergeResult _emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod); + void _immerge_block(VoxelBufferInternal &voxel_buffer, Vector3i origin_in_voxels, int lod); - zylann::FileResult save_meta(); - zylann::FileResult load_meta(); + FileResult save_meta(); + FileResult load_meta(); Vector3i get_block_position_from_voxels(const Vector3i &origin_in_voxels) const; Vector3i get_region_position_from_blocks(const Vector3i &block_position) const; void close_all_regions(); @@ -83,8 +85,7 @@ private: uint8_t lod_count = 0; uint8_t block_size_po2 = 0; // How many voxels in a cubic block uint8_t region_size_po2 = 0; // How many blocks in one cubic region - zylann::FixedArray - channel_depths; + FixedArray channel_depths; uint32_t sector_size = 0; // Blocks are stored at offsets multiple of that size }; @@ -110,7 +111,7 @@ private: } }; - static thread_local zylann::voxel::BlockSerializer _block_serializer; + static thread_local BlockSerializer _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. @@ -120,7 +121,7 @@ private: Vector3i position; int lod = 0; bool file_exists = false; - zylann::voxel::RegionFile region; + RegionFile region; uint64_t last_opened = 0; //uint64_t last_accessed; }; @@ -136,4 +137,6 @@ private: Mutex _mutex; }; +} // namespace zylann::voxel + #endif // VOXEL_STREAM_REGION_H diff --git a/streams/sqlite/voxel_stream_sqlite.cpp b/streams/sqlite/voxel_stream_sqlite.cpp index cc7a4894..39cd1f2a 100644 --- a/streams/sqlite/voxel_stream_sqlite.cpp +++ b/streams/sqlite/voxel_stream_sqlite.cpp @@ -572,13 +572,8 @@ void VoxelStreamSQLiteInternal::save_meta(Meta meta) { } } -} // namespace zylann::voxel - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -using namespace zylann; -using namespace voxel; - thread_local BlockSerializer VoxelStreamSQLite::_voxel_block_serializer; thread_local std::vector VoxelStreamSQLite::_temp_block_data; thread_local std::vector VoxelStreamSQLite::_temp_compressed_block_data; @@ -986,3 +981,5 @@ void VoxelStreamSQLite::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "database_path", PROPERTY_HINT_FILE), "set_database_path", "get_database_path"); } + +} // namespace zylann::voxel diff --git a/streams/sqlite/voxel_stream_sqlite.h b/streams/sqlite/voxel_stream_sqlite.h index ac03ac4f..eab98c13 100644 --- a/streams/sqlite/voxel_stream_sqlite.h +++ b/streams/sqlite/voxel_stream_sqlite.h @@ -8,8 +8,8 @@ #include namespace zylann::voxel { + class VoxelStreamSQLiteInternal; -} // Saves voxel data into a single SQLite database file. class VoxelStreamSQLite : public VoxelStream { @@ -23,8 +23,8 @@ public: void set_database_path(String path); String get_database_path() const; - Result emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; - void immerge_block(zylann::voxel::VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; + Result emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; + void immerge_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; void emerge_blocks(Span p_blocks, Vector &out_results) override; void immerge_blocks(Span p_blocks) override; @@ -57,21 +57,23 @@ private: // Because of this, in our use case, it might be simpler to just leave SQLite in thread-safe mode, // and synchronize ourselves. - zylann::voxel::VoxelStreamSQLiteInternal *get_connection(); - void recycle_connection(zylann::voxel::VoxelStreamSQLiteInternal *con); - void flush_cache(zylann::voxel::VoxelStreamSQLiteInternal *con); + VoxelStreamSQLiteInternal *get_connection(); + void recycle_connection(VoxelStreamSQLiteInternal *con); + void flush_cache(VoxelStreamSQLiteInternal *con); static void _bind_methods(); String _connection_path; - std::vector _connection_pool; + std::vector _connection_pool; Mutex _connection_mutex; - zylann::voxel::VoxelStreamCache _cache; + VoxelStreamCache _cache; // TODO I should consider specialized memory allocators - static thread_local zylann::voxel::BlockSerializer _voxel_block_serializer; + static thread_local BlockSerializer _voxel_block_serializer; static thread_local std::vector _temp_block_data; static thread_local std::vector _temp_compressed_block_data; }; +} // namespace zylann::voxel + #endif // VOXEL_STREAM_SQLITE_H diff --git a/streams/vox_loader.cpp b/streams/vox_loader.cpp index f5b5f1de..31daddf1 100644 --- a/streams/vox_loader.cpp +++ b/streams/vox_loader.cpp @@ -3,8 +3,7 @@ #include "../storage/voxel_buffer.h" #include "vox_data.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { Error VoxelVoxLoader::load_from_file(String fpath, Ref p_voxels, Ref palette) { ERR_FAIL_COND_V(p_voxels.is_null(), ERR_INVALID_PARAMETER); @@ -76,3 +75,5 @@ Error VoxelVoxLoader::load_from_file(String fpath, Ref p_voxels, Re void VoxelVoxLoader::_bind_methods() { ClassDB::bind_method(D_METHOD("load_from_file", "fpath", "voxels"), &VoxelVoxLoader::load_from_file); } + +} // namespace zylann::voxel diff --git a/streams/vox_loader.h b/streams/vox_loader.h index 53167508..70f1ca73 100644 --- a/streams/vox_loader.h +++ b/streams/vox_loader.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel { + class VoxelBuffer; class VoxelColorPalette; @@ -19,4 +21,6 @@ private: static void _bind_methods(); }; +} // namespace zylann::voxel + #endif // VOX_LOADER_H diff --git a/streams/voxel_block_request.h b/streams/voxel_block_request.h index 6979970c..09e4f9f2 100644 --- a/streams/voxel_block_request.h +++ b/streams/voxel_block_request.h @@ -6,9 +6,11 @@ #include "instance_data.h" #include +namespace zylann::voxel { + // TODO Rename VoxelStreamBlockRequest struct VoxelBlockRequest { - zylann::voxel::VoxelBufferInternal &voxel_buffer; + VoxelBufferInternal &voxel_buffer; Vector3i origin_in_voxels; int lod; }; @@ -19,4 +21,6 @@ struct VoxelStreamInstanceDataRequest { uint8_t lod; }; +} // namespace zylann::voxel + #endif // VOXEL_BLOCK_REQUEST_H diff --git a/streams/voxel_block_serializer.cpp b/streams/voxel_block_serializer.cpp index 47aef0a7..b20d4c4e 100644 --- a/streams/voxel_block_serializer.cpp +++ b/streams/voxel_block_serializer.cpp @@ -439,8 +439,6 @@ void BlockSerializer::deserialize(Ref peer, VoxelBufferInternal &vox } } -} // namespace zylann::voxel - //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// int VoxelBlockSerializer::serialize(Ref peer, Ref voxel_buffer, bool compress) { @@ -461,3 +459,5 @@ void VoxelBlockSerializer::_bind_methods() { ClassDB::bind_method( D_METHOD("deserialize", "peer", "voxel_buffer", "size", "decompress"), &VoxelBlockSerializer::deserialize); } + +} // namespace zylann::voxel diff --git a/streams/voxel_block_serializer.h b/streams/voxel_block_serializer.h index 979aa36f..5055eaf8 100644 --- a/streams/voxel_block_serializer.h +++ b/streams/voxel_block_serializer.h @@ -41,8 +41,6 @@ private: FileAccessMemory _file_access_memory; }; -} // namespace zylann::voxel - class VoxelBuffer; class VoxelBlockSerializer : public RefCounted { @@ -54,7 +52,9 @@ public: private: static void _bind_methods(); - zylann::voxel::BlockSerializer _serializer; + BlockSerializer _serializer; }; +} // namespace zylann::voxel + #endif // VOXEL_BLOCK_SERIALIZER_H diff --git a/streams/voxel_stream.h b/streams/voxel_stream.h index efab6c83..6fc46138 100644 --- a/streams/voxel_stream.h +++ b/streams/voxel_stream.h @@ -5,6 +5,8 @@ #include "voxel_block_request.h" #include +namespace zylann::voxel { + // Provides access to a source of paged voxel data, which may load and save. // This is intented for files, so it may run in a single background thread and gets requests in batches. // Must be implemented in a thread-safe way. @@ -36,10 +38,10 @@ public: // Queries a block of voxels beginning at the given world-space voxel position and LOD. // If you use LOD, the result at a given coordinate must always remain the same regardless of it. // In other words, voxels values must solely depend on their coordinates or fixed parameters. - virtual Result emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod); + virtual Result emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod); // TODO Deprecate - virtual void immerge_block(zylann::voxel::VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod); + virtual void immerge_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod); // TODO Rename load_voxel_blocks // Note: Don't modify the order of `p_blocks`. @@ -59,7 +61,7 @@ public: struct FullLoadingResult { struct Block { - std::shared_ptr voxels; + std::shared_ptr voxels; std::unique_ptr instances_data; Vector3i position; unsigned int lod; @@ -107,6 +109,8 @@ private: RWLock _parameters_lock; }; -VARIANT_ENUM_CAST(VoxelStream::Result); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelStream::Result); #endif // VOXEL_STREAM_H diff --git a/streams/voxel_stream_block_files.h b/streams/voxel_stream_block_files.h index 183a1df4..b7fc6e3f 100644 --- a/streams/voxel_stream_block_files.h +++ b/streams/voxel_stream_block_files.h @@ -7,6 +7,8 @@ class FileAccess; +namespace zylann::voxel { + // 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. @@ -15,8 +17,8 @@ class VoxelStreamBlockFiles : public VoxelStream { public: VoxelStreamBlockFiles(); - Result emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; - void immerge_block(zylann::voxel::VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; + Result emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; + void immerge_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; int get_used_channels_mask() const override; @@ -29,13 +31,13 @@ protected: static void _bind_methods(); private: - zylann::FileResult save_meta(); - zylann::FileResult load_meta(); - zylann::FileResult load_or_create_meta(); + FileResult save_meta(); + FileResult load_meta(); + FileResult load_or_create_meta(); 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 zylann::voxel::BlockSerializer _block_serializer; + static thread_local BlockSerializer _block_serializer; String _directory_path; @@ -43,8 +45,7 @@ private: uint8_t version = -1; uint8_t lod_count = 0; uint8_t block_size_po2 = 0; // How many voxels in a block - zylann::FixedArray - channel_depths; + FixedArray channel_depths; }; Meta _meta; @@ -52,4 +53,6 @@ private: bool _meta_saved = false; }; +} // namespace zylann::voxel + #endif // VOXEL_STREAM_BLOCK_FILES_H diff --git a/streams/voxel_stream_script.cpp b/streams/voxel_stream_script.cpp index 4e505fae..fc3a27cc 100644 --- a/streams/voxel_stream_script.cpp +++ b/streams/voxel_stream_script.cpp @@ -2,7 +2,7 @@ #include "../constants/voxel_string_names.h" #include "../util/godot/funcs.h" -using namespace zylann::voxel; +namespace zylann::voxel { VoxelStream::Result VoxelStreamScript::emerge_block( VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) { @@ -60,3 +60,5 @@ void VoxelStreamScript::_bind_methods() { // BIND_VMETHOD(MethodInfo(Variant::INT, "_get_used_channels_mask")); } + +} // namespace zylann::voxel diff --git a/streams/voxel_stream_script.h b/streams/voxel_stream_script.h index 954948d3..fe6cfe27 100644 --- a/streams/voxel_stream_script.h +++ b/streams/voxel_stream_script.h @@ -5,14 +5,16 @@ #include // needed for GDVIRTUAL macro #include // Also needed for GDVIRTUAL macro... +namespace zylann::voxel { + // Provides access to a source of paged voxel data, which may load and save. // Must be implemented in a multi-thread-safe way. // If you are looking for a more specialized API to generate voxels, use VoxelGenerator. class VoxelStreamScript : public VoxelStream { GDCLASS(VoxelStreamScript, VoxelStream) public: - Result emerge_block(zylann::voxel::VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; - void immerge_block(zylann::voxel::VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; + Result emerge_block(VoxelBufferInternal &out_buffer, Vector3i origin_in_voxels, int lod) override; + void immerge_block(VoxelBufferInternal &buffer, Vector3i origin_in_voxels, int lod) override; int get_used_channels_mask() const override; @@ -26,4 +28,6 @@ protected: static void _bind_methods(); }; +} // namespace zylann::voxel + #endif // VOXEL_STREAM_SCRIPT_H diff --git a/terrain/instancing/voxel_instance_component.h b/terrain/instancing/voxel_instance_component.h index 52ab6e1d..ab8828fa 100644 --- a/terrain/instancing/voxel_instance_component.h +++ b/terrain/instancing/voxel_instance_component.h @@ -4,6 +4,8 @@ #include "voxel_instancer.h" #include +namespace zylann::voxel { + // Used as child of scene items instanced with VoxelInstancer. // // It is needed because such instances are tied with some of the logic in VoxelInstancer. @@ -109,4 +111,6 @@ private: int _instance_index = -1; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCE_COMPONENT_H diff --git a/terrain/instancing/voxel_instance_generator.cpp b/terrain/instancing/voxel_instance_generator.cpp index 99db5881..7b66edc5 100644 --- a/terrain/instancing/voxel_instance_generator.cpp +++ b/terrain/instancing/voxel_instance_generator.cpp @@ -5,7 +5,7 @@ #include #include -using namespace zylann; +namespace zylann::voxel { namespace { const float MAX_DENSITY = 1.f; @@ -772,3 +772,5 @@ void VoxelInstanceGenerator::_bind_methods() { BIND_ENUM_CONSTANT(DIMENSION_3D); BIND_ENUM_CONSTANT(DIMENSION_COUNT); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instance_generator.h b/terrain/instancing/voxel_instance_generator.h index 459c1754..c7f4fd3d 100644 --- a/terrain/instancing/voxel_instance_generator.h +++ b/terrain/instancing/voxel_instance_generator.h @@ -8,6 +8,8 @@ #include #include +namespace zylann::voxel { + // TODO This may have to be moved to the meshing thread some day // Decides where to spawn instances on top of a voxel surface. @@ -46,7 +48,11 @@ public: DISTRIBUTION_COUNT }; - enum Dimension { DIMENSION_2D = 0, DIMENSION_3D, DIMENSION_COUNT }; + enum Dimension { // + DIMENSION_2D = 0, + DIMENSION_3D, + DIMENSION_COUNT + }; // This API might change so for now it's not exposed to scripts void generate_transforms(std::vector &out_transforms, Vector3i grid_position, int lod_index, @@ -136,8 +142,10 @@ private: float _max_slope_degrees = 180.f; }; -VARIANT_ENUM_CAST(VoxelInstanceGenerator::EmitMode); -VARIANT_ENUM_CAST(VoxelInstanceGenerator::Distribution); -VARIANT_ENUM_CAST(VoxelInstanceGenerator::Dimension); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelInstanceGenerator::EmitMode); +VARIANT_ENUM_CAST(zylann::voxel::VoxelInstanceGenerator::Distribution); +VARIANT_ENUM_CAST(zylann::voxel::VoxelInstanceGenerator::Dimension); #endif // VOXEL_INSTANCE_GENERATOR_H diff --git a/terrain/instancing/voxel_instance_library.cpp b/terrain/instancing/voxel_instance_library.cpp index 03b131b2..034a832d 100644 --- a/terrain/instancing/voxel_instance_library.cpp +++ b/terrain/instancing/voxel_instance_library.cpp @@ -5,6 +5,8 @@ #include #include +namespace zylann::voxel { + VoxelInstanceLibrary::~VoxelInstanceLibrary() { for_each_item([this](int id, VoxelInstanceLibraryItemBase &item) { item.remove_listener(this, id); }); } @@ -176,3 +178,5 @@ void VoxelInstanceLibrary::_bind_methods() { BIND_CONSTANT(MAX_ID); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instance_library.h b/terrain/instancing/voxel_instance_library.h index 4013b862..c829bae3 100644 --- a/terrain/instancing/voxel_instance_library.h +++ b/terrain/instancing/voxel_instance_library.h @@ -3,6 +3,8 @@ #include "voxel_instance_library_item_base.h" +namespace zylann::voxel { + // Contains a list of items that can be used by VoxelInstancer, associated with a unique ID class VoxelInstanceLibrary : public Resource, public VoxelInstanceLibraryItemBase::IListener { GDCLASS(VoxelInstanceLibrary, Resource) @@ -59,4 +61,6 @@ private: Vector _listeners; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCER_LIBRARY_H diff --git a/terrain/instancing/voxel_instance_library_item.cpp b/terrain/instancing/voxel_instance_library_item.cpp index 7fcf8808..c4255e8e 100644 --- a/terrain/instancing/voxel_instance_library_item.cpp +++ b/terrain/instancing/voxel_instance_library_item.cpp @@ -6,6 +6,8 @@ #include #include +namespace zylann::voxel { + void VoxelInstanceLibraryItem::set_mesh(Ref mesh, int mesh_lod_index) { ERR_FAIL_INDEX(mesh_lod_index, static_cast(_mesh_lods.size())); if (_mesh_lods[mesh_lod_index] == mesh) { @@ -262,3 +264,5 @@ void VoxelInstanceLibraryItem::_bind_methods() { BIND_CONSTANT(MAX_MESH_LODS); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instance_library_item.h b/terrain/instancing/voxel_instance_library_item.h index 8da5036f..ca1fb2ab 100644 --- a/terrain/instancing/voxel_instance_library_item.h +++ b/terrain/instancing/voxel_instance_library_item.h @@ -7,6 +7,8 @@ // TODO Rename VoxelInstanceLibraryMultimeshItem (did not do it for compatibility) +namespace zylann::voxel { + // Settings for a model that can be used by VoxelInstancer class VoxelInstanceLibraryItem : public VoxelInstanceLibraryItemBase { GDCLASS(VoxelInstanceLibraryItem, VoxelInstanceLibraryItemBase) @@ -77,7 +79,7 @@ private: set_mesh(mesh, 3); } - zylann::FixedArray, MAX_MESH_LODS> _mesh_lods; + FixedArray, MAX_MESH_LODS> _mesh_lods; unsigned int _mesh_lod_count = 1; // It is preferred to have materials on the mesh already, @@ -91,4 +93,6 @@ private: Vector _collision_shapes; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCE_LIBRARY_ITEM_H diff --git a/terrain/instancing/voxel_instance_library_item_base.cpp b/terrain/instancing/voxel_instance_library_item_base.cpp index e5aa9fd0..167fa367 100644 --- a/terrain/instancing/voxel_instance_library_item_base.cpp +++ b/terrain/instancing/voxel_instance_library_item_base.cpp @@ -3,6 +3,8 @@ #include +namespace zylann::voxel { + void VoxelInstanceLibraryItemBase::set_item_name(String name) { _name = name; } @@ -103,3 +105,5 @@ void VoxelInstanceLibraryItemBase::_bind_methods() { "set_generator", "get_generator"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "persistent"), "set_persistent", "is_persistent"); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instance_library_item_base.h b/terrain/instancing/voxel_instance_library_item_base.h index 2219817a..dbac8852 100644 --- a/terrain/instancing/voxel_instance_library_item_base.h +++ b/terrain/instancing/voxel_instance_library_item_base.h @@ -6,10 +6,12 @@ // TODO Rename VoxelInstanceLibraryItem (did not do it for compatibility) +namespace zylann::voxel { + class VoxelInstanceLibraryItemBase : public Resource { GDCLASS(VoxelInstanceLibraryItemBase, Resource) public: - enum ChangeType { + enum ChangeType { // CHANGE_LOD_INDEX, CHANGE_GENERATOR, CHANGE_VISUAL, @@ -75,4 +77,6 @@ private: Vector _listeners; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCE_LIBRARY_ITEM_BASE_H diff --git a/terrain/instancing/voxel_instance_library_scene_item.cpp b/terrain/instancing/voxel_instance_library_scene_item.cpp index ae642532..7e401b71 100644 --- a/terrain/instancing/voxel_instance_library_scene_item.cpp +++ b/terrain/instancing/voxel_instance_library_scene_item.cpp @@ -1,5 +1,7 @@ #include "voxel_instance_library_scene_item.h" +namespace zylann::voxel { + void VoxelInstanceLibrarySceneItem::set_scene(Ref scene) { if (scene != _scene) { _scene = scene; @@ -15,6 +17,8 @@ void VoxelInstanceLibrarySceneItem::_bind_methods() { ClassDB::bind_method(D_METHOD("set_scene", "scene"), &VoxelInstanceLibrarySceneItem::set_scene); ClassDB::bind_method(D_METHOD("get_scene"), &VoxelInstanceLibrarySceneItem::get_scene); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), - "set_scene", "get_scene"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "scene", PROPERTY_HINT_RESOURCE_TYPE, "PackedScene"), "set_scene", + "get_scene"); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instance_library_scene_item.h b/terrain/instancing/voxel_instance_library_scene_item.h index 2454330c..870b0867 100644 --- a/terrain/instancing/voxel_instance_library_scene_item.h +++ b/terrain/instancing/voxel_instance_library_scene_item.h @@ -5,6 +5,8 @@ #include +namespace zylann::voxel { + class VoxelInstanceLibrarySceneItem : public VoxelInstanceLibraryItemBase { GDCLASS(VoxelInstanceLibrarySceneItem, VoxelInstanceLibraryItemBase) public: @@ -17,4 +19,6 @@ private: Ref _scene; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCE_LIBRARY_SCENE_ITEM_H diff --git a/terrain/instancing/voxel_instancer.cpp b/terrain/instancing/voxel_instancer.cpp index 499354b2..2bc8c7fb 100644 --- a/terrain/instancing/voxel_instancer.cpp +++ b/terrain/instancing/voxel_instancer.cpp @@ -17,8 +17,7 @@ #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelInstancer::VoxelInstancer() { set_notify_transform(true); @@ -1633,3 +1632,5 @@ void VoxelInstancer::_bind_methods() { BIND_ENUM_CONSTANT(UP_MODE_POSITIVE_Y); BIND_ENUM_CONSTANT(UP_MODE_SPHERE); } + +} // namespace zylann::voxel diff --git a/terrain/instancing/voxel_instancer.h b/terrain/instancing/voxel_instancer.h index 55ae36d0..d8f02a18 100644 --- a/terrain/instancing/voxel_instancer.h +++ b/terrain/instancing/voxel_instancer.h @@ -20,12 +20,15 @@ #include #include +class PhysicsBody3D; + +namespace zylann::voxel { + class VoxelLodTerrain; class VoxelInstancerRigidBody; class VoxelInstanceComponent; class VoxelInstanceLibrarySceneItem; class VoxelTool; -class PhysicsBody3D; // Note: a large part of this node could be made generic to support the sole idea of instancing within octants? // Even nodes like gridmaps could be rebuilt on top of this, if its concept of "grid" was decoupled. @@ -143,7 +146,7 @@ private: uint8_t lod_index; // Position in mesh block coordinate system Vector3i grid_position; - zylann::DirectMultiMeshInstance multimesh_instance; + DirectMultiMeshInstance multimesh_instance; // For physics we use nodes because it's easier to manage. // Such instances may be less numerous. // If the item associated to this block has no collisions, this will be empty. @@ -187,7 +190,7 @@ private: // Can't use `HashMap` because it lacks move semantics. std::unordered_map> loaded_instances_data; - zylann::FixedArray mesh_lod_distances; + FixedArray mesh_lod_distances; Lod() = default; Lod(const Lod &) = delete; // non construction-copyable @@ -196,7 +199,7 @@ private: UpMode _up_mode = UP_MODE_POSITIVE_Y; - zylann::FixedArray _lods; + FixedArray _lods; std::vector _blocks; // Does not have nulls HashMap _layers; // Each layer corresponds to a library item Ref _library; @@ -206,11 +209,13 @@ private: VoxelLodTerrain *_parent; #ifdef TOOLS_ENABLED - zylann::DebugRenderer _debug_renderer; + DebugRenderer _debug_renderer; bool _gizmos_enabled = false; #endif }; -VARIANT_ENUM_CAST(VoxelInstancer::UpMode); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelInstancer::UpMode); #endif // VOXEL_INSTANCER_H diff --git a/terrain/instancing/voxel_instancer_rigidbody.h b/terrain/instancing/voxel_instancer_rigidbody.h index 8668886a..295e3e19 100644 --- a/terrain/instancing/voxel_instancer_rigidbody.h +++ b/terrain/instancing/voxel_instancer_rigidbody.h @@ -4,6 +4,8 @@ #include "voxel_instancer.h" #include +namespace zylann::voxel { + // Provides collision to VoxelInstancer multimesh instances class VoxelInstancerRigidBody : public RigidDynamicBody3D { GDCLASS(VoxelInstancerRigidBody, RigidDynamicBody3D); @@ -63,4 +65,6 @@ private: int _instance_index = -1; }; +} // namespace zylann::voxel + #endif // VOXEL_INSTANCER_RIGIDBODY_H diff --git a/terrain/voxel_box_mover.cpp b/terrain/voxel_box_mover.cpp index e355120f..5adf266a 100644 --- a/terrain/voxel_box_mover.cpp +++ b/terrain/voxel_box_mover.cpp @@ -3,8 +3,7 @@ #include "../meshers/cubes/voxel_mesher_cubes.h" #include "../util/godot/funcs.h" -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { static AABB expand_with_vector(AABB box, Vector3 v) { if (v.x > 0) { @@ -202,7 +201,7 @@ Vector3 VoxelBoxMover::get_motion(Vector3 p_pos, Vector3 p_motion, AABB p_aabb, } // Calculate collisions (narrow phase) - const Vector3 slided_motion = ::get_motion(box, motion, potential_boxes); + const Vector3 slided_motion = zylann::voxel::get_motion(box, motion, potential_boxes); // Switch back to world const Vector3 world_slided_motion = to_world.basis.xform(slided_motion); @@ -226,3 +225,5 @@ Vector3 VoxelBoxMover::_b_get_motion(Vector3 pos, Vector3 motion, AABB aabb, Nod ERR_FAIL_COND_V(terrain == nullptr, Vector3()); return get_motion(pos, motion, aabb, terrain); } + +} // namespace zylann::voxel diff --git a/terrain/voxel_box_mover.h b/terrain/voxel_box_mover.h index b5f5c9c4..81557862 100644 --- a/terrain/voxel_box_mover.h +++ b/terrain/voxel_box_mover.h @@ -4,6 +4,8 @@ #include "voxel_terrain.h" #include +namespace zylann::voxel { + // Helper to get simple AABB physics class VoxelBoxMover : public RefCounted { GDCLASS(VoxelBoxMover, RefCounted) @@ -23,4 +25,6 @@ private: uint32_t _collision_mask = 0xffffffff; // Everything }; +} // namespace zylann::voxel + #endif // VOXEL_BOX_MOVER_H diff --git a/terrain/voxel_lod_terrain.cpp b/terrain/voxel_lod_terrain.cpp index 790c923b..002cfe55 100644 --- a/terrain/voxel_lod_terrain.cpp +++ b/terrain/voxel_lod_terrain.cpp @@ -17,8 +17,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { namespace { @@ -164,7 +163,7 @@ VoxelLodTerrain::VoxelLodTerrain() { // Infinite by default _bounds_in_voxels = Box3i::from_center_extents(Vector3i(), Vector3iUtil::create(constants::MAX_VOLUME_EXTENT)); - struct ApplyMeshUpdateTask : public zylann::ITimeSpreadTask { + struct ApplyMeshUpdateTask : public ITimeSpreadTask { void run() override { if (!VoxelServer::get_singleton()->is_volume_valid(volume_id)) { // The node can have been destroyed while this task was still pending @@ -488,8 +487,8 @@ void VoxelLodTerrain::set_mesh_block_active(VoxelMeshBlock &block, bool active) // Generates all non-present blocks in preparation for an edit. // This function schedules one parallel task for every block. // The returned tracker may be polled to detect when it is complete. -std::shared_ptr VoxelLodTerrain::preload_boxes_async( - Span voxel_boxes, Span next_tasks) { +std::shared_ptr VoxelLodTerrain::preload_boxes_async( + Span voxel_boxes, Span next_tasks) { VOXEL_PROFILE_SCOPE(); ERR_FAIL_COND_V_MSG(_full_load_mode == false, nullptr, "This function can only be used in full load mode"); const uint32_t volume_id = _volume_id; @@ -526,7 +525,7 @@ std::shared_ptr VoxelLodTerrain::preload_boxes_a PRINT_VERBOSE(String("Preloading boxes with {1} tasks").format(varray(SIZE_T_TO_VARIANT(todo.size())))); - std::shared_ptr tracker = nullptr; + std::shared_ptr tracker = nullptr; // TODO `next_tasks` is executed in parallel. But since they can be edits, may we do them in sequence? @@ -538,8 +537,8 @@ std::shared_ptr VoxelLodTerrain::preload_boxes_a // it would destroy `next_tasks`. // This may first run the generation tasks, and then the edits - tracker = gd_make_shared( - todo.size(), next_tasks, [](Span p_next_tasks) { + tracker = + gd_make_shared(todo.size(), next_tasks, [](Span p_next_tasks) { VoxelServer::get_singleton()->push_async_tasks(p_next_tasks); }); @@ -722,8 +721,7 @@ void VoxelLodTerrain::post_edit_area(Box3i p_box) { } } -void VoxelLodTerrain::push_async_edit( - zylann::IThreadedTask *task, Box3i box, std::shared_ptr tracker) { +void VoxelLodTerrain::push_async_edit(IThreadedTask *task, Box3i box, std::shared_ptr tracker) { CRASH_COND(task == nullptr); CRASH_COND(tracker == nullptr); AsyncEdit e; @@ -1326,7 +1324,7 @@ void VoxelLodTerrain::_process(float delta) { // It has to happen first because blocks can be unloaded afterwards. flush_pending_lod_edits(); - zylann::ProfilingClock profiling_clock; + ProfilingClock profiling_clock; static thread_local std::vector data_blocks_to_save; @@ -2079,8 +2077,8 @@ void VoxelLodTerrain::process_async_edits() { // Schedule all next edits when the previous ones are done std::vector boxes_to_preload; - std::vector tasks_to_schedule; - std::shared_ptr last_tracker = nullptr; + std::vector tasks_to_schedule; + std::shared_ptr last_tracker = nullptr; for (unsigned int edit_index = 0; edit_index < _pending_async_edits.size(); ++edit_index) { AsyncEdit &edit = _pending_async_edits[edit_index]; @@ -3084,3 +3082,5 @@ void VoxelLodTerrain::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "full_load_mode_enabled"), "set_full_load_mode_enabled", "is_full_load_mode_enabled"); } + +} // namespace zylann::voxel diff --git a/terrain/voxel_lod_terrain.h b/terrain/voxel_lod_terrain.h index 1294ebfe..8a011e9c 100644 --- a/terrain/voxel_lod_terrain.h +++ b/terrain/voxel_lod_terrain.h @@ -13,6 +13,8 @@ #include "../editor/voxel_debug.h" #endif +namespace zylann::voxel { + class VoxelTool; class VoxelStream; class VoxelInstancer; @@ -86,7 +88,7 @@ public: bool is_area_editable(Box3i p_box) const; VoxelSingleValue get_voxel(Vector3i pos, unsigned int channel, VoxelSingleValue defval); bool try_set_voxel_without_update(Vector3i pos, unsigned int channel, uint64_t value); - void copy(Vector3i p_origin_voxels, zylann::voxel::VoxelBufferInternal &dst_buffer, uint8_t channels_mask); + void copy(Vector3i p_origin_voxels, VoxelBufferInternal &dst_buffer, uint8_t channels_mask); template void write_box(const Box3i &p_voxel_box, unsigned int channel, F action) { @@ -96,11 +98,11 @@ public: return; } Ref generator = _generator; - zylann::voxel::VoxelDataLodMap::Lod &data_lod0 = _data->lods[0]; + VoxelDataLodMap::Lod &data_lod0 = _data->lods[0]; { RWLockWrite wlock(data_lod0.map_lock); data_lod0.map.write_box( - voxel_box, channel, action, [&generator](zylann::voxel::VoxelBufferInternal &voxels, Vector3i pos) { + voxel_box, channel, action, [&generator](VoxelBufferInternal &voxels, Vector3i pos) { if (generator.is_valid()) { VoxelBlockRequest r{ voxels, pos, 0 }; generator->generate_block(r); @@ -118,11 +120,11 @@ public: return; } Ref generator = _generator; - zylann::voxel::VoxelDataLodMap::Lod &data_lod0 = _data->lods[0]; + VoxelDataLodMap::Lod &data_lod0 = _data->lods[0]; { RWLockWrite wlock(data_lod0.map_lock); - data_lod0.map.write_box_2(voxel_box, channel1, channel2, action, - [&generator](zylann::voxel::VoxelBufferInternal &voxels, Vector3i pos) { + data_lod0.map.write_box_2( + voxel_box, channel1, channel2, action, [&generator](VoxelBufferInternal &voxels, Vector3i pos) { if (generator.is_valid()) { VoxelBlockRequest r{ voxels, pos, 0 }; generator->generate_block(r); @@ -136,8 +138,7 @@ public: void post_edit_area(Box3i p_box); // TODO This still sucks atm cuz the edit will still run on the main thread - void push_async_edit( - zylann::IThreadedTask *task, Box3i box, std::shared_ptr tracker); + void push_async_edit(IThreadedTask *task, Box3i box, std::shared_ptr tracker); void process_async_edits(); void abort_async_edits(); @@ -187,7 +188,7 @@ public: void remesh_all_blocks() override; struct BlockToSave { - std::shared_ptr voxels; + std::shared_ptr voxels; Vector3i position; uint8_t lod; }; @@ -224,7 +225,7 @@ public: Array get_mesh_block_surface(Vector3i block_pos, int lod_index) const; Vector get_meshed_block_positions_at_lod(int lod_index) const; - std::shared_ptr get_storage() const { + std::shared_ptr get_storage() const { return _data; } @@ -247,8 +248,8 @@ private: //void process_block_loading_responses(); void send_mesh_requests(); - void apply_mesh_update(const zylann::voxel::VoxelServer::BlockMeshOutput &ob); - void apply_data_block_response(zylann::voxel::VoxelServer::BlockDataOutput &ob); + void apply_mesh_update(const VoxelServer::BlockMeshOutput &ob); + void apply_data_block_response(VoxelServer::BlockDataOutput &ob); void unload_data_block_no_lock(Vector3i block_pos, uint8_t lod_index, std::vector &blocks_to_save); void unload_mesh_block(Vector3i block_pos, uint8_t lod_index); @@ -267,15 +268,15 @@ private: Vector3 get_local_viewer_pos() const; void try_schedule_loading_with_neighbors_no_lock( const Vector3i &p_data_block_pos, uint8_t lod_index, std::vector &blocks_to_load); - bool is_block_surrounded(const Vector3i &p_bpos, int lod_index, const zylann::voxel::VoxelDataMap &map) const; + bool is_block_surrounded(const Vector3i &p_bpos, int lod_index, const VoxelDataMap &map) const; bool check_block_loaded_and_meshed( const Vector3i &p_mesh_block_pos, uint8_t lod_index, std::vector &blocks_to_load); - bool check_block_mesh_updated(zylann::voxel::VoxelMeshBlock *block, std::vector &blocks_to_load); + bool check_block_mesh_updated(VoxelMeshBlock *block, std::vector &blocks_to_load); void _set_lod_count(int p_lod_count); - void set_mesh_block_active(zylann::voxel::VoxelMeshBlock &block, bool active); + void set_mesh_block_active(VoxelMeshBlock &block, bool active); - std::shared_ptr preload_boxes_async( - Span voxel_boxes, Span next_tasks); + std::shared_ptr preload_boxes_async( + Span voxel_boxes, Span next_tasks); void _on_stream_params_changed(); @@ -286,7 +287,7 @@ private: void process_deferred_collision_updates(uint32_t timeout_msec); void process_fading_blocks(float delta); - void add_transition_update(zylann::voxel::VoxelMeshBlock *block); + void add_transition_update(VoxelMeshBlock *block); void add_transition_updates_around(Vector3i block_pos, int lod_index); void process_transition_updates(); uint8_t get_transition_mask(Vector3i block_pos, int lod_index) const; @@ -301,7 +302,7 @@ private: Dictionary _b_get_statistics() const; struct OctreeItem { - zylann::voxel::LodOctree octree; + LodOctree octree; }; #ifdef TOOLS_ENABLED @@ -332,7 +333,7 @@ private: // TODO Get rid of this kind of member, use threadlocal pooling instead // Only populated and then cleared inside _process, so lifetime of pointers should be valid - std::vector _blocks_pending_transition_update; + std::vector _blocks_pending_transition_update; Ref _material; std::vector> _shader_material_pool; @@ -341,27 +342,27 @@ private: unsigned int _collision_lod_count = 0; unsigned int _collision_layer = 1; unsigned int _collision_mask = 1; - float _collision_margin = zylann::voxel::constants::DEFAULT_COLLISION_MARGIN; + float _collision_margin = constants::DEFAULT_COLLISION_MARGIN; int _collision_update_delay = 0; VoxelInstancer *_instancer = nullptr; struct AsyncEdit { - zylann::IThreadedTask *task; + IThreadedTask *task; Box3i box; - std::shared_ptr task_tracker; + std::shared_ptr task_tracker; }; std::vector _pending_async_edits; struct RunningAsyncEdit { - std::shared_ptr tracker; + std::shared_ptr tracker; Box3i box; }; std::vector _running_async_edits; // Data stored with a shared pointer so it can be sent to asynchronous tasks - std::shared_ptr _data; + std::shared_ptr _data; // Each LOD works in a set of coordinates spanning 2x more voxels the higher their index is struct Lod { @@ -373,10 +374,10 @@ private: Vector3i last_viewer_data_block_pos; int last_view_distance_data_blocks = 0; - zylann::voxel::VoxelMeshMap mesh_map; + VoxelMeshMap mesh_map; std::vector blocks_pending_update; std::vector deferred_collision_updates; - Map fading_blocks; + Map fading_blocks; Vector3i last_viewer_mesh_block_pos; int last_view_distance_mesh_blocks = 0; @@ -385,7 +386,7 @@ private: } }; - zylann::FixedArray _lods; + FixedArray _lods; unsigned int _lod_count = 0; // Distance between a viewer and the end of LOD0 float _lod_distance = 0.f; @@ -401,12 +402,14 @@ private: bool _show_octree_node_gizmos = false; bool _show_edited_blocks = false; unsigned int _edited_blocks_gizmos_lod_index = 0; - zylann::DebugRenderer _debug_renderer; + DebugRenderer _debug_renderer; #endif Stats _stats; }; -VARIANT_ENUM_CAST(VoxelLodTerrain::ProcessCallback) +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelLodTerrain::ProcessCallback) #endif // VOXEL_LOD_TERRAIN_HPP diff --git a/terrain/voxel_node.cpp b/terrain/voxel_node.cpp index 8dc3f65b..3b325c95 100644 --- a/terrain/voxel_node.cpp +++ b/terrain/voxel_node.cpp @@ -3,6 +3,8 @@ #include "../meshers/voxel_mesher.h" #include "../streams/voxel_stream.h" +namespace zylann::voxel { + void VoxelNode::set_mesher(Ref mesher) { // Implemented in subclasses } @@ -156,3 +158,5 @@ void VoxelNode::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "gi_mode", PROPERTY_HINT_ENUM, "Disabled,Baked,Dynamic"), "set_gi_mode", "get_gi_mode"); } + +} // namespace zylann::voxel diff --git a/terrain/voxel_node.h b/terrain/voxel_node.h index 96d9bfce..83f1da75 100644 --- a/terrain/voxel_node.h +++ b/terrain/voxel_node.h @@ -7,6 +7,8 @@ #include +namespace zylann::voxel { + // Base class for voxel volumes class VoxelNode : public Node3D { GDCLASS(VoxelNode, Node3D) @@ -67,6 +69,8 @@ private: GIMode _gi_mode = GI_MODE_DISABLED; }; -VARIANT_ENUM_CAST(VoxelNode::GIMode); +} // namespace zylann::voxel + +VARIANT_ENUM_CAST(zylann::voxel::VoxelNode::GIMode); #endif // VOXEL_NODE_H diff --git a/terrain/voxel_terrain.cpp b/terrain/voxel_terrain.cpp index 75a1e46b..85d04931 100644 --- a/terrain/voxel_terrain.cpp +++ b/terrain/voxel_terrain.cpp @@ -14,8 +14,7 @@ #include #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelTerrain::VoxelTerrain() { // Note: don't do anything heavy in the constructor. @@ -28,7 +27,7 @@ VoxelTerrain::VoxelTerrain() { // Infinite by default _bounds_in_voxels = Box3i::from_center_extents(Vector3i(), Vector3iUtil::create(constants::MAX_VOLUME_EXTENT)); - struct ApplyMeshUpdateTask : public zylann::ITimeSpreadTask { + struct ApplyMeshUpdateTask : public ITimeSpreadTask { void run() override { if (!VoxelServer::get_singleton()->is_volume_valid(volume_id)) { // The node can have been destroyed while this task was still pending @@ -832,7 +831,7 @@ void VoxelTerrain::_process() { } void VoxelTerrain::process_viewers() { - zylann::ProfilingClock profiling_clock; + ProfilingClock profiling_clock; // Ordered by ascending index in paired viewers list std::vector unpaired_viewer_indexes; @@ -1121,7 +1120,7 @@ void VoxelTerrain::apply_data_block_response(VoxelServer::BlockDataOutput &ob) { } void VoxelTerrain::process_meshing() { - zylann::ProfilingClock profiling_clock; + ProfilingClock profiling_clock; _stats.dropped_block_meshs = 0; @@ -1423,3 +1422,5 @@ void VoxelTerrain::_bind_methods() { ADD_SIGNAL( MethodInfo(VoxelStringNames::get_singleton()->block_unloaded, PropertyInfo(Variant::VECTOR3, "position"))); } + +} // namespace zylann::voxel diff --git a/terrain/voxel_terrain.h b/terrain/voxel_terrain.h index f0328893..35d124e9 100644 --- a/terrain/voxel_terrain.h +++ b/terrain/voxel_terrain.h @@ -8,6 +8,8 @@ #include +namespace zylann::voxel { + class VoxelTool; // Infinite paged terrain made of voxel blocks all with the same level of detail. @@ -69,10 +71,10 @@ public: void set_material(unsigned int id, Ref material); Ref get_material(unsigned int id) const; - zylann::voxel::VoxelDataMap &get_storage() { + VoxelDataMap &get_storage() { return _data_map; } - const zylann::voxel::VoxelDataMap &get_storage() const { + const VoxelDataMap &get_storage() const { return _data_map; } @@ -103,7 +105,7 @@ public: const Stats &get_stats() const; struct BlockToSave { - std::shared_ptr voxels; + std::shared_ptr voxels; Vector3i position; }; @@ -121,8 +123,8 @@ private: void process_viewers(); //void process_received_data_blocks(); void process_meshing(); - void apply_mesh_update(const zylann::voxel::VoxelServer::BlockMeshOutput &ob); - void apply_data_block_response(zylann::voxel::VoxelServer::BlockDataOutput &ob); + void apply_mesh_update(const VoxelServer::BlockMeshOutput &ob); + void apply_data_block_response(VoxelServer::BlockDataOutput &ob); void _on_stream_params_changed(); void _set_block_size_po2(int p_block_size_po2); @@ -140,15 +142,15 @@ private: void unload_data_block(Vector3i bpos); void unload_mesh_block(Vector3i bpos); //void make_data_block_dirty(Vector3i bpos); - void try_schedule_mesh_update(zylann::voxel::VoxelMeshBlock *block); + void try_schedule_mesh_update(VoxelMeshBlock *block); void try_schedule_mesh_update_from_data(const Box3i &box_in_voxels); void save_all_modified_blocks(bool with_copy); void get_viewer_pos_and_direction(Vector3 &out_pos, Vector3 &out_direction) const; void send_block_data_requests(); - void emit_data_block_loaded(const zylann::voxel::VoxelDataBlock *block); - void emit_data_block_unloaded(const zylann::voxel::VoxelDataBlock *block); + void emit_data_block_loaded(const VoxelDataBlock *block); + void emit_data_block_unloaded(const VoxelDataBlock *block); bool try_get_paired_viewer_index(uint32_t id, size_t &out_i) const; @@ -183,9 +185,9 @@ private: std::vector _paired_viewers; // Voxel storage - zylann::voxel::VoxelDataMap _data_map; + VoxelDataMap _data_map; // Mesh storage - zylann::voxel::VoxelMeshMap _mesh_map; + VoxelMeshMap _mesh_map; // Area within which voxels can exist. // Note, these bounds might not be exactly represented. This volume is chunk-based, so the result will be @@ -213,7 +215,7 @@ private: bool _generate_collisions = true; unsigned int _collision_layer = 1; unsigned int _collision_mask = 1; - float _collision_margin = zylann::voxel::constants::DEFAULT_COLLISION_MARGIN; + float _collision_margin = constants::DEFAULT_COLLISION_MARGIN; bool _run_stream_in_editor = true; //bool _stream_enabled = false; @@ -222,4 +224,6 @@ private: Stats _stats; }; +} // namespace zylann::voxel + #endif // VOXEL_TERRAIN_H diff --git a/terrain/voxel_viewer.cpp b/terrain/voxel_viewer.cpp index f1ebcb30..3cb278e9 100644 --- a/terrain/voxel_viewer.cpp +++ b/terrain/voxel_viewer.cpp @@ -2,8 +2,7 @@ #include "../server/voxel_server.h" #include -using namespace zylann; -using namespace voxel; +namespace zylann::voxel { VoxelViewer::VoxelViewer() { set_notify_transform(!Engine::get_singleton()->is_editor_hint()); @@ -92,3 +91,5 @@ void VoxelViewer::_bind_methods() { ADD_PROPERTY( PropertyInfo(Variant::BOOL, "requires_collisions"), "set_requires_collisions", "is_requiring_collisions"); } + +} // namespace zylann::voxel diff --git a/terrain/voxel_viewer.h b/terrain/voxel_viewer.h index a87efe8b..20ef8185 100644 --- a/terrain/voxel_viewer.h +++ b/terrain/voxel_viewer.h @@ -3,6 +3,8 @@ #include +namespace zylann::voxel { + // Triggers loading of voxel nodes around its position. Voxels will update in priority closer to viewers. // Usually added as child of the player's camera. class VoxelViewer : public Node3D { @@ -36,4 +38,6 @@ private: bool _requires_collisions = true; }; +} // namespace zylann::voxel + #endif // VOXEL_VIEWER_H diff --git a/util/noise/fast_noise_2.cpp b/util/noise/fast_noise_2.cpp index 44720695..eecb09fd 100644 --- a/util/noise/fast_noise_2.cpp +++ b/util/noise/fast_noise_2.cpp @@ -2,7 +2,7 @@ #include "../math/funcs.h" #include -using namespace zylann; +namespace zylann { FastNoise2::FastNoise2() { // Setup default @@ -467,14 +467,14 @@ void FastNoise2::update_generator() { _generator = generator_node; } -zylann::math::Interval FastNoise2::get_estimated_output_range() const { +math::Interval FastNoise2::get_estimated_output_range() const { // TODO Optimize: better range analysis on FastNoise2 // Most noises should have known bounds like FastNoiseLite, but the node-graph nature of this library // can make it difficult to calculate. Would be nice if the library could provide that out of the box. if (is_remap_enabled()) { - return zylann::math::Interval(get_remap_output_min(), get_remap_output_max()); + return math::Interval(get_remap_output_min(), get_remap_output_max()); } else { - return zylann::math::Interval(-1.f, 1.f); + return math::Interval(-1.f, 1.f); } } @@ -671,3 +671,5 @@ void FastNoise2::_bind_methods() { BIND_ENUM_CONSTANT(SIMD_AVX512); BIND_ENUM_CONSTANT(SIMD_NEON); } + +} // namespace zylann diff --git a/util/noise/fast_noise_2.h b/util/noise/fast_noise_2.h index 6402eb97..8e77f82c 100644 --- a/util/noise/fast_noise_2.h +++ b/util/noise/fast_noise_2.h @@ -8,6 +8,8 @@ class Image; +namespace zylann { + // Can't call it FastNoise? because FastNoise is a namespace already class FastNoise2 : public Resource { GDCLASS(FastNoise2, Resource) @@ -169,7 +171,7 @@ public: void generate_image(Ref image, bool tileable) const; - zylann::math::Interval get_estimated_output_range() const; + math::Interval get_estimated_output_range() const; private: // Non-static method for scripts because Godot4 does not support binding static methods (it's only implemented for @@ -208,10 +210,12 @@ private: FastNoise::SmartNode<> _generator; }; -VARIANT_ENUM_CAST(FastNoise2::SIMDLevel); -VARIANT_ENUM_CAST(FastNoise2::NoiseType); -VARIANT_ENUM_CAST(FastNoise2::FractalType); -VARIANT_ENUM_CAST(FastNoise2::CellularDistanceFunction); -VARIANT_ENUM_CAST(FastNoise2::CellularReturnType); +} // namespace zylann + +VARIANT_ENUM_CAST(zylann::FastNoise2::SIMDLevel); +VARIANT_ENUM_CAST(zylann::FastNoise2::NoiseType); +VARIANT_ENUM_CAST(zylann::FastNoise2::FractalType); +VARIANT_ENUM_CAST(zylann::FastNoise2::CellularDistanceFunction); +VARIANT_ENUM_CAST(zylann::FastNoise2::CellularReturnType); #endif // VOXEL_FAST_NOISE_2_H diff --git a/util/noise/fast_noise_lite.cpp b/util/noise/fast_noise_lite.cpp index 5a140c5c..89f0417e 100644 --- a/util/noise/fast_noise_lite.cpp +++ b/util/noise/fast_noise_lite.cpp @@ -2,6 +2,8 @@ #include "../math/funcs.h" #include +namespace zylann { + FastNoiseLite::FastNoiseLite() { _fn.SetNoiseType(static_cast<_FastNoise::NoiseType>(_noise_type)); _fn.SetSeed(_seed); @@ -196,7 +198,7 @@ FastNoiseLite::CellularReturnType FastNoiseLite::get_cellular_return_type() cons } void FastNoiseLite::set_cellular_jitter(float jitter) { - jitter = zylann::math::clamp(jitter, 0.f, 1.f); + jitter = math::clamp(jitter, 0.f, 1.f); if (_cellular_jitter == jitter) { return; } @@ -358,3 +360,5 @@ void FastNoiseLite::_bind_methods() { BIND_ENUM_CONSTANT(CELLULAR_RETURN_DISTANCE_2_MUL); BIND_ENUM_CONSTANT(CELLULAR_RETURN_DISTANCE_2_DIV); } + +} // namespace zylann diff --git a/util/noise/fast_noise_lite.h b/util/noise/fast_noise_lite.h index a549aa6b..b6efe147 100644 --- a/util/noise/fast_noise_lite.h +++ b/util/noise/fast_noise_lite.h @@ -5,6 +5,8 @@ #include "fast_noise_lite_gradient.h" +namespace zylann { + class FastNoiseLite : public Resource { GDCLASS(FastNoiseLite, Resource) @@ -162,10 +164,12 @@ private: Ref _warp_noise; }; -VARIANT_ENUM_CAST(FastNoiseLite::NoiseType); -VARIANT_ENUM_CAST(FastNoiseLite::FractalType); -VARIANT_ENUM_CAST(FastNoiseLite::RotationType3D); -VARIANT_ENUM_CAST(FastNoiseLite::CellularDistanceFunction); -VARIANT_ENUM_CAST(FastNoiseLite::CellularReturnType); +} // namespace zylann + +VARIANT_ENUM_CAST(zylann::FastNoiseLite::NoiseType); +VARIANT_ENUM_CAST(zylann::FastNoiseLite::FractalType); +VARIANT_ENUM_CAST(zylann::FastNoiseLite::RotationType3D); +VARIANT_ENUM_CAST(zylann::FastNoiseLite::CellularDistanceFunction); +VARIANT_ENUM_CAST(zylann::FastNoiseLite::CellularReturnType); #endif // FAST_NOISE_LITE_H diff --git a/util/noise/fast_noise_lite_gradient.cpp b/util/noise/fast_noise_lite_gradient.cpp index 0a3439d2..09e79a1f 100644 --- a/util/noise/fast_noise_lite_gradient.cpp +++ b/util/noise/fast_noise_lite_gradient.cpp @@ -1,5 +1,7 @@ #include "fast_noise_lite_gradient.h" +namespace zylann { + static fast_noise_lite::FastNoiseLite::FractalType to_fnl_fractal_type(FastNoiseLiteGradient::FractalType type) { switch (type) { case FastNoiseLiteGradient::FRACTAL_NONE: @@ -226,3 +228,5 @@ void FastNoiseLiteGradient::_bind_methods() { BIND_ENUM_CONSTANT(ROTATION_3D_IMPROVE_XY_PLANES); BIND_ENUM_CONSTANT(ROTATION_3D_IMPROVE_XZ_PLANES); } + +} // namespace zylann diff --git a/util/noise/fast_noise_lite_gradient.h b/util/noise/fast_noise_lite_gradient.h index 13408e33..7ba5e0b7 100644 --- a/util/noise/fast_noise_lite_gradient.h +++ b/util/noise/fast_noise_lite_gradient.h @@ -5,6 +5,8 @@ #include "../../thirdparty/fast_noise/FastNoiseLite.h" +namespace zylann { + // Domain warp is a transformation of coordinates before sampling the actual noise. // It can be done with another instance of noise, however it needs a sample for each coordinate, // so FastNoiseLite provides specialized versions of this using gradients. @@ -117,8 +119,10 @@ private: RotationType3D _rotation_type_3d = ROTATION_3D_NONE; }; -VARIANT_ENUM_CAST(FastNoiseLiteGradient::NoiseType); -VARIANT_ENUM_CAST(FastNoiseLiteGradient::FractalType); -VARIANT_ENUM_CAST(FastNoiseLiteGradient::RotationType3D); +} // namespace zylann + +VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::NoiseType); +VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::FractalType); +VARIANT_ENUM_CAST(zylann::FastNoiseLiteGradient::RotationType3D); #endif // FAST_NOISE_LITE_GRADIENT_H