Skip to content

Commit 37ba225

Browse files
committed
Audio: Remove all IIFEs.
1 parent 6266232 commit 37ba225

File tree

3 files changed

+71
-65
lines changed

3 files changed

+71
-65
lines changed

src/audio/AudioContext.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,25 @@
22
* @author mrdoob / http://mrdoob.com/
33
*/
44

5-
var context;
5+
var _context;
66

77
var AudioContext = {
88

99
getContext: function () {
1010

11-
if ( context === undefined ) {
11+
if ( _context === undefined ) {
1212

13-
context = new ( window.AudioContext || window.webkitAudioContext )();
13+
_context = new ( window.AudioContext || window.webkitAudioContext )();
1414

1515
}
1616

17-
return context;
17+
return _context;
1818

1919
},
2020

2121
setContext: function ( value ) {
2222

23-
context = value;
23+
_context = value;
2424

2525
}
2626

src/audio/AudioListener.js

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Clock } from '../core/Clock.js';
88
import { Object3D } from '../core/Object3D.js';
99
import { AudioContext } from './AudioContext.js';
1010

11+
var _position, _quaternion, _scale;
12+
var _orientation;
13+
1114
function AudioListener() {
1215

1316
Object3D.call( this );
@@ -23,6 +26,10 @@ function AudioListener() {
2326

2427
this.timeDelta = 0;
2528

29+
// private
30+
31+
this._clock = new Clock();
32+
2633
}
2734

2835
AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
@@ -91,54 +98,52 @@ AudioListener.prototype = Object.assign( Object.create( Object3D.prototype ), {
9198

9299
},
93100

94-
updateMatrixWorld: ( function () {
95-
96-
var position = new Vector3();
97-
var quaternion = new Quaternion();
98-
var scale = new Vector3();
101+
updateMatrixWorld: function ( force ) {
99102

100-
var orientation = new Vector3();
101-
var clock = new Clock();
103+
Object3D.prototype.updateMatrixWorld.call( this, force );
102104

103-
return function updateMatrixWorld( force ) {
105+
if ( _position === undefined ) {
104106

105-
Object3D.prototype.updateMatrixWorld.call( this, force );
107+
_position = new Vector3();
108+
_quaternion = new Quaternion();
109+
_scale = new Vector3();
110+
_orientation = new Vector3();
106111

107-
var listener = this.context.listener;
108-
var up = this.up;
112+
}
109113

110-
this.timeDelta = clock.getDelta();
114+
var listener = this.context.listener;
115+
var up = this.up;
111116

112-
this.matrixWorld.decompose( position, quaternion, scale );
117+
this.timeDelta = this._clock.getDelta();
113118

114-
orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
119+
this.matrixWorld.decompose( _position, _quaternion, _scale );
115120

116-
if ( listener.positionX ) {
121+
_orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion );
117122

118-
// code path for Chrome (see #14393)
123+
if ( listener.positionX ) {
119124

120-
var endTime = this.context.currentTime + this.timeDelta;
125+
// code path for Chrome (see #14393)
121126

122-
listener.positionX.linearRampToValueAtTime( position.x, endTime );
123-
listener.positionY.linearRampToValueAtTime( position.y, endTime );
124-
listener.positionZ.linearRampToValueAtTime( position.z, endTime );
125-
listener.forwardX.linearRampToValueAtTime( orientation.x, endTime );
126-
listener.forwardY.linearRampToValueAtTime( orientation.y, endTime );
127-
listener.forwardZ.linearRampToValueAtTime( orientation.z, endTime );
128-
listener.upX.linearRampToValueAtTime( up.x, endTime );
129-
listener.upY.linearRampToValueAtTime( up.y, endTime );
130-
listener.upZ.linearRampToValueAtTime( up.z, endTime );
127+
var endTime = this.context.currentTime + this.timeDelta;
131128

132-
} else {
129+
listener.positionX.linearRampToValueAtTime( _position.x, endTime );
130+
listener.positionY.linearRampToValueAtTime( _position.y, endTime );
131+
listener.positionZ.linearRampToValueAtTime( _position.z, endTime );
132+
listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
133+
listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
134+
listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
135+
listener.upX.linearRampToValueAtTime( up.x, endTime );
136+
listener.upY.linearRampToValueAtTime( up.y, endTime );
137+
listener.upZ.linearRampToValueAtTime( up.z, endTime );
133138

134-
listener.setPosition( position.x, position.y, position.z );
135-
listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
139+
} else {
136140

137-
}
141+
listener.setPosition( _position.x, _position.y, _position.z );
142+
listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
138143

139-
};
144+
}
140145

141-
} )()
146+
}
142147

143148
} );
144149

src/audio/PositionalAudio.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import { Quaternion } from '../math/Quaternion.js';
77
import { Audio } from './Audio.js';
88
import { Object3D } from '../core/Object3D.js';
99

10+
var _position, _quaternion, _scale;
11+
var _orientation;
12+
1013
function PositionalAudio( listener ) {
1114

1215
Audio.call( this, listener );
@@ -93,50 +96,48 @@ PositionalAudio.prototype = Object.assign( Object.create( Audio.prototype ), {
9396

9497
},
9598

96-
updateMatrixWorld: ( function () {
97-
98-
var position = new Vector3();
99-
var quaternion = new Quaternion();
100-
var scale = new Vector3();
101-
102-
var orientation = new Vector3();
99+
updateMatrixWorld: function ( force ) {
103100

104-
return function updateMatrixWorld( force ) {
101+
Object3D.prototype.updateMatrixWorld.call( this, force );
105102

106-
Object3D.prototype.updateMatrixWorld.call( this, force );
103+
if ( _position === undefined ) {
107104

108-
if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
105+
_position = new Vector3();
106+
_quaternion = new Quaternion();
107+
_scale = new Vector3();
108+
_orientation = new Vector3();
109109

110-
this.matrixWorld.decompose( position, quaternion, scale );
110+
}
111111

112-
orientation.set( 0, 0, 1 ).applyQuaternion( quaternion );
112+
if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
113113

114-
var panner = this.panner;
114+
this.matrixWorld.decompose( _position, _quaternion, _scale );
115115

116-
if ( panner.positionX ) {
116+
_orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
117117

118-
// code path for Chrome and Firefox (see #14393)
118+
var panner = this.panner;
119119

120-
var endTime = this.context.currentTime + this.listener.timeDelta;
120+
if ( panner.positionX ) {
121121

122-
panner.positionX.linearRampToValueAtTime( position.x, endTime );
123-
panner.positionY.linearRampToValueAtTime( position.y, endTime );
124-
panner.positionZ.linearRampToValueAtTime( position.z, endTime );
125-
panner.orientationX.linearRampToValueAtTime( orientation.x, endTime );
126-
panner.orientationY.linearRampToValueAtTime( orientation.y, endTime );
127-
panner.orientationZ.linearRampToValueAtTime( orientation.z, endTime );
122+
// code path for Chrome and Firefox (see #14393)
128123

129-
} else {
124+
var endTime = this.context.currentTime + this.listener.timeDelta;
130125

131-
panner.setPosition( position.x, position.y, position.z );
132-
panner.setOrientation( orientation.x, orientation.y, orientation.z );
126+
panner.positionX.linearRampToValueAtTime( _position.x, endTime );
127+
panner.positionY.linearRampToValueAtTime( _position.y, endTime );
128+
panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
129+
panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
130+
panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
131+
panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
133132

134-
}
133+
} else {
135134

136-
};
135+
panner.setPosition( _position.x, _position.y, _position.z );
136+
panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
137137

138-
} )()
138+
}
139139

140+
}
140141

141142
} );
142143

0 commit comments

Comments
 (0)