UNPKG

starling-framework

Version:

A fast, productive library for 2D cross-platform development.

135 lines (119 loc) 4.68 kB
// Class: starling.rendering.BatchProcessor var $global = typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this $global.Object.defineProperty(exports, "__esModule", {value: true}); var __map_reserved = {}; // Imports var $hxClasses = require("./../../hxClasses_stub").default; var $hxEnums = require("./../../hxEnums_stub").default; var $import = require("./../../import_stub").default; function openfl__$Vector_VectorIterator() {return require("./../../openfl/_Vector/VectorIterator");} function openfl__$Vector_Vector_$Impl_$() {return require("./../../openfl/_Vector/Vector_Impl_");} function starling_utils_MeshSubset() {return require("./../../starling/utils/MeshSubset");} function starling_rendering_BatchPool() {return require("./../../starling/rendering/BatchPool");} function starling_rendering_BatchToken() {return require("./../../starling/rendering/BatchToken");} // Constructor var BatchProcessor = function() { this._batches = (openfl__$Vector_Vector_$Impl_$().default)._new(); this._batchPool = new (starling_rendering_BatchPool().default)(); this._cacheToken = new (starling_rendering_BatchToken().default)(); } // Meta BatchProcessor.__name__ = "starling.rendering.BatchProcessor"; BatchProcessor.__isInterface__ = false; BatchProcessor.prototype = { dispose: function() { var batch = new (openfl__$Vector_VectorIterator().default)(this._batches); while(batch.hasNext()) { var batch1 = batch.next(); batch1.dispose(); } this._batches.length = 0; this._batchPool.purge(); this._currentBatch = null; this._onBatchComplete = null; }, addMesh: function(mesh,state,subset,ignoreTransformations) { if(ignoreTransformations == null) { ignoreTransformations = false; } if(subset == null) { subset = BatchProcessor.sMeshSubset; subset.vertexID = subset.indexID = 0; subset.numVertices = mesh.get_numVertices(); subset.numIndices = mesh.get_numIndices(); } else { if(subset.numVertices < 0) { subset.numVertices = mesh.get_numVertices() - subset.vertexID; } if(subset.numIndices < 0) { subset.numIndices = mesh.get_numIndices() - subset.indexID; } } if(subset.numVertices > 0) { if(this._currentBatch == null || !this._currentBatch.canAddMesh(mesh,subset.numVertices)) { this.finishBatch(); this._currentStyleType = mesh.get_style().get_type(); this._currentBatch = this._batchPool.get(this._currentStyleType); this._currentBatch.set_blendMode(state != null ? state.get_blendMode() : mesh.get_blendMode()); this._cacheToken.setTo(this._batches.length); (openfl__$Vector_Vector_$Impl_$().default).set(this._batches,this._batches.length,this._currentBatch); } var matrix = state != null ? state._modelviewMatrix : null; var alpha = state != null ? state._alpha : 1.0; this._currentBatch.addMeshAt(mesh,-1,-1,matrix,alpha,subset,ignoreTransformations); this._cacheToken.vertexID += subset.numVertices; this._cacheToken.indexID += subset.numIndices; } }, finishBatch: function() { var meshBatch = this._currentBatch; if(meshBatch != null) { this._currentBatch = null; this._currentStyleType = null; if(this._onBatchComplete != null) { this._onBatchComplete(meshBatch); } } }, clear: function() { var numBatches = this._batches.length; var _g = 0; var _g1 = numBatches; while(_g < _g1) { var i = _g++; this._batchPool.put(this._batches[i]); } this._batches.length = 0; this._currentBatch = null; this._currentStyleType = null; this._cacheToken.reset(); }, getBatchAt: function(batchID) { return this._batches[batchID]; }, trim: function() { this._batchPool.purge(); }, fillToken: function(token) { token.batchID = this._cacheToken.batchID; token.vertexID = this._cacheToken.vertexID; token.indexID = this._cacheToken.indexID; return token; }, get_numBatches: function() { return this._batches.length; }, get_onBatchComplete: function() { return this._onBatchComplete; }, set_onBatchComplete: function(value) { return this._onBatchComplete = value; } }; BatchProcessor.prototype.__class__ = BatchProcessor.prototype.constructor = $hxClasses["starling.rendering.BatchProcessor"] = BatchProcessor; // Init Object.defineProperties(BatchProcessor.prototype,{ numBatches : { get : function () { return this.get_numBatches (); }}, onBatchComplete : { get : function () { return this.get_onBatchComplete (); }, set : function (v) { return this.set_onBatchComplete (v); }}}); // Statics BatchProcessor.sMeshSubset = new (starling_utils_MeshSubset().default)() // Export exports.default = BatchProcessor;