-
-
Notifications
You must be signed in to change notification settings - Fork 845
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use std::time::Duration for time intervals #7616
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welome! I think instant::Instant
can be used in place of the proposed RuffleDuration
. instant
is already a dependency of ruffle-core
, and currently being used in various places across the codebase. So I'll be glad if you please proceed with instant::Instant
. Also, looks like the PR has conflicts against current master branch. Can you please resolve them while at it?
@relrelb Doesn't that conflict with what Mike was suggesting here? #6075 (comment) |
Right, I take my words back. I was confusing between instant and duration, which are not the same thing. |
@relrelb I fixed conflict.
As for this one, the regression test failed due to lack of precision in std::Duration (same definition in instant::Duration), as I wrote in my comment here(#6075 (comment)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This looks exactly what I had in mind. There are only a few small naming issues.
scanner/Cargo.toml
Outdated
sha2 = "0.10.2" | ||
sha2 = "0.10.2" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated formatting change in the PR, could you remove this change?
core/src/duration.rs
Outdated
pub fn zero() -> Self { | ||
Self(OrderedFloat::zero()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this pub const ZERO: Self
. This matches what we do for Twips
.
core/src/duration.rs
Outdated
pub const fn one_sec() -> Self { | ||
Self(OrderedFloat(1.0)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make this pub const ONE_SECOND: Self
core/src/duration.rs
Outdated
#[derive(Debug, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Default, Serialize, Deserialize)] | ||
pub struct RuffleDuration(OrderedFloat<f64>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For ease of typing and to follow Rust naming conventions, let's name this Duration
instead of RuffleDuration
. Rust prefers to avoid stuttering in names (ruffle_core::RuffleDuration
vs. ruffle_core::Duration
). We can explicitly specify for methods that want the std
version (std::instant::Duration
), or use a renaming import (use std::instant::Duration as StdDuration
).
Instead of adding ordered_float
dependency so that we can derive Ord
and Eq
, let's instead implement any necessary methods ourselves. For example, Ord
isn't necessary if we add a direct min
/max
method:
pub fn min(self, other: RuffleDuration) -> RuffleDuration {
if self.0 < other.0 {
self
} else {
other
}
}
then the duration can become:
pub struct Duration(f64);
without the need for ordered_float
.
I know we already have lots of dependencies, but I like to avoid adding new ones when possible.
@Herschel Thanks for the review. |
tests/tests/regression_tests.rs
Outdated
@@ -1372,7 +1372,7 @@ fn run_swf( | |||
// with timer execution (timers will see an elapsed time of *at least* | |||
// the requested timer interval). | |||
if frame_time_sleep { | |||
std::thread::sleep(frame_time_duration); | |||
std::thread::sleep(StdDuration::from_nanos(frame_time.as_nanos() as u64)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be frame_time.into()
?
tests/tests/regression_tests.rs
Outdated
@@ -1310,8 +1311,7 @@ fn run_swf( | |||
let base_path = Path::new(swf_path).parent().unwrap(); | |||
let mut executor = NullExecutor::new(); | |||
let movie = SwfMovie::from_path(swf_path, None)?; | |||
let frame_time = 1000.0 / movie.frame_rate().to_f64(); | |||
let frame_time_duration = Duration::from_millis(frame_time as u64); | |||
let frame_time = Duration::from_millis(1000.0 / movie.frame_rate().to_f64()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be Duration::from_secs(1.0 / ...);
now
Sorry, this is late, but I have fixed the review points. |
Hmm... looks like this PR needs some TLC. I'll come back to it later. |
…tion. At that time, the regression test with a duration of sub nano second was dropped.
2673859
to
042ee49
Compare
I've pushed an update to this PR that rebases it on a relatively-current master and attempts to fix a few incompatibilities that cropped up from new types adopting I still need to come back to this. There's some stuff in web and desktop that relies on |
Is this PR difficult to update and review due to its size? If it is, I wonder whether it could be split into multiple smaller PRs - like, the first PR would be core/src/duration.rs . And after that is merged, a PR would be opened that takes a part of the changes in this PR, gets it merged, and then rinse and repeat with new, small PRs until all changes in this PR has been merged. The advantage of having a large PR is, I would guess, that you can then try out the new type in all the places where it might be relevant, and thus uncover problems early on, which is very useful and help and can avoid backtracking late in the process. But, now that there is a large PR, I imagine that you already have that potential advantage of a large PR, and can then proceed with small PRs taken from this large PR. |
@higumachan In case that you do not currently seek to work on this further, would it be alright with you for others to take a stab at getting these changes merged, for instance through multiple smaller PRs that reference this PR? |
#6075
I replaced the interval declared in f64 that I could find with ruffle_core::RuffleDuration.
Please let me know if you find any omissions in the f64-declared intervals, as they are difficult to find.