forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime.js
More file actions
64 lines (59 loc) · 1.72 KB
/
time.js
File metadata and controls
64 lines (59 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
pc.extend(pc, (function () {
/**
* @private
* @constructor
* @name pc.Timer
* @description Create a new Timer instance.
* @classdesc A Timer counts milliseconds from when start() is called until when stop() is called.
*/
var Timer = function Timer() {
this._isRunning = false;
this._a = 0;
this._b = 0;
};
Timer.prototype = {
/**
* @private
* @function
* @name pc.Timer#start
* @description Start the timer
*/
start: function () {
this._isRunning = true;
this._a = pc.now();
},
/**
* @private
* @function
* @name pc.Timer#stop
* @description Stop the timer
*/
stop: function() {
this._isRunning = false;
this._b = pc.now();
},
/**
* @private
* @function
* @name pc.Timer#getMilliseconds
* @description Get the number of milliseconds that passed between start() and stop() being called
* @returns {Number} The elapsed milliseconds.
*/
getMilliseconds: function() {
return this._b - this._a;
}
};
return {
Timer: Timer,
/**
* @private
* @function
* @name pc.now
* @description Get current time in milliseconds. Use it to measure time difference. Reference time may differ on different platforms.
* @returns {Number} The time in milliseconds
*/
now: (!window.performance || !window.performance.now || !window.performance.timing)? Date.now : function () {
return window.performance.now();
}
};
}()));