Example #1
0
        public static double GetDistance(ShortPoint p1, ShortPoint p2)
        {
            float x = p2.X - p1.X;
            float y = p2.Y - p1.Y;

            return(Math.Sqrt(x * x + y * y));
        }
Example #2
0
        protected override TileGridBlock CreateBlock(ShortPoint blockLocation)
        {
            var block = new TileGridBlock(BlockSize, blockLocation, CellEqualityComparer);

            CalculateBounds(ref blockLocation, out block.LocalBounds, out block.Origin);

            return(block);
        }
Example #3
0
        /**更新关键帧*/
        private void upDateKeyFrame(Bitmap newKeyFrame, ShortPoint point)
        {
            globalComparerBitmap = (Bitmap)newKeyFrame.Clone();

            DifferentBitmapWithCursor differentBitmapWithCursor = new ScreenBitmap.DifferentBitmapWithCursor();

            differentBitmapWithCursor.setBitmapType(SendPacket.BitmapType.COMPLETE);
            differentBitmapWithCursor.setCursorPoint(point);
            differentBitmapWithCursor.setDifBitmap(newKeyFrame);
            screenCopyDifQueue.Enqueue(differentBitmapWithCursor);
            textBoxDBQ.Text = "" + screenCopyDifQueue.getQueueSize();
        }
Example #4
0
 /**更新关键帧*/
 private void updateKeyFrame(Bitmap btm, ShortPoint cursorPoint)
 {
     if (btm != null)
     {
         globalCompareBitmap = (Bitmap)btm.Clone();
         BitmapWithCursor bitmapWithCursor = new BitmapWithCursor();
         bitmapWithCursor.setPacketType(RecPacket.PacketType.BITMAP);
         bitmapWithCursor.setCursorPoint(cursorPoint);
         bitmapWithCursor.setScreenBitmap(btm);
         /**添加到队列*/
         displayQueue.Enqueue(bitmapWithCursor);
     }
 }
Example #5
0
        private bool IsCloseToBorder(ShortRect window, ShortPoint playerPos, Player player,
                                     float borderAreaSpacePart)
        {
            int horzSpace = (int)(window.Width / borderAreaSpacePart);
            int vertSpace = (int)(window.Height / borderAreaSpacePart);

            return((playerPos.X <= window.X + horzSpace && playerPos.X - horzSpace >= 0 &&
                    (player.Direction == D.W || player.Direction == D.NW || player.Direction == D.SW)) ||
                   (playerPos.X >= window.X + window.Width - horzSpace && playerPos.X + horzSpace < _width &&
                    (player.Direction == D.E || player.Direction == D.NE || player.Direction == D.SE)) ||
                   (playerPos.Y <= window.Y + vertSpace && playerPos.Y - vertSpace >= 0 &&
                    (player.Direction == D.N || player.Direction == D.NE || player.Direction == D.NW)) ||
                   (playerPos.Y >= window.Y + window.Height - vertSpace && playerPos.Y + vertSpace < _height &&
                    (player.Direction == D.S || player.Direction == D.SE || player.Direction == D.SW)));
        }
Example #6
0
        public bool NeedsToLoadMapWindow(Player player, float borderAreaSpacePart)
        {
            ShortPoint playerPos = player.Position.ToShortPoint(ConstMap.PIXEL_SIZE);

            foreach (ShortRect window in _windows)
            {
                if (!window.Contains(playerPos))
                {
                    continue;
                }
                if (!IsCloseToBorder(window, playerPos, player, borderAreaSpacePart))
                {
                    return(false);
                }
            }
            return(true);
        }
Example #7
0
        protected virtual void CalculateBounds(ref ShortPoint location, out BoundingBoxExt bounds, out Vector2 origin)
        {
            var blockSize = BlockSize;
            int left, top, right, bottom;

            GridBlock.CalculateEdges(ref blockSize, ref location, out left, out top, out right, out bottom);

            var     size = CellSize;
            var     topLeft = new Vector3(left * size.X, top * size.Y, 0);
            var     bottomRight = new Vector3(right * size.X, bottom * size.Y, 0);
            Vector3 min, max;

            Vector3.Min(ref topLeft, ref bottomRight, out min);
            Vector3.Max(ref topLeft, ref bottomRight, out max);

            bounds = new BoundingBoxExt(min, max);
            origin = topLeft.XY();
        }
Example #8
0
        public void GridBlock_GetCellLocation()
        {
            ShortPoint blockLocation;
            int        cellX;
            int        cellY;
            int        index;

            blockLocation = new ShortPoint(1, 1);

            GetCellLocation(0, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, 1);
            Assert.AreEqual(cellY, 16);

            GetCellLocation(15, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, 16);
            Assert.AreEqual(cellY, 16);

            GetCellLocation(240, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, 1);
            Assert.AreEqual(cellY, 1);

            GetCellLocation(255, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, 16);
            Assert.AreEqual(cellY, 1);


            blockLocation = new ShortPoint(-1, -1);

            GetCellLocation(0, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, -16);
            Assert.AreEqual(cellY, -1);

            GetCellLocation(15, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, -1);
            Assert.AreEqual(cellY, -1);

            GetCellLocation(240, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, -16);
            Assert.AreEqual(cellY, -16);

            GetCellLocation(255, blockLocation, out cellX, out cellY);
            Assert.AreEqual(cellX, -1);
            Assert.AreEqual(cellY, -16);
        }
Example #9
0
        private List <ShortPoint> Search(int[,] tileMap, ShortPoint currentPosition, ShortPoint targetPosition, HashSet <ShortPoint> visited, int maxPathLength)
        {
            if (Form != null)
            {
                //tileMap[currentPosition.X, currentPosition.Y] = 2;
                //Form.Refresh();
            }

            if (maxPathLength == 0)
            {
                return(null);
            }

            if (currentPosition == targetPosition)
            {
                return(new[] { currentPosition }.ToList());
            }
            else
            {
                ShortPoint[] unvisitedNeighbours = currentPosition.GetNeighbours(tileMap).Where(n => visited.Contains(n) == false).ToArray();

                if (unvisitedNeighbours.Length > 0)
                {
                    Random.Shuffle(unvisitedNeighbours);

                    foreach (ShortPoint unvisitedNeighbour in unvisitedNeighbours)
                    {
                        visited.Add(unvisitedNeighbour);
                        var path = Search(tileMap, unvisitedNeighbour, targetPosition, visited, maxPathLength - 1);
                        //visited.Remove(unvisitedNeighbour);

                        if (path != null)
                        {
                            path.Add(unvisitedNeighbour);
                            return(path);
                        }
                    }
                }

                return(null);
            }
        }
 public void setCursorPoint(ShortPoint cursorPoint)
 {
     this.cursorPoint = cursorPoint;
 }
Example #11
0
 public static double GetDistance(ShortPoint p1, ShortPoint p2)
 {
     float x = p2.X - p1.X;
     float y = p2.Y - p1.Y;
     return Math.Sqrt(x * x + y * y);
 }
Example #12
0
        public byte[] MapWindowGet(PlayerDataEx playerData, out ShortRect mapWindow)
        {
            const float resCoef = MAP_WINDOW_RES_COEF / ConstMap.PIXEL_SIZE;

            float      dStartX, dStartY;
            float      dWidth  = playerData.ScreenRes.Width * resCoef;
            float      dHeight = playerData.ScreenRes.Height * resCoef;
            ShortPoint pos     = playerData.Player.Position.ToShortPoint(ConstMap.PIXEL_SIZE);

            switch (playerData.Player.Direction)
            {
            case Direction.N:
                dStartX = pos.X - dWidth / 2;
                dStartY = pos.Y - dHeight;
                break;

            case Direction.S:
                dStartX = pos.X - dWidth / 2;
                dStartY = pos.Y;
                break;

            case Direction.W:
                dStartX = pos.X - dWidth;
                dStartY = pos.Y - dHeight / 2;
                break;

            case Direction.E:
                dStartX = pos.X;
                dStartY = pos.Y - dHeight / 2;
                break;

            case Direction.NW:
                dStartX = pos.X - dWidth / 1.1f;
                dStartY = pos.Y - dHeight / 1.1f;
                break;

            case Direction.NE:
                dStartX = pos.X - dWidth * 0.1f;
                dStartY = pos.Y - dHeight / 1.1f;
                break;

            case Direction.SW:
                dStartX = pos.X - dWidth / 1.1f;
                dStartY = pos.Y - dHeight * 0.1f;
                break;

            case Direction.SE:
                dStartX = pos.X - dWidth * 0.1f;
                dStartY = pos.Y - dHeight * 0.1f;
                break;

            default:
                dStartX = pos.X - dWidth / 2;
                dStartY = pos.Y - dHeight / 2;
                break;
            }

            int mapWidth = playerData.Map.Width, mapHeight = playerData.Map.Height;

            ushort startX = (ushort)Math.Max(dStartX, 0);
            ushort startY = (ushort)Math.Max(dStartY, 0);
            ushort width  = (ushort)Math.Floor(startX + dWidth > mapWidth
                ? dWidth - (startX + dWidth - mapWidth)
                : dWidth);
            ushort height = (ushort)Math.Floor(startY + dHeight > mapHeight
                ? dHeight - (startY + dHeight - mapHeight)
                : dHeight);

            mapWindow = new ShortRect(startX, startY, width, height);
            return(playerData.Map.GetWindow(mapWindow.X, mapWindow.Y, mapWindow.Width, mapWindow.Height));
        }
Example #13
0
 public static void Read(byte *bData, out ShortPoint val, ref int pos)
 {
     val  = *(ShortPoint *)&bData[pos];
     pos += sizeof(ShortPoint);
 }
Example #14
0
 static void GetBlockCellLocation(int x, int y, out ShortPoint blockLocation, out int cellX, out int cellY, int blockSize = GridBlock.DefaultBlockSize)
 {
     GridBlock.GetBlockCellLocation(ref x, ref y, ref blockSize, out blockLocation, out cellX, out cellY);
 }
Example #15
0
        /**
         * 控制扫描块的大小,块越大,扫描速度越快,但是发送的数据量就越大;
         * 块越小,扫描速度就越慢,但是发送的数据量就小;
         * 局域网一般100*100
         * 广域网一般40*40 或 20*20
         * 是否需要协商块的大小????进一步实验决定。默认的事30*30,
         * 现在已经完全由server决定,client不需要blocksize
         **/
        //private static Size bitCmpSize = new Size(30, 30);
        /**图形恢复函数*/
        private void recoverBitmapFun()
        {
            while (isConnect)
            {
                try
                {
                    DifferentBitmapWithCursor difbitWithCur = deCompressDifQueue.Dequeue();
                    if (difbitWithCur != null)
                    {
                        RecPacket.PacketType packetType       = difbitWithCur.getPacketType();
                        BitmapWithCursor     bitmapWithCursor = new BitmapWithCursor();
                        bitmapWithCursor.setPacketType(packetType);
                        switch (packetType)
                        {
                        case RecPacket.PacketType.BITMAP:
                            RecPacket.BitmapType type        = difbitWithCur.getBitmapType();
                            ShortPoint           cursorpoint = difbitWithCur.getCursorPoint();
                            Bitmap          btm       = difbitWithCur.getDifBitmap();
                            List <ShortRec> difPoints = difbitWithCur.getDifPointsList();
                            switch (type)
                            {
                            case RecPacket.BitmapType.BLOCK:
                                //Stopwatch sw = new Stopwatch();
                                //sw.Start();
                                Bitmap recBitmap = RecoverBitmap.recoverScreenBitmap(difPoints, globalCompareBitmap, btm /*, bitCmpSize*/);
                                //sw.Stop();
                                //Console.WriteLine("client:"+sw.ElapsedMilliseconds+"ms");
                                bitmapWithCursor.setCursorPoint(cursorpoint);
                                bitmapWithCursor.setScreenBitmap(recBitmap);
                                globalCompareBitmap = (Bitmap)recBitmap.Clone();
                                /**放到显示队列*/
                                displayQueue.Enqueue(bitmapWithCursor);
                                break;

                            case RecPacket.BitmapType.COMPLETE:
                                updateKeyFrame(btm, cursorpoint);
                                break;

                            default:
                                break;
                            }
                            labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        case RecPacket.PacketType.TEXT:
                            bitmapWithCursor.setStringValue(difbitWithCur.getStringValue());
                            displayQueue.Enqueue(bitmapWithCursor);
                            labeldispalyQueue.Text = "显示队列大小:" + displayQueue.getQueueSize() + "\r\n";
                            break;

                        default:
                            break;
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
Example #16
0
 private bool IsCloseToBorder(ShortRect window, ShortPoint playerPos, Player player,
     float borderAreaSpacePart)
 {
     int horzSpace = (int) (window.Width/borderAreaSpacePart);
     int vertSpace = (int) (window.Height/borderAreaSpacePart);
     return (playerPos.X <= window.X + horzSpace && playerPos.X - horzSpace >= 0 &&
             (player.Direction == D.W || player.Direction == D.NW || player.Direction == D.SW)) ||
            (playerPos.X >= window.X + window.Width - horzSpace && playerPos.X + horzSpace < _width &&
             (player.Direction == D.E || player.Direction == D.NE || player.Direction == D.SE)) ||
            (playerPos.Y <= window.Y + vertSpace && playerPos.Y - vertSpace >= 0 &&
             (player.Direction == D.N || player.Direction == D.NE || player.Direction == D.NW)) ||
            (playerPos.Y >= window.Y + window.Height - vertSpace && playerPos.Y + vertSpace < _height &&
             (player.Direction == D.S || player.Direction == D.SE || player.Direction == D.SW));
 }
Example #17
0
 public TileGridBlock(int blockSize, ShortPoint location, IEqualityComparer <TileReference> cellEqualityComparer) : base(blockSize, location, cellEqualityComparer)
 {
     Invalidate();
 }
Example #18
0
 public static void Write(byte *bData, ShortPoint val, ref int pos)
 {
     (*(ShortPoint *)&bData[pos]) = val;
     pos += sizeof(ShortPoint);
 }
Example #19
0
 static void GetCellLocation(int index, ShortPoint blockLocation, out int cellX, out int cellY, int blockSize = GridBlock.DefaultBlockSize)
 {
     GridBlock.GetCellLocation(ref index, ref blockSize, ref blockLocation, out cellX, out cellY);
 }