playcanvas
Version:
PlayCanvas WebGL game engine
268 lines (267 loc) • 7.68 kB
TypeScript
export type MiniStatsSizeOptions = {
/**
* - Width of the graph area.
*/
width: number;
/**
* - Height of the graph area.
*/
height: number;
/**
* - Spacing between graphs.
*/
spacing: number;
/**
* - Whether to show graphs.
*/
graphs: boolean;
};
export type MiniStatsProcessorOptions = {
/**
* - Whether to show the graph.
*/
enabled: boolean;
/**
* - Watermark - shown as a line on the graph, useful for displaying a
* budget.
*/
watermark: number;
};
export type MiniStatsGraphOptions = {
/**
* - Display name.
*/
name: string;
/**
* - Path to data inside Application.stats.
*/
stats: string[];
/**
* - Number of decimal places (defaults to none).
*/
decimalPlaces?: number;
/**
* - Units (defaults to "").
*/
unitsName?: string;
/**
* - Watermark - shown as a line on the graph, useful for displaying
* a budget.
*/
watermark?: number;
};
export type MiniStatsOptions = {
/**
* - Sizes of area to render individual graphs in and
* spacing between individual graphs.
*/
sizes: MiniStatsSizeOptions[];
/**
* - Index into sizes array for initial setting.
*/
startSizeIndex: number;
/**
* - Refresh rate of text stats in ms.
*/
textRefreshRate: number;
/**
* - CPU graph options.
*/
cpu: MiniStatsProcessorOptions;
/**
* - GPU graph options.
*/
gpu: MiniStatsProcessorOptions;
/**
* - Array of options to render additional graphs based
* on stats collected into Application.stats.
*/
stats: MiniStatsGraphOptions[];
};
/**
* @import { AppBase } from '../../framework/app-base.js'
* @import { GraphicsDevice } from '../../platform/graphics/graphics-device.js'
*/
/**
* @typedef {object} MiniStatsSizeOptions
* @property {number} width - Width of the graph area.
* @property {number} height - Height of the graph area.
* @property {number} spacing - Spacing between graphs.
* @property {boolean} graphs - Whether to show graphs.
*/
/**
* @typedef {object} MiniStatsProcessorOptions
* @property {boolean} enabled - Whether to show the graph.
* @property {number} watermark - Watermark - shown as a line on the graph, useful for displaying a
* budget.
*/
/**
* @typedef {object} MiniStatsGraphOptions
* @property {string} name - Display name.
* @property {string[]} stats - Path to data inside Application.stats.
* @property {number} [decimalPlaces] - Number of decimal places (defaults to none).
* @property {string} [unitsName] - Units (defaults to "").
* @property {number} [watermark] - Watermark - shown as a line on the graph, useful for displaying
* a budget.
*/
/**
* @typedef {object} MiniStatsOptions
* @property {MiniStatsSizeOptions[]} sizes - Sizes of area to render individual graphs in and
* spacing between individual graphs.
* @property {number} startSizeIndex - Index into sizes array for initial setting.
* @property {number} textRefreshRate - Refresh rate of text stats in ms.
* @property {MiniStatsProcessorOptions} cpu - CPU graph options.
* @property {MiniStatsProcessorOptions} gpu - GPU graph options.
* @property {MiniStatsGraphOptions[]} stats - Array of options to render additional graphs based
* on stats collected into Application.stats.
*/
/**
* MiniStats is a small graphical overlay that displays realtime performance metrics. By default,
* it shows CPU and GPU utilization, frame timings and draw call count. It can also be configured
* to display additional graphs based on data collected into {@link AppBase#stats}.
*/
export class MiniStats {
/**
* Returns the default options for MiniStats. The default options configure the overlay to
* show the following graphs:
*
* - CPU utilization
* - GPU utilization
* - Overall frame time
* - Draw call count
*
* @returns {object} The default options for MiniStats.
* @example
* const options = pc.MiniStats.getDefaultOptions();
*/
static getDefaultOptions(): object;
/**
* Create a new MiniStats instance.
*
* @param {AppBase} app - The application.
* @param {MiniStatsOptions} [options] - Options for the MiniStats instance.
* @example
* // create a new MiniStats instance using default options
* const miniStats = new pc.MiniStats(app);
*/
constructor(app: AppBase, options?: MiniStatsOptions);
wordAtlas: WordAtlas;
sizes: MiniStatsSizeOptions[];
_activeSizeIndex: number;
/**
* Sets the opacity of the MiniStats overlay.
*
* @type {number}
* @ignore
*/
set opacity(value: number);
/**
* Gets the opacity of the MiniStats overlay.
*
* @type {number}
* @ignore
*/
get opacity(): number;
/**
* Sets the active size index. Setting the active size index will resize the overlay to the
* size specified by the corresponding entry in the sizes array.
*
* @type {number}
* @ignore
*/
set activeSizeIndex(value: number);
/**
* Gets the active size index.
*
* @type {number}
* @ignore
*/
get activeSizeIndex(): number;
app: AppBase;
drawLayer: import("../../index.js").Layer;
device: GraphicsDevice;
render2d: Render2d;
div: HTMLDivElement;
width: number;
height: number;
gspacing: number;
clr: number[];
_enabled: boolean;
/**
* Destroy the MiniStats instance.
*
* @example
* miniStats.destroy();
*/
destroy(): void;
/**
* Gets the overall height of the MiniStats overlay.
*
* @type {number}
* @ignore
*/
get overallHeight(): number;
/**
* Sets the enabled state of the MiniStats overlay.
*
* @type {boolean}
*/
set enabled(value: boolean);
/**
* Gets the enabled state of the MiniStats overlay.
*
* @type {boolean}
*/
get enabled(): boolean;
/**
* Create the graphs requested by the user and add them to the MiniStats instance.
*
* @param {AppBase} app - The application.
* @param {GraphicsDevice} device - The graphics device.
* @param {object} options - Options for the MiniStats instance.
* @private
*/
private initGraphs;
graphs: any[];
texture: Texture;
/**
* Render the MiniStats overlay. This is called automatically when the `postrender` event is
* fired by the application.
*
* @private
*/
private render;
/**
* Resize the MiniStats overlay.
*
* @param {number} width - The new width.
* @param {number} height - The new height.
* @param {boolean} showGraphs - Whether to show the graphs.
* @private
*/
private resize;
/**
* Update the size and position of the MiniStats overlay. This is called automatically when the
* `resizecanvas` event is fired by the graphics device.
*
* @private
*/
private updateDiv;
/**
* Called when the graphics device is lost.
*
* @private
*/
private loseContext;
/**
* Called when the `postrender` event is fired by the application.
*
* @private
*/
private postRender;
}
import { WordAtlas } from './word-atlas.js';
import type { AppBase } from '../../framework/app-base.js';
import type { GraphicsDevice } from '../../platform/graphics/graphics-device.js';
import { Render2d } from './render2d.js';
import { Texture } from '../../platform/graphics/texture.js';