public override void InterpolateBetweenAndExecute(GenericInstruction otherInstruction, float thisRatio)
        {
            IInterpolator <ValueType> interpolator = InstructionManager.GetInterpolator(mValue.GetType(), mMember) as
                                                     IInterpolator <ValueType>;

            ValueType interpolatedValue = interpolator.Interpolate(mValue,
                                                                   ((ValueType)otherInstruction.MemberValueAsObject),
                                                                   thisRatio);

            LateBinder <TargetType> .Instance.SetProperty <ValueType>(mTarget, mMember, interpolatedValue);
        }
Esempio n. 2
0
        public GenericInstruction ToInstruction(object target)
        {
            // Get the type of the property.  It could be null so can't do Value.GetType()
            Type typeOfTarget = target.GetType();

            MemberInfo[] memberInfos = typeOfTarget.GetMember(Member);

            Type typeOfMember = null;

            FieldInfo fieldInfo = typeOfTarget.GetField(Member);

            if (fieldInfo != null)
            {
                typeOfMember = fieldInfo.FieldType;
            }
            if (typeOfMember == null)
            {
                PropertyInfo propertyInfo = typeOfTarget.GetProperty(Member);

                typeOfMember = propertyInfo.PropertyType;
            }

            Type t = typeof(Instruction <, >).MakeGenericType(
                target.GetType(),
                typeOfMember);

#if WINDOWS_8 || UWP
            ConstructorInfo ctor = t.GetConstructor(
                new Type[] { target.GetType(), typeof(string), typeOfMember, typeof(double) });
#else
            ConstructorInfo ctor = t.GetConstructor(
                BindingFlags.Instance | BindingFlags.Public,
                null,
                new Type[] { target.GetType(), typeof(string), typeOfMember, typeof(double) },
                null);
#endif

            GenericInstruction instruction = (GenericInstruction)ctor.Invoke(
                new Object[]                 {
                target,
                Member,
                Value,
                Time
            }
                );

            return(instruction);
        }
Esempio n. 3
0
        public Instruction After(double time)
        {
            Instruction toReturn;

            if (mSetOrCall == SetOrCall.Set)
            {
                Type memberType      = GetMemberType(MemberToSet);
                Type instructionType = typeof(Instruction <,>).MakeGenericType(typeof(T), memberType);

                GenericInstruction instruction = (GenericInstruction)Activator.CreateInstance(instructionType);

                instruction.TimeToExecute = TimeManager.CurrentTime + time;
                instruction.SetTarget(Caller);
                instruction.Member = MemberToSet;
                instruction.MemberValueAsObject = ValueToSet;
                toReturn = instruction;
            }
            else if (ActionT != null)
            {
                DelegateInstruction <T> delegateInstruction = new DelegateInstruction <T>(ActionT, Caller);
                delegateInstruction.TimeToExecute = TimeManager.CurrentTime + time;

                toReturn = delegateInstruction;
            }
            else
            {
                DelegateInstruction delegateInstruction = new DelegateInstruction(Action);
                delegateInstruction.TimeToExecute = TimeManager.CurrentTime + time;

                toReturn = delegateInstruction;
            }


            Caller.Instructions.Add(toReturn);

            return(toReturn);
        }
 public abstract void InterpolateBetweenAndExecute(GenericInstruction otherInstruction, float thisRatio);
Esempio n. 5
0
        public InstructionList CreateVelocityListAtIndex(int keyframeIndex)
        {
            if (keyframeIndex > Count - 1)
            {
                // The user passed either the last instruction index or an out-of-bounds index,
                // so return an empty list.
                return(new InstructionList(0));
            }

            else
            {
                #region Get keyframeAtIndex and keyframeAfter

                InstructionList keyframeAtIndex = this[keyframeIndex];

                InstructionList keyframeAfter = null;

                double timeBetween;

                if (keyframeIndex == Count - 1)
                {
                    // If it's the last keyframe, use the same keyframe to stop all velocity
                    keyframeAfter = keyframeAtIndex;
                    timeBetween   = 1; // To prevent NaN values
                }
                else
                {
                    keyframeAfter = this[keyframeIndex + 1];
                    timeBetween   = keyframeAfter[0].TimeToExecute - keyframeAtIndex[0].TimeToExecute;
                }
                #endregion

                InstructionList instructionList = new InstructionList();

                #region Loop through all instructions and create interpolation instructions

                for (int i = 0; i < keyframeAtIndex.Count; i++)
                {
                    Instruction        instructionAtIndex          = keyframeAtIndex[i];
                    GenericInstruction instructionAtIndexAsGeneric = instructionAtIndex as GenericInstruction;

                    Type typeOfTarget = instructionAtIndexAsGeneric.Target.GetType();

                    bool shouldInterpolate =
                        instructionAtIndexAsGeneric.MemberValueAsObject != null &&

                        instructionAtIndexAsGeneric != null &&
                        InstructionManager.HasInterpolatorForType(
                            instructionAtIndexAsGeneric.MemberValueAsObject.GetType());

                    string velocityMemberName = InstructionManager.GetVelocityForState(
                        instructionAtIndexAsGeneric.Member);

                    if (shouldInterpolate && !string.IsNullOrEmpty(velocityMemberName))
                    {
                        Type typeOfValue = instructionAtIndexAsGeneric.MemberValueAsObject.GetType();
                        //bool hasInterpolated = false;

                        GenericInstruction instructionAfterAsGeneric = keyframeAfter[i] as GenericInstruction;

                        if (instructionAfterAsGeneric != null &&
                            instructionAtIndexAsGeneric.Target == instructionAfterAsGeneric.Target &&
                            instructionAtIndexAsGeneric.Member == instructionAfterAsGeneric.Member)
                        {
                            // We've found the instruction!  Create a velocity instruction
                            Instruction instruction = CreateInstructionFor(
                                instructionAtIndexAsGeneric.Target,
                                velocityMemberName,
                                instructionAtIndexAsGeneric.MemberValueAsObject,
                                instructionAfterAsGeneric.MemberValueAsObject,
                                timeBetween,
                                instructionAtIndexAsGeneric.TimeToExecute,
                                typeOfTarget,
                                typeOfValue);

                            instruction.TimeToExecute = instructionAtIndex.TimeToExecute;

                            instructionList.Add(instruction);
                        }
                    }
                    // switch on the Type, but can't use a Switch statement
                }
                #endregion

                return(instructionList);
            }
        }
Esempio n. 6
0
        public void SetState(double time, bool setVelocity)
        {
            InstructionList keyframeBefore = KeyframeAtOrBefore(time);
            InstructionList keyframeAfter  = KeyframeAtOrAfter(time);

            if (keyframeBefore == null && keyframeAfter == null)
            {
                return;
            }

            else if (keyframeBefore == keyframeAfter)
            {
                keyframeBefore.Execute();
            }
            else if (keyframeBefore != null && keyframeAfter == null)
            {
                keyframeBefore.Execute();
            }
            else if (keyframeAfter != null && keyframeBefore == null)
            {
                keyframeAfter.Execute();
            }
            else // the two keyframes are not the same, and neither are null
            {
                double timeAfter  = keyframeAfter[0].TimeToExecute;
                double timeBefore = keyframeBefore[0].TimeToExecute;

                double range = timeAfter - timeBefore;

                double ratioAfter  = (time - timeBefore) / range;
                double ratioBefore = 1 - ratioAfter;

                for (int i = 0; i < keyframeBefore.Count; i++)
                {
                    Instruction instructionBefore = keyframeBefore[i];

                    GenericInstruction instructionBeforeAsGeneric = instructionBefore as GenericInstruction;

                    object memberValueAsObject = instructionBeforeAsGeneric.MemberValueAsObject;
                    // DO MORE HERE

                    bool shouldInterpolate =
                        instructionBeforeAsGeneric.MemberValueAsObject != null &&
                        instructionBeforeAsGeneric != null &&
                        InstructionManager.HasInterpolatorForType(
                            instructionBeforeAsGeneric.MemberValueAsObject.GetType());

                    if (shouldInterpolate)
                    {
                        bool hasInterpolated = false;

                        GenericInstruction instructionAfterAsGeneric =
                            keyframeAfter[i] as GenericInstruction;

                        if (instructionAfterAsGeneric != null &&
                            instructionBeforeAsGeneric.Target == instructionAfterAsGeneric.Target &&
                            instructionBeforeAsGeneric.Member == instructionAfterAsGeneric.Member)
                        {
                            // We've found the instruction!  Interpolate!
                            instructionBeforeAsGeneric.InterpolateBetweenAndExecute(instructionAfterAsGeneric, (float)ratioBefore);

                            hasInterpolated = true;
                        }

                        if (hasInterpolated == false)
                        {
                            // for now, fail.  Eventually will want to search the entire KeyframeAfter to see if it
                            // contains a matching instruction for interpolation
                            throw new NotImplementedException("The keyframes instructions do not match up.  Cannot interpolate.");
                        }
                    }
                    else
                    {
                        keyframeBefore[i].Execute();
                    }
                }
            }
        }