You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
for (size_t i = 1; i < m_controller_history.size(); i++){ // start at index i = 1, since prev_snapshot starts at i=0 and we continue when current == previous.
@@ -542,10 +543,42 @@ JsonValue RecordKeyboardController::controller_history_to_json(Logger& logger, C
542
543
continue;
543
544
}
544
545
545
-
// cout << time_stamp << endl;
546
-
// cout << prev_time_stamp << endl;
547
-
auto elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(time_stamp - prev_time_stamp); // might need to figure out how rounding works.
546
+
// Normalize each time stamp relative to the initial time stamp, and round to milliseconds.
547
+
// When only considering the distance between adjacent timestamps, you end up with drift due to rounding from nanoseconds to milliseconds,
548
+
549
+
// example:
550
+
// Timestamps Diff only comparing adjacent Total time since start
551
+
// 12:00 1ns 1.4ns -> 1ms 0ms
552
+
// 12:00 1401ns 1.4ns -> 1ms 1ms
553
+
// 12:00 2801ns 1.4ns -> 1ms 2ms
554
+
// 12:00 4201ns 1.4ns -> 1ms 3ms
555
+
// 12:00 5601ns 1.4ns -> 1ms 4ms
556
+
// 12:00 7001ns 1.4ns -> 1ms 5ms
557
+
// 12:00 8401ns 1.4ns -> 1ms 6ms
558
+
// 12:00 9801ns 1.4ns -> 1ms 7ms
559
+
// 12:00 11201ns 8ms
560
+
// total time elapsed: 11.201ms vs 8ms
561
+
562
+
// Normalized timestamps Diff using normalized timestamps Total time since start
563
+
// 0ns 1ms 0ms
564
+
// 1.4ms -> 1ms 2ms 1ms
565
+
// 2.8ms -> 3ms 1ms 3ms
566
+
// 4.2ms -> 4ms 2ms 4ms
567
+
// 5.6ms -> 6ms 1ms 6ms
568
+
// 7.0ms -> 7ms 1ms 7ms
569
+
// 8.4ms -> 8ms 2ms 8ms
570
+
// 9.8ms -> 10ms 1ms 10ms
571
+
// 11.2ms -> 11ms 11ms
572
+
// total time elapsed: 11.201ms vs 11ms
573
+
574
+
575
+
Milliseconds current_timestamp_time_since_start =
576
+
std::chrono::round<Milliseconds>(std::chrono::duration_cast<std::chrono::nanoseconds>(time_stamp - initial_time_stamp)); // find the time difference as nanoseconds, then round to milliseconds
0 commit comments