Browse Source

extract now calculation in clock

simonThiele 10 years ago
parent
commit
899595bb2a
1 changed files with 10 additions and 6 deletions
  1. 10 6
      src/core/Clock.js

+ 10 - 6
src/core/Clock.js

@@ -20,9 +20,7 @@ THREE.Clock.prototype = {
 
 	start: function () {
 
-		this.startTime = self.performance !== undefined && self.performance.now !== undefined
-					 ? self.performance.now()
-					 : Date.now();
+		this.startTime = this.getNow();
 
 		this.oldTime = this.startTime;
 		this.running = true;
@@ -55,9 +53,7 @@ THREE.Clock.prototype = {
 
 		if ( this.running ) {
 
-			var newTime = self.performance !== undefined && self.performance.now !== undefined
-					 ? self.performance.now()
-					 : Date.now();
+			var newTime = this.getNow();
 
 			diff = 0.001 * ( newTime - this.oldTime );
 			this.oldTime = newTime;
@@ -68,6 +64,14 @@ THREE.Clock.prototype = {
 
 		return diff;
 
+	},
+
+	getNow: function () {
+		var now = self.performance !== undefined && self.performance.now !== undefined
+			? self.performance.now()
+			: Date.now();
+
+		return now;
 	}
 
 };