Last active
May 5, 2017 06:33
-
-
Save flimshaw/0446885d687f3c14a09684465b805b6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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