Skip to content

Commit 886e8a3

Browse files
committed
Option index i64, Option bool i32
1 parent bdc0f54 commit 886e8a3

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

src/runtime/sys.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,18 @@ extern "C" {
7979
pub fn timer_undo_split();
8080
/// Resets the timer.
8181
pub fn timer_reset();
82-
/// Accesses the index of the split the attempt is currently on. If there's
83-
/// no attempt in progress, `-1` is returned instead. This returns an
84-
/// index that is equal to the amount of segments when the attempt is
85-
/// finished, but has not been reset. So you need to be careful when using
86-
/// this value for indexing.
87-
pub fn timer_current_split_index() -> i32;
82+
/// Accesses the index of the split the attempt is currently on.
83+
/// If there's no attempt in progress, `-1` is returned instead.
84+
/// This returns an index that is equal to the amount of segments
85+
/// when the attempt is finished, but has not been reset.
86+
/// So you need to be careful when using this value for indexing.
87+
/// Same index does not imply same split on undo and then split.
88+
pub fn timer_current_split_index() -> i64;
8889
/// Whether the segment at `idx` was splitted this attempt.
89-
pub fn timer_segment_splitted(idx: i32) -> bool;
90+
/// Returns `1` if the segment was splitted, or `0` if skipped.
91+
/// If `idx` is greater than or equal to the current split index,
92+
/// `-1` is returned instead.
93+
pub fn timer_segment_splitted(idx: u64) -> i32;
9094
/// Sets a custom key value pair. This may be arbitrary information that the
9195
/// auto splitter wants to provide for visualization. The pointers need to
9296
/// point to valid UTF-8 encoded text with the respective given length.

src/runtime/timer.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,31 @@ pub fn state() -> TimerState {
112112
}
113113
}
114114

115-
/// Accesses the index of the split the attempt is currently on. If there's
116-
/// no attempt in progress, `-1` is returned instead. This returns an
117-
/// index that is equal to the amount of segments when the attempt is
118-
/// finished, but has not been reset. So you need to be careful when using
119-
/// this value for indexing.
120-
pub fn current_split_index() -> i32 {
121-
unsafe { sys::timer_current_split_index() }
115+
/// Accesses the index of the split the attempt is currently on.
116+
/// If there's no attempt in progress, `None` is returned instead.
117+
/// This returns an index that is equal to the amount of segments
118+
/// when the attempt is finished, but has not been reset.
119+
/// So you need to be careful when using this value for indexing.
120+
/// Same index does not imply same split on undo and then split.
121+
pub fn current_split_index() -> Option<u64> {
122+
let i = unsafe { sys::timer_current_split_index() };
123+
if i.is_negative() {
124+
return None;
125+
}
126+
Some(i as u64)
122127
}
123128

124129
/// Whether the segment at `idx` was splitted this attempt.
125-
pub fn segment_splitted(idx: i32) -> bool {
126-
unsafe { sys::timer_segment_splitted(idx) }
130+
/// Returns `Some(true)` if the segment was splitted,
131+
/// or `Some(false)` if skipped.
132+
/// If `idx` is greater than or equal to the current split index,
133+
/// `None` is returned instead.
134+
pub fn segment_splitted(idx: u64) -> Option<bool> {
135+
match unsafe { sys::timer_segment_splitted(idx) } {
136+
1 => Some(true),
137+
0 => Some(false),
138+
_ => None,
139+
}
127140
}
128141

129142
/// Sets the game time.

0 commit comments

Comments
 (0)