diff --git a/library/terraman_library.cpp b/library/terraman_library.cpp index 4282af9..6722556 100644 --- a/library/terraman_library.cpp +++ b/library/terraman_library.cpp @@ -24,6 +24,8 @@ SOFTWARE. #include "../world/terra_chunk.h" +#include "terra_material_cache.h" + #ifdef PROPS_PRESENT #include "../../props/props/prop_data.h" #endif @@ -67,20 +69,20 @@ Ref TerramanLibrary::material_lod_get(const int index) { return _materials[index]; } -int TerramanLibrary::material_cached_get_key(const Ref &chunk) { - return call("_material_cached_get_key", chunk); +int TerramanLibrary::material_cache_get_key(const Ref &chunk) { + return call("_material_cache_get_key", chunk); } -int TerramanLibrary::_material_cached_get_key(Ref chunk) { +int TerramanLibrary::_material_cache_get_key(Ref chunk) { return 0; } -Ref TerramanLibrary::material_lod_cached_get(const int index, const int key) { - return call("_material_lod_cached_get", index, key); +Ref TerramanLibrary::material_cache_get(const int key) { + return call("_material_cache_get", key); } -Ref TerramanLibrary::_material_lod_cached_get(const int index, const int key) { - ERR_FAIL_V_MSG(material_lod_get(index), "This TerramanLibrary doesn't support cached materials!"); +Ref TerramanLibrary::_material_cache_get(const int key) { + ERR_FAIL_V_MSG(Ref(), "This TerramanLibrary doesn't support cached materials!"); } void TerramanLibrary::material_add(const Ref &value) { @@ -142,20 +144,20 @@ Ref TerramanLibrary::liquid_material_lod_get(const int index) { return _liquid_materials[index]; } -int TerramanLibrary::liquid_material_cached_get_key(const Ref &chunk) { - return call("_liquid_material_cached_get_key", chunk); +int TerramanLibrary::liquid_material_cache_get_key(const Ref &chunk) { + return call("_liquid_material_cache_get_key", chunk); } -int TerramanLibrary::_liquid_material_cached_get_key(Ref chunk) { +int TerramanLibrary::_liquid_material_cache_get_key(Ref chunk) { return 0; } -Ref TerramanLibrary::liquid_material_lod_cached_get(const int index, const int key) { - return call("_liquid_material_lod_cached_get", index, key); +Ref TerramanLibrary::liquid_material_cache_get(const int key) { + return call("_liquid_material_cache_get", key); } -Ref TerramanLibrary::_liquid_material_lod_cached_get(const int index, const int key) { - ERR_FAIL_V_MSG(liquid_material_lod_get(index), "This TerramanLibrary doesn't support cached liquid materials!"); +Ref TerramanLibrary::_liquid_material_cache_get(const int key) { + ERR_FAIL_V_MSG(Ref(), "This TerramanLibrary doesn't support cached liquid materials!"); } void TerramanLibrary::liquid_material_add(const Ref &value) { @@ -217,20 +219,20 @@ Ref TerramanLibrary::prop_material_lod_get(const int index) { return _prop_materials[index]; } -int TerramanLibrary::prop_material_cached_get_key(const Ref &chunk) { - return call("_prop_material_cached_get_key", chunk); +int TerramanLibrary::prop_material_cache_get_key(const Ref &chunk) { + return call("_prop_material_cache_get_key", chunk); } -int TerramanLibrary::_prop_material_cached_get_key(Ref chunk) { +int TerramanLibrary::_prop_material_cache_get_key(Ref chunk) { return 0; } -Ref TerramanLibrary::prop_material_lod_cached_get(const int index, const int key) { - return call("_prop_material_lod_cached_get", index, key); +Ref TerramanLibrary::prop_material_cache_get(const int key) { + return call("_prop_material_cache_get", key); } -Ref TerramanLibrary::_prop_material_lod_cached_get(const int index, const int key) { - ERR_FAIL_V_MSG(prop_material_lod_get(index), "This TerramanLibrary doesn't support cached prop materials!"); +Ref TerramanLibrary::_prop_material_cache_get(const int key) { + ERR_FAIL_V_MSG(Ref(), "This TerramanLibrary doesn't support cached prop materials!"); } void TerramanLibrary::prop_material_add(const Ref &value) { @@ -347,16 +349,16 @@ void TerramanLibrary::_bind_methods() { BIND_VMETHOD(MethodInfo("_setup_material_albedo", PropertyInfo(Variant::INT, "material_index"), PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"))); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_material_cached_get_key")); - BIND_VMETHOD(MethodInfo("_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::INT, "key"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_material_cache_get_key")); + BIND_VMETHOD(MethodInfo("_material_cache_get", PropertyInfo(Variant::OBJECT, "key", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"))); ClassDB::bind_method(D_METHOD("material_get", "index"), &TerramanLibrary::material_get); ClassDB::bind_method(D_METHOD("material_lod_get", "index"), &TerramanLibrary::material_lod_get); - ClassDB::bind_method(D_METHOD("material_cached_get_key", "chunk"), &TerramanLibrary::material_cached_get_key); - ClassDB::bind_method(D_METHOD("_material_cached_get_key", "chunk"), &TerramanLibrary::_material_cached_get_key); - ClassDB::bind_method(D_METHOD("material_lod_cached_get", "index", "key"), &TerramanLibrary::material_lod_cached_get); - ClassDB::bind_method(D_METHOD("_material_lod_cached_get", "index", "key"), &TerramanLibrary::_material_lod_cached_get); + ClassDB::bind_method(D_METHOD("material_cache_get_key", "chunk"), &TerramanLibrary::material_cache_get_key); + ClassDB::bind_method(D_METHOD("_material_cache_get_key", "chunk"), &TerramanLibrary::_material_cache_get_key); + ClassDB::bind_method(D_METHOD("material_cache_get", "key"), &TerramanLibrary::material_cache_get); + ClassDB::bind_method(D_METHOD("_material_cache_get", "key"), &TerramanLibrary::_material_cache_get); ClassDB::bind_method(D_METHOD("material_add", "value"), &TerramanLibrary::material_add); ClassDB::bind_method(D_METHOD("material_set", "index", "value"), &TerramanLibrary::material_set); @@ -368,16 +370,16 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("materials_set"), &TerramanLibrary::materials_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "materials_set", "materials_get"); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_liquid_material_cached_get_key")); - BIND_VMETHOD(MethodInfo("_liquid_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::INT, "key"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_liquid_material_cache_get_key")); + BIND_VMETHOD(MethodInfo("_liquid_material_cache_get", PropertyInfo(Variant::OBJECT, "key", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"))); ClassDB::bind_method(D_METHOD("liquid_material_get", "index"), &TerramanLibrary::liquid_material_get); ClassDB::bind_method(D_METHOD("liquid_material_lod_get", "index"), &TerramanLibrary::liquid_material_lod_get); - ClassDB::bind_method(D_METHOD("liquid_material_cached_get_key", "chunk"), &TerramanLibrary::liquid_material_cached_get_key); - ClassDB::bind_method(D_METHOD("_liquid_material_cached_get_key", "chunk"), &TerramanLibrary::_liquid_material_cached_get_key); - ClassDB::bind_method(D_METHOD("liquid_material_lod_cached_get", "index", "key"), &TerramanLibrary::liquid_material_lod_cached_get); - ClassDB::bind_method(D_METHOD("_liquid_material_lod_cached_get", "index", "key"), &TerramanLibrary::_liquid_material_lod_cached_get); + ClassDB::bind_method(D_METHOD("liquid_material_cache_get_key", "chunk"), &TerramanLibrary::liquid_material_cache_get_key); + ClassDB::bind_method(D_METHOD("_liquid_material_cache_get_key", "chunk"), &TerramanLibrary::_liquid_material_cache_get_key); + ClassDB::bind_method(D_METHOD("liquid_material_cache_get", "key"), &TerramanLibrary::liquid_material_cache_get); + ClassDB::bind_method(D_METHOD("_liquid_material_cache_get", "key"), &TerramanLibrary::_liquid_material_cache_get); ClassDB::bind_method(D_METHOD("liquid_material_add", "value"), &TerramanLibrary::liquid_material_add); ClassDB::bind_method(D_METHOD("liquid_material_set", "index", "value"), &TerramanLibrary::liquid_material_set); @@ -389,16 +391,16 @@ void TerramanLibrary::_bind_methods() { ClassDB::bind_method(D_METHOD("liquid_materials_set"), &TerramanLibrary::liquid_materials_set); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "liquid_materials", PROPERTY_HINT_NONE, "17/17:Material", PROPERTY_USAGE_DEFAULT, "Material"), "liquid_materials_set", "liquid_materials_get"); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_prop_material_cached_get_key")); - BIND_VMETHOD(MethodInfo("_prop_material_lod_cached_get", PropertyInfo(Variant::INT, "index"), PropertyInfo(Variant::INT, "key"))); + BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::INT, "ret"), "_prop_material_cache_get_key")); + BIND_VMETHOD(MethodInfo("_prop_material_cache_get", PropertyInfo(Variant::OBJECT, "key", PROPERTY_HINT_RESOURCE_TYPE, "TerraMaterialCache"))); ClassDB::bind_method(D_METHOD("prop_material_get", "index"), &TerramanLibrary::prop_material_get); ClassDB::bind_method(D_METHOD("prop_material_lod_get", "index"), &TerramanLibrary::prop_material_lod_get); - ClassDB::bind_method(D_METHOD("prop_material_cached_get_key", "chunk"), &TerramanLibrary::prop_material_cached_get_key); - ClassDB::bind_method(D_METHOD("_prop_material_cached_get_key", "chunk"), &TerramanLibrary::_prop_material_cached_get_key); - ClassDB::bind_method(D_METHOD("prop_material_lod_cached_get", "index", "key"), &TerramanLibrary::prop_material_lod_cached_get); - ClassDB::bind_method(D_METHOD("_prop_material_lod_cached_get", "index", "key"), &TerramanLibrary::_prop_material_lod_cached_get); + ClassDB::bind_method(D_METHOD("prop_material_cache_get_key", "chunk"), &TerramanLibrary::prop_material_cache_get_key); + ClassDB::bind_method(D_METHOD("_prop_material_cache_get_key", "chunk"), &TerramanLibrary::_prop_material_cache_get_key); + ClassDB::bind_method(D_METHOD("prop_material_cache_get", "key"), &TerramanLibrary::prop_material_cache_get); + ClassDB::bind_method(D_METHOD("_prop_material_cache_get", "key"), &TerramanLibrary::_prop_material_cache_get); ClassDB::bind_method(D_METHOD("prop_material_add", "value"), &TerramanLibrary::prop_material_add); ClassDB::bind_method(D_METHOD("prop_material_set", "index", "value"), &TerramanLibrary::prop_material_set); diff --git a/library/terraman_library.h b/library/terraman_library.h index fc6b0be..bc53100 100644 --- a/library/terraman_library.h +++ b/library/terraman_library.h @@ -43,6 +43,7 @@ SOFTWARE. #define Texture Texture2D #endif +class TerraMaterialCache; class TerraSurface; class TerraMesher; class PackedScene; @@ -71,10 +72,10 @@ public: Ref material_get(const int index); Ref material_lod_get(const int index); - int material_cached_get_key(const Ref &chunk); - virtual int _material_cached_get_key(Ref chunk); - Ref material_lod_cached_get(const int index, const int key); - virtual Ref _material_lod_cached_get(const int index, const int key); + int material_cache_get_key(const Ref &chunk); + virtual int _material_cache_get_key(Ref chunk); + Ref material_cache_get(const int key); + virtual Ref _material_cache_get(const int key); void material_add(const Ref &value); void material_set(const int index, const Ref &value); @@ -88,10 +89,10 @@ public: Ref liquid_material_get(const int index); Ref liquid_material_lod_get(const int index); - int liquid_material_cached_get_key(const Ref &chunk); - virtual int _liquid_material_cached_get_key(Ref chunk); - Ref liquid_material_lod_cached_get(const int index, const int key); - virtual Ref _liquid_material_lod_cached_get(const int index, const int key); + int liquid_material_cache_get_key(const Ref &chunk); + virtual int _liquid_material_cache_get_key(Ref chunk); + Ref liquid_material_cache_get(const int key); + virtual Ref _liquid_material_cache_get(const int key); void liquid_material_add(const Ref &value); void liquid_material_set(const int index, const Ref &value); @@ -105,10 +106,10 @@ public: Ref prop_material_get(const int index); Ref prop_material_lod_get(const int index); - int prop_material_cached_get_key(const Ref &chunk); - virtual int _prop_material_cached_get_key(Ref chunk); - Ref prop_material_lod_cached_get(const int index, const int key); - virtual Ref _prop_material_lod_cached_get(const int index, const int key); + int prop_material_cache_get_key(const Ref &chunk); + virtual int _prop_material_cache_get_key(Ref chunk); + Ref prop_material_cache_get(const int key); + virtual Ref _prop_material_cache_get(const int key); void prop_material_add(const Ref &value); void prop_material_set(const int index, const Ref &value); diff --git a/world/jobs/terra_terrarin_job.cpp b/world/jobs/terra_terrarin_job.cpp index 06a2e28..02ba9e4 100644 --- a/world/jobs/terra_terrarin_job.cpp +++ b/world/jobs/terra_terrarin_job.cpp @@ -24,6 +24,7 @@ SOFTWARE. #include "../../library/terra_surface.h" #include "../../library/terraman_library.h" +#include "../../library/terra_material_cache.h" #include "../../meshers/blocky/terra_mesher_blocky.h" #include "../../meshers/default/terra_mesher_default.h" @@ -98,7 +99,7 @@ void TerraTerrarinJob::phase_library_setup() { } if (lib->supports_caching()) { - _terrain_material_key = lib->material_cached_get_key(_chunk); + _terrain_material_key = lib->material_cache_get_key(_chunk); if (_mesher.is_valid()) { _mesher->set_terrain_material_key(_terrain_material_key); @@ -483,7 +484,7 @@ void TerraTerrarinJob::step_type_normal() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); } @@ -524,7 +525,7 @@ void TerraTerrarinJob::step_type_normal_lod() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); } @@ -548,7 +549,7 @@ void TerraTerrarinJob::step_type_drop_uv2() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); } @@ -572,7 +573,7 @@ void TerraTerrarinJob::step_type_merge_verts() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); } @@ -608,7 +609,7 @@ void TerraTerrarinJob::step_type_bake_texture() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); } @@ -643,7 +644,7 @@ void TerraTerrarinJob::step_type_simplify_mesh() { Ref lmat; if (chunk->get_library()->supports_caching()) { - lmat = chunk->get_library()->material_lod_cached_get(_current_mesh, _terrain_material_key); + lmat = chunk->get_library()->material_cache_get(_terrain_material_key)->material_lod_get(_current_mesh); } else { lmat = chunk->get_library()->material_lod_get(_current_mesh); }