From 9c0b713fee9944162b9f01a7938bb2eb2914bcd3 Mon Sep 17 00:00:00 2001 From: wins1ey Date: Mon, 10 Jun 2024 13:55:13 +0100 Subject: [PATCH] Update OnStart, OnSplit, OnReset to call when performed manually --- src/auto-splitter.c | 36 ++++++++++++++++++++++++------------ src/auto-splitter.h | 3 +++ src/timer.c | 7 +++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/auto-splitter.c b/src/auto-splitter.c index e8fc01c..7ce3315 100644 --- a/src/auto-splitter.c +++ b/src/auto-splitter.c @@ -24,9 +24,12 @@ int maps_cache_cycles_value = 0; // same as `maps_cache_cycles` but this one rep atomic_bool timer_started = false; atomic_bool auto_splitter_enabled = true; atomic_bool call_start = false; +atomic_bool call_on_start = false; atomic_bool call_split = false; +atomic_bool call_on_split = false; atomic_bool toggle_loading = false; atomic_bool call_reset = false; +atomic_bool call_on_reset = false; bool prev_is_loading; static const char* disabled_functions[] = { @@ -391,19 +394,28 @@ void run_auto_splitter_cycle( } if (!atomic_load(&timer_started)) { - if (start_exists && start(L)) { - if (on_start_exists) { - call_va(L, "OnStart", ""); - } - } - } else if (reset_exists && reset(L)) { - if (on_reset_exists) { - call_va(L, "OnReset", ""); - } - } else if (split_exists && split(L)) { - if (on_split_exists) { - call_va(L, "OnSplit", ""); + if (start_exists) { + start(L); } + } else if (reset_exists) { + reset(L); + } else if (split_exists) { + split(L); + } + + if (on_start_exists && atomic_load(&call_on_start)) { + call_va(L, "OnStart", ""); + atomic_store(&call_on_start, false); + } + + if (on_split_exists && atomic_load(&call_on_split)) { + call_va(L, "OnSplit", ""); + atomic_store(&call_on_split, false); + } + + if (on_reset_exists && atomic_load(&call_on_reset)) { + call_va(L, "OnReset", ""); + atomic_store(&call_on_reset, false); } // Clear the memory maps cache if needed diff --git a/src/auto-splitter.h b/src/auto-splitter.h index 11853b7..78f4751 100644 --- a/src/auto-splitter.h +++ b/src/auto-splitter.h @@ -7,9 +7,12 @@ extern atomic_bool timer_started; extern atomic_bool auto_splitter_enabled; extern atomic_bool call_start; +extern atomic_bool call_on_start; extern atomic_bool call_split; +extern atomic_bool call_on_split; extern atomic_bool toggle_loading; extern atomic_bool call_reset; +extern atomic_bool call_on_reset; extern char auto_splitter_file[PATH_MAX]; extern int maps_cache_cycles_value; diff --git a/src/timer.c b/src/timer.c index a3c4888..2288fc3 100644 --- a/src/timer.c +++ b/src/timer.c @@ -4,6 +4,9 @@ #include #include #include +#include + +#include "auto-splitter.h" long long ls_time_now(void) { @@ -597,6 +600,7 @@ int ls_timer_start(ls_timer* timer) if (!timer->started) { ++*timer->attempt_count; timer->started = 1; + atomic_store(&call_on_start, true); } timer->running = 1; } @@ -641,6 +645,7 @@ int ls_timer_split(ls_timer* timer) ls_timer_stop(timer); ls_game_update_splits((ls_game*)timer->game, timer); } + atomic_store(&call_on_split, true); return timer->curr_split; } } @@ -691,9 +696,11 @@ int ls_timer_reset(ls_timer* timer) { if (!timer->running) { if (timer->started && timer->time <= 0) { + atomic_store(&call_on_reset, true); return ls_timer_cancel(timer); } reset_timer(timer); + atomic_store(&call_on_reset, true); return 1; } return 0;