Skip to content

Commit

Permalink
Fix compiling with GodotCpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Zylann committed Sep 21, 2024
1 parent 29eb5b1 commit 1fcdf60
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions constants/voxel_string_names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ VoxelStringNames::VoxelStringNames() {
async_search_completed = StringName("async_search_completed");

file_selected = StringName("file_selected");

jitter = StringName("jitter");
triangle_area_threshold = StringName("triangle_area_threshold");
density = StringName("density");
noise_dimension = StringName("noise_dimension");
noise_on_scale = StringName("noise_on_scale");
}

} // namespace zylann::voxel
6 changes: 6 additions & 0 deletions constants/voxel_string_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ class VoxelStringNames {
StringName async_search_completed;

StringName file_selected;

StringName jitter;
StringName triangle_area_threshold;
StringName density;
StringName noise_dimension;
StringName noise_on_scale;
};

} // namespace zylann::voxel
Expand Down
15 changes: 10 additions & 5 deletions terrain/instancing/voxel_instance_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,34 +974,39 @@ void VoxelInstanceGenerator::get_configuration_warnings(PackedStringArray &warni
}

void VoxelInstanceGenerator::_validate_property(PropertyInfo &p_property) const {
if (p_property.name == "jitter") {
// In core, `PropertyInfo.name` is a String so `operator == "literal"` works.
// But in GodotCpp, it is a StringName, which does not have such operator.
// So I had to use StringNames to make the code compile in both scenarios without hurting performance.
const VoxelStringNames &sn = VoxelStringNames::get_singleton();

if (p_property.name == sn.jitter) {
if (_emit_mode != EMIT_ONE_PER_TRIANGLE) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
return;
}

if (p_property.name == "triangle_area_threshold") {
if (p_property.name == sn.triangle_area_threshold) {
if (_emit_mode != EMIT_FROM_FACES && _emit_mode != EMIT_ONE_PER_TRIANGLE) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
return;
}

if (p_property.name == "density") {
if (p_property.name == sn.density) {
if (_emit_mode == EMIT_ONE_PER_TRIANGLE) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
}
return;
}

if (_noise.is_null() && _noise_graph.is_null()) {
if (p_property.name == "noise_dimension") {
if (p_property.name == sn.noise_dimension) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
return;
}

if (p_property.name == "noise_on_scale") {
if (p_property.name == sn.noise_on_scale) {
p_property.usage = PROPERTY_USAGE_NO_EDITOR;
return;
}
Expand Down

0 comments on commit 1fcdf60

Please sign in to comment.