Skip to main content
↑
↓
Spherical forums
Community for the
Sphere game engine
New?
Contact Us
to register an account!
1 Hour
1 Day
1 Week
1 Month
Forever
Community
Help
Search
Recent Posts
Log in
Contact Us
News
Spherical
Facebook
-
Twitter
-
Discord chat
New?
Contact us
to register an account!
Sphere Development
Resources
JavaScript's TypedArrays and Sphere's ByteArrays.
1
Print
Topic: JavaScript's TypedArrays and Sphere's ByteArrays.
(Read 4582 times)
previous topic
-
next topic
0 Members and 2 Guests are viewing this topic.
Flying Jester
Legendary Poster
Posts: 1,161
Logged
TurboSphere Developer
JavaScript's TypedArrays and Sphere's ByteArrays.
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
Last Edit
: September 09, 2014, 06:24:59 pm by Flying Jester
Learn some history?
The Flying Jester's Blog of Sorts
DaVince
Legendary Poster
Posts: 1,001
Logged
Administrator
Used Sphere for, like, half my life
Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #1
–
September 12, 2014, 06:41:24 am
Also seems like it could be useful in a web implementation of Sphere, this.
Spherical Downloads Repo
||
My (really old) Sphere stuff
N E O
Hero Poster
Posts: 585
Making it happen!
Logged
Administrator
Senior Administrator
Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #2
–
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!
Flying Jester
Legendary Poster
Posts: 1,161
Logged
TurboSphere Developer
Re: JavaScript's TypedArrays and Sphere's ByteArrays.
Reply #3
–
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.
Learn some history?
The Flying Jester's Blog of Sorts
1
Print
Sphere Development
Resources
JavaScript's TypedArrays and Sphere's ByteArrays.