Exemplo n.º 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);
    }
Exemplo n.º 2
0
 public override void OnVibrate(IComp Comp, string Contact, object Val)
 {
     if (Contacts[Contact] == Comp)
     {
         Values[Contact] = Val;
     }
 }
Exemplo n.º 3
0
 public override void DisconnectWith(IComp Comp, string Contact)
 {
     if (Contacts.ContainsKey(Contact))
     {
         Contacts.Remove(Contact);
         Comp.DisconnectWith(this, Contact);
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
        public static CConduit Connect(IComp A, IComp B, string Contact)
        {
            var C = new CConduit();

            C.Connect(A, Contact);
            C.Connect(B, Contact);
            return(C);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 9
0
 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);
         }
     }
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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));
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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];
             }
         }
     }
 }
Exemplo n.º 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;
            }
        }
Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 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);
        }
    }
Exemplo n.º 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();
            }
        }
Exemplo n.º 19
0
        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;
            }
        }
Exemplo n.º 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);
                    }
                }
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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;
                }
            }
Exemplo n.º 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);
            }
        }
Exemplo n.º 25
0
 public override void DisconnectWith(IComp Comp, string Contact)
 {
 }
Exemplo n.º 26
0
 public override void Connect(IComp Comp, string Contact)
 {
 }
Exemplo n.º 27
0
 public static void AsyncVirbrate(IComp From, KeyValuePair <String, IComp> Pair, Object Val)
 {
     Pair.Value.OnVibrate(From, Pair.Key, Val);
 }
Exemplo n.º 28
0
 public static bool Has(this Entity entity, IComp compData)
 {
     return(entity.HasComponent(compData.EntitasData.Id));
 }
Exemplo n.º 29
0
 public static Entity Remove(this Entity entity, IComp <object> compData)
 {
     return(entity.RemoveComponent(compData.EntitasData.Id));
 }
Exemplo n.º 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);
        }