Beispiel #1
0
        private void Save()
        {
            using (var fs = File.OpenWrite("map0.ssmap"))
            {
                var payload = new ByteBufferWriter(0);

                var floats = new List <float>();

                var count = 0;
                for (; count < _boxes.Count; count++)
                {
                    var box = _boxes[count];

                    floats.Add(box.Min.X);
                    floats.Add(box.Min.Y);
                    floats.Add(box.Max.X);
                    floats.Add(box.Max.Y);
                }

                payload.WriteInt32(count);

                foreach (var f in floats)
                {
                    payload.WriteFloat(f);
                }

                var data = payload.ToArray();

                fs.Write(data, 0, data.Length);
            }
        }
Beispiel #2
0
        private void writeDataByteBuffer(ByteBufferWriter writer, int index, object data)
        {
            Assert.IsNotNull(writer);
            Assert.IsNotNull(data);
            writer.WriteVarint32((uint)index);
            switch (index)
            {
            case 0:
                writer.WriteBool((bool)data);
                break;

            case 1:
                writer.WriteByte((byte)data);
                break;

            case 2:
                writer.WriteUint16((ushort)data);
                break;

            case 3:
                writer.WriteUint32((uint)data);
                break;

            case 4:
                writer.WriteUint64((ulong)data);
                break;

            case 5:
                writer.WriteInt16((short)data);
                break;

            case 6:
                writer.WriteInt32((int)data);
                break;

            case 7:
                writer.WriteInt64((long)data);
                break;

            case 8:
                writer.WriteVarint32((uint)data);
                break;

            case 9:
                writer.WriteVarint64((ulong)data);
                break;

            case 10:
                writer.WriteSVarint32((int)data);
                break;

            case 11:
                writer.WriteSVarint64((long)data);
                break;

            case 12:
                writer.WriteFloat((float)data);
                break;

            case 13:
                writer.WriteDouble((double)data);
                break;

            case 14:
                writer.WriteString((string)data);
                break;

            case 15: {
                var buffer = (byte[])data;
                writer.WriteVarint32((uint)buffer.Length);
                writer.WriteBuffer(buffer, 0, buffer.Length);
            }
            break;

            case 16: {
                writer.WriteVarint32((uint)(int)data);
                writer.Skip((int)data);
            }
            break;

            default:
                Assert.Fail();
                break;
            }
        }