From c6f85d7a8dce7b39cb7cb895a7dd918fe3bcb05a Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 10 Nov 2021 11:47:36 +0100 Subject: improve handling of incompatible enums --- source/blender/blenkernel/intern/node.cc | 30 ++++++++++++++++++++++--- source/blender/editors/space_node/drawnode.cc | 6 +++++ source/blender/makesdna/DNA_node_types.h | 3 ++- source/blender/nodes/NOD_socket_declarations.hh | 2 ++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index 0e23992432f..4522dca9519 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -5138,8 +5138,23 @@ static EnumInputInferencingInfo get_input_enum_socket_inferencing_info( struct EnumState { std::shared_ptr items; int group_output_index = -1; + bool targets_are_invalid = false; }; +static bool enum_states_are_compatible(const EnumState &a, const EnumState &b) +{ + if (a.items && b.items) { + return a.items->items() == b.items->items(); + } + if (a.group_output_index == -1 || b.group_output_index == -1) { + return true; + } + if (a.group_output_index == b.group_output_index) { + return true; + } + return false; +} + static bool update_enum_inferencing(const NodeTreeRef &tree) { using namespace blender::nodes; @@ -5169,12 +5184,19 @@ static bool update_enum_inferencing(const NodeTreeRef &tree) if (socket->typeinfo()->type != SOCK_ENUM) { continue; } - /* TODO: Handle case when connected to incompatible enums. */ EnumState enum_state; for (const InputSocketRef *target_socket : socket->directly_linked_sockets()) { if (target_socket->is_available()) { - enum_state = state_by_socket.lookup_default(target_socket, {}); - break; + EnumState new_state = state_by_socket.lookup_default(target_socket, {}); + if (enum_states_are_compatible(enum_state, new_state)) { + enum_state = new_state; + enum_state.targets_are_invalid = false; + } + else { + enum_state = {}; + enum_state.targets_are_invalid = true; + break; + } } } state_by_socket.add_new(socket, enum_state); @@ -5202,6 +5224,7 @@ static bool update_enum_inferencing(const NodeTreeRef &tree) BLI_assert(inference_index >= 0); const OutputSocketRef &output_socket = node->output(inference_index); input_state = state_by_socket.lookup(&output_socket); + input_state.targets_are_invalid = false; } state_by_socket.add_new(socket, input_state); } @@ -5217,6 +5240,7 @@ static bool update_enum_inferencing(const NodeTreeRef &tree) else { socket_value->items = nullptr; } + socket_value->targets_are_invalid = state.targets_are_invalid; } EnumInferencingInterface *new_inferencing_interface = new EnumInferencingInterface(); diff --git a/source/blender/editors/space_node/drawnode.cc b/source/blender/editors/space_node/drawnode.cc index 6554dc699ac..104f48cda0a 100644 --- a/source/blender/editors/space_node/drawnode.cc +++ b/source/blender/editors/space_node/drawnode.cc @@ -4450,6 +4450,12 @@ void node_draw_link(const bContext *C, View2D *v2d, SpaceNode *snode, bNodeLink th_col1 = th_col2 = th_col3 = TH_REDALERT; } } + if (link->fromsock && link->fromsock->type == SOCK_ENUM) { + bNodeSocketValueEnum *socket_value = (bNodeSocketValueEnum *)link->fromsock->default_value; + if (socket_value->targets_are_invalid) { + th_col1 = th_col2 = th_col3 = TH_REDALERT; + } + } node_draw_link_bezier(C, v2d, snode, link, th_col1, th_col2, th_col3); } diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h index e2d55f006f4..bf4a54f904a 100644 --- a/source/blender/makesdna/DNA_node_types.h +++ b/source/blender/makesdna/DNA_node_types.h @@ -687,7 +687,8 @@ typedef struct bNodeSocketValueMaterial { /* TODO: Add something to help with versioning for built-in enums. */ typedef struct bNodeSocketValueEnum { int value; - char _pad[4]; + char targets_are_invalid; + char _pad[3]; /** * Possible items for the enum. This is only runtime data and is not owned by the socket. */ diff --git a/source/blender/nodes/NOD_socket_declarations.hh b/source/blender/nodes/NOD_socket_declarations.hh index f6a4af397ba..ac9fc0c1adb 100644 --- a/source/blender/nodes/NOD_socket_declarations.hh +++ b/source/blender/nodes/NOD_socket_declarations.hh @@ -16,6 +16,8 @@ #pragma once +#include + #include "NOD_node_declaration.hh" #include "RNA_types.h" -- cgit v1.2.3