Skip to content

Commit

Permalink
Update OnStart, OnSplit, OnReset to call when performed manually
Browse files Browse the repository at this point in the history
  • Loading branch information
wins1ey committed Jun 10, 2024
1 parent e7cd28a commit 9c0b713
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
36 changes: 24 additions & 12 deletions src/auto-splitter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/auto-splitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
7 changes: 7 additions & 0 deletions src/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdbool.h>

#include "auto-splitter.h"

long long ls_time_now(void)
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 9c0b713

Please sign in to comment.