From a751d99131416a9db164e8f342957045a296ac87 Mon Sep 17 00:00:00 2001
From: Cory Petkovsek <632766+TokisanGames@users.noreply.github.com>
Date: Thu, 21 Dec 2023 02:53:42 +0700
Subject: [PATCH] Remove 0.8.x deprecated classes and upgrade code
---
Terrain3D.vcxproj | 2 -
Terrain3D.vcxproj.filters | 6 --
doc/docs/storage_format.md | 7 ++-
src/register_types.cpp | 1 -
src/terrain_3d.cpp | 8 +--
src/terrain_3d_storage.cpp | 86 ---------------------------
src/terrain_3d_storage.h | 12 ----
src/terrain_3d_surface.cpp | 116 -------------------------------------
src/terrain_3d_surface.h | 69 ----------------------
9 files changed, 6 insertions(+), 301 deletions(-)
delete mode 100644 src/terrain_3d_surface.cpp
delete mode 100644 src/terrain_3d_surface.h
diff --git a/Terrain3D.vcxproj b/Terrain3D.vcxproj
index a8c297b31..d5ef4a2b6 100644
--- a/Terrain3D.vcxproj
+++ b/Terrain3D.vcxproj
@@ -149,7 +149,6 @@
-
@@ -161,7 +160,6 @@
-
diff --git a/Terrain3D.vcxproj.filters b/Terrain3D.vcxproj.filters
index bdc2328ee..cb514be11 100644
--- a/Terrain3D.vcxproj.filters
+++ b/Terrain3D.vcxproj.filters
@@ -42,9 +42,6 @@
4. Headers
-
- 4. Headers
-
4. Headers
@@ -80,9 +77,6 @@
5. C++
-
- 5. C++
-
5. C++
diff --git a/doc/docs/storage_format.md b/doc/docs/storage_format.md
index dbd205856..8ae113939 100644
--- a/doc/docs/storage_format.md
+++ b/doc/docs/storage_format.md
@@ -1,8 +1,11 @@
Storage Format Changelog
==========================
-The format version is found as [Terrain3DStorage.version](../api/class_terrain3dstorage.rst#class-terrain3dstorage-property-version) and visible in the inspector under `Storage/Version`.
+The format version is found as [Terrain3DStorage.version](../api/class_terrain3dstorage.rst#class-terrain3dstorage-property-version) and visible in the inspector under `Storage/Version`. This version is different from the plugin version, shown at the top of the inspector.
+
* 0.842 - Control map changed from FORMAT_RGB to 32-bit packed integer (encoded in FORMAT_RF) [#234](https://github.com/TokisanGames/Terrain3D/pull/234/)
* 0.841 - Colormap painted/stored as srgb and converted to linear in the shader (prev painted/stored as linear). [64dc3e4](https://github.com/TokisanGames/Terrain3D/commit/64dc3e4b5e71c11ac3f2cd4fedf9aeb7d235f45c)
* 0.84 - Separated material processing from Storage as a `Terrain3DMaterial` resource. [#224](https://github.com/TokisanGames/Terrain3D/pull/224/)
* 0.83 - Separated Surfaces (textures) from Storage as a `Terrain3DTextureList` resource. [#188](https://github.com/TokisanGames/Terrain3D/pull/188/)
-* 0.8 - Initial version
\ No newline at end of file
+* 0.8 - Initial version
+
+Note in plugin v0.9.1 the deprecated code to upgrade 0.8x storage versions was removed. To upgrade your Terrain3DStorage to 0.9.1+ load it in 0.8.4 or 0.9.0 and save it.
\ No newline at end of file
diff --git a/src/register_types.cpp b/src/register_types.cpp
index db1682371..346a952ed 100644
--- a/src/register_types.cpp
+++ b/src/register_types.cpp
@@ -20,7 +20,6 @@ void initialize_terrain_3d(ModuleInitializationLevel p_level) {
ClassDB::register_class();
ClassDB::register_class();
ClassDB::register_class();
- ClassDB::register_class(); // DEPRECATED 0.8.3, remove 0.9
ClassDB::register_class();
ClassDB::register_class();
ClassDB::register_class();
diff --git a/src/terrain_3d.cpp b/src/terrain_3d.cpp
index de3643541..8119bd0df 100644
--- a/src/terrain_3d.cpp
+++ b/src/terrain_3d.cpp
@@ -39,9 +39,6 @@ void Terrain3D::_initialize() {
LOG(DEBUG, "Creating blank storage");
_storage.instantiate();
_storage->set_version(Terrain3DStorage::CURRENT_VERSION);
- } else if (_texture_list.is_null() && _storage->get_version() < 0.83f) {
- // DEPREPCATED 0.8.3, remove 0.9
- _texture_list = _storage->get_texture_list();
}
if (_texture_list.is_null()) {
LOG(DEBUG, "Creating blank texture list");
@@ -620,10 +617,7 @@ void Terrain3D::set_material(const Ref &p_material) {
void Terrain3D::set_storage(const Ref &p_storage) {
if (_storage != p_storage) {
_storage = p_storage;
- if (_storage.is_valid()) {
- // DEPRECATED 0.8.4 remove 0.9 - Version redundant w/ set_version after 0.8.4
- LOG(INFO, "Loaded storage version: ", vformat("%.3f", p_storage->get_version()));
- } else {
+ if (_storage.is_null()) {
LOG(INFO, "Clearing storage");
}
_clear();
diff --git a/src/terrain_3d_storage.cpp b/src/terrain_3d_storage.cpp
index 76cb656f0..67e548a2f 100644
--- a/src/terrain_3d_storage.cpp
+++ b/src/terrain_3d_storage.cpp
@@ -39,12 +39,6 @@ Terrain3DStorage::~Terrain3DStorage() {
void Terrain3DStorage::set_version(real_t p_version) {
LOG(INFO, vformat("%.3f", p_version));
_version = p_version;
- if (_version >= 0.841f) {
- _841_colormap_upgraded = true;
- }
- if (_version >= 0.842f) {
- _842_controlmap_upgraded = true;
- }
if (_version < CURRENT_VERSION) {
LOG(WARN, "Storage version ", vformat("%.3f", _version), " will be updated to ", vformat("%.3f", CURRENT_VERSION), " upon save");
_modified = true;
@@ -405,30 +399,6 @@ void Terrain3DStorage::set_height_maps(const TypedArray &p_maps) {
void Terrain3DStorage::set_control_maps(const TypedArray &p_maps) {
LOG(INFO, "Setting control maps: ", p_maps.size());
TypedArray maps = p_maps;
- // DEPRECATED 0.8.4 Remove 0.9
- // Convert old RGB8 control format <0.841 to bit based format 0.8.42
- if (_version < 0.842 && !_842_controlmap_upgraded && maps.size() > 0 &&
- (Ref(maps[0])->get_format() != FORMAT[TYPE_CONTROL])) {
- LOG(WARN, "Converting control maps to int format: ", vformat("%.3f", _version), "->", vformat("%.3f", CURRENT_VERSION));
- for (int i = 0; i < maps.size(); i++) {
- Ref old_img = maps[i];
- PackedByteArray pba;
- pba.resize(_region_size * _region_size * sizeof(uint32_t));
- for (int x = 0; x < old_img->get_width(); x++) {
- for (int y = 0; y < old_img->get_height(); y++) {
- Color pixel = old_img->get_pixel(x, y);
- uint32_t base = (pixel.get_r8() & 0x1F) << 27; // 5 bits 32-28
- uint32_t over = (pixel.get_g8() & 0x1F) << 22; // 5 bits 27-23
- uint32_t blend = (pixel.get_b8() & 0xFF) << 14; // 8 bits 22-15
- uint32_t value = base | over | blend;
- pba.encode_u32((y * _region_size + x) * sizeof(uint32_t), value);
- }
- }
- Ref new_img = Image::create_from_data(_region_size, _region_size, false, Image::FORMAT_RF, pba);
- maps[i] = new_img;
- }
- _842_controlmap_upgraded = true;
- }
_control_maps = sanitize_maps(TYPE_CONTROL, maps);
force_update_maps(TYPE_CONTROL);
}
@@ -436,22 +406,6 @@ void Terrain3DStorage::set_control_maps(const TypedArray &p_maps) {
void Terrain3DStorage::set_color_maps(const TypedArray &p_maps) {
LOG(INFO, "Setting color maps: ", p_maps.size());
TypedArray maps = p_maps;
- // DEPRECATED 0.8.4 Remove 0.9
- // Convert colormap from linear <0.84 to srgb 0.841
- if (_version < 0.841 && !_841_colormap_upgraded && maps.size() > 0) {
- LOG(WARN, "Converting color maps from linear to srgb: ", vformat("%.3f", _version), "->", vformat("%.3f", CURRENT_VERSION));
- for (int i = 0; i < maps.size(); i++) {
- Ref img = maps[i];
- for (int x = 0; x < img->get_width(); x++) {
- for (int y = 0; y < img->get_height(); y++) {
- Color c = img->get_pixel(x, y);
- img->set_pixel(x, y, c.linear_to_srgb());
- }
- }
- maps[i] = img;
- }
- _841_colormap_upgraded = true;
- }
_color_maps = sanitize_maps(TYPE_COLOR, maps);
force_update_maps(TYPE_COLOR);
}
@@ -1023,34 +977,6 @@ void Terrain3DStorage::print_audit_data() {
Util::dump_gen(_generated_color_maps, "color");
}
-// DEPRECATED 0.8.3, remove 0.9
-void Terrain3DStorage::set_surfaces(const TypedArray &p_surfaces) {
- set_version(0.8f);
- LOG(WARN, "Converting Surfaces to separate TextureList: ", vformat("%.3f", _version), "->", vformat("%.3f", CURRENT_VERSION));
- _texture_list.instantiate();
- TypedArray textures;
- textures.resize(p_surfaces.size());
-
- for (int i = 0; i < p_surfaces.size(); i++) {
- LOG(DEBUG, "Converting surface: ", i);
- Ref sfc = p_surfaces[i];
- Ref tex;
- tex.instantiate();
-
- Terrain3DTexture::Settings *tex_data = tex->get_data();
- Terrain3DSurface::Settings *sfc_data = sfc->get_data();
- tex_data->_name = sfc_data->_name;
- tex_data->_texture_id = sfc_data->_surface_id;
- tex_data->_albedo_color = sfc_data->_albedo;
- tex_data->_albedo_texture = sfc_data->_albedo_texture;
- tex_data->_normal_texture = sfc_data->_normal_texture;
- tex_data->_uv_scale = sfc_data->_uv_scale;
- tex_data->_uv_rotation = sfc_data->_uv_rotation;
- textures[i] = tex;
- }
- _texture_list->set_textures(textures);
-}
-
///////////////////////////
// Protected Functions
///////////////////////////
@@ -1140,16 +1066,4 @@ void Terrain3DStorage::_bind_methods() {
ADD_SIGNAL(MethodInfo("height_maps_changed"));
ADD_SIGNAL(MethodInfo("region_size_changed"));
ADD_SIGNAL(MethodInfo("regions_changed"));
-
- // DEPRECATED 0.8.4, Remove 0.9
- int flags = PROPERTY_USAGE_NONE;
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "data_version", PROPERTY_HINT_NONE, "", flags), "set_version", "get_version");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "data_height_range", PROPERTY_HINT_NONE, "", flags), "set_height_range", "get_height_range");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data_region_offsets", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::VECTOR2, PROPERTY_HINT_NONE), flags), "set_region_offsets", "get_region_offsets");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data_height_maps", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Image"), flags), "set_height_maps", "get_height_maps");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data_control_maps", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Image"), flags), "set_control_maps", "get_control_maps");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data_color_maps", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Image"), flags), "set_color_maps", "get_color_maps");
- ClassDB::bind_method(D_METHOD("set_surfaces", "surfaces"), &Terrain3DStorage::set_surfaces);
- ClassDB::bind_method(D_METHOD("get_surfaces"), &Terrain3DStorage::get_surfaces);
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "data_surfaces", PROPERTY_HINT_ARRAY_TYPE, vformat("%tex_size/%tex_size:%tex_size", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "Terrain3DSurface"), flags), "set_surfaces", "get_surfaces");
}
diff --git a/src/terrain_3d_storage.h b/src/terrain_3d_storage.h
index 4e7144673..1a47ccf6f 100644
--- a/src/terrain_3d_storage.h
+++ b/src/terrain_3d_storage.h
@@ -8,7 +8,6 @@
#include "constants.h"
#include "generated_tex.h"
-#include "terrain_3d_surface.h" // DEPRECATED 0.8.3, remove 0.9
#include "terrain_3d_texture_list.h"
#include "util.h"
@@ -100,12 +99,6 @@ class Terrain3DStorage : public Resource {
// Functions
void _clear();
- // DEPRECATED 0.8.3, remove 0.9
- Ref _texture_list;
- // DEPRECATED 0.8.4, remove 0.9
- bool _841_colormap_upgraded = false;
- bool _842_controlmap_upgraded = false;
-
public:
Terrain3DStorage();
~Terrain3DStorage();
@@ -176,11 +169,6 @@ class Terrain3DStorage : public Resource {
Vector3 get_normal(Vector3 global_position);
void print_audit_data();
- // DEPRECATED 0.8.3, remove 0.9
- void set_surfaces(const TypedArray &p_surfaces);
- TypedArray get_surfaces() const { return TypedArray(); }
- Ref get_texture_list() const { return _texture_list; }
-
protected:
static void _bind_methods();
};
diff --git a/src/terrain_3d_surface.cpp b/src/terrain_3d_surface.cpp
deleted file mode 100644
index 5bc15853e..000000000
--- a/src/terrain_3d_surface.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-// Copyright © 2023 Cory Petkovsek, Roope Palmroos, and Contributors.
-
-#include
-
-#include "logger.h"
-#include "terrain_3d_surface.h"
-
-/******************************************************************
- * This class is DEPRECATED in 0.8.3. Remove 0.9. Do not use.
- ******************************************************************/
-
-///////////////////////////
-// Private Functions
-///////////////////////////
-
-bool Terrain3DSurface::_texture_is_valid(const Ref &p_texture) const {
- if (p_texture.is_null()) {
- LOG(DEBUG, "Provided texture is null.");
- return true;
- }
-
- Ref img = p_texture->get_image();
- Image::Format format = Image::FORMAT_MAX;
- if (img.is_valid()) {
- format = img->get_format();
- }
- if (format != Image::FORMAT_DXT5) {
- LOG(ERROR, "Invalid format. Expected channel packed DXT5 RGBA8. See documentation for format.");
- return false;
- }
-
- return true;
-}
-
-///////////////////////////
-// Public Functions
-///////////////////////////
-
-Terrain3DSurface::Terrain3DSurface() {
-}
-
-Terrain3DSurface::~Terrain3DSurface() {
-}
-
-void Terrain3DSurface::clear() {
- _data._name = "New Texture";
- _data._surface_id = 0;
- _data._albedo = Color(1.0, 1.0, 1.0, 1.0);
- _data._albedo_texture.unref();
- _data._normal_texture.unref();
- _data._uv_scale = 0.1f;
- _data._uv_rotation = 0.0f;
-}
-
-void Terrain3DSurface::set_name(String p_name) {
- _data._name = p_name;
-}
-
-void Terrain3DSurface::set_surface_id(int p_new_id) {
- int old_id = _data._surface_id;
- _data._surface_id = p_new_id;
-}
-
-void Terrain3DSurface::set_albedo(Color p_color) {
- _data._albedo = p_color;
-}
-
-void Terrain3DSurface::set_albedo_texture(const Ref &p_texture) {
- if (_texture_is_valid(p_texture)) {
- _data._albedo_texture = p_texture;
- }
-}
-
-void Terrain3DSurface::set_normal_texture(const Ref &p_texture) {
- if (_texture_is_valid(p_texture)) {
- _data._normal_texture = p_texture;
- }
-}
-
-void Terrain3DSurface::set_uv_scale(real_t p_scale) {
- _data._uv_scale = p_scale;
-}
-
-void Terrain3DSurface::set_uv_rotation(real_t p_rotation) {
- _data._uv_rotation = CLAMP(p_rotation, 0.0f, 1.0f);
-}
-
-///////////////////////////
-// Protected Functions
-///////////////////////////
-
-void Terrain3DSurface::_bind_methods() {
- ClassDB::bind_method(D_METHOD("clear"), &Terrain3DSurface::clear);
- ClassDB::bind_method(D_METHOD("set_name", "name"), &Terrain3DSurface::set_name);
- ClassDB::bind_method(D_METHOD("get_name"), &Terrain3DSurface::get_name);
- ClassDB::bind_method(D_METHOD("set_surface_id", "id"), &Terrain3DSurface::set_surface_id);
- ClassDB::bind_method(D_METHOD("get_surface_id"), &Terrain3DSurface::get_surface_id);
- ClassDB::bind_method(D_METHOD("set_albedo", "color"), &Terrain3DSurface::set_albedo);
- ClassDB::bind_method(D_METHOD("get_albedo"), &Terrain3DSurface::get_albedo);
- ClassDB::bind_method(D_METHOD("set_albedo_texture", "texture"), &Terrain3DSurface::set_albedo_texture);
- ClassDB::bind_method(D_METHOD("get_albedo_texture"), &Terrain3DSurface::get_albedo_texture);
- ClassDB::bind_method(D_METHOD("set_normal_texture", "texture"), &Terrain3DSurface::set_normal_texture);
- ClassDB::bind_method(D_METHOD("get_normal_texture"), &Terrain3DSurface::get_normal_texture);
- ClassDB::bind_method(D_METHOD("set_uv_scale", "scale"), &Terrain3DSurface::set_uv_scale);
- ClassDB::bind_method(D_METHOD("get_uv_scale"), &Terrain3DSurface::get_uv_scale);
- ClassDB::bind_method(D_METHOD("set_uv_rotation", "scale"), &Terrain3DSurface::set_uv_rotation);
- ClassDB::bind_method(D_METHOD("get_uv_rotation"), &Terrain3DSurface::get_uv_rotation);
-
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "name", PROPERTY_HINT_NONE), "set_name", "get_name");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "surface_id", PROPERTY_HINT_NONE), "set_surface_id", "get_surface_id");
- ADD_PROPERTY(PropertyInfo(Variant::COLOR, "albedo", PROPERTY_HINT_COLOR_NO_ALPHA), "set_albedo", "get_albedo");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "albedo_texture", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture,CompressedTexture2D"), "set_albedo_texture", "get_albedo_texture");
- ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal_texture", PROPERTY_HINT_RESOURCE_TYPE, "ImageTexture,CompressedTexture2D"), "set_normal_texture", "get_normal_texture");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "uv_scale", PROPERTY_HINT_RANGE, "0.001, 2.0"), "set_uv_scale", "get_uv_scale");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "uv_rotation", PROPERTY_HINT_RANGE, "0.0, 1.0"), "set_uv_rotation", "get_uv_rotation");
-}
\ No newline at end of file
diff --git a/src/terrain_3d_surface.h b/src/terrain_3d_surface.h
deleted file mode 100644
index 83bd6d641..000000000
--- a/src/terrain_3d_surface.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright © 2023 Cory Petkovsek, Roope Palmroos, and Contributors.
-
-#ifndef TERRAIN3D_SURFACE_CLASS_H
-#define TERRAIN3D_SURFACE_CLASS_H
-
-#include
-
-using namespace godot;
-
-/******************************************************************
- * This class is DEPRECATED in 0.8.3. Remove 0.9. Do not use.
- ******************************************************************/
-
-class Terrain3DSurface : public Resource {
- GDCLASS(Terrain3DSurface, Resource);
-
-public:
- // Constants
- static inline const char *__class__ = "Terrain3DSurface";
-
- struct Settings {
- String _name = "New Texture";
- int _surface_id = 0;
- Color _albedo = Color(1.0, 1.0, 1.0, 1.0);
- Ref _albedo_texture;
- Ref _normal_texture;
- real_t _uv_scale = 0.1f;
- real_t _uv_rotation = 0.0f;
- };
-
-private:
- Settings _data;
-
- bool _texture_is_valid(const Ref &p_texture) const;
-
-public:
- Terrain3DSurface();
- ~Terrain3DSurface();
-
- // Edit data directly to avoid signal emitting recursion
- Settings *get_data() { return &_data; }
- void clear();
-
- void set_name(String p_name);
- String get_name() const { return _data._name; }
-
- void set_surface_id(int p_new_id);
- int get_surface_id() const { return _data._surface_id; }
-
- void set_albedo(Color p_color);
- Color get_albedo() const { return _data._albedo; }
-
- void set_albedo_texture(const Ref &p_texture);
- Ref get_albedo_texture() const { return _data._albedo_texture; }
-
- void set_normal_texture(const Ref &p_texture);
- Ref get_normal_texture() const { return _data._normal_texture; }
-
- void set_uv_scale(real_t p_scale);
- real_t get_uv_scale() const { return _data._uv_scale; }
-
- void set_uv_rotation(real_t p_rotation);
- real_t get_uv_rotation() const { return _data._uv_rotation; }
-
-protected:
- static void _bind_methods();
-};
-
-#endif // TERRAIN3D_SURFACE_CLASS_H
\ No newline at end of file