diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/packages/ticker/src/Ticker.js b/packages/ticker/src/Ticker.js index c188840..4bb6d7a 100644 --- a/packages/ticker/src/Ticker.js +++ b/packages/ticker/src/Ticker.js @@ -10,7 +10,7 @@ * e.g. When the ticker is started and the emitter has listeners. * * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class Ticker { @@ -41,7 +41,7 @@ /** * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically + * {@link PIXI.Ticker#start} automatically * when a listener is added. * * @member {boolean} @@ -51,8 +51,8 @@ /** * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * This value is capped by setting {@link PIXI.Ticker#minFPS} + * and is scaled with {@link PIXI.Ticker#speed}. * **Note:** The cap may be exceeded by scaling. * * @member {number} @@ -62,7 +62,7 @@ /** * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * Opposed to what the scalar {@link PIXI.Ticker#deltaTime} * is based, this value is neither capped nor scaled. * If the platform supports DOMHighResTimeStamp, * this value will have a precision of 1 µs. @@ -74,7 +74,7 @@ this.elapsedMS = 1 / settings.TARGET_FPMS; /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * The last time {@link PIXI.Ticker#update} was invoked. * This value is also reset internally outside of invoking * update, but only when a new animation frame is requested. * If the platform supports DOMHighResTimeStamp, @@ -86,7 +86,7 @@ this.lastTime = -1; /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * Factor of current {@link PIXI.Ticker#deltaTime}. * @example * // Scales ticker.deltaTime to what would be * // the equivalent of approximately 120 FPS @@ -99,10 +99,10 @@ /** * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * `true` if {@link PIXI.Ticker#start} has been called. + * `false` if {@link PIXI.Ticker#stop} has been called. * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * event of {@link PIXI.Ticker#autoStart} being `true` * and a listener is added. * * @member {boolean} @@ -111,6 +111,14 @@ this.started = false; /** + * If enabled, deleting is disabled. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + + /** * Internal tick method bound to ticker instance. * This is because in early 2015, Function.bind * is still 60% slower in high performance scenarios. @@ -198,7 +206,7 @@ * @param {Function} fn - The listener function to be added for updates * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ add(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -211,7 +219,7 @@ * @param {Function} fn - The listener function to be added for one update * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ addOnce(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -225,7 +233,7 @@ * * @private * @param {TickerListener} listener - Current listener being added. - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ _addListener(listener) { @@ -270,7 +278,7 @@ * * @param {Function} fn - The listener function to be removed * @param {Function} [context] - The listener context to be removed - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ remove(fn, context) { @@ -331,25 +339,28 @@ */ destroy() { - this.stop(); - - let listener = this._head.next; - - while (listener) + if (!this._protected) { - listener = listener.destroy(true); - } + this.stop(); - this._head.destroy(); - this._head = null; + let listener = this._head.next; + + while (listener) + { + listener = listener.destroy(true); + } + + this._head.destroy(); + this._head = null; + } } /** * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, + * current {@link PIXI.Ticker#elapsedMS}, + * the current {@link PIXI.Ticker#deltaTime}, * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * and then finally setting {@link PIXI.Ticker#lastTime} * with the value of currentTime that was provided. * This method will be called automatically by animation * frame callbacks if the ticker instance has been started @@ -418,8 +429,8 @@ * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * {@link PIXI.Ticker#speed}, which is specific + * to scaling {@link PIXI.Ticker#deltaTime}. * * @member {number} * @readonly @@ -431,9 +442,9 @@ /** * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * elapse between invoking {@link PIXI.Ticker#update}. + * This value is used to cap {@link PIXI.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.Ticker#FPS}. * When setting this property it is clamped to a value between * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * @@ -452,4 +463,59 @@ this._maxElapsedMS = 1 / minFPMS; } + + /** + * The shared ticker instance used by {@link PIXI.AnimatedSprite}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * let ticker = PIXI.Ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.Ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * let renderer = PIXI.autoDetectRenderer(800, 600); + * let stage = new PIXI.Container(); + * let interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @member {PIXI.Ticker} + * @static + */ + static get shared() + { + if (!Ticker._shared) + { + const shared = Ticker._shared = new Ticker(); + + shared.autoStart = true; + shared._protected = true; + } + + return Ticker._shared; + } } diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/packages/ticker/src/Ticker.js b/packages/ticker/src/Ticker.js index c188840..4bb6d7a 100644 --- a/packages/ticker/src/Ticker.js +++ b/packages/ticker/src/Ticker.js @@ -10,7 +10,7 @@ * e.g. When the ticker is started and the emitter has listeners. * * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class Ticker { @@ -41,7 +41,7 @@ /** * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically + * {@link PIXI.Ticker#start} automatically * when a listener is added. * * @member {boolean} @@ -51,8 +51,8 @@ /** * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * This value is capped by setting {@link PIXI.Ticker#minFPS} + * and is scaled with {@link PIXI.Ticker#speed}. * **Note:** The cap may be exceeded by scaling. * * @member {number} @@ -62,7 +62,7 @@ /** * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * Opposed to what the scalar {@link PIXI.Ticker#deltaTime} * is based, this value is neither capped nor scaled. * If the platform supports DOMHighResTimeStamp, * this value will have a precision of 1 µs. @@ -74,7 +74,7 @@ this.elapsedMS = 1 / settings.TARGET_FPMS; /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * The last time {@link PIXI.Ticker#update} was invoked. * This value is also reset internally outside of invoking * update, but only when a new animation frame is requested. * If the platform supports DOMHighResTimeStamp, @@ -86,7 +86,7 @@ this.lastTime = -1; /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * Factor of current {@link PIXI.Ticker#deltaTime}. * @example * // Scales ticker.deltaTime to what would be * // the equivalent of approximately 120 FPS @@ -99,10 +99,10 @@ /** * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * `true` if {@link PIXI.Ticker#start} has been called. + * `false` if {@link PIXI.Ticker#stop} has been called. * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * event of {@link PIXI.Ticker#autoStart} being `true` * and a listener is added. * * @member {boolean} @@ -111,6 +111,14 @@ this.started = false; /** + * If enabled, deleting is disabled. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + + /** * Internal tick method bound to ticker instance. * This is because in early 2015, Function.bind * is still 60% slower in high performance scenarios. @@ -198,7 +206,7 @@ * @param {Function} fn - The listener function to be added for updates * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ add(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -211,7 +219,7 @@ * @param {Function} fn - The listener function to be added for one update * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ addOnce(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -225,7 +233,7 @@ * * @private * @param {TickerListener} listener - Current listener being added. - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ _addListener(listener) { @@ -270,7 +278,7 @@ * * @param {Function} fn - The listener function to be removed * @param {Function} [context] - The listener context to be removed - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ remove(fn, context) { @@ -331,25 +339,28 @@ */ destroy() { - this.stop(); - - let listener = this._head.next; - - while (listener) + if (!this._protected) { - listener = listener.destroy(true); - } + this.stop(); - this._head.destroy(); - this._head = null; + let listener = this._head.next; + + while (listener) + { + listener = listener.destroy(true); + } + + this._head.destroy(); + this._head = null; + } } /** * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, + * current {@link PIXI.Ticker#elapsedMS}, + * the current {@link PIXI.Ticker#deltaTime}, * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * and then finally setting {@link PIXI.Ticker#lastTime} * with the value of currentTime that was provided. * This method will be called automatically by animation * frame callbacks if the ticker instance has been started @@ -418,8 +429,8 @@ * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * {@link PIXI.Ticker#speed}, which is specific + * to scaling {@link PIXI.Ticker#deltaTime}. * * @member {number} * @readonly @@ -431,9 +442,9 @@ /** * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * elapse between invoking {@link PIXI.Ticker#update}. + * This value is used to cap {@link PIXI.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.Ticker#FPS}. * When setting this property it is clamped to a value between * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * @@ -452,4 +463,59 @@ this._maxElapsedMS = 1 / minFPMS; } + + /** + * The shared ticker instance used by {@link PIXI.AnimatedSprite}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * let ticker = PIXI.Ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.Ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * let renderer = PIXI.autoDetectRenderer(800, 600); + * let stage = new PIXI.Container(); + * let interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @member {PIXI.Ticker} + * @static + */ + static get shared() + { + if (!Ticker._shared) + { + const shared = Ticker._shared = new Ticker(); + + shared.autoStart = true; + shared._protected = true; + } + + return Ticker._shared; + } } diff --git a/packages/ticker/src/TickerListener.js b/packages/ticker/src/TickerListener.js index 12cbd16..1704dfb 100644 --- a/packages/ticker/src/TickerListener.js +++ b/packages/ticker/src/TickerListener.js @@ -3,7 +3,7 @@ * * @private * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class TickerListener { diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/packages/ticker/src/Ticker.js b/packages/ticker/src/Ticker.js index c188840..4bb6d7a 100644 --- a/packages/ticker/src/Ticker.js +++ b/packages/ticker/src/Ticker.js @@ -10,7 +10,7 @@ * e.g. When the ticker is started and the emitter has listeners. * * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class Ticker { @@ -41,7 +41,7 @@ /** * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically + * {@link PIXI.Ticker#start} automatically * when a listener is added. * * @member {boolean} @@ -51,8 +51,8 @@ /** * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * This value is capped by setting {@link PIXI.Ticker#minFPS} + * and is scaled with {@link PIXI.Ticker#speed}. * **Note:** The cap may be exceeded by scaling. * * @member {number} @@ -62,7 +62,7 @@ /** * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * Opposed to what the scalar {@link PIXI.Ticker#deltaTime} * is based, this value is neither capped nor scaled. * If the platform supports DOMHighResTimeStamp, * this value will have a precision of 1 µs. @@ -74,7 +74,7 @@ this.elapsedMS = 1 / settings.TARGET_FPMS; /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * The last time {@link PIXI.Ticker#update} was invoked. * This value is also reset internally outside of invoking * update, but only when a new animation frame is requested. * If the platform supports DOMHighResTimeStamp, @@ -86,7 +86,7 @@ this.lastTime = -1; /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * Factor of current {@link PIXI.Ticker#deltaTime}. * @example * // Scales ticker.deltaTime to what would be * // the equivalent of approximately 120 FPS @@ -99,10 +99,10 @@ /** * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * `true` if {@link PIXI.Ticker#start} has been called. + * `false` if {@link PIXI.Ticker#stop} has been called. * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * event of {@link PIXI.Ticker#autoStart} being `true` * and a listener is added. * * @member {boolean} @@ -111,6 +111,14 @@ this.started = false; /** + * If enabled, deleting is disabled. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + + /** * Internal tick method bound to ticker instance. * This is because in early 2015, Function.bind * is still 60% slower in high performance scenarios. @@ -198,7 +206,7 @@ * @param {Function} fn - The listener function to be added for updates * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ add(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -211,7 +219,7 @@ * @param {Function} fn - The listener function to be added for one update * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ addOnce(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -225,7 +233,7 @@ * * @private * @param {TickerListener} listener - Current listener being added. - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ _addListener(listener) { @@ -270,7 +278,7 @@ * * @param {Function} fn - The listener function to be removed * @param {Function} [context] - The listener context to be removed - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ remove(fn, context) { @@ -331,25 +339,28 @@ */ destroy() { - this.stop(); - - let listener = this._head.next; - - while (listener) + if (!this._protected) { - listener = listener.destroy(true); - } + this.stop(); - this._head.destroy(); - this._head = null; + let listener = this._head.next; + + while (listener) + { + listener = listener.destroy(true); + } + + this._head.destroy(); + this._head = null; + } } /** * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, + * current {@link PIXI.Ticker#elapsedMS}, + * the current {@link PIXI.Ticker#deltaTime}, * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * and then finally setting {@link PIXI.Ticker#lastTime} * with the value of currentTime that was provided. * This method will be called automatically by animation * frame callbacks if the ticker instance has been started @@ -418,8 +429,8 @@ * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * {@link PIXI.Ticker#speed}, which is specific + * to scaling {@link PIXI.Ticker#deltaTime}. * * @member {number} * @readonly @@ -431,9 +442,9 @@ /** * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * elapse between invoking {@link PIXI.Ticker#update}. + * This value is used to cap {@link PIXI.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.Ticker#FPS}. * When setting this property it is clamped to a value between * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * @@ -452,4 +463,59 @@ this._maxElapsedMS = 1 / minFPMS; } + + /** + * The shared ticker instance used by {@link PIXI.AnimatedSprite}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * let ticker = PIXI.Ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.Ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * let renderer = PIXI.autoDetectRenderer(800, 600); + * let stage = new PIXI.Container(); + * let interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @member {PIXI.Ticker} + * @static + */ + static get shared() + { + if (!Ticker._shared) + { + const shared = Ticker._shared = new Ticker(); + + shared.autoStart = true; + shared._protected = true; + } + + return Ticker._shared; + } } diff --git a/packages/ticker/src/TickerListener.js b/packages/ticker/src/TickerListener.js index 12cbd16..1704dfb 100644 --- a/packages/ticker/src/TickerListener.js +++ b/packages/ticker/src/TickerListener.js @@ -3,7 +3,7 @@ * * @private * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class TickerListener { diff --git a/packages/ticker/src/const.js b/packages/ticker/src/const.js index 85c0a14..c2beece 100644 --- a/packages/ticker/src/const.js +++ b/packages/ticker/src/const.js @@ -1,16 +1,16 @@ /** * Represents the update priorities used by internal PIXI classes when registered with - * the {@link PIXI.ticker.Ticker} object. Higher priority items are updated first and lower + * the {@link PIXI.Ticker} object. Higher priority items are updated first and lower * priority items, such as render, should go later. * * @static * @constant * @name UPDATE_PRIORITY - * @memberof PIXI.ticker + * @memberof PIXI * @type {object} * @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager} * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite} - * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.ticker.Ticker#add}. + * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.Ticker#add}. * @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering. * @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.prepare.BasePrepare} utility. */ diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/packages/ticker/src/Ticker.js b/packages/ticker/src/Ticker.js index c188840..4bb6d7a 100644 --- a/packages/ticker/src/Ticker.js +++ b/packages/ticker/src/Ticker.js @@ -10,7 +10,7 @@ * e.g. When the ticker is started and the emitter has listeners. * * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class Ticker { @@ -41,7 +41,7 @@ /** * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically + * {@link PIXI.Ticker#start} automatically * when a listener is added. * * @member {boolean} @@ -51,8 +51,8 @@ /** * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * This value is capped by setting {@link PIXI.Ticker#minFPS} + * and is scaled with {@link PIXI.Ticker#speed}. * **Note:** The cap may be exceeded by scaling. * * @member {number} @@ -62,7 +62,7 @@ /** * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * Opposed to what the scalar {@link PIXI.Ticker#deltaTime} * is based, this value is neither capped nor scaled. * If the platform supports DOMHighResTimeStamp, * this value will have a precision of 1 µs. @@ -74,7 +74,7 @@ this.elapsedMS = 1 / settings.TARGET_FPMS; /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * The last time {@link PIXI.Ticker#update} was invoked. * This value is also reset internally outside of invoking * update, but only when a new animation frame is requested. * If the platform supports DOMHighResTimeStamp, @@ -86,7 +86,7 @@ this.lastTime = -1; /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * Factor of current {@link PIXI.Ticker#deltaTime}. * @example * // Scales ticker.deltaTime to what would be * // the equivalent of approximately 120 FPS @@ -99,10 +99,10 @@ /** * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * `true` if {@link PIXI.Ticker#start} has been called. + * `false` if {@link PIXI.Ticker#stop} has been called. * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * event of {@link PIXI.Ticker#autoStart} being `true` * and a listener is added. * * @member {boolean} @@ -111,6 +111,14 @@ this.started = false; /** + * If enabled, deleting is disabled. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + + /** * Internal tick method bound to ticker instance. * This is because in early 2015, Function.bind * is still 60% slower in high performance scenarios. @@ -198,7 +206,7 @@ * @param {Function} fn - The listener function to be added for updates * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ add(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -211,7 +219,7 @@ * @param {Function} fn - The listener function to be added for one update * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ addOnce(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -225,7 +233,7 @@ * * @private * @param {TickerListener} listener - Current listener being added. - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ _addListener(listener) { @@ -270,7 +278,7 @@ * * @param {Function} fn - The listener function to be removed * @param {Function} [context] - The listener context to be removed - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ remove(fn, context) { @@ -331,25 +339,28 @@ */ destroy() { - this.stop(); - - let listener = this._head.next; - - while (listener) + if (!this._protected) { - listener = listener.destroy(true); - } + this.stop(); - this._head.destroy(); - this._head = null; + let listener = this._head.next; + + while (listener) + { + listener = listener.destroy(true); + } + + this._head.destroy(); + this._head = null; + } } /** * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, + * current {@link PIXI.Ticker#elapsedMS}, + * the current {@link PIXI.Ticker#deltaTime}, * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * and then finally setting {@link PIXI.Ticker#lastTime} * with the value of currentTime that was provided. * This method will be called automatically by animation * frame callbacks if the ticker instance has been started @@ -418,8 +429,8 @@ * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * {@link PIXI.Ticker#speed}, which is specific + * to scaling {@link PIXI.Ticker#deltaTime}. * * @member {number} * @readonly @@ -431,9 +442,9 @@ /** * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * elapse between invoking {@link PIXI.Ticker#update}. + * This value is used to cap {@link PIXI.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.Ticker#FPS}. * When setting this property it is clamped to a value between * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * @@ -452,4 +463,59 @@ this._maxElapsedMS = 1 / minFPMS; } + + /** + * The shared ticker instance used by {@link PIXI.AnimatedSprite}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * let ticker = PIXI.Ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.Ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * let renderer = PIXI.autoDetectRenderer(800, 600); + * let stage = new PIXI.Container(); + * let interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @member {PIXI.Ticker} + * @static + */ + static get shared() + { + if (!Ticker._shared) + { + const shared = Ticker._shared = new Ticker(); + + shared.autoStart = true; + shared._protected = true; + } + + return Ticker._shared; + } } diff --git a/packages/ticker/src/TickerListener.js b/packages/ticker/src/TickerListener.js index 12cbd16..1704dfb 100644 --- a/packages/ticker/src/TickerListener.js +++ b/packages/ticker/src/TickerListener.js @@ -3,7 +3,7 @@ * * @private * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class TickerListener { diff --git a/packages/ticker/src/const.js b/packages/ticker/src/const.js index 85c0a14..c2beece 100644 --- a/packages/ticker/src/const.js +++ b/packages/ticker/src/const.js @@ -1,16 +1,16 @@ /** * Represents the update priorities used by internal PIXI classes when registered with - * the {@link PIXI.ticker.Ticker} object. Higher priority items are updated first and lower + * the {@link PIXI.Ticker} object. Higher priority items are updated first and lower * priority items, such as render, should go later. * * @static * @constant * @name UPDATE_PRIORITY - * @memberof PIXI.ticker + * @memberof PIXI * @type {object} * @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager} * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite} - * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.ticker.Ticker#add}. + * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.Ticker#add}. * @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering. * @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.prepare.BasePrepare} utility. */ diff --git a/packages/ticker/src/index.js b/packages/ticker/src/index.js index 968d75b..19057ef 100644 --- a/packages/ticker/src/index.js +++ b/packages/ticker/src/index.js @@ -1,74 +1,4 @@ -import Ticker from './Ticker'; - -/** - * The shared ticker instance used by {@link PIXI.AnimatedSprite}. - * and by {@link PIXI.interaction.InteractionManager}. - * The property {@link PIXI.ticker.Ticker#autoStart} is set to `true` - * for this instance. Please follow the examples for usage, including - * how to opt-out of auto-starting the shared ticker. - * - * @example - * let ticker = PIXI.ticker.shared; - * // Set this to prevent starting this ticker when listeners are added. - * // By default this is true only for the PIXI.ticker.shared instance. - * ticker.autoStart = false; - * // FYI, call this to ensure the ticker is stopped. It should be stopped - * // if you have not attempted to render anything yet. - * ticker.stop(); - * // Call this when you are ready for a running shared ticker. - * ticker.start(); - * - * @example - * // You may use the shared ticker to render... - * let renderer = PIXI.autoDetectRenderer(800, 600); - * let stage = new PIXI.Container(); - * let interactionManager = PIXI.interaction.InteractionManager(renderer); - * document.body.appendChild(renderer.view); - * ticker.add(function (time) { - * renderer.render(stage); - * }); - * - * @example - * // Or you can just update it manually. - * ticker.autoStart = false; - * ticker.stop(); - * function animate(time) { - * ticker.update(time); - * renderer.render(stage); - * requestAnimationFrame(animate); - * } - * animate(performance.now()); - * - * @type {PIXI.ticker.Ticker} - * @memberof PIXI.ticker - */ -const shared = new Ticker(); - -shared.autoStart = true; -shared.destroy = () => -{ - // protect destroying shared ticker - // this is used by other internal systems - // like AnimatedSprite and InteractionManager -}; - -/** - * This namespace contains an API for interacting with PIXI's internal global update loop. - * - * This ticker is used for rendering, {@link PIXI.AnimatedSprite AnimatedSprite}, - * {@link PIXI.interaction.InteractionManager InteractionManager} and many other time-based PIXI systems. - * @example - * const ticker = new PIXI.ticker.Ticker(); - * ticker.stop(); - * ticker.add((deltaTime) => { - * // do something every frame - * }); - * ticker.start(); - * @namespace PIXI.ticker - */ -export { shared, Ticker }; - +export { default as Ticker } from './Ticker'; export * from './const'; import './settings'; - diff --git a/bundles/pixi.js/src/deprecated.js b/bundles/pixi.js/src/deprecated.js index a529402..4f94f16 100644 --- a/bundles/pixi.js/src/deprecated.js +++ b/bundles/pixi.js/src/deprecated.js @@ -41,24 +41,6 @@ Object.defineProperties(PIXI, { /** - * @deprecated since 5.0.0 - * @see PIXI.ticker.UPDATE_PRIORITY - * @static - * @constant - * @name UPDATE_PRIORITY - * @memberof PIXI - * @type {object} - */ - UPDATE_PRIORITY: { - get() - { - warn('PIXI.UPDATE_PRIORITY has moved to PIXI.ticker.UPDATE_PRIORITY'); - - return PIXI.ticker.UPDATE_PRIORITY; - }, - }, - - /** * @constant * @name SVG_SIZE * @memberof PIXI @@ -154,6 +136,44 @@ }, }); +/** + * This namespace has been removed and items have been moved to + * the top-level `PIXI` object. + * @namespace PIXI.ticker + * @deprecated since 5.0.0 + */ +PIXI.ticker = {}; + +Object.defineProperties(PIXI.ticker, { + /** + * @class PIXI.ticker.Ticker + * @deprecated since 5.0.0 + * @see PIXI.Ticker + */ + Ticker: { + get() + { + warn('PIXI.ticker.Ticker has moved to PIXI.Ticker'); + + return PIXI.Ticker; + }, + }, + /** + * @name PIXI.ticker.shared + * @type {PIXI.Ticker} + * @deprecated since 5.0.0 + * @see PIXI.Ticker.shared + */ + shared: { + get() + { + warn('PIXI.ticker.shared has moved to PIXI.Ticker.shared'); + + return PIXI.Ticker.shared; + }, + }, +}); + Object.defineProperties(PIXI.loaders.Loader, { /** * @function PIXI.loaders.Loader.addPixiMiddleware diff --git a/bundles/pixi.js/src/index.js b/bundles/pixi.js/src/index.js index 2a9082c..a4fd8d6 100644 --- a/bundles/pixi.js/src/index.js +++ b/bundles/pixi.js/src/index.js @@ -14,6 +14,7 @@ export * from '@pixi/math'; export * from '@pixi/constants'; export * from '@pixi/display'; +export * from '@pixi/ticker'; // export libs import * as accessibility from '@pixi/accessibility'; @@ -25,7 +26,6 @@ // import * as particles from '@pixi/particles'; import * as filters from './filters'; import * as utils from '@pixi/utils'; -import * as ticker from '@pixi/ticker'; import { settings } from '@pixi/settings'; // imported for side effect of extending the prototype only, contains no exports @@ -55,6 +55,5 @@ // particles, prepare, utils, - ticker, settings, }; diff --git a/bundles/pixi.js/test/index.js b/bundles/pixi.js/test/index.js index 242a269..775e1f6 100755 --- a/bundles/pixi.js/test/index.js +++ b/bundles/pixi.js/test/index.js @@ -1,5 +1,5 @@ /* eslint-disable global-require */ -const PIXI = require('../'); +const PIXI = global.PIXI = require('../'); describe('PIXI', function () { @@ -8,7 +8,6 @@ expect(PIXI).to.not.be.undefined; expect(PIXI.interaction).to.not.be.undefined; expect(PIXI.settings).to.not.be.undefined; - expect(PIXI.ticker).to.not.be.undefined; expect(PIXI.loaders).to.not.be.undefined; expect(PIXI.extract).to.not.be.undefined; expect(PIXI.mesh).to.not.be.undefined; diff --git a/packages/app/src/Application.js b/packages/app/src/Application.js index aba3e5b..de015d8 100644 --- a/packages/app/src/Application.js +++ b/packages/app/src/Application.js @@ -1,7 +1,7 @@ import { autoDetectRenderer } from '@pixi/core'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; -import { shared, Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * Convenience class to create a new PIXI application. @@ -50,7 +50,7 @@ * If you experience unexplained flickering try setting this to true. **webgl only** * @param {string} [options.powerPreference] - Parameter passed to webgl context, set to "high-performance" * for devices with dual graphics card **webgl only** - * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.ticker.shared, `false` to create new ticker. + * @param {boolean} [options.sharedTicker=false] - `true` to use PIXI.Ticker.shared, `false` to create new ticker. * @param {boolean} [options.sharedLoader=false] - `true` to use PIXI.loaders.shared, `false` to create new Loader. */ constructor(options, arg2, arg3, arg4, arg5) @@ -92,17 +92,17 @@ /** * Internal reference to the ticker - * @member {PIXI.ticker.Ticker} + * @member {PIXI.Ticker} * @private */ this._ticker = null; /** * Ticker for doing render updates. - * @member {PIXI.ticker.Ticker} - * @default PIXI.ticker.shared + * @member {PIXI.Ticker} + * @default PIXI.Ticker.shared */ - this.ticker = options.sharedTicker ? shared : new Ticker(); + this.ticker = options.sharedTicker ? Ticker.shared : new Ticker(); // Start the rendering if (options.autoStart) diff --git a/packages/core/src/textures/VideoBaseTexture.js b/packages/core/src/textures/VideoBaseTexture.js index e8be3da..d0b7fbf 100644 --- a/packages/core/src/textures/VideoBaseTexture.js +++ b/packages/core/src/textures/VideoBaseTexture.js @@ -1,6 +1,6 @@ import BaseTexture from './BaseTexture'; import { uid, BaseTextureCache, determineCrossOrigin } from '@pixi/utils'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * A texture of a [playing] Video. @@ -125,7 +125,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } @@ -139,7 +139,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -187,7 +187,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } if (this.source && this.source._pixiId) @@ -293,12 +293,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); this._isAutoUpdating = true; } } diff --git a/packages/core/src/textures/resources/VideoResource.js b/packages/core/src/textures/resources/VideoResource.js index 61311e8..e79fbb3 100644 --- a/packages/core/src/textures/resources/VideoResource.js +++ b/packages/core/src/textures/resources/VideoResource.js @@ -1,5 +1,5 @@ import TextureResource from './TextureResource'; -import { shared } from '@pixi/ticker'; +import { Ticker } from '@pixi/ticker'; /** * Resource type for HTMLVideoElement. @@ -104,7 +104,7 @@ if (!this._isAutoUpdating && this.autoUpdate) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } @@ -118,7 +118,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } } @@ -167,7 +167,7 @@ { if (this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } /* if (this.source && this.source._pixiId) @@ -197,12 +197,12 @@ if (!this._autoUpdate && this._isAutoUpdating) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); this._isAutoUpdating = false; } else if (this._autoUpdate && !this._isAutoUpdating) { - shared.add(this.update, this); + Ticker.shared.add(this.update, this); this._isAutoUpdating = true; } } diff --git a/packages/interaction/src/InteractionManager.js b/packages/interaction/src/InteractionManager.js index cbbbf4a..c6163e0 100644 --- a/packages/interaction/src/InteractionManager.js +++ b/packages/interaction/src/InteractionManager.js @@ -1,5 +1,5 @@ import { WebGLRenderer, CanvasRenderer } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { Point } from '@pixi/math'; import { DisplayObject } from '@pixi/display'; import { mixins } from '@pixi/utils'; @@ -708,7 +708,7 @@ return; } - shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.INTERACTION); if (window.navigator.msPointerEnabled) { @@ -771,7 +771,7 @@ return; } - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); if (window.navigator.msPointerEnabled) { @@ -816,7 +816,7 @@ /** * Updates the state of interactive objects. - * Invoked by a throttled ticker update from {@link PIXI.ticker.shared}. + * Invoked by a throttled ticker update from {@link PIXI.Ticker.shared}. * * @param {number} deltaTime - time delta since last tick */ diff --git a/packages/interaction/test/MockPointer.js b/packages/interaction/test/MockPointer.js index 8144ed6..514fc23 100644 --- a/packages/interaction/test/MockPointer.js +++ b/packages/interaction/test/MockPointer.js @@ -1,6 +1,7 @@ -const { shared } = require('@pixi/ticker'); +const { Ticker } = require('@pixi/ticker'); const { CanvasRenderer } = require('@pixi/core'); const { Rectangle } = require('@pixi/math'); +const { shared } = Ticker; /** * Use this to mock mouse/touch/pointer events diff --git a/packages/prepare/src/BasePrepare.js b/packages/prepare/src/BasePrepare.js index 2ce78e1..ec3bcf1 100644 --- a/packages/prepare/src/BasePrepare.js +++ b/packages/prepare/src/BasePrepare.js @@ -1,5 +1,5 @@ import { Texture, BaseTexture } from '@pixi/core'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; import { settings } from '@pixi/settings'; import { Container } from '@pixi/display'; import { Text, TextStyle, TextMetrics } from '@pixi/text'; @@ -161,7 +161,7 @@ if (!this.ticking) { this.ticking = true; - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } else if (done) @@ -231,7 +231,7 @@ else { // if we are not finished, on the next rAF do this again - shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); + Ticker.shared.addOnce(this.tick, this, UPDATE_PRIORITY.UTILITY); } } @@ -308,7 +308,7 @@ { if (this.ticking) { - shared.remove(this.tick, this); + Ticker.shared.remove(this.tick, this); } this.ticking = false; this.addHooks = null; diff --git a/packages/sprite-animated/src/AnimatedSprite.js b/packages/sprite-animated/src/AnimatedSprite.js index f5932b9..c9ab48d 100644 --- a/packages/sprite-animated/src/AnimatedSprite.js +++ b/packages/sprite-animated/src/AnimatedSprite.js @@ -1,6 +1,6 @@ import { Texture } from '@pixi/core'; import { Sprite } from '@pixi/sprite'; -import { shared, UPDATE_PRIORITY } from '@pixi/ticker'; +import { Ticker, UPDATE_PRIORITY } from '@pixi/ticker'; /** * @typedef FrameObject @@ -34,7 +34,7 @@ /** * @param {PIXI.Texture[]|FrameObject[]} textures - an array of {@link PIXI.Texture} or frame * objects that make up the animation - * @param {boolean} [autoUpdate=true] - Whether to use PIXI.ticker.shared to auto update animation time. + * @param {boolean} [autoUpdate=true] - Whether to use PIXI.Ticker.shared to auto update animation time. */ constructor(textures, autoUpdate) { @@ -53,7 +53,7 @@ this.textures = textures; /** - * `true` uses PIXI.ticker.shared to auto update animation time. + * `true` uses PIXI.Ticker.shared to auto update animation time. * @type {boolean} * @default true * @private @@ -128,7 +128,7 @@ this.playing = false; if (this._autoUpdate) { - shared.remove(this.update, this); + Ticker.shared.remove(this.update, this); } } @@ -146,7 +146,7 @@ this.playing = true; if (this._autoUpdate) { - shared.add(this.update, this, UPDATE_PRIORITY.HIGH); + Ticker.shared.add(this.update, this, UPDATE_PRIORITY.HIGH); } } diff --git a/packages/ticker/src/Ticker.js b/packages/ticker/src/Ticker.js index c188840..4bb6d7a 100644 --- a/packages/ticker/src/Ticker.js +++ b/packages/ticker/src/Ticker.js @@ -10,7 +10,7 @@ * e.g. When the ticker is started and the emitter has listeners. * * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class Ticker { @@ -41,7 +41,7 @@ /** * Whether or not this ticker should invoke the method - * {@link PIXI.ticker.Ticker#start} automatically + * {@link PIXI.Ticker#start} automatically * when a listener is added. * * @member {boolean} @@ -51,8 +51,8 @@ /** * Scalar time value from last frame to this frame. - * This value is capped by setting {@link PIXI.ticker.Ticker#minFPS} - * and is scaled with {@link PIXI.ticker.Ticker#speed}. + * This value is capped by setting {@link PIXI.Ticker#minFPS} + * and is scaled with {@link PIXI.Ticker#speed}. * **Note:** The cap may be exceeded by scaling. * * @member {number} @@ -62,7 +62,7 @@ /** * Time elapsed in milliseconds from last frame to this frame. - * Opposed to what the scalar {@link PIXI.ticker.Ticker#deltaTime} + * Opposed to what the scalar {@link PIXI.Ticker#deltaTime} * is based, this value is neither capped nor scaled. * If the platform supports DOMHighResTimeStamp, * this value will have a precision of 1 µs. @@ -74,7 +74,7 @@ this.elapsedMS = 1 / settings.TARGET_FPMS; /** - * The last time {@link PIXI.ticker.Ticker#update} was invoked. + * The last time {@link PIXI.Ticker#update} was invoked. * This value is also reset internally outside of invoking * update, but only when a new animation frame is requested. * If the platform supports DOMHighResTimeStamp, @@ -86,7 +86,7 @@ this.lastTime = -1; /** - * Factor of current {@link PIXI.ticker.Ticker#deltaTime}. + * Factor of current {@link PIXI.Ticker#deltaTime}. * @example * // Scales ticker.deltaTime to what would be * // the equivalent of approximately 120 FPS @@ -99,10 +99,10 @@ /** * Whether or not this ticker has been started. - * `true` if {@link PIXI.ticker.Ticker#start} has been called. - * `false` if {@link PIXI.ticker.Ticker#stop} has been called. + * `true` if {@link PIXI.Ticker#start} has been called. + * `false` if {@link PIXI.Ticker#stop} has been called. * While `false`, this value may change to `true` in the - * event of {@link PIXI.ticker.Ticker#autoStart} being `true` + * event of {@link PIXI.Ticker#autoStart} being `true` * and a listener is added. * * @member {boolean} @@ -111,6 +111,14 @@ this.started = false; /** + * If enabled, deleting is disabled. + * @member {boolean} + * @default false + * @private + */ + this._protected = false; + + /** * Internal tick method bound to ticker instance. * This is because in early 2015, Function.bind * is still 60% slower in high performance scenarios. @@ -198,7 +206,7 @@ * @param {Function} fn - The listener function to be added for updates * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ add(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -211,7 +219,7 @@ * @param {Function} fn - The listener function to be added for one update * @param {Function} [context] - The listener context * @param {number} [priority=PIXI.UPDATE_PRIORITY.NORMAL] - The priority for emitting - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ addOnce(fn, context, priority = UPDATE_PRIORITY.NORMAL) { @@ -225,7 +233,7 @@ * * @private * @param {TickerListener} listener - Current listener being added. - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ _addListener(listener) { @@ -270,7 +278,7 @@ * * @param {Function} fn - The listener function to be removed * @param {Function} [context] - The listener context to be removed - * @returns {PIXI.ticker.Ticker} This instance of a ticker + * @returns {PIXI.Ticker} This instance of a ticker */ remove(fn, context) { @@ -331,25 +339,28 @@ */ destroy() { - this.stop(); - - let listener = this._head.next; - - while (listener) + if (!this._protected) { - listener = listener.destroy(true); - } + this.stop(); - this._head.destroy(); - this._head = null; + let listener = this._head.next; + + while (listener) + { + listener = listener.destroy(true); + } + + this._head.destroy(); + this._head = null; + } } /** * Triggers an update. An update entails setting the - * current {@link PIXI.ticker.Ticker#elapsedMS}, - * the current {@link PIXI.ticker.Ticker#deltaTime}, + * current {@link PIXI.Ticker#elapsedMS}, + * the current {@link PIXI.Ticker#deltaTime}, * invoking all listeners with current deltaTime, - * and then finally setting {@link PIXI.ticker.Ticker#lastTime} + * and then finally setting {@link PIXI.Ticker#lastTime} * with the value of currentTime that was provided. * This method will be called automatically by animation * frame callbacks if the ticker instance has been started @@ -418,8 +429,8 @@ * The frames per second at which this ticker is running. * The default is approximately 60 in most modern browsers. * **Note:** This does not factor in the value of - * {@link PIXI.ticker.Ticker#speed}, which is specific - * to scaling {@link PIXI.ticker.Ticker#deltaTime}. + * {@link PIXI.Ticker#speed}, which is specific + * to scaling {@link PIXI.Ticker#deltaTime}. * * @member {number} * @readonly @@ -431,9 +442,9 @@ /** * Manages the maximum amount of milliseconds allowed to - * elapse between invoking {@link PIXI.ticker.Ticker#update}. - * This value is used to cap {@link PIXI.ticker.Ticker#deltaTime}, - * but does not effect the measured value of {@link PIXI.ticker.Ticker#FPS}. + * elapse between invoking {@link PIXI.Ticker#update}. + * This value is used to cap {@link PIXI.Ticker#deltaTime}, + * but does not effect the measured value of {@link PIXI.Ticker#FPS}. * When setting this property it is clamped to a value between * `0` and `PIXI.settings.TARGET_FPMS * 1000`. * @@ -452,4 +463,59 @@ this._maxElapsedMS = 1 / minFPMS; } + + /** + * The shared ticker instance used by {@link PIXI.AnimatedSprite}. + * and by {@link PIXI.interaction.InteractionManager}. + * The property {@link PIXI.Ticker#autoStart} is set to `true` + * for this instance. Please follow the examples for usage, including + * how to opt-out of auto-starting the shared ticker. + * + * @example + * let ticker = PIXI.Ticker.shared; + * // Set this to prevent starting this ticker when listeners are added. + * // By default this is true only for the PIXI.Ticker.shared instance. + * ticker.autoStart = false; + * // FYI, call this to ensure the ticker is stopped. It should be stopped + * // if you have not attempted to render anything yet. + * ticker.stop(); + * // Call this when you are ready for a running shared ticker. + * ticker.start(); + * + * @example + * // You may use the shared ticker to render... + * let renderer = PIXI.autoDetectRenderer(800, 600); + * let stage = new PIXI.Container(); + * let interactionManager = PIXI.interaction.InteractionManager(renderer); + * document.body.appendChild(renderer.view); + * ticker.add(function (time) { + * renderer.render(stage); + * }); + * + * @example + * // Or you can just update it manually. + * ticker.autoStart = false; + * ticker.stop(); + * function animate(time) { + * ticker.update(time); + * renderer.render(stage); + * requestAnimationFrame(animate); + * } + * animate(performance.now()); + * + * @member {PIXI.Ticker} + * @static + */ + static get shared() + { + if (!Ticker._shared) + { + const shared = Ticker._shared = new Ticker(); + + shared.autoStart = true; + shared._protected = true; + } + + return Ticker._shared; + } } diff --git a/packages/ticker/src/TickerListener.js b/packages/ticker/src/TickerListener.js index 12cbd16..1704dfb 100644 --- a/packages/ticker/src/TickerListener.js +++ b/packages/ticker/src/TickerListener.js @@ -3,7 +3,7 @@ * * @private * @class - * @memberof PIXI.ticker + * @memberof PIXI */ export default class TickerListener { diff --git a/packages/ticker/src/const.js b/packages/ticker/src/const.js index 85c0a14..c2beece 100644 --- a/packages/ticker/src/const.js +++ b/packages/ticker/src/const.js @@ -1,16 +1,16 @@ /** * Represents the update priorities used by internal PIXI classes when registered with - * the {@link PIXI.ticker.Ticker} object. Higher priority items are updated first and lower + * the {@link PIXI.Ticker} object. Higher priority items are updated first and lower * priority items, such as render, should go later. * * @static * @constant * @name UPDATE_PRIORITY - * @memberof PIXI.ticker + * @memberof PIXI * @type {object} * @property {number} INTERACTION=50 Highest priority, used for {@link PIXI.interaction.InteractionManager} * @property {number} HIGH=25 High priority updating, {@link PIXI.VideoBaseTexture} and {@link PIXI.AnimatedSprite} - * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.ticker.Ticker#add}. + * @property {number} NORMAL=0 Default priority for ticker events, see {@link PIXI.Ticker#add}. * @property {number} LOW=-25 Low priority used for {@link PIXI.Application} rendering. * @property {number} UTILITY=-50 Lowest priority used for {@link PIXI.prepare.BasePrepare} utility. */ diff --git a/packages/ticker/src/index.js b/packages/ticker/src/index.js index 968d75b..19057ef 100644 --- a/packages/ticker/src/index.js +++ b/packages/ticker/src/index.js @@ -1,74 +1,4 @@ -import Ticker from './Ticker'; - -/** - * The shared ticker instance used by {@link PIXI.AnimatedSprite}. - * and by {@link PIXI.interaction.InteractionManager}. - * The property {@link PIXI.ticker.Ticker#autoStart} is set to `true` - * for this instance. Please follow the examples for usage, including - * how to opt-out of auto-starting the shared ticker. - * - * @example - * let ticker = PIXI.ticker.shared; - * // Set this to prevent starting this ticker when listeners are added. - * // By default this is true only for the PIXI.ticker.shared instance. - * ticker.autoStart = false; - * // FYI, call this to ensure the ticker is stopped. It should be stopped - * // if you have not attempted to render anything yet. - * ticker.stop(); - * // Call this when you are ready for a running shared ticker. - * ticker.start(); - * - * @example - * // You may use the shared ticker to render... - * let renderer = PIXI.autoDetectRenderer(800, 600); - * let stage = new PIXI.Container(); - * let interactionManager = PIXI.interaction.InteractionManager(renderer); - * document.body.appendChild(renderer.view); - * ticker.add(function (time) { - * renderer.render(stage); - * }); - * - * @example - * // Or you can just update it manually. - * ticker.autoStart = false; - * ticker.stop(); - * function animate(time) { - * ticker.update(time); - * renderer.render(stage); - * requestAnimationFrame(animate); - * } - * animate(performance.now()); - * - * @type {PIXI.ticker.Ticker} - * @memberof PIXI.ticker - */ -const shared = new Ticker(); - -shared.autoStart = true; -shared.destroy = () => -{ - // protect destroying shared ticker - // this is used by other internal systems - // like AnimatedSprite and InteractionManager -}; - -/** - * This namespace contains an API for interacting with PIXI's internal global update loop. - * - * This ticker is used for rendering, {@link PIXI.AnimatedSprite AnimatedSprite}, - * {@link PIXI.interaction.InteractionManager InteractionManager} and many other time-based PIXI systems. - * @example - * const ticker = new PIXI.ticker.Ticker(); - * ticker.stop(); - * ticker.add((deltaTime) => { - * // do something every frame - * }); - * ticker.start(); - * @namespace PIXI.ticker - */ -export { shared, Ticker }; - +export { default as Ticker } from './Ticker'; export * from './const'; import './settings'; - diff --git a/packages/ticker/test/index.js b/packages/ticker/test/index.js index 6ec9556..b0992ac 100644 --- a/packages/ticker/test/index.js +++ b/packages/ticker/test/index.js @@ -1,6 +1,7 @@ -const { Ticker, shared, UPDATE_PRIORITY } = require('../'); +const { Ticker, UPDATE_PRIORITY } = require('../'); +const { shared } = Ticker; -describe('PIXI.ticker.Ticker', function () +describe('PIXI.Ticker', function () { before(function () {