Example #1
0
        // Non-Blocking Query Functions
        public bool NonBlockingPathRequest(
            NavMesh navMesh,
            RoomKey roomKey,
            Point3d startPosition,
            Point3d endPosition,
            OnPathComputerComplete onComplete)
        {
            bool success = false;

            if (m_state == eState.invalid || m_state == eState.complete)
            {
                ResetRequest();
                ResetResult();

                m_navMesh       = navMesh;
                m_roomKey       = roomKey;
                m_startPosition = startPosition;
                m_endPosition   = endPosition;

                m_state = eState.compute_end_points;
                m_maxNodesSearchedPerUpdate = NON_BLOCKING_MAX_NODES_SEARCHED_PER_UPDATE;
                m_completeCallback          = onComplete;

                success = true;
            }

            return(success);
        }
Example #2
0
        private void NavCellsFromXML(XmlNode navMeshXml)
        {
            string[] navMeshStringRows = navMeshXml.InnerText.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            uint     rowCount          = (uint)navMeshStringRows.Length;
            uint     colomnCount       = (uint)navMeshStringRows[0].Length;

            // Compute derived room properties
            float    roomWidth        = (float)colomnCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE;
            float    roomHeight       = (float)rowCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE;
            BitArray navCellData      = new BitArray((int)(rowCount * colomnCount));
            int      navMeshDataIndex = 0;

            foreach (string rowString in navMeshStringRows)
            {
                foreach (char c in rowString)
                {
                    navCellData[navMeshDataIndex] = (c == '1');
                    ++navMeshDataIndex;
                }
            }

            m_colomnCount          = colomnCount;
            m_rowCount             = rowCount;
            m_nonEmptyNavCellCount = 0;
            m_roomKey     = null;
            m_boundingBox = new AABB3d();
            m_boundingBox.SetBounds2d(-roomWidth / 2.0f, -roomHeight / 2.0f, roomWidth / 2.0f, roomHeight / 2.0f);

            NavMesh.BuildNavCellConnectivityGrid(
                colomnCount,
                rowCount,
                navCellData,
                out m_navCells,
                out m_nonEmptyNavCellCount);
        }
Example #3
0
 // Helper Functions
 private void ResetRequest()
 {
     m_navMesh       = null;
     m_roomKey       = null;
     m_startPosition = new Point3d();
     m_endPosition   = new Point3d();
     m_startNavRef   = null;
     m_endNavRef     = null;
 }
Example #4
0
 public NavMesh()
 {
     m_roomKey              = null;
     m_boundingBox          = new AABB3d();
     m_rowCount             = 0;
     m_colomnCount          = 0;
     m_nonEmptyNavCellCount = 0;
     m_navCells             = null;
     m_pvs = null;
 }
Example #5
0
        public NavMesh(RoomKey roomKey, NavMesh navMeshTemplate)
        {
            m_roomKey     = new RoomKey(roomKey);
            m_boundingBox = new AABB3d(navMeshTemplate.m_boundingBox);

            m_rowCount             = navMeshTemplate.m_rowCount;
            m_colomnCount          = navMeshTemplate.m_colomnCount;
            m_nonEmptyNavCellCount = navMeshTemplate.m_nonEmptyNavCellCount;

            m_navCells = new NavCell[navMeshTemplate.m_navCells.Length];
            Array.Copy(navMeshTemplate.m_navCells, m_navCells, m_navCells.Length);

            m_pvs = new PotentiallyVisibleSet(navMeshTemplate.m_pvs);
        }
Example #6
0
        private void NavCellsFromCompressedRawByteArray(
            byte[] compressedNavCells)
        {
            byte[] header       = new byte[COMPRESSED_DATA_HEADER_BYTE_COUNT];
            byte[] uncompressed =
                CompressionUtilities.RunLengthDecodeByteArray(
                    compressedNavCells,
                    CompressionUtilities.eEncodeType.Zeros,
                    header);
            BitArray navCellData = new BitArray(uncompressed);

            // Read out the header
            Debug.Assert(COMPRESSED_DATA_HEADER_BYTE_COUNT == 2);
            uint colomnCount = (uint)header[0];
            uint rowCount    = (uint)header[1];

            // Compute derived room properties
            int   navCellCount = (int)(rowCount * colomnCount);
            float roomWidth    = (float)colomnCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE;
            float roomHeight   = (float)rowCount * GameConstants.NAV_MESH_WORLD_UNITS_SIZE;

            // Initialize the nav cell derived data
            m_colomnCount          = colomnCount;
            m_rowCount             = rowCount;
            m_nonEmptyNavCellCount = 0;
            m_roomKey     = null;
            m_boundingBox = new AABB3d();
            m_boundingBox.SetBounds2d(-roomWidth / 2.0f, -roomHeight / 2.0f, roomWidth / 2.0f, roomHeight / 2.0f);

            // Truncate extra bits added due to the bit array getting rounded up to the nearest byte
            navCellData.Length = navCellCount;

            // Compute the connectivity data from the nav cell bit array
            NavMesh.BuildNavCellConnectivityGrid(
                colomnCount,
                rowCount,
                navCellData,
                out m_navCells,
                out m_nonEmptyNavCellCount);
        }
Example #7
0
        // Blocking Query Functions
        public bool BlockingPathRequest(
            NavMesh navMesh,
            RoomKey roomKey,
            Point3d startPosition,
            Point3d endPosition)
        {
            ResetRequest();
            ResetResult();

            m_navMesh       = navMesh;
            m_roomKey       = roomKey;
            m_startPosition = startPosition;
            m_endPosition   = endPosition;

            m_state = eState.compute_end_points;
            m_maxNodesSearchedPerUpdate = 0; // Allowed to search as many nodes as we want

            while (m_state != eState.complete)
            {
                ComputeState();
            }

            return(m_resultCode == eResult.success);
        }
Example #8
0
 public void SetRoomKey(RoomKey roomKey)
 {
     m_roomKey = new RoomKey(roomKey);
 }