[Bf-blender-cvs] [ad6fa163047] functions: use more debug time checks
Jacques Lucke
noreply at git.blender.org
Mon Jul 15 18:12:58 CEST 2019
Commit: ad6fa16304783f11931ab11bc3932d30bc66c2e2
Author: Jacques Lucke
Date: Mon Jul 15 17:19:02 2019 +0200
Branches: functions
https://developer.blender.org/rBad6fa16304783f11931ab11bc3932d30bc66c2e2
use more debug time checks
===================================================================
M release/scripts/startup/nodes/function_nodes/random_number.py
M source/blender/functions/backends/tuple_call/tuple_call.hpp
M source/blender/functions/functions/random.cpp
===================================================================
diff --git a/release/scripts/startup/nodes/function_nodes/random_number.py b/release/scripts/startup/nodes/function_nodes/random_number.py
index ae5088a5ae2..74c7a2a37f2 100644
--- a/release/scripts/startup/nodes/function_nodes/random_number.py
+++ b/release/scripts/startup/nodes/function_nodes/random_number.py
@@ -8,5 +8,5 @@ class RandomNumberNode(bpy.types.Node, FunctionNode):
def declaration(self, builder):
builder.fixed_input("seed", "Seed", "Float")
builder.fixed_input("min", "Min", "Float")
- builder.fixed_input("max", "Max", "Float")
+ builder.fixed_input("max", "Max", "Float", default=1.0)
builder.fixed_output("value", "Value", "Float")
diff --git a/source/blender/functions/backends/tuple_call/tuple_call.hpp b/source/blender/functions/backends/tuple_call/tuple_call.hpp
index 4397c644c31..28b630b514c 100644
--- a/source/blender/functions/backends/tuple_call/tuple_call.hpp
+++ b/source/blender/functions/backends/tuple_call/tuple_call.hpp
@@ -43,7 +43,16 @@ class TupleCallBodyBase : public FunctionBody {
/**
* Same as tuple.get<T>(index), but checks if the name is correct in debug builds.
*/
- template<typename T> T get_output(Tuple &tuple, uint index, StringRef expected_name)
+ template<typename T> T get_input(Tuple &tuple, uint index, StringRef expected_name) const
+ {
+#ifdef DEBUG
+ StringRef real_name = this->owner()->input_name(index);
+ BLI_assert(real_name == expected_name);
+#endif
+ UNUSED_VARS_NDEBUG(expected_name);
+ return tuple.get<T>(index);
+ }
+ template<typename T> T get_output(Tuple &tuple, uint index, StringRef expected_name) const
{
#ifdef DEBUG
StringRef real_name = this->owner()->output_name(index);
@@ -52,6 +61,16 @@ class TupleCallBodyBase : public FunctionBody {
UNUSED_VARS_NDEBUG(expected_name);
return tuple.get<T>(index);
}
+ template<typename T>
+ void set_output(Tuple &tuple, uint index, StringRef expected_name, const T &value) const
+ {
+#ifdef DEBUG
+ StringRef real_name = this->owner()->output_name(index);
+ BLI_assert(real_name == expected_name);
+#endif
+ UNUSED_VARS_NDEBUG(expected_name);
+ tuple.set<T>(index, value);
+ }
};
class TupleCallBody : public TupleCallBodyBase {
diff --git a/source/blender/functions/functions/random.cpp b/source/blender/functions/functions/random.cpp
index 58032fc3481..ef646174f4c 100644
--- a/source/blender/functions/functions/random.cpp
+++ b/source/blender/functions/functions/random.cpp
@@ -24,11 +24,11 @@ static float random_float(uint32_t x)
class RandomNumber : public TupleCallBody {
void call(Tuple &fn_in, Tuple &fn_out, ExecutionContext &UNUSED(ctx)) const override
{
- float seed = fn_in.get<float>(0);
- float min = fn_in.get<float>(1);
- float max = fn_in.get<float>(2);
+ float seed = this->get_input<float>(fn_in, 0, "Seed");
+ float min = this->get_input<float>(fn_in, 1, "Min");
+ float max = this->get_input<float>(fn_in, 2, "Max");
float result = random_float(float_as_uint(seed)) * (max - min) + min;
- fn_out.set<float>(0, result);
+ this->set_output<float>(fn_out, 0, "Value", result);
}
};
More information about the Bf-blender-cvs
mailing list