Skip to content

Commit e5819d0

Browse files
committed
Update OnStart, OnSplit, OnReset to call when performed manually
1 parent e7cd28a commit e5819d0

File tree

3 files changed

+37
-12
lines changed

3 files changed

+37
-12
lines changed

src/auto-splitter.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ int maps_cache_cycles_value = 0; // same as `maps_cache_cycles` but this one rep
2424
atomic_bool timer_started = false;
2525
atomic_bool auto_splitter_enabled = true;
2626
atomic_bool call_start = false;
27+
atomic_bool call_on_start = false;
2728
atomic_bool call_split = false;
29+
atomic_bool call_on_split = false;
2830
atomic_bool toggle_loading = false;
2931
atomic_bool call_reset = false;
32+
atomic_bool call_on_reset = false;
3033
bool prev_is_loading;
3134

3235
static const char* disabled_functions[] = {
@@ -391,19 +394,28 @@ void run_auto_splitter_cycle(
391394
}
392395

393396
if (!atomic_load(&timer_started)) {
394-
if (start_exists && start(L)) {
395-
if (on_start_exists) {
396-
call_va(L, "OnStart", "");
397-
}
398-
}
399-
} else if (reset_exists && reset(L)) {
400-
if (on_reset_exists) {
401-
call_va(L, "OnReset", "");
402-
}
403-
} else if (split_exists && split(L)) {
404-
if (on_split_exists) {
405-
call_va(L, "OnSplit", "");
397+
if (start_exists) {
398+
start(L);
406399
}
400+
} else if (reset_exists) {
401+
reset(L);
402+
} else if (split_exists) {
403+
split(L);
404+
}
405+
406+
if (on_start_exists && atomic_load(&call_on_start)) {
407+
call_va(L, "OnStart", "");
408+
atomic_store(&call_on_start, false);
409+
}
410+
411+
if (on_split_exists && atomic_load(&call_on_split)) {
412+
call_va(L, "OnSplit", "");
413+
atomic_store(&call_on_split, false);
414+
}
415+
416+
if (on_reset_exists && atomic_load(&call_on_reset)) {
417+
call_va(L, "OnReset", "");
418+
atomic_store(&call_on_reset, false);
407419
}
408420

409421
// Clear the memory maps cache if needed
@@ -456,6 +468,9 @@ void run_auto_splitter()
456468
bool update_exists = lua_function_exists(L, "Update");
457469
bool init_exists = lua_function_exists(L, "Init");
458470
bool memory_map_exists = false;
471+
atomic_store(&call_on_start, false);
472+
atomic_store(&call_on_split, false);
473+
atomic_store(&call_on_reset, false);
459474

460475
if (startup_exists) {
461476
startup(L);

src/auto-splitter.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@
77
extern atomic_bool timer_started;
88
extern atomic_bool auto_splitter_enabled;
99
extern atomic_bool call_start;
10+
extern atomic_bool call_on_start;
1011
extern atomic_bool call_split;
12+
extern atomic_bool call_on_split;
1113
extern atomic_bool toggle_loading;
1214
extern atomic_bool call_reset;
15+
extern atomic_bool call_on_reset;
1316
extern char auto_splitter_file[PATH_MAX];
1417
extern int maps_cache_cycles_value;
1518

src/timer.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
#include <stdlib.h>
55
#include <string.h>
66
#include <time.h>
7+
#include <stdbool.h>
8+
9+
#include "auto-splitter.h"
710

811
long long ls_time_now(void)
912
{
@@ -597,6 +600,7 @@ int ls_timer_start(ls_timer* timer)
597600
if (!timer->started) {
598601
++*timer->attempt_count;
599602
timer->started = 1;
603+
atomic_store(&call_on_start, true);
600604
}
601605
timer->running = 1;
602606
}
@@ -641,6 +645,7 @@ int ls_timer_split(ls_timer* timer)
641645
ls_timer_stop(timer);
642646
ls_game_update_splits((ls_game*)timer->game, timer);
643647
}
648+
atomic_store(&call_on_split, true);
644649
return timer->curr_split;
645650
}
646651
}
@@ -691,9 +696,11 @@ int ls_timer_reset(ls_timer* timer)
691696
{
692697
if (!timer->running) {
693698
if (timer->started && timer->time <= 0) {
699+
atomic_store(&call_on_reset, true);
694700
return ls_timer_cancel(timer);
695701
}
696702
reset_timer(timer);
703+
atomic_store(&call_on_reset, true);
697704
return 1;
698705
}
699706
return 0;

0 commit comments

Comments
 (0)