mirror of
https://github.com/godotengine/godot.git
synced 2024-11-24 21:22:48 +00:00
Do not defer PathFollow3D transform updates
Co-authored-by: Yaohua Xiong <xiongyaohua@gmail.com>
This commit is contained in:
parent
444683bd09
commit
51b8b74d4b
@ -216,24 +216,7 @@ void Path3D::_bind_methods() {
|
||||
ADD_SIGNAL(MethodInfo("curve_changed"));
|
||||
}
|
||||
|
||||
// Update transform, in deferred mode by default to avoid superfluity.
|
||||
void PathFollow3D::update_transform(bool p_immediate) {
|
||||
transform_dirty = true;
|
||||
|
||||
if (p_immediate) {
|
||||
_update_transform();
|
||||
} else {
|
||||
callable_mp(this, &PathFollow3D::_update_transform).call_deferred();
|
||||
}
|
||||
}
|
||||
|
||||
// Update transform immediately .
|
||||
void PathFollow3D::_update_transform() {
|
||||
if (!transform_dirty) {
|
||||
return;
|
||||
}
|
||||
transform_dirty = false;
|
||||
|
||||
void PathFollow3D::update_transform() {
|
||||
if (!path) {
|
||||
return;
|
||||
}
|
||||
@ -286,10 +269,8 @@ void PathFollow3D::_notification(int p_what) {
|
||||
Node *parent = get_parent();
|
||||
if (parent) {
|
||||
path = Object::cast_to<Path3D>(parent);
|
||||
if (path) {
|
||||
update_transform();
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
@ -414,6 +395,9 @@ void PathFollow3D::_bind_methods() {
|
||||
|
||||
void PathFollow3D::set_progress(real_t p_progress) {
|
||||
ERR_FAIL_COND(!isfinite(p_progress));
|
||||
if (progress == p_progress) {
|
||||
return;
|
||||
}
|
||||
progress = p_progress;
|
||||
|
||||
if (path) {
|
||||
@ -435,10 +419,11 @@ void PathFollow3D::set_progress(real_t p_progress) {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_h_offset(real_t p_h_offset) {
|
||||
h_offset = p_h_offset;
|
||||
if (path) {
|
||||
update_transform();
|
||||
if (h_offset == p_h_offset) {
|
||||
return;
|
||||
}
|
||||
h_offset = p_h_offset;
|
||||
update_transform();
|
||||
}
|
||||
|
||||
real_t PathFollow3D::get_h_offset() const {
|
||||
@ -446,10 +431,11 @@ real_t PathFollow3D::get_h_offset() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_v_offset(real_t p_v_offset) {
|
||||
v_offset = p_v_offset;
|
||||
if (path) {
|
||||
update_transform();
|
||||
if (v_offset == p_v_offset) {
|
||||
return;
|
||||
}
|
||||
v_offset = p_v_offset;
|
||||
update_transform();
|
||||
}
|
||||
|
||||
real_t PathFollow3D::get_v_offset() const {
|
||||
@ -476,6 +462,9 @@ real_t PathFollow3D::get_progress_ratio() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_rotation_mode(RotationMode p_rotation_mode) {
|
||||
if (rotation_mode == p_rotation_mode) {
|
||||
return;
|
||||
}
|
||||
rotation_mode = p_rotation_mode;
|
||||
|
||||
update_configuration_warnings();
|
||||
@ -487,6 +476,9 @@ PathFollow3D::RotationMode PathFollow3D::get_rotation_mode() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_use_model_front(bool p_use_model_front) {
|
||||
if (use_model_front == p_use_model_front) {
|
||||
return;
|
||||
}
|
||||
use_model_front = p_use_model_front;
|
||||
update_transform();
|
||||
}
|
||||
@ -496,6 +488,9 @@ bool PathFollow3D::is_using_model_front() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_loop(bool p_loop) {
|
||||
if (loop == p_loop) {
|
||||
return;
|
||||
}
|
||||
loop = p_loop;
|
||||
update_transform();
|
||||
}
|
||||
@ -505,6 +500,9 @@ bool PathFollow3D::has_loop() const {
|
||||
}
|
||||
|
||||
void PathFollow3D::set_tilt_enabled(bool p_enabled) {
|
||||
if (tilt_enabled == p_enabled) {
|
||||
return;
|
||||
}
|
||||
tilt_enabled = p_enabled;
|
||||
update_transform();
|
||||
}
|
||||
|
@ -90,7 +90,6 @@ protected:
|
||||
void _validate_property(PropertyInfo &p_property) const;
|
||||
|
||||
void _notification(int p_what);
|
||||
void _update_transform();
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
@ -124,7 +123,7 @@ public:
|
||||
|
||||
PackedStringArray get_configuration_warnings() const override;
|
||||
|
||||
void update_transform(bool p_immediate = false);
|
||||
void update_transform();
|
||||
|
||||
static Transform3D correct_posture(Transform3D p_transform, PathFollow3D::RotationMode p_rotation_mode);
|
||||
|
||||
|
@ -60,39 +60,30 @@ TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress ratio") {
|
||||
SceneTree::get_singleton()->get_root()->add_child(path);
|
||||
|
||||
path_follow_3d->set_progress_ratio(0);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.125);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(50, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.25);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.375);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 50, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.5);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.625);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 50), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.75);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.875);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 50, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress_ratio(1);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 0, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
memdelete(path);
|
||||
@ -113,39 +104,30 @@ TEST_CASE("[SceneTree][PathFollow3D] Sampling with progress") {
|
||||
SceneTree::get_singleton()->get_root()->add_child(path);
|
||||
|
||||
path_follow_3d->set_progress(0);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(50);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(50, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(100);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(150);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 50, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(200);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(250);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 50), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(300);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 100, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(350);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 50, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
path_follow_3d->set_progress(400);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 0, 100), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
memdelete(path);
|
||||
@ -163,13 +145,11 @@ TEST_CASE("[SceneTree][PathFollow3D] Removal of a point in curve") {
|
||||
SceneTree::get_singleton()->get_root()->add_child(path);
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.5);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(100, 0, 0), path_follow_3d->get_transform().get_origin()));
|
||||
|
||||
curve->remove_point(1);
|
||||
|
||||
path_follow_3d->set_progress_ratio(0.5);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK_MESSAGE(
|
||||
is_equal_approx(Vector3(50, 50, 0), path_follow_3d->get_transform().get_origin()),
|
||||
"Path follow's position should be updated after removing a point from the curve");
|
||||
@ -270,47 +250,36 @@ TEST_CASE("[SceneTree][PathFollow3D] Calculate forward vector") {
|
||||
path_follow_3d->set_rotation_mode(PathFollow3D::RotationMode::ROTATION_ORIENTED);
|
||||
|
||||
path_follow_3d->set_progress(-50);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(0);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(50);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(100);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(100 + dist_cube_100 / 2);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-0.577348, -0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(100 + dist_cube_100 - 0.01);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(-0.577348, -0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(250 + dist_cube_100);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0, 0, -1), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(400 + dist_cube_100 - 0.01);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0, 0, -1), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(400 + 1.5 * dist_cube_100);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0.577348, 0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(400 + 2 * dist_cube_100 - 0.01);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(0.577348, 0.577348, 0.577348), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
path_follow_3d->set_progress(500 + 2 * dist_cube_100);
|
||||
path_follow_3d->update_transform(true);
|
||||
CHECK(is_equal_approx(Vector3(1, 0, 0), path_follow_3d->get_transform().get_basis().get_column(2)));
|
||||
|
||||
memdelete(path);
|
||||
|
Loading…
Reference in New Issue
Block a user