Skip to content

Commit f21b180

Browse files
committed
Allow negative timestamp
1 parent 59418d4 commit f21b180

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

vello_pacing/src/choreographed.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,38 +43,36 @@ pub struct Thinking;
4343
///
4444
/// This might not actually be true - the timebase of the return values from [`ndk::choreographer::ChoreographerFrameCallbackData`]
4545
/// aren't documented by
46-
struct Timestamp(u64);
46+
struct Timestamp(i64);
4747

48-
impl Mul<u64> for Timestamp {
48+
impl Mul<i64> for Timestamp {
4949
type Output = Self;
5050

51-
fn mul(self, rhs: u64) -> Self::Output {
51+
fn mul(self, rhs: i64) -> Self::Output {
5252
Self(self.0 * rhs)
5353
}
5454
}
5555

5656
impl Timestamp {
57-
const fn from_nanos(nanos: u64) -> Self {
57+
const fn from_nanos(nanos: i64) -> Self {
5858
Self(nanos)
5959
}
6060

61-
const fn from_micros(micros: u64) -> Self {
61+
const fn from_micros(micros: i64) -> Self {
6262
Self::from_nanos(micros * 1_000)
6363
}
6464

65-
const fn from_millis(millis: u64) -> Self {
65+
const fn from_millis(millis: i64) -> Self {
6666
Self::from_nanos(millis * 1_000_000)
6767
}
6868

6969
/// Get the current time in `CLOCK_MONOTONIC`.
7070
///
71-
/// TODO: This assumes that the value is less than ~2.5billion seconds (i.e. ~70 years)
71+
/// TODO: This assumed the returned value is not negative.
72+
/// Hopefully that's fine?
7273
fn now() -> Self {
7374
let spec = nix::time::clock_gettime(ClockId::CLOCK_MONOTONIC).unwrap();
74-
let stamp = (spec.tv_sec() * 1_000_000_000 + spec.tv_nsec())
75-
.try_into()
76-
.unwrap();
77-
Self(stamp)
75+
Self(spec.tv_sec() * 1_000_000_000 + spec.tv_nsec())
7876
}
7977
}
8078

0 commit comments

Comments
 (0)