Example #1
0
 public override void Write(BitWriteBuffer buffer)
 {
     buffer.Write(m_needsUpdate);
     if (m_needsUpdate)
     {
         buffer.Write(m_frameTime);
         m_needsUpdate = false;
     }
 }
        public void TestReadWrite()
        {
            byte byteValue   = 32;
            int  numBitsByte = BitUtils.BitsToHoldUInt(byteValue);

            uint uintValue   = 123456;
            int  numBitsUInt = BitUtils.BitsToHoldUInt((uint)uintValue);

            BitWriteBuffer wb = new BitWriteBuffer();

            wb.Write(true);
            wb.Write(false);
            wb.Write(byteValue);
            wb.Write(byteValue, numBitsByte);
            wb.Write(uintValue);
            wb.Write(uintValue, numBitsUInt);

            byte[] data = wb.Data;
            using (Stream stream = File.OpenWrite("data.bin"))
            {
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    writer.Write(wb.LengthBits);
                    writer.Write(wb.LengthBytes);
                    writer.Write(data, 0, wb.LengthBytes);
                }
            }

            BitReadBuffer rb = null;

            using (Stream stream = File.OpenRead("data.bin"))
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    int lenBits  = reader.ReadInt32();
                    int lenBytes = reader.ReadInt32();
                    data = new byte[lenBytes];
                    reader.Read(data, 0, lenBytes);

                    rb = new BitReadBuffer(data, lenBits);
                }
            }

            Assert.AreEqual(true, rb.ReadBoolean());
            Assert.AreEqual(false, rb.ReadBoolean());

            Assert.AreEqual(byteValue, rb.ReadByte());
            Assert.AreEqual(byteValue, rb.ReadByte(numBitsByte));

            Assert.AreEqual(uintValue, rb.ReadUInt32());
            Assert.AreEqual(uintValue, rb.ReadUInt32(numBitsUInt));
        }
Example #3
0
        private void WriteKeyEntries(BitWriteBuffer buffer, List <KeyEntry> entries)
        {
            bool hasKeys = entries.Count > 0;

            buffer.Write(hasKeys);
            if (hasKeys)
            {
                buffer.Write((byte)entries.Count);
                for (int i = 0; i < entries.Count; ++i)
                {
                    buffer.Write((uint)entries[i].state, BitsPerKeyState);
                    buffer.Write((uint)entries[i].arg.key, BitsPerKey);

                    bool hasPlayerIndex = entries[i].arg.playerIndex != -1;
                    buffer.Write(hasPlayerIndex);
                    if (hasPlayerIndex)
                    {
                        buffer.Write((uint)entries[i].arg.playerIndex, BitsPerPlayerIndex);
                    }
                }

                entries.Clear();
            }
        }
Example #4
0
 public override void Write(BitWriteBuffer buffer)
 {
     buffer.Write(m_randSeed);
 }
Example #5
0
        //////////////////////////////////////////////////////////////////////////////

        #region Commands

        private void Write(DemoCmd cmd)
        {
            m_buffer.Write((uint)cmd.cmdType, BitsPerCmdType);
            cmd.Write(m_buffer);
        }