Restored the ability for linear interpolation to work on a mix of integer and float keyframes.

This commit is contained in:
Michael Wörner 2023-12-11 22:41:16 +01:00
parent 6882e5042d
commit 12ce2e33b2

View file

@ -5485,7 +5485,7 @@ Variant Animation::cast_to_blendwise(const Variant p_value) {
switch (p_value.get_type()) {
case Variant::BOOL:
case Variant::INT: {
return p_value.operator real_t();
return p_value.operator double();
} break;
case Variant::STRING:
case Variant::STRING_NAME: {
@ -5521,7 +5521,7 @@ Variant Animation::cast_from_blendwise(const Variant p_value, const Variant::Typ
return p_value.operator real_t() >= 0.5;
} break;
case Variant::INT: {
return (int)Math::round(p_value.operator real_t());
return (int64_t)Math::round(p_value.operator double());
} break;
case Variant::STRING: {
return array_to_string(p_value);
@ -5594,16 +5594,20 @@ Variant Animation::array_to_string(const Variant p_value) {
}
Variant Animation::add_variant(const Variant &a, const Variant &b) {
if (a.get_type() != b.get_type() && !a.is_array()) {
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return add_variant(cast_to_blendwise(a), cast_to_blendwise(b));
} else if (!a.is_array()) {
return a;
}
}
switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) + (b.operator real_t());
return (a.operator double()) + (b.operator double());
} break;
case Variant::RECT2: {
const Rect2 ra = a.operator Rect2();
@ -5704,16 +5708,20 @@ Variant Animation::add_variant(const Variant &a, const Variant &b) {
}
Variant Animation::subtract_variant(const Variant &a, const Variant &b) {
if (a.get_type() != b.get_type() && !a.is_array()) {
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return subtract_variant(cast_to_blendwise(a), cast_to_blendwise(b));
} else if (!a.is_array()) {
return a;
}
}
switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) - (b.operator real_t());
return (a.operator double()) - (b.operator double());
} break;
case Variant::RECT2: {
const Rect2 ra = a.operator Rect2();
@ -5814,16 +5822,20 @@ Variant Animation::subtract_variant(const Variant &a, const Variant &b) {
}
Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
if (a.get_type() != b.get_type() && !a.is_array()) {
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return blend_variant(cast_to_blendwise(a), cast_to_blendwise(b), c);
} else if (!a.is_array()) {
return a;
}
}
switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
return (a.operator real_t()) + (b.operator real_t()) * c;
return (a.operator double()) + (b.operator double()) * c;
} break;
case Variant::VECTOR2: {
return (a.operator Vector2()) + (b.operator Vector2()) * c;
@ -5947,17 +5959,21 @@ Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
}
Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float c, bool p_snap_array_element) {
if (a.get_type() != b.get_type() && !a.is_array()) {
if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) {
return interpolate_variant(cast_to_blendwise(a), cast_to_blendwise(b), c);
} else if (!a.is_array()) {
return a;
}
}
switch (a.get_type()) {
case Variant::NIL: {
return Variant();
} break;
case Variant::FLOAT: {
const real_t va = a.operator real_t();
return va + ((b.operator real_t()) - va) * c;
const double va = a.operator double();
return va + ((b.operator double()) - va) * c;
} break;
case Variant::VECTOR2: {
return (a.operator Vector2()).lerp(b.operator Vector2(), c);