From a3d32cf1c4b7910fc32f853761537d762ae6bed3 Mon Sep 17 00:00:00 2001 From: Cory Petkovsek <632766+TokisanGames@users.noreply.github.com> Date: Fri, 17 Nov 2023 01:05:34 +0700 Subject: [PATCH] Fix GDCLASS public override --- CONTRIBUTING.md | 3 +- src/generated_tex.cpp | 2 +- src/generated_tex.h | 5 +- src/geoclipmap.h | 4 +- src/logger.h | 2 +- src/terrain_3d.cpp | 8 +-- src/terrain_3d.h | 10 ++- src/terrain_3d_editor.h | 10 ++- src/terrain_3d_material.cpp | 4 +- src/terrain_3d_material.h | 5 +- src/terrain_3d_storage.cpp | 116 ++++++++++++++++---------------- src/terrain_3d_storage.h | 11 ++- src/terrain_3d_surface.h | 9 ++- src/terrain_3d_texture.h | 9 ++- src/terrain_3d_texture_list.cpp | 52 +++++++------- src/terrain_3d_texture_list.h | 7 +- src/util.h | 2 +- 17 files changed, 141 insertions(+), 118 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9aae2f00b..f4040542f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -46,7 +46,8 @@ Braces: Private & Public: * Private variables/functions prefaced with `_` -* Private/public/protected explicit and grouped together in that order, in header and cpp files +* One initial public section for constants +* Private/public/protected for members and functions in that order, in header and cpp files * Functions in h and cpp files in same order Other formatting: diff --git a/src/generated_tex.cpp b/src/generated_tex.cpp index 7ff47d4aa..c88abcebd 100644 --- a/src/generated_tex.cpp +++ b/src/generated_tex.cpp @@ -11,7 +11,7 @@ void GeneratedTex::create(const TypedArray &p_layers) { if (!p_layers.is_empty()) { - if (Terrain3D::_debug_level >= DEBUG) { + if (Terrain3D::debug_level >= DEBUG) { LOG(DEBUG, "RenderingServer creating Texture2DArray, layers size: ", p_layers.size()); for (int i = 0; i < p_layers.size(); i++) { Ref img = p_layers[i]; diff --git a/src/generated_tex.h b/src/generated_tex.h index a466ad69e..7db34506d 100644 --- a/src/generated_tex.h +++ b/src/generated_tex.h @@ -8,8 +8,11 @@ using namespace godot; class GeneratedTex { -private: +public: + // Constants static inline const char *__class__ = "Terrain3DGeneratedTex"; + +private: RID _rid = RID(); Ref _image; bool _dirty = false; diff --git a/src/geoclipmap.h b/src/geoclipmap.h index 3ec8d8e0a..df4855fe2 100644 --- a/src/geoclipmap.h +++ b/src/geoclipmap.h @@ -8,9 +8,11 @@ using namespace godot; class GeoClipMap { -private: +public: + // Constants static inline const char *__class__ = "Terrain3DGeoClipMap"; +private: static inline int _patch_2d(int x, int y, int res); static RID _create_mesh(PackedVector3Array p_vertices, PackedInt32Array p_indices, AABB p_aabb); diff --git a/src/logger.h b/src/logger.h index c48dac0f2..d3b80c635 100644 --- a/src/logger.h +++ b/src/logger.h @@ -30,7 +30,7 @@ UtilityFunctions::push_error(__class__, "::", __func__, ": ", __VA_ARGS__); \ else if (level == WARN) \ UtilityFunctions::push_warning(__class__, "::", __func__, ": ", __VA_ARGS__); \ - else if (Terrain3D::_debug_level >= level) \ + else if (Terrain3D::debug_level >= level) \ UtilityFunctions::print(__class__, "::", __func__, ": ", __VA_ARGS__); #endif // LOGGER_CLASS_H \ No newline at end of file diff --git a/src/terrain_3d.cpp b/src/terrain_3d.cpp index 8c8dfdb23..77d69696c 100644 --- a/src/terrain_3d.cpp +++ b/src/terrain_3d.cpp @@ -23,7 +23,7 @@ /////////////////////////// // Initialize static member variable -int Terrain3D::_debug_level{ ERROR }; +int Terrain3D::debug_level{ ERROR }; void Terrain3D::_initialize() { LOG(INFO, "Checking material, storage, texture_list, signal, and mesh initialization"); @@ -67,8 +67,8 @@ void Terrain3D::_initialize() { // Initialize the system if (!_initialized && _is_inside_world && is_inside_tree()) { _material->initialize(_storage->get_region_size()); - _storage->_update_regions(true); // generate map arrays - _texture_list->_update_list(); // generate texture arrays + _storage->update_regions(true); // generate map arrays + _texture_list->update_list(); // generate texture arrays _build(_clipmap_levels, _clipmap_size); _build_collision(); _initialized = true; @@ -480,7 +480,7 @@ Terrain3D::~Terrain3D() { void Terrain3D::set_debug_level(int p_level) { LOG(INFO, "Setting debug level: ", p_level); - _debug_level = CLAMP(p_level, 0, DEBUG_MAX); + debug_level = CLAMP(p_level, 0, DEBUG_MAX); } void Terrain3D::set_clipmap_levels(int p_count) { diff --git a/src/terrain_3d.h b/src/terrain_3d.h index 830af53dc..3b387a574 100644 --- a/src/terrain_3d.h +++ b/src/terrain_3d.h @@ -20,17 +20,19 @@ using namespace godot; class Terrain3D : public Node3D { -private: GDCLASS(Terrain3D, Node3D); + +public: + // Constants static inline const char *__class__ = "Terrain3D"; +private: // Terrain state String _version = "0.8.4-dev"; bool _is_inside_world = false; bool _initialized = false; // Terrain settings - static int _debug_level; int _clipmap_size = 48; int _clipmap_levels = 7; @@ -86,13 +88,15 @@ class Terrain3D : public Node3D { void _update_instances(); public: + static int debug_level; + Terrain3D(); ~Terrain3D(); // Terrain settings String get_version() const { return _version; } void set_debug_level(int p_level); - int get_debug_level() const { return _debug_level; } + int get_debug_level() const { return debug_level; } void set_clipmap_levels(int p_count); int get_clipmap_levels() const { return _clipmap_levels; } void set_clipmap_size(int p_size); diff --git a/src/terrain_3d_editor.h b/src/terrain_3d_editor.h index 58f84b579..c2536d6c2 100644 --- a/src/terrain_3d_editor.h +++ b/src/terrain_3d_editor.h @@ -11,11 +11,11 @@ using namespace godot; class Terrain3DEditor : public Object { -private: GDCLASS(Terrain3DEditor, Object); - static inline const char *__class__ = "Terrain3DEditor"; - // Constants & Definitions +public: + // Constants + static inline const char *__class__ = "Terrain3DEditor"; enum Operation { ADD, @@ -94,12 +94,11 @@ class Terrain3DEditor : public Object { real_t get_jitter() const { return _jitter; } }; +private: // Object references - Terrain3D *_terrain = nullptr; // Painter settings & variables - Tool _tool = REGION; Operation _operation = ADD; Brush _brush; @@ -109,7 +108,6 @@ class Terrain3DEditor : public Object { bool _modified = false; Array _undo_set; // 0-2: map 0,1,2, 3: Region offsets, 4: height range -private: void _operate_region(Vector3 p_global_position); void _operate_map(Vector3 p_global_position, real_t p_camera_direction); bool _is_in_bounds(Vector2i p_position, Vector2i p_max_position); diff --git a/src/terrain_3d_material.cpp b/src/terrain_3d_material.cpp index ecfd59288..cc8c16c84 100644 --- a/src/terrain_3d_material.cpp +++ b/src/terrain_3d_material.cpp @@ -28,7 +28,7 @@ void Terrain3DMaterial::_preload_shaders() { #include "shaders/main.glsl" ); - if (Terrain3D::_debug_level >= DEBUG) { + if (Terrain3D::debug_level >= DEBUG) { Array keys = _shader_code.keys(); for (int i = 0; i < keys.size(); i++) { LOG(DEBUG, "Loaded shader insert: ", keys[i]); @@ -186,7 +186,7 @@ void Terrain3DMaterial::_update_regions(const Array &p_args) { RS->material_set_param(_material, "_region_map", _region_map); RS->material_set_param(_material, "_region_map_size", Terrain3DStorage::REGION_MAP_SIZE); RS->material_set_param(_material, "_region_uv_limit", Terrain3DStorage::REGION_MAP_SIZE / 2); - if (Terrain3D::_debug_level >= DEBUG) { + if (Terrain3D::debug_level >= DEBUG) { LOG(DEBUG, "Region map"); for (int i = 0; i < _region_map.size(); i++) { if (_region_map[i]) { diff --git a/src/terrain_3d_material.h b/src/terrain_3d_material.h index 1e7f25b4a..c0197534e 100644 --- a/src/terrain_3d_material.h +++ b/src/terrain_3d_material.h @@ -10,10 +10,13 @@ using namespace godot; class Terrain3DMaterial : public Resource { -private: GDCLASS(Terrain3DMaterial, Resource); + +public: + // Constants static inline const char *__class__ = "Terrain3DMaterial"; +private: bool _initialized = false; RID _material; RID _shader; diff --git a/src/terrain_3d_storage.cpp b/src/terrain_3d_storage.cpp index 98e36ad22..82f21cf93 100644 --- a/src/terrain_3d_storage.cpp +++ b/src/terrain_3d_storage.cpp @@ -22,58 +22,6 @@ void Terrain3DStorage::_clear() { _generated_color_maps.clear(); } -void Terrain3DStorage::_update_regions(bool force_emit) { - if (_generated_height_maps.is_dirty()) { - LOG(DEBUG_CONT, "Regenerating height layered texture from ", _height_maps.size(), " maps"); - _generated_height_maps.create(_height_maps); - force_emit = true; - _modified = true; - emit_signal("height_maps_changed"); - } - - if (_generated_control_maps.is_dirty()) { - LOG(DEBUG_CONT, "Regenerating control layered texture from ", _control_maps.size(), " maps"); - _generated_control_maps.create(_control_maps); - force_emit = true; - _modified = true; - } - - if (_generated_color_maps.is_dirty()) { - LOG(DEBUG_CONT, "Regenerating color layered texture from ", _color_maps.size(), " maps"); - _generated_color_maps.create(_color_maps); - force_emit = true; - _modified = true; - } - - if (_region_map_dirty) { - LOG(DEBUG_CONT, "Regenerating ", REGION_MAP_VSIZE, " region map array"); - _region_map.clear(); - _region_map.resize(REGION_MAP_SIZE * REGION_MAP_SIZE); - _region_map_dirty = false; - for (int i = 0; i < _region_offsets.size(); i++) { - Vector2i ofs = _region_offsets[i]; - Vector2i pos = Vector2i(ofs + (REGION_MAP_VSIZE / 2)); - if (pos.x >= REGION_MAP_SIZE || pos.y >= REGION_MAP_SIZE || pos.x < 0 || pos.y < 0) { - continue; - } - _region_map[pos.y * REGION_MAP_SIZE + pos.x] = i + 1; // 0 = no region - } - force_emit = true; - _modified = true; - } - - // Don't emit if no changes and not requested - if (force_emit) { - Array region_signal_args; - region_signal_args.push_back(_generated_height_maps.get_rid()); - region_signal_args.push_back(_generated_control_maps.get_rid()); - region_signal_args.push_back(_generated_color_maps.get_rid()); - region_signal_args.push_back(_region_map); - region_signal_args.push_back(_region_offsets); - emit_signal("regions_changed", region_signal_args); - } -} - /////////////////////////// // Public Functions /////////////////////////// @@ -155,7 +103,7 @@ void Terrain3DStorage::set_region_offsets(const TypedArray &p_offsets) LOG(INFO, "Setting region offsets with array sized: ", p_offsets.size()); _region_offsets = p_offsets; _region_map_dirty = true; - _update_regions(); + update_regions(); } /** Returns a region offset given a location */ @@ -231,11 +179,11 @@ Error Terrain3DStorage::add_region(Vector3 p_global_position, const TypedArray= REGION_MAP_SIZE || pos.y >= REGION_MAP_SIZE || pos.x < 0 || pos.y < 0) { + continue; + } + _region_map[pos.y * REGION_MAP_SIZE + pos.x] = i + 1; // 0 = no region + } + force_emit = true; + _modified = true; + } + + // Don't emit if no changes and not requested + if (force_emit) { + Array region_signal_args; + region_signal_args.push_back(_generated_height_maps.get_rid()); + region_signal_args.push_back(_generated_control_maps.get_rid()); + region_signal_args.push_back(_generated_color_maps.get_rid()); + region_signal_args.push_back(_region_map); + region_signal_args.push_back(_region_offsets); + emit_signal("regions_changed", region_signal_args); } } @@ -615,7 +615,7 @@ void Terrain3DStorage::force_update_maps(MapType p_map_type) { _generated_color_maps.clear(); break; } - _update_regions(); + update_regions(); } void Terrain3DStorage::save() { diff --git a/src/terrain_3d_storage.h b/src/terrain_3d_storage.h index cf9f33a4a..9b5c4b698 100644 --- a/src/terrain_3d_storage.h +++ b/src/terrain_3d_storage.h @@ -14,11 +14,11 @@ using namespace godot; class Terrain3DStorage : public Resource { -private: GDCLASS(Terrain3DStorage, Resource); - static inline const char *__class__ = "Terrain3DStorage"; - // Constants & Definitions +public: + // Constants + static inline const char *__class__ = "Terrain3DStorage"; static inline const real_t CURRENT_VERSION = 0.842; static inline const int REGION_MAP_SIZE = 16; @@ -66,8 +66,8 @@ class Terrain3DStorage : public Resource { HEIGHT_FILTER_MINIMUM }; +private: // Storage Settings & flags - real_t _version = 0.8; // Set to ensure Godot always saves this bool _modified = false; bool _save_16_bit = false; @@ -75,7 +75,6 @@ class Terrain3DStorage : public Resource { Vector2i _region_sizev = Vector2i(_region_size, _region_size); // Stored Data - Vector2 _height_range = Vector2(0, 0); /** @@ -99,7 +98,6 @@ class Terrain3DStorage : public Resource { // Functions void _clear(); - void _update_regions(bool force_emit = false); // DEPRECATED 0.8.3, remove 0.9 Ref _texture_list; @@ -133,6 +131,7 @@ class Terrain3DStorage : public Resource { bool has_region(Vector3 p_global_position) { return get_region_index(p_global_position) != -1; } Error add_region(Vector3 p_global_position, const TypedArray &p_images = TypedArray(), bool p_update = true); void remove_region(Vector3 p_global_position, bool p_update = true); + void update_regions(bool force_emit = false); // Maps void set_map_region(MapType p_map_type, int p_region_index, const Ref p_image); diff --git a/src/terrain_3d_surface.h b/src/terrain_3d_surface.h index 851dce794..83bd6d641 100644 --- a/src/terrain_3d_surface.h +++ b/src/terrain_3d_surface.h @@ -12,8 +12,10 @@ using namespace godot; ******************************************************************/ class Terrain3DSurface : public Resource { -private: GDCLASS(Terrain3DSurface, Resource); + +public: + // Constants static inline const char *__class__ = "Terrain3DSurface"; struct Settings { @@ -24,7 +26,10 @@ class Terrain3DSurface : public Resource { Ref _normal_texture; real_t _uv_scale = 0.1f; real_t _uv_rotation = 0.0f; - } _data; + }; + +private: + Settings _data; bool _texture_is_valid(const Ref &p_texture) const; diff --git a/src/terrain_3d_texture.h b/src/terrain_3d_texture.h index 7521a5c4f..60b47f1d3 100644 --- a/src/terrain_3d_texture.h +++ b/src/terrain_3d_texture.h @@ -8,8 +8,10 @@ using namespace godot; class Terrain3DTexture : public Resource { -private: GDCLASS(Terrain3DTexture, Resource); + +public: + // Constants static inline const char *__class__ = "Terrain3DTexture"; struct Settings { @@ -20,7 +22,10 @@ class Terrain3DTexture : public Resource { Ref _normal_texture; real_t _uv_scale = 0.1f; real_t _uv_rotation = 0.0f; - } _data; + }; + +private: + Settings _data; bool _is_texture_valid(const Ref &p_texture) const; diff --git a/src/terrain_3d_texture_list.cpp b/src/terrain_3d_texture_list.cpp index 3978494ea..fefc23472 100644 --- a/src/terrain_3d_texture_list.cpp +++ b/src/terrain_3d_texture_list.cpp @@ -32,30 +32,7 @@ void Terrain3DTextureList::_swap_textures(int p_old_id, int p_new_id) { _textures[p_new_id] = texture_a; _textures[p_old_id] = texture_b; - _update_list(); -} - -void Terrain3DTextureList::_update_list() { - LOG(INFO, "Reconnecting texture signals"); - for (int i = 0; i < _textures.size(); i++) { - Ref texture_set = _textures[i]; - - if (texture_set.is_null()) { - LOG(ERROR, "Texture at index ", i, " is null, but shouldn't be."); - continue; - } - if (!texture_set->is_connected("file_changed", Callable(this, "_update_texture_files"))) { - LOG(DEBUG, "Connecting file_changed signal"); - texture_set->connect("file_changed", Callable(this, "_update_texture_files")); - } - if (!texture_set->is_connected("setting_changed", Callable(this, "_update_texture_settings"))) { - LOG(DEBUG, "Connecting setting_changed signal"); - texture_set->connect("setting_changed", Callable(this, "_update_texture_settings")); - } - } - _generated_albedo_textures.clear(); - _generated_normal_textures.clear(); - _update_texture_data(true, true); + update_list(); } void Terrain3DTextureList::_update_texture_files() { @@ -215,6 +192,29 @@ Terrain3DTextureList::~Terrain3DTextureList() { _generated_normal_textures.clear(); } +void Terrain3DTextureList::update_list() { + LOG(INFO, "Reconnecting texture signals"); + for (int i = 0; i < _textures.size(); i++) { + Ref texture_set = _textures[i]; + + if (texture_set.is_null()) { + LOG(ERROR, "Texture at index ", i, " is null, but shouldn't be."); + continue; + } + if (!texture_set->is_connected("file_changed", Callable(this, "_update_texture_files"))) { + LOG(DEBUG, "Connecting file_changed signal"); + texture_set->connect("file_changed", Callable(this, "_update_texture_files")); + } + if (!texture_set->is_connected("setting_changed", Callable(this, "_update_texture_settings"))) { + LOG(DEBUG, "Connecting setting_changed signal"); + texture_set->connect("setting_changed", Callable(this, "_update_texture_settings")); + } + } + _generated_albedo_textures.clear(); + _generated_normal_textures.clear(); + _update_texture_data(true, true); +} + void Terrain3DTextureList::set_texture(int p_index, const Ref &p_texture) { LOG(INFO, "Setting texture index: ", p_index); if (p_index < 0 || p_index >= MAX_TEXTURES) { @@ -248,7 +248,7 @@ void Terrain3DTextureList::set_texture(int p_index, const Ref _textures[p_index] = p_texture; } } - _update_list(); + update_list(); } /** @@ -283,7 +283,7 @@ void Terrain3DTextureList::set_textures(const TypedArray &p_te texture->connect("id_changed", Callable(this, "_swap_textures")); } } - _update_list(); + update_list(); } void Terrain3DTextureList::save() { diff --git a/src/terrain_3d_texture_list.h b/src/terrain_3d_texture_list.h index 4086b2a9b..ae9c305b3 100644 --- a/src/terrain_3d_texture_list.h +++ b/src/terrain_3d_texture_list.h @@ -9,19 +9,21 @@ using namespace godot; class Terrain3DTextureList : public Resource { -private: GDCLASS(Terrain3DTextureList, Resource); + +public: + // Constants static inline const char *__class__ = "Terrain3DTextureList"; static inline const int MAX_TEXTURES = 32; +private: TypedArray _textures; GeneratedTex _generated_albedo_textures; GeneratedTex _generated_normal_textures; void _swap_textures(int p_old_id, int p_new_id); - void _update_list(); void _update_texture_files(); void _update_texture_settings(); void _update_texture_data(bool p_textures, bool p_settings); @@ -30,6 +32,7 @@ class Terrain3DTextureList : public Resource { Terrain3DTextureList(); ~Terrain3DTextureList(); + void update_list(); void set_texture(int p_index, const Ref &p_texture); Ref get_texture(int p_index) const { return _textures[p_index]; } void set_textures(const TypedArray &p_textures); diff --git a/src/util.h b/src/util.h index abeea4068..8ca85ae5d 100644 --- a/src/util.h +++ b/src/util.h @@ -11,9 +11,9 @@ using namespace godot; class Util { +public: static inline const char *__class__ = "Terrain3DUtil"; -public: // Print info to the console static void print_dict(String name, const Dictionary &p_dict, int p_level = 1); // Defaults to INFO static void dump_gen(GeneratedTex p_gen, String name = "");