Beispiel #1
0
        void DrawLine(Vector2 start, Vector2 end)
        {
            DrawArea area = new DrawArea(start, end, BrushSize);

            loopBuffer.Push(area);
            int h  = (int)area.hw;
            int sx = (int)area.minx;

            sx -= h;
            int ex = (int)area.maxx;

            ex += h;
            int sy = (int)area.miny;

            sy -= h;
            int ey = (int)area.maxy;

            ey += h;
            var p = Vector2.zero;

            for (int i = sx; i < ex; i++)
            {
                p.x = i;
                for (int j = sy; j < ey; j++)
                {
                    var pos = new Vector2(i, j);
                    if (area.CheckPix(pos))
                    {
                        var a = loopBuffer[0];
                        if (a != null)
                        {
                            if (a.CheckPix(pos))
                            {
                                goto label;
                            }
                        }
                        FillColor(pos);
                    }
                    label :;
                }
            }
        }
Beispiel #2
0
    void ReceiveCallBack(IAsyncResult AR)
    {
        try
        {
            if (null == mSocket)
            {
                return;
            }

            int REnd = mSocket.EndReceive(AR);
            mCurPosition += REnd;

            // Got Message, lock
            do
            {
                if (mCurPosition >= MsgPrefixLength)
                {
                    T   head = (T)BytesToStruct(mDataBuffer, typeof(T));
                    int len  = (int)head.msgSize;

                    if (len < 0)
                    {
                        PushEvent(ENetEvent.Error, (int)(ESocketError.PacketError));
                        Close();
                        PushEvent(ENetEvent.Close, 0);
                        return;
                    }
                    else if (len > mCurPosition)
                    {
                        break;
                    }
                    else
                    {
                        bool bRes = false;
                        lock (mLocker)
                        {
                            bRes = mReceiveLoopBuffer.Push(mDataBuffer, 0, len);
                        }

                        if (!bRes)
                        {
                            PushEvent(ENetEvent.Error, (int)(ESocketError.OverflowReceive));
                            Close();
                            PushEvent(ENetEvent.Close, 0);

                            return;
                        }
                        PushEvent(ENetEvent.Receive, len);

                        mCurPosition -= len;
                        if (mCurPosition > 0)
                        {
                            Array.Copy(mDataBuffer, len, mDataBuffer, 0, mCurPosition);
                        }
                    }
                }
                else
                {
                    break;
                }
            } while (mCurPosition > 0);

            mSocket.BeginReceive(mDataBuffer, mCurPosition, mDataBuffer.Length - mCurPosition, 0, new AsyncCallback(ReceiveCallBack), null);
        }
        catch (SocketException ex)
        {
            Debug.LogError("Connected: " + mSocket.Connected + ". Exception: " + ex.ToString());
            PushEvent(ENetEvent.Error, (int)(ex.SocketErrorCode));
            PushEvent(ENetEvent.Close, 0);
            if (!IsConnected())
            {
                mSocket.Close();
                mSocket = null;
            }
        }
    }