Skip to content

Instantly share code, notes, and snippets.

@k0t0vich
Created September 24, 2012 11:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save k0t0vich/3775520 to your computer and use it in GitHub Desktop.
Save k0t0vich/3775520 to your computer and use it in GitHub Desktop.
private static var MAXIMUM_POOL_LENGTH:uint = 5000;
private static var POOL:Array = [];
public function SphericalCoordinates(azimuth:Number = 0, elevation:Number = 0,
radius:Number = 1) {
this.elevation = elevation;
this.azimuth = azimuth;
this.radius = radius;
}
public static function fromCache(azimuth:Number = 0, elevation:Number = 0,
radius:Number = 1):SphericalCoordinates {
var sp:SphericalCoordinates;
if (POOL.length > 0){
sp = POOL.pop();
sp.azimuth = azimuth;
sp.elevation = elevation;
sp.radius = radius;
} else {
sp = new SphericalCoordinates(azimuth, elevation, radius);
}
return sp;
}
public function destroy():void {
if (POOL.length < MAXIMUM_POOL_LENGTH) {
POOL.push(this);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment