Running null engine on specific framerate

Hi everyone!

Quick question! I’m running NullEngine server side with Bun, and I’m trying to optimize my CPU usage, since servers cost money :money_with_wings:

I’m struggling to understand how to run the render loop correctly with lower fps. Usually the loop target I guess is 60fps, but I would like to try it 20fps so I guess the cpu time would be less.

Here is the basic initialization code I use now to try and get things 20fps:

const options: NullEngineOptions = {
  renderHeight: 0,
  renderWidth: 0,
  textureSize: 0,
  lockstepMaxSteps: 4,
  deterministicLockstep: true,
  timeStep: 1 / 20,
}
this.engine = new NullEngine(options)
this.scene.executeWhenReady(async () => {
  this.engine.runRenderLoop(() => {
     // Run logic systems here
     
     // This prints ~30-34
     console.log(this.engine.getFps().toFixed())
    
     // Render
     this.scene.render(false, false)
  })
})

Can someone instruct how I would manage to do this, would be fun to try something like running the server 10fps and see what happens :smiley: I am also using physics and recast navigation on server side.

It seems that whatever I now do, the engine.getFps() seems unchanged… Also, is the this.engine.maxFPS = 20 not usable in the null engine?

Thanks in advance :pray:

Hey there! The NullEngine has no access to WebGL or window or document objects.
So it simply calls the renderLoop every 16ms :slight_smile:

If you do not want that, you can simply skip calling runRenderLoop and instead call this when you want:

engine.beginFrame();
// This prints ~30-34
console.log(this.engine.getFps().toFixed())
    
// Render
this.scene.render(false, false);
engine.endFrame();
1 Like

Oh the beginFrame and endFrame did the trick, now I have a custom loop setup and it works! :star_struck: Thanks Delta :slight_smile:

1 Like