change dt handling
This commit is contained in:
parent
fae2501b85
commit
41b86029e8
27
main.js
27
main.js
|
@ -150,20 +150,31 @@ async function run() {
|
||||||
const height = 50;
|
const height = 50;
|
||||||
const universe = Universe.new(width, height);
|
const universe = Universe.new(width, height);
|
||||||
|
|
||||||
const TIMEFACTOR = 1.0/7000;
|
const TIMEFACTOR = 20000.0;
|
||||||
let t = performance.now()*TIMEFACTOR;
|
const MAX_DT = 1.0/Math.max(width, height)/2.0;
|
||||||
|
|
||||||
|
let t = 0;
|
||||||
|
let first_draw = true;
|
||||||
|
let warn_time = -1;
|
||||||
|
|
||||||
universe.init(0.5, 0.5);
|
universe.init(0.5, 0.5);
|
||||||
|
|
||||||
function drawMe(t_draw) {
|
function drawMe(t_draw) {
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
let dt = t_draw*TIMEFACTOR - t;
|
let dt = (t_draw - t) / TIMEFACTOR;
|
||||||
if (dt >= 0.01) {
|
t = t_draw;
|
||||||
console.warn("Can not keep up with framerate");
|
if (first_draw || dt <= 0.0) {
|
||||||
t = t_draw*TIMEFACTOR;
|
first_draw = false;
|
||||||
dt = 0.01;
|
dt = MAX_DT;
|
||||||
} else {
|
} else {
|
||||||
t += dt;
|
if (dt >= MAX_DT) {
|
||||||
|
warn_time += 1;
|
||||||
|
if (warn_time != -2) {
|
||||||
|
console.warn("Can not keep up with framerate");
|
||||||
|
}
|
||||||
|
dt = MAX_DT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
universe.advance(dt);
|
universe.advance(dt);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue