Custom active mesh determining?

Hi everyone!

Quick question; I am trying to optimize my server code once again for cpu usage. It is a bit difficult since with Bun I cannot get a debug inspect mode that I used to rely on with Node. Also JavaScriptCode might behave a bit differently than V8. But anyways…

I am running null engine and the engine instrumentation gives me
Active Meshes Evaluation: 4.60ms

This is not that much, server is running 20tick per second so there is 50ms time to handle the frame. I’m just wondering if this number is correct since my assumption would be that null engine is not checking the active meshes, since pretty much every mesh should be active as the server acts more as an all seeing eye…

But the number still worries me since it might be costly to cpu.

What I would like to be able to do:

  • Tell globally to the scene that I want all the meshes to be active OR
  • Customize the activity checking so that it is very simple like “mark active if near player” (can frame graph do this?)

I think you can also mark meshes individually as always active, but does this work with hierarchial meshes? Also, my server engine has the performance priority set as aggressive.

Here are things I have done so far & my initialization code:

    console.time('server-game-manager: null-engine-booted')
    const options: NullEngineOptions = {
      renderHeight: 0,
      renderWidth: 0,
      textureSize: 0,
      lockstepMaxSteps: 4,
      deterministicLockstep: true,
      timeStep: 1 / 20,
    }
    this.engine = new NullEngine(options)
    console.log('server-game-manager: null engine time step', this.engine.getTimeStep())
    this.engine.disablePerformanceMonitorInBackground = false

    this.scene = new Scene(this.engine)
    this.scene.skipPointerMovePicking = true
    this.scene.autoClear = false
    this.scene.useRightHandedSystem = true
    this.scene.performancePriority = ScenePerformancePriority.Aggressive
    this.scene.skipFrustumClipping = true // If you don't need precise culling
    this.scene.freezeActiveMeshes(true)

    // Camera
    this.camera = createCamera(this.scene)
    console.timeEnd('server-game-manager: null-engine-booted')
1 Like

cc @sebavan

1 Like

evaluateActiveMeshes is indeed working as it is the one pushing everything to the next steps and so on.

Your setup sounds good.

Did it not improve the perfs enough ?

1 Like

The current setup gives the value 4.60ms of active mesh evaluation, but I thought this step should be 0ms since all the meshes should be active? I mean, what do we evaluate in the server with null engine?

We still need to do all the work at least once :frowning: to compute all matrices and such.

1 Like

I do understand that the function needs to run, but what I mean is that I would want everything to be active in the server using null engine, so that I would not need to mark everything with alwaysSelectAsActiveMesh… So that the processing time for the active mesh calculation would be 0, right?

I found out some meshes now that seemed to not have alwaysSelectAsActiveMesh = true that slowed down the cpu alot… I think I have to double check all the other mesh creation places now, I just wished there was something like scene.everyMeshIsActive = true globally :smiley: But after finding out those meshes the calculation time is 0.4ms and CPU processing is pretty ok now!

1 Like

I see, do you want to make a PR to add a static for the default value of alwaysSelectAsActiveMesh ? This way you could control it in your app.

Do you mean skipFrustumClipping?

a cartoon of homer simpson standing in a grassy area

Would be nice but I think I can live with setting it individually. I also had a silly mistake of having also hand meshes included for my server side mesh code, instead of just the main body. So this caused the 100 meshes that I want to always be active, to have 200 hand meshes that went through the active mesh evaluation…

Thanks for all the support though :smiling_face_with_three_hearts:

I have this already in there and not sure if it does anything…

1 Like