jhaakma / ashfall

Ashfall is a survival, camping and needs mod for Morrowind. It uses the latest in MWSE Lua scripting functionality to implement a wide range of mechanics that integrate seamlessly into the game and provide a truly immersive experience.
23 stars 6 forks source link

[tentController] Performance-friendly tentSimulate() #19

Closed stanleyqubit closed 10 months ago

stanleyqubit commented 2 years ago

Hey mer, awesome mod 👍 just an itsy-bitsy issue I'm experiencing with it on my modest machine.

In its current state, tentSimulate() in tentController.lua will begin to cullRain() even if it's not currently raining. Rain culling also occurs independently of whether you are inside or outside the tent. Traversing over the entire sceneRainRoot can be a little too hardware-intensive when there's 3000 niNodes to traverse over on every frame (that's the Max Raindrops value for [Weather Thunderstorm] in my morrowind.ini)

The main reason behind this PR is to make tentSimulate() have less of an impact on FPS when having an ashfall modular tent up and active.

Proposed changes:

  1. Add extra checks before calling cullRain():

    • common.data.insideTent (rain culling only makes sense when inside the tent imo, thus no impact on framerate when not sheltered inside the tent)
    • check if it's currently raining or about to rain (need this for what comes next, because we're only going to cull rain particles)
  2. Switch from traversing over tes3.worldController.weatherController.sceneRainRoot to iterating over tes3.worldController.weatherController.particlesActive (Same result, but with less computation. At least, this is what I'm seeing at first glance. Huge FPS gain on my end.)

Apologies if mistaken, I'm sort of a novice at modding and lua.