示例#1
0
    /* We will do a few important things here for the belt system to work
     *      1. Split up belts into sperate list based on if they are feeding into each other
     *      2. Make item lines, and put the 'lines' on lists
     *      3. go through those lines recursively to find their update order using A* like method
     *      4. sort these lists based on the found update order
     *
     */
    public void PrepassBelts(List <BeltObject> allBelts)
    {
        var temp = Time.realtimeSinceStartup;

        Debug.Log("Clear old things");
        allBeltGroups.Clear();
        foreach (BeltObject belt in allBelts)
        {
            belt.isProcessed = false;
            belt.CreateBeltItemSlots();
        }
        temp = Time.realtimeSinceStartup - temp;
        Debug.Log("belt item slot creation: " + (temp).ToString("f6"));

        var groupBeltTotal    = 0f;
        var groupBeltCount    = 0f;
        var processSlotsTotal = 0f;
        var processSlotsCount = 0f;

        Debug.Log("Creating Belt Groups");
        for (int i = 0; i < allBelts.Count; i++)
        {
            if (allBelts[i].isProcessed)
            {
                continue;
            }

            temp = Time.realtimeSinceStartup;
            BeltGroup newBeltGroup = new BeltGroup();
            //newBeltGroup.belts = new List<BeltObject>();
            //newBeltGroup.beltItemSlotGroups = new List<List<BeltItemSlot>>();
            allBeltGroups.Add(newBeltGroup);
            RecursiveGroupBelts(allBelts[i], newBeltGroup.belts);

            List <BeltItemSlot> beltGroupBeltSlots = new List <BeltItemSlot>();
            foreach (BeltObject belt in newBeltGroup.belts)
            {
                belt.beltGroup = allBeltGroups.Count - 1;
                beltGroupBeltSlots.AddRange(belt.allBeltItemSlots);
            }
            temp            = Time.realtimeSinceStartup - temp;
            groupBeltTotal += temp;
            groupBeltCount++;

            temp = Time.realtimeSinceStartup;
            ProcessBeltGroupItemSlots(newBeltGroup, beltGroupBeltSlots);
            temp = Time.realtimeSinceStartup - temp;
            processSlotsTotal += temp;
            processSlotsCount++;
            //Debug.Log(newBeltGroup.beltItemSlotGroups.Count);
        }

        Debug.Log("Grouping belts total: " + (groupBeltTotal).ToString("f6"));
        Debug.Log("Grouping Slots total: " + (processSlotsTotal).ToString("f6"));
    }
示例#2
0
    void ProcessBeltGroupItemSlots(BeltGroup group, List <BeltItemSlot> slots)
    {
        group.beltItemSlotGroups = new List <List <BeltItemSlot> >();
        //Debug.Log("Splitting belts item slots into lists");
        for (int i = 0; i < slots.Count; i++)
        {
            if (slots[i].isProcessed)
            {
                continue;
            }
            List <BeltItemSlot> newBeltItemSlotGroup = new List <BeltItemSlot>();
            group.beltItemSlotGroups.Add(newBeltItemSlotGroup);
            RecursiveGroupBeltItemSlots(slots[i], newBeltItemSlotGroup, 0);
            foreach (BeltItemSlot beltItemSlot in newBeltItemSlotGroup)
            {
                beltItemSlot.beltItemSlotGroup = slots.Count - 1;
            }
        }

        int n = 0;

        //Debug.Log("Sorting belt item slots");
        foreach (List <BeltItemSlot> beltItemSlotGroup in group.beltItemSlotGroups)
        {
            beltItemSlotGroup.Sort((x, y) => x.index.CompareTo(y.index));
            beltItemSlotGroup.Reverse();

            //if (n == 2) {
#if UNITY_EDITOR
            if (BeltMaster.s != null)
            {
                if (BeltMaster.s.debugDraw)
                {
                    for (int i = 0; i < beltItemSlotGroup.Count - 1; i++)
                    {
                        Debug.DrawLine(beltItemSlotGroup[i].position - Vector3.forward * i * 0.05f, beltItemSlotGroup[i + 1].position - Vector3.forward * (i + 1) * 0.05f, Color.magenta, 200f);
                    }
                }
            }
#endif
            //}
            n++;
        }

        //Debug.Log(group.beltItemSlotGroups.Count);
    }
示例#3
0
    public void ProcessOneBeltChange(BeltObject belt)
    {
        belt.RemoveOldItemSlots(allBeltGroups[belt.beltGroup].beltItemSlotGroups);
        belt.CreateBeltItemSlots();
        List <BeltItemSlot> targetBeltSlots = belt.allBeltItemSlots;

        List <BeltGroup> myNearbyBeltGroups = GetNearbyBeltGroups(belt);


        BeltGroup targetBeltGroup;

        // If there is no nearby belt group, create a new one with this in it
        if (myNearbyBeltGroups.Count == 0)
        {
            targetBeltGroup       = new BeltGroup();
            targetBeltGroup.belts = new List <BeltObject>();
            allBeltGroups.Add(targetBeltGroup);
        }
        else
        {
            targetBeltGroup = myNearbyBeltGroups[0];
            targetBeltGroup.belts.Add(belt);
            foreach (BeltGroup group in myNearbyBeltGroups)
            {
                foreach (List <BeltItemSlot> belItemSlotList in group.beltItemSlotGroups)
                {
                    targetBeltSlots.AddRange(belItemSlotList);
                }
            }

            for (int i = 1; i < myNearbyBeltGroups.Count; i++)
            {
                allBeltGroups.Remove(myNearbyBeltGroups[i]);
            }
        }



        targetBeltGroup.belts.Add(belt);
        targetBeltGroup.beltItemSlotGroups.Add(targetBeltSlots);

        ProcessBeltGroupItemSlots(targetBeltGroup, targetBeltSlots);
    }