parent
d3c580f0bc
commit
4bbe87abb7
1 changed files with 114 additions and 65 deletions
|
@ -67,7 +67,6 @@ void Tween::_add_pending_command(StringName p_key, const Variant &p_arg1, const
|
||||||
count = 0;
|
count = 0;
|
||||||
|
|
||||||
// Add the specified arguments to the command
|
// Add the specified arguments to the command
|
||||||
// TODO: Make this a switch statement?
|
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
cmd.arg[0] = p_arg1;
|
cmd.arg[0] = p_arg1;
|
||||||
if (count > 1)
|
if (count > 1)
|
||||||
|
@ -459,6 +458,20 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
|
||||||
result = r;
|
result = r;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Variant::RECT2: {
|
||||||
|
// Get the Rect2 for initial and delta value
|
||||||
|
Rect2 i = initial_val;
|
||||||
|
Rect2 d = delta_val;
|
||||||
|
Rect2 r;
|
||||||
|
|
||||||
|
// Execute the equation for the position and size of Rect2
|
||||||
|
APPLY_EQUATION(position.x);
|
||||||
|
APPLY_EQUATION(position.y);
|
||||||
|
APPLY_EQUATION(size.x);
|
||||||
|
APPLY_EQUATION(size.y);
|
||||||
|
result = r;
|
||||||
|
} break;
|
||||||
|
|
||||||
case Variant::VECTOR3: {
|
case Variant::VECTOR3: {
|
||||||
// Get vectors for initial and delta values
|
// Get vectors for initial and delta values
|
||||||
Vector3 i = initial_val;
|
Vector3 i = initial_val;
|
||||||
|
@ -473,6 +486,55 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
|
||||||
result = r;
|
result = r;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Variant::TRANSFORM2D: {
|
||||||
|
// Get the transforms for initial and delta values
|
||||||
|
Transform2D i = initial_val;
|
||||||
|
Transform2D d = delta_val;
|
||||||
|
Transform2D r;
|
||||||
|
|
||||||
|
// Execute the equation on the transforms and mutate the r transform
|
||||||
|
// This uses the custom APPLY_EQUATION macro defined above
|
||||||
|
APPLY_EQUATION(elements[0][0]);
|
||||||
|
APPLY_EQUATION(elements[0][1]);
|
||||||
|
APPLY_EQUATION(elements[1][0]);
|
||||||
|
APPLY_EQUATION(elements[1][1]);
|
||||||
|
APPLY_EQUATION(elements[2][0]);
|
||||||
|
APPLY_EQUATION(elements[2][1]);
|
||||||
|
result = r;
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Variant::QUAT: {
|
||||||
|
// Get the quaternian for the initial and delta values
|
||||||
|
Quat i = initial_val;
|
||||||
|
Quat d = delta_val;
|
||||||
|
Quat r;
|
||||||
|
|
||||||
|
// Execute the equation on the quaternian values and mutate the r quaternian
|
||||||
|
// This uses the custom APPLY_EQUATION macro defined above
|
||||||
|
APPLY_EQUATION(x);
|
||||||
|
APPLY_EQUATION(y);
|
||||||
|
APPLY_EQUATION(z);
|
||||||
|
APPLY_EQUATION(w);
|
||||||
|
result = r;
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case Variant::AABB: {
|
||||||
|
// Get the AABB's for the initial and delta values
|
||||||
|
AABB i = initial_val;
|
||||||
|
AABB d = delta_val;
|
||||||
|
AABB r;
|
||||||
|
|
||||||
|
// Execute the equation for the position and size of the AABB's and mutate the r AABB
|
||||||
|
// This uses the custom APPLY_EQUATION macro defined above
|
||||||
|
APPLY_EQUATION(position.x);
|
||||||
|
APPLY_EQUATION(position.y);
|
||||||
|
APPLY_EQUATION(position.z);
|
||||||
|
APPLY_EQUATION(size.x);
|
||||||
|
APPLY_EQUATION(size.y);
|
||||||
|
APPLY_EQUATION(size.z);
|
||||||
|
result = r;
|
||||||
|
} break;
|
||||||
|
|
||||||
case Variant::BASIS: {
|
case Variant::BASIS: {
|
||||||
// Get the basis for initial and delta values
|
// Get the basis for initial and delta values
|
||||||
Basis i = initial_val;
|
Basis i = initial_val;
|
||||||
|
@ -493,52 +555,6 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
|
||||||
result = r;
|
result = r;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Variant::TRANSFORM2D: {
|
|
||||||
// Get the transforms for initial and delta values
|
|
||||||
Transform2D i = initial_val;
|
|
||||||
Transform2D d = delta_val;
|
|
||||||
Transform2D r;
|
|
||||||
|
|
||||||
// Execute the equation on the transforms and mutate the r transform
|
|
||||||
// This uses the custom APPLY_EQUATION macro defined above
|
|
||||||
APPLY_EQUATION(elements[0][0]);
|
|
||||||
APPLY_EQUATION(elements[0][1]);
|
|
||||||
APPLY_EQUATION(elements[1][0]);
|
|
||||||
APPLY_EQUATION(elements[1][1]);
|
|
||||||
APPLY_EQUATION(elements[2][0]);
|
|
||||||
APPLY_EQUATION(elements[2][1]);
|
|
||||||
result = r;
|
|
||||||
} break;
|
|
||||||
case Variant::QUAT: {
|
|
||||||
// Get the quaternian for the initial and delta values
|
|
||||||
Quat i = initial_val;
|
|
||||||
Quat d = delta_val;
|
|
||||||
Quat r;
|
|
||||||
|
|
||||||
// Execute the equation on the quaternian values and mutate the r quaternian
|
|
||||||
// This uses the custom APPLY_EQUATION macro defined above
|
|
||||||
APPLY_EQUATION(x);
|
|
||||||
APPLY_EQUATION(y);
|
|
||||||
APPLY_EQUATION(z);
|
|
||||||
APPLY_EQUATION(w);
|
|
||||||
result = r;
|
|
||||||
} break;
|
|
||||||
case Variant::AABB: {
|
|
||||||
// Get the AABB's for the initial and delta values
|
|
||||||
AABB i = initial_val;
|
|
||||||
AABB d = delta_val;
|
|
||||||
AABB r;
|
|
||||||
|
|
||||||
// Execute the equation for the position and size of the AABB's and mutate the r AABB
|
|
||||||
// This uses the custom APPLY_EQUATION macro defined above
|
|
||||||
APPLY_EQUATION(position.x);
|
|
||||||
APPLY_EQUATION(position.y);
|
|
||||||
APPLY_EQUATION(position.z);
|
|
||||||
APPLY_EQUATION(size.x);
|
|
||||||
APPLY_EQUATION(size.y);
|
|
||||||
APPLY_EQUATION(size.z);
|
|
||||||
result = r;
|
|
||||||
} break;
|
|
||||||
case Variant::TRANSFORM: {
|
case Variant::TRANSFORM: {
|
||||||
// Get the transforms for the initial and delta values
|
// Get the transforms for the initial and delta values
|
||||||
Transform i = initial_val;
|
Transform i = initial_val;
|
||||||
|
@ -561,6 +577,7 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
|
||||||
APPLY_EQUATION(origin.z);
|
APPLY_EQUATION(origin.z);
|
||||||
result = r;
|
result = r;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case Variant::COLOR: {
|
case Variant::COLOR: {
|
||||||
// Get the Color for initial and delta value
|
// Get the Color for initial and delta value
|
||||||
Color i = initial_val;
|
Color i = initial_val;
|
||||||
|
@ -575,6 +592,7 @@ Variant Tween::_run_equation(InterpolateData &p_data) {
|
||||||
APPLY_EQUATION(a);
|
APPLY_EQUATION(a);
|
||||||
result = r;
|
result = r;
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
// If unknown, just return the initial value
|
// If unknown, just return the initial value
|
||||||
result = initial_val;
|
result = initial_val;
|
||||||
|
@ -1129,26 +1147,18 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
|
||||||
delta_val = final_val.operator Vector2() - initial_val.operator Vector2();
|
delta_val = final_val.operator Vector2() - initial_val.operator Vector2();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case Variant::RECT2: {
|
||||||
|
// Build a new Rect2 and use the new position and sizes to make a delta
|
||||||
|
Rect2 i = initial_val;
|
||||||
|
Rect2 f = final_val;
|
||||||
|
delta_val = Rect2(f.position - i.position, f.size - i.size);
|
||||||
|
} break;
|
||||||
|
|
||||||
case Variant::VECTOR3:
|
case Variant::VECTOR3:
|
||||||
// Convert to Vectors and find the delta
|
// Convert to Vectors and find the delta
|
||||||
delta_val = final_val.operator Vector3() - initial_val.operator Vector3();
|
delta_val = final_val.operator Vector3() - initial_val.operator Vector3();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Variant::BASIS: {
|
|
||||||
// Build a new basis which is the delta between the initial and final values
|
|
||||||
Basis i = initial_val;
|
|
||||||
Basis f = final_val;
|
|
||||||
delta_val = Basis(f.elements[0][0] - i.elements[0][0],
|
|
||||||
f.elements[0][1] - i.elements[0][1],
|
|
||||||
f.elements[0][2] - i.elements[0][2],
|
|
||||||
f.elements[1][0] - i.elements[1][0],
|
|
||||||
f.elements[1][1] - i.elements[1][1],
|
|
||||||
f.elements[1][2] - i.elements[1][2],
|
|
||||||
f.elements[2][0] - i.elements[2][0],
|
|
||||||
f.elements[2][1] - i.elements[2][1],
|
|
||||||
f.elements[2][2] - i.elements[2][2]);
|
|
||||||
} break;
|
|
||||||
|
|
||||||
case Variant::TRANSFORM2D: {
|
case Variant::TRANSFORM2D: {
|
||||||
// Build a new transform which is the difference between the initial and final values
|
// Build a new transform which is the difference between the initial and final values
|
||||||
Transform2D i = initial_val;
|
Transform2D i = initial_val;
|
||||||
|
@ -1175,6 +1185,21 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
|
||||||
delta_val = AABB(f.position - i.position, f.size - i.size);
|
delta_val = AABB(f.position - i.position, f.size - i.size);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case Variant::BASIS: {
|
||||||
|
// Build a new basis which is the delta between the initial and final values
|
||||||
|
Basis i = initial_val;
|
||||||
|
Basis f = final_val;
|
||||||
|
delta_val = Basis(f.elements[0][0] - i.elements[0][0],
|
||||||
|
f.elements[0][1] - i.elements[0][1],
|
||||||
|
f.elements[0][2] - i.elements[0][2],
|
||||||
|
f.elements[1][0] - i.elements[1][0],
|
||||||
|
f.elements[1][1] - i.elements[1][1],
|
||||||
|
f.elements[1][2] - i.elements[1][2],
|
||||||
|
f.elements[2][0] - i.elements[2][0],
|
||||||
|
f.elements[2][1] - i.elements[2][1],
|
||||||
|
f.elements[2][2] - i.elements[2][2]);
|
||||||
|
} break;
|
||||||
|
|
||||||
case Variant::TRANSFORM: {
|
case Variant::TRANSFORM: {
|
||||||
// Build a new transform which is the difference between the initial and final values
|
// Build a new transform which is the difference between the initial and final values
|
||||||
Transform i = initial_val;
|
Transform i = initial_val;
|
||||||
|
@ -1203,10 +1228,34 @@ bool Tween::_calc_delta_val(const Variant &p_initial_val, const Variant &p_final
|
||||||
delta_val = Color(f.r - i.r, f.g - i.g, f.b - i.b, f.a - i.a);
|
delta_val = Color(f.r - i.r, f.g - i.g, f.b - i.b, f.a - i.a);
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default:
|
default: {
|
||||||
// TODO: Should move away from a 'magic string'?
|
static Variant::Type supported_types[] = {
|
||||||
ERR_PRINT("Invalid param type, except(int/real/vector2/vector/matrix/matrix32/quat/aabb/transform/color)");
|
Variant::BOOL,
|
||||||
|
Variant::INT,
|
||||||
|
Variant::REAL,
|
||||||
|
Variant::VECTOR2,
|
||||||
|
Variant::RECT2,
|
||||||
|
Variant::VECTOR3,
|
||||||
|
Variant::TRANSFORM2D,
|
||||||
|
Variant::QUAT,
|
||||||
|
Variant::AABB,
|
||||||
|
Variant::BASIS,
|
||||||
|
Variant::TRANSFORM,
|
||||||
|
Variant::COLOR,
|
||||||
|
};
|
||||||
|
|
||||||
|
int length = *(&supported_types + 1) - supported_types;
|
||||||
|
String error_msg = "Invalid parameter type. Supported types are: ";
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
error_msg += ", ";
|
||||||
|
}
|
||||||
|
error_msg += Variant::get_type_name(supported_types[i]);
|
||||||
|
}
|
||||||
|
error_msg += ".";
|
||||||
|
ERR_PRINT(error_msg);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue