From ebc5449101bccce6db4b9fc56a059a5bd611ded3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 24 Feb 2022 00:05:29 +0100 Subject: [PATCH] Port the new getters from props. Also added notes. --- library/terrain_2d_material_cache.cpp | 16 ++++++++++++++++ library/terrain_2d_material_cache.h | 6 ++++++ library/terrain_2d_material_cache_pcm.cpp | 8 ++++++-- library/terrain_2d_material_cache_pcm.h | 3 +++ world/jobs/terrain_2d_terrain_job.cpp | 15 --------------- 5 files changed, 31 insertions(+), 17 deletions(-) diff --git a/library/terrain_2d_material_cache.cpp b/library/terrain_2d_material_cache.cpp index 33e4c38..4a1a926 100644 --- a/library/terrain_2d_material_cache.cpp +++ b/library/terrain_2d_material_cache.cpp @@ -142,10 +142,23 @@ Ref Terrain2DMaterialCache::additional_texture_get_atlas(const int Ref Terrain2DMaterialCache::additional_texture_get_atlas_tex(const Ref &texture) { return Ref(); } +Rect2 Terrain2DMaterialCache::additional_texture_get_rect(const Ref &texture) { + Ref at = additional_texture_get_atlas_tex(texture); + + if (!at.is_valid()) { + return Rect2(); + } + + return at->get_region(); +} Rect2 Terrain2DMaterialCache::additional_texture_get_uv_rect(const Ref &texture) { return Rect2(0, 0, 1, 1); } +Ref Terrain2DMaterialCache::texture_get_merged() { + return Ref(); +} + #ifdef PROPS_2D_PRESENT void Terrain2DMaterialCache::prop_add_textures(const Ref &prop) { if (!prop.is_valid()) { @@ -263,8 +276,11 @@ void Terrain2DMaterialCache::_bind_methods() { ClassDB::bind_method(D_METHOD("additional_texture_get", "index"), &Terrain2DMaterialCache::additional_texture_get); ClassDB::bind_method(D_METHOD("additional_texture_get_atlas", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas); ClassDB::bind_method(D_METHOD("additional_texture_get_atlas_tex", "index"), &Terrain2DMaterialCache::additional_texture_get_atlas_tex); + ClassDB::bind_method(D_METHOD("additional_texture_get_rect", "texture"), &Terrain2DMaterialCache::additional_texture_get_rect); ClassDB::bind_method(D_METHOD("additional_texture_get_uv_rect", "texture"), &Terrain2DMaterialCache::additional_texture_get_uv_rect); + ClassDB::bind_method(D_METHOD("texture_get_merged"), &Terrain2DMaterialCache::texture_get_merged); + #ifdef PROPS_2D_PRESENT ClassDB::bind_method(D_METHOD("prop_add_textures", "prop"), &Terrain2DMaterialCache::prop_add_textures); ClassDB::bind_method(D_METHOD("prop_remove_textures", "prop"), &Terrain2DMaterialCache::prop_remove_textures); diff --git a/library/terrain_2d_material_cache.h b/library/terrain_2d_material_cache.h index e24ed53..2fd6285 100644 --- a/library/terrain_2d_material_cache.h +++ b/library/terrain_2d_material_cache.h @@ -75,8 +75,14 @@ public: virtual Ref additional_texture_get(const int index); virtual Ref additional_texture_get_atlas(const int index); virtual Ref additional_texture_get_atlas_tex(const Ref &texture); + virtual Rect2 additional_texture_get_rect(const Ref &texture); virtual Rect2 additional_texture_get_uv_rect(const Ref &texture); + //todo rename to get texture, and make it a property. + //mergers set it themselves + //Also do it for props + virtual Ref texture_get_merged(); + #ifdef PROPS_2D_PRESENT void prop_add_textures(const Ref &prop); void prop_remove_textures(const Ref &prop); diff --git a/library/terrain_2d_material_cache_pcm.cpp b/library/terrain_2d_material_cache_pcm.cpp index bdc4150..f8e7f02 100644 --- a/library/terrain_2d_material_cache_pcm.cpp +++ b/library/terrain_2d_material_cache_pcm.cpp @@ -141,9 +141,9 @@ void Terrain2DMaterialCachePCM::refresh_rects() { ERR_FAIL_COND(_packer->get_texture_count() == 0); - Ref tex = _packer->get_generated_texture(0); + _merged_texture = _packer->get_generated_texture(0); - setup_material_albedo(tex); + setup_material_albedo(_merged_texture); } for (int i = 0; i < _surfaces.size(); i++) { @@ -157,6 +157,10 @@ void Terrain2DMaterialCachePCM::refresh_rects() { _initialized = true; } +Ref Terrain2DMaterialCachePCM::texture_get_merged() { + return _merged_texture; +} + void Terrain2DMaterialCachePCM::_setup_material_albedo(Ref texture) { Ref m = material_get(); diff --git a/library/terrain_2d_material_cache_pcm.h b/library/terrain_2d_material_cache_pcm.h index cd385bd..2eb607b 100644 --- a/library/terrain_2d_material_cache_pcm.h +++ b/library/terrain_2d_material_cache_pcm.h @@ -70,6 +70,8 @@ public: void refresh_rects(); + Ref texture_get_merged(); + void _setup_material_albedo(Ref texture); Terrain2DMaterialCachePCM(); @@ -79,6 +81,7 @@ protected: static void _bind_methods(); Ref _packer; + Ref _merged_texture; }; #endif diff --git a/world/jobs/terrain_2d_terrain_job.cpp b/world/jobs/terrain_2d_terrain_job.cpp index a291adb..d1d278e 100644 --- a/world/jobs/terrain_2d_terrain_job.cpp +++ b/world/jobs/terrain_2d_terrain_job.cpp @@ -184,12 +184,6 @@ void Terrain2DTerrain2DJob::phase_physics_process() { chunk->colliders_create(Terrain2DChunkDefault::MESH_INDEX_LIQUID); } } - /* - else { - if (!has_meshes(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_AREA)) { - create_colliders_area(MESH_INDEX_LIQUID); - } - }*/ PhysicsServer::get_singleton()->shape_set_data(chunk->mesh_rid_get(Terrain2DChunkDefault::MESH_INDEX_LIQUID, Terrain2DChunkDefault::MESH_TYPE_INDEX_SHAPE), temp_arr_collider_liquid); @@ -211,14 +205,6 @@ void Terrain2DTerrain2DJob::phase_terrain_mesh() { } if ((chunk->get_build_flags() & Terrain2DChunkDefault::BUILD_FLAG_USE_LIGHTING) != 0) { - //if (should_do()) { - // _mesher->bake_colors(_chunk); - - // if (should_return()) { - // return; - // } - //} - if (should_do()) { if (_liquid_mesher.is_valid()) { _liquid_mesher->bake_colors(_chunk); @@ -295,7 +281,6 @@ void Terrain2DTerrain2DJob::phase_terrain_mesh() { } } - // if (should_do()) { VS::get_singleton()->mesh_add_surface_from_arrays(mesh_rid, VisualServer::PRIMITIVE_TRIANGLES, temp_mesh_arr); }