Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move AppBase constructor properties to class fields #6801

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 81 additions & 76 deletions src/framework/app-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,93 @@ class AppBase extends EventHandler {
* @returns {void}
*/

/** @private */
_destroyRequested = false;

/** @private */
_inFrameUpdate = false;

/** @private */
_time = 0;

/** @private */
_librariesLoaded = false;

/** @private */
_fillMode = FILLMODE_KEEP_ASPECT;

/** @private */
_resolutionMode = RESOLUTION_FIXED;

/** @private */
_allowResize = true;

/**
* A request id returned by requestAnimationFrame, allowing us to cancel it.
*
* @ignore
*/
frameRequestId;

/**
* Scales the global time delta. Defaults to 1.
*
* @type {number}
* @example
* // Set the app to run at half speed
* this.app.timeScale = 0.5;
*/
timeScale = 1;

/**
* Clamps per-frame delta time to an upper bound. Useful since returning from a tab
* deactivation can generate huge values for dt, which can adversely affect game state.
* Defaults to 0.1 (seconds).
*
* @type {number}
* @example
* // Don't clamp inter-frame times of 200ms or less
* this.app.maxDeltaTime = 0.2;
*/
maxDeltaTime = 0.1; // Maximum delta is 0.1s or 10 fps.

/**
* The total number of frames the application has updated since start() was called.
*
* @type {number}
* @ignore
*/
frame = 0;

/**
* When true, the application's render function is called every frame. Setting autoRender to
* false is useful to applications where the rendered image may often be unchanged over time.
* This can heavily reduce the application's load on the CPU and GPU. Defaults to true.
*
* @type {boolean}
* @example
* // Disable rendering every frame and only render on a keydown event
* this.app.autoRender = false;
* this.app.keyboard.on('keydown', (event) => {
* this.app.renderNextFrame = true;
* });
*/
autoRender = true;

/**
* Set to true to render the scene on the next iteration of the main loop. This only has an
* effect if {@link AppBase#autoRender} is set to false. The value of renderNextFrame is set
* back to false again as soon as the scene has been rendered.
*
* @type {boolean}
* @example
* // Render the scene only while space key is pressed
* if (this.app.keyboard.isPressed(pc.KEY_SPACE)) {
* this.app.renderNextFrame = true;
* }
*/
renderNextFrame = false;

/**
* Create a new AppBase instance.
*
Expand Down Expand Up @@ -163,87 +243,12 @@ class AppBase extends EventHandler {
setApplication(this);

app = this;

/** @private */
this._destroyRequested = false;

/** @private */
this._inFrameUpdate = false;

/** @private */
this._time = 0;

/**
* Scales the global time delta. Defaults to 1.
*
* @type {number}
* @example
* // Set the app to run at half speed
* this.app.timeScale = 0.5;
*/
this.timeScale = 1;

/**
* Clamps per-frame delta time to an upper bound. Useful since returning from a tab
* deactivation can generate huge values for dt, which can adversely affect game state.
* Defaults to 0.1 (seconds).
*
* @type {number}
* @example
* // Don't clamp inter-frame times of 200ms or less
* this.app.maxDeltaTime = 0.2;
*/
this.maxDeltaTime = 0.1; // Maximum delta is 0.1s or 10 fps.

/**
* The total number of frames the application has updated since start() was called.
*
* @type {number}
* @ignore
*/
this.frame = 0;

/**
* When true, the application's render function is called every frame. Setting autoRender
* to false is useful to applications where the rendered image may often be unchanged over
* time. This can heavily reduce the application's load on the CPU and GPU. Defaults to
* true.
*
* @type {boolean}
* @example
* // Disable rendering every frame and only render on a keydown event
* this.app.autoRender = false;
* this.app.keyboard.on('keydown', function (event) {
* this.app.renderNextFrame = true;
* }, this);
*/
this.autoRender = true;

/**
* Set to true to render the scene on the next iteration of the main loop. This only has an
* effect if {@link AppBase#autoRender} is set to false. The value of renderNextFrame
* is set back to false again as soon as the scene has been rendered.
*
* @type {boolean}
* @example
* // Render the scene only while space key is pressed
* if (this.app.keyboard.isPressed(pc.KEY_SPACE)) {
* this.app.renderNextFrame = true;
* }
*/
this.renderNextFrame = false;

this._librariesLoaded = false;
this._fillMode = FILLMODE_KEEP_ASPECT;
this._resolutionMode = RESOLUTION_FIXED;
this._allowResize = true;
}

/**
* Initialize the app.
*
* @param {AppOptions} appOptions - Options specifying the init
* parameters for the app.
* @param {AppOptions} appOptions - Options specifying the init parameters for the app.
*/
init(appOptions) {
const device = appOptions.graphicsDevice;
Expand Down
3 changes: 1 addition & 2 deletions src/framework/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ class ApplicationStats {
/**
* Create a new ApplicationStats instance.
*
* @param {GraphicsDevice} device - The
* graphics device.
* @param {GraphicsDevice} device - The graphics device.
*/
constructor(device) {
this.frame = {
Expand Down