Spherical forums

Sphere Development => Resources => Topic started by: Flying Jester on September 09, 2014, 06:22:24 pm

Title: JavaScript's TypedArrays and Sphere's ByteArrays.
Post by: Flying Jester on September 09, 2014, 06:22:24 pm
For a long time, it was basically impossible to work with binary data natively in JS. Sphere solved this problem with a custom object, the ByteArray.

But time's change, and rooms are rearranged. Now we have TypedArrays, which are explicitly meant for the same task.

I've written a script that implements the ByteArray object using TypedArrays. I intend this to be the basis of the implementation of ByteArrays in TurboSphere, especially because TurboSphere will use TypedArrays in its API instead of ByteArrays.

https://gist.github.com/FlyingJester/03c7a0ae4a5d782d114b (https://gist.github.com/FlyingJester/03c7a0ae4a5d782d114b)
Title: Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Post by: DaVince on September 12, 2014, 06:41:24 am
Also seems like it could be useful in a web implementation of Sphere, this.
Title: Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Post by: N E O on September 12, 2014, 01:09:24 pm
Yea, this will likely be the web shim for ByteArrays, but its use of typed arrays will almost certainly exclude older browsers which can't or don't support typed array shims. Thanks for doing the work!
Title: Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Post by: Flying Jester on November 14, 2014, 07:51:49 pm
So, I'm using this to read map files, and I've uncovered a couple problems with this implementation.

I'll post an updated version of this once I get everything working nicely, but there is one major issue with this implementation. A large ArrayBuffer will blow out the JS stack. I'm testing using Kefka's Revenge and Trial & Error maps, and almost all of them are too big to fully buffer into a JS array as I do here, since you can end up with a few arrays on the stack, all as big as the ArrayBuffer is. The more elegant solution that I didn't realize at the time is to just use the Uint8Array.buffer.slice() method.