Exemplo n.º 1
0
        public static void PersistColorRgba(this StatePersister persister, ref ColorRgba value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var r = value.R;

            persister.PersistByte(ref r);

            var g = value.G;

            persister.PersistByte(ref g);

            var b = value.B;

            persister.PersistByte(ref b);

            var a = value.A;

            persister.PersistByte(ref a);

            persister.EndObject();

            if (persister.Mode == StatePersistMode.Read)
            {
                value = new ColorRgba(r, g, b, a);
            }
        }
Exemplo n.º 2
0
        public static void PersistColorRgbaInt(this StatePersister persister, ref ColorRgba value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var r = (int)value.R;

            persister.PersistInt32(ref r);

            var g = (int)value.G;

            persister.PersistInt32(ref g);

            var b = (int)value.B;

            persister.PersistInt32(ref b);

            var a = (int)value.A;

            persister.PersistInt32(ref a);

            persister.EndObject();

            if (persister.Mode == StatePersistMode.Read)
            {
                if (r > 255 || g > 255 || b > 255 || a > 255)
                {
                    throw new InvalidOperationException();
                }

                value = new ColorRgba((byte)r, (byte)g, (byte)b, (byte)a);
            }
        }
Exemplo n.º 3
0
        public static void PersistPoint3D(this StatePersister persister, ref Point3D value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            persister.PersistPoint3DImpl(ref value);

            persister.EndObject();
        }
Exemplo n.º 4
0
        public static void PersistHashSet <T>(this StatePersister persister, HashSet <T> value, PersistListItemCallback <T> callback, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            persister.PersistHashSetValueImpl(value, callback);

            persister.EndObject();
        }
Exemplo n.º 5
0
        public static void PersistHashSetValue <T>(this StatePersister persister, HashSet <T> value, PersistListItemCallback <T> callback)
        {
            persister.BeginObject();

            persister.PersistHashSetValueImpl(value, callback);

            persister.EndObject();
        }
Exemplo n.º 6
0
        public static void PersistMatrix4x3Value(this StatePersister persister, ref Matrix4x3 value, bool readVersion = true)
        {
            persister.BeginObject();

            persister.PersistMatrix4x3Impl(ref value, readVersion);

            persister.EndObject();
        }
Exemplo n.º 7
0
        public static void PersistMatrix4x3(this StatePersister persister, ref Matrix4x3 value, bool readVersion = true, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            persister.PersistMatrix4x3Impl(ref value, readVersion);

            persister.EndObject();
        }
Exemplo n.º 8
0
        public static void PersistObjectNameAndIdList(this StatePersister persister, List <ObjectNameAndId> value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject();

            persister.PersistVersion(1);

            persister.PersistList(
                value,
Exemplo n.º 9
0
        public static void PersistPoint3DValue(this StatePersister persister, ref Point3D value)
        {
            persister.BeginObject();

            persister.PersistPoint3DImpl(ref value);

            persister.EndObject();
        }
Exemplo n.º 10
0
        public static void PersistVector3Value(this StatePersister persister, ref Vector3 value)
        {
            persister.BeginObject();

            persister.PersistSingle(ref value.X, "X");
            persister.PersistSingle(ref value.Y, "Y");
            persister.PersistSingle(ref value.Z, "Z");

            persister.EndObject();
        }
Exemplo n.º 11
0
        public static void PersistVector3(this StatePersister persister, ref Vector3 value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            persister.PersistSingle(ref value.X, "X");
            persister.PersistSingle(ref value.Y, "Y");
            persister.PersistSingle(ref value.Z, "Z");

            persister.EndObject();
        }
Exemplo n.º 12
0
        public static void PersistListWithUInt32Count <T>(this StatePersister persister, List <T> value, PersistListItemCallback <T> callback, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var count = (uint)value.Count;

            persister.PersistUInt32(ref count);

            PersistListImpl(persister, value, count, callback);

            persister.EndObject();
        }
Exemplo n.º 13
0
        public static void PersistListWithByteCountValue <T>(this StatePersister persister, List <T> value, PersistListItemCallback <T> callback)
        {
            persister.BeginObject();

            var count = (byte)value.Count;

            persister.PersistByte(ref count);

            PersistListImpl(persister, value, count, callback);

            persister.EndObject();
        }
Exemplo n.º 14
0
        public static void PersistDictionaryWithUInt32Count <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var count = (uint)value.Count;

            persister.PersistUInt32(ref count);

            persister.PersistDictionaryImpl(value, count, callback);

            persister.EndObject();
        }
Exemplo n.º 15
0
        public static void PersistDictionaryValue <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, PersistDictionaryItemCallback <TKey, TValue> callback)
        {
            persister.BeginObject();

            var count = (ushort)value.Count;

            persister.PersistUInt16(ref count);

            persister.PersistDictionaryImpl(value, count, callback);

            persister.EndObject();
        }
Exemplo n.º 16
0
        private static void PersistDictionaryImpl <TKey, TValue>(this StatePersister persister, Dictionary <TKey, TValue> value, uint count, PersistDictionaryItemCallback <TKey, TValue> callback)
        {
            persister.BeginArray("Items");

            if (persister.Mode == StatePersistMode.Read)
            {
                value.Clear();

                for (var i = 0; i < count; i++)
                {
                    persister.BeginObject();

                    var itemKey   = default(TKey);
                    var itemValue = default(TValue);
                    callback(persister, ref itemKey, ref itemValue);
                    value.Add(itemKey, itemValue);

                    persister.EndObject();
                }
            }
            else
            {
                foreach (var item in value)
                {
                    persister.BeginObject();

                    var itemKey   = item.Key;
                    var itemValue = item.Value;
                    callback(persister, ref itemKey, ref itemValue);

                    persister.EndObject();
                }
            }

            persister.EndArray();
        }
Exemplo n.º 17
0
        public static void PersistBitArray <TEnum>(this StatePersister persister, ref BitArray <TEnum> result, [CallerArgumentExpression("result")] string name = "")
            where TEnum : Enum
        {
            persister.BeginObject(name);

            persister.PersistVersion(1);

            if (persister.Mode == StatePersistMode.Read)
            {
                result.SetAll(false);
            }

            var count = (uint)result.NumBitsSet;

            persister.PersistUInt32(ref count);

            persister.BeginArray("Items");

            if (persister.Mode == StatePersistMode.Read)
            {
                var stringToValueMap = Data.Ini.IniParser.GetEnumMap <TEnum>();

                for (var i = 0; i < count; i++)
                {
                    string stringValue = default;
                    persister.PersistAsciiStringValue(ref stringValue);

                    var enumValue = (TEnum)stringToValueMap[stringValue];

                    result.Set(enumValue, true);
                }
            }
            else
            {
                var valueToStringMap = Data.Ini.IniParser.GetEnumMapReverse <TEnum>();

                foreach (var setBit in result.GetSetBits())
                {
                    var stringValue = valueToStringMap[setBit];

                    persister.PersistAsciiStringValue(ref stringValue);
                }
            }

            persister.EndArray();

            persister.EndObject();
        }
Exemplo n.º 18
0
        public static void PersistArrayWithUInt32Length <T>(this StatePersister persister, T[] value, PersistListItemCallback <T> callback, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var length = (uint)value.Length;

            persister.PersistUInt32(ref length);

            if (length != value.Length)
            {
                throw new InvalidStateException();
            }

            PersistArray(persister, value, callback, "Items");

            persister.EndObject();
        }
Exemplo n.º 19
0
        public static void PersistPoint2D(this StatePersister persister, ref Point2D value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var x = value.X;

            persister.PersistInt32(ref x);

            var y = value.Y;

            persister.PersistInt32(ref y);

            if (persister.Mode == StatePersistMode.Read)
            {
                value = new Point2D(x, y);
            }

            persister.EndObject();
        }
Exemplo n.º 20
0
        public static void PersistDateTime(this StatePersister persister, ref DateTime value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var year = (ushort)value.Year;

            persister.PersistUInt16(ref year);

            var month = (ushort)value.Month;

            persister.PersistUInt16(ref month);

            var day = (ushort)value.Day;

            persister.PersistUInt16(ref day);

            var dayOfWeek = (ushort)value.DayOfWeek;

            persister.PersistUInt16(ref dayOfWeek);

            var hour = (ushort)value.Hour;

            persister.PersistUInt16(ref hour);

            var minute = (ushort)value.Minute;

            persister.PersistUInt16(ref minute);

            var second = (ushort)value.Second;

            persister.PersistUInt16(ref second);

            var millisecond = (ushort)value.Millisecond;

            persister.PersistUInt16(ref millisecond);

            persister.EndObject();

            if (persister.Mode == StatePersistMode.Read)
            {
                value = new DateTime(year, month, day, hour, minute, second, millisecond);
            }
        }
Exemplo n.º 21
0
        public static void PersistRandomVariable(this StatePersister persister, ref RandomVariable value, [CallerArgumentExpression("value")] string name = "")
        {
            persister.BeginObject(name);

            var distributionType = value.DistributionType;

            persister.PersistEnum(ref distributionType);

            var low = value.Low;

            persister.PersistSingle(ref low);

            var high = value.High;

            persister.PersistSingle(ref high);

            persister.EndObject();

            if (persister.Mode == StatePersistMode.Read)
            {
                value = new RandomVariable(low, high, distributionType);
            }
        }