sej
    Preparing search index...

    Class Optimizer

    The optimizer tracks the amount of time spent between frames or between calls to begin and end and calculates the difference between the target amount of time to spend and the actual time spent on the last frame.

    After the specified amount of time has passed the average time spent is calculated and the framerate the amount of work is either increased or decreased depending on whether or not the time spent was above or below the target.

    The amount of work is adjusted by iteratively calling prioritized optimizations and sampling framerate until the target work time is met.

    Index

    Constructors

    Properties

    beginTime: number

    The timestamp indicating when the optimization process begins. Represented as the number of milliseconds elapsed since the UNIX epoch.

    completed: boolean

    Whether or not the optimizer has stopped iterating and sampling the framerate.

    currOptimization: number

    The current optimization level or state. This value represents the current stage or level of optimization being applied.

    currPriority: null | number

    The current priority level of the optimizer. This can be a number representing the priority or null if no priority is set.

    elapsedFrames: number

    The number of frames that have elapsed since the start of the optimization process.

    elapsedTime: number

    The amount of time that has elapsed, in milliseconds.

    maxPriority: number
    minPriority: number

    The minimum priority level for the optimizer. This value determines the lowest priority task that the optimizer will consider.

    optimizations: { [key: number]: Optimization[] }

    A dictionary where the key is a number representing an optimization level and the value is an array of Optimization objects associated with that level.

    See OptimizerOptions for more information.

    waitedFrames: number

    The number of frames that have been waited. This property keeps track of how many frames have passed while waiting for a certain condition or event.

    waitedMillis: number

    The number of milliseconds that the optimizer has waited. This value is used to track the waiting time for certain operations.

    Accessors

    • get enabled(): boolean

      Getter and setter for enabling or disabling the optimizer. Elapsed time is reset on reenable.

      Returns boolean

    • set enabled(val: boolean): void

      Getter and setter for enabling or disabling the optimizer. Elapsed time is reset on reenable.

      Parameters

      • val: boolean

      Returns void

    Methods

    • Adds an optimization to the optimizer with an optional priority.

      Parameters

      • optimization: Optimization

        The optimization to add. Can be an instance of Optimization or a function.

      • priority: number = 0

        The priority of the optimization. Defaults to 0 if not provided.

        If the optimization parameter is a function, it will be wrapped in an Optimization instance. The priority is parsed as an integer and defaults to 0 if parsing fails. The optimization is then added to the internal optimizations list at the specified priority. The minPriority and maxPriority properties are updated accordingly.

      Returns void

    • Adds a sample time to the optimizer and performs optimization logic.

      Parameters

      • sampleTime: number

        The time of the sample to add, in milliseconds.

        This method performs the following steps:

        1. Checks if the optimizer is enabled, the window is focused, and the optimization is not completed.
        2. Waits for the required number of frames and milliseconds between calls.
        3. Increments the elapsed time and frame count.
        4. If the elapsed time or frame count exceeds the specified interval or maximum frame samples, it calculates the average frame time and determines if optimization is needed.
        5. Depending on whether the optimizer is currently increasing or decreasing work, it adjusts the priority and performs optimization iterations.
        6. Resets the elapsed time and frame count, and sets the wait time for the next call.

      Returns void

    • Disposes of the optimizer by removing event listeners for window blur and focus events. This helps to clean up resources and prevent memory leaks when the optimizer is no longer needed.

      Returns void

    • Restarts the optimizer by resetting its state.

      This method performs the following actions:

      • Resets any checks by calling resetCheck().
      • Sets the _increasingWork property to the value of options.increaseWork.
      • Sets currPriority to null.
      • Resets currOptimization to 0.
      • Marks the optimizer as not completed by setting completed to false.

      Returns void

    • Updates the optimizer by ending the current process and beginning a new one. This method ensures that any ongoing operations are properly terminated before starting a new operation cycle.

      Returns void