Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Wojciechowski committed Sep 23, 2015
1 parent e25a5e2 commit 6470103
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 33 deletions.
7 changes: 7 additions & 0 deletions js/data/buffer/buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,12 @@ Buffer.prototype = {

this.setupViews();
}
},

serialize: function() {
return {
serialized: this,
transferables: [this.array]
};
}
};
40 changes: 17 additions & 23 deletions js/data/buffer/triangle_element_buffer.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
'use strict';

var util = require('../../util/util');
var Buffer = require('./buffer');

module.exports = TriangleElementBuffer;

function TriangleElementBuffer(buffer) {
Buffer.call(this, buffer);
}

TriangleElementBuffer.prototype = util.inherit(Buffer, {
itemSize: 6, // bytes per triangle (3 * unsigned short == 6 bytes)
arrayType: 'ELEMENT_ARRAY_BUFFER',

add: function(a, b, c) {
var pos2 = this.pos / 2;

this.resize();

this.ushorts[pos2 + 0] = a;
this.ushorts[pos2 + 1] = b;
this.ushorts[pos2 + 2] = c;

this.pos += this.itemSize;
var createBuffer2Shim = require('../buffer2_shim');
var Buffer2 = require('../buffer2');

module.exports = createBuffer2Shim({
buffer2: {
type: Buffer2.BufferType.ELEMENT,
attributes: {
verticies: {
components: 3,
type: Buffer2.AttributeType.UNSIGNED_SHORT
}
}
},
methods: {
add: function(a, b, c) {
this.buffer2.push([a, b, c]);
}
}
});
25 changes: 25 additions & 0 deletions js/data/buffer2_shim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

var Buffer1 = require('./buffer/buffer');
var Buffer2 = require('./buffer2');
var util = require('../util/util');

module.exports = function createBuffer2Shim(options) {

function Klass(instanceOptions) {
this.buffer2 = new Buffer2(instanceOptions || options.buffer2);
}

Klass.prototype = util.inherit(Klass, util.extend({
get pos() { return this.buffer2.length * this.itemSize; },
get itemSize() { return this.buffer2.itemSize; },
get array() { return this.buffer2.arrayBuffer; },
get arrayType() { return this.buffer2.type; },
bind: Buffer1.prototype.bind,
destroy: Buffer1.prototype.destroy,
serialize: function() { return this.buffer2.serialize(); }
}, options.methods));

return Klass;

};
17 changes: 12 additions & 5 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,14 @@ WorkerTile.prototype.parse = function(data, layers, actor, callback) {
buffers.collisionBoxVertex = result.buffers.collisionBoxVertex;
}

var transferables = [],
elementGroups = {};
var transferables = [];
var serializedBuffers = [];
var elementGroups = {};

for (k in buffers) {
transferables.push(buffers[k].array);
var buffer = buffers[k];
serializedBuffers.push(buffer.serialized);
transferables = transferables.concat(buffer.transferables);
}

for (k in buckets) {
Expand All @@ -239,7 +242,6 @@ WorkerTile.prototype.redoPlacement = function(angle, pitch, collisionDebug) {
}

var buffers = new BufferSet();
var transferables = [];
var elementGroups = {};
var collisionTile = new CollisionTile(angle, pitch);

Expand All @@ -253,8 +255,13 @@ WorkerTile.prototype.redoPlacement = function(angle, pitch, collisionDebug) {
}
}

var serializedBuffers = [];
var transferables = [];

for (var k in buffers) {
transferables.push(buffers[k].array);
var buffer = buffers[k].serialize();
transferables = transferables.concat(buffer.transferables);
serializedBuffers.push(buffer.serialized);
}

return {
Expand Down
8 changes: 3 additions & 5 deletions test/js/buffer/triangle_element_buffer.test.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
'use strict';

var test = require('prova');
var Buffer = require('../../../js/data/buffer/buffer');
var TriangleElementBuffer = require('../../../js/data/buffer/triangle_element_buffer');

test('TriangleElementBuffer', function(t) {
var buf = new Buffer();
t.ok(new TriangleElementBuffer(buf), 'default buffer');
var triangleElems = new TriangleElementBuffer(buf);
triangleElems.setupViews();
var serialized = (new TriangleElementBuffer()).serialize().serialized;
t.ok(new TriangleElementBuffer(serialized), 'default buffer');
var triangleElems = new TriangleElementBuffer(serialized);
t.equal(triangleElems.itemSize, 6);
t.equal(triangleElems.arrayType, 'ELEMENT_ARRAY_BUFFER');
t.equal(triangleElems.add(0, 0, 0), undefined);
Expand Down

0 comments on commit 6470103

Please sign in to comment.