69
69
#include " scene/main/window.h"
70
70
#include " servers/audio/audio_stream.h"
71
71
72
- constexpr double FPS_DECIMAL = 1 ;
72
+ constexpr double FPS_DECIMAL = 1.0 ;
73
73
constexpr double SECOND_DECIMAL = 0.0001 ;
74
+ constexpr double FACTOR = 0.0625 ;
74
75
75
76
void AnimationTrackKeyEdit::_bind_methods () {
76
77
ClassDB::bind_method (D_METHOD (" _update_obj" ), &AnimationTrackKeyEdit::_update_obj);
@@ -1821,7 +1822,7 @@ void AnimationTimelineEdit::update_values() {
1821
1822
}
1822
1823
1823
1824
editing = true ;
1824
- if (use_fps && animation->get_step () > 0 ) {
1825
+ if (use_fps && animation->get_step () > 0.0 ) {
1825
1826
length->set_value (animation->get_length () / animation->get_step ());
1826
1827
length->set_step (FPS_DECIMAL);
1827
1828
length->set_tooltip_text (TTR (" Animation length (frames)" ));
@@ -5019,7 +5020,6 @@ void AnimationTrackEditor::_snap_mode_changed(int p_mode) {
5019
5020
key_edit->set_use_fps (use_fps);
5020
5021
}
5021
5022
marker_edit->set_use_fps (use_fps);
5022
- step->set_step (use_fps ? FPS_DECIMAL : SECOND_DECIMAL);
5023
5023
_update_step_spinbox ();
5024
5024
}
5025
5025
@@ -5030,12 +5030,10 @@ void AnimationTrackEditor::_update_step_spinbox() {
5030
5030
step->set_block_signals (true );
5031
5031
5032
5032
if (timeline->is_using_fps ()) {
5033
- if (animation->get_step () == 0 ) {
5034
- step->set_value (0 );
5033
+ if (animation->get_step () == 0.0 ) {
5034
+ step->set_value (0.0 );
5035
5035
} else {
5036
- // The value stored within tscn cannot restored the original FPS due to lack of precision,
5037
- // so the value should be limited to integer.
5038
- step->set_value (Math::round (1.0 / animation->get_step ()));
5036
+ step->set_value (1.0 / animation->get_step ());
5039
5037
}
5040
5038
5041
5039
} else {
@@ -5149,7 +5147,9 @@ void AnimationTrackEditor::_update_step(double p_new_step) {
5149
5147
5150
5148
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
5151
5149
undo_redo->create_action (TTR (" Change Animation Step" ));
5152
- float step_value = p_new_step;
5150
+ // To ensure that the conversion results are consistent between serialization and load, the value is snapped with 0.0625 to be a rational number.
5151
+ // step_value must also be less than or equal to 1000 to ensure that no error accumulates due to interactions with retrieving values from inner range.
5152
+ double step_value = MIN (1000.0 , Math::snapped (p_new_step, FACTOR));
5153
5153
if (timeline->is_using_fps ()) {
5154
5154
if (step_value != 0.0 ) {
5155
5155
step_value = 1.0 / step_value;
@@ -6366,8 +6366,8 @@ void AnimationTrackEditor::goto_prev_step(bool p_from_mouse_event) {
6366
6366
return ;
6367
6367
}
6368
6368
float anim_step = animation->get_step ();
6369
- if (anim_step == 0 ) {
6370
- anim_step = 1 ;
6369
+ if (anim_step == 0.0 ) {
6370
+ anim_step = 1.0 ;
6371
6371
}
6372
6372
if (p_from_mouse_event && Input::get_singleton ()->is_key_pressed (Key::SHIFT)) {
6373
6373
// Use more precise snapping when holding Shift.
@@ -6377,8 +6377,8 @@ void AnimationTrackEditor::goto_prev_step(bool p_from_mouse_event) {
6377
6377
6378
6378
float pos = timeline->get_play_position ();
6379
6379
pos = Math::snapped (pos - anim_step, anim_step);
6380
- if (pos < 0 ) {
6381
- pos = 0 ;
6380
+ if (pos < 0.0 ) {
6381
+ pos = 0.0 ;
6382
6382
}
6383
6383
set_anim_pos (pos);
6384
6384
_timeline_changed (pos, false );
@@ -6389,8 +6389,8 @@ void AnimationTrackEditor::goto_next_step(bool p_from_mouse_event, bool p_timeli
6389
6389
return ;
6390
6390
}
6391
6391
float anim_step = animation->get_step ();
6392
- if (anim_step == 0 ) {
6393
- anim_step = 1 ;
6392
+ if (anim_step == 0.0 ) {
6393
+ anim_step = 1.0 ;
6394
6394
}
6395
6395
if (p_from_mouse_event && Input::get_singleton ()->is_key_pressed (Key::SHIFT)) {
6396
6396
// Use more precise snapping when holding Shift.
0 commit comments