Esempio n. 1
0
    public void DoConnect(string host, uint port, uint clientNum, uint packetSize, uint sendPacketNum)
    {
        if (_clients.Count < clientNum)
        {
            while (_clients.Count != clientNum)
            {
                var newSocket = new NodeConnect(); // 이 부분을 바꿔서 접속 방식 변경
                _clients.Add(newSocket);
                newSocket.Initialize();
            }
        }

        try
        {
            AbstractConnection.SetTarget(host, port);
            for (int i = 0; i < clientNum; i++)
            {
                _clients[i].Connect(sendPacketNum, packetSize);
            }
        }
        catch (ArgumentOutOfRangeException e)
        {
            LogText.Instance.Print("=== Argument Out Of Range : " + e);
        }
        catch (Exception e)
        {
            LogText.Instance.Print("Do Connect Err : " + e);
        }
    }
Esempio n. 2
0
 internal static void InvokeNodeConnect(ClusterEventArgs e)
 {
     NodeConnect?.Invoke(e);
 }
Esempio n. 3
0
    void OnStart()
    {
        //清除地图
        ClearMap();

        //重定义地图尺寸
        //mapSize=new Point(GameHelp.Random(5,10),GameHelp.Random(5,10));
        mapSize = new Point(10, 10);

        //选择起始点
        pre = new Point(GameHelp.Random(0, mapSize.x), GameHelp.Random(0, mapSize.y));

        //初始化地图寄存数组
        rnc_ary = new RoomNodeCtl[mapSize.x, mapSize.y];

        //地图中心偏移
        float mdx = (mapSize.x * 0.5f);
        float mdy = (mapSize.y * 0.5f);

        //最右边和最下边 索引
        int l_x = mapSize.x - 1;
        int l_y = mapSize.y - 1;

        //房间图块尺寸
        float size     = 180f;
        float halfSize = size * 0.5f;

        //先创建基本房间矩阵
        for (int i = 0; i < mapSize.x; i++)
        {
            bool far = false;
            bool fad = false;

            for (int o = 0; o < mapSize.y; o++)
            {
                int e_x = i - 1;
                int e_y = o - 1;

                //创建房间物体
                GameObject go = GameObject.Instantiate(Game.SObj("Node")) as GameObject;
                go.transform.parent        = nodeRoot;
                go.transform.localPosition = new Vector3((i - mdx) * size + halfSize, (mdy - o) * size - halfSize, 0);
                go.transform.localScale    = Vector3.one;
                RoomNodeCtl  rnc = go.GetComponent <RoomNodeCtl>();
                ButtonMsgObj bmo = go.GetComponent <ButtonMsgObj>();
                bmo.value     = rnc;
                bmo.target    = this.gameObject;
                rnc_ary[i, o] = rnc;
                rnc.id        = new Point(i, o);
                rnc_lst.Add(rnc);

                //SpriteRenderer sr=go.transform.Find("spt").GetComponent<SpriteRenderer>();

                if (!(i == l_x && o == l_y))
                {
                    //分布随机右或下连接点
                    bool r = (GameHelp.Random());
                    bool d = (GameHelp.Random());
                    if (r == false && d == false)
                    {
                        if ((GameHelp.Random()))
                        {
                            r = true;
                        }
                        else
                        {
                            d = true;
                        }
                    }

                    if (i == l_x)
                    {
                        r = false;
                        if (!rnc_ary[e_x, o].right)
                        {
                            d = true;
                        }
                    }

                    if (o == l_y)
                    {
                        d = false;
                        if (!rnc_ary[i, e_y].down)
                        {
                            r = true;
                        }
                    }

                    CreateLine(r, d, rnc);
                    rnc_ary[i, o].right = r; rnc_ary[i, o].down = d;
                }
                //添加到剩余ids
                lSid.Add(new Point(i, o));
            }
        }

        //补位 能够减少通道计算损耗--------------------------------------------------
        //右下角
        if (rnc_ary[mapSize.x - 1, mapSize.y - 2].down == false && rnc_ary[mapSize.x - 2, mapSize.y - 1].right == false)
        {
            if (GameHelp.Random())
            {
                rnc_ary[mapSize.x - 1, mapSize.y - 2].down = true;
            }
            else
            {
                rnc_ary[mapSize.x - 2, mapSize.y - 1].right = true;
            }
        }

        //右上角
        if (rnc_ary[mapSize.x - 2, 0].right == false && rnc_ary[mapSize.x - 1, 0].down == false)
        {
            if (GameHelp.Random())
            {
                rnc_ary[mapSize.x - 2, 0].right = true;
            }
            else
            {
                rnc_ary[mapSize.x - 1, 0].down = true;
            }
        }

        //相机锁定pre位置
        //cam.transform.localPosition=rnc_ary[(int)pre.x,(int)pre.y].transform.parent.localPosition;

        //临时ids总通道集
        List <List <Point> > allSid = new List <List <Point> >();

        //搜索出所有的通道集
        while (lSid.Count > 0)
        {
            RoomNodeCtl rnc = rnc_ary[lSid[0].x, lSid[0].y];
            hSid = new List <Point>();

            hSid.Add(rnc.id);
            Find(rnc);
            allSid.Add(hSid);
            RemoveSid(hSid);

            //给找到的通道染色
            Color c = new Color(Random.Range(0.5f, 1f), Random.Range(0.5f, 1f), Random.Range(0.5f, 1f));
            foreach (Point id in hSid)
            {
                rnc_ary[id.x, id.y].spt.color = c;
            }
        }

        //选取维度最高通道作为主要通道
        int          max       = int.MinValue;
        List <Point> mainSid   = null;
        int          mainSidId = 0;

        for (int i = 0; i < allSid.Count; i++)
        {
            if (allSid[i].Count > max)
            {
                max       = allSid[i].Count;
                mainSidId = i;
            }
        }

        //从全通道列表中移除主要通道
        mainSid = allSid[mainSidId];
        allSid.RemoveAt(mainSidId);

        //给主通道染色
        foreach (Point id in mainSid)
        {
            rnc_ary[id.x, id.y].spt.color = new Color(0, 0.8f, 1f);
        }

        //剩余通道与主要通道进行融合
        int e = 0;

        Debug.Log("剩余通道数量:" + allSid.Count);

        while (allSid.Count > 0)
        {
            //寻找目前可以连接到主通道的剩余通道
            List <Point> rnc_str = allSid[e];
            Debug.Log("通道[" + e + "]数量:" + rnc_str.Count);

            /*	foreach(Point id in rnc_str)
             *      {
             *              rnc_ary[id.x,id.y].spt.color=new Color(1f,1f,0.5f);
             *      }*/

            for (int o = 0; o < rnc_str.Count; o++)
            {
                Point id = rnc_str[o];
                List <NodeConnect> nc_lst = new List <NodeConnect>();

                Debug.Log("id:" + id.ToString());

                //查找与主通道可以连接的接口
                if (id.x < mapSize.x - 1)
                {
                    if (mainSid.Contains(new Point(id.x + 1, id.y)))
                    {
                        nc_lst.Add(new NodeConnect(id.x, id.y, NodeConnect.TYPE.RIGHT));
                    }
                }
                if (id.y < mapSize.y - 1)
                {
                    if (mainSid.Contains(new Point(id.x, id.y + 1)))
                    {
                        nc_lst.Add(new NodeConnect(id.x, id.y, NodeConnect.TYPE.UP));
                    }
                }
                if (id.x > 0)
                {
                    if (mainSid.Contains(new Point(id.x - 1, id.y)))
                    {
                        nc_lst.Add(new NodeConnect(id.x, id.y, NodeConnect.TYPE.LEFT));
                    }
                }
                if (id.y > 0)
                {
                    if (mainSid.Contains(new Point(id.x, id.y - 1)))
                    {
                        nc_lst.Add(new NodeConnect(id.x, id.y, NodeConnect.TYPE.DOWN));
                    }
                }

                //存在至少一个接口
                if (nc_lst.Count > 0)
                {
                    Debug.Log("接口数量:" + nc_lst.Count);


                    //取任意一个连接位
                    NodeConnect nc = nc_lst[GameHelp.Random(0, nc_lst.Count - 1)];
                    Debug.Log(nc.id.ToString() + "  " + nc.type);
                    //连接可连接位
                    if (nc.type == NodeConnect.TYPE.RIGHT)
                    {
                        rnc_ary[nc.id.x, nc.id.y].right = true;
                    }
                    else if (nc.type == NodeConnect.TYPE.LEFT)
                    {
                        rnc_ary[nc.id.x - 1, nc.id.y].right = true;
                    }
                    else if (nc.type == NodeConnect.TYPE.DOWN)
                    {
                        rnc_ary[nc.id.x, nc.id.y - 1].down = true;
                    }
                    else if (nc.type == NodeConnect.TYPE.UP)
                    {
                        rnc_ary[nc.id.x, nc.id.y].down = true;
                    }

                    //将当前通道添加到主通道
                    AddSid(rnc_str, mainSid);

                    //从剩余通道中移除当前通道
                    allSid.RemoveAt(e);
                    break;
                }
            }

            e++;
            if (e >= allSid.Count)
            {
                e = 0;
            }
        }

        DistributionRoomType();

        //GetDepth(pre,pre,out aim);

        /*
         * Transform aim_trs= rnc_ary[(int)aim.x,(int)aim.y].transform;
         * Transform pre_trs= rnc_ary[(int)pre.x,(int)pre.y].transform;
         *
         * pre_trs.GetComponent<SpriteRenderer>().color=new Color(1f,0.65f,0.0f,2);
         * pre_trs.parent.transform.Find("spt").localScale=new Vector3(96,96,1);
         *
         * aim_trs.GetComponent<SpriteRenderer>().color=new Color(0.15f,1,0.25f,2);
         * aim_trs.parent.transform.Find("spt").localScale=new Vector3(96,96,1);
         */
        //cam_m.SetLocalAim(Vector3.zero);
    }