appcelerator/hyperloop — pull request #103 by infosia (2013-10-16 14:47:53+00:00)
Title: Add ability to put @memory from JS array dynamically

Add ability to put memory from JS array dynamically.

```javascript
// put float array
m = @memory();
m.putFloat([0.5, 1.0, 1.5])
assert(m.length===(3 * size_of_float), "@memory.putFloat([])", m.length);
assert(m.toFloat(0) == 0.5, "@memory.toFloat(0)==0.5", m.toFloat(0));
assert(m.toFloat(1) == 1.0, "@memory.toFloat(1)==1.0", m.toFloat(1));
assert(m.toFloat(2) == 1.5, "@memory.toFloat(2)==1.5", m.toFloat(2));

// add float array from given index
m.putFloat([20.110000610351562, 20], 3);
assert(m.length===(5 * size_of_float), "@memory.putFloat([])", m.length);
assert(m.toFloat(0) == 0.5, "@memory.toFloat(0)", m.toFloat(0));
assert(m.toFloat(1) == 1.0, "@memory.toFloat(1)", m.toFloat(1));
assert(m.toFloat(2) == 1.5, "@memory.toFloat(2)", m.toFloat(2));
assert(m.toFloat(3) == 20.110000610351562, "@memory.toFloat(3)", m.toFloat(3));
assert(m.toFloat(4) == 20, "@memory.toFloat(4)", m.toFloat(4));
```

Vertex initialization for OpenGL Game of Life example become over 2x faster by pushing data using JS array all at once.

```javascript
var colorDataArray = [];
var cellDataArray = [];
for (var x = 0; x < xSize; x++) {
cells[x] = [];
for (var y = 0; y < ySize; y++) {
var alive = Math.random() >= 0.5;

// save the cell
cells[x][y] = {
lastAlive: alive,
alive: alive
};

var alpha = alive ? 1.0 : 0.0;

colorDataArray.push(1.0);
colorDataArray.push(1.0);
colorDataArray.push(1.0);
colorDataArray.push(alpha);

cellDataArray.push(CELL_START + (x * CELL_SIZE));
cellDataArray.push(CELL_START + (y * CELL_SIZE));
cellDataArray.push(0.0);

/* much faster than pushing data individually like below
colorBufferData.putFloat(1.0, colorindex);
colorBufferData.putFloat(1.0, colorindex + 1);
colorBufferData.putFloat(1.0, colorindex + 2);
colorBufferData.putFloat(alpha, colorindex + 3);

cellVertexData.putFloat(CELL_START + (x * CELL_SIZE), cellindex);
cellVertexData.putFloat(CELL_START + (y * CELL_SIZE), cellindex + 1);
cellVertexData.putFloat(0.0, cellindex + 2);
*/

}
}

// load the data into memory at once
cellVertexData.putFloat(cellDataArray);
colorBufferData.putFloat(colorDataArray);
```