Пример #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));
        }
Пример #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))
                                    )
                                )
                            ));
        }
Пример #3
0
        public static Ex Let2(Alias[] aliases, Func <Ex> inner, TExArgCtx applier)
        {
            var stmts = new Ex[aliases.Length + 1];
            var vars  = new ParameterExpression[aliases.Length];
            var lets  = new List <IDisposable>();

            for (int ii = 0; ii < aliases.Length; ++ii)
            {
                Ex alias_value = aliases[ii].func(applier);
                lets.Add(applier.Let(aliases[ii].alias, vars[ii] =
                                         V(alias_value.Type, applier.Ctx.NameWithSuffix(aliases[ii].alias))));
                stmts[ii] = Ex.Assign(vars[ii], alias_value);
            }
            stmts[aliases.Length] = inner();
            for (int ii = 0; ii < lets.Count; ++ii)
            {
                lets[ii].Dispose();
            }
            return(Ex.Block(vars, stmts));
        }
Пример #4
0
        public static TEx <T> Let <T, L>(string alias, Func <TExArgCtx, TEx <L> > content, Func <TEx <T> > inner, TExArgCtx applier)
        {
            var variabl = V <L>();

            using var let = applier.Let(alias, variabl);
            return(Ex.Block(new[] { variabl },
                            Ex.Assign(variabl, content(applier)),
                            inner()
                            ));
        }
Пример #5
0
 public LocalLet(TExArgCtx ctx, string alias, Expression val)
 {
     this.alias = alias;
     (this.ctx = ctx).Ctx.AliasStack.Push(alias, val);
 }