예제 #1
0
        unsafe byte[] ReadLandChunk(uint chunkX, uint chunkY)
        {
            // bounds check: keep chunk index within bounds of map
            chunkX %= ChunkWidth;
            chunkY %= ChunkHeight;
            // if this chunk is cached in the buffer, return the cached chunk.
            uint key   = (chunkX << 16) + chunkY;
            uint index = chunkX % 16 + ((chunkY % 16) * 16);

            if (m_BufferedLandChunkKeys[index] == key)
            {
                return(m_BufferedLandChunks[index]);
            }
            // if it was not cached in the buffer, we will be loading it.
            m_BufferedLandChunkKeys[index] = key;
            // load the map chunk from a file. Check the patch file first (mapdif#.mul), then the base file (map#.mul).
            if (m_Patch.TryGetLandPatch(MapIndex, chunkX, chunkY, ref m_BufferedLandChunks[index]))
            {
                return(m_BufferedLandChunks[index]);
            }
            int ptr = (int)((chunkX * ChunkHeight) + chunkY) * SizeOfLandChunk + 4;

            if (m_UOPIndex != null)
            {
                ptr = m_UOPIndex.Lookup(ptr);
            }
            m_MapDataStream.Seek(ptr, SeekOrigin.Begin);
            NativeMethods.ReadBuffer(m_MapDataStream, m_BufferedLandChunks[index], SizeOfLandChunkData);
            Metrics.ReportDataRead(SizeOfLandChunkData);
            return(m_BufferedLandChunks[index]);
        }
예제 #2
0
        private unsafe byte[] readLandChunk(uint chunkX, uint chunkY)
        {
            // bounds check: keep chunk index within bounds of map
            chunkX %= ChunkWidth;
            chunkY %= ChunkHeight;

            // if this chunk is cached in the buffer, return the cached chunk.
            uint key   = (chunkX << 16) + chunkY;
            uint index = chunkX % 16 + ((chunkY % 16) * 16);

            if (m_bufferedLandChunks_Keys[index] == key)
            {
                return(m_bufferedLandChunks[index]);
            }

            // if it was not cached in the buffer, we will be loading it.
            m_bufferedLandChunks_Keys[index] = key;

            // load the map chunk from a file. Check the patch file first (mapdif#.mul), then the base file (map#.mul).
            if (m_Patch.TryGetLandPatch(chunkX, chunkY, ref m_bufferedLandChunks[index]))
            {
                return(m_bufferedLandChunks[index]);
            }
            else
            {
                uint ptr = ((chunkX * ChunkHeight) + chunkY) * m_SizeLandChunk + 4;
                m_MapDataStream.Seek(ptr, SeekOrigin.Begin);
                fixed(byte *pData = m_bufferedLandChunks[index])
                {
                    NativeMethods.Read(m_MapDataStream.SafeFileHandle, pData, m_SizeLandChunkData);
                }

                Metrics.ReportDataRead(m_SizeLandChunkData);
                return(m_bufferedLandChunks[index]);
            }
        }