diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2020-09-28 15:56:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-28 15:56:29 +0200 |
commit | b07f020c99545b756cf58c20e47f06bdf3247ef5 (patch) | |
tree | e1975a2718b1ee85d646a8bca356e2be56f03450 /core/variant_op.cpp | |
parent | bd12dc33d9991e69cc4cb9de187bca13d7108c58 (diff) | |
parent | e4942e4a96e6d53c6bf40c5602e29cd38595c2a9 (diff) |
Merge pull request #42133 from vnen/variant-op-consistency
Allow commutative multiplication in Variant
Diffstat (limited to 'core/variant_op.cpp')
-rw-r--r-- | core/variant_op.cpp | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/core/variant_op.cpp b/core/variant_op.cpp index ec4eea05bf..533b056f91 100644 --- a/core/variant_op.cpp +++ b/core/variant_op.cpp @@ -1031,6 +1031,9 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, case FLOAT: { _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._float); } + case INT: { + _RETURN(*reinterpret_cast<const Quat *>(p_a._data._mem) * p_b._data._int); + } default: _RETURN_FAIL; } @@ -1062,8 +1065,64 @@ void Variant::evaluate(const Operator &p_op, const Variant &p_a, } } - DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, INT, *, _int); - DEFAULT_OP_NUM_VEC(math, OP_MULTIPLY, FLOAT, *, _float); + CASE_TYPE(math, OP_MULTIPLY, INT) { + if (p_b.type == INT) { + _RETURN(p_a._data._int * p_b._data._int); + } + if (p_b.type == FLOAT) { + _RETURN(p_a._data._int * p_b._data._float); + } + if (p_b.type == VECTOR2) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector2 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector3 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR2I) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector2i *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3I) { + _RETURN(p_a._data._int * *reinterpret_cast<const Vector3i *>(p_b._data._mem)); + } + if (p_b.type == QUAT) { + _RETURN(p_a._data._int * *reinterpret_cast<const Quat *>(p_b._data._mem)); + } + if (p_b.type == COLOR) { + _RETURN(p_a._data._int * *reinterpret_cast<const Color *>(p_b._data._mem)); + } + + _RETURN_FAIL + } + + CASE_TYPE(math, OP_MULTIPLY, FLOAT) { + if (p_b.type == INT) { + _RETURN(p_a._data._float * p_b._data._int); + } + if (p_b.type == FLOAT) { + _RETURN(p_a._data._float * p_b._data._float); + } + if (p_b.type == VECTOR2) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector2 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector3 *>(p_b._data._mem)); + } + if (p_b.type == VECTOR2I) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector2i *>(p_b._data._mem)); + } + if (p_b.type == VECTOR3I) { + _RETURN(p_a._data._float * *reinterpret_cast<const Vector3i *>(p_b._data._mem)); + } + if (p_b.type == QUAT) { + _RETURN(p_a._data._float * *reinterpret_cast<const Quat *>(p_b._data._mem)); + } + if (p_b.type == COLOR) { + _RETURN(p_a._data._float * *reinterpret_cast<const Color *>(p_b._data._mem)); + } + + _RETURN_FAIL + } + DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2, *, Vector2); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR2I, *, Vector2i); DEFAULT_OP_LOCALMEM_NUM(math, OP_MULTIPLY, VECTOR3, *, Vector3); |