Example #1
0
        private void UpdateCellsPatches(List <Cell> cells)
        {
            //using (new Profiler("[Nav] Cells patches refreshed [%t]"))
            {
                foreach (Cell c in cells)
                {
                    if (!c.HasFlags(MovementFlag.Walk))
                    {
                        continue;
                    }

                    HashSet <Cell> merged_cells = new HashSet <Cell> {
                        c
                    };

                    // find all patches, this cell neighbours belongs to
                    foreach (var neighbour in c.Neighbours)
                    {
                        CellsPatch connected_patch = m_CellsPatches.FirstOrDefault(x => x.Cells.Contains(neighbour.cell));

                        if (connected_patch != null)
                        {
                            merged_cells.UnionWith(connected_patch.Cells);
                            m_CellsPatches.Remove(connected_patch);
                        }
                    }

                    m_CellsPatches.Add(new CellsPatch(merged_cells, c.Flags));
                }
            }
        }
Example #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);
                        }

                        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.");
        }