Skip to content

Commit

Permalink
Remove 0.8.x deprecated classes and upgrade code
Browse files Browse the repository at this point in the history
  • Loading branch information
TokisanGames committed Dec 20, 2023
1 parent 24a5993 commit a751d99
Show file tree
Hide file tree
Showing 9 changed files with 6 additions and 301 deletions.
2 changes: 0 additions & 2 deletions Terrain3D.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@
<ClInclude Include="src\util.h" />
<ClInclude Include="src\terrain_3d_material.h" />
<ClInclude Include="src\terrain_3d_storage.h" />
<ClInclude Include="src\terrain_3d_surface.h" />
<ClInclude Include="src\terrain_3d_texture.h" />
<ClInclude Include="src\terrain_3d_texture_list.h" />
</ItemGroup>
Expand All @@ -161,7 +160,6 @@
<ClCompile Include="src\terrain_3d_editor.cpp" />
<ClCompile Include="src\terrain_3d_material.cpp" />
<ClCompile Include="src\terrain_3d_storage.cpp" />
<ClCompile Include="src\terrain_3d_surface.cpp" />
<ClCompile Include="src\terrain_3d_texture.cpp" />
<ClCompile Include="src\terrain_3d_texture_list.cpp" />
<ClCompile Include="src\util.cpp" />
Expand Down
6 changes: 0 additions & 6 deletions Terrain3D.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@
<ClInclude Include="src\terrain_3d_storage.h">
<Filter>4. Headers</Filter>
</ClInclude>
<ClInclude Include="src\terrain_3d_surface.h">
<Filter>4. Headers</Filter>
</ClInclude>
<ClInclude Include="src\terrain_3d_texture.h">
<Filter>4. Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -80,9 +77,6 @@
<ClCompile Include="src\terrain_3d_storage.cpp">
<Filter>5. C++</Filter>
</ClCompile>
<ClCompile Include="src\terrain_3d_surface.cpp">
<Filter>5. C++</Filter>
</ClCompile>
<ClCompile Include="src\terrain_3d_texture.cpp">
<Filter>5. C++</Filter>
</ClCompile>
Expand Down
7 changes: 5 additions & 2 deletions doc/docs/storage_format.md
Original file line number Diff line number Diff line change
@@ -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
* 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.
1 change: 0 additions & 1 deletion src/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ void initialize_terrain_3d(ModuleInitializationLevel p_level) {
ClassDB::register_class<Terrain3D>();
ClassDB::register_class<Terrain3DMaterial>();
ClassDB::register_class<Terrain3DStorage>();
ClassDB::register_class<Terrain3DSurface>(); // DEPRECATED 0.8.3, remove 0.9
ClassDB::register_class<Terrain3DTexture>();
ClassDB::register_class<Terrain3DTextureList>();
ClassDB::register_class<Terrain3DEditor>();
Expand Down
8 changes: 1 addition & 7 deletions src/terrain_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -620,10 +617,7 @@ void Terrain3D::set_material(const Ref<Terrain3DMaterial> &p_material) {
void Terrain3D::set_storage(const Ref<Terrain3DStorage> &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();
Expand Down
86 changes: 0 additions & 86 deletions src/terrain_3d_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -405,53 +399,13 @@ void Terrain3DStorage::set_height_maps(const TypedArray<Image> &p_maps) {
void Terrain3DStorage::set_control_maps(const TypedArray<Image> &p_maps) {
LOG(INFO, "Setting control maps: ", p_maps.size());
TypedArray<Image> 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<Image>(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<Image> 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<Image> 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);
}

void Terrain3DStorage::set_color_maps(const TypedArray<Image> &p_maps) {
LOG(INFO, "Setting color maps: ", p_maps.size());
TypedArray<Image> 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<Image> 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);
}
Expand Down Expand Up @@ -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<Terrain3DSurface> &p_surfaces) {
set_version(0.8f);
LOG(WARN, "Converting Surfaces to separate TextureList: ", vformat("%.3f", _version), "->", vformat("%.3f", CURRENT_VERSION));
_texture_list.instantiate();
TypedArray<Terrain3DTexture> textures;
textures.resize(p_surfaces.size());

for (int i = 0; i < p_surfaces.size(); i++) {
LOG(DEBUG, "Converting surface: ", i);
Ref<Terrain3DSurface> sfc = p_surfaces[i];
Ref<Terrain3DTexture> 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
///////////////////////////
Expand Down Expand Up @@ -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");
}
12 changes: 0 additions & 12 deletions src/terrain_3d_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -100,12 +99,6 @@ class Terrain3DStorage : public Resource {
// Functions
void _clear();

// DEPRECATED 0.8.3, remove 0.9
Ref<Terrain3DTextureList> _texture_list;
// DEPRECATED 0.8.4, remove 0.9
bool _841_colormap_upgraded = false;
bool _842_controlmap_upgraded = false;

public:
Terrain3DStorage();
~Terrain3DStorage();
Expand Down Expand Up @@ -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<Terrain3DSurface> &p_surfaces);
TypedArray<Terrain3DSurface> get_surfaces() const { return TypedArray<Terrain3DSurface>(); }
Ref<Terrain3DTextureList> get_texture_list() const { return _texture_list; }

protected:
static void _bind_methods();
};
Expand Down
116 changes: 0 additions & 116 deletions src/terrain_3d_surface.cpp

This file was deleted.

Loading

0 comments on commit a751d99

Please sign in to comment.