Exemplo n.º 1
0
        protected override async Task Close(PipeEndpoint e, Endpoint ee = null, CancellationToken cancel = default(CancellationToken))
        {
            MessageEntry m = new MessageEntry(MessageEntryType.PipeDisconnectReq, MemberName);

            m.AddElement("index", e.Index);
            MessageEntry ret = await stub.ProcessRequest(m, cancel);
        }
Exemplo n.º 2
0
 protected override void DeleteEndpoint(PipeEndpoint e)
 {
     lock (pipeendpointlock)
     {
         pipeendpoints[e.Endpoint].Remove(e.Index);
     }
 }
Exemplo n.º 3
0
    public override IEnumerator FlowBack(PipeEndpoint input)
    {
        yield return(new WaitForSeconds(flowThroughTime / 4));

        isShaking = true;
        flowing   = false;
        StartCoroutine(TurnLever());
    }
Exemplo n.º 4
0
    public override IEnumerator FlowThrough(PipeEndpoint input)
    {
        flowing   = true;
        isShaking = true;
        yield return(new WaitForSeconds(flowThroughTime));

        endpointA.OutFlow(true);
    }
Exemplo n.º 5
0
    private void OnTriggerExit(Collider other)
    {
        PipeEndpoint endpoint = other.GetComponent <PipeEndpoint>();

        if (endpoint != null)
        {
            connectedNeighbor = null;
        }
    }
Exemplo n.º 6
0
        protected override async Task Close(PipeEndpoint e, Endpoint ee, CancellationToken cancel = default(CancellationToken))
        {
            MessageEntry m = new MessageEntry(MessageEntryType.PipeClosed, MemberName);

            m.AddElement("index", e.Index);
            await skel.SendPipeMessage(m, ee, cancel);

            DeleteEndpoint(e);
        }
Exemplo n.º 7
0
    public override IEnumerator FlowThrough(PipeEndpoint input)
    {
        yield return(new WaitForSeconds(flowThroughTime / 2));

        isShaking = true;
        yield return(new WaitForSeconds(flowThroughTime / 2));

        focusManager.ToggleState(false);
        gameboy.SetActive(true);
    }
Exemplo n.º 8
0
    public virtual IEnumerator FlowThrough(PipeEndpoint input)
    {
        canRotate = false;
        yield return(new WaitForSeconds(flowThroughTime / 2));

        isShaking = true;
        yield return(new WaitForSeconds(flowThroughTime / 2));

        PipeEndpoint output;

        if (input.Equals(endpointA))
        {
            output = endpointB;
        }
        else
        {
            output = endpointA;
        }
        output.OutFlow(true);
    }
Exemplo n.º 9
0
    public virtual IEnumerator FlowBack(PipeEndpoint input)
    {
        yield return(new WaitForSeconds(flowThroughTime / 2));

        isShaking          = false;
        transform.position = originalPosition;
        yield return(new WaitForSeconds(flowThroughTime / 2));

        canRotate = true;

        PipeEndpoint output;

        if (input.Equals(endpointA))
        {
            output = endpointB;
        }
        else
        {
            output = endpointA;
        }
        output.OutFlow(false);
    }
Exemplo n.º 10
0
        protected bool DispatchPacket(MessageElement me, PipeEndpoint e, out uint packetnumber)
        {
            int index = Int32.Parse(me.ElementName);
            List <MessageElement> elems = ((MessageElementMap <string>)me.Data).Elements;

            packetnumber = (MessageElement.FindElement(elems, "packetnumber").CastData <uint[]>())[0];
            object data;

            if (!rawelements)
            {
                data = UnpackAnyType(MessageElement.FindElement(elems, "packet"));
            }
            else
            {
                data = MessageElement.FindElement(elems, "packet");
            }
            e.PipePacketReceived((T)data, packetnumber);

            bool requestack = (elems.Any(x => x.ElementName == "requestack"));

            return(requestack);
        }
Exemplo n.º 11
0
        public override async Task <PipeEndpoint> Connect(int index, CancellationToken cancel = default(CancellationToken))
        {
            object connecting_key = new object();

            connecting.Add(Tuple.Create(index, connecting_key));
            int rindex = -1;

            try
            {
                MessageEntry m = new MessageEntry(MessageEntryType.PipeConnectReq, MemberName);
                m.AddElement("index", index);
                MessageEntry ret = await stub.ProcessRequest(m, cancel);

                rindex = (ret.FindElement("index").CastData <int[]>())[0];

                PipeEndpoint e;
                if (early_endpoints.ContainsKey(rindex))
                {
                    e = early_endpoints[rindex];
                    early_endpoints.Remove(rindex);
                }
                else
                {
                    e = new PipeEndpoint(this, rindex);
                }
                pipeendpoints.Add(rindex, e);
                return(e);
            }
            finally
            {
                connecting.RemoveAll(x => Object.ReferenceEquals(x.Item2, connecting_key));
                if (connecting.Count == 0)
                {
                    early_endpoints.Clear();
                }
            }
        }
Exemplo n.º 12
0
        public override void PipePacketReceived(MessageEntry m, Endpoint e = null)
        {
            if (m.EntryType == MessageEntryType.PipeClosed)
            {
                try
                {
                    int index = (m.FindElement("index").CastData <int[]>())[0];
                    pipeendpoints[index].RemoteClose();
                }
                catch { };
            }
            else if (m.EntryType == MessageEntryType.PipePacket)
            {
                List <MessageElement> ack = new List <MessageElement>();
                foreach (MessageElement me in m.elements)
                {
                    try
                    {
                        int  index = Int32.Parse(me.ElementName);
                        uint pnum;

                        PipeEndpoint p = null;
                        if (pipeendpoints.ContainsKey(index))
                        {
                            p = pipeendpoints[index];
                        }
                        else
                        {
                            if (early_endpoints.ContainsKey(index))
                            {
                                p = early_endpoints[index];
                            }
                            else
                            if (connecting.Count > 0)
                            {
                                if (connecting.Any(x => x.Item1 == -1 || x.Item1 == index))
                                {
                                    p = new PipeEndpoint(this, index);
                                    early_endpoints.Add(index, p);
                                }
                            }
                        }

                        if (p == null)
                        {
                            continue;
                        }
                        if (DispatchPacket(me, p, out pnum))
                        {
                            ack.Add(new MessageElement(me.ElementName, new uint[] { pnum }));
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
                try
                {
                    if (ack.Count > 0)
                    {
                        MessageEntry mack = new MessageEntry(MessageEntryType.PipePacketRet, m.MemberName);
                        mack.elements = ack;
                        stub.SendPipeMessage(mack, default(CancellationToken)).IgnoreResult();
                    }
                }
                catch { }
            }
            else if (m.EntryType == MessageEntryType.PipePacketRet)
            {
                try
                {
                    foreach (MessageElement me in m.elements)
                    {
                        int index = Int32.Parse(me.ElementName);
                        DispatchPacketAck(me, pipeendpoints[index]);
                    }
                }
                catch { }
            }
        }
Exemplo n.º 13
0
 protected abstract Task Close(PipeEndpoint e, Endpoint ee = null, CancellationToken cancel = default(CancellationToken));
Exemplo n.º 14
0
        public Task <MessageEntry> PipeCommand(MessageEntry m, Endpoint e)
        {
            lock (pipeendpointlock)
            {
                switch (m.EntryType)
                {
                case MessageEntryType.PipeConnectReq:
                {
                    if (!pipeendpoints.Keys.Contains(e.LocalEndpoint))
                    {
                        pipeendpoints.Add(e.LocalEndpoint, new Dictionary <int, PipeEndpoint>());
                    }

                    Dictionary <int, PipeEndpoint> ep = pipeendpoints[e.LocalEndpoint];

                    int index = (m.FindElement("index").CastData <int[]>())[0];
                    if (index == -1)
                    {
                        index = (ep.Count == 0) ? 1 : (ep.Keys.Max() + 1);
                    }

                    if (ep.Keys.Contains(index))
                    {
                        throw new Exception("Pipe endpoint index in use");
                    }

                    PipeEndpoint p = new PipeEndpoint(this, index, e);
                    ep.Add(index, p);
                    try
                    {
                        if (callback != null)
                        {
                            callback(p);
                        }
                    }
                    catch { }

                    MessageEntry ret = new MessageEntry(MessageEntryType.PipeConnectRet, MemberName);
                    ret.AddElement("index", index);
                    return(Task.FromResult(ret));
                }

                case MessageEntryType.PipeDisconnectReq:
                {
                    if (!pipeendpoints.Keys.Contains(e.LocalEndpoint))
                    {
                        throw new Exception("Invalid pipe");
                    }
                    Dictionary <int, PipeEndpoint> ep = pipeendpoints[e.LocalEndpoint];

                    int index = (m.FindElement("index").CastData <int[]>())[0];
                    if (!ep.Keys.Contains(index))
                    {
                        throw new Exception("Invalid pipe");
                    }


                    ep.Remove(index);

                    return(Task.FromResult(new MessageEntry(MessageEntryType.PipeDisconnectReq, MemberName)));
                }

                default:
                    throw new Exception("Invalid Command");
                }
            }
        }
Exemplo n.º 15
0
 protected override void DeleteEndpoint(PipeEndpoint e)
 {
     pipeendpoints.Remove(e.Index);
 }
Exemplo n.º 16
0
        protected void DispatchPacketAck(MessageElement me, PipeEndpoint e)
        {
            uint pnum = me.CastData <uint[]>()[0];

            e.PipePacketAckReceived(pnum);
        }
Exemplo n.º 17
0
 protected abstract void DeleteEndpoint(PipeEndpoint e);