Beispiel #1
0
        public static BlockExpression RotateLerp(Ex target, Ex source, TExArgCtx bpi, bool isRate, bool isTrue, Ex rate)
        {
            if (isRate)
            {
                rate = rate.Mul(M.degRad);
            }
            if (isTrue)
            {
                rate = rate.Mul(ETime.FRAME_TIME);
            }
            TExV2       v   = TExV2.Variable();
            TEx <float> ang = ExUtils.VFloat();

            Expression[] exprs = new Expression[3];
            exprs[1] = ang.Is(RadDiff(target, v));
            if (isTrue)
            {
                var key = bpi.Ctx.NameWithSuffix("_RotateLerpKey");
                exprs[0] = v.Is(
                    Ex.Condition(FiringCtx.Contains <Vector2>(bpi, key),
                                 FiringCtx.GetValue <Vector2>(bpi, key),
                                 FiringCtx.SetValue <Vector2>(bpi, key, source)
                                 ));
                exprs[2] =
                    FiringCtx.SetValue <Vector2>(bpi, key, RotateRad(isRate ? (Ex)Limit(rate, ang) : ang.Mul(rate), v));
            }
            else
            {
                exprs[0] = v.Is(source);
                exprs[2] = RotateRad(isRate ?
                                     (Ex)Limit(bpi.t.Mul(rate), ang) :
                                     ang.Mul(Min(bpi.t.Mul(rate), E1)), v);
            }
            return(Ex.Block(new ParameterExpression[] { v, ang }, exprs));
        }
Beispiel #2
0
        public static BlockExpression LaserRotateLerp(Ex target, Ex source, TExArgCtx bpi, Ex rate)
        {
            var         r1        = rate.Mul(ExC(ETime.FRAME_TIME));
            TExV2       v         = TExV2.Variable();
            TEx <float> ang       = ExUtils.VFloat();
            var         dirKey    = bpi.Ctx.NameWithSuffix("_LaserRotateLerpDirKey");
            var         sideKey   = bpi.Ctx.NameWithSuffix("_LaserRotateLerpSideKey");
            var         inter_ang = HighPass(ExC(0.01f), RadDiff(target, v));

            return(Ex.Block(new ParameterExpression[] { v, ang },
                            Ex.Condition(
                                bpi.FCtxHas <Vector2>(dirKey).And(bpi.t.GT0()),
                                Ex.Block(
                                    v.Is(bpi.FCtxGet <Vector2>(dirKey)),
                                    ang.Is(Ex.Condition(bpi.FCtxGet <float>(sideKey).LT0(),
                                                        RadToNeg(inter_ang),
                                                        RadToPos(inter_ang)
                                                        )),
                                    bpi.FCtxSet <Vector2>(dirKey, RotateRad(Limit(r1, ang), v))
                                    ),
                                Ex.Block(
                                    v.Is(source),
                                    ang.Is(RadDiff(target, v)),
                                    bpi.FCtxSet <float>(sideKey, Sign(ang)),
                                    bpi.FCtxSet <Vector2>(dirKey, RotateRad(Limit(r1, ang), v))
                                    )
                                )
                            ));
        }
Beispiel #3
0
 public static Ex DictContains(Ex dict, Ex key)
 {
     if (!containsKeyMIMap.TryGetValue(dict.Type, out ExFunction method))
     {
         containsKeyMIMap[dict.Type] = method =
             ExUtils.Wrap(dict.Type, "ContainsKey", key.Type);
     }
     return(method.InstanceOf(dict, key));
 }
Beispiel #4
0
        public static Ex DictSafeGet(this Ex dict, Ex key, string err)
        {
            return(Ex.Block(
                       Ex.IfThen(Ex.Not(ExUtils.DictContains(dict, key)), Ex.Throw(Ex.Constant(new Exception(err)))),
                       dict.DictGet(key)
                       ));

            /*
             * return Ex.Condition(ExUtils.DictContains<K, V>(dict, key), dict.DictGet(key), Ex.Block(
             *  Ex.Throw(Ex.Constant(new Exception(err))),
             *  dict.DictGet(key)
             * ));*/
        }
Beispiel #5
0
        public static Func <T, TEx <R> > EaseD <T, R>(Func <tfloat, tfloat> easer, float maxTime,
                                                      Func <T, TEx <R> > fd, Func <T, Ex> t, Func <T, Ex, T> withT)
        {
            var ratTime = ExUtils.VFloat();

            // x'(t) = f'(g(t)) g'(t). Where g(t) = T e(t/T): g'(t) = e'(t/T)
            return(bpi => Ex.Block(new[] { ratTime },
                                   Ex.Assign(ratTime, Clamp01(ExC(1f / maxTime).Mul(t(bpi)))),
                                   Ex.Multiply(
                                       DerivativeVisitor.Derivate(ratTime, E1, easer(ratTime)),
                                       fd(withT(bpi, ExC(maxTime).Mul(easer(ratTime)))))
                                   ));
        }