示例#1
0
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            switch (e.KeyCode)
            {
            case Keys.A:
                key_hit_ |= KeyHit.A;
                break;

            case Keys.S:
                key_hit_ |= KeyHit.W;
                break;

            case Keys.D:
                key_hit_ |= KeyHit.D;
                break;

            case Keys.W:
                key_hit_ |= KeyHit.S;
                break;
            }
        }
示例#2
0
        private void Form1_KeyUp(object sender, KeyEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            switch (e.KeyCode)
            {
            case Keys.A:
                key_hit_ &= (~KeyHit.A);
                break;

            case Keys.S:
                key_hit_ &= (~KeyHit.W);
                break;

            case Keys.D:
                key_hit_ &= (~KeyHit.D);
                break;

            case Keys.W:
                key_hit_ &= (~KeyHit.S);
                break;
            }
        }
示例#3
0
 public KeyboardAction(int firstKey, int secondKey, int thirdKey, KeyHit type)
 {
     _firstKey  = firstKey;
     _secondKey = secondKey;
     _thirdKey  = thirdKey;
     _type      = type;
 }
示例#4
0
 private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
 {
     if (!IsValid())
     {
         return;
     }
     line_start_    = new Point(e.X, e.Y);
     is_mouse_down_ = true;
     key_hit_       = 0;
 }
示例#5
0
        public void Execute()
        {
            Services.Instance.InputService.Tick();
            // keyboard
            KeyHit kh = GetKeyboadHit();

            float moveDir  = CalcMoveDir(kh);
            bool  isMoving = moveDir >= 0;

            if (!isMoving)
            {
                isMoving = GfxSystem.GetJoyStickDir(out moveDir);
            }

            GameContext gameContext = Contexts.sharedInstance.game;

            GameEntity mainPlayer = gameContext.mainPlayerEntity;

            if (null != mainPlayer)
            {
                if (mainPlayer.hasMovement)
                {
                    if (!(SkillSystem.Instance.IsDisableMoveInput(mainPlayer) || BuffSystem.Instance.IsDisableMoveInput(mainPlayer)))
                    {
                        if (mainPlayer.hasAttr)
                        {
                            float moveSpeed = isMoving ? mainPlayer.attr.Value.MoveSpeed : 0;
                            mainPlayer.ReplaceMovement(new Vector3(Mathf.Sin(moveDir), 0, Mathf.Cos(moveDir)) * moveSpeed);
                        }
                    }
                }
                if (isMoving && !Mathf.Approximately(moveDir, mainPlayer.rotation.Value))
                {
                    if (!(SkillSystem.Instance.IsDisableRotationInput(mainPlayer) || BuffSystem.Instance.IsDisableRotationInput(mainPlayer)))
                    {
                        mainPlayer.ReplaceRotation(moveDir);
                    }
                }
                if (isMoving)
                {
                    SkillSystem.Instance.BreakSkill(mainPlayer, SkillBreakType.Move);
                }
            }
        }
示例#6
0
        public void KeyboardEvent(int firstkey, int secondKey, int thirdKey, KeyHit type)
        {
            //Console.Out.WriteLine(Correlate(firstkey));
            switch (type)
            {
            case KeyHit.singleKeyDown:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                break;

            case KeyHit.singleKeyUp:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_KEYUP, 0);
                break;

            case KeyHit.doubleKeyDown:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                keybd_event(Correlate(secondKey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                break;

            case KeyHit.doubleKeyUp:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_KEYUP, 0);
                keybd_event(Correlate(secondKey), 0, KEYEVENTF_KEYUP, 0);
                break;

            case KeyHit.tripleKeyDown:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                keybd_event(Correlate(secondKey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                keybd_event(Correlate(thirdKey), 0, KEYEVENTF_EXTENDEDKEY, 0);
                break;

            case KeyHit.tripleKeyUp:
                keybd_event(Correlate(firstkey), 0, KEYEVENTF_KEYUP, 0);
                keybd_event(Correlate(secondKey), 0, KEYEVENTF_KEYUP, 0);
                keybd_event(Correlate(thirdKey), 0, KEYEVENTF_KEYUP, 0);
                break;

            default:
                break;
            }
        }
示例#7
0
        private KeyHit GetKeyboadHit()
        {
            KeyHit kh = KeyHit.None;

            if (Services.Instance.InputService.IsKeyPressed(Keyboard.Code.W))
            {
                kh |= KeyHit.Up;
            }
            if (Services.Instance.InputService.IsKeyPressed(Keyboard.Code.A))
            {
                kh |= KeyHit.Left;
            }
            if (Services.Instance.InputService.IsKeyPressed(Keyboard.Code.S))
            {
                kh |= KeyHit.Down;
            }
            if (Services.Instance.InputService.IsKeyPressed(Keyboard.Code.D))
            {
                kh |= KeyHit.Right;
            }

            return(kh);
        }
示例#8
0
 /**
  * @brief 计算移动方向
  *           0
  *          /|\
  *           |
  * 3π/2 -----*-----> π/2
  *           |
  *           |
  *           |
  *           π
  */
 private float CalcMoveDir(KeyHit kh)
 {
     return(s_MoveDirs[(int)kh]);
 }
示例#9
0
        public void Update(bool move_enable)
        {
            UserInfo playerself = WorldSystem.Instance.GetPlayerSelf();

            if (playerself == null || playerself.IsDead())
            {
                return;
            }
            KeyHit kh = KeyHit.None;

            if (move_enable)
            {
                if (DashFireSpatial.SpatialObjType.kNPC == playerself.GetRealControlledObject().SpaceObject.GetObjType())
                {
                    NpcInfo npcInfo = playerself.GetRealControlledObject().CastNpcInfo();
                    if (null != npcInfo)
                    {
                        if (!npcInfo.CanMove)
                        {
                            return;
                        }
                    }
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.W)))
                {
                    kh |= KeyHit.Up;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.A)))
                {
                    kh |= KeyHit.Left;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.S)))
                {
                    kh |= KeyHit.Down;
                }
                if (GfxSystem.IsKeyPressed(GetKeyCode(KeyIndex.D)))
                {
                    kh |= KeyHit.Right;
                }
            }

            Motion m = kh == KeyHit.None ? Motion.Stop : Motion.Moving;

            MotionChanged = MotionStatus != m || last_key_hit_ != kh;

            if (MotionChanged)
            {
                //LogSystem.Debug("MotionChanged:{0}!={1} || {2}!={3}", MotionStatus, m, last_key_hit_, kh);
            }

            last_key_hit_ = kh;
            MotionStatus  = m;
            MoveDir       = CalcMoveDir(kh);
            if (MoveDir < 0)
            {
                MotionStatus = Motion.Stop;
            }
            if (MotionChanged)
            {
                //GfxSystem.GfxLog(string.Format("InputMoveDir:{0} Pos:{1}", MoveDir, playerself.GetMovementStateInfo().GetPosition3D().ToString()));
            }
        }
示例#10
0
        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            if (!IsValid())
            {
                return;
            }
            line_end_ = new Point(e.X, e.Y);
            CellPos end = new CellPos();

            cell_manager_.GetCell(new Vector3(e.X, 0, map_height_ - e.Y), out end.row, out end.col);
            CellPos start = new CellPos();

            cell_manager_.GetCell(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), out start.row, out start.col);

            if (e.Button == MouseButtons.Left)
            {
                switch (left_button_function_)
                {
                case FunctionType.kSetStaticBlock:
                {
                    int  row         = end.row;
                    int  col         = end.col;
                    byte obstacle    = byte.Parse(obstacleType.Text);
                    byte oldObstacle = cell_manager_.GetCellStatus(row, col);
                    cell_manager_.SetCellStatus(row, col, obstacle);

                    if (map_patch_parser_.Exist(row, col))
                    {
                        map_patch_parser_.Update(row, col, obstacle);
                    }
                    else
                    {
                        map_patch_parser_.Update(row, col, obstacle, oldObstacle);
                    }

                    UpdateObstacleGraph();
                }
                break;

                case FunctionType.kHitPoint:
                {
                    long           stTime = TimeUtility.Instance.GetElapsedTimeUs();
                    List <CellPos> result = cell_manager_.GetCellsCrossByLine(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y),
                                                                              new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime = TimeUtility.Instance.GetElapsedTimeUs();
                    this.Text = "pos(" + line_start_.X + "," + line_start_.Y + "->" + line_end_.X + "," + line_end_.Y + ") GetCellsCrossByLine consume " + (edTime - stTime) + "us";
                    hit_points_.Clear();
                    foreach (CellPos pos in result)
                    {
                        hit_points_.Add(pos);
                    }
                }
                break;

                case FunctionType.kGetCell:
                {
                    byte obstacle = cell_manager_.GetCellStatus(end.row, end.col);
                    obstacleType.Text = obstacle.ToString();
                    this.Text         = "pos(" + e.X + "," + e.Y + ") cell(" + end.row + "," + end.col + ") obstacle:" + obstacle;
                }
                break;

                case FunctionType.kAddObj:
                {
                    TestSpaceObject obj = new TestSpaceObject(next_space_objid_);
                    ++next_space_objid_;
                    obj.SetPosition(new Vector3(e.X, 0, e.Y));
                    space_objs_.Add(obj);

                    prkdtree_.Clear();
                    kdtree_.Clear();
                    int objCt = space_objs_.Count;
                    if (objCt > 0)
                    {
                        ISpaceObject[] temp = new ISpaceObject[objCt];
                        for (int i = 0; i < objCt; ++i)
                        {
                            temp[i] = space_objs_[i];
                        }
                        long stTime1 = TimeUtility.Instance.GetElapsedTimeUs();
                        prkdtree_.Build(temp);
                        long edTime1 = TimeUtility.Instance.GetElapsedTimeUs();

                        long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                        kdtree_.Build(temp);
                        long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                        System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
                        stopWatch.Start();
                        cell_manager_.ClearDynamic();
                        foreach (ISpaceObject spaceObj in space_objs_)
                        {
                            List <CellPos> cells = cell_manager_.GetCellsInCircle(Transform(spaceObj.GetPosition()), 20);
                            foreach (CellPos cellpos in cells)
                            {
                                cell_manager_.SetCellStatus(cellpos.row, cellpos.col, BlockType.DYNAMIC_BLOCK);
                            }
                        }
                        stopWatch.Stop();


                        this.Text = "obj num " + objCt + " prkdtree consume " + (edTime1 - stTime1) + "us kdtree consume " + (edTime2 - stTime1) + "us dynmic consume " + (stopWatch.ElapsedTicks) + "ticks";
                    }
                }
                break;

                case FunctionType.kQueryObj:
                {
                    Vector3 pos   = new Vector3(e.X, 0, e.Y);
                    int     objCt = space_objs_.Count;
                    if (objCt > 0)
                    {
                        float radius  = float.Parse(queryRadius.Text);
                        long  stTime1 = TimeUtility.Instance.GetElapsedTimeUs();
                        selected_objs_.Clear();
                        prkdtree_.Query(pos, radius * scale, (float distSqr, PrKdTreeObject treeObj) =>
                            {
                                selected_objs_.Add(treeObj.SpaceObject as TestSpaceObject);
                            });
                        long edTime1 = TimeUtility.Instance.GetElapsedTimeUs();

                        long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                        selected_objs2_.Clear();
                        kdtree_.Query(pos, radius * scale, (float distSqr, KdTreeObject treeObj) =>
                            {
                                selected_objs2_.Add(treeObj.SpaceObject as TestSpaceObject);
                            });
                        long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                        this.Text = "obj num " + objCt + " query prkdtree " + selected_objs_.Count + " consume " + (edTime1 - stTime1) + "us query kdtree " + selected_objs2_.Count + " consume " + (edTime2 - stTime2) + "us";
                    }
                }
                break;
                }
            }
            else
            {
                if (e.Button == MouseButtons.Right && left_button_function_ == FunctionType.kSetStaticBlock)
                {
                    int row, col;
                    cell_manager_.GetCell(new Vector3(e.X, 0, e.Y), out row, out col);
                    byte oldObstacle = cell_manager_.GetCellStatus(row, col);
                    byte obstacle    = BlockType.NOT_BLOCK;
                    cell_manager_.SetCellStatus(end.row, end.col, obstacle);

                    if (map_patch_parser_.Exist(row, col))
                    {
                        map_patch_parser_.Update(row, col, obstacle);
                    }
                    else
                    {
                        map_patch_parser_.Update(row, col, obstacle, oldObstacle);
                    }

                    UpdateObstacleGraph();
                }
                else
                {
                    long stTime = TimeUtility.Instance.GetElapsedTimeUs();
                    found_path_ = spatial_system_.FindPathWithCellMap(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime = TimeUtility.Instance.GetElapsedTimeUs();

                    long stTime2 = TimeUtility.Instance.GetElapsedTimeUs();
                    int  stRow, stCol, edRow, edCol;
                    spatial_system_.GetCell(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), out stRow, out stCol);
                    spatial_system_.GetCell(new Vector3(line_end_.X, 0, map_height_ - line_end_.Y), out edRow, out edCol);
                    //List<CellPos> path = new List<CellPos>();
                    //tree_cache_finder_.GetPath(new CellPos(stRow, stCol), new CellPos(edRow, edCol), path);
                    found_path_ = jump_point_finder_.FindPath(new CellPos(stRow, stCol), new CellPos(edRow, edCol));
                    long edTime2 = TimeUtility.Instance.GetElapsedTimeUs();

                    long stTime3 = TimeUtility.Instance.GetElapsedTimeUs();
                    found_path_ = spatial_system_.FindPath(new Vector3(line_start_.X, 0, map_height_ - line_start_.Y), new Vector3(line_end_.X, 0, map_height_ - line_end_.Y));
                    long edTime3 = TimeUtility.Instance.GetElapsedTimeUs();

                    /*//
                     * found_path_.Clear();
                     * if (path.Count > 0) {
                     * foreach (CellPos p in path) {
                     * found_path_.Add(spatial_system_.GetCellCenter(p.row, p.col));
                     * }
                     * }
                     * ///*/
                    this.Text = "findpath:" + new Vector2(line_start_.X, map_height_ - line_start_.Y).ToString() + " to " + new Vector2(line_end_.X, map_height_ - line_end_.Y).ToString() + " consume " + (edTime - stTime) / 1000.0f + "ms no preprocess consume " + (edTime2 - stTime2) / 1000.0f + "ms triangulation network consume " + (edTime3 - stTime3) / 1000.0f + "ms";
                }
            }
            is_mouse_down_ = false;
            key_hit_       = 0;
        }
        private KeyboardAction DataPacketToKeyboardAction(Byte[] packet)
        {
            KeyHit type = _packetDecomposer.fetchKeyHit(packet);

            return(new KeyboardAction(_packetDecomposer.fetchKey(packet), 0, 0, type));
        }