Skip to content

Commit

Permalink
I think I got surprise triggering to fully work now? The core of it w…
Browse files Browse the repository at this point in the history
…as that I had to sleep after sending SIGUSR1 signals to the dashboard, since not sleeping made some signals not get delivered, oddly enough. This is probably a race condition, and I am not sure of how to make a good solution yet; so I will settle with this for now.
  • Loading branch information
CaspianA1 committed May 31, 2024
1 parent 9b637d6 commit 4ee2903
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 4 additions & 2 deletions scripts/trigger_surprise.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ unsigned_int_pattern='^[0-9]+$'

# Param: the signal to send
try_signal() {
pkill -f -$1 wbor-studio-dashboard || fail "Could not send the signal '$1' to the dashboard (check if it's running)!"
# TODO: when not sleeping, why is the amount of signals received by the dashboard not equal to the amount sent?
killall -q -$1 wbor-studio-dashboard || fail "Could not send the signal '$1' to the dashboard (check if it's running)!"
sleep 0.1
}

# 1. Send repeated signals to increment surprise index (SIGUSR1)
for ((i = 0; i < $surprise_index; i++)); do try_signal SIGUSR1; done

# 2. Send signal to trigger surprise and reset surprise indexw (SIGUSR2)
# 2. Send signal to trigger surprise and reset surprise index (SIGUSR2)
try_signal SIGUSR2
10 changes: 6 additions & 4 deletions src/dashboard_defs/surprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn make_surprise_window(

// An appearance is considered artificially triggered if it was activated by the `trigger_surprise.bash` script
fn appearance_was_artificially_triggered(s: &RefCell<SharedSurpriseInfo>, index: usize) -> bool {
let check_and_clear_atomic_bool = |b: &Arc<AtomicBool>| b.swap(false, Ordering::Relaxed);
let check_and_clear_atomic_bool = |b: &Arc<AtomicBool>| b.swap(false, Ordering::SeqCst);

let mut sb = s.borrow();

Expand Down Expand Up @@ -132,13 +132,16 @@ pub fn make_surprise_window(
let surprise_info = params.window.get_state_mut::<SurpriseInfo>();
let rand_generator = &mut params.shared_window_state.get_mut::<SharedWindowState>().rand_generator;

let trigger_appearance_by_chance = appearance_was_randomly_triggered(surprise_info, rand_generator);
let trigger_appearance_artificially = appearance_was_artificially_triggered(&surprise_info.shared_info, surprise_info.index);
let not_currently_active = surprise_info.curr_num_steps_when_appeared.is_none();
let trigger_appearance_by_chance = appearance_was_randomly_triggered(surprise_info, rand_generator);

// Doing the redundant `&&` here since I want to avoid doing signaled surprise incrementation when a surprise is active
let trigger_appearance_artificially = not_currently_active && appearance_was_artificially_triggered(&surprise_info.shared_info, surprise_info.index);

if (trigger_appearance_by_chance || trigger_appearance_artificially) && not_currently_active {
log::info!("Trigger surprise with index {}!", surprise_info.index);
surprise_info.curr_num_steps_when_appeared = Some(0);
surprise_info.shared_info.borrow_mut().curr_signaled_index = 0; // Reset the index back to 0 for next time
}

if let Some(num_steps_when_appeared) = &mut surprise_info.curr_num_steps_when_appeared {
Expand All @@ -147,7 +150,6 @@ pub fn make_surprise_window(
let stop_showing = *num_steps_when_appeared == surprise_info.num_update_steps_to_appear_for + 1;

let should_skip_drawing = if stop_showing {
surprise_info.shared_info.borrow_mut().curr_signaled_index = 0; // Reset the index back to 0 for next time
surprise_info.curr_num_steps_when_appeared = None;
true
}
Expand Down

0 comments on commit 4ee2903

Please sign in to comment.