feat: removed practically unneeded properties

This commit is contained in:
Sara Gerretsen 2026-02-26 20:24:25 +01:00
parent 2efd3d2ddf
commit 65bf506f0b
3 changed files with 43 additions and 106 deletions

View file

@ -6,7 +6,6 @@
#include <algorithm>
void TerrainModifier::_bind_methods() {
BIND_HPROPERTY(Variant::INT, blend_mode, PROPERTY_HINT_ENUM, BlendMode_hint());
BIND_PROPERTY(Variant::FLOAT, blend_distance);
}
@ -35,22 +34,10 @@ float TerrainModifier::blend(float under, float over) {
: this->blend_distance * 0.25f - distance / this->blend_distance
};
if (center_distance < 0.f) {
if (this->blend_mode == Override) {
return over;
} else if (this->blend_mode == Add) {
return under > over ? under : over;
} else {
return under > over ? over : under;
}
return over;
}
float const smooth_center_distance{ center_distance * center_distance };
if (this->blend_mode == Override) {
return over + smooth_center_distance;
} else {
return (this->blend_mode == Add
? (under > over ? under : over) + smooth_center_distance
: (under > over ? over : under) - smooth_center_distance);
}
return over + smooth_center_distance;
}
void TerrainModifier::push_changed(Rect2 area) {
@ -77,14 +64,6 @@ float TerrainModifier::get_blend_distance() const {
return this->blend_distance;
}
void TerrainModifier::set_blend_mode(BlendMode mode) {
this->blend_mode = mode;
}
TerrainModifier::BlendMode TerrainModifier::get_blend_mode() const {
return this->blend_mode;
}
void SharedMutex::lock_shared() {
this->lock.lock();
this->shared_count++;
@ -113,14 +92,10 @@ void SharedMutex::unlock_exclusive() {
void TerrainModifierDistance::_bind_methods() {
BIND_HPROPERTY(Variant::OBJECT, distance_weight_curve, PROPERTY_HINT_RESOURCE_TYPE, "Curve");
BIND_HPROPERTY(Variant::OBJECT, distance_height_curve, PROPERTY_HINT_RESOURCE_TYPE, "Curve");
}
void TerrainModifierDistance::curves_changed() {
this->lock.lock_exclusive();
if (this->distance_height_curve.is_valid()) {
this->distance_height_curve->bake();
}
if (this->distance_weight_curve.is_valid()) {
this->distance_weight_curve->bake();
}
@ -180,7 +155,7 @@ float TerrainModifierDistance::distance_at(Vector2 const &world_coordinate) {
float TerrainModifierDistance::evaluate_at(Vector2 world_coordinate, float before) {
this->lock.lock_shared();
if (this->distance_weight_curve.is_null() || this->distance_height_curve.is_null()) {
if (this->distance_weight_curve.is_null()) {
this->lock.unlock_shared();
return before;
}
@ -192,18 +167,14 @@ float TerrainModifierDistance::evaluate_at(Vector2 world_coordinate, float befor
float const weight_offset{
std::clamp(distance, this->distance_weight_curve->get_min_domain(), this->distance_weight_curve->get_max_domain())
};
float const height_offset{
std::clamp(distance, this->distance_height_curve->get_min_domain(), this->distance_height_curve->get_max_domain())
};
this->lock.unlock_shared();
this->lock.lock_exclusive();
float const weight{ this->distance_weight_curve->sample_baked(weight_offset) };
float const height{ this->distance_height_curve->sample_baked(height_offset) };
this->lock.unlock_exclusive();
this->lock.lock_shared();
float out{ weight <= 0.f ? before : Math::lerp(before, blend(before, height + get_thread_safe_global_position().y), weight) };
float out{ weight <= 0.f ? before : Math::lerp(before, blend(before, get_thread_safe_global_position().y), weight) };
this->lock.unlock_shared();
return out;
@ -214,9 +185,6 @@ PackedStringArray TerrainModifierDistance::get_configuration_warnings() const {
if (this->distance_weight_curve.is_null()) {
warnings.push_back("distance_weight_curve is invalid, add a valid distance_weight_curve");
}
if (this->distance_height_curve.is_null()) {
warnings.push_back("distance_height_curve is invalid, add a valid distance_height_curve");
}
return warnings;
}
@ -239,23 +207,3 @@ void TerrainModifierDistance::set_distance_weight_curve(Ref<Curve> curve) {
Ref<Curve> TerrainModifierDistance::get_distance_weight_curve() const {
return this->distance_weight_curve;
}
void TerrainModifierDistance::set_distance_height_curve(Ref<Curve> curve) {
this->lock.lock_exclusive();
if (Engine::get_singleton()->is_editor_hint()) {
if (this->distance_height_curve.is_valid()) {
this->distance_height_curve->disconnect_changed(callable_mp(this, &self_type::curves_changed));
}
if (curve.is_valid()) {
curve->connect_changed(callable_mp(this, &self_type::curves_changed));
}
}
this->distance_height_curve = curve;
this->lock.unlock_exclusive();
curves_changed();
update_configuration_warnings();
}
Ref<Curve> TerrainModifierDistance::get_distance_height_curve() const {
return this->distance_height_curve;
}