From 832cbec46cd7206b2ad77df1703db2a1bac9516e Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 2 Sep 2025 10:47:35 -0400 Subject: [PATCH 1/3] Add current_split_index --- src/runtime/sys.rs | 6 ++++++ src/runtime/timer.rs | 9 +++++++++ 2 files changed, 15 insertions(+) diff --git a/src/runtime/sys.rs b/src/runtime/sys.rs index 4fef9ff5..45d4e385 100644 --- a/src/runtime/sys.rs +++ b/src/runtime/sys.rs @@ -79,6 +79,12 @@ extern "C" { pub fn timer_undo_split(); /// Resets the timer. pub fn timer_reset(); + /// Accesses the index of the split the attempt is currently on. If there's + /// no attempt in progress, `-1` is returned instead. This returns an + /// index that is equal to the amount of segments when the attempt is + /// finished, but has not been reset. So you need to be careful when using + /// this value for indexing. + pub fn timer_current_split_index() -> i32; /// Sets a custom key value pair. This may be arbitrary information that the /// auto splitter wants to provide for visualization. The pointers need to /// point to valid UTF-8 encoded text with the respective given length. diff --git a/src/runtime/timer.rs b/src/runtime/timer.rs index b1eb218d..a9386f3d 100644 --- a/src/runtime/timer.rs +++ b/src/runtime/timer.rs @@ -112,6 +112,15 @@ pub fn state() -> TimerState { } } +/// Accesses the index of the split the attempt is currently on. If there's +/// no attempt in progress, `-1` is returned instead. This returns an +/// index that is equal to the amount of segments when the attempt is +/// finished, but has not been reset. So you need to be careful when using +/// this value for indexing. +pub fn current_split_index() -> i32 { + unsafe { sys::timer_current_split_index() } +} + /// Sets the game time. #[inline] pub fn set_game_time(time: time::Duration) { From bdc0f548d0b31504c1fc358ac0aa643d7f9e7440 Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 2 Sep 2025 10:48:01 -0400 Subject: [PATCH 2/3] Add segment_splitted --- src/runtime/sys.rs | 2 ++ src/runtime/timer.rs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/runtime/sys.rs b/src/runtime/sys.rs index 45d4e385..2f9d0a8d 100644 --- a/src/runtime/sys.rs +++ b/src/runtime/sys.rs @@ -85,6 +85,8 @@ extern "C" { /// finished, but has not been reset. So you need to be careful when using /// this value for indexing. pub fn timer_current_split_index() -> i32; + /// Whether the segment at `idx` was splitted this attempt. + pub fn timer_segment_splitted(idx: i32) -> bool; /// Sets a custom key value pair. This may be arbitrary information that the /// auto splitter wants to provide for visualization. The pointers need to /// point to valid UTF-8 encoded text with the respective given length. diff --git a/src/runtime/timer.rs b/src/runtime/timer.rs index a9386f3d..ae966cb7 100644 --- a/src/runtime/timer.rs +++ b/src/runtime/timer.rs @@ -121,6 +121,11 @@ pub fn current_split_index() -> i32 { unsafe { sys::timer_current_split_index() } } +/// Whether the segment at `idx` was splitted this attempt. +pub fn segment_splitted(idx: i32) -> bool { + unsafe { sys::timer_segment_splitted(idx) } +} + /// Sets the game time. #[inline] pub fn set_game_time(time: time::Duration) { From 886e8a323b80ee9e51a9c5a5d320d533fdf9b0db Mon Sep 17 00:00:00 2001 From: AlexKnauth Date: Tue, 2 Sep 2025 15:53:59 -0400 Subject: [PATCH 3/3] Option index i64, Option bool i32 --- src/runtime/sys.rs | 18 +++++++++++------- src/runtime/timer.rs | 31 ++++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/runtime/sys.rs b/src/runtime/sys.rs index 2f9d0a8d..ab1d6838 100644 --- a/src/runtime/sys.rs +++ b/src/runtime/sys.rs @@ -79,14 +79,18 @@ extern "C" { pub fn timer_undo_split(); /// Resets the timer. pub fn timer_reset(); - /// Accesses the index of the split the attempt is currently on. If there's - /// no attempt in progress, `-1` is returned instead. This returns an - /// index that is equal to the amount of segments when the attempt is - /// finished, but has not been reset. So you need to be careful when using - /// this value for indexing. - pub fn timer_current_split_index() -> i32; + /// Accesses the index of the split the attempt is currently on. + /// If there's no attempt in progress, `-1` is returned instead. + /// This returns an index that is equal to the amount of segments + /// when the attempt is finished, but has not been reset. + /// So you need to be careful when using this value for indexing. + /// Same index does not imply same split on undo and then split. + pub fn timer_current_split_index() -> i64; /// Whether the segment at `idx` was splitted this attempt. - pub fn timer_segment_splitted(idx: i32) -> bool; + /// Returns `1` if the segment was splitted, or `0` if skipped. + /// If `idx` is greater than or equal to the current split index, + /// `-1` is returned instead. + pub fn timer_segment_splitted(idx: u64) -> i32; /// Sets a custom key value pair. This may be arbitrary information that the /// auto splitter wants to provide for visualization. The pointers need to /// point to valid UTF-8 encoded text with the respective given length. diff --git a/src/runtime/timer.rs b/src/runtime/timer.rs index ae966cb7..c6942785 100644 --- a/src/runtime/timer.rs +++ b/src/runtime/timer.rs @@ -112,18 +112,31 @@ pub fn state() -> TimerState { } } -/// Accesses the index of the split the attempt is currently on. If there's -/// no attempt in progress, `-1` is returned instead. This returns an -/// index that is equal to the amount of segments when the attempt is -/// finished, but has not been reset. So you need to be careful when using -/// this value for indexing. -pub fn current_split_index() -> i32 { - unsafe { sys::timer_current_split_index() } +/// Accesses the index of the split the attempt is currently on. +/// If there's no attempt in progress, `None` is returned instead. +/// This returns an index that is equal to the amount of segments +/// when the attempt is finished, but has not been reset. +/// So you need to be careful when using this value for indexing. +/// Same index does not imply same split on undo and then split. +pub fn current_split_index() -> Option { + let i = unsafe { sys::timer_current_split_index() }; + if i.is_negative() { + return None; + } + Some(i as u64) } /// Whether the segment at `idx` was splitted this attempt. -pub fn segment_splitted(idx: i32) -> bool { - unsafe { sys::timer_segment_splitted(idx) } +/// Returns `Some(true)` if the segment was splitted, +/// or `Some(false)` if skipped. +/// If `idx` is greater than or equal to the current split index, +/// `None` is returned instead. +pub fn segment_splitted(idx: u64) -> Option { + match unsafe { sys::timer_segment_splitted(idx) } { + 1 => Some(true), + 0 => Some(false), + _ => None, + } } /// Sets the game time.