浏览代码

Date.Now Tools Dependency

sebavan 6 年之前
父节点
当前提交
0350319fa2

+ 1 - 5
Tools/Config/tempCircularValidation/core.json

@@ -39,7 +39,6 @@
         "../../src/Materials/Textures/baseTexture.ts",
         "../../src/Materials/Textures/internalTexture.ts",
         "../../src/Materials/material.ts",
-        "../../src/Misc/performanceMonitor.ts",
         "../../src/Misc/promise.ts",
         "../../src/Misc/tools.ts",
         "../../src/PostProcesses/passPostProcess.ts"
@@ -151,9 +150,6 @@
         "../../src/Loading/sceneLoader.ts",
         "../../src/Misc/tools.ts"
     ],
-    "../../src/Misc/performanceMonitor.ts": [
-        "../../src/Misc/tools.ts"
-    ],
     "../../src/Misc/promise.ts": [
         "../../src/Misc/tools.ts"
     ],
@@ -235,5 +231,5 @@
         "../../src/Misc/tools.ts",
         "../../src/PostProcesses/postProcessManager.ts"
     ],
-    "errorCount": 118
+    "errorCount": 116
 }

+ 6 - 5
Viewer/src/loader/plugins/telemetryLoaderPlugin.ts

@@ -1,7 +1,8 @@
 import { ILoaderPlugin } from "./loaderPlugin";
 import { telemetryManager } from "../../managers/telemetryManager";
 import { ViewerModel } from "../../model/viewerModel";
-import { Tools, ISceneLoaderPlugin, ISceneLoaderPluginAsync } from "babylonjs";
+import { ISceneLoaderPlugin, ISceneLoaderPluginAsync } from "babylonjs";
+import { PrecisionDate } from "babylonjs/Misc/precisionDate";
 
 export class TelemetryLoaderPlugin implements ILoaderPlugin {
 
@@ -12,19 +13,19 @@ export class TelemetryLoaderPlugin implements ILoaderPlugin {
 
     public onInit(loader: ISceneLoaderPlugin | ISceneLoaderPluginAsync, model: ViewerModel) {
         this._model = model;
-        this._loadStart = Tools.Now;
+        this._loadStart = PrecisionDate.Now;
     }
 
     public onLoaded(model: ViewerModel) {
         telemetryManager.broadcast("Model Loaded", model.getViewerId(), {
             model: model,
-            loadTime: Tools.Now - this._loadStart
+            loadTime: PrecisionDate.Now - this._loadStart
         });
         telemetryManager.flushWebGLErrors(model.rootMesh.getEngine(), model.getViewerId());
     }
 
     public onError(message: string, exception: any) {
-        this._loadEnd = Tools.Now;
+        this._loadEnd = PrecisionDate.Now;
         telemetryManager.broadcast("Load Error", this._model.getViewerId(), {
             model: this._model,
             loadTime: this._loadEnd - this._loadStart
@@ -34,7 +35,7 @@ export class TelemetryLoaderPlugin implements ILoaderPlugin {
     }
 
     public onComplete() {
-        this._loadEnd = Tools.Now;
+        this._loadEnd = PrecisionDate.Now;
         telemetryManager.broadcast("Load Complete", this._model.getViewerId(), {
             model: this._model,
             loadTime: this._loadEnd - this._loadStart

+ 3 - 3
src/Behaviors/Cameras/autoRotationBehavior.ts

@@ -2,9 +2,9 @@ import { Behavior } from "../../Behaviors/behavior";
 import { Camera } from "../../Cameras/camera";
 import { ArcRotateCamera } from "../../Cameras/arcRotateCamera";
 import { Nullable } from "../../types";
-import { Tools } from "../../Misc/tools";
 import { Observer } from "../../Misc/observable";
 import { PointerInfoPre, PointerEventTypes } from "../../Events/pointerEvents";
+import { PrecisionDate } from "../../Misc/precisionDate";
 
     /**
      * The autoRotation behavior (AutoRotationBehavior) is designed to create a smooth rotation of an ArcRotateCamera when there is no user interaction.
@@ -122,7 +122,7 @@ import { PointerInfoPre, PointerEventTypes } from "../../Events/pointerEvents";
             });
 
             this._onAfterCheckInputsObserver = camera.onAfterCheckInputsObservable.add(() => {
-                let now = Tools.Now;
+                let now = PrecisionDate.Now;
                 let dt = 0;
                 if (this._lastFrameTime != null) {
                     dt =  now - this._lastFrameTime;
@@ -192,7 +192,7 @@ import { PointerInfoPre, PointerEventTypes } from "../../Events/pointerEvents";
          */
         private _applyUserInteraction(): void {
             if (this._userIsMoving() && !this._shouldAnimationStopForInteraction()) {
-                this._lastInteractionTime = Tools.Now;
+                this._lastInteractionTime = PrecisionDate.Now;
             }
         }
 

+ 3 - 2
src/Behaviors/Cameras/framingBehavior.ts

@@ -5,6 +5,7 @@ import { ExponentialEase, EasingFunction } from "../../Animations/easing";
 import { Nullable } from "../../types";
 import { PointerInfoPre, PointerEventTypes } from "../../Events/pointerEvents";
 import { Tools } from "../../Misc/tools";
+import { PrecisionDate } from "../../Misc/precisionDate";
 import { Observer } from "../../Misc/observable";
 import { AbstractMesh } from "../../Meshes/abstractMesh";
 import { Vector3, Vector2 } from "../../Maths/math";
@@ -430,7 +431,7 @@ import { Animation } from "../../Animations/animation";
                 return;
             }
 
-            let timeSinceInteraction = Tools.Now - this._lastInteractionTime;
+            let timeSinceInteraction = PrecisionDate.Now - this._lastInteractionTime;
             let defaultBeta = Math.PI * 0.5 - this._defaultElevation;
             let limitBeta = Math.PI * 0.5;
 
@@ -498,7 +499,7 @@ import { Animation } from "../../Animations/animation";
 		 */
         private _applyUserInteraction(): void {
             if (this.isUserIsMoving) {
-                this._lastInteractionTime = Tools.Now;
+                this._lastInteractionTime = PrecisionDate.Now;
                 this.stopAllAnimations();
                 this._clearAnimationLocks();
             }

+ 2 - 2
src/Misc/performanceMonitor.ts

@@ -1,5 +1,5 @@
 import { Nullable } from "../types";
-import { Tools } from "./tools";
+import { PrecisionDate } from "./precisionDate";
 
     /**
 	 * Performance monitor tracks rolling average frame-time and frame-time variance over a user defined sliding-window
@@ -22,7 +22,7 @@ import { Tools } from "./tools";
 		 * Samples current frame
 		 * @param timeMs A timestamp in milliseconds of the current frame to compare with other frames
 		 */
-        public sampleFrame(timeMs: number = Tools.Now) {
+        public sampleFrame(timeMs: number = PrecisionDate.Now) {
             if (!this._enabled) { return; }
 
             if (this._lastFrameTimeMs != null) {

+ 17 - 0
src/Misc/precisionDate.ts

@@ -0,0 +1,17 @@
+import { DomManagement } from './domManagement';
+
+/**
+ * Class containing a set of static utilities functions for precision date
+ */
+export class PrecisionDate {
+    /**
+     * Gets either window.performance.now() if supported or Date.now() else
+     */
+    public static get Now(): number {
+        if (DomManagement.IsWindowObjectExist() && window.performance && window.performance.now) {
+            return window.performance.now();
+        }
+
+        return Date.now();
+    }
+}

+ 5 - 8
src/Misc/tools.ts

@@ -15,6 +15,7 @@ import { DomManagement } from "./domManagement";
 import { Logger } from "./logger";
 import { _TypeStore } from "./typeStore";
 import { DeepCopier } from "./deepCopier";
+import { PrecisionDate } from './precisionDate';
 
 declare type Engine = import("../Engines/engine").Engine;
 
@@ -1801,11 +1802,7 @@ declare type Engine = import("../Engines/engine").Engine;
          * Gets either window.performance.now() if supported or Date.now() else
          */
         public static get Now(): number {
-            if (DomManagement.IsWindowObjectExist() && window.performance && window.performance.now) {
-                return window.performance.now();
-            }
-
-            return Date.now();
+            return PrecisionDate.Now;
         }
 
         /**
@@ -2029,7 +2026,7 @@ declare type Engine = import("../Engines/engine").Engine;
             if (!PerfCounter.Enabled) {
                 return;
             }
-            this._startMonitoringTime = Tools.Now;
+            this._startMonitoringTime = PrecisionDate.Now;
         }
 
         /**
@@ -2045,7 +2042,7 @@ declare type Engine = import("../Engines/engine").Engine;
                 this.fetchNewFrame();
             }
 
-            let currentTime = Tools.Now;
+            let currentTime = PrecisionDate.Now;
             this._current = currentTime - this._startMonitoringTime;
 
             if (newFrame) {
@@ -2063,7 +2060,7 @@ declare type Engine = import("../Engines/engine").Engine;
             this._average = this._totalAccumulated / this._totalValueCount;
 
             // Reset last sec?
-            let now = Tools.Now;
+            let now = PrecisionDate.Now;
             if ((now - this._lastSecTime) > 1000) {
                 this._lastSecAverage = this._lastSecAccumulated / this._lastSecValueCount;
                 this._lastSecTime = now;

+ 2 - 1
src/scene.ts

@@ -1,5 +1,6 @@
 import { Nullable } from "./types";
 import { IAnimatable, IFileRequest, Tools, PerfCounter } from "./Misc/tools";
+import { PrecisionDate } from "./Misc/precisionDate";
 import { Observable, Observer } from "./Misc/observable";
 import { SmartArrayNoDuplicate, SmartArray, ISmartArrayLike } from "./Misc/smartArray";
 import { StringDictionary } from "./Misc/stringDictionary";
@@ -2694,7 +2695,7 @@ import { EngineStore } from "./Engines/engineStore";
             }
 
             // Getting time
-            var now = Tools.Now;
+            var now = PrecisionDate.Now;
             if (!this._animationTimeLast) {
                 if (this._pendingData.length > 0) {
                     return;