Exemple #1
0
 public void Dispose()
 {
     _mapIndex?.Close();
     _mapStream?.Close();
     StaticsDataStream?.Close();
     _staticsIndexReader?.Close();
 }
Exemple #2
0
        private unsafe StaticTile[][][] ReadStaticBlock(int x, int y)
        {
            try
            {
                _staticsIndexReader.BaseStream.Seek((x * BlockHeight + y) * 12, SeekOrigin.Begin);

                var lookup = _staticsIndexReader.ReadInt32();
                var length = _staticsIndexReader.ReadInt32();

                if (lookup < 0 || length <= 0)
                {
                    return(EmptyStaticBlock);
                }

                var count = length / 7;

                StaticsDataStream.Seek(lookup, SeekOrigin.Begin);

                if (_tileBuffer.Length < count)
                {
                    _tileBuffer = new StaticTile[count];
                }

                var staTiles = _tileBuffer; // new StaticTile[tileCount];

                fixed(StaticTile *pTiles = staTiles)
                {
                    NativeReader.Read(StaticsDataStream.SafeFileHandle.DangerousGetHandle(), pTiles, length);
                    if (_lists == null)
                    {
                        _lists = new TileList[8][];

                        for (var i = 0; i < 8; ++i)
                        {
                            _lists[i] = new TileList[8];

                            for (var j = 0; j < 8; ++j)
                            {
                                _lists[i][j] = new TileList();
                            }
                        }
                    }

                    var lists = _lists;

                    StaticTile *pCur = pTiles, pEnd = pTiles + count;

                    while (pCur < pEnd)
                    {
                        lists[pCur->_x & 0x7][pCur->_y & 0x7].Add(pCur->_id, pCur->_z);
                        pCur += 1;
                    }

                    var tiles = new StaticTile[8][][];

                    for (var i = 0; i < 8; ++i)
                    {
                        tiles[i] = new StaticTile[8][];

                        for (var j = 0; j < 8; ++j)
                        {
                            tiles[i][j] = lists[i][j].ToArray();
                        }
                    }

                    return(tiles);
                }
            }
            catch (EndOfStreamException)
            {
                return(EmptyStaticBlock);
            }
        }