Esempio n. 1
0
        protected virtual void OnDeserialize(BinaryReader r)
        {
            using (new WriteLock(DataLock))
                using (new WriteLock(InputLock))
                {
                    //using (new Profiler("Navmesh deserialization took %t"))
                    {
                        m_AllCells.Clear();
                        m_GridCells.Clear();
                        m_Regions.Clear();
                        m_CellsOverlappedByRegions.Clear();

                        Cell.CompareByGlobalId comp_by_global_id = new Cell.CompareByGlobalId();

                        int all_cells_count = r.ReadInt32();

                        // pre-allocate cells
                        for (int i = 0; i < all_cells_count; ++i)
                        {
                            Cell cell = new Cell(0, 0, 0, 0, 0, 0, MovementFlag.None);
                            cell.GlobalId = r.ReadInt32();
                            m_AllCells.Add(cell);
                        }

                        foreach (Cell cell in m_AllCells)
                        {
                            cell.Deserialize(m_AllCells, r);
                        }

                        Cell.LastCellGlobalId = r.ReadInt32();

                        int grid_cells_count = r.ReadInt32();

                        // pre-allocate grid cells
                        for (int i = 0; i < grid_cells_count; ++i)
                        {
                            GridCell grid_cell = new GridCell(0, 0, 0, 0, 0, 0);
                            grid_cell.GlobalId = r.ReadInt32();
                            m_GridCells.Add(grid_cell);
                        }

                        foreach (GridCell grid_cell in m_GridCells)
                        {
                            grid_cell.Deserialize(m_GridCells, m_AllCells, r);
                        }

                        GridCell.LastGridCellGlobalId = r.ReadInt32();

                        List <CellsPatch> patches = new List <CellsPatch>();
                        int patches_count         = r.ReadInt32();

                        // pre-allocate patches
                        for (int i = 0; i < patches_count; ++i)
                        {
                            CellsPatch patch = new CellsPatch(new HashSet <Cell>(), MovementFlag.None);
                            patch.GlobalId = r.ReadInt32();
                            patches.Add(patch);
                        }

                        foreach (CellsPatch patch in patches)
                        {
                            patch.Deserialize(m_AllCells, r);
                        }

                        m_CellsPatches = new HashSet <CellsPatch>(patches);

                        CellsPatch.LastCellsPatchGlobalId = r.ReadInt32();

                        int regions_count = r.ReadInt32();
                        for (int i = 0; i < regions_count; ++i)
                        {
                            m_Regions.Add(new region_data(r));
                        }

                        int cells_overlapped_by_regions_count = r.ReadInt32();
                        for (int i = 0; i < cells_overlapped_by_regions_count; ++i)
                        {
                            int key = r.ReadInt32();
                            m_CellsOverlappedByRegions.Add(key, new overlapped_cell_data(m_AllCells, r));
                        }
                    }
                }

            Log("[Nav] Navmesh deserialized.");
        }
Esempio n. 2
0
        protected virtual void OnDeserialize(BinaryReader r)
        {
            using (new WriteLock(DataLock))
                using (new WriteLock(InputLock))
                {
                    //using (new Profiler("Navmesh deserialization took {t}"))
                    {
                        m_AllCells.Clear();
                        m_GridCells.Clear();
                        m_Regions.Clear();
                        m_CellsOverlappedByRegions.Clear();

                        Cell.CompareByGlobalId comp_by_global_id = new Cell.CompareByGlobalId();

                        int all_cells_count = r.ReadInt32();

                        // pre-allocate cells
                        for (int i = 0; i < all_cells_count; ++i)
                        {
                            Cell cell = new Cell(0, 0, 0, 0, 0, 0, MovementFlag.None);
                            cell.GlobalId = r.ReadInt32();
                            m_AllCells.Add(cell);
                        }

                        m_AllCells.Sort(comp_by_global_id);

                        foreach (Cell cell in m_AllCells)
                        {
                            cell.Deserialize(m_AllCells, r);
                        }

                        Cell.LastCellGlobalId = r.ReadInt32();

                        int grid_cells_count = r.ReadInt32();

                        // pre-allocate grid cells
                        for (int i = 0; i < grid_cells_count; ++i)
                        {
                            GridCell grid_cell = new GridCell(0, 0, 0, 0, 0, 0);
                            grid_cell.GlobalId = r.ReadInt32();
                            m_GridCells.Add(grid_cell);
                        }

                        m_GridCells.Sort(comp_by_global_id);

                        foreach (GridCell grid_cell in m_GridCells)
                        {
                            grid_cell.Deserialize(m_GridCells, m_AllCells, r);
                        }

                        GridCell.LastGridCellGlobalId = r.ReadInt32();

                        int regions_count = r.ReadInt32();
                        for (int i = 0; i < regions_count; ++i)
                        {
                            m_Regions.Add(new region_data(r));
                        }

                        int cells_overlapped_by_regions_count = r.ReadInt32();
                        for (int i = 0; i < cells_overlapped_by_regions_count; ++i)
                        {
                            int key = r.ReadInt32();
                            m_CellsOverlappedByRegions.Add(key, new overlapped_cell_data(m_AllCells, r));
                        }

                        Navigator.Deserialize(m_AllCells, r);

                        if (Explorator != null)
                        {
                            Explorator.Deserialize(m_AllCells, r);
                        }
                    }
                }

            Log("[Nav] Navmesh deserialized.");
        }