@@ -3,6 +3,7 @@ const twgl = require('twgl.js');
33const Rectangle = require ( './Rectangle' ) ;
44const RenderConstants = require ( './RenderConstants' ) ;
55const ShaderManager = require ( './ShaderManager' ) ;
6+ const Skin = require ( './Skin' ) ;
67const EffectTransform = require ( './EffectTransform' ) ;
78
89/**
@@ -108,6 +109,8 @@ class Drawable {
108109 /** @todo move convex hull functionality, maybe bounds functionality overall, to Skin classes */
109110 this . _convexHullPoints = null ;
110111 this . _convexHullDirty = true ;
112+
113+ this . _skinWasAltered = this . _skinWasAltered . bind ( this ) ;
111114 }
112115
113116 /**
@@ -146,7 +149,13 @@ class Drawable {
146149 */
147150 set skin ( newSkin ) {
148151 if ( this . _skin !== newSkin ) {
152+ if ( this . _skin ) {
153+ this . _skin . removeListener ( Skin . Events . WasAltered , this . _skinWasAltered ) ;
154+ }
149155 this . _skin = newSkin ;
156+ if ( this . _skin ) {
157+ this . _skin . addListener ( Skin . Events . WasAltered , this . _skinWasAltered ) ;
158+ }
150159 this . _skinWasAltered ( ) ;
151160 }
152161 }
@@ -176,55 +185,98 @@ class Drawable {
176185 }
177186
178187 /**
179- * Update the position, direction, scale, or effect properties of this Drawable .
180- * @param {object.<string,* > } properties The new property values to set .
188+ * Update the position if it is different. Marks the transform as dirty .
189+ * @param {Array.<number > } position A new position .
181190 */
182- updateProperties ( properties ) {
183- let dirty = false ;
184- if ( 'position' in properties && (
185- this . _position [ 0 ] !== properties . position [ 0 ] ||
186- this . _position [ 1 ] !== properties . position [ 1 ] ) ) {
187- this . _position [ 0 ] = Math . round ( properties . position [ 0 ] ) ;
188- this . _position [ 1 ] = Math . round ( properties . position [ 1 ] ) ;
189- dirty = true ;
190- }
191- if ( 'direction' in properties && this . _direction !== properties . direction ) {
192- this . _direction = properties . direction ;
191+ updatePosition ( position ) {
192+ if ( this . _position [ 0 ] !== position [ 0 ] ||
193+ this . _position [ 1 ] !== position [ 1 ] ) {
194+ this . _position [ 0 ] = Math . round ( position [ 0 ] ) ;
195+ this . _position [ 1 ] = Math . round ( position [ 1 ] ) ;
196+ this . setTransformDirty ( ) ;
197+ }
198+ }
199+
200+ /**
201+ * Update the direction if it is different. Marks the transform as dirty.
202+ * @param {number } direction A new direction.
203+ */
204+ updateDirection ( direction ) {
205+ if ( this . _direction !== direction ) {
206+ this . _direction = direction ;
193207 this . _rotationTransformDirty = true ;
194- dirty = true ;
208+ this . setTransformDirty ( ) ;
195209 }
196- if ( 'scale' in properties && (
197- this . _scale [ 0 ] !== properties . scale [ 0 ] ||
198- this . _scale [ 1 ] !== properties . scale [ 1 ] ) ) {
199- this . _scale [ 0 ] = properties . scale [ 0 ] ;
200- this . _scale [ 1 ] = properties . scale [ 1 ] ;
210+ }
211+
212+ /**
213+ * Update the scale if it is different. Marks the transform as dirty.
214+ * @param {Array.<number> } scale A new scale.
215+ */
216+ updateScale ( scale ) {
217+ if ( this . _scale [ 0 ] !== scale [ 0 ] ||
218+ this . _scale [ 1 ] !== scale [ 1 ] ) {
219+ this . _scale [ 0 ] = scale [ 0 ] ;
220+ this . _scale [ 1 ] = scale [ 1 ] ;
201221 this . _rotationCenterDirty = true ;
202222 this . _skinScaleDirty = true ;
203- dirty = true ;
223+ this . setTransformDirty ( ) ;
204224 }
205- if ( 'visible' in properties ) {
206- this . _visible = properties . visible ;
225+ }
226+
227+ /**
228+ * Update visibility if it is different. Marks the convex hull as dirty.
229+ * @param {boolean } visible A new visibility state.
230+ */
231+ updateVisible ( visible ) {
232+ if ( this . _visible !== visible ) {
233+ this . _visible = visible ;
207234 this . setConvexHullDirty ( ) ;
208235 }
209- if ( dirty ) {
210- this . setTransformDirty ( ) ;
236+ }
237+
238+ /**
239+ * Update an effect. Marks the convex hull as dirty if the effect changes shape.
240+ * @param {string } effectName The name of the effect.
241+ * @param {number } rawValue A new effect value.
242+ */
243+ updateEffect ( effectName , rawValue ) {
244+ const effectInfo = ShaderManager . EFFECT_INFO [ effectName ] ;
245+ if ( rawValue ) {
246+ this . enabledEffects |= effectInfo . mask ;
247+ } else {
248+ this . enabledEffects &= ~ effectInfo . mask ;
249+ }
250+ const converter = effectInfo . converter ;
251+ this . _uniforms [ effectInfo . uniformName ] = converter ( rawValue ) ;
252+ if ( effectInfo . shapeChanges ) {
253+ this . setConvexHullDirty ( ) ;
254+ }
255+ }
256+
257+ /**
258+ * Update the position, direction, scale, or effect properties of this Drawable.
259+ * @deprecated Use specific update* methods instead.
260+ * @param {object.<string,*> } properties The new property values to set.
261+ */
262+ updateProperties ( properties ) {
263+ if ( 'position' in properties ) {
264+ this . updatePosition ( properties . position ) ;
265+ }
266+ if ( 'direction' in properties ) {
267+ this . updateDirection ( properties . direction ) ;
268+ }
269+ if ( 'scale' in properties ) {
270+ this . updateScale ( properties . scale ) ;
271+ }
272+ if ( 'visible' in properties ) {
273+ this . updateVisible ( properties . visible ) ;
211274 }
212275 const numEffects = ShaderManager . EFFECTS . length ;
213276 for ( let index = 0 ; index < numEffects ; ++ index ) {
214277 const effectName = ShaderManager . EFFECTS [ index ] ;
215278 if ( effectName in properties ) {
216- const rawValue = properties [ effectName ] ;
217- const effectInfo = ShaderManager . EFFECT_INFO [ effectName ] ;
218- if ( rawValue ) {
219- this . enabledEffects |= effectInfo . mask ;
220- } else {
221- this . enabledEffects &= ~ effectInfo . mask ;
222- }
223- const converter = effectInfo . converter ;
224- this . _uniforms [ effectInfo . uniformName ] = converter ( rawValue ) ;
225- if ( effectInfo . shapeChanges ) {
226- this . setConvexHullDirty ( ) ;
227- }
279+ this . updateEffect ( effectName , properties [ effectName ] ) ;
228280 }
229281 }
230282 }
@@ -425,6 +477,16 @@ class Drawable {
425477 return true ;
426478 }
427479
480+ // If the effect bits for mosaic, pixelate, whirl, or fisheye are set, use linear
481+ if ( ( this . _effectBits & (
482+ ShaderManager . EFFECT_INFO . fisheye . mask |
483+ ShaderManager . EFFECT_INFO . whirl . mask |
484+ ShaderManager . EFFECT_INFO . pixelate . mask |
485+ ShaderManager . EFFECT_INFO . mosaic . mask
486+ ) ) !== 0 ) {
487+ return false ;
488+ }
489+
428490 // We can't use nearest neighbor unless we are a multiple of 90 rotation
429491 if ( this . _direction % 90 !== 0 ) {
430492 return false ;
@@ -512,7 +574,6 @@ class Drawable {
512574 * @return {!Rectangle } Bounds for the Drawable.
513575 */
514576 getFastBounds ( result ) {
515- this . updateMatrix ( ) ;
516577 if ( ! this . needsConvexHullPoints ( ) ) {
517578 return this . getBounds ( result ) ;
518579 }
0 commit comments