Merge pull request #33 from wilsonsilva/master

Performance update using object and array literals
This commit is contained in:
Andrey Kopysov
2012-12-12 20:49:52 -08:00
21 changed files with 49 additions and 49 deletions

View File

@@ -56,7 +56,7 @@ package alternativa.engine3d.animation {
/** /**
* @private * @private
*/ */
private var states:Object = new Object(); private var states:Object = {};
// private var datasList:BlendedData; // private var datasList:BlendedData;
/** /**

View File

@@ -26,8 +26,8 @@ package alternativa.engine3d.animation {
public var transform:TransformKey = new TransformKey(); public var transform:TransformKey = new TransformKey();
public var transformWeightSum:Number = 0; public var transformWeightSum:Number = 0;
public var numbers:Object = new Object(); public var numbers:Object = {};
public var numberWeightSums:Object = new Object(); public var numberWeightSums:Object = {};
public function AnimationState() { public function AnimationState() {

View File

@@ -777,7 +777,7 @@ public class Camera3D extends Object3D {
*/ */
public var debug:Boolean = false; public var debug:Boolean = false;
private var debugSet:Object = new Object(); private var debugSet:Object = {};
/** /**
* Adds an object or a class to list of debug drawing. * Adds an object or a class to list of debug drawing.

View File

@@ -767,10 +767,10 @@ package alternativa.engine3d.core {
if (listener == null) throw new TypeError("Parameter listener must be non-null."); if (listener == null) throw new TypeError("Parameter listener must be non-null.");
var listeners:Object; var listeners:Object;
if (useCapture) { if (useCapture) {
if (captureListeners == null) captureListeners = new Object(); if (captureListeners == null) captureListeners = {};
listeners = captureListeners; listeners = captureListeners;
} else { } else {
if (bubbleListeners == null) bubbleListeners = new Object(); if (bubbleListeners == null) bubbleListeners = {};
listeners = bubbleListeners; listeners = bubbleListeners;
} }
var vector:Vector.<Function> = listeners[type]; var vector:Vector.<Function> = listeners[type];

View File

@@ -737,7 +737,7 @@ package alternativa.engine3d.loaders {
var byteArray:ByteArray = buffer.byteBuffer; var byteArray:ByteArray = buffer.byteBuffer;
byteArray.endian = Endian.LITTLE_ENDIAN; byteArray.endian = Endian.LITTLE_ENDIAN;
var offset:int = 0; var offset:int = 0;
var attributes:Array = new Array(); var attributes:Array = [];
var jointsOffset:int = 0; var jointsOffset:int = 0;
for (var k:int = 0; k < buffer.attributes.length; k++) { for (var k:int = 0; k < buffer.attributes.length; k++) {
var attr:int; var attr:int;

View File

@@ -150,7 +150,7 @@ package alternativa.engine3d.loaders {
private function parseObject(chunkInfo:ChunkInfo):void { private function parseObject(chunkInfo:ChunkInfo):void {
// Create list of objects, if it need. // Create list of objects, if it need.
if (objectDatas == null) { if (objectDatas == null) {
objectDatas = new Object(); objectDatas = {};
} }
// Create object data // Create object data
var object:ObjectData = new ObjectData(); var object:ObjectData = new ObjectData();
@@ -274,7 +274,7 @@ package alternativa.engine3d.loaders {
private function parseSurface(object:ObjectData):void { private function parseSurface(object:ObjectData):void {
// Create list of surfaces, if it need. // Create list of surfaces, if it need.
if (object.surfaces == null) { if (object.surfaces == null) {
object.surfaces = new Object(); object.surfaces = {};
} }
// Name of surface and number of faces. // Name of surface and number of faces.
var sur:String = getString(data.position); var sur:String = getString(data.position);
@@ -451,7 +451,7 @@ package alternativa.engine3d.loaders {
private function parseMaterialName(material:MaterialData):void { private function parseMaterialName(material:MaterialData):void {
// Create list of materials, if it need // Create list of materials, if it need
if (materialDatas == null) { if (materialDatas == null) {
materialDatas = new Object(); materialDatas = {};
} }
// Get name of material // Get name of material
material.name = getString(data.position); material.name = getString(data.position);

View File

@@ -65,8 +65,8 @@ package alternativa.engine3d.loaders {
private var fillMaterial:FillMaterial; private var fillMaterial:FillMaterial;
public function ParserMaterial() { public function ParserMaterial() {
textures = new Object(); textures = {};
colors = new Object(); colors = {};
} }
/** /**

View File

@@ -49,9 +49,9 @@ package alternativa.engine3d.loaders {
*/ */
public var context:Context3D; public var context:Context3D;
private var textures:Object = new Object(); private var textures:Object = {};
private var bitmapDatas:Object = new Object(); private var bitmapDatas:Object = {};
private var byteArrays:Object = new Object(); private var byteArrays:Object = {};
private var currentBitmapDatas:Vector.<BitmapData>; private var currentBitmapDatas:Vector.<BitmapData>;
private var currentUrl:String; private var currentUrl:String;
@@ -131,8 +131,8 @@ package alternativa.engine3d.loaders {
if (resources != null) { if (resources != null) {
throw new Error("Cannot clean while loading"); throw new Error("Cannot clean while loading");
} }
textures = new Object(); textures = {};
bitmapDatas = new Object(); bitmapDatas = {};
} }
/** /**
@@ -142,11 +142,11 @@ package alternativa.engine3d.loaders {
if (resources != null) { if (resources != null) {
throw new Error("Cannot clean while loading"); throw new Error("Cannot clean while loading");
} }
textures = new Object(); textures = {};
for each (var b:BitmapData in bitmapDatas) { for each (var b:BitmapData in bitmapDatas) {
b.dispose(); b.dispose();
} }
bitmapDatas = new Object(); bitmapDatas = {};
} }
/** /**

View File

@@ -78,8 +78,8 @@ package alternativa.engine3d.loaders.collada {
private function constructStructures():void { private function constructStructures():void {
var element:XML; var element:XML;
sources = new Object(); sources = {};
arrays = new Object(); arrays = {};
for each (element in data..source) { for each (element in data..source) {
// Collect all <source>. Dictionary <code>arrays</code> is filled at constructors. // Collect all <source>. Dictionary <code>arrays</code> is filled at constructors.
var source:DaeSource = new DaeSource(element, this); var source:DaeSource = new DaeSource(element, this);
@@ -88,7 +88,7 @@ package alternativa.engine3d.loaders.collada {
} }
} }
lights = new Object(); lights = {};
for each (element in data.library_lights.light) { for each (element in data.library_lights.light) {
// Collect all <image>. // Collect all <image>.
var light:DaeLight = new DaeLight(element, this); var light:DaeLight = new DaeLight(element, this);
@@ -96,7 +96,7 @@ package alternativa.engine3d.loaders.collada {
lights[light.id] = light; lights[light.id] = light;
} }
} }
images = new Object(); images = {};
for each (element in data.library_images.image) { for each (element in data.library_images.image) {
// Collect all <image>. // Collect all <image>.
var image:DaeImage = new DaeImage(element, this); var image:DaeImage = new DaeImage(element, this);
@@ -104,7 +104,7 @@ package alternativa.engine3d.loaders.collada {
images[image.id] = image; images[image.id] = image;
} }
} }
effects = new Object(); effects = {};
for each (element in data.library_effects.effect) { for each (element in data.library_effects.effect) {
// Collect all <effect>. Dictionary <code>images</code> is filled at constructors. // Collect all <effect>. Dictionary <code>images</code> is filled at constructors.
var effect:DaeEffect = new DaeEffect(element, this); var effect:DaeEffect = new DaeEffect(element, this);
@@ -112,7 +112,7 @@ package alternativa.engine3d.loaders.collada {
effects[effect.id] = effect; effects[effect.id] = effect;
} }
} }
materials = new Object(); materials = {};
for each (element in data.library_materials.material) { for each (element in data.library_materials.material) {
// Collect all <material>. // Collect all <material>.
var material:DaeMaterial = new DaeMaterial(element, this); var material:DaeMaterial = new DaeMaterial(element, this);
@@ -120,8 +120,8 @@ package alternativa.engine3d.loaders.collada {
materials[material.id] = material; materials[material.id] = material;
} }
} }
geometries = new Object(); geometries = {};
vertices = new Object(); vertices = {};
for each (element in data.library_geometries.geometry) { for each (element in data.library_geometries.geometry) {
// Collect all <geometry>. Dictionary <code>vertices</code> is filled at constructors. // Collect all <geometry>. Dictionary <code>vertices</code> is filled at constructors.
var geom:DaeGeometry = new DaeGeometry(element, this); var geom:DaeGeometry = new DaeGeometry(element, this);
@@ -130,7 +130,7 @@ package alternativa.engine3d.loaders.collada {
} }
} }
controllers = new Object(); controllers = {};
for each (element in data.library_controllers.controller) { for each (element in data.library_controllers.controller) {
// Collect all <controllers>. // Collect all <controllers>.
var controller:DaeController = new DaeController(element, this); var controller:DaeController = new DaeController(element, this);
@@ -139,7 +139,7 @@ package alternativa.engine3d.loaders.collada {
} }
} }
nodes = new Object(); nodes = {};
for each (element in data.library_nodes.node) { for each (element in data.library_nodes.node) {
// Create only root nodes. Others are created recursively at constructors. // Create only root nodes. Others are created recursively at constructors.
var node:DaeNode = new DaeNode(element, this); var node:DaeNode = new DaeNode(element, this);
@@ -174,7 +174,7 @@ package alternativa.engine3d.loaders.collada {
private function constructAnimations():void { private function constructAnimations():void {
var element:XML; var element:XML;
samplers = new Object(); samplers = {};
for each (element in data.library_animations..sampler) { for each (element in data.library_animations..sampler) {
// Collect all <sampler>. // Collect all <sampler>.
var sampler:DaeSampler = new DaeSampler(element, this); var sampler:DaeSampler = new DaeSampler(element, this);

View File

@@ -39,7 +39,7 @@ package alternativa.engine3d.loaders.collada {
} }
private function parseSetParams():Object { private function parseSetParams():Object {
var params:Object = new Object(); var params:Object = {};
var list:XMLList = data.instance_effect.setparam; var list:XMLList = data.instance_effect.setparam;
for each (var element:XML in list) { for each (var element:XML in list) {
var param:DaeParam = new DaeParam(element, document); var param:DaeParam = new DaeParam(element, document);

View File

@@ -143,7 +143,7 @@ package alternativa.engine3d.loaders.collada {
} }
private function parseInstanceMaterials(geometry:XML):Object { private function parseInstanceMaterials(geometry:XML):Object {
var instances:Object = new Object(); var instances:Object = {};
var list:XMLList = geometry.bind_material.technique_common.instance_material; var list:XMLList = geometry.bind_material.technique_common.instance_material;
for (var i:int = 0, count:int = list.length(); i < count; i++) { for (var i:int = 0, count:int = list.length(); i < count; i++) {
var instance:DaeInstanceMaterial = new DaeInstanceMaterial(list[i], document); var instance:DaeInstanceMaterial = new DaeInstanceMaterial(list[i], document);

View File

@@ -51,7 +51,7 @@ package alternativa.engine3d.materials.compiler {
alternativa3d var _linkedVariables:Object; alternativa3d var _linkedVariables:Object;
// Dictionary of temporary variables at this linker. Key is a name of variable, value is a variable. // Dictionary of temporary variables at this linker. Key is a name of variable, value is a variable.
private var _localVariables:Object = new Object(); private var _localVariables:Object = {};
// Key - procedure, value - array of strings. // Key - procedure, value - array of strings.
private var _inputParams:Dictionary = new Dictionary(); private var _inputParams:Dictionary = new Dictionary();
@@ -61,9 +61,9 @@ package alternativa.engine3d.materials.compiler {
// Counters of variables by types // Counters of variables by types
private var _locals:Vector.<uint> = new Vector.<uint>(6, true); private var _locals:Vector.<uint> = new Vector.<uint>(6, true);
private var samplers:Object = new Object(); private var samplers:Object = {};
private var _varyings:Object = new Object(); private var _varyings:Object = {};
/** /**
* Creates a new Linker instance. * Creates a new Linker instance.
@@ -81,8 +81,8 @@ package alternativa.engine3d.materials.compiler {
data = null; data = null;
_locals[0] = _locals[1] = _locals[2] = _locals[3] = _locals[4] = _locals[5] = 0; _locals[0] = _locals[1] = _locals[2] = _locals[3] = _locals[4] = _locals[5] = 0;
procedures.length = 0; procedures.length = 0;
_varyings = new Object(); _varyings = {};
samplers = new Object(); samplers = {};
commandsCount = 0; commandsCount = 0;
slotsCount = 0; slotsCount = 0;
@@ -218,7 +218,7 @@ package alternativa.engine3d.materials.compiler {
if (data != null) return; if (data != null) return;
var v:Variable; var v:Variable;
var variables:Object = _linkedVariables = new Object(); var variables:Object = _linkedVariables = {};
var p:Procedure; var p:Procedure;
var i:int, j:int; var i:int, j:int;
var nv:Variable; var nv:Variable;

View File

@@ -179,7 +179,7 @@ package alternativa.engine3d.objects {
if (geometry == null) { if (geometry == null) {
geometry = new Geometry(4); geometry = new Geometry(4);
var attributes:Array = new Array(); var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -105,7 +105,7 @@ package alternativa.engine3d.objects {
var attributesLengths:Vector.<int> = new Vector.<int>(numAttributes, true); var attributesLengths:Vector.<int> = new Vector.<int>(numAttributes, true);
var numMeshes:Number = collectAttributes(root, attributesDict, attributesLengths); var numMeshes:Number = collectAttributes(root, attributesDict, attributesLengths);
var attributes:Array = new Array(); var attributes:Array = [];
var i:int; var i:int;
for (i = 0; i < numAttributes; i++) { for (i = 0; i < numAttributes; i++) {

View File

@@ -99,7 +99,7 @@ package alternativa.engine3d.objects {
geometry = new Geometry(24); geometry = new Geometry(24);
var attributes:Array = new Array(); var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -214,7 +214,7 @@ package alternativa.engine3d.objects {
if (geometry == null) { if (geometry == null) {
geometry = new Geometry(4); geometry = new Geometry(4);
var attributes:Array = new Array(); var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -187,7 +187,7 @@ package alternativa.engine3d.primitives {
// Set bounds // Set bounds
geometry = new Geometry(); geometry = new Geometry();
geometry._indices = indices; geometry._indices = indices;
var attributes:Array = new Array; var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -267,7 +267,7 @@ package alternativa.engine3d.primitives {
geometry = new Geometry(); geometry = new Geometry();
geometry._indices = indices; geometry._indices = indices;
var attributes:Array = new Array(); var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -100,7 +100,7 @@ package alternativa.engine3d.primitives {
// Set bounds // Set bounds
geometry = new Geometry(); geometry = new Geometry();
geometry._indices = indices; geometry._indices = indices;
var attributes:Array = new Array; var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;

View File

@@ -35,7 +35,7 @@ package alternativa.engine3d.resources {
* *
* @example This code creates stream on properties: x,y,z,u,v and forms a triangle by three vertices. * @example This code creates stream on properties: x,y,z,u,v and forms a triangle by three vertices.
* <listing version="3.0"> * <listing version="3.0">
* var attributes:Array = new Array(); * var attributes:Array = [];
* attributes[0] = VertexAttributes.POSITION; * attributes[0] = VertexAttributes.POSITION;
* attributes[1] = VertexAttributes.POSITION; * attributes[1] = VertexAttributes.POSITION;
* attributes[2] = VertexAttributes.POSITION; * attributes[2] = VertexAttributes.POSITION;
@@ -146,7 +146,7 @@ package alternativa.engine3d.resources {
*/ */
public function calculateNormals():void { public function calculateNormals():void {
if (!hasAttribute(VertexAttributes.POSITION)) throw new Error("Vertices positions is required to calculate normals"); if (!hasAttribute(VertexAttributes.POSITION)) throw new Error("Vertices positions is required to calculate normals");
var normals:Array = new Array(); var normals:Array = [];
var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION]; var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION];
var positionsData:ByteArray = positionsStream.data; var positionsData:ByteArray = positionsStream.data;
var positionsOffset:int = _attributesOffsets[VertexAttributes.POSITION]*4; var positionsOffset:int = _attributesOffsets[VertexAttributes.POSITION]*4;
@@ -283,7 +283,7 @@ package alternativa.engine3d.resources {
if (!hasAttribute(VertexAttributes.NORMAL)) throw new Error("Vertices normals is required to calculate tangents, call calculateNormals first"); if (!hasAttribute(VertexAttributes.NORMAL)) throw new Error("Vertices normals is required to calculate tangents, call calculateNormals first");
if (!hasAttribute(VertexAttributes.TEXCOORDS[uvChannel])) throw new Error("Specified uv channel does not exist in geometry"); if (!hasAttribute(VertexAttributes.TEXCOORDS[uvChannel])) throw new Error("Specified uv channel does not exist in geometry");
var tangents:Array = new Array(); var tangents:Array = [];
var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION]; var positionsStream:VertexStream = _attributesStreams[VertexAttributes.POSITION];
var positionsData:ByteArray = positionsStream.data; var positionsData:ByteArray = positionsStream.data;

View File

@@ -230,7 +230,7 @@ package alternativa.engine3d.shadows {
var geometry:Geometry = new Geometry(4); var geometry:Geometry = new Geometry(4);
mesh.geometry = geometry; mesh.geometry = geometry;
var attributes:Array = new Array(); var attributes:Array = [];
attributes[0] = VertexAttributes.POSITION; attributes[0] = VertexAttributes.POSITION;
attributes[1] = VertexAttributes.POSITION; attributes[1] = VertexAttributes.POSITION;
attributes[2] = VertexAttributes.POSITION; attributes[2] = VertexAttributes.POSITION;