Skip to content

Commit

Permalink
Merge pull request #48 from AlexKnauth/load-remover-reset
Browse files Browse the repository at this point in the history
Fix auto-start: load_remover reset
  • Loading branch information
AlexKnauth authored Feb 6, 2024
2 parents 4aa87e2 + 0c2921a commit 30be19a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
4 changes: 2 additions & 2 deletions splits/current/layout-lswasr.lsl
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
<ScriptPath>C:\Users\Owner\Documents\git\LiveSplit\hollowknight-autosplit-wasm\target\wasm32-wasi\debug\hollowknight_autosplit_wasm.wasm</ScriptPath>
<CustomSettings>
<Setting id="splits" type="list">
<Setting type="string" value="LegacyStart" />
<Setting type="string" value="StartNewGame" />
<Setting type="string" value="KingsPass" />
<Setting type="string" value="Grub1" />
<Setting type="string" value="EnterBroodingMawlek" />
Expand All @@ -202,7 +202,7 @@
<Setting type="string" value="MaskFragment3" />
<Setting type="string" value="Mask1" />
</Setting>
<Setting id="splits_0_item" type="string" value="LegacyStart" />
<Setting id="splits_0_item" type="string" value="StartNewGame" />
<Setting id="splits_1_item" type="string" value="KingsPass" />
<Setting id="splits_2_item" type="string" value="Grub1" />
<Setting id="splits_3_item" type="string" value="EnterBroodingMawlek" />
Expand Down
2 changes: 1 addition & 1 deletion splits/current/splits-direct.lss
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<AutoSplitterSettings>
<Ordered>True</Ordered>
<AutosplitEndRuns>True</AutosplitEndRuns>
<AutosplitStartRuns></AutosplitStartRuns>
<AutosplitStartRuns>StartNewGame</AutosplitStartRuns>
<Splits>
<Split>KingsPass</Split>
<Split>Grub1</Split>
Expand Down
2 changes: 1 addition & 1 deletion src/AutoSplitterSettings.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Ordered>True</Ordered>
<AutosplitEndRuns>True</AutosplitEndRuns>
<AutosplitStartRuns></AutosplitStartRuns>
<AutosplitStartRuns>StartNewGame</AutosplitStartRuns>
<Splits>
<Split>KingsPass</Split>
<Split>Grub1</Split>
Expand Down
35 changes: 14 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ async fn tick_action(
// detect manual starts
TimerState::Running if *i == 0 && is_timer_state_between_runs(*last_timer_state) => {
*i = 1;
load_remover.reset();
asr::print_message("Detected a manual start.");
}
// detect manual end-splits
Expand All @@ -145,35 +146,25 @@ async fn tick_action(
let n = splits.len();
let trans_now = scene_store.transition_now(&process, &game_manager_finder);
loop {
match splits::splits(&splits[*i], &process, &game_manager_finder, trans_now, scene_store, player_data_store) {
SplitterAction::Split => {
splitter_action(SplitterAction::Split, i, n);
next_tick().await;
break;
}
SplitterAction::Skip => {
splitter_action(SplitterAction::Skip, i, n);
let a = splits::splits(&splits[*i], &process, &game_manager_finder, trans_now, scene_store, player_data_store);
match a {
SplitterAction::Split | SplitterAction::ManualSplit => {
splitter_action(a, i, n, load_remover);
next_tick().await;
// no break, allow other actions after a skip
}
SplitterAction::Reset => {
*i = 0;
splitter_action(SplitterAction::Reset, i, n);
load_remover.reset();
break;
}
SplitterAction::ManualSplit => {
splitter_action(SplitterAction::ManualSplit, i, n);
SplitterAction::Skip | SplitterAction::Reset => {
splitter_action(a, i, n, load_remover);
next_tick().await;
break;
// no break, allow other actions after a skip or reset
}
SplitterAction::Pass => {
if auto_reset {
match splits::splits(&splits[0], &process, &game_manager_finder, trans_now, scene_store, player_data_store) {
let a0 = splits::splits(&splits[0], &process, &game_manager_finder, trans_now, scene_store, player_data_store);
match a0 {
SplitterAction::Split | SplitterAction::Reset => {
*i = 0;
splitter_action(SplitterAction::Split, i, n);
load_remover.reset();
splitter_action(a0, i, n, load_remover);
}
_ => (),
}
Expand All @@ -196,11 +187,12 @@ fn is_timer_state_between_runs(s: TimerState) -> bool {
s == TimerState::NotRunning || s == TimerState::Ended
}

fn splitter_action(a: SplitterAction, i: &mut usize, n: usize) {
fn splitter_action(a: SplitterAction, i: &mut usize, n: usize, load_remover: &mut TimingMethodLoadRemover) {
match a {
SplitterAction::Pass => (),
SplitterAction::Reset => {
asr::timer::reset();
load_remover.reset();
*i = 0;
}
SplitterAction::Skip => {
Expand All @@ -210,6 +202,7 @@ fn splitter_action(a: SplitterAction, i: &mut usize, n: usize) {
SplitterAction::Split if *i == 0 => {
asr::timer::reset();
asr::timer::start();
load_remover.reset();
*i += 1;
}
SplitterAction::Split => {
Expand Down
2 changes: 1 addition & 1 deletion src/splits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4092,7 +4092,7 @@ fn entering_kings_pass(p: &Pair<&str>, prc: &Process, g: &GameManagerFinder) ->

pub fn auto_reset_safe(s: &[Split]) -> bool {
let s_first = s.first();
(s_first == Some(&Split::StartNewGame) || s_first == Some(&Split::LegacyStart))
(s_first == Some(&Split::StartNewGame))
&& !s[1..].contains(&Split::StartNewGame)
&& !s[1..].contains(&Split::LegacyStart)
&& !s[0..(s.len()-1)].contains(&Split::EndingSplit)
Expand Down

0 comments on commit 30be19a

Please sign in to comment.