Skip to content

Commit

Permalink
Fix elapsed_time_since_shown tracking time since the scene was
Browse files Browse the repository at this point in the history
switched out of, rather than into; fix time not being tracked properly
at launch.
  • Loading branch information
Limeth committed Jul 26, 2021
1 parent 519320c commit 21d7347
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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
@@ -1,6 +1,6 @@
[package]
name = "obs-shaderfilter-plus"
version = "0.3.0"
version = "0.3.1"
authors = ["Jakub Hlusička <[email protected]>"]
edition = "2018"

Expand Down
31 changes: 25 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,13 +413,14 @@ struct Data {
property_message_display: bool,

settings_update_requested: Arc<AtomicBool>,
shown: bool,
enabled: Arc<AtomicBool>,
}

impl Data {
pub fn new(source: SourceContext) -> Self {
let settings_update_requested = Arc::new(AtomicBool::new(true));
let enabled = Arc::new(AtomicBool::new(true));
let enabled = Arc::new(AtomicBool::new(false));
let enabled_clone = enabled.clone();

Self {
Expand Down Expand Up @@ -482,6 +483,7 @@ impl Data {
},
property_message_display: false,
settings_update_requested,
shown: false,
enabled,
}
}
Expand Down Expand Up @@ -556,10 +558,18 @@ impl VideoTickSource<Data> for ShaderFilterPlus {
let elapsed_time_previous = data.elapsed_time_previous.replace(elapsed_time)
.unwrap_or(elapsed_time);
let now = Instant::now();
let elapsed_time_since_shown = if let Some(shown_at) = data.shown_at.as_ref() {
shown_at.elapsed().as_secs_f32()
let elapsed_time_since_shown = if data.shown {
if let Some(shown_at) = data.shown_at.as_ref() {
shown_at.elapsed().as_secs_f32()
} else {
data.shown_at = Some(now);
0.0
}
} else {
data.shown_at = Some(now);
if data.shown_at.is_some() {
data.shown_at = None;
}

0.0
};
let elapsed_time_since_enabled = if data.enabled.load(Ordering::SeqCst) {
Expand All @@ -574,7 +584,7 @@ impl VideoTickSource<Data> for ShaderFilterPlus {
data.enabled_at = None;
}

std::f32::NAN
0.0
};
let elapsed_time_since_shown_previous = data.elapsed_time_since_shown_previous
.replace(elapsed_time_since_shown)
Expand Down Expand Up @@ -799,7 +809,15 @@ impl UpdateSource<Data> for ShaderFilterPlus {
impl HideSource<Data> for ShaderFilterPlus {
fn hide(mut context: PluginContext<Data>) {
if let Some(data) = context.data_mut().as_mut() {
data.shown_at = None;
data.shown = false;
}
}
}

impl ShowSource<Data> for ShaderFilterPlus {
fn show(mut context: PluginContext<Data>) {
if let Some(data) = context.data_mut().as_mut() {
data.shown = true;
}
}
}
Expand All @@ -823,6 +841,7 @@ impl Module for ShaderFilterPlus {
.enable_video_render()
.enable_video_tick()
.enable_hide()
.enable_show()
.build();

load_context.register_source(source);
Expand Down

0 comments on commit 21d7347

Please sign in to comment.