Beispiel #1
0
        public override object ReadJson(JsonReader reader, Type ty,
                                        object existingValue, JsonSerializer serializer)
        {
            var bytes = reader.Value as byte[];

            if (ty.IsGenericType && ty.GetGenericTypeDefinition() == typeof(SortedMap <,>))
            {
                // will dispatch to Spreads types
                return(Serializer.Deserialize(bytes, ty));
            }

            // Other than maps, we are cool at arrays. For other types JSON.NET is cool
            if (!ty.IsArray)
            {
                return(serializer.Deserialize(reader, ty));
            }

            var elTy = ty.GetElementType();

            if (BlittableHelper.IsBlittable(elTy)
                //|| ty == typeof(DateTimeOffset)
                || ty == typeof(DateTime))
            {
                //if (bytes == null) {
                //	return null;
                //} else if (bytes.Length == 0) {
                //	return Array.CreateInstance(ty.GetElementType(), 0);
                //}
                // will dispatch to Spreads types
                return(Serializer.Deserialize(bytes, ty));
            }

            //var bytes = reader.Value as byte[];
            return(serializer.Deserialize(reader, ty));
        }
Beispiel #2
0
        public static AnimationCurveEvaluatorDirectGroup Create <T>()
        {
            // Those types require interpolators
            // TODO: Simple enough for now, but at some point we might want a mechanism to register them externally?
            if (typeof(T) == typeof(float))
            {
                return(new AnimationCurveEvaluatorDirectFloatGroup());
            }

            if (typeof(T) == typeof(Quaternion))
            {
                return(new AnimationCurveEvaluatorDirectQuaternionGroup());
            }

            if (typeof(T) == typeof(Vector3))
            {
                return(new AnimationCurveEvaluatorDirectVector3Group());
            }

            if (typeof(T) == typeof(Vector4))
            {
                return(new AnimationCurveEvaluatorDirectVector4Group());
            }

            // Blittable
            if (BlittableHelper.IsBlittable(typeof(T)))
            {
                return(new AnimationCurveEvaluatorDirectBlittableGroup <T>());
            }

            // Objects
            return(new AnimationCurveEvaluatorDirectObjectGroup <T>());
        }
Beispiel #3
0
        public override void WriteJson(JsonWriter writer, object value,
                                       JsonSerializer serializer)
        {
            var ty = value.GetType();

            //if (ty.IsGenericType && ty.GetGenericTypeDefinition() == typeof(SortedMap<,>)) {
            //	// will dispatch to Spreads types
            //	var bytes = Serializer.Serialize(value); // TODO resolvedCall = true
            //	writer.WriteValue(bytes);
            //}

            //// Other than maps, we are cool at arrays. For other types JSON.NET is cool
            //if (!ty.IsArray) {
            //	serializer.Serialize(writer, value);
            //}

            if (ty.IsArray)
            {
                var elTy = ty.GetElementType();
                if (BlittableHelper.IsBlittable(elTy)
                    //|| ty == typeof(DateTimeOffset)
                    || ty == typeof(DateTime))
                {
                    //var arr = (Array)value;
                    //if (arr.Length == 0) {
                    //	writer.WriteValue(EmptyArray<byte>.Instance);
                    //} else {
                    // will dispatch to Spreads types
                    var bytes = Serializer.Serialize(value); // TODO resolvedCall = true
                    writer.WriteValue(bytes);
                    //}
                }
                else
                {
                    serializer.Serialize(writer, value);
                }
            }
            else
            {
                // will dispatch to Spreads types
                var bytes = Serializer.Serialize(value); // TODO resolvedCall = true
                writer.WriteValue(bytes);
            }
        }
Beispiel #4
0
        public static AnimationCurveEvaluatorOptimizedGroup Create <T>()
        {
            // Those types require interpolators
            // TODO: Simple enough for now, but at some point we might want a mechanism to register them externally?
            if (typeof(T) == typeof(float))
            {
                return(new AnimationCurveEvaluatorOptimizedFloatGroup());
            }

            // TODO: Reintroduces explicit int path for now, since generic path does not work on iOS
            if (typeof(T) == typeof(int))
            {
                return(new AnimationCurveEvaluatorOptimizedIntGroup());
            }

            if (typeof(T) == typeof(Quaternion))
            {
                return(new AnimationCurveEvaluatorOptimizedQuaternionGroup());
            }

            if (typeof(T) == typeof(Vector3))
            {
                return(new AnimationCurveEvaluatorOptimizedVector3Group());
            }

            if (typeof(T) == typeof(Vector4))
            {
                return(new AnimationCurveEvaluatorOptimizedVector4Group());
            }

            // Blittable
            if (BlittableHelper.IsBlittable(typeof(T)))
            {
                return(new AnimationCurveEvaluatorOptimizedBlittableGroup <T>());
            }

            // Objects
            return(new AnimationCurveEvaluatorOptimizedObjectGroup <T>());
        }
Beispiel #5
0
        protected override sealed JsonConverter ResolveContractConverter(Type ty)
        {
            // Serialize maps directly
            if (ty.IsGenericType && ty.GetGenericTypeDefinition() == typeof(SortedMap <,>))
            {
                return(new SpreadsJsonConverter());
            }

            // Other than maps, we are cool at arrays. For other types JSON.NET is cool
            if (!ty.IsArray)
            {
                return(base.ResolveContractConverter(ty));
            }

            var elTy = ty.GetElementType();

            if (BlittableHelper.IsBlittable(elTy) ||
                elTy == typeof(DateTimeOffset) ||
                elTy == typeof(DateTime))
            {
                return(new SpreadsJsonConverter());
            }
            return(base.ResolveContractConverter(ty));
        }
 public void BlittableDateTimeTest()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableDateTime>());
 }
 public void BlittableCharTest()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableChar>());
 }
 public void DecimalWrapperTest()
 {
     Assert.False(BlittableHelper.IsBlittable <DecimalWrapper>());
 }
 public void DecimalTest()
 {
     Assert.False(BlittableHelper.IsBlittable <decimal>());
 }
 public void DateTimeTest()
 {
     Assert.False(BlittableHelper.IsBlittable <DateTime>());
 }
 public void ArrayTest()
 {
     Assert.True(BlittableHelper.IsBlittable <int[]>());
 }
 public void BlittableCompositeTestWrapper()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableCompositeWrapper>());
 }
 public void BlittableDecimalTestWrapper()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableDecimalWrapper>());
 }
 public void BlittableDecimalTest()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableDecimal>());
 }
 public void BooleanTest()
 {
     Assert.False(BlittableHelper.IsBlittable <bool>());
 }
 public void BlittableBooleanWrapperTest()
 {
     Assert.True(BlittableHelper.IsBlittable <BlittableBooleanWrapper>());
 }
 public void CharTest()
 {
     Assert.False(BlittableHelper.IsBlittable <char>());
 }
Beispiel #18
0
        public AnimationClipEvaluator CreateEvaluator(AnimationClip clip)
        {
            // Check if this clip has already been used
            if (clips.Add(clip) || clip.ShouldRescanChannels)
            {
                // If new clip, let's scan its channel to add new ones.
                foreach (var curve in clip.Channels)
                {
                    Channel channel;
                    if (channelsByName.TryGetValue(curve.Key, out channel))
                    {
                        // TODO: Check if channel matches
                    }
                    else
                    {
                        // New channel, add it to every evaluator

                        // Find blend type
                        BlendType blendType;
                        var       elementType = curve.Value.ElementType;

                        if (elementType == typeof(Quaternion))
                        {
                            blendType = BlendType.Quaternion;
                        }
                        else if (elementType == typeof(float))
                        {
                            blendType = BlendType.Float1;
                        }
                        else if (elementType == typeof(Vector2))
                        {
                            blendType = BlendType.Float2;
                        }
                        else if (elementType == typeof(Vector3))
                        {
                            blendType = BlendType.Float3;
                        }
                        else if (elementType == typeof(Vector4))
                        {
                            blendType = BlendType.Float4;
                        }
                        else
                        {
                            blendType = BlittableHelper.IsBlittable(elementType) ? BlendType.Blit : BlendType.Object;
                        }

                        // Create channel structure
                        channel.BlendType            = blendType;
                        channel.Offset               = blendType == BlendType.Object ? objectsSize : structureSize;
                        channel.PropertyName         = curve.Key;
                        channel.Size                 = curve.Value.ElementSize;
                        channel.IsUserCustomProperty = curve.Value.IsUserCustomProperty;

                        // Add channel
                        channelsByName.Add(channel.PropertyName, channel);
                        channels.Add(channel);

                        if (blendType == BlendType.Object)
                        {
                            objectsSize++;
                        }
                        else
                        {
                            // Update new structure size
                            // We also reserve space for a float that will specify channel existence and factor in case of subtree blending
                            structureSize += sizeof(float) + channel.Size;
                        }

                        // Add new channel update info to every evaluator
                        // TODO: Maybe it's better lazily done? (avoid need to store list of all evaluators)
                        foreach (var currentEvaluator in evaluators)
                        {
                            currentEvaluator.AddChannel(ref channel);
                        }
                    }
                }
            }

            // Update results to fit the new data size
            lock (availableResultsPool)
            {
                foreach (var result in availableResultsPool)
                {
                    if (result.DataSize < structureSize)
                    {
                        result.DataSize = structureSize;
                        result.Data     = new byte[structureSize];
                    }
                }
            }

            // Create evaluator and store it in list of instantiated evaluators
            AnimationClipEvaluator evaluator;

            lock (evaluatorPool)
            {
                if (evaluatorPool.Count > 0)
                {
                    evaluator = evaluatorPool.Pop();
                }
                else
                {
                    evaluator = new AnimationClipEvaluator();
                }
            }

            evaluator.Initialize(clip, channels);
            evaluators.Add(evaluator);

            return(evaluator);
        }
Beispiel #19
0
 /// <summary>
 /// Check if an array is of primtive types, these can be skipped in most processors
 /// </summary>
 /// <param name="descriptor"></param>
 /// <returns></returns>
 protected bool IsArrayOfPrimitiveType(ArrayDescriptor descriptor)
 => BlittableHelper.IsBlittable(descriptor.ElementType);