コード例 #1
0
ファイル: FrameManager.cs プロジェクト: Kwarthys/BeeKeeper
    /*
     * private CombPointCloud getCloudOfId(int combId)
     * {
     *    CombPointCloud cpc = null;
     *
     *    for(int i = 0; i < frames.Count && cpc==null; ++i)
     *    {
     *        //cpc = frames[i].getCPC(combId);
     *    }
     *
     *    if(cpc == null)
     *    {
     *        //Spawn it
     *        //Debug.LogError("Shouldn't have to create a frame"); this can happen at start, but is quickly overriden by the correct stuff
     *        int fid = combId / 2;
     *        TextureBasedFrameBehaviour f = spawnAFrame(fid);
     *
     *        //cpc = f.getCPC(combId);
     *
     *        //frames.Add(f);
     *    }
     *    return cpc;
     * }
     */

    public void updateBeePoints(UpdateOrder o)
    {
        List <UpdateOrder> sortedOrders   = new List <UpdateOrder>();
        UpdateOrder        foragersUpdate = new UpdateOrder();

        for (int i = 0; i < o.targetsIDs.Count; ++i)
        {
            Vector3 target = o.newTargets[i];

            //if(UnityEngine.Random.value > 0.99f)Debug.Log("target: " + target + " -> " + getPosOnFrame(target));

            if (target.z == -1)
            {
                //forager
                foragersUpdate.add(target, o.targetsIDs[i], o.colors[i]);
            }
            else
            {
                int frameTargetIDInList = (int)(target.z / 2);

                while (sortedOrders.Count <= frameTargetIDInList)
                {
                    sortedOrders.Add(new UpdateOrder());
                }

                if (target.x < 0)
                {
                    //sending two request for bees changing frames to prevent them to freeze for a timestep. Basically telerpoting them to the first target en route to the second
                    sortedOrders[frameTargetIDInList].add(getPosOnFrame(target), o.targetsIDs[i]);
                    target.x = -target.x;
                }


                sortedOrders[frameTargetIDInList].add(getPosOnFrame(target), o.targetsIDs[i], o.colors[i]);
            }
        }

        for (int i = 0; i < sortedOrders.Count; ++i)
        {
            //if (Random.value > 0.99f) Debug.Log("Order " + i + " populated with " + sortedOrders[i].targetsIDs.Count);
            frames[i].beePointCloud.updatePoints(sortedOrders[i]);
        }

        //Debug.Log("FUpdate: " + foragersUpdate.targetsIDs.Count);
        foragerCloud.updatePoints(foragersUpdate);
    }
コード例 #2
0
    /*********************/

    void Update()
    {
        if (Time.realtimeSinceStartup - lastRefresh > refreshRate)
        {
            List <Vector3> targets = new List <Vector3>();
            List <int>     ids     = new List <int>();
            List <Color>   colors  = new List <Color>();

            //Debug.Log("ContactGrapher AgentsSize - " + model.theAgents.Count);

            //update graph
            int size = model.theAgents.Count;
            foreach (BeeAgent b in model.theAgents.Values)
            {
                Vector3 point = transformPoint(new Vector3(b.age, b.JH, b.amountExchanged));
                targets.Add(point);
                colors.Add(b.JH > 0.5f ? Color.yellow : Color.red);
                //Debug.Log(b.JH > 0.5f ? Color.yellow : Color.red);

                int pointID;

                if (!idToPointID.ContainsKey(b.id))
                {
                    pointID = pointCloud.idManager.getNextFreeIndex();
                    idToPointID.Add(b.id, pointID);
                }
                else
                {
                    pointID = idToPointID[b.id];
                }

                ids.Add(pointID);
            }

            pointCloud.updatePoints(new UpdateOrder(targets, ids, colors));

            lastRefresh = Time.realtimeSinceStartup;
        }
    }