diff options
author | Jacques Lucke <jacques@blender.org> | 2021-06-28 14:13:52 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-06-28 14:16:32 +0300 |
commit | 7d281a4f7d354d270fc9c9f3c7a65b4409362aa0 (patch) | |
tree | 6a749a4833bdf543a10d95881fcca52ba310248b /source/blender/modifiers | |
parent | f7e2559fd649610881b1749b6d30cc2ba9fcbdb6 (diff) |
Functions: improve CPPType
* Reduce code duplication.
* Give methods more standardized names (e.g. `move_to_initialized` -> `move_assign`).
* Support wrapping arbitrary C++ types, even those that e.g. are not copyable.
Diffstat (limited to 'source/blender/modifiers')
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes.cc | 2 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_nodes_evaluator.cc | 26 |
2 files changed, 18 insertions, 10 deletions
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc b/source/blender/modifiers/intern/MOD_nodes.cc index 5daecef1946..d776adeff75 100644 --- a/source/blender/modifiers/intern/MOD_nodes.cc +++ b/source/blender/modifiers/intern/MOD_nodes.cc @@ -714,7 +714,7 @@ static void initialize_group_input(NodesModifierData &nmd, { const SocketPropertyType *property_type = get_socket_property_type(socket); if (property_type == nullptr) { - cpp_type.copy_to_uninitialized(cpp_type.default_value(), r_value); + cpp_type.copy_construct(cpp_type.default_value(), r_value); return; } if (nmd.settings.properties == nullptr) { diff --git a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc index 980607db839..8314a443ba6 100644 --- a/source/blender/modifiers/intern/MOD_nodes_evaluator.cc +++ b/source/blender/modifiers/intern/MOD_nodes_evaluator.cc @@ -292,14 +292,22 @@ class LockedNode : NonCopyable, NonMovable { } }; -static const CPPType *get_socket_cpp_type(const DSocket socket) +static const CPPType *get_socket_cpp_type(const SocketRef &socket) { - return nodes::socket_cpp_type_get(*socket->typeinfo()); + const CPPType *type = nodes::socket_cpp_type_get(*socket.typeinfo()); + if (type == nullptr) { + return nullptr; + } + /* The evaluator only supports types that have special member functions. */ + if (!type->has_special_member_functions()) { + return nullptr; + } + return type; } -static const CPPType *get_socket_cpp_type(const SocketRef &socket) +static const CPPType *get_socket_cpp_type(const DSocket socket) { - return nodes::socket_cpp_type_get(*socket.typeinfo()); + return get_socket_cpp_type(*socket.socket_ref()); } static bool node_supports_laziness(const DNode node) @@ -888,7 +896,7 @@ class GeometryNodesEvaluator { OutputState &output_state = node_state.outputs[socket->index()]; output_state.has_been_computed = true; void *buffer = allocator.allocate(type->size(), type->alignment()); - type->copy_to_uninitialized(type->default_value(), buffer); + type->copy_construct(type->default_value(), buffer); this->forward_output({node.context(), socket}, {*type, buffer}); } } @@ -967,7 +975,7 @@ class GeometryNodesEvaluator { /* Move value into memory owned by the outer allocator. */ const CPPType &type = *input_state.type; void *buffer = outer_allocator_.allocate(type.size(), type.alignment()); - type.move_to_uninitialized(value, buffer); + type.move_construct(value, buffer); params_.r_output_values.append({type, buffer}); } @@ -1204,7 +1212,7 @@ class GeometryNodesEvaluator { } else { /* Cannot convert, use default value instead. */ - to_type.copy_to_uninitialized(to_type.default_value(), buffer); + to_type.copy_construct(to_type.default_value(), buffer); } this->add_value_to_input_socket(to_socket, from_socket, {to_type, buffer}); } @@ -1230,7 +1238,7 @@ class GeometryNodesEvaluator { const CPPType &type = *value_to_forward.type(); for (const DInputSocket &to_socket : to_sockets.drop_front(1)) { void *buffer = allocator.allocate(type.size(), type.alignment()); - type.copy_to_uninitialized(value_to_forward.get(), buffer); + type.copy_construct(value_to_forward.get(), buffer); this->add_value_to_input_socket(to_socket, from_socket, {type, buffer}); } /* Forward the original value to one of the targets. */ @@ -1331,7 +1339,7 @@ class GeometryNodesEvaluator { } /* Use a default fallback value when the loaded type is not compatible. */ void *default_buffer = allocator.allocate(required_type.size(), required_type.alignment()); - required_type.copy_to_uninitialized(required_type.default_value(), default_buffer); + required_type.copy_construct(required_type.default_value(), default_buffer); return {required_type, default_buffer}; } |