Ejemplo n.º 1
0
        internal void Deserialize <T>(List <T> all_cells, BinaryReader r) where T : Cell, new()
        {
            GlobalId = r.ReadInt32();
            Id       = r.ReadInt32();
            AABB.Deserialize(r);
            Flags            = (MovementFlag)r.ReadInt32();
            Replacement      = r.ReadBoolean();
            Disabled         = r.ReadBoolean();
            MovementCostMult = r.ReadSingle();

            T temp_cell = new T();

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

            int neighbours_num = r.ReadInt32();

            for (int i = 0; i < neighbours_num; ++i)
            {
                Neighbour neighbour = new Neighbour(null, null, MovementFlag.None);

                int neighbour_global_id = r.ReadInt32();
                temp_cell.GlobalId = neighbour_global_id;
                neighbour.cell     = all_cells.ElementAt(all_cells.BinarySearch((T)temp_cell, comp_by_global_id));

                if (r.ReadBoolean())
                {
                    neighbour.border_point = new Vec3(r);
                }

                neighbour.connection_flags = (MovementFlag)r.ReadInt32();

                Neighbours.Add(neighbour);
            }
        }
Ejemplo 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);
                        }

                        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.");
        }
Ejemplo n.º 3
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.");
        }