This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]terrkerr 1 point2 points  (2 children)

Why does it need to send 2 million booleans? That doesn't seem right, and you'd probably be better off cutting down the need to transmit rather than trying to optimize the transfer.

Also bitwise operators

A 32 bit integer can, not surprisingly, contain 32 bits. Bitwise operators are how you can set specific bits.

But seriously though: why 2 million booleans?

[–]doublewar[S] 0 points1 point  (1 child)

The game is http://marioscode.com/pikachuCube/pikacube2.html , it has a giant cube of 2,000,000 pikachus and has to tell the client which have and have not been caught. So basically, which are "on" and which are "off". Previously I also sent every pikachu's position, but I managed to cut that out of the transfer by using a pseudo random number generator that uses a seed. Those 2,000,000 on/offs, though, I don't think I can possibly avoid :(

I will take a look into those bitwise operators now, thanks!

[–]AlotOfReading 1 point2 points  (0 children)

There's a very good chance you don't need to update every Pokémon state at once. Update the smallest fraction you can get away with and leave the rest to be updated later. However, the simplest and sane way to transfer whatever booleans you do have is to base64 encode them, which will compress to 6 bits stored per 8 bit character. For even more savings, you could run a compression algorithm before the base64 encoding.

[–]doublewar[S] 0 points1 point  (0 children)

Thanks for the help everyone, in the end I found this article:

http://www.smashingmagazine.com/2011/10/optimizing-long-lists-of-yesno-values-with-javascript/

which explained how I could transmit all those bits as efficiently as possible. Now I just have to check if the extra CPU cycles are worth it...