Skip to content

Commit

Permalink
Workaround shadowing warnings introduced in godot#76946
Browse files Browse the repository at this point in the history
The huge majority of them are shadowings raised by MSVC between local
variables and PRIVATE member variables from parent classes.
  • Loading branch information
Zylann committed Jun 2, 2023
1 parent 50a4287 commit ffcafd9
Show file tree
Hide file tree
Showing 29 changed files with 179 additions and 174 deletions.
24 changes: 12 additions & 12 deletions editor/graph/voxel_graph_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,11 @@ void VoxelGraphEditor::build_gui_from_graph() {

// Connections

std::vector<ProgramGraph::Connection> connections;
graph.get_connections(connections);
std::vector<ProgramGraph::Connection> all_connections;
graph.get_connections(all_connections);

for (size_t i = 0; i < connections.size(); ++i) {
const ProgramGraph::Connection &con = connections[i];
for (size_t i = 0; i < all_connections.size(); ++i) {
const ProgramGraph::Connection &con = all_connections[i];
const String from_node_name = node_to_gui_name(con.src.node_id);
const String to_node_name = node_to_gui_name(con.dst.node_id);
VoxelGraphEditorNode *to_node_view = get_node_typed<VoxelGraphEditorNode>(*_graph_edit, NodePath(to_node_name));
Expand Down Expand Up @@ -554,11 +554,11 @@ void VoxelGraphEditor::update_node_layout(uint32_t node_id) {
// Add connections back by reading the graph

// TODO Optimize: the graph stores an adjacency list, we could use that
std::vector<ProgramGraph::Connection> connections;
_graph->get_connections(connections);
std::vector<ProgramGraph::Connection> all_connections;
_graph->get_connections(all_connections);

for (size_t i = 0; i < connections.size(); ++i) {
const ProgramGraph::Connection &con = connections[i];
for (size_t i = 0; i < all_connections.size(); ++i) {
const ProgramGraph::Connection &con = all_connections[i];

if (con.dst.node_id == node_id) {
graph_edit.connect_node(node_to_gui_name(con.src.node_id), con.src.port_index,
Expand Down Expand Up @@ -703,8 +703,8 @@ void VoxelGraphEditor::_on_graph_edit_delete_nodes_request(Array node_names) {

_undo_redo->create_action(ZN_TTR("Delete Nodes"));

std::vector<ProgramGraph::Connection> connections;
_graph->get_connections(connections);
std::vector<ProgramGraph::Connection> all_connections;
_graph->get_connections(all_connections);

for (size_t i = 0; i < to_erase.size(); ++i) {
const VoxelGraphEditorNode *node_view = to_erase[i];
Expand Down Expand Up @@ -733,8 +733,8 @@ void VoxelGraphEditor::_on_graph_edit_delete_nodes_request(Array node_names) {
_undo_redo->add_undo_method(this, "create_node_gui", node_id);

// Connections undo
for (size_t j = 0; j < connections.size(); ++j) {
const ProgramGraph::Connection &con = connections[j];
for (size_t j = 0; j < all_connections.size(); ++j) {
const ProgramGraph::Connection &con = all_connections[j];

if (con.src.node_id == node_id || con.dst.node_id == node_id) {
_undo_redo->add_undo_method(*_graph, "add_connection", con.src.node_id, con.src.port_index,
Expand Down
7 changes: 5 additions & 2 deletions editor/graph/voxel_graph_editor_io_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ VoxelGraphEditorIODialog::VoxelGraphEditorIODialog() {

get_ok_button()->connect("pressed", ZN_GODOT_CALLABLE_MP(this, VoxelGraphEditorIODialog, _on_ok_pressed));

Button *ok_button = get_ok_button();
ok_button->set_custom_minimum_size(Vector2(100 * EDSCALE, 0));
// Godot devs added more shadowing warnings around may 2023 but with MSVC it prevents us to use local variable names
// that are the same as PRIVATE variables from inherited classes (and Godot does not prefix members)... So sometimes
// have to come up with pointless name differences just to avoid it
Button *ok_button_ptr = get_ok_button();
ok_button_ptr->set_custom_minimum_size(Vector2(100 * EDSCALE, 0));

Button *cancel_button = get_cancel_button();
cancel_button->set_custom_minimum_size(Vector2(100 * EDSCALE, 0));
Expand Down
6 changes: 3 additions & 3 deletions editor/graph/voxel_graph_editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,11 @@ void VoxelGraphEditorNode::clear_range_analysis_tooltips() {
}
}

void VoxelGraphEditorNode::set_profiling_ratio_visible(bool visible) {
if (_profiling_ratio_enabled == visible) {
void VoxelGraphEditorNode::set_profiling_ratio_visible(bool p_visible) {
if (_profiling_ratio_enabled == p_visible) {
return;
}
_profiling_ratio_enabled = visible;
_profiling_ratio_enabled = p_visible;
queue_redraw();
}

Expand Down
2 changes: 1 addition & 1 deletion editor/graph/voxel_graph_editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VoxelGraphEditorNode : public GraphNode {
return _preview;
}

void set_profiling_ratio_visible(bool visible);
void set_profiling_ratio_visible(bool p_visible);
void set_profiling_ratio(float ratio);

private:
Expand Down
10 changes: 5 additions & 5 deletions editor/graph/voxel_range_analysis_dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ VoxelRangeAnalysisDialog::VoxelRangeAnalysisDialog() {

AABB VoxelRangeAnalysisDialog::get_aabb() const {
const Vector3 center(_pos_x_spinbox->get_value(), _pos_y_spinbox->get_value(), _pos_z_spinbox->get_value());
const Vector3 size(_size_x_spinbox->get_value(), _size_y_spinbox->get_value(), _size_z_spinbox->get_value());
return AABB(center - 0.5f * size, size);
const Vector3 aabb_size(_size_x_spinbox->get_value(), _size_y_spinbox->get_value(), _size_z_spinbox->get_value());
return AABB(center - 0.5f * aabb_size, aabb_size);
}

bool VoxelRangeAnalysisDialog::is_analysis_enabled() const {
Expand All @@ -67,16 +67,16 @@ void VoxelRangeAnalysisDialog::_on_area_spinbox_value_changed(float value) {
emit_signal("area_changed");
}

void VoxelRangeAnalysisDialog::add_row(String text, SpinBox *&sb, GridContainer *parent, float defval) {
void VoxelRangeAnalysisDialog::add_row(String text, SpinBox *&sb, GridContainer *container, float defval) {
sb = memnew(SpinBox);
sb->set_min(-99999.f);
sb->set_max(99999.f);
sb->set_value(defval);
sb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
Label *label = memnew(Label);
label->set_text(text);
parent->add_child(label);
parent->add_child(sb);
container->add_child(label);
container->add_child(sb);
sb->connect("value_changed", ZN_GODOT_CALLABLE_MP(this, VoxelRangeAnalysisDialog, _on_area_spinbox_value_changed));
}

Expand Down
2 changes: 1 addition & 1 deletion editor/graph/voxel_range_analysis_dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class VoxelRangeAnalysisDialog : public AcceptDialog {
void _on_enabled_checkbox_toggled(bool enabled);
void _on_area_spinbox_value_changed(float value);

void add_row(String text, SpinBox *&sb, GridContainer *parent, float defval);
void add_row(String text, SpinBox *&sb, GridContainer *container, float defval);

static void _bind_methods();

Expand Down
12 changes: 6 additions & 6 deletions editor/terrain/editor_property_aabb_min_max.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ EditorPropertyAABBMinMax::EditorPropertyAABBMinMax() {

for (unsigned int i = 0; i < _spinboxes.size(); i++) {
if (i == 0) {
Label *label = memnew(Label);
label->set_text("Min");
grid->add_child(label);
Label *min_label = memnew(Label);
min_label->set_text("Min");
grid->add_child(min_label);

} else if (i == 3) {
Label *label = memnew(Label);
label->set_text("Max");
grid->add_child(label);
Label *max_label = memnew(Label);
max_label->set_text("Max");
grid->add_child(max_label);
}

EditorSpinSlider *sb = memnew(EditorSpinSlider);
Expand Down
4 changes: 2 additions & 2 deletions generators/graph/program_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ uint32_t ProgramGraph::Node::find_output_connection(uint32_t output_port_index,
return ProgramGraph::NULL_INDEX;
}

bool ProgramGraph::Node::find_input_port_by_name(std::string_view name, unsigned int &out_i) const {
bool ProgramGraph::Node::find_input_port_by_name(std::string_view port_name, unsigned int &out_i) const {
for (unsigned int i = 0; i < inputs.size(); ++i) {
const ProgramGraph::Port &port = inputs[i];
if (port.dynamic_name == name) {
if (port.dynamic_name == port_name) {
out_i = i;
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion generators/graph/program_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProgramGraph : NonCopyable {
uint32_t find_input_connection(PortLocation src, uint32_t input_port_index) const;
uint32_t find_output_connection(uint32_t output_port_index, PortLocation dst) const;

bool find_input_port_by_name(std::string_view name, unsigned int &out_i) const;
bool find_input_port_by_name(std::string_view port_name, unsigned int &out_i) const;
};

~ProgramGraph();
Expand Down
56 changes: 28 additions & 28 deletions generators/graph/voxel_graph_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ void VoxelGraphFunction::remove_connection(
emit_changed();
}

void VoxelGraphFunction::get_connections(std::vector<ProgramGraph::Connection> &connections) const {
_graph.get_connections(connections);
void VoxelGraphFunction::get_connections(std::vector<ProgramGraph::Connection> &p_connections) const {
_graph.get_connections(p_connections);
}

bool VoxelGraphFunction::try_get_connection_to(
Expand All @@ -380,19 +380,19 @@ bool VoxelGraphFunction::has_node(uint32_t node_id) const {
return _graph.try_get_node(node_id) != nullptr;
}

void VoxelGraphFunction::set_node_name(uint32_t node_id, StringName name) {
void VoxelGraphFunction::set_node_name(uint32_t node_id, StringName p_name) {
ProgramGraph::Node *node = _graph.try_get_node(node_id);
ERR_FAIL_COND_MSG(node == nullptr, "No node was found with the specified ID");
if (node->name == name) {
if (node->name == p_name) {
return;
}
if (name != StringName()) {
const uint32_t existing_node_id = _graph.find_node_by_name(name);
if (p_name != StringName()) {
const uint32_t existing_node_id = _graph.find_node_by_name(p_name);
if (existing_node_id != ProgramGraph::NULL_ID && node_id == existing_node_id) {
ZN_PRINT_ERROR(format("More than one graph node has the name \"{}\"", String(name)));
ZN_PRINT_ERROR(format("More than one graph node has the name \"{}\"", String(p_name)));
}
}
node->name = name;
node->name = p_name;
emit_signal(SIGNAL_NODE_NAME_CHANGED, node_id);
}

Expand All @@ -402,8 +402,8 @@ StringName VoxelGraphFunction::get_node_name(uint32_t node_id) const {
return node->name;
}

uint32_t VoxelGraphFunction::find_node_by_name(StringName name) const {
return _graph.find_node_by_name(name);
uint32_t VoxelGraphFunction::find_node_by_name(StringName p_name) const {
return _graph.find_node_by_name(p_name);
}

void VoxelGraphFunction::set_node_param(uint32_t node_id, uint32_t param_index, Variant value) {
Expand Down Expand Up @@ -477,29 +477,29 @@ inline bool has_duplicate(const PackedStringArray &sa) {
return find_duplicate(Span<const String>(sa.ptr(), sa.size())) != size_t(sa.size());
}

void VoxelGraphFunction::set_expression_node_inputs(uint32_t node_id, PackedStringArray names) {
void VoxelGraphFunction::set_expression_node_inputs(uint32_t node_id, PackedStringArray input_names) {
ProgramGraph::Node *node = _graph.try_get_node(node_id);

// Validate
ERR_FAIL_COND(node == nullptr);
ERR_FAIL_COND(node->type_id != NODE_EXPRESSION);
for (int i = 0; i < names.size(); ++i) {
const String name = names[i];
ERR_FAIL_COND(!name.is_valid_identifier());
for (int i = 0; i < input_names.size(); ++i) {
const String input_name = input_names[i];
ERR_FAIL_COND(!input_name.is_valid_identifier());
}
ERR_FAIL_COND(has_duplicate(names));
ERR_FAIL_COND(has_duplicate(input_names));
for (unsigned int i = 0; i < node->inputs.size(); ++i) {
const ProgramGraph::Port &port = node->inputs[i];
// Sounds annoying if you call this from a script, but this is supposed to be editor functionality for now
ERR_FAIL_COND_MSG(port.connections.size() > 0,
ZN_TTR("Cannot change input ports if connections exist, disconnect them first."));
}

node->inputs.resize(names.size());
node->default_inputs.resize(names.size());
for (int i = 0; i < names.size(); ++i) {
const String name = names[i];
const CharString name_utf8 = name.utf8();
node->inputs.resize(input_names.size());
node->default_inputs.resize(input_names.size());
for (int i = 0; i < input_names.size(); ++i) {
const String input_name = input_names[i];
const CharString name_utf8 = input_name.utf8();
node->inputs[i].dynamic_name = name_utf8.get_data();
}
}
Expand Down Expand Up @@ -1188,37 +1188,37 @@ bool find_port_by_name(Span<const VoxelGraphFunction::Port> ports, const String
}

bool VoxelGraphFunction::get_node_input_index_by_name(
uint32_t node_id, String name, unsigned int &out_input_index) const {
uint32_t node_id, String input_name, unsigned int &out_input_index) const {
const ProgramGraph::Node &node = _graph.get_node(node_id);

if (node.type_id == VoxelGraphFunction::NODE_FUNCTION) {
ZN_ASSERT(node.params.size() >= 1);
Ref<VoxelGraphFunction> func = node.params[0];
if (func.is_valid()) {
return find_port_by_name(func->get_input_definitions(), name, out_input_index);
return find_port_by_name(func->get_input_definitions(), input_name, out_input_index);
}

} else {
for (unsigned int i = 0; i < node.inputs.size(); ++i) {
const std::string &dynamic_name = node.inputs[i].dynamic_name;
if (!dynamic_name.empty() && to_godot(dynamic_name) == name) {
if (!dynamic_name.empty() && to_godot(dynamic_name) == input_name) {
out_input_index = i;
return true;
}
}

const NodeTypeDB &type_db = NodeTypeDB::get_singleton();
return type_db.try_get_input_index_from_name(node.type_id, name, out_input_index);
return type_db.try_get_input_index_from_name(node.type_id, input_name, out_input_index);
}

return false;
}

bool VoxelGraphFunction::get_node_param_index_by_name(
uint32_t node_id, String name, unsigned int &out_param_index) const {
uint32_t node_id, String param_name, unsigned int &out_param_index) const {
const ProgramGraph::Node &node = _graph.get_node(node_id);
const NodeTypeDB &type_db = NodeTypeDB::get_singleton();
return type_db.try_get_param_index_from_name(node.type_id, name, out_param_index);
return type_db.try_get_param_index_from_name(node.type_id, param_name, out_param_index);
}

void VoxelGraphFunction::update_function_nodes(std::vector<ProgramGraph::Connection> *removed_connections) {
Expand Down Expand Up @@ -1264,8 +1264,8 @@ void VoxelGraphFunction::_b_set_node_param_null(int node_id, int param_index) {
set_node_param(node_id, param_index, Variant());
}

void VoxelGraphFunction::_b_set_node_name(int node_id, String name) {
set_node_name(node_id, name);
void VoxelGraphFunction::_b_set_node_name(int node_id, String node_name) {
set_node_name(node_id, node_name);
}

PackedInt32Array to_godot_int32_array(const std::vector<uint32_t> &vec) {
Expand Down
14 changes: 7 additions & 7 deletions generators/graph/voxel_graph_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,24 @@ class VoxelGraphFunction : public Resource {
void add_connection(uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
void remove_connection(
uint32_t src_node_id, uint32_t src_port_index, uint32_t dst_node_id, uint32_t dst_port_index);
void get_connections(std::vector<ProgramGraph::Connection> &connections) const;
void get_connections(std::vector<ProgramGraph::Connection> &p_connections) const;

// Finds which source port is connected to the given destination.
// Returns false if `dst` has no inbound connection.
bool try_get_connection_to(ProgramGraph::PortLocation dst, ProgramGraph::PortLocation &out_src) const;

bool has_node(uint32_t node_id) const;

void set_node_name(uint32_t node_id, StringName name);
void set_node_name(uint32_t node_id, StringName p_name);
StringName get_node_name(uint32_t node_id) const;
uint32_t find_node_by_name(StringName name) const;
uint32_t find_node_by_name(StringName p_name) const;

Variant get_node_param(uint32_t node_id, uint32_t param_index) const;
void set_node_param(uint32_t node_id, uint32_t param_index, Variant value);

static bool get_expression_variables(std::string_view code, std::vector<std::string_view> &vars);
void get_expression_node_inputs(uint32_t node_id, std::vector<std::string> &out_names) const;
void set_expression_node_inputs(uint32_t node_id, PackedStringArray names);
void set_expression_node_inputs(uint32_t node_id, PackedStringArray input_names);

Variant get_node_default_input(uint32_t node_id, uint32_t input_index) const;
void set_node_default_input(uint32_t node_id, uint32_t input_index, Variant value);
Expand Down Expand Up @@ -213,8 +213,8 @@ class VoxelGraphFunction : public Resource {
bool contains_reference_to_function(const VoxelGraphFunction &p_func, int max_recursion = 16) const;
void auto_pick_inputs_and_outputs();

bool get_node_input_index_by_name(uint32_t node_id, String name, unsigned int &out_input_index) const;
bool get_node_param_index_by_name(uint32_t node_id, String name, unsigned int &out_param_index) const;
bool get_node_input_index_by_name(uint32_t node_id, String input_name, unsigned int &out_input_index) const;
bool get_node_param_index_by_name(uint32_t node_id, String param_name, unsigned int &out_param_index) const;

void update_function_nodes(std::vector<ProgramGraph::Connection> *removed_connections);

Expand All @@ -231,7 +231,7 @@ class VoxelGraphFunction : public Resource {
// TODO Only exists because the UndoRedo API is confusing `null` with `absence of argument`...
// See https://github.com/godotengine/godot/issues/36895
void _b_set_node_param_null(int node_id, int param_index);
void _b_set_node_name(int node_id, String name);
void _b_set_node_name(int node_id, String node_name);

Array _b_get_input_definitions() const;
void _b_set_input_definitions(Array data);
Expand Down
Loading

0 comments on commit ffcafd9

Please sign in to comment.