Author Topic: Bitstream Saving  (Read 1424 times)


  • Not-a-newbie
  • *
  • Posts: 18
  • Karma: 1
    • View Profile
Bitstream Saving
« on: January 13, 2008, 10:58:23 PM »
I have a problem that I worked around, but I would like to get a response.

In each packet that I send.  I also send the last 5 packets.

So I Write the packet to a bitstream and keep the bitstream around so that I don't have to go through the process of writing it again, save some cpu.

Then when I send a packet, I write my saved bitstreams to one bitstream using

sendbits.Write( packettype );

for ( i = 0; i < 5; ++i )
  sendbits.Write( &savebits );

I just keep an index around to savebits and call Reset(), then use it again.  Seemed like a good idea.

But when I get some of these packets, they get messed up.  Seems that some data is missing, stepping through the code I get many less bits than I expected.  The data is wrong and inconsistent on subsequent calls, but I believe that is because I'm losing bits.

Am I doing something wrong?  I did fix this problem by just not saving the bitstreams and rewriting everything to the bitstream every time.  But it seemed a waste to go through that processing again when it's the same exact packet that I'm resending.


putting multiplayer code into my engine for the next release, tcp had too much lag so I'm trying this out.