示例#1
0
        /// @par 
        ///
        /// Must be the first function called after construction, before other
        /// functions are used.
        ///
        /// This function can be used multiple times.
        /// Initializes the query object.
        ///  @param[in]		nav			Pointer to the dtNavMesh object to use for all queries.
        ///  @param[in]		maxNodes	Maximum number of search nodes. [Limits: 0 < value <= 65536]
        /// @returns The status flags for the query.
        public dtStatus init(dtNavMesh nav, int maxNodes)
        {
	        m_nav = nav;
	
	        if (m_nodePool == null || m_nodePool.getMaxNodes() < maxNodes)
	        {
		        if (m_nodePool != null)
		        {
			        //m_nodePool.~dtNodePool();
			        //dtFree(m_nodePool);
			        m_nodePool = null;
		        }
		        m_nodePool = new dtNodePool(maxNodes, (int) dtNextPow2((uint)(maxNodes/4)));//(dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(maxNodes, dtNextPow2(maxNodes/4));
		        if (m_nodePool == null)
			        return DT_FAILURE | DT_OUT_OF_MEMORY;
	        }
	        else
	        {
		        m_nodePool.clear();
	        }
	
	        if (m_tinyNodePool == null)
	        {
		        m_tinyNodePool = new dtNodePool(64, 32);//(dtAlloc(sizeof(dtNodePool), DT_ALLOC_PERM)) dtNodePool(64, 32);
		        if (m_tinyNodePool == null)
			        return DT_FAILURE | DT_OUT_OF_MEMORY;
	        }
	        else
	        {
		        m_tinyNodePool.clear();
	        }
	
	        // TODO: check the open list size too.
	        if (m_openList == null || m_openList.getCapacity() < maxNodes)
	        {
		        if (m_openList != null)
		        {
			        //m_openList.~dtNodeQueue();
			        //dtFree(m_openList);
			        m_openList = null;
		        }
		        m_openList = new dtNodeQueue(maxNodes);//(dtAlloc(sizeof(dtNodeQueue), DT_ALLOC_PERM)) dtNodeQueue(maxNodes);
		        if (m_openList == null)
			        return DT_FAILURE | DT_OUT_OF_MEMORY;
	        }
	        else
	        {
		        m_openList.clear();
	        }
	
	        return DT_SUCCESS;
        }
示例#2
0
	// Initializes the navmesh with data.
	// Params:
	//	data - (in) Pointer to navmesh data.
	//	dataSize - (in) size of the navmesh data.
	//	ownsData - (in) Flag indicating if the navmesh should own and delete the data.
	public bool init( byte[] data, int dataSize, bool ownsData, int iIndex )
	{
		m_iIndex = iIndex;
		m_header = new dtStatNavMeshHeader();
		
		MemoryStream fs = new MemoryStream (data);			
		BinaryReader readerStream = new BinaryReader(fs);	
		
		readerStream.BaseStream.Position = 0;
			
		int iFiledataSize = readerStream.ReadInt32() + 4;		
		m_header.magic = readerStream.ReadInt32();
		m_header.version = readerStream.ReadInt32();
		
		if( iFiledataSize != dataSize )			
		{
			Debug.LogError("DetourStatNavMesh::init() [ dataSize != dataSize ]file size : " + iFiledataSize + " data Size :" + dataSize);
			return false;
		}
		
		if( m_header.magic != 1312904781 )
		{
			Debug.LogError("DetourStatNavMesh::init() [ magic diff ]");
			return false;
		}
		
		if( m_header.version != 3 )
		{
			Debug.LogError("DetourStatNavMesh::init() [ version diff ]");
			return false;
		}
		
		m_header.npolys = readerStream.ReadInt32();
		m_header.nverts = readerStream.ReadInt32();
		m_header.nnodes = readerStream.ReadInt32();
		m_header.ndmeshes = readerStream.ReadInt32();
		m_header.ndverts = readerStream.ReadInt32();
		m_header.ndtris = readerStream.ReadInt32();
		m_header.cs = readerStream.ReadSingle();
		
		m_header.bmin[0] = readerStream.ReadSingle();
		m_header.bmin[1] = readerStream.ReadSingle();
		m_header.bmin[2] = readerStream.ReadSingle();		
		m_header.bmax[0] = readerStream.ReadSingle();
		m_header.bmax[1] = readerStream.ReadSingle();
		m_header.bmax[2] = readerStream.ReadSingle();
		
		
		int headerSize = dtStatNavMeshHeader.size+4; 
		int vertsSize = m_header.nverts;
		int polysSize = m_header.npolys;
		int nodesSize = m_header.npolys*2;
		int detailMeshesSize = m_header.ndmeshes;
		int detailVertsSize = m_header.ndverts;
		int detailTrisSize = m_header.ndtris;
		
		//------
		readerStream.BaseStream.Position = headerSize;
		m_header.verts = new Vector3[vertsSize];
		for( int i=0; i<vertsSize; ++i )
		{
			m_header.verts[i].x = readerStream.ReadSingle();
			m_header.verts[i].y = readerStream.ReadSingle();
			m_header.verts[i].z = readerStream.ReadSingle();
		}		
		
		//------
		m_header.polys = new dtStatPoly[polysSize];
		for( int i=0; i<polysSize; ++i )
		{
			m_header.polys[i] = new dtStatPoly();
			for( int k=0; k<DT_STAT_VERTS_PER_POLYGON; ++k )
			{
				m_header.polys[i].v[k] = readerStream.ReadUInt16();
			}
			
			for( int k=0; k<DT_STAT_VERTS_PER_POLYGON; ++k )
			{
				m_header.polys[i].n[k] = readerStream.ReadUInt16();
			}
			
			m_header.polys[i].nv = readerStream.ReadByte();
			m_header.polys[i].flags = readerStream.ReadByte();
		}		
		
		//------
		m_header.bvtree = new dtStatBVNode[nodesSize];
		for( int i=0; i<nodesSize; ++i )
		{
			m_header.bvtree[i] = new dtStatBVNode();
			for( int k=0; k<3; ++k )
			{
				m_header.bvtree[i].bmin[k] = readerStream.ReadUInt16();
			}
			
			for( int k=0; k<3; ++k )
			{
				m_header.bvtree[i].bmax[k] = readerStream.ReadUInt16();
			}
			
			m_header.bvtree[i].i = readerStream.ReadInt32();
		}
		
		
		//------
		m_header.dmeshes = new dtStatPolyDetail[detailMeshesSize];
		for( int i=0; i<detailMeshesSize; ++i )
		{
			m_header.dmeshes[i] = new dtStatPolyDetail();		
			m_header.dmeshes[i].vbase = readerStream.ReadUInt16();
			m_header.dmeshes[i].nverts = readerStream.ReadUInt16();
			m_header.dmeshes[i].tbase = readerStream.ReadUInt16();
			m_header.dmeshes[i].ntris = readerStream.ReadUInt16();
		}
		
		
		m_header.dverts = new Vector3[detailVertsSize];
		for( int i=0; i<detailVertsSize; ++i )
		{
			m_header.dverts[i].x = readerStream.ReadSingle();
			m_header.dverts[i].y = readerStream.ReadSingle();
			m_header.dverts[i].z = readerStream.ReadSingle();
		}
		
		m_header.dtris = new dtTriIdx[detailTrisSize];
		for( int i=0; i<detailTrisSize; ++i )
		{
			m_header.dtris[i] = new dtTriIdx();
			m_header.dtris[i].datas[0] = readerStream.ReadByte();
			m_header.dtris[i].datas[1] = readerStream.ReadByte();
			m_header.dtris[i].datas[2] = readerStream.ReadByte();
			m_header.dtris[i].datas[3] = readerStream.ReadByte();
		}
		
		m_nodePool = new dtNodePool(2048, 256);		
		m_openList = new dtNodeQueue(2048);
		
		
		/*if( ownsData )
		{
			m_data = data;
			m_dataSize = dataSize;
		}*/

		return true;
	}