From 8b418a63c4e5453dc050a07cafc8bd75dfd81d91 Mon Sep 17 00:00:00 2001 From: Omar Emara Date: Thu, 20 Mar 2025 12:19:43 +0200 Subject: [PATCH] Cleanup: Use socket type in single input value operation This patch uses the socket type as opposed to the result type in the switch case that initialize the values of the single input value results, since that makes more sense as we are retrieving the values from the sockets. This also matches the implementation in pixel operations. --- .../intern/input_single_value_operation.cc | 50 ++++++++----------- 1 file changed, 22 insertions(+), 28 deletions(-) diff --git a/source/blender/compositor/intern/input_single_value_operation.cc b/source/blender/compositor/intern/input_single_value_operation.cc index ffd27e0d239..70ed9afbc39 100644 --- a/source/blender/compositor/intern/input_single_value_operation.cc +++ b/source/blender/compositor/intern/input_single_value_operation.cc @@ -5,6 +5,8 @@ #include "BLI_assert.h" #include "BLI_math_vector_types.hh" +#include "DNA_node_types.h" + #include "COM_input_single_value_operation.hh" #include "COM_operation.hh" #include "COM_result.hh" @@ -18,44 +20,36 @@ InputSingleValueOperation::InputSingleValueOperation(Context &context, DInputSoc : Operation(context), input_socket_(input_socket) { const ResultType result_type = get_node_socket_result_type(input_socket_.bsocket()); - Result result = context.create_result(result_type); - - /* The result of an input single value operation is guaranteed to have a single user. */ - result.set_reference_count(1); - - populate_result(result); + this->populate_result(context.create_result(result_type)); } void InputSingleValueOperation::execute() { - /* Allocate a single value for the result. */ - Result &result = get_result(); + Result &result = this->get_result(); result.allocate_single_value(); - const bNodeSocket *bsocket = input_socket_.bsocket(); - - /* Set the value of the result to the default value of the input socket. */ - switch (result.type()) { - case ResultType::Float: - result.set_single_value(bsocket->default_value_typed()->value); + switch (input_socket_->type) { + case SOCK_FLOAT: { + const float value = input_socket_->default_value_typed()->value; + result.set_single_value(value); break; - case ResultType::Int: - result.set_single_value(bsocket->default_value_typed()->value); + } + case SOCK_INT: { + const int value = input_socket_->default_value_typed()->value; + result.set_single_value(value); break; - case ResultType::Float3: - result.set_single_value( - float3(bsocket->default_value_typed()->value)); + } + case SOCK_VECTOR: { + const float3 value = input_socket_->default_value_typed()->value; + result.set_single_value(value); break; - case ResultType::Color: - result.set_single_value(float4(bsocket->default_value_typed()->value)); + } + case SOCK_RGBA: { + const float4 value = input_socket_->default_value_typed()->value; + result.set_single_value(value); break; - case ResultType::Float4: - result.set_single_value( - float4(float3(bsocket->default_value_typed()->value), 0.0f)); - break; - case ResultType::Float2: - case ResultType::Int2: - /* Those types are internal and needn't be handled by operations. */ + } + default: BLI_assert_unreachable(); break; }