Skip to content

Instantly share code, notes, and snippets.

@flimshaw
Last active May 5, 2017 06:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flimshaw/0446885d687f3c14a09684465b805b6d to your computer and use it in GitHub Desktop.
Save flimshaw/0446885d687f3c14a09684465b805b6d to your computer and use it in GitHub Desktop.
var http = require('http')
class HttpStore {
constructor(storeUrl) {
// begin downloading the url we requested, stream it to our handleData function
http.get(storeUrl, (res) => {
res.on('data', this.handleData.bind(this))
res.on('end', this.handleEnd.bind(this))
})
this.bytesIn = 0;
this.downloaded = 0;
this.chunkCounter = 0;
this.loading = true;
this.chunkSize = 16384;
this.queue = [];
}
handleData(buf) {
// queue the most recent packet of data for transmission to the GPU, pass some info about it
this.queue.push({
buf: buf,
offset: this.chunkCounter,
count: buf.length
})
// increment our packet counter
this.chunkCounter += buf.length;
}
handleEnd(data) {
console.log("DONE");
}
// called on enterframe, apply all queued updates to the particle simulation
update(view) {
this.queue.map( (q) => {
view.queueUpdate(q.buf, q.offset, q.count);
})
this.queue = [];
}
}
module.exports = HttpStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment