-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.js
More file actions
64 lines (55 loc) · 1.58 KB
/
Time.js
File metadata and controls
64 lines (55 loc) · 1.58 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
define([
'goo/entities/systems/System',
'js/Game'
],
function (
System,
Game
){
"use strict";
function Time(goo){
this._ft = 1.0 / Time.fps; // forecasted dt
this._pFt = 1.0 / Time.fps; // previous forecasted dt
this._tr = 0.0; // trend
this._pTr = 0.0; // previous trend
this._avg = (2/(1 + Time.fps)); // dt average
this._maxFrame = this._ft * 10;
//this._accumulated = 0.0;
this.world = goo;
System.call(this, "Time", []);
};
Time.prototype = Object.create(System.prototype);
Time.contstructor = Time;
Time.fps = 60;
Time.dt = 1.0 / Time.fps; // smoothed dt
Time.fixedFPS = 60;
Time.fixedDT = 1.0 / Time.fixedFPS;
Time.time = 0.0;;
Time.timeScale = 1.0;
Time.alpha = 0.0;
Time.negAlpha = 0.0;
Time.accumulated = 0.0;
Time.prototype.process = function(entities, tpf){
if(tpf > this._maxFrame){tpf = this._maxFrame;}
this._pFt = this._ft;
this._pTr = this._tr;
this._ft = ((tpf * this._avg) + ((1-this._avg) * (this._pFt + this._pTr))) * Time.timeScale;
this._tr = ((this._ft - this._pFt) * this._avg) + ((1 - this._avg) * this._pTr);
Time.dt = this._ft + this._tr;
Time.time += Time.dt;
Game.raiseEvent("Update");
Time.accumulated += Time.dt;
while(Time.fixedDT < Time.accumulated){
Game.raiseEvent("FixedUpdate");
Time.accumulated -= Time.fixedDT;
}
Time.alpha = Time.accumulated / Time.fixedDT;
Time.negAlpha = 1 - Time.alpha;
if(Game.ammoWorld){
Game.ammoWorld.stepSimulation(tpf, Math.floor(Time.dt / Time.fixedDT)+1, Time.fixedDT);
Game.raiseEvent("AmmoUpdate");
}
Game.raiseEvent("LateUpdate");
};
return Time;
});