- Counts frames per second from the running app, and keeps the last 5 one-second samples.
- Singleton.
import { FPSCounter } from 'ohzi-components'gives you the instance, so don't callnew. - PerformanceController reads it to adjust the DPR.
-
init(time): Initialize component.time: Time fromohzi-core. Seconds are counted ontime.elapsed_time.
-
update(): Should be called in anupdatemethod, once per frame. -
reset(): Setsfpsand every sample back to 60.
fps: Frames counted during the last full second.avg: Getter. Average of the last 5 samples.fps_samples: The last 5 one-second counts, oldest first. Starts as[60, 60, 60, 60, 60].
import { Time } from 'ohzi-core';
import { FPSCounter } from 'ohzi-components';
FPSCounter.init(Time);
// In your update loop
FPSCounter.update();
fps_label.textContent = `${FPSCounter.fps} fps (avg ${Math.round(FPSCounter.avg)})`;- Don't call
update()yourself when a PerformanceController is running. Itsupdate()already calls it, and a second call doubles the count. - The samples start at 60, so
avgtakes about 5 seconds to reflect the real framerate.