Exemple #1
0
        public BlockInfo <BlockInfo> Pack(byte[] dat, byte type, UInt16 msgId, Int16 time)
        {
            int len = dat.Length;
            int p   = len / FragmentSize;
            int r   = len % FragmentSize;
            int all = p;//总计分卷数量

            if (r > 0)
            {
                all++;
            }
            BlockInfo <BlockInfo> info = block1.RegNew(all);

            info.DataCount = all;
            int s = 0;

            unsafe
            {
                fixed(byte *bp = &tmpBuffer[0])
                {
                    for (int i = 0; i < p; i++)
                    {
                        MsgHead *head = (MsgHead *)bp;
                        head->Type    = type;
                        head->MsgID   = msgId;
                        head->CurPart = (UInt16)i;
                        head->AllPart = (UInt16)all;
                        head->PartLen = (UInt16)FragmentSize;
                        head->Lenth   = (UInt32)len;
                        int t = MsgHead.Size;
                        for (int j = 0; j < FragmentSize; j++)
                        {
                            tmpBuffer[t] = dat[s];
                            t++;
                            s++;
                        }
                        info.Addr[i] = PackInt(FragmentSize + MsgHead.Size);
                    }
                    if (r > 0)
                    {
                        MsgHead *head = (MsgHead *)bp;
                        head->Type    = type;
                        head->MsgID   = msgId;
                        head->CurPart = (UInt16)p;
                        head->AllPart = (UInt16)all;
                        head->PartLen = (UInt16)r;
                        head->Lenth   = (UInt32)len;
                        int t = MsgHead.Size;
                        for (int j = 0; j < r; j++)
                        {
                            tmpBuffer[t] = dat[s];
                            t++;
                            s++;
                        }
                        info.Addr[p] = PackInt(r + MsgHead.Size);
                    }
                }
            }
            return(info);
        }
Exemple #2
0
        internal BlockInfo MemoryRequest(int len)
        {
            int c = len / 1500;

            if (len % 1500 > 0)
            {
                c++;
            }
            BlockInfo block = new BlockInfo();

            for (int i = 0; i < Buffer.Count; i++)
            {
                var t = Buffer[i];
                if (t.RemainBlock >= c)
                {
                    if (t.RegNew(ref block, len))
                    {
                        return(block);
                    }
                }
            }
            BlockBuffer <byte> tmp = new BlockBuffer <byte>(1500, 8192);

            tmp.RegNew(ref block, len);
            Buffer.Add(tmp);
            return(block);
        }
Exemple #3
0
        public void ReciveMsg(byte[] buf, int len, KcpData link)
        {
            var tmp = recvBuffer.RegNew(len);

            tmp.DataCount = len;
            unsafe
            {
                byte *ptr = tmp.Addr;
                for (int i = 0; i < len; i++)
                {
                    ptr[i] = buf[i];
                }
            }
            SocMsg msg = new SocMsg();

            msg.link = link;
            msg.dat  = tmp;
            queue.Enqueue(msg);
        }
Exemple #4
0
        /// <summary>
        /// 创建带有表情符的网格
        /// </summary>
        /// <param name="text"></param>
        protected static void CreateEmojiMesh(HText text)
        {
            if (text.TmpVerts.DataCount == 0)
            {
                text.vertInfo.DataCount  = 0;
                text.trisInfo.DataCount  = 0;
                text.trisInfo2.DataCount = 0;
                return;
            }
            bufferA.Clear();
            bufferB.Clear();
            var emojis = text.emojiString.emojis;
            var str    = text.emojiString.FilterString;
            var verts  = text.TmpVerts;
            int c      = verts.DataCount;

            text.tris = null;
            if (text.vertInfo.Size == 0)
            {
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            else
            if (text.vertInfo.Size <c | text.vertInfo.Size> c + 32)
            {
                text.vertInfo.Release();
                text.vertInfo = VertexBuffer.RegNew(c);
            }
            var       emoji = text.emojiString;
            EmojiInfo info  = null;

            if (emoji.emojis.Count > 0)
            {
                info = emoji.emojis[0];
            }
            int     index = 0;
            int     e     = c / 4;
            int     ac    = 0;
            Color32 col   = Color.white;

            unsafe
            {
                HVertex *   hv  = text.vertInfo.Addr;
                TextVertex *src = verts.Addr;
                for (int i = 0; i < e; i++)
                {
                    int s  = i * 4;
                    int ss = ac;
                    int ti = src[s].Index;
                    for (int j = 0; j < 4; j++)
                    {
                        hv[ss].position = src[s].position;
                        hv[ss].color    = src[s].color;
                        hv[ss].uv       = src[s].uv;
                        hv[ss].uv4.x    = 1;
                        hv[ss].uv4.y    = 1;
                        hv[ss].picture  = 0;
                        s++;
                        ss++;
                    }
                    if (info != null)
                    {
                        if (ti > info.pos)
                        {
                            info = null;
                            for (int j = index; j < emoji.emojis.Count; j++)
                            {
                                if (emoji.emojis[j].pos >= ti)
                                {
                                    index = j;
                                    info  = emoji.emojis[j];
                                    break;
                                }
                            }
                        }
                        ss = ac;
                        if (info != null)
                        {
                            if (ti == info.pos)
                            {
                                AddTris(bufferB, ac);
                                hv[ss].uv      = info.uv[0];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[1];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[2];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                                ss++;
                                hv[ss].uv      = info.uv[3];
                                hv[ss].color   = col;
                                hv[ss].picture = 1;
                            }
                            else
                            {
                                AddTris(bufferA, ac);
                            }
                        }
                        else
                        {
                            AddTris(bufferA, ac);
                        }
                    }
                    else
                    {
                        AddTris(bufferA, ac);
                    }
                    ac += 4;
                }
            }
            text.vertInfo.DataCount = ac;
            ApplyTris(text);
        }