From 193b5dee93b8d02f9663afb2eafb52fdfb6df79d Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 23 Feb 2022 22:05:33 +0100 Subject: [PATCH] More cleanups. --- world/default/terrain_2d_chunk_default.cpp | 123 +-------------------- world/default/terrain_2d_chunk_default.h | 10 -- world/default/terrain_2d_world_default.cpp | 102 ----------------- world/default/terrain_2d_world_default.h | 20 ---- 4 files changed, 2 insertions(+), 253 deletions(-) diff --git a/world/default/terrain_2d_chunk_default.cpp b/world/default/terrain_2d_chunk_default.cpp index d06f8bb..eb1c64d 100644 --- a/world/default/terrain_2d_chunk_default.cpp +++ b/world/default/terrain_2d_chunk_default.cpp @@ -55,48 +55,6 @@ void Terrain2DChunkDefault::set_lights_dirty(const bool value) { _lights_dirty = value; } -int Terrain2DChunkDefault::get_lod_num() const { - return _lod_num; -} -void Terrain2DChunkDefault::set_lod_num(const int value) { - _lod_num = value; -} - -int Terrain2DChunkDefault::get_current_lod_level() const { - return _current_lod_level; -} -void Terrain2DChunkDefault::set_current_lod_level(const int value) { - _current_lod_level = value; - - if ((_build_flags & BUILD_FLAG_CREATE_LODS) == 0) - return; - - if (_current_lod_level < 0) - _current_lod_level = 0; - - int lod_num = mesh_rid_get_count(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE); - - if (_current_lod_level > lod_num) - _current_lod_level = lod_num; - - for (int i = 0; i < lod_num; ++i) { - bool vis = false; - - if (i == _current_lod_level) - vis = true; - - RID rid = mesh_rid_get_index(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE, i); - - if (rid != RID()) - VisualServer::get_singleton()->instance_set_visible(rid, vis); - - rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i); - - if (rid != RID()) - VisualServer::get_singleton()->instance_set_visible(rid, vis); - } -} - void Terrain2DChunkDefault::emit_build_finished() { emit_signal("mesh_generation_finished", this); @@ -302,32 +260,17 @@ void Terrain2DChunkDefault::meshes_create(const int mesh_index, const int mesh_c Dictionary m = _rids[mesh_index]; ERR_FAIL_COND(m.has(MESH_TYPE_INDEX_MESH)); - ERR_FAIL_COND(m.has(MESH_TYPE_INDEX_MESH_INSTANCE)); Array am; Array ami; for (int i = 0; i < mesh_count; ++i) { - RID mesh_instance_rid = VS::get_singleton()->instance_create(); - - //if (get_voxel_world()->get_world_2d().is_valid()) - // VS::get_singleton()->instance_set_scenario(mesh_instance_rid, get_voxel_world()->get_world_2d()->get_scenario()); - RID mesh_rid = VS::get_singleton()->mesh_create(); - VS::get_singleton()->instance_set_base(mesh_instance_rid, mesh_rid); - - //VS::get_singleton()->instance_set_transform(mesh_instance_rid, get_transform()); - - if (i != 0) - VS::get_singleton()->instance_set_visible(mesh_instance_rid, false); - am.push_back(mesh_rid); - ami.push_back(mesh_instance_rid); } m[MESH_TYPE_INDEX_MESH] = am; - m[MESH_TYPE_INDEX_MESH_INSTANCE] = ami; _rids[mesh_index] = m; } @@ -350,20 +293,7 @@ void Terrain2DChunkDefault::meshes_free(const int mesh_index) { } } - if (m.has(MESH_TYPE_INDEX_MESH_INSTANCE)) { - Array a = m[MESH_TYPE_INDEX_MESH_INSTANCE]; - - for (int i = 0; i < a.size(); ++i) { - RID r = a[i]; - - if (r != rid) { - VS::get_singleton()->free(r); - } - } - } - m.erase(MESH_TYPE_INDEX_MESH); - m.erase(MESH_TYPE_INDEX_MESH_INSTANCE); } void Terrain2DChunkDefault::colliders_create(const int mesh_index, const int layer_mask) { @@ -494,17 +424,6 @@ void Terrain2DChunkDefault::update_transforms() { Dictionary d = _rids[v]; - if (d.has(MESH_TYPE_INDEX_MESH_INSTANCE)) { - Array arr = d[MESH_TYPE_INDEX_MESH_INSTANCE]; - - for (int i = 0; i < arr.size(); ++i) { - RID rid = arr[i]; - - // if (rid != empty_rid) - // VS::get_singleton()->instance_set_transform(rid, get_transform()); - } - } - if (d.has(MESH_TYPE_INDEX_BODY)) { RID rid = d[MESH_TYPE_INDEX_BODY]; @@ -712,32 +631,6 @@ void Terrain2DChunkDefault::draw_debug_mdr_colliders() { } } -void Terrain2DChunkDefault::_visibility_changed(bool visible) { - if (visible) { - set_current_lod_level(_current_lod_level); - return; - } - - int lod_num = mesh_rid_get_count(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE); - - for (int i = 0; i < lod_num; ++i) { - RID rid = mesh_rid_get_index(MESH_INDEX_TERRAIN, MESH_TYPE_INDEX_MESH_INSTANCE, i); - - if (rid != RID()) - VisualServer::get_singleton()->instance_set_visible(rid, false); - - rid = mesh_rid_get_index(MESH_INDEX_LIQUID, MESH_TYPE_INDEX_MESH_INSTANCE, i); - - if (rid != RID()) - VisualServer::get_singleton()->instance_set_visible(rid, false); - - rid = mesh_rid_get_index(MESH_INDEX_PROP, MESH_TYPE_INDEX_MESH_INSTANCE, i); - - if (rid != RID()) - VisualServer::get_singleton()->instance_set_visible(rid, false); - } -} - void Terrain2DChunkDefault::_exit_tree() { Terrain2DChunk::_exit_tree(); @@ -856,9 +749,8 @@ void Terrain2DChunkDefault::_finalize_build() { } #endif - set_current_lod_level(get_current_lod_level()); - call_deferred("update_transforms"); + //call_deferred("update"); } Terrain2DChunkDefault::Terrain2DChunkDefault() { @@ -896,14 +788,6 @@ void Terrain2DChunkDefault::_bind_methods() { ClassDB::bind_method(D_METHOD("set_lights_dirty", "value"), &Terrain2DChunkDefault::set_lights_dirty); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "lights_dirty", PROPERTY_HINT_NONE, "", 0), "set_lights_dirty", "get_lights_dirty"); - ClassDB::bind_method(D_METHOD("get_lod_num"), &Terrain2DChunkDefault::get_lod_num); - ClassDB::bind_method(D_METHOD("set_lod_num"), &Terrain2DChunkDefault::set_lod_num); - ADD_PROPERTY(PropertyInfo(Variant::INT, "lod_num", PROPERTY_HINT_NONE, "", 0), "set_lod_num", "get_lod_num"); - - ClassDB::bind_method(D_METHOD("get_current_lod_level"), &Terrain2DChunkDefault::get_current_lod_level); - ClassDB::bind_method(D_METHOD("set_current_lod_level"), &Terrain2DChunkDefault::set_current_lod_level); - ADD_PROPERTY(PropertyInfo(Variant::INT, "current_lod_level"), "set_current_lod_level", "get_current_lod_level"); - //Meshes ClassDB::bind_method(D_METHOD("get_mesh_rids"), &Terrain2DChunkDefault::mesh_rids_get); ClassDB::bind_method(D_METHOD("set_mesh_rids", "rids"), &Terrain2DChunkDefault::mesh_rids_set); @@ -957,9 +841,7 @@ void Terrain2DChunkDefault::_bind_methods() { //virtuals ClassDB::bind_method(D_METHOD("_channel_setup"), &Terrain2DChunkDefault::_channel_setup); - - ClassDB::bind_method(D_METHOD("_visibility_changed", "visible"), &Terrain2DChunkDefault::_visibility_changed); - + //lights ClassDB::bind_method(D_METHOD("_bake_lights"), &Terrain2DChunkDefault::_bake_lights); ClassDB::bind_method(D_METHOD("_bake_light", "light"), &Terrain2DChunkDefault::_bake_light); @@ -985,7 +867,6 @@ void Terrain2DChunkDefault::_bind_methods() { BIND_CONSTANT(MESH_INDEX_CLUTTER); BIND_CONSTANT(MESH_TYPE_INDEX_MESH); - BIND_CONSTANT(MESH_TYPE_INDEX_MESH_INSTANCE); BIND_CONSTANT(MESH_TYPE_INDEX_SHAPE); BIND_CONSTANT(MESH_TYPE_INDEX_BODY); diff --git a/world/default/terrain_2d_chunk_default.h b/world/default/terrain_2d_chunk_default.h index a8c0b8a..f1d3bf3 100644 --- a/world/default/terrain_2d_chunk_default.h +++ b/world/default/terrain_2d_chunk_default.h @@ -82,7 +82,6 @@ public: enum { MESH_TYPE_INDEX_MESH = 0, - MESH_TYPE_INDEX_MESH_INSTANCE, MESH_TYPE_INDEX_SHAPE, MESH_TYPE_INDEX_BODY, MESH_TYPE_INDEX_AREA, @@ -108,13 +107,6 @@ public: bool get_lights_dirty() const; void set_lights_dirty(const bool value); - //Lod - int get_lod_num() const; - void set_lod_num(const int value); - - int get_current_lod_level() const; - void set_current_lod_level(const int value); - //Meshes Dictionary mesh_rids_get(); void mesh_rids_set(const Dictionary &rids); @@ -187,8 +179,6 @@ public: protected: virtual void _channel_setup(); - virtual void _visibility_changed(bool visible); - virtual void _exit_tree(); virtual void _world_transform_changed(); diff --git a/world/default/terrain_2d_world_default.cpp b/world/default/terrain_2d_world_default.cpp index 9db5d25..0a26911 100644 --- a/world/default/terrain_2d_world_default.cpp +++ b/world/default/terrain_2d_world_default.cpp @@ -47,42 +47,6 @@ _FORCE_INLINE_ void Terrain2DWorldDefault::set_build_flags(const int flags) { } } -float Terrain2DWorldDefault::get_lod_update_interval() const { - return _lod_update_interval; -} -void Terrain2DWorldDefault::set_lod_update_interval(const float value) { - _lod_update_interval = value; -} - -int Terrain2DWorldDefault::get_num_lods() const { - return _num_lods; -} -void Terrain2DWorldDefault::set_num_lods(const int value) { - _num_lods = value; -} - -void Terrain2DWorldDefault::update_lods() { - if (!get_active()) { - return; - } - - call("_update_lods"); -} - -int Terrain2DWorldDefault::get_chunk_lod_first_falloff() const { - return _chunk_lod_first_falloff; -} -void Terrain2DWorldDefault::set_chunk_lod_first_falloff(const int value) { - _chunk_lod_first_falloff = value; -} - -int Terrain2DWorldDefault::get_chunk_lod_falloff() const { - return _chunk_lod_falloff; -} -void Terrain2DWorldDefault::set_chunk_lod_falloff(const int value) { - _chunk_lod_falloff = value; -} - PoolColorArray Terrain2DWorldDefault::get_vertex_colors(const Transform &transform, const PoolVector3Array &vertices, const float base_light_value, const float ao_strength) { PoolColorArray arr; arr.resize(vertices.size()); @@ -141,42 +105,6 @@ PoolColorArray Terrain2DWorldDefault::get_vertex_colors(const Transform &transfo return arr; } -void Terrain2DWorldDefault::_update_lods() { - /* - if (!get_player() || !INSTANCE_VALIDATE(get_player())) { - return; - } - - if (_num_lods <= 1) - return; - - Vector2 ppos = get_player()->get_transform().get_origin(); - - int ppx = int(ppos.x / get_chunk_size_x() / get_voxel_scale()); - int ppz = int(ppos.z / get_chunk_size_z() / get_voxel_scale()); - - for (int i = 0; i < chunk_get_count(); ++i) { - Ref c = chunk_get_index(i); - - if (!c.is_valid()) - continue; - - int dx = Math::abs(ppx - c->get_position_x()); - int dz = Math::abs(ppz - c->get_position_z()); - - int mr = MAX(dx, dz); - - mr -= _chunk_lod_first_falloff; - mr /= _chunk_lod_falloff; - - mr = CLAMP(mr, 0, _num_lods - 1); - - if (c->get_current_lod_level() != mr) - c->set_current_lod_level(mr); - } - */ -} - Ref Terrain2DWorldDefault::_create_chunk(int x, int z, Ref chunk) { if (!chunk.is_valid()) { chunk = Ref(memnew(Terrain2DChunkDefault)); @@ -202,7 +130,6 @@ Ref Terrain2DWorldDefault::_create_chunk(int x, int z, Refset_build_flags(_build_flags); - vcd->set_lod_num(_num_lods); } return Terrain2DWorld::_create_chunk(x, z, chunk); @@ -230,12 +157,7 @@ int Terrain2DWorldDefault::_get_channel_index_info(const Terrain2DWorld::Channel } Terrain2DWorldDefault::Terrain2DWorldDefault() { - _chunk_lod_first_falloff = 2; - _chunk_lod_falloff = 2; - _lod_update_timer = 0; - _lod_update_interval = 0.5; _build_flags = Terrain2DChunkDefault::BUILD_FLAG_CREATE_COLLIDER | Terrain2DChunkDefault::BUILD_FLAG_CREATE_LODS; - _num_lods = 4; set_data_margin_start(1); set_data_margin_end(1); @@ -263,10 +185,6 @@ void Terrain2DWorldDefault::_notification(int p_what) { } } - if (active) { - update_lods(); - } - break; } } @@ -308,25 +226,5 @@ void Terrain2DWorldDefault::_bind_methods() { ClassDB::bind_method(D_METHOD("set_build_flags", "value"), &Terrain2DWorldDefault::set_build_flags); ADD_PROPERTY(PropertyInfo(Variant::INT, "build_flags", PROPERTY_HINT_FLAGS, Terrain2DChunkDefault::BINDING_STRING_BUILD_FLAGS), "set_build_flags", "get_build_flags"); - ClassDB::bind_method(D_METHOD("get_lod_update_interval"), &Terrain2DWorldDefault::get_lod_update_interval); - ClassDB::bind_method(D_METHOD("set_lod_update_interval", "value"), &Terrain2DWorldDefault::set_lod_update_interval); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "lod_update_interval"), "set_lod_update_interval", "get_lod_update_interval"); - - ClassDB::bind_method(D_METHOD("get_chunk_lod_first_falloff"), &Terrain2DWorldDefault::get_chunk_lod_first_falloff); - ClassDB::bind_method(D_METHOD("set_chunk_lod_first_falloff", "value"), &Terrain2DWorldDefault::set_chunk_lod_first_falloff); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_lod_first_falloff"), "set_chunk_lod_first_falloff", "get_chunk_lod_first_falloff"); - - ClassDB::bind_method(D_METHOD("get_chunk_lod_falloff"), &Terrain2DWorldDefault::get_chunk_lod_falloff); - ClassDB::bind_method(D_METHOD("set_chunk_lod_falloff", "value"), &Terrain2DWorldDefault::set_chunk_lod_falloff); - ADD_PROPERTY(PropertyInfo(Variant::INT, "chunk_lod_falloff"), "set_chunk_lod_falloff", "get_chunk_lod_falloff"); - - ClassDB::bind_method(D_METHOD("get_num_lods"), &Terrain2DWorldDefault::get_num_lods); - ClassDB::bind_method(D_METHOD("set_num_lods", "value"), &Terrain2DWorldDefault::set_num_lods); - ADD_PROPERTY(PropertyInfo(Variant::INT, "num_lods"), "set_num_lods", "get_num_lods"); - - BIND_VMETHOD(MethodInfo("_update_lods")); - ClassDB::bind_method(D_METHOD("update_lods"), &Terrain2DWorldDefault::update_lods); - ClassDB::bind_method(D_METHOD("_update_lods"), &Terrain2DWorldDefault::_update_lods); - ClassDB::bind_method(D_METHOD("get_vertex_colors", "transform", "vertices", "base_light_value", "ao_strength"), &Terrain2DWorldDefault::get_vertex_colors, DEFVAL(0.45), DEFVAL(0.2)); } \ No newline at end of file diff --git a/world/default/terrain_2d_world_default.h b/world/default/terrain_2d_world_default.h index 479eb51..866d66d 100644 --- a/world/default/terrain_2d_world_default.h +++ b/world/default/terrain_2d_world_default.h @@ -32,20 +32,6 @@ public: int get_build_flags() const; void set_build_flags(const int flags); - float get_lod_update_interval() const; - void set_lod_update_interval(const float value); - - int get_chunk_lod_first_falloff() const; - void set_chunk_lod_first_falloff(const int value); - - int get_chunk_lod_falloff() const; - void set_chunk_lod_falloff(const int value); - - int get_num_lods() const; - void set_num_lods(const int value); - - void update_lods(); - PoolColorArray get_vertex_colors(const Transform &transform, const PoolVector3Array &vertices, const float base_light_value = 0.45, const float ao_strength = 0.2); Terrain2DWorldDefault(); @@ -53,7 +39,6 @@ public: protected: void _notification(int p_what); - void _update_lods(); Ref _create_chunk(int x, int z, Ref p_chunk); virtual void _chunk_added(Ref chunk); int _get_channel_index_info(const ChannelTypeInfo channel_type); @@ -64,11 +49,6 @@ protected: private: int _build_flags; - float _lod_update_timer; - float _lod_update_interval; - int _chunk_lod_first_falloff; - int _chunk_lod_falloff; - int _num_lods; }; #endif