コード例 #1
0
ファイル: Form1.cs プロジェクト: mengran3275188/EntitasUnity
        private void Reset()
        {
            tiled_map_parser_ = new TiledMapParser();
            nav_map_parser_   = new NavmeshMapParser();
            map_patch_parser_ = new MapPatchParser();
            spatial_system_   = new Spatial.SpatialSystem();
            cell_manager_     = new CellManager();

            back_image_       = Image.FromFile(map_image_);
            pictureBox1.Image = back_image_;
            pictureBox1.Size  = back_image_.Size;
            map_width_        = back_image_.Width;
            map_height_       = back_image_.Height;

            context_.MaximumBuffer = new Size((int)map_width_, (int)map_height_);
            Graphics targetDC = this.pictureBox1.CreateGraphics();

            graphics_          = context_.Allocate(targetDC, new Rectangle(0, 0, (int)map_width_, (int)map_height_));
            obstacle_graphics_ = context_.Allocate(targetDC, new Rectangle(0, 0, (int)map_width_, (int)map_height_));

            scale       = map_width_ / map_actual_width_;
            cell_width_ = cell_actual_width_ * scale;
            if (cell_width_ < 1)
            {
                cell_width_ = 1;
            }
            map_actual_height_ = map_height_ * map_actual_width_ / map_width_;

            ///*
            cell_manager_.Init(map_actual_width_, map_actual_height_, cell_actual_width_);
            cell_manager_.Scale(map_width_ / map_actual_width_);
            nav_map_parser_.ParseTileDataWithNavmeshUseFileScale(nav_file_, map_actual_width_, map_actual_height_);
            nav_map_parser_.GenerateObstacleInfoWithNavmesh(cell_manager_);

            //map_parser_.ParseTiledData(obstacle_file_, map_width_, map_height_);
            //map_parser_.GenerateObstacleInfo(cell_manager_);
            //map_parser_.SaveObstacleInfo(obs_file_);
            cell_manager_.Scale(map_actual_width_ / map_width_);
            cell_manager_.Save(map_file_);
            //tree_cache_finder_.PreprocessMap(cell_manager_, path_file_);
            //tree_cache_finder_.PrepareForSearch(path_file_);
            jump_point_finder_ = new JumpPointFinder();
            jump_point_finder_.Init(cell_manager_);
            //jump_point_finder_.PreprocessMap(path_file_);
            //*/

            spatial_system_.Init(map_file_, path_file_);
            long stTime = TimeUtility.Instance.GetElapsedTimeUs();

            spatial_system_.LoadObstacle(obs_file_, true);
            spatial_system_.TriangulationNetworkFinder.SparseDistance = 16.0f;
            triangles = spatial_system_.TriangulationNetworkFinder.TriangulationNetwork;
            long edTime = TimeUtility.Instance.GetElapsedTimeUs();

            LogUtil.Info("triangulation consume " + (edTime - stTime) + "us");

            spatial_system_.JumpPointFinder.RecordVisitedCells = false;
            cell_manager_ = spatial_system_.GetCellManager();
            cell_manager_.Scale(scale);

            jump_point_finder_.Init(cell_manager_);

            map_patch_parser_.Load(map_patch_file_);
            map_patch_parser_.VisitPatches((int row, int col, byte obstacle) =>
            {
                cell_manager_.SetCellStatus(row, col, obstacle);
                LogUtil.Info("map patch:{0},{1}->{2}", row, col, obstacle);
            });

            control_obj_.SetPosition(new Vector3(0, 0, 0));
            spatial_system_.AddObj(control_obj_);

            prkdtree_ = new PrKdTree(map_width_);
            kdtree_.Clear();
            space_objs_.Clear();
            selected_objs_.Clear();
            selected_objs2_.Clear();
            hit_points_.Clear();
            found_path_ = null;

            UpdateObstacleGraph();
            hit_points_.Clear();
        }