Skip to content

Commit 7a01fbf

Browse files
committed
Small optimisations
1 parent b7ea007 commit 7a01fbf

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

src/lib.rs

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,64 +88,60 @@ impl Memory {
8888
}
8989

9090
fn start(watchers: &Watchers) -> bool {
91-
watchers.briefingByte.pair.is_some_and(|val|
92-
val.current == 1
93-
&& watchers.fpsFloat.pair.is_some_and(|val| val.current < 10000.0)
94-
)
95-
|| watchers.loadByte.pair.is_some_and(|val|
96-
val.changed_from_to(&0, &1)
97-
&& watchers.fpsFloat.pair.is_some_and(|val| val.current != 60.0)
98-
&& watchers.warRecord.pair.is_some_and(|val| val.current.matches("Loadbar.dds"))
99-
)
91+
watchers.briefingByte.pair.unwrap().current == 1
92+
&& watchers.fpsFloat.pair.unwrap().current < 10000.0
93+
|| watchers.loadByte.pair.unwrap().changed_from_to(&0, &1)
94+
&& watchers.fpsFloat.pair.unwrap().current != 60.0
95+
&& watchers.warRecord.pair.unwrap().current.matches("Loadbar.dds")
10096
}
10197

10298
fn isWarRecord(watchers: &Watchers) -> bool {
10399
watchers.fpsFloat.pair.is_some_and(|val|
104100
val.current != val.old
105101
&& val.old == 60.0
106-
&& watchers.warRecord.pair.is_some_and(|val| val.current.matches("oldmenu1.dds"))
107102
)
103+
&& watchers.warRecord.pair.unwrap().current.matches("oldmenu1.dds")
108104
}
109105

110106
fn leftWarRecord(watchers: &Watchers) -> bool {
111-
watchers.warRecord.pair.is_some_and(|val| val.current.matches("loading\\level"))
112-
|| watchers.warRecord.pair.is_some_and(|val| val.current.matches("frontsc2.dds"))
107+
watchers.warRecord.pair.is_some_and(|val|
108+
val.current.matches("loading\\level")
109+
|| val.current.matches("frontsc2.dds")
110+
)
113111
}
114112

115113
fn isLoading(watchers: &Watchers) -> Option<bool> {
116114
Some(
117115
watchers.loadByte.pair?.current == 0
118-
&& (watchers.briefingByte.pair?.current != 1 && watchers.fpsFloat.pair?.current < 10000.0)
116+
&& watchers.briefingByte.pair?.current != 1
119117
|| watchers.fpsFloat.pair?.current > 10000.0
120118
)
121119
}
122120

123121
fn split(watchers: &Watchers, settings: &Settings) -> bool {
124122
match settings.Individual_level {
125-
true => watchers.startByte.pair.is_some_and(|val| val.current == 5)
126-
&& watchers.mcByte.pair.is_some_and(|val| val.current == 256),
123+
true => watchers.startByte.pair.unwrap().current == 5
124+
&& watchers.mcByte.pair.unwrap().current == 256,
127125
false => watchers.level.pair.is_some_and(|val|
128126
val.changed()
129127
&& !val.current.matches("02a")
130128
|| val.current.matches("08d")
131-
&& watchers.startByte.pair.is_some_and(|val|
132-
val.old == 5 && val.current == 2
133-
)
129+
&& watchers.startByte.pair.unwrap().changed_from_to(&5, &2)
134130
|| val.current.matches("02a")
135-
&& watchers.startByte.pair.is_some_and(|val| val.current == 5)
136-
&& watchers.mcByte.pair.is_some_and(|val| val.current == 256)
131+
&& watchers.startByte.pair.unwrap().current == 5
132+
&& watchers.mcByte.pair.unwrap().current == 256
137133
)
138134
}
139135
}
140136

141137
fn mainLoop(process: &Process, memory: &Memory, watchers: &mut Watchers) {
142-
watchers.startByte.update_infallible(process.read(memory.start).unwrap_or_default());
138+
watchers.startByte.update_infallible(process.read(memory.start).unwrap_or(0));
143139

144140
watchers.loadByte.update_infallible(process.read(memory.load).unwrap_or(1));
145141

146-
watchers.briefingByte.update_infallible(process.read(memory.briefing).unwrap_or_default());
147-
watchers.mcByte.update_infallible(process.read(memory.mc).unwrap_or_default());
148-
watchers.fpsFloat.update_infallible(process.read(memory.fps).unwrap_or_default());
142+
watchers.briefingByte.update_infallible(process.read(memory.briefing).unwrap_or(0));
143+
watchers.mcByte.update_infallible(process.read(memory.mc).unwrap_or(0));
144+
watchers.fpsFloat.update_infallible(process.read(memory.fps).unwrap_or(0.0));
149145

150146
watchers.level.update_infallible(process.read(memory.level).unwrap_or_default());
151147
watchers.warRecord.update_infallible(process.read(memory.warRecord).unwrap_or_default());
@@ -177,6 +173,8 @@ async fn main() {
177173
tickToggled = false;
178174
}
179175

176+
mainLoop(&process, &memory, &mut watchers);
177+
180178
if [TimerState::Running, TimerState::Paused].contains(&timer::state()) {
181179
if isWarRecord(&watchers) {
182180
warRec = 1;
@@ -201,9 +199,12 @@ async fn main() {
201199
timer::start();
202200
}
203201

204-
mainLoop(&process, &memory, &mut watchers);
205202
next_tick().await;
206203
}
207204
}).await;
205+
206+
if timer::state().eq(&TimerState::Running) {
207+
timer::pause_game_time();
208+
}
208209
}
209210
}

0 commit comments

Comments
 (0)