예제 #1
0
    public CompT CompHermano <CompT> (bool siNecesarioActivo = false) where CompT : MonoBehaviour, IComp
    {
        IComp tcomp = null;

        if (transform.parent != null)
        {
            IComp [] tCompsPadre = transform.parent.GetComponents <IComp> ();
            if (tCompsPadre != null)
            {
                foreach (IComp tCompPadre in tCompsPadre)
                {
                    /*if ( tCompPadre.GetType () == typeof ( CompT ) ) {
                     *  return ( CompT ) tCompPadre;
                     * } */
                    tcomp = tCompPadre.CompHijo <CompT> (siNecesarioActivo);
                    if (tcomp == null)
                    {
                        tcomp = tCompPadre.CompHermano <CompT> (siNecesarioActivo);
                    }
                    if (tcomp != null)
                    {
                        return((CompT)tcomp);
                    }
                }
            }
        }
        return(( CompT )tcomp);
    }
예제 #2
0
 public override void OnVibrate(IComp Comp, string Contact, object Val)
 {
     if (Contacts[Contact] == Comp)
     {
         Values[Contact] = Val;
     }
 }
예제 #3
0
파일: C1Way.cs 프로젝트: ManhQLe/Cir8NET
 public override void DisconnectWith(IComp Comp, string Contact)
 {
     if (Contacts.ContainsKey(Contact))
     {
         Contacts.Remove(Contact);
         Comp.DisconnectWith(this, Contact);
     }
 }
예제 #4
0
        public static Entity Replace <TComponent, TValue>(this Entity entity, IComp <TComponent, SingleValueComponent <TValue> .Editor> compData, TValue value)
            where TComponent : SingleValueComponent <TValue>, new()
        {
            TComponent comp = entity.CreateComponent <TComponent>(compData.EntitasData.Id);

            compData.Editor.SetActionReplace(entity, compData.EntitasData.Id, comp);
            return(compData.Editor.Apply(value));
        }
예제 #5
0
파일: Cir8.cs 프로젝트: ManhQLe/Cir8NET
        public static CConduit Connect(IComp A, IComp B, string Contact)
        {
            var C = new CConduit();

            C.Connect(A, Contact);
            C.Connect(B, Contact);
            return(C);
        }
예제 #6
0
파일: Cir8.cs 프로젝트: ManhQLe/Cir8NET
        public static CConduit Link(IComp Comp1, String C1, String C2, IComp Comp2)
        {
            var Con = new CConduit();

            Con.Connect(Comp1, C1);
            Con.Connect(Comp2, C2);
            return(Con);
        }
예제 #7
0
        public static TEditor Replace <TComponent, TEditor>(this Entity entity, IComp <TComponent, TEditor> compData)
            where TComponent : IComponent, new()
            where TEditor : IComponentEditor <TComponent>
        {
            TComponent comp = entity.CreateComponent <TComponent>(compData.EntitasData.Id);

            compData.Editor.SetActionReplace(entity, compData.EntitasData.Id, comp);
            return(compData.Editor);
        }
예제 #8
0
        public override void DisconnectWith(IComp Comp, string Contact)
        {
            IComp C = Ports.Contacts[Contact];

            if (C != null)
            {
                IComp V;
                Ports.Contacts.TryRemove(Contact, out V);
                Comp.DisconnectWith(this, Contact);
            }
        }
예제 #9
0
파일: C1Way.cs 프로젝트: ManhQLe/Cir8NET
 public override void OnVibrate(IComp Comp, string Contact, object Val)
 {
     if (Contact == "IN" && Contacts["IN"] == Comp)
     {
         var C = Contacts["OUT"];
         if (C != null)
         {
             C.OnVibrate(this, Contact, Val);
         }
     }
 }
예제 #10
0
        public override void DisconnectWith(IComp Comp, string Contact)
        {
            var idx = Contacts.FindIndex((pair) =>
            {
                return(pair.Key == Contact && pair.Value == Comp);
            });

            if (idx >= 0)
            {
                Contacts.RemoveAt(idx);
            }
        }
예제 #11
0
 private static Operand GetIntComparison(
     EmitterContext context,
     IComp cond,
     Operand srcA,
     Operand srcB,
     bool isSigned,
     bool extended)
 {
     return(extended
         ? GetIntComparisonExtended(context, cond, srcA, srcB, isSigned)
         : GetIntComparison(context, cond, srcA, srcB, isSigned));
 }
예제 #12
0
        public override void Connect(IComp Comp, string Contact)
        {
            var idx = Contacts.FindIndex((pair) =>
            {
                return(pair.Key == Contact && pair.Value == Comp);
            });

            if (idx < 0)
            {
                Contacts.Add(new KeyValuePair <string, IComp>(Contact, Comp));
                Comp.Connect(this, Contact);
            }
        }
예제 #13
0
        private static void EmitIcmp(
            EmitterContext context,
            IComp cmpOp,
            Operand srcA,
            Operand srcB,
            Operand srcC,
            int rd,
            bool isSigned)
        {
            Operand cmpRes = GetIntComparison(context, cmpOp, srcC, Const(0), isSigned);

            Operand res = context.ConditionalSelect(cmpRes, srcA, srcB);

            context.Copy(GetDest(rd), res);
        }
예제 #14
0
 void AsignarCompHijos()
 {
     componentes = new List <IComp> ();
     for (int cmp = 0; cmp < transform.childCount; cmp++)
     {
         IComp comp = transform.GetChild(cmp).GetComponent <IComp> ();
         if (comp != null)
         {
             componentes.Add(comp);
             if (cmp > 0)
             {
                 comp.CompEntrada = componentes [cmp - 1];
             }
         }
     }
 }
예제 #15
0
        public override void Connect(IComp Comp, string Contact)
        {
            var C = Contacts[Contact];

            if (C != null)
            {
                if (C != Comp)
                {
                    C.Connect(Comp, Contact);
                }
            }
            else
            {
                Contacts[Contact] = Comp;
            }
        }
예제 #16
0
 public override void OnVibrate(IComp Comp, string Contact, object Val)
 {
     foreach (var pair in Contacts)
     {
         if (pair.Value != Comp && pair.Key != Contact)
         {
             if (ParallelTrx)
             {
                 new Thread(() => AsyncVirbrate(this, pair, Val)).Start();
             }
             else
             {
                 pair.Value.OnVibrate(this, pair.Key, Val);
             }
         }
     }
 }
예제 #17
0
        private static Operand GetIntComparison(EmitterContext context, IComp cond, Operand srcA, Operand srcB, bool isSigned)
        {
            Operand res;

            if (cond == IComp.T)
            {
                res = Const(IrConsts.True);
            }
            else if (cond == IComp.F)
            {
                res = Const(IrConsts.False);
            }
            else
            {
                var inst = cond switch
                {
                    IComp.Lt => Instruction.CompareLessU32,
                    IComp.Eq => Instruction.CompareEqual,
                    IComp.Le => Instruction.CompareLessOrEqualU32,
                    IComp.Gt => Instruction.CompareGreaterU32,
                    IComp.Ne => Instruction.CompareNotEqual,
                    IComp.Ge => Instruction.CompareGreaterOrEqualU32,
                    _ => throw new InvalidOperationException($"Unexpected condition \"{cond}\".")
                };

                if (isSigned)
                {
                    switch (cond)
                    {
                    case IComp.Lt: inst = Instruction.CompareLess; break;

                    case IComp.Le: inst = Instruction.CompareLessOrEqual; break;

                    case IComp.Gt: inst = Instruction.CompareGreater; break;

                    case IComp.Ge: inst = Instruction.CompareGreaterOrEqual; break;
                    }
                }

                res = context.Add(inst, Local(), srcA, srcB);
            }

            return(res);
        }
    }
예제 #18
0
        public override void OnVibrate(IComp Comp, string Contact, object Val)
        {
            var C = Contacts[Contact];

            if (C == Comp)
            {
                Sem.WaitOne();
                Collections.Add(Val);
                if (Collections.Count == MAX)
                {
                    var Col = Collections;
                    foreach (var c in Contacts.Keys)
                    {
                        Contacts[c].OnVibrate(this, c, Col);
                    }
                }
                Sem.Release();
            }
        }
예제 #19
0
파일: C1Way.cs 프로젝트: ManhQLe/Cir8NET
        public override void Connect(IComp Comp, string Contact)
        {
            if (Contact != "IN" && Contact != "OUT")
            {
                throw new Exception("Only contacts available are IN and OUT");
            }
            var C = Contacts[Contact];

            if (C != null)
            {
                if (C != Comp)
                {
                    C.Connect(Comp, Contact);
                }
            }
            else
            {
                Contacts[Contact] = Comp;
            }
        }
예제 #20
0
        public override void OnVibrate(IComp Comp, string Contact, object Val)
        {
            if (Ins == null || Ins.Length == 0)
            {
                this.FX(this);
            }

            var IsInput = Ins.Contains(Contact);

            if (IsInput)
            {
                bool Already = false;
                if (Stage)
                {
                    Sem.WaitOne();
                    Already            = _HasInput.ContainsKey(Contact);
                    _HasInput[Contact] = true;

                    Ports.Values[Contact] = Val;
                    if (!Already && ++ICount == Ins.Length)
                    {
                        this.FX(this, Contact);
                        _HasInput.Clear();
                        ICount = 0;
                    }
                    Sem.Release();
                }
                else
                {
                    Already               = _HasInput.ContainsKey(Contact);
                    _HasInput[Contact]    = true;
                    Ports.Values[Contact] = Val;
                    if (!Already && ++ICount >= Ins.Length ||
                        ICount >= Ins.Length
                        )
                    {
                        this.FX(this, Contact);
                    }
                }
            }
        }
예제 #21
0
        public override void Connect(IComp Comp, string Contact)
        {
            if (++Initialized == 1)
            {
                this.InitFX(this);
            }

            if (Ports.Contacts.ContainsKey(Contact))
            {
                var EComp = Ports.Contacts[Contact];
                if (EComp != Comp)
                {
                    EComp.Connect(Comp, Contact);
                }
            }
            else
            {
                Ports.Contacts[Contact] = Comp;
                Comp.Connect(this, Contact);
            }
        }
예제 #22
0
        private static void EmitIsetp(
            EmitterContext context,
            IComp cmpOp,
            BoolOp logicOp,
            Operand srcA,
            Operand srcB,
            int srcPred,
            bool srcPredInv,
            int destPred,
            int destPredInv,
            bool isSigned,
            bool extended)
        {
            Operand p0Res = GetIntComparison(context, cmpOp, srcA, srcB, isSigned, extended);
            Operand p1Res = context.BitwiseNot(p0Res);
            Operand pred  = GetPredicate(context, srcPred, srcPredInv);

            p0Res = GetPredLogicalOp(context, logicOp, p0Res, pred);
            p1Res = GetPredLogicalOp(context, logicOp, p1Res, pred);

            context.Copy(Register(destPred, RegisterType.Predicate), p0Res);
            context.Copy(Register(destPredInv, RegisterType.Predicate), p1Res);
        }
예제 #23
0
            internal EntitasDataSummary(Type containingType)
            {
                FieldInfo[] fields = containingType.GetFields();
                ComponentNames = new string[fields.Length];
                ComponentTypes = new Type[fields.Length];
                IList <IComp> comps = new List <IComp>();

                foreach (FieldInfo field in fields)
                {
                    IComp comp = (IComp)field.GetValue(null);  // force jit call constructor on each component
                    comps.Add(comp);
                }
                for (int i = 0; i < fields.Length; ++i)
                {
                    EntitasData data = comps[i].EntitasData;
                    data.Id           = i;
                    ComponentNames[i] = data.name;
                    ComponentTypes[i] = data.type;
                    var matcher = (Matcher)Matcher.AllOf(i);
                    matcher.componentNames = ComponentNames;
                    data.Match             = matcher;
                }
            }
예제 #24
0
        private static void EmitIset(
            EmitterContext context,
            IComp cmpOp,
            BoolOp logicOp,
            Operand srcA,
            Operand srcB,
            int srcPred,
            bool srcPredInv,
            int rd,
            bool boolFloat,
            bool isSigned,
            bool extended,
            bool writeCC)
        {
            Operand res  = GetIntComparison(context, cmpOp, srcA, srcB, isSigned, extended);
            Operand pred = GetPredicate(context, srcPred, srcPredInv);

            res = GetPredLogicalOp(context, logicOp, res, pred);

            Operand dest = GetDest(rd);

            if (boolFloat)
            {
                res = context.ConditionalSelect(res, ConstF(1), Const(0));

                context.Copy(dest, res);

                SetFPZnFlags(context, res, writeCC);
            }
            else
            {
                context.Copy(dest, res);

                SetZnFlags(context, res, writeCC, extended);
            }
        }
예제 #25
0
 public override void DisconnectWith(IComp Comp, string Contact)
 {
 }
예제 #26
0
 public override void Connect(IComp Comp, string Contact)
 {
 }
예제 #27
0
 public static void AsyncVirbrate(IComp From, KeyValuePair <String, IComp> Pair, Object Val)
 {
     Pair.Value.OnVibrate(From, Pair.Key, Val);
 }
예제 #28
0
 public static bool Has(this Entity entity, IComp compData)
 {
     return(entity.HasComponent(compData.EntitasData.Id));
 }
예제 #29
0
 public static Entity Remove(this Entity entity, IComp <object> compData)
 {
     return(entity.RemoveComponent(compData.EntitasData.Id));
 }
예제 #30
0
        public static TValue GetValue <TValue>(this Entity entity, IComp <ISingleValueComponent <TValue>, object> compData)
        {
            ISingleValueComponent <TValue> component = (ISingleValueComponent <TValue>)entity.GetComponent(compData.EntitasData.Id);

            return(component.Value);
        }