Skip to content

Commit

Permalink
Add Current Split Index to the C API
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelJBerk authored Jun 29, 2021
1 parent bcbff22 commit 14d77e8
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions capi/src/timer.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! A Timer provides all the capabilities necessary for doing speedrun attempts.
use super::{output_str, output_time, output_time_span, output_vec};
use crate::run::{NullableOwnedRun, OwnedRun};
use crate::shared_timer::OwnedSharedTimer;
use livesplit_core::run::saver;
use livesplit_core::{Run, Time, TimeSpan, Timer, TimerPhase, TimingMethod};
use std::os::raw::c_char;
use std::ptr;
use crate::{
run::{NullableOwnedRun, OwnedRun},
shared_timer::OwnedSharedTimer,
};
use livesplit_core::{run::saver, Run, Time, TimeSpan, Timer, TimerPhase, TimingMethod};
use std::{os::raw::c_char, ptr};

/// type
pub type OwnedTimer = Box<Timer>;
Expand Down Expand Up @@ -77,6 +77,16 @@ pub extern "C" fn Timer_set_run(this: &mut Timer, run: OwnedRun) -> NullableOwne
this.set_run(*run).err().map(Box::new)
}

/// 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.
#[no_mangle]
pub extern "C" fn Timer_current_split_index(this: &Timer) -> isize {
this.current_split_index().map_or(-1, |i| i as isize)
}

/// Starts the Timer if there is no attempt in progress. If that's not the
/// case, nothing happens.
#[no_mangle]
Expand Down

0 comments on commit 14d77e8

Please sign in to comment.