• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

A Nix-friendly SQLite-enhanced fork of Flitter, a speedrunning split timer for Unix-style terminals


Commit MetaInfo

Revision2696389e343469082565b0dfe9feea3d5e3a551d (tree)
Time2022-12-23 10:21:21
AuthorCorbin <cds@corb...>
CommiterCorbin

Log Message

Start factoring gettimeofday() calls.

I know that this doesn't look like progress, but I'm trying to work
incrementally.

Change Summary

Incremental Difference

--- a/src/display.ml
+++ b/src/display.ml
@@ -59,12 +59,13 @@ let time_status timer split_num =
5959 else
6060 color depends on whether currently ahead and how lead/loss compares to last available lead/loss
6161 *)
62+ let now = Core_unix.gettimeofday () in
6263 if Splits.is_gold timer split_num then Gold
6364 else
64- match Splits.ahead_by timer split_num with
65+ match Splits.ahead_by timer split_num ~now with
6566 | None -> Ahead_gain
6667 | Some delta -> (
67- match Splits.ahead_by timer (split_num - 1) with
68+ match Splits.ahead_by timer (split_num - 1) ~now with
6869 | None -> if delta < 0 then Ahead_gain else Behind_loss
6970 | Some prev_delta ->
7071 if delta < 0 then
@@ -89,13 +90,13 @@ let show_delta timer split_num =
8990 *)
9091 match timer.state with
9192 | Idle -> false
92- | Timing (splits, _, _) | Paused (splits, _, _, _) | Done (splits, _, _) -> (
93+ | Timing (splits, _, now) | Paused (splits, _, _, now) | Done (splits, _, now) -> (
9394 if split_num < Array.length splits then true
9495 else
9596 match time_status timer split_num with
9697 | Behind_gain | Behind_loss -> true
9798 | Ahead_gain | Ahead_loss | Gold -> (
98- let sgmt = Splits.segment_time timer split_num in
99+ let sgmt = Splits.segment_time timer split_num ~now in
99100 let gold = timer.golds.(split_num).duration in
100101 match (sgmt, gold) with Some s, Some g -> s > g | _ -> false))
101102
@@ -123,7 +124,8 @@ let split_row timer width i =
123124 let delta_image =
124125 if show_comparison then I.string uncolored_attr "-"
125126 else
126- match Splits.ahead_by timer i with
127+ let now = Core_unix.gettimeofday () in
128+ match Splits.ahead_by timer i ~now with
127129 | None -> I.string uncolored_attr "-"
128130 | Some delta ->
129131 if not (show_delta timer i) then I.string uncolored_attr ""
@@ -135,9 +137,10 @@ let split_row timer width i =
135137
136138 (* Compute the image of the split's segment time *)
137139 let sgmt_image =
140+ let now = Core_unix.gettimeofday () in
138141 let seg_time =
139142 if show_comparison then Splits.archived_segment_time timer i
140- else Splits.segment_time timer i
143+ else Splits.segment_time timer i ~now
141144 in
142145
143146 match seg_time with
@@ -147,8 +150,9 @@ let split_row timer width i =
147150
148151 (* Compute the image of the split's absolute time *)
149152 let time =
153+ let now = Core_unix.gettimeofday () in
150154 if show_comparison then Splits.archived_split_time timer i
151- else Splits.split_time timer i
155+ else Splits.split_time timer i ~now
152156 in
153157 let time_str =
154158 match time with Some t -> Duration.to_string t 1 | None -> "-"
@@ -243,11 +247,11 @@ let previous_segment timer width =
243247 let time_img =
244248 match timer.state with
245249 | Idle -> empty_time_img
246- | Timing (splits, _, _) | Paused (splits, _, _, _) | Done (splits, _, _)
250+ | Timing (splits, _, now) | Paused (splits, _, _, now) | Done (splits, _, now)
247251 -> (
248252 let curr_split = Array.length splits in
249- let prev_delta = Splits.ahead_by timer (curr_split - 1) in
250- let prev_prev_delta = Splits.ahead_by timer (curr_split - 2) in
253+ let prev_delta = Splits.ahead_by timer (curr_split - 1) ~now in
254+ let prev_prev_delta = Splits.ahead_by timer (curr_split - 2) ~now in
251255 match (prev_delta, prev_prev_delta) with
252256 | Some pd, Some ppd ->
253257 let diff = pd - ppd in
@@ -265,7 +269,7 @@ let best_possible_time timer width =
265269 let t =
266270 match timer.state with
267271 | Idle -> Splits.gold_sum timer 0 (Array.length timer.split_names)
268- | Timing (splits, _, _) | Paused (splits, _, _, _) -> (
272+ | Timing (splits, _, now) | Paused (splits, _, _, now) -> (
269273 let curr_split = Array.length splits in
270274 let total_splits = Array.length timer.split_names in
271275
@@ -274,7 +278,7 @@ let best_possible_time timer width =
274278 let last_split_time =
275279 if curr_split = 0 then Some 0 else splits.(curr_split - 1)
276280 in
277- let curr_seg = Splits.segment_time timer curr_split in
281+ let curr_seg = Splits.segment_time timer curr_split ~now in
278282
279283 match (future_sob, curr_gold, last_split_time, curr_seg) with
280284 | ( Some future_sob',
--- a/src/splits.ml
+++ b/src/splits.ml
@@ -1,13 +1,9 @@
11 open Core
22 open Timer_types
33
4-let split_time timer ?now split_num =
4+let split_time timer ~now split_num =
55 if split_num < 0 then Some 0
66 else
7- let curr_time =
8- match now with Some t -> t | None -> Core_unix.gettimeofday ()
9- in
10-
117 match timer.state with
128 | Idle -> None
139 | Paused (splits, start_time, pause_time, _) ->
@@ -18,21 +14,21 @@ let split_time timer ?now split_num =
1814 | Timing (splits, start_time, _) | Done (splits, start_time, _) ->
1915 if split_num > Array.length splits then None
2016 else if split_num = Array.length splits then
21- Some (Duration.between start_time curr_time)
17+ Some (Duration.between start_time now)
2218 else splits.(split_num)
2319
2420 let duration timer =
2521 match timer.state with
2622 | Idle -> 0
27- | Timing (splits, _, _) | Paused (splits, _, _, _) | Done (splits, _, _) -> (
28- match split_time timer (Array.length splits) with
23+ | Timing (splits, _, now) | Paused (splits, _, _, now) | Done (splits, _, now) -> (
24+ match split_time ~now timer (Array.length splits) with
2925 | Some t -> t
3026 | None -> assert false)
3127
32-let ahead_by timer ?now split_num =
28+let ahead_by timer ~now split_num =
3329 if split_num < 0 then None
3430 else
35- let split_time = split_time timer ?now split_num in
31+ let split_time = split_time timer ~now split_num in
3632 let comp_time =
3733 match timer.comparison with
3834 | None -> None
@@ -43,9 +39,9 @@ let ahead_by timer ?now split_num =
4339 | Some st, Some ct -> Some (st - ct)
4440 | _ -> None
4541
46-let segment_time timer ?now split_num =
47- let t0 = split_time timer ?now (split_num - 1) in
48- let t1 = split_time timer ?now split_num in
42+let segment_time timer ~now split_num =
43+ let t0 = split_time timer ~now (split_num - 1) in
44+ let t1 = split_time timer ~now split_num in
4945
5046 match (t0, t1) with Some t0', Some t1' -> Some (t1' - t0') | _ -> None
5147
@@ -56,7 +52,8 @@ let current_split timer =
5652 Some (Array.length splits)
5753
5854 let is_gold timer split_num =
59- match (current_split timer, segment_time timer split_num) with
55+ let now = Core_unix.gettimeofday () in
56+ match (current_split timer, segment_time ~now timer split_num) with
6057 | Some n, Some seg_time -> (
6158 if split_num >= n then false
6259 else
@@ -68,9 +65,9 @@ let is_gold timer split_num =
6865 let updated_golds timer =
6966 match timer.state with
7067 | Idle -> timer.golds
71- | Timing (splits, _, _) | Paused (splits, _, _, _) | Done (splits, _, _) ->
68+ | Timing (splits, _, now) | Paused (splits, _, _, now) | Done (splits, _, now) ->
7269 let seg_durations =
73- Array.mapi splits ~f:(fun i _ -> segment_time timer i)
70+ Array.mapi splits ~f:(fun i _ -> segment_time ~now timer i)
7471 in
7572 let old_durations = Array.map timer.golds ~f:(fun g -> g.duration) in
7673
--- a/src/splits.mli
+++ b/src/splits.mli
@@ -1,13 +1,13 @@
11 val is_gold : Timer_types.timer -> int -> bool
2-val ahead_by : Timer_types.timer -> ?now:float -> int -> int option
3-val segment_time : Timer_types.timer -> ?now:float -> int -> int option
2+val ahead_by : Timer_types.timer -> now:float -> int -> int option
3+val segment_time : Timer_types.timer -> now:float -> int -> int option
44 val archived_split_time : Timer_types.timer -> int -> int option
55 val archived_segment_time : Timer_types.timer -> int -> int option
66
77 val archive_done_run :
88 Timer_types.timer -> Duration.t option array -> Timer_types.archived_run
99
10-val split_time : Timer_types.timer -> ?now:float -> int -> int option
10+val split_time : Timer_types.timer -> now:float -> int -> int option
1111 val gold_sum : Timer_types.timer -> int -> int -> int option
1212 val updated_golds : Timer_types.timer -> Timer_types.gold array
1313 val updated_pb : Timer_types.timer -> Timer_types.archived_run option