Skip to content
Permalink
Browse files

minor tweaks here and there.

In this changeset:
- NetworkQueue is now a singleton for easier reference.
- overwriting the transformer no longer overwrites the constraints.
- Performance Tweaks
  - tile-hash is now super-quick
  - instead of n-times calling getLevel(n), once getting the array
- Mimetypes now feature uppercase variants.
  • Loading branch information...
ccoenen committed Sep 15, 2009
1 parent 1a2e818 commit c6b49132ce4fb672aa6ee9ae72ded2330e0431bb
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -473,7 +474,7 @@ public final class MultiScaleContainer extends Sprite

private function createLoader():void
{
_loader = new NetworkQueue()
_loader = NetworkQueue.getInstance();
}

private function createRenderManager():void
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -187,8 +188,11 @@ internal class MultiScaleImageBase extends Sprite

public function set transformer(value:IViewportTransformer):void
{
if (transformer !== value)
viewport.transformer = value
if (transformer === value)
return;
var oldConstraint:IViewportConstraint = viewport.transformer.constraint;
viewport.transformer = value
viewport.transformer.constraint = oldConstraint;
}

//----------------------------------
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -62,6 +63,14 @@ public interface IImagePyramidDescriptor extends IMultiScaleImageDescriptor
*/
function get numLevels():int

//----------------------------------
// levels
//----------------------------------
/**
* returns the levels-array.
*/
function get levels():Array

//----------------------------------
// tileWidth
//----------------------------------
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -278,14 +279,19 @@ public class ImagePyramidDescriptorBase
/**
* @private
*/
private var levels:Array = []
private var _levels:Array = []

public function get levels():Array {
return _levels;
}


/**
* @private
*/
protected function addLevel(level:IImagePyramidLevel):IImagePyramidLevel
{
levels.push(level)
_levels.push(level)
return level
}

@@ -297,7 +303,7 @@ public class ImagePyramidDescriptorBase
if (index < 0 || index >= numLevels)
throw new ArgumentError("[ImagePyramidDescriptorBase] Illegal level index.")

return levels[index]
return _levels[index]
}

//--------------------------------------------------------------------------
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -68,6 +69,13 @@ public final class NetworkQueue extends EventDispatcher

private static const MAX_CONNECTIONS:uint = 8


/**
* singleton instance
*/
private static const _instance:NetworkQueue = new NetworkQueue();


//--------------------------------------------------------------------------
//
// Constructor
@@ -95,6 +103,13 @@ public final class NetworkQueue extends EventDispatcher
// Methods
//
//--------------------------------------------------------------------------

/**
* please use this instead of instanciating your own Queue
*/
public static function getInstance():NetworkQueue {
return _instance;
}

public function addRequest(url:String,
type:Class,
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -240,14 +241,15 @@ public final class ImagePyramidRenderManager implements IDisposable
fromLevel = optimalLevel.index

var level:IImagePyramidLevel
var levels:Array = descriptor.levels;
var nextTile:ImagePyramidTile
var renderingQueue:Array = []

// Iterate over levels
for (var l:int = fromLevel; l >= toLevel; --l)
{
var done:Boolean = true
level = descriptor.getLevelAt(l)
level = levels[l] as IImagePyramidLevel;

// Load or draw visible tiles
var fromPoint:Point = new Point(localBounds.left * level.width,
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -95,14 +96,14 @@ public final class ImagePyramidRenderer extends Renderer
// source
//----------------------------------

private var _source:*
private var _source:IImagePyramidDescriptor;

public function get source():*
public function get source():IImagePyramidDescriptor
{
return _source
return _source;
}

public function set source(value:*):void
public function set source(value:IImagePyramidDescriptor):void
{
if (_source === value)
return
@@ -178,20 +179,18 @@ public final class ImagePyramidRenderer extends Renderer
*/
openzoom_internal function getTile(level:int, column:int, row:int):ImagePyramidTile
{
var descriptor:IImagePyramidDescriptor = _source as IImagePyramidDescriptor

if (!descriptor)
if (!_source)
trace("[ImagePyramidRenderer] getTile: Source undefined")

var tile:ImagePyramidTile = tileCache[ImagePyramidTile.getHashCode(level, column, row)]

if (!descriptor.existsTile(level, column, row))
if (!_source.existsTile(level, column, row))
return null

if (!tile)
{
var url:String = descriptor.getTileURL(level, column, row)
var bounds:Rectangle = descriptor.getTileBounds(level, column, row)
var url:String = _source.getTileURL(level, column, row)
var bounds:Rectangle = _source.getTileBounds(level, column, row)

tile = new ImagePyramidTile(level, column, row, url, bounds)
tileCache[tile.hashCode] = tile
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -243,9 +244,13 @@ internal class ImagePyramidTile implements IDisposable,
//
//--------------------------------------------------------------------------

public static function getHashCode(level:int, column:int, row:int):int
public static function getHashCode(level:uint, column:uint, row:uint):uint
{
return parseInt([level, column, row].join(""))
// this would mean a maximum of 64 levels, 8192 cols and rows
level = level << 26
column = column << 13
var x : uint = level | column | row;
return x;
}

//--------------------------------------------------------------------------
@@ -22,6 +22,7 @@
//
// Contributor(s):
// Daniel Gasienica <daniel@gasienica.ch>
// Claudius Coenen <coenen@meso.net>
//
// Alternatively, the contents of this file may be used under the terms of
// either the GNU General Public License Version 3 or later (the "GPL"), or
@@ -67,18 +68,19 @@ public final class MIMEUtil
switch (extension)
{
case "jpg":
type = "image/jpeg"
break

case "jpeg":
case "JPG":
case "JPEG":
type = "image/jpeg"
break

case "png":
case "PNG":
type = "image/png"
break

case "gif":
case "GIF":
type = "image/gif"
break

0 comments on commit c6b4913

Please sign in to comment.
You can’t perform that action at this time.