Permalink
Browse files

Optimised Projector's getNext*InPool.

  • Loading branch information...
mrdoob committed Aug 18, 2012
1 parent a23ddd1 commit 8dad1561898ff3dfbcd749765df67331e8ec2f95
Showing with 95 additions and 124 deletions.
  1. +43 −72 src/core/Projector.js
  2. +52 −52 src/core/Vector4.js
View
@@ -6,11 +6,12 @@
THREE.Projector = function() {
- var _object, _objectCount, _objectPool = [],
- _vertex, _vertexCount, _vertexPool = [],
- _face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
- _line, _lineCount, _linePool = [],
- _particle, _particleCount, _particlePool = [],
+ var _object, _objectCount, _objectPool = [], _objectPoolLength = 0,
+ _vertex, _vertexCount, _vertexPool = [], _vertexPoolLength = 0,
+ _face, _face3Count, _face3Pool = [], _face3PoolLength = 0,
+ _face4Count, _face4Pool = [], _face4PoolLength = 0,
+ _line, _lineCount, _linePool = [], _linePoolLength = 0,
+ _particle, _particleCount, _particlePool = [], _particlePoolLength = 0,
_renderData = { objects: [], sprites: [], lights: [], elements: [] },
@@ -322,7 +323,7 @@ THREE.Projector = function() {
_modelViewProjectionMatrix.multiply( _viewProjectionMatrix, modelMatrix );
vertices = object.geometry.vertices;
-
+
v1 = getNextVertexInPool();
v1.positionScreen.copy( vertices[ 0 ] );
_modelViewProjectionMatrix.multiplyVector4( v1.positionScreen );
@@ -413,128 +414,98 @@ THREE.Projector = function() {
function getNextObjectInPool() {
- var object;
-
- if ( _objectCount === _objectPool.length ) {
+ if ( _objectCount === _objectPoolLength ) {
- object = new THREE.RenderableObject();
+ var object = new THREE.RenderableObject();
_objectPool.push( object );
-
- } else {
-
- object = _objectPool[ _objectCount ];
+ _objectPoolLength ++;
+ _objectCount ++;
+ return object;
}
- _objectCount ++;
-
- return object;
+ return _objectPool[ _objectCount ++ ];
}
function getNextVertexInPool() {
- var vertex;
+ if ( _vertexCount === _vertexPoolLength ) {
- if ( _vertexCount === _vertexPool.length ) {
-
- vertex = new THREE.RenderableVertex();
+ var vertex = new THREE.RenderableVertex();
_vertexPool.push( vertex );
-
- } else {
-
- vertex = _vertexPool[ _vertexCount ];
+ _vertexPoolLength ++;
+ _vertexCount ++;
+ return vertex;
}
- _vertexCount ++;
-
- return vertex;
+ return _vertexPool[ _vertexCount ++ ];
}
function getNextFace3InPool() {
- var face;
-
- if ( _face3Count === _face3Pool.length ) {
+ if ( _face3Count === _face3PoolLength ) {
- face = new THREE.RenderableFace3();
+ var face = new THREE.RenderableFace3();
_face3Pool.push( face );
-
- } else {
-
- face = _face3Pool[ _face3Count ];
+ _face3PoolLength ++;
+ _face3Count ++;
+ return face;
}
- _face3Count ++;
-
- return face;
+ return _face3Pool[ _face3Count ++ ];
}
function getNextFace4InPool() {
- var face;
+ if ( _face4Count === _face4PoolLength ) {
- if ( _face4Count === _face4Pool.length ) {
-
- face = new THREE.RenderableFace4();
+ var face = new THREE.RenderableFace4();
_face4Pool.push( face );
-
- } else {
-
- face = _face4Pool[ _face4Count ];
+ _face4PoolLength ++;
+ _face4Count ++;
+ return face;
}
- _face4Count ++;
-
- return face;
+ return _face4Pool[ _face4Count ++ ];
}
function getNextLineInPool() {
- var line;
-
- if ( _lineCount === _linePool.length ) {
+ if ( _lineCount === _linePoolLength ) {
- line = new THREE.RenderableLine();
+ var line = new THREE.RenderableLine();
_linePool.push( line );
-
- } else {
-
- line = _linePool[ _lineCount ];
+ _linePoolLength ++;
+ _lineCount ++
+ return line;
}
- _lineCount ++;
-
- return line;
+ return _linePool[ _lineCount ++ ];
}
function getNextParticleInPool() {
- var particle;
+ if ( _particleCount === _particlePoolLength ) {
- if ( _particleCount === _particlePool.length ) {
-
- particle = new THREE.RenderableParticle();
+ var particle = new THREE.RenderableParticle();
_particlePool.push( particle );
-
- } else {
-
- particle = _particlePool[ _particleCount ];
+ _particlePoolLength ++;
+ _particleCount ++
+ return particle;
}
- _particleCount ++;
-
- return particle;
+ return _particlePool[ _particleCount ++ ];
}
Oops, something went wrong.

0 comments on commit 8dad156

Please sign in to comment.