61
61
#include " scene/main/window.h"
62
62
#include " servers/audio/audio_stream.h"
63
63
64
- constexpr double FPS_DECIMAL = 1 ;
64
+ constexpr double FPS_DECIMAL = 1.0 ;
65
65
constexpr double SECOND_DECIMAL = 0.0001 ;
66
+ constexpr double FACTOR = 0.0625 ;
66
67
67
68
void AnimationTrackKeyEdit::_bind_methods () {
68
69
ClassDB::bind_method (D_METHOD (" _update_obj" ), &AnimationTrackKeyEdit::_update_obj);
@@ -1799,7 +1800,7 @@ void AnimationTimelineEdit::update_values() {
1799
1800
}
1800
1801
1801
1802
editing = true ;
1802
- if (use_fps && animation->get_step () > 0 ) {
1803
+ if (use_fps && animation->get_step () > 0.0 ) {
1803
1804
length->set_value (animation->get_length () / animation->get_step ());
1804
1805
length->set_step (FPS_DECIMAL);
1805
1806
length->set_tooltip_text (TTR (" Animation length (frames)" ));
@@ -5016,7 +5017,6 @@ void AnimationTrackEditor::_snap_mode_changed(int p_mode) {
5016
5017
key_edit->set_use_fps (use_fps);
5017
5018
}
5018
5019
marker_edit->set_use_fps (use_fps);
5019
- step->set_step (use_fps ? FPS_DECIMAL : SECOND_DECIMAL);
5020
5020
_update_step_spinbox ();
5021
5021
}
5022
5022
@@ -5027,12 +5027,10 @@ void AnimationTrackEditor::_update_step_spinbox() {
5027
5027
step->set_block_signals (true );
5028
5028
5029
5029
if (timeline->is_using_fps ()) {
5030
- if (animation->get_step () == 0 ) {
5031
- step->set_value (0 );
5030
+ if (animation->get_step () == 0.0 ) {
5031
+ step->set_value (0.0 );
5032
5032
} else {
5033
- // The value stored within tscn cannot restored the original FPS due to lack of precision,
5034
- // so the value should be limited to integer.
5035
- step->set_value (Math::round (1.0 / animation->get_step ()));
5033
+ step->set_value (1.0 / animation->get_step ());
5036
5034
}
5037
5035
5038
5036
} else {
@@ -5146,7 +5144,9 @@ void AnimationTrackEditor::_update_step(double p_new_step) {
5146
5144
5147
5145
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton ();
5148
5146
undo_redo->create_action (TTR (" Change Animation Step" ));
5149
- float step_value = p_new_step;
5147
+ // To ensure that the conversion results are consistent between serialization and load, the value is snapped with 0.0625 to be a rational number.
5148
+ // 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.
5149
+ double step_value = MIN (1000.0 , Math::snapped (p_new_step, FACTOR));
5150
5150
if (timeline->is_using_fps ()) {
5151
5151
if (step_value != 0.0 ) {
5152
5152
step_value = 1.0 / step_value;
@@ -6363,8 +6363,8 @@ void AnimationTrackEditor::goto_prev_step(bool p_from_mouse_event) {
6363
6363
return ;
6364
6364
}
6365
6365
float anim_step = animation->get_step ();
6366
- if (anim_step == 0 ) {
6367
- anim_step = 1 ;
6366
+ if (anim_step == 0.0 ) {
6367
+ anim_step = 1.0 ;
6368
6368
}
6369
6369
if (p_from_mouse_event && Input::get_singleton ()->is_key_pressed (Key::SHIFT)) {
6370
6370
// Use more precise snapping when holding Shift.
@@ -6374,8 +6374,8 @@ void AnimationTrackEditor::goto_prev_step(bool p_from_mouse_event) {
6374
6374
6375
6375
float pos = timeline->get_play_position ();
6376
6376
pos = Math::snapped (pos - anim_step, anim_step);
6377
- if (pos < 0 ) {
6378
- pos = 0 ;
6377
+ if (pos < 0.0 ) {
6378
+ pos = 0.0 ;
6379
6379
}
6380
6380
set_anim_pos (pos);
6381
6381
_timeline_changed (pos, false );
@@ -6386,8 +6386,8 @@ void AnimationTrackEditor::goto_next_step(bool p_from_mouse_event, bool p_timeli
6386
6386
return ;
6387
6387
}
6388
6388
float anim_step = animation->get_step ();
6389
- if (anim_step == 0 ) {
6390
- anim_step = 1 ;
6389
+ if (anim_step == 0.0 ) {
6390
+ anim_step = 1.0 ;
6391
6391
}
6392
6392
if (p_from_mouse_event && Input::get_singleton ()->is_key_pressed (Key::SHIFT)) {
6393
6393
// Use more precise snapping when holding Shift.
0 commit comments