[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] bit operations



You can probably achieve nearly the same level of compression (or even perhaps better depending on the data) much more easily by using the struct module and then compressing the result using zlib.

The you don't have to do any manual packing and unpacking of the data, which is tedious and error-prone.

-Casey

On Oct 4, 2010, at 4:18 AM, inigo delgado wrote:

> Hi:
> 
> This is more a python question... And may be stupid... but i cannot see it... please help.
> 
> I want to make my game playable online. So I have to send all the info to the client and then he will draw corresponding frames in corresponding positions in the screen...
> 
> So I want to send a list of integers to the client [(x, y) coords, image(ship/explosion...) index, frame index (they are many frames for each ship/explosion...)....  )]
> 
> So I decided to 'pack' them in order to send less bytes in a array (x,y never should be > 2048, so I can send this coords in 22 bits -3 bytes instead of 4-) doing something like this code that I've done to test :
> 
> t = 0.0 + (1 << 48) + (2 << 40) + (3 << 32) + (4 << 24) +  (5 <<16) + (6 << 8) + 7 # So I have all the info in one number
> print "t is " + `t`
> j =  (t >> 48)
> print j
> 
> And I've this output:
> 
> t is 283686952306183.0
> 
>  j =  (t >> 48)
> 
> TypeError: unsupported operand type(s) for >>: 'float' and 'int'
> 
> why this error? :(
>