Beispiel #1
0
        private static void ReadXMLBezierPositions(XmlReader reader, EffectStateRatioSet set)
        {
            var bcps = new List <BezierControlPoint>(2);

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Name == "BezierPosition")
                    {
                        try
                        {
                            var pos = reader.GetAttribute("Position");
                            var bcp = BezierControlPoint.Deserialize(pos);
                            bcps.Add(bcp);
                        }
                        catch
                        {
                        }
                    }
                }
            }
            if (bcps.Count >= 2)
            {
                set.BAnalyzer = new BezierAnalyzer(bcps.ToArray());
            }
            reader.Close();
        }
Beispiel #2
0
        private static BaseEffect ReadXMLEffect(XmlReader reader, ReadResourceCallBack callback, string dir)
        {
            var effect = new BaseEffect();
            EffectStateStructure lastess = null;
            var set = new EffectStateRatioSet();

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.Name)
                    {
                    case "Effect":
                        effect.Filename = Path.Combine(dir, reader.GetAttribute("FilePath"));
                        callback(effect.Filename);
                        break;

                    case "State":
                        var       ess = new EffectStateStructure();
                        BlendMode blendMode;
                        if (!Enum.TryParse <BlendMode>(reader.GetAttribute("Blend"), out blendMode))
                        {
                            blendMode = BlendMode.None;
                        }
                        ess.BlendMode = blendMode;
                        ess.X         = float.Parse(reader.GetAttribute("X"), CultureInfo.InvariantCulture);
                        ess.Y         = float.Parse(reader.GetAttribute("Y"), CultureInfo.InvariantCulture);
                        ess.Alpha     = float.Parse(reader.GetAttribute("Alpha"), CultureInfo.InvariantCulture);
                        ess.Rotation  = float.Parse(reader.GetAttribute("Rotation"), CultureInfo.InvariantCulture);
                        ess.ScaleX    = float.Parse(reader.GetAttribute("ScaleX"), CultureInfo.InvariantCulture);
                        ess.ScaleY    = float.Parse(reader.GetAttribute("ScaleY"), CultureInfo.InvariantCulture);
                        if (lastess != null)
                        {
                            set.StartState = lastess;
                            set.EndState   = ess;
                            effect.Sets.Add(set.StartFrame, set);
                            set = new EffectStateRatioSet();
                        }
                        lastess = ess;
                        break;

                    case "RatioMakers":
                        set.StartFrame = int.Parse(reader.GetAttribute("StartFrame"), CultureInfo.InvariantCulture);
                        set.EndFrame   = int.Parse(reader.GetAttribute("EndFrame"), CultureInfo.InvariantCulture);
                        ReadXMLRatioMakers(reader.ReadSubtree(), set);
                        break;

                    case "BezierPositions":
                        ReadXMLBezierPositions(reader.ReadSubtree(), set);
                        break;
                    }
                }
            }
            effect.CheckFrameLength();
            reader.Close();
            return(effect);
        }
Beispiel #3
0
        /// <summary>
        /// 長さ1の線形状態にする
        /// </summary>
        public void SetDefault()
        {
            var set = new EffectStateRatioSet
            {
                StartState = new EffectStateStructure(),
                EndState   = new EffectStateStructure(),
                StartFrame = 0,
                EndFrame   = 1
            };

            set.SetDefaultMaker();
            FrameLength = 1;
            Sets.Add(0, set);
        }
Beispiel #4
0
        /// <summary>
        /// コンストラクタ
        /// </summary>
        public EffectManager()
        {
            stopwatch = new Stopwatch();
            FPS       = 60;
            Effects   = new List <IEffect>();
            Sets      = new SortedList <int, EffectStateRatioSet>();
            var set = new EffectStateRatioSet
            {
                StartState = new EffectStateStructure(),
                EndState   = new EffectStateStructure(),
                StartFrame = 0,
                EndFrame   = 1
            };

            set.SetDefaultMaker();
            Sets.Add(0, set);
        }
Beispiel #5
0
        private void InnerUpdate()
        {
            EffectStateRatioSet set = Sets.Values[BinaryFinder.FindNearest(Sets.Keys, ref currentFrame)];

            CurrentState = set.StartState.GetMixedState(set.GetRatios(CurrentFrame), set.EndState);
            Parallel.ForEach(Effects, new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, effect =>
            {
                if (effect.Effects.Count == 0)
                {
                    effect.Update(currentFrame, CurrentState);
                }
                else
                {
                    effect.Update(currentFrame * effect.FPS / FPS, CurrentState);
                }
            });
        }
Beispiel #6
0
        private bool InnerUpdate(float parentframe, EffectStateStructure parentState)
        {
            currentframe = parentframe - StartFrame;
            if (currentframe > FrameLength || currentframe < 0)
            {
                return(false);
            }
            EffectStateRatioSet set = Sets.Values[BinaryFinder.FindNearest(Sets.Keys, ref parentframe)];

            CurrentState = set.StartState.GetMixedState(set.GetRatios(parentframe), set.EndState);
            if (set.IsBezierPosition)
            {
                var bratio = set.GetRatio(RatioType.BezierPosition, parentframe);
                set.BAnalyzer.GetPoint(BezierCaliculator.BezierAnalyzer.MaxRatio * (1 - bratio), out PointF outp, out PointF outdir);
                CurrentState.X = outp.X;
                CurrentState.Y = outp.Y;
            }
            CurrentState.Compose(parentState);
            return(true);
        }
Beispiel #7
0
        /// <summary>
        /// クローンメソッド
        /// </summary>
        /// <returns></returns>
        public object CloneExceptState()
        {
            var ret = new EffectStateRatioSet
            {
                StartFrame = StartFrame,
                EndFrame   = EndFrame
            };

            if (BAnalyzer != null)
            {
                ret.BAnalyzer = (BezierAnalyzer)BAnalyzer.Clone();
            }
            ret.StartState = StartState;
            ret.EndState   = EndState;
            //ret.StartState = (EffectStateStructure)StartState.Clone();
            //ret.EndState = (EffectStateStructure)EndState.Clone();
            for (int i = 0; i < RatioMakers.Length; i++)
            {
                ret.RatioMakers[i]     = (IRatioMaker)RatioMakers[i].Clone();
                ret.RatioMakers[i].Set = ret;
            }
            return(ret);
        }
Beispiel #8
0
        private static void ReadXMLRatioMakers(XmlReader reader, EffectStateRatioSet set)
        {
            while (reader.Read())
            {
                if (reader.Name == "RatioMaker")
                {
                    RatioType type = RatioType.X;
                    switch (reader.GetAttribute("Type"))
                    {
                    case "X":
                        type = RatioType.X;
                        break;

                    case "Y":
                        type = RatioType.Y;
                        break;

                    case "Alpha":
                        type = RatioType.Alpha;
                        break;

                    case "Rotation":
                        type = RatioType.Rotation;
                        break;

                    case "ScaleX":
                        type = RatioType.ScaleX;
                        break;

                    case "ScaleY":
                        type = RatioType.ScaleY;
                        break;

                    case "BezierPosition":
                        type = RatioType.BezierPosition;
                        break;
                    }
                    IRatioMaker maker = null;
                    switch (reader.GetAttribute("MakerType"))
                    {
                    case "LinearRatioMaker":
                        maker = new LinearRatioMaker();
                        break;

                    case "ConstantRatioMaker":
                        maker = new ConstantRatioMaker();
                        break;

                    case "BezierRatioMaker":
                        var p1 = BezierControlPoint.Deserialize(reader.GetAttribute("P1"));
                        var p2 = BezierControlPoint.Deserialize(reader.GetAttribute("P2"));
                        maker = new BezierRatioMaker(p1, p2);
                        break;
                    }
                    maker.Set = set;
                    set[type] = maker;
                }
            }
            reader.Close();
            set.SetDefaultToNullMaker();
        }