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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ members = ["obs"]
crate-type = ["cdylib"]

[dependencies]
livesplit-core = { git = "https://github.com/LiveSplit/livesplit-core", features = [
livesplit-core = { git = "https://github.com/AlexKnauth/livesplit-core", branch = "Refragg-2", features = [
"software-rendering",
"font-loading",
] }
Expand Down
105 changes: 92 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,11 @@
unsafe {
debug!("Loading settings.");

let global_timer = get_global_timer(splits_path);
let global_timer = get_global_timer(
splits_path,
#[cfg(feature = "auto-splitting")]
&local_auto_splitter,
);
global_timer
.timer
.auto_save
Expand All @@ -506,11 +510,6 @@
let texture = gs_texture_create(width, height, GS_RGBA, 1, ptr::null_mut(), GS_DYNAMIC);
obs_leave_graphics();

#[cfg(feature = "auto-splitting")]
if let Some(local_auto_splitter) = &local_auto_splitter {
auto_splitter_load(&global_timer, local_auto_splitter.clone())
}

Self {
#[cfg(feature = "auto-splitting")]
local_auto_splitter,
Expand Down Expand Up @@ -627,6 +626,9 @@
return;
}

// Update AutoSplitter Settings Map before reset-autosaving
#[cfg(feature = "auto-splitting")]
update_auto_splitter_settings_map(&state.global_timer);
drop(state.global_timer.timer.reset(None));
}
}
Expand Down Expand Up @@ -921,6 +923,9 @@
) -> bool {
unsafe {
let state: &mut State = &mut (*data.cast::<Mutex<State>>()).lock().unwrap();
// Update AutoSplitter Settings Map before saving
#[cfg(feature = "auto-splitting")]
update_auto_splitter_settings_map(&state.global_timer);
state.global_timer.timer.save();
false
}
Expand Down Expand Up @@ -1181,6 +1186,17 @@
.store(enabled, atomic::Ordering::Relaxed);
}

/// Update AutoSplitter Settings Map, from the
/// auto_splitting::Runtime to the Inner Timer Run,
/// to prepare for it to be saved to a splits file
#[cfg(feature = "auto-splitting")]
fn update_auto_splitter_settings_map(global_timer: &GlobalTimer) -> Option<()> {
let m = global_timer.auto_splitter.settings_map()?;
let mut t = global_timer.timer.timer.write().ok()?;
t.run_auto_splitter_settings_map_store(m);
Some(())
}

#[cfg(feature = "auto-splitting")]
unsafe extern "C" fn auto_splitter_activate_clicked(
_props: *mut obs_properties_t,
Expand Down Expand Up @@ -1313,6 +1329,9 @@
unsafe extern "C" fn media_restart(data: *mut c_void) {
unsafe {
let state: &mut State = &mut (*data.cast::<Mutex<State>>()).lock().unwrap();
// Update AutoSplitter Settings Map before reset-autosaving
#[cfg(feature = "auto-splitting")]
update_auto_splitter_settings_map(&state.global_timer);
drop(state.global_timer.timer.reset(None));
drop(state.global_timer.timer.start());
}
Expand All @@ -1321,6 +1340,9 @@
unsafe extern "C" fn media_stop(data: *mut c_void) {
unsafe {
let state: &mut State = &mut (*data.cast::<Mutex<State>>()).lock().unwrap();
// Update AutoSplitter Settings Map before reset-autosaving
#[cfg(feature = "auto-splitting")]
update_auto_splitter_settings_map(&state.global_timer);
drop(state.global_timer.timer.reset(None));
}
}
Expand Down Expand Up @@ -1838,23 +1860,62 @@
match &widget.kind {
WidgetKind::Title { .. } => {}
WidgetKind::Bool { default_value } => {
let value = obs_data_get_bool(settings_obj, data_key.as_ptr());
if value != *default_value {
map.insert(key.clone(), Value::Bool(value));
let old_value = state
.auto_splitter_map
.get(&key)

Check warning on line 1865 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler
.and_then(|v| v.to_bool())
.unwrap_or(*default_value);
let asr_value = map
.get(&key)

Check warning on line 1869 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler
.and_then(|v| v.to_bool())
.unwrap_or(*default_value);
if asr_value != old_value {
obs_data_set_bool(settings_obj, data_key.as_ptr(), asr_value);
state
.auto_splitter_map
.insert(key.clone(), Value::Bool(asr_value));
} else {
map.remove(key);
let obs_value = obs_data_get_bool(settings_obj, data_key.as_ptr());
if obs_value != *default_value {
map.insert(key.clone(), Value::Bool(obs_value));
} else {
map.remove(key);
}
}
}
WidgetKind::Choice {
default_option_key, ..
} => {
if let Some(value) =
let old_value = state
.auto_splitter_map
.get(&key)

Check warning on line 1892 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler
.and_then(|v| v.as_string())
.unwrap_or(default_option_key);
let asr_value = map
.get(&key)

Check warning on line 1896 in src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

this expression creates a reference which is immediately dereferenced by the compiler
.and_then(|v| v.as_string())
.unwrap_or(default_option_key);
if asr_value != old_value {
if let Ok(new_value) =
CString::from_vec_with_nul(format!("{}\0", asr_value).into())
{
obs_data_set_string(
settings_obj,
data_key.as_ptr(),
new_value.as_ptr(),
);
}
state
.auto_splitter_map
.insert(key.clone(), Value::String(asr_value.clone()));
} else if let Some(obs_value) =
CStr::from_ptr(obs_data_get_string(settings_obj, data_key.as_ptr()))
.to_str()
.ok()
.filter(|v| *v != &**default_option_key)
{
map.insert(key.clone(), Value::String(Arc::from(value)));
map.insert(key.clone(), Value::String(Arc::from(obs_value)));
} else {
map.remove(key);
}
Expand All @@ -1881,6 +1942,13 @@
.set_settings_map_if_unchanged(&original, map.clone())
!= Some(false)
{
state
.global_timer
.timer
.timer
.write()
.unwrap()
.run_auto_splitter_settings_map_store(map.clone());
state.auto_splitter_map = map;
break;
}
Expand Down Expand Up @@ -1908,10 +1976,17 @@
}

fn handle_splits_path_change(state: &mut State, splits_path: PathBuf) {
state.global_timer = get_global_timer(splits_path);
state.global_timer = get_global_timer(
splits_path,
#[cfg(feature = "auto-splitting")]
&state.local_auto_splitter,
);
}

fn get_global_timer(splits_path: PathBuf) -> Arc<GlobalTimer> {
fn get_global_timer(
splits_path: PathBuf,
#[cfg(feature = "auto-splitting")] local_auto_splitter: &Option<PathBuf>,
) -> Arc<GlobalTimer> {
let mut timers = TIMERS.lock().unwrap();
timers.retain(|timer| timer.strong_count() > 0);
if let Some(timer) = timers.iter().find_map(|timer| {
Expand Down Expand Up @@ -1942,6 +2017,10 @@
#[cfg(feature = "auto-splitting")]
auto_splitter_is_enabled: AtomicBool::new(false),
});
#[cfg(feature = "auto-splitting")]
if let Some(local_auto_splitter) = local_auto_splitter {
auto_splitter_load(&global_timer, local_auto_splitter.clone());
}
timers.push(Arc::downgrade(&global_timer));
global_timer
}
Expand Down
Loading