void Receive(ElementPacket e)
    {
        bool hasreqs = true;

        foreach (int r in e.requirements)
        {
            if (!DCGBase.all.ContainsKey(r))
            {
                hasreqs = false;                 //DCG does not contain this requirement, so we do not have all reqs
                if (expectations.ContainsKey(r)) //If we were already expecting something with id r, add that this e requires it
                {
                    expectations[r].requirers.Add(e.id);
                }
                else //If we weren't already expecting r, register it as a new expected element
                {
                    ExpectedElement exp = new ExpectedElement();
                    exp.id        = r;
                    exp.requirers = new List <int>();
                    exp.requirers.Add(e.id);
                    expectations.Add(r, exp);
                }
            }
        }

        if (hasreqs)
        {
            Create(e);
        }
        else
        {
            waiting.Add(e.id, e); //If we couldn't create e yet, put it in the waitlist
        }
    }
 public void RpcAddElement(int id, int[] requirements, ElementType type, int senderID)
 {
     if (NetPlayer.local.playerID == senderID)
     {
         return;
     }
     else
     {
         ElementPacket ep = new ElementPacket();
         ep.id           = id;
         ep.requirements = requirements;
         ep.type         = type;
         Receive(ep);
     }
 }
    void Create(ElementPacket packet)
    {
        switch (packet.type)
        {
        case ElementType.point:
            PointPacket p = packet as PointPacket;
            new Point(p.position, p.id);
            break;

        case ElementType.edge:
            List <Point> points = new List <Point>();
            foreach (int reqid in packet.requirements)
            {
                points.Add(DCGBase.all[reqid] as Point);
            }
            new Edge(points, packet.id);
            break;

        case ElementType.face:
            List <Edge> edges = new List <Edge>();
            foreach (int reqid in packet.requirements)
            {
                edges.Add(DCGBase.all[reqid] as Edge);
            }
            new Face(edges, packet.id);
            break;

        case ElementType.solid:
            List <Face> faces = new List <Face>();
            foreach (int reqid in packet.requirements)
            {
                faces.Add(DCGBase.all[reqid] as Face);
            }
            new Solid(faces, packet.id);
            break;

        default:
            Debug.LogError("Network sent unfamiliar item type!");
            break;
        }

        if (waiting.ContainsKey(packet.id)) //if this item is in the waitlist, remove it.
        {
            waiting.Remove(packet.id);
        }

        if (expectations.ContainsKey(packet.id))
        {
            foreach (int reqer in expectations[packet.id].requirers)
            {
                bool hasAll = true;
                foreach (int req in waiting[reqer].requirements)
                {
                    hasAll = hasAll && DCGBase.all.ContainsKey(req);
                }
                if (hasAll)
                {
                    Create(waiting[reqer]);
                }
            }
            expectations.Remove(packet.id);
        }
    }