From 64d1775bd5bc725ef5e881aad55219f0d3ba2b47 Mon Sep 17 00:00:00 2001 From: "Raoul v. R" Date: Sun, 1 Jan 2023 20:15:21 +0100 Subject: [PATCH 1/3] Update Timer API --- src/core/EffectComposer.js | 7 +- src/core/Timer.js | 173 +++++++++---------------------------- types/postprocessing.d.ts | 78 +++++------------ 3 files changed, 63 insertions(+), 195 deletions(-) diff --git a/src/core/EffectComposer.js b/src/core/EffectComposer.js index 80c69eabc..37fbeba89 100644 --- a/src/core/EffectComposer.js +++ b/src/core/EffectComposer.js @@ -592,7 +592,8 @@ export class EffectComposer { if(deltaTime === undefined) { - deltaTime = this.timer.update().getDelta(); + this.timer.update(); + deltaTime = this.timer.delta; } @@ -685,10 +686,10 @@ export class EffectComposer { reset() { - const autoReset = this.timer.isAutoResetEnabled(); + const autoReset = this.timer.autoReset; this.dispose(); this.autoRenderToScreen = true; - this.timer.setAutoResetEnabled(autoReset); + this.timer.autoReset = autoReset; } diff --git a/src/core/Timer.js b/src/core/Timer.js index 9d06fa80b..4a9542a96 100644 --- a/src/core/Timer.js +++ b/src/core/Timer.js @@ -42,35 +42,35 @@ export class Timer { * * @type {Number} * @private + * @see {@link delta} */ - this.delta = 0; + this._delta = 0; /** - * The fixed time step in milliseconds. - * - * Default is 16.667 (60 fps). + * The total elapsed time in milliseconds. * * @type {Number} * @private + * @see {@link elapsed} */ - this.fixedDelta = 1000.0 / 60.0; + this._elapsed = 0; /** - * The total elapsed time in milliseconds. + * The fixed time step in milliseconds. Default is 16.667 (60 fps). * * @type {Number} * @private + * @see {@link fixedDelta} */ - this.elapsed = 0; + this._fixedDelta = 1000.0 / 60.0; /** * The timescale. * * @type {Number} - * @private */ this.timescale = 1.0; @@ -79,65 +79,41 @@ export class Timer { * Determines whether this timer should use a fixed time step. * * @type {Boolean} - * @private */ - this.fixedDeltaEnabled = false; + this.useFixedDelta = false; /** - * Indicates whether auto reset is enabled. - * * @type {Boolean} * @private + * @see {@link autoReset} */ - this.autoReset = false; + this._autoReset = false; } /** - * Enables or disables the fixed time step. + * Enables or disables auto reset based on page visibility. * - * @param {Boolean} enabled - Whether the fixed delta time should be used. - * @return {Timer} This timer. - */ - - setFixedDeltaEnabled(enabled) { - - this.fixedDeltaEnabled = enabled; - return this; - - } - - /** - * Indicates whether auto reset is enabled. + * If enabled, the timer will be reset when the page becomes visible. This effectively pauses the timer when the page + * is hidden. Has no effect if the API is not supported. * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API} - * @return {Boolean} Whether the timer will be reset on visibility change. + * @type {Boolean} + * @see https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API */ - isAutoResetEnabled(enabled) { + get autoReset() { - return this.autoReset; + return this._autoReset; } - /** - * Enables or disables auto reset based on page visibility. - * - * If enabled, the timer will be reset when the page becomes visible. This effectively pauses the timer when the page - * is hidden. Has no effect if the API is not supported. - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API} - * @param {Boolean} enabled - Whether the timer should be reset on visibility change. - * @return {Timer} This timer. - */ - - setAutoResetEnabled(enabled) { + set autoReset(value) { if(typeof document !== "undefined" && document.hidden !== undefined) { - if(enabled) { + if(value) { document.addEventListener("visibilitychange", this); @@ -147,141 +123,74 @@ export class Timer { } - this.autoReset = enabled; + this._autoReset = value; } - return this; - } - /** - * Returns the delta time. - * - * @return {Number} The delta time in seconds. - */ + get delta() { - getDelta() { - - return this.delta * MILLISECONDS_TO_SECONDS; + return this._delta * MILLISECONDS_TO_SECONDS; } - /** - * Returns the fixed delta time. - * - * @return {Number} The fixed delta time in seconds. - */ - - getFixedDelta() { + get fixedDelta() { - return this.fixedDelta * MILLISECONDS_TO_SECONDS; + return this._fixedDelta * MILLISECONDS_TO_SECONDS; } - /** - * Sets the fixed delta time. - * - * @param {Number} fixedDelta - The delta time in seconds. - * @return {Timer} This timer. - */ - - setFixedDelta(fixedDelta) { - - this.fixedDelta = fixedDelta * SECONDS_TO_MILLISECONDS; - return this; - - } - - /** - * Returns the elapsed time. - * - * @return {Number} The elapsed time in seconds. - */ - - getElapsed() { - - return this.elapsed * MILLISECONDS_TO_SECONDS; - - } - - /** - * Returns the timescale. - * - * @return {Number} The timescale. - */ - - getTimescale() { + set fixedDelta(value) { - return this.timescale; + this._fixedDelta = value * SECONDS_TO_MILLISECONDS; } - /** - * Sets the timescale. - * - * @param {Number} timescale - The timescale. - * @return {Timer} This timer. - */ + get elapsed() { - setTimescale(timescale) { - - this.timescale = timescale; - return this; + return this._elapsed * MILLISECONDS_TO_SECONDS; } /** * Updates this timer. * - * @param {Number} [timestamp] - The current time in milliseconds. - * @return {Timer} This timer. + * @param {Boolean} [timestamp] - The current time in milliseconds. */ update(timestamp) { - if(this.fixedDeltaEnabled) { + if(this.useFixedDelta) { - this.delta = this.fixedDelta; + this._delta = this.fixedDelta; } else { this.previousTime = this.currentTime; this.currentTime = (timestamp !== undefined) ? timestamp : performance.now(); - this.delta = this.currentTime - this.previousTime; + this._delta = this.currentTime - this.previousTime; } - this.delta *= this.timescale; - this.elapsed += this.delta; - - return this; + this._delta *= this.timescale; + this._elapsed += this._delta; } /** * Resets this timer. - * - * @return {Timer} This timer. */ reset() { - this.delta = 0; - this.elapsed = 0; + this._delta = 0; + this._elapsed = 0; this.currentTime = performance.now(); - return this; - } - /** - * Handles events. - * - * @param {Event} event - The event. - */ - - handleEvent(event) { + handleEvent(e) { if(!document.hidden) { @@ -292,13 +201,9 @@ export class Timer { } - /** - * Disposes this timer. - */ - dispose() { - this.setAutoResetEnabled(false); + this.autoReset = false; } diff --git a/types/postprocessing.d.ts b/types/postprocessing.d.ts index 2b8919ecd..0b701fd27 100644 --- a/types/postprocessing.d.ts +++ b/types/postprocessing.d.ts @@ -5060,91 +5060,53 @@ declare module "postprocessing" { * * @experimental Temporary substitute for {@link https://github.com/mrdoob/three.js/pull/17912} * @implements {Disposable} + * @implements {EventListenerObject} */ - export class Timer implements Disposable { + export class Timer implements Disposable, EventListenerObject { /** - * Enables or disables the fixed time step. - * - * @param {Boolean} enabled - Whether the fixed delta time should be used. - * @return {Timer} This timer. + * The current delta time in seconds. */ - setFixedDeltaEnabled(enabled: boolean): Timer; + get delta(): number; /** - * Indicates whether auto reset is enabled. - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API} - * @return {Boolean} Whether the timer will be reset on visibility change. + * The fixed delta time in seconds. */ - isAutoResetEnabled(): boolean; + get fixedDelta(): number; + set fixedDelta(value: number); /** - * Enables or disables auto reset based on page visibility. - * - * If enabled, the timer will be reset when the page becomes visible. This effectively pauses the timer when the page - * is hidden. Has no effect if the API is not supported. - * - * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API} - * @param {Boolean} enabled - Whether the timer should be reset on visibility change. - * @return {Timer} This timer. - */ - setAutoResetEnabled(enabled: boolean): Timer; - /** - * Returns the delta time. - * - * @return {Number} The delta time in seconds. - */ - getDelta(): number; - /** - * Returns the fixed delta time. - * - * @return {Number} The fixed delta time in seconds. + * The elapsed time in seconds. */ - getFixedDelta(): number; + get elapsed(): number; /** - * Sets the fixed delta time. - * - * @param {Number} fixedDelta - The delta time in seconds. - * @return {Timer} This timer. + * Determines whether this timer should use a fixed time step. */ - setFixedDelta(fixedDelta: number): Timer; + useFixedDelta: boolean; /** - * Returns the elapsed time. - * - * @return {Number} The elapsed time in seconds. + * The timescale. */ - getElapsed(): number; + timescale: number; /** - * Returns the timescale. + * Enables or disables auto reset based on page visibility. * - * @return {Number} The timescale. - */ - getTimescale(): number; - /** - * Sets the timescale. + * If enabled, the timer will be reset when the page becomes visible. This effectively pauses the timer when the page + * is hidden. Has no effect if the API is not supported. * - * @param {Number} timescale - The timescale. - * @return {Timer} This timer. + * @see https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API */ - setTimescale(timescale: number): Timer; + get autoReset(): boolean; + set autoReset(value: boolean); /** * Updates this timer. * * @param {Number} [timestamp] - The current time in milliseconds. - * @return {Timer} This timer. */ - update(timestamp?: number): Timer; + update(timestamp?: number): void; /** * Resets this timer. * * @return {Timer} This timer. */ reset(): Timer; - /** - * Handles events. - * - * @param {Event} event - The event. - */ - handleEvent(event: Event): void; /** * Disposes this timer. */ From a7742ca298a4d189e76445beeb02eb6a62665c4d Mon Sep 17 00:00:00 2001 From: "Raoul v. R" Date: Sun, 1 Jan 2023 20:16:29 +0100 Subject: [PATCH 2/3] Update pnpm-lock.yaml --- pnpm-lock.yaml | 66 +++++++++++++++++++++++++------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 92e1c97c1..820d80c31 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -40,9 +40,9 @@ specifiers: devDependencies: '@tweakpane/core': 1.1.1 - '@types/three': 0.146.0 - '@typescript-eslint/eslint-plugin': 5.47.1_txmweb6yn7coi7nfrp22gpyqmy - '@typescript-eslint/parser': 5.47.1_lzzuuodtsqwxnvqeq4g4likcqa + '@types/three': 0.147.1 + '@typescript-eslint/eslint-plugin': 5.47.1_axni7f4fgvh6tlufnh6hwgsifq + '@typescript-eslint/parser': 5.47.1_iukboom6ndih5an6iafl45j2fe autoprefixer: 10.4.13_postcss@8.4.20 ava: 5.1.0 copyfiles: 2.4.1 @@ -55,9 +55,9 @@ devDependencies: esdoc: 1.1.0 esdoc-importpath-plugin: 1.0.2 esdoc-standard-plugin: 1.0.0 - eslint: 8.30.0 + eslint: 8.31.0 eslint-config-aether: 1.5.1 - eslint-watch: 8.0.0_eslint@8.30.0 + eslint-watch: 8.0.0_eslint@8.31.0 gzipper: 7.2.0 hugo-bin: 0.97.0 npm-run-all: 4.1.5 @@ -452,8 +452,8 @@ packages: dev: true optional: true - /@eslint/eslintrc/1.4.0: - resolution: {integrity: sha512-7yfvXy6MWLgWSFsLhz5yH3iQ52St8cdUY6FoGieKkRDVxuxmrNuUetIuu6cmjNWwniUHiWXjxCr5tTXDrbYS5A==} + /@eslint/eslintrc/1.4.1: + resolution: {integrity: sha512-XXrH9Uarn0stsyldqDYq8r++mROmWRI1xKMXa640Bb//SY1+ECYX6VzT6Lcx5frD0V30XieqJ0oX9I2Xj5aoMA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dependencies: ajv: 6.12.6 @@ -567,8 +567,8 @@ packages: resolution: {integrity: sha512-21cFJr9z3g5dW8B0CVI9g2O9beqaThGQ6ZFBqHfwhzLDKUxaqTIy3vnfah/UPkfOiF2pLq+tGz+W8RyCskuslw==} dev: true - /@types/three/0.146.0: - resolution: {integrity: sha512-75AgysUrIvTCB054eQa2pDVFurfeFW8CrMQjpzjt3yHBfuuknoSvvsESd/3EhQxPrz9si3+P0wiDUVsWUlljfA==} + /@types/three/0.147.1: + resolution: {integrity: sha512-1dGYrF9E7frAXu3CRUYtTFj97PlA/Q0OedDQBROn3fKjtKXNhXc6/VNgkGod3axJMeNPNFDa6ur9eOcQ+aD0zw==} dependencies: '@types/webxr': 0.5.0 dev: true @@ -577,7 +577,7 @@ packages: resolution: {integrity: sha512-IUMDPSXnYIbEO2IereEFcgcqfDREOgmbGqtrMpVPpACTU6pltYLwHgVkrnYv0XhWEcjio9sYEfIEzgn3c7nDqA==} dev: true - /@typescript-eslint/eslint-plugin/5.47.1_txmweb6yn7coi7nfrp22gpyqmy: + /@typescript-eslint/eslint-plugin/5.47.1_axni7f4fgvh6tlufnh6hwgsifq: resolution: {integrity: sha512-r4RZ2Jl9kcQN7K/dcOT+J7NAimbiis4sSM9spvWimsBvDegMhKLA5vri2jG19PmIPbDjPeWzfUPQ2hjEzA4Nmg==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -588,12 +588,12 @@ packages: typescript: optional: true dependencies: - '@typescript-eslint/parser': 5.47.1_lzzuuodtsqwxnvqeq4g4likcqa + '@typescript-eslint/parser': 5.47.1_iukboom6ndih5an6iafl45j2fe '@typescript-eslint/scope-manager': 5.47.1 - '@typescript-eslint/type-utils': 5.47.1_lzzuuodtsqwxnvqeq4g4likcqa - '@typescript-eslint/utils': 5.47.1_lzzuuodtsqwxnvqeq4g4likcqa + '@typescript-eslint/type-utils': 5.47.1_iukboom6ndih5an6iafl45j2fe + '@typescript-eslint/utils': 5.47.1_iukboom6ndih5an6iafl45j2fe debug: 4.3.4 - eslint: 8.30.0 + eslint: 8.31.0 ignore: 5.2.4 natural-compare-lite: 1.4.0 regexpp: 3.2.0 @@ -604,7 +604,7 @@ packages: - supports-color dev: true - /@typescript-eslint/parser/5.47.1_lzzuuodtsqwxnvqeq4g4likcqa: + /@typescript-eslint/parser/5.47.1_iukboom6ndih5an6iafl45j2fe: resolution: {integrity: sha512-9Vb+KIv29r6GPu4EboWOnQM7T+UjpjXvjCPhNORlgm40a9Ia9bvaPJswvtae1gip2QEeVeGh6YquqAzEgoRAlw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -618,7 +618,7 @@ packages: '@typescript-eslint/types': 5.47.1 '@typescript-eslint/typescript-estree': 5.47.1_typescript@4.9.4 debug: 4.3.4 - eslint: 8.30.0 + eslint: 8.31.0 typescript: 4.9.4 transitivePeerDependencies: - supports-color @@ -632,7 +632,7 @@ packages: '@typescript-eslint/visitor-keys': 5.47.1 dev: true - /@typescript-eslint/type-utils/5.47.1_lzzuuodtsqwxnvqeq4g4likcqa: + /@typescript-eslint/type-utils/5.47.1_iukboom6ndih5an6iafl45j2fe: resolution: {integrity: sha512-/UKOeo8ee80A7/GJA427oIrBi/Gd4osk/3auBUg4Rn9EahFpevVV1mUK8hjyQD5lHPqX397x6CwOk5WGh1E/1w==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -643,9 +643,9 @@ packages: optional: true dependencies: '@typescript-eslint/typescript-estree': 5.47.1_typescript@4.9.4 - '@typescript-eslint/utils': 5.47.1_lzzuuodtsqwxnvqeq4g4likcqa + '@typescript-eslint/utils': 5.47.1_iukboom6ndih5an6iafl45j2fe debug: 4.3.4 - eslint: 8.30.0 + eslint: 8.31.0 tsutils: 3.21.0_typescript@4.9.4 typescript: 4.9.4 transitivePeerDependencies: @@ -678,7 +678,7 @@ packages: - supports-color dev: true - /@typescript-eslint/utils/5.47.1_lzzuuodtsqwxnvqeq4g4likcqa: + /@typescript-eslint/utils/5.47.1_iukboom6ndih5an6iafl45j2fe: resolution: {integrity: sha512-l90SdwqfmkuIVaREZ2ykEfCezepCLxzWMo5gVfcJsJCaT4jHT+QjgSkYhs5BMQmWqE9k3AtIfk4g211z/sTMVw==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} peerDependencies: @@ -689,9 +689,9 @@ packages: '@typescript-eslint/scope-manager': 5.47.1 '@typescript-eslint/types': 5.47.1 '@typescript-eslint/typescript-estree': 5.47.1_typescript@4.9.4 - eslint: 8.30.0 + eslint: 8.31.0 eslint-scope: 5.1.1 - eslint-utils: 3.0.0_eslint@8.30.0 + eslint-utils: 3.0.0_eslint@8.31.0 semver: 7.3.8 transitivePeerDependencies: - supports-color @@ -2413,13 +2413,13 @@ packages: estraverse: 5.3.0 dev: true - /eslint-utils/3.0.0_eslint@8.30.0: + /eslint-utils/3.0.0_eslint@8.31.0: resolution: {integrity: sha512-uuQC43IGctw68pJA1RgbQS8/NP7rch6Cwd4j3ZBtgo4/8Flj4eGE7ZYSZRN3iq5pVUv6GPdW5Z1RFleo84uLDA==} engines: {node: ^10.0.0 || ^12.0.0 || >= 14.0.0} peerDependencies: eslint: '>=5' dependencies: - eslint: 8.30.0 + eslint: 8.31.0 eslint-visitor-keys: 2.1.0 dev: true @@ -2433,7 +2433,7 @@ packages: engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} dev: true - /eslint-watch/8.0.0_eslint@8.30.0: + /eslint-watch/8.0.0_eslint@8.31.0: resolution: {integrity: sha512-piws/uE4gkZdz1pwkaEFx+kSWvoGnVX8IegFRrE1NUvlXjtU0rg7KhT1QDj/NzhAwbiLEfdRHWz5q738R4zDKA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true @@ -2442,7 +2442,7 @@ packages: dependencies: chokidar: 3.5.3 debug: 4.3.4 - eslint: 8.30.0 + eslint: 8.31.0 execa: 5.1.1 keypress: 0.2.1 lodash.debounce: 4.0.8 @@ -2455,12 +2455,12 @@ packages: - supports-color dev: true - /eslint/8.30.0: - resolution: {integrity: sha512-MGADB39QqYuzEGov+F/qb18r4i7DohCDOfatHaxI2iGlPuC65bwG2gxgO+7DkyL38dRFaRH7RaRAgU6JKL9rMQ==} + /eslint/8.31.0: + resolution: {integrity: sha512-0tQQEVdmPZ1UtUKXjX7EMm9BlgJ08G90IhWh0PKDCb3ZLsgAOHI8fYSIzYVZej92zsgq+ft0FGsxhJ3xo2tbuA==} engines: {node: ^12.22.0 || ^14.17.0 || >=16.0.0} hasBin: true dependencies: - '@eslint/eslintrc': 1.4.0 + '@eslint/eslintrc': 1.4.1 '@humanwhocodes/config-array': 0.11.8 '@humanwhocodes/module-importer': 1.0.1 '@nodelib/fs.walk': 1.2.8 @@ -2471,7 +2471,7 @@ packages: doctrine: 3.0.0 escape-string-regexp: 4.0.0 eslint-scope: 7.1.1 - eslint-utils: 3.0.0_eslint@8.30.0 + eslint-utils: 3.0.0_eslint@8.31.0 eslint-visitor-keys: 3.3.0 espree: 9.4.1 esquery: 1.4.0 @@ -4856,7 +4856,7 @@ packages: dependencies: lilconfig: 2.0.6 postcss: 8.4.20 - yaml: 2.2.0 + yaml: 2.2.1 dev: true /postcss-logical/5.0.4_postcss@8.4.20: @@ -6678,8 +6678,8 @@ packages: engines: {node: '>= 6'} dev: true - /yaml/2.2.0: - resolution: {integrity: sha512-auf7Gi6QwO7HW//GA9seGvTXVGWl1CM/ADWh1+RxtXr6XOxnT65ovDl9fTi4e0monEyJxCHqDpF6QnFDXmJE4g==} + /yaml/2.2.1: + resolution: {integrity: sha512-e0WHiYql7+9wr4cWMx3TVQrNwejKaEe7/rHNmQmqRjazfOP5W8PB6Jpebb5o6fIapbz9o9+2ipcaTM2ZwDI6lw==} engines: {node: '>= 14'} dev: true From 617d088981d5e00f209ffccf5976074d43f0a362 Mon Sep 17 00:00:00 2001 From: "Raoul v. R" Date: Sun, 1 Jan 2023 20:17:26 +0100 Subject: [PATCH 3/3] Version 6.29.3 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 03dfebd0e..925700461 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "postprocessing", - "version": "6.29.2", + "version": "6.29.3", "description": "A post processing library that provides the means to implement image filter effects for three.js.", "homepage": "https://github.com/pmndrs/postprocessing", "main": "build/postprocessing.js",