[Bf-blender-cvs] [6069ff45c7b] temp-enum-socket: add more enum storage

Jacques Lucke noreply at git.blender.org
Mon Nov 8 16:07:02 CET 2021


Commit: 6069ff45c7b0b916e088a1e5a5356f31adafb97a
Author: Jacques Lucke
Date:   Sat Nov 6 17:12:38 2021 +0100
Branches: temp-enum-socket
https://developer.blender.org/rB6069ff45c7b0b916e088a1e5a5356f31adafb97a

add more enum storage

===================================================================

M	source/blender/blenkernel/intern/node.cc
M	source/blender/makesdna/DNA_node_types.h
M	source/blender/makesrna/intern/rna_nodetree.c
M	source/blender/nodes/function/nodes/node_fn_enum.cc

===================================================================

diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc
index 43d3b29c9e8..0b4bcc5740f 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -627,6 +627,14 @@ void ntreeBlendWrite(BlendWriter *writer, bNodeTree *ntree)
       else if (node->typeinfo != &NodeTypeUndefined) {
         BLO_write_struct_by_name(writer, node->typeinfo->storagename, node->storage);
       }
+      else if (node->type == FN_NODE_ENUM) {
+        NodeFunctionEnum *storage = (NodeFunctionEnum *)node->storage;
+        BLO_write_struct_list(writer, NodeFunctionEnumItem, &storage->items);
+        LISTBASE_FOREACH (NodeFunctionEnumItem *, item, &storage->items) {
+          BLO_write_string(writer, item->name);
+          BLO_write_string(writer, item->description);
+        }
+      }
     }
 
     if (node->type == CMP_NODE_OUTPUT_FILE) {
@@ -804,6 +812,16 @@ void ntreeBlendReadData(BlendDataReader *reader, bNodeTree *ntree)
           BLO_read_data_address(reader, &storage->string);
           break;
         }
+        case FN_NODE_ENUM: {
+          NodeFunctionEnum *storage = (NodeFunctionEnum *)node->storage;
+          BLO_read_list(reader, &storage->items);
+          LISTBASE_FOREACH (NodeFunctionEnumItem *, item, &storage->items) {
+            BLO_read_data_address(reader, &item->owner);
+            BLO_read_data_address(reader, &item->name);
+            BLO_read_data_address(reader, &item->description);
+          }
+          break;
+        }
         default:
           break;
       }
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 24796616b61..69b5004dda8 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -1600,8 +1600,17 @@ typedef struct NodeGeometryViewer {
   int8_t data_type;
 } NodeGeometryViewer;
 
+typedef struct NodeFunctionEnumItem {
+  bNode *owner;
+  int value;
+  char _pad[4];
+  char *name;
+  char *description;
+} NodeFunctionEnumItem;
+
 typedef struct NodeFunctionEnum {
-  int some_value;
+  /** NodeFunctionEnumItem. */
+  ListBase items;
 } NodeFunctionEnum;
 
 /* script node mode */
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index b5efde8e8f0..9ecfec54e07 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -5072,10 +5072,10 @@ static void def_fn_enum(StructRNA *srna)
 
   RNA_def_struct_sdna_from(srna, "NodeFunctionEnum", "storage");
 
-  prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
-  RNA_def_property_int_sdna(prop, NULL, "some_value");
-  RNA_def_property_ui_text(prop, "Integer", "Input value used for unconnected socket");
-  RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
+  // prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
+  // RNA_def_property_int_sdna(prop, NULL, "some_value");
+  // RNA_def_property_ui_text(prop, "Integer", "Input value used for unconnected socket");
+  // RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
 }
 
 /* -- Shader Nodes ---------------------------------------------------------- */
diff --git a/source/blender/nodes/function/nodes/node_fn_enum.cc b/source/blender/nodes/function/nodes/node_fn_enum.cc
index 67d245e9b65..4c424ba1fd3 100644
--- a/source/blender/nodes/function/nodes/node_fn_enum.cc
+++ b/source/blender/nodes/function/nodes/node_fn_enum.cc
@@ -38,9 +38,10 @@ static void fn_node_enum_init(bNodeTree *UNUSED(tree), bNode *node)
   node->storage = data;
 }
 
-static void fn_node_enum_layout(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
+static void fn_node_enum_layout(uiLayout *UNUSED(layout),
+                                bContext *UNUSED(C),
+                                PointerRNA *UNUSED(ptr))
 {
-  uiItemR(layout, ptr, "value", 0, "", ICON_NONE);
 }
 
 static const fn::MultiFunction *get_multi_function(bNode &UNUSED(bnode))
@@ -54,6 +55,32 @@ static void fn_node_enum_build_multi_function(NodeMultiFunctionBuilder &builder)
   builder.set_matching_fn(fn);
 }
 
+static void fn_node_enum_copy_storage(bNodeTree *UNUSED(dest_ntree),
+                                      bNode *dst_node,
+                                      const bNode *src_node)
+{
+  const NodeFunctionEnum *src_storage = (const NodeFunctionEnum *)src_node->storage;
+  NodeFunctionEnum *dst_storage = (NodeFunctionEnum *)MEM_dupallocN(src_storage);
+  BLI_listbase_clear(&dst_storage->items);
+  LISTBASE_FOREACH (const NodeFunctionEnumItem *, src_item, &src_storage->items) {
+    NodeFunctionEnumItem *dst_item = (NodeFunctionEnumItem *)MEM_dupallocN(src_item);
+    dst_item->owner = dst_node;
+    dst_item->name = (char *)MEM_dupallocN(src_item->name);
+    dst_item->description = (char *)MEM_dupallocN(src_item->description);
+    BLI_addtail(&dst_storage->items, dst_item);
+  }
+  dst_node->storage = dst_storage;
+}
+
+static void fn_node_enum_free_storage(bNode *node)
+{
+  NodeFunctionEnum *storage = (NodeFunctionEnum *)node->storage;
+  LISTBASE_FOREACH_MUTABLE (NodeFunctionEnumItem *, item, &storage->items) {
+    MEM_freeN(item);
+  }
+  MEM_freeN(storage);
+}
+
 }  // namespace blender::nodes
 
 void register_node_type_fn_enum()
@@ -61,8 +88,10 @@ void register_node_type_fn_enum()
   static bNodeType ntype;
 
   fn_node_type_base(&ntype, FN_NODE_ENUM, "Enum", NODE_CLASS_SCRIPT, 0);
-  node_type_storage(
-      &ntype, "NodeFunctionEnum", node_free_standard_storage, node_copy_standard_storage);
+  node_type_storage(&ntype,
+                    "NodeFunctionEnum",
+                    blender::nodes::fn_node_enum_free_storage,
+                    blender::nodes::fn_node_enum_copy_storage);
   node_type_init(&ntype, blender::nodes::fn_node_enum_init);
   ntype.declare = blender::nodes::fn_node_enum_declare;
   ntype.build_multi_function = blender::nodes::fn_node_enum_build_multi_function;



More information about the Bf-blender-cvs mailing list