Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/runtime/sys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +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.
/// 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.
/// 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.
Expand Down
27 changes: 27 additions & 0 deletions src/runtime/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,33 @@
}
}

/// 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<u64> {
let i = unsafe { sys::timer_current_split_index() };

Check warning on line 122 in src/runtime/timer.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

unsafe block missing a safety comment
if i.is_negative() {
return None;
}
Some(i as u64)
}

/// Whether the segment at `idx` was splitted this attempt.
/// 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<bool> {
match unsafe { sys::timer_segment_splitted(idx) } {

Check warning on line 135 in src/runtime/timer.rs

View workflow job for this annotation

GitHub Actions / Check clippy lints

unsafe block missing a safety comment
1 => Some(true),
0 => Some(false),
_ => None,
}
}

/// Sets the game time.
#[inline]
pub fn set_game_time(time: time::Duration) {
Expand Down
Loading