From 07affcde4dbd6cde2cba310fab6c8fef837cece3 Mon Sep 17 00:00:00 2001
From: Marshall Quander <marshall@quander.me>
Date: Fri, 5 Oct 2018 14:45:35 -0700
Subject: [PATCH] Don't call Date.now in drawing tick

---
 src/components/tools/networked-drawing.js | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/components/tools/networked-drawing.js b/src/components/tools/networked-drawing.js
index 518de9cd8..833e0b97c 100644
--- a/src/components/tools/networked-drawing.js
+++ b/src/components/tools/networked-drawing.js
@@ -105,7 +105,7 @@ AFRAME.registerComponent("networked-drawing", {
     this.scene.remove(this.drawing);
   },
 
-  tick() {
+  tick(t) {
     const connected = NAF.connection.isConnected() && this.networkedEl;
     const isMine = connected && NAF.utils.isMine(this.networkedEl);
 
@@ -144,7 +144,7 @@ AFRAME.registerComponent("networked-drawing", {
       }
     }
 
-    this._deleteLines();
+    this._deleteExpiredLines(t);
   },
 
   _broadcastDrawing: (() => {
@@ -193,12 +193,11 @@ AFRAME.registerComponent("networked-drawing", {
     };
   })(),
 
-  _deleteLines() {
+  _deleteExpiredLines(time) {
     const length = this.networkBufferHistory.length;
     if (length > 0) {
-      const now = Date.now();
-      const time = this.networkBufferHistory[0].time;
-      if (length > this.data.maxLines || time + this.data.maxDrawTimeout <= now) {
+      const drawTime = this.networkBufferHistory[0].time;
+      if (length > this.data.maxLines || drawTime + this.data.maxDrawTimeout <= time) {
         const datum = this.networkBufferHistory[0];
         if (length > 1) {
           datum.idxLength += 2 - (this.segments % 2);
@@ -388,7 +387,7 @@ AFRAME.registerComponent("networked-drawing", {
     const datum = {
       networkBufferCount: this.networkBufferCount,
       idxLength: this.vertexCount - 1,
-      time: Date.now()
+      time: this.el.sceneEl.clock.elapsedTime * 1000
     };
     this.networkBufferHistory.push(datum);
     this.vertexCount = 0;
-- 
GitLab