Fix incorrect cast when animating `int`

Type was cast to `int` rather than `int64_t`
Also corrects `real_t` to `double`

(cherry picked from commit 035cf5e210)
This commit is contained in:
A Thousand Ships 2023-09-04 11:03:39 +02:00 committed by Yuri Sizov
parent 4d498e18ec
commit 74506ce901
1 changed files with 12 additions and 12 deletions

View File

@ -5579,8 +5579,8 @@ Variant Animation::subtract_variant(const Variant &a, const Variant &b) {
Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) { Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
if (a.get_type() != b.get_type()) { if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) { if (a.is_num() && b.is_num()) {
real_t va = a; double va = a;
real_t vb = b; double vb = b;
return va + vb * c; return va + vb * c;
} }
return a; return a;
@ -5591,7 +5591,7 @@ Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
return Variant(); return Variant();
} }
case Variant::INT: { case Variant::INT: {
return int((a.operator int64_t()) + (b.operator int64_t()) * c + 0.5); return int64_t((a.operator int64_t()) + (b.operator int64_t()) * c + 0.5);
} }
case Variant::FLOAT: { case Variant::FLOAT: {
return (a.operator double()) + (b.operator double()) * c; return (a.operator double()) + (b.operator double()) * c;
@ -5664,8 +5664,8 @@ Variant Animation::blend_variant(const Variant &a, const Variant &b, float c) {
Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float c) { Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float c) {
if (a.get_type() != b.get_type()) { if (a.get_type() != b.get_type()) {
if (a.is_num() && b.is_num()) { if (a.is_num() && b.is_num()) {
real_t va = a; double va = a;
real_t vb = b; double vb = b;
return va + (vb - va) * c; return va + (vb - va) * c;
} }
return a; return a;
@ -5677,11 +5677,11 @@ Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float
} }
case Variant::INT: { case Variant::INT: {
const int64_t va = a.operator int64_t(); const int64_t va = a.operator int64_t();
return int(va + ((b.operator int64_t()) - va) * c); return int64_t(va + ((b.operator int64_t()) - va) * c);
} }
case Variant::FLOAT: { case Variant::FLOAT: {
const real_t va = a.operator real_t(); const double va = a.operator double();
return va + ((b.operator real_t()) - va) * c; return va + ((b.operator double()) - va) * c;
} }
case Variant::VECTOR2: { case Variant::VECTOR2: {
return (a.operator Vector2()).lerp(b.operator Vector2(), c); return (a.operator Vector2()).lerp(b.operator Vector2(), c);
@ -5783,7 +5783,7 @@ Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float
case Variant::PACKED_INT32_ARRAY: { case Variant::PACKED_INT32_ARRAY: {
const Vector<int32_t> arr_a = a; const Vector<int32_t> arr_a = a;
const Vector<int32_t> arr_b = b; const Vector<int32_t> arr_b = b;
int32_t sz = arr_a.size(); int sz = arr_a.size();
if (sz == 0 || arr_b.size() != sz) { if (sz == 0 || arr_b.size() != sz) {
return a; return a;
} else { } else {
@ -5795,7 +5795,7 @@ Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float
const int32_t *br = arr_b.ptr(); const int32_t *br = arr_b.ptr();
Variant va; Variant va;
for (int32_t i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
va = interpolate_variant(ar[i], br[i], c); va = interpolate_variant(ar[i], br[i], c);
vw[i] = va; vw[i] = va;
} }
@ -5806,7 +5806,7 @@ Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float
case Variant::PACKED_INT64_ARRAY: { case Variant::PACKED_INT64_ARRAY: {
const Vector<int64_t> arr_a = a; const Vector<int64_t> arr_a = a;
const Vector<int64_t> arr_b = b; const Vector<int64_t> arr_b = b;
int64_t sz = arr_a.size(); int sz = arr_a.size();
if (sz == 0 || arr_b.size() != sz) { if (sz == 0 || arr_b.size() != sz) {
return a; return a;
} else { } else {
@ -5818,7 +5818,7 @@ Variant Animation::interpolate_variant(const Variant &a, const Variant &b, float
const int64_t *br = arr_b.ptr(); const int64_t *br = arr_b.ptr();
Variant va; Variant va;
for (int64_t i = 0; i < sz; i++) { for (int i = 0; i < sz; i++) {
va = interpolate_variant(ar[i], br[i], c); va = interpolate_variant(ar[i], br[i], c);
vw[i] = va; vw[i] = va;
} }