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); } }
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); } }
public static void PersistPoint3D(this StatePersister persister, ref Point3D value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(name); persister.PersistPoint3DImpl(ref value); persister.EndObject(); }
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(); }
public static void PersistHashSetValue <T>(this StatePersister persister, HashSet <T> value, PersistListItemCallback <T> callback) { persister.BeginObject(); persister.PersistHashSetValueImpl(value, callback); persister.EndObject(); }
public static void PersistMatrix4x3Value(this StatePersister persister, ref Matrix4x3 value, bool readVersion = true) { persister.BeginObject(); persister.PersistMatrix4x3Impl(ref value, readVersion); persister.EndObject(); }
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(); }
public static void PersistObjectNameAndIdList(this StatePersister persister, List <ObjectNameAndId> value, [CallerArgumentExpression("value")] string name = "") { persister.BeginObject(); persister.PersistVersion(1); persister.PersistList( value,
public static void PersistPoint3DValue(this StatePersister persister, ref Point3D value) { persister.BeginObject(); persister.PersistPoint3DImpl(ref value); persister.EndObject(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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(); }
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); } }
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); } }