Skip to content

Commit

Permalink
better renderloop
Browse files Browse the repository at this point in the history
  • Loading branch information
Spiri0 committed Sep 15, 2024
1 parent c645ae9 commit ae17b28
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,33 +106,31 @@ class Main extends entity.Entity{
this.camera_.position.set(0, 0, 0);
}



RAF() {

const dstFPS = 40;
const fpsInterval = 1000 / dstFPS;

requestAnimationFrame(() => {
const now = performance.now();
const elapsed = now - this.then;

if(elapsed > fpsInterval) {

this.then = now - (elapsed % fpsInterval);

requestAnimationFrame((t) => {

if (this.previousRAF === null) {
this.previousRAF = t;
} else {
/*
const cameraDistance = this.camera_.position.length();
if(cameraDistance >= 5000){
this.MoveCameraToOrigin();
}

this.Step(elapsed);
this.threejs_.Render();
}
*/
const deltaTime = (t - this.previousRAF);
this.Step(deltaTime);
this.threejs_.Render();
this.previousRAF = t;
}

this.RAF();
});
}


this.RAF();
});
}


Step(timeElapsed) {
Expand Down

0 comments on commit ae17b28

Please sign in to comment.